Repository navigation
feat(sagemaker): add train_dapo with dynamic sampling and Clip-Higher - #214
Open
chenqihong wants to merge 1 commit into
Open
chenqihong wants to merge 1 commit into
chenqihong wants to merge 1 commit into
Conversation
train_dapo.py follows the train_grpo.py loop and adds DAPO dynamic sampling (keep only groups whose rewards differ, resample until batch_size groups are kept, capped by max_num_gen_batches) and Clip-Higher (clip_low_threshold / clip_high_threshold sent as loss_fn_config). load_config takes an optional config_cls so DapoConfig can add fields while train_grpo keeps reading the same YAML. Documented in SETUP.md and config.yaml.example.
Linbo-Liu
reviewed
Nov 2, 2026
| args = parser.parse_args() | ||
| config = load_config(args.config, DapoConfig) | ||
| if not isinstance(config, DapoConfig): | ||
| raise TypeError(f"expected DapoConfig, got {type(config).__name__}") |
Contributor
There was a problem hiding this comment.
is this a bit over-engineered?
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
train_dapo.pyto the experimental SageMaker backend: thetrain_grpo.pyloop plus two parts of DAPO.batch_sizeprompts and keeps only groups whose rewards differ (an all-equal group has zero advantage), untilbatch_sizegroups are kept. Capped bymax_num_gen_batches; hitting the cap saves a checkpoint and stops.clip_low_threshold/clip_high_thresholdare sent asloss_fn_config.Token-level loss and overlong reward shaping are not included: the loss is computed server side, and overlong shaping depends on each agent's reward scale.
Changes
train_dapo.py: new.train()keeps the structure oftrain_grpo.py; the differences are the sampling step,loss_fn_config, a per-stepsampling:log line (generation batches, filtered fraction, kept groups, empty rollouts), and the final-eval condition. Advantages reusecompute_grpo_advantages.config.py:load_configtakes an optionalconfig_cls(defaultConfig), soDapoConfig(Config)can add its three fields whiletrain_grpo.pyreads the same YAML unchanged.config.yaml.example,SETUP.md: document the DAPO fields and how to runtrain_dapo.py.test_config.py,test_train_dapo.py(sampling logic, and the fulltrain()loop against fake SageMaker/ACR clients).Two small behavior differences from
train_grpo.py:batch_sizeraises instead of running 0 steps, so bad data never starts a billed session.train_grpo.pyusesglobal_step % eval_every, which skips the final eval when no step ran or the last step was skipped for having no datums. I lefttrain_grpo.pyunchanged; happy to fix it in a follow-up.Testing
pytest tests/: 655 passed, 23 skipped, 1 failed. The failure istests/aws_tools/apigateway_tools_test.py::ForwardingTest::test_handles_concurrent_requests, which this PR does not touch; it is flaky locally (passed 1 of 3 reruns). The SageMaker tests (47) all pass;test_train_dapo.pyskips whensagemaker.train.training_sessionis not installed.pre-commitpasses on the changed files.Note on dependencies
With
uv sync, the lock file installssagemaker-train1.24.0 (notraining_sessionmodule) and botocore 1.43.106 (no training-session operations), so neithertrain_grpo.pynortrain_dapo.pyruns. SETUP.md installs withuv pip install sagemaker-train, which should pick up current versions; I have not verified that path. I ran withsagemaker-train1.28.0 and botocore 1.43.117. Not changed in this PR.