-
Notifications
You must be signed in to change notification settings - Fork 259
[skyrl-train] Fix loss reduction by moving normalization to the advantage computation #925
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
justinvyu
wants to merge
32
commits into
NovaSky-AI:main
Choose a base branch
from
justinvyu:fix_loss_reduction2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
b7b494c
normalize the advantages instead
justinvyu da24f6b
sum reduction for the loss
justinvyu cbed7ff
add a few options
justinvyu fc7b775
always sum on the loss calculation side
justinvyu c411586
fix some bugs
justinvyu 1bf83d8
revert the critic worker changes
justinvyu dc838e1
more revert
justinvyu 84e34e2
Merge branch 'main' of https://github.com/erictang000/SkyRL into fix_…
erictang000 be22e03
Merge branch 'main' of https://github.com/erictang000/SkyRL into fix_…
erictang000 6259174
fix conflict with main
erictang000 4b8e556
x
erictang000 4547ae1
fix normalization
erictang000 635a9c1
change reduce_loss to just sums everywhere
erictang000 cd7506b
fix tests
erictang000 0133819
Merge branch 'main' of https://github.com/erictang000/SkyRL into fix_…
erictang000 ddeaae4
scale by num_microbatches in megatron loss
erictang000 ef24d32
x
erictang000 89145e5
add dp size scaling to megatron and move fsdp loss scaling to loss ra…
erictang000 133d9a9
Merge branch 'main' of https://github.com/erictang000/SkyRL into fix_…
erictang000 49babe4
debugging megatron fsdp loss diff
erictang000 a3fa670
Merge branch 'main' of https://github.com/erictang000/SkyRL into fix_…
erictang000 c0dd9ff
Merge branch 'fix_loss_reduction2' of https://github.com/justinvyu/Sk…
erictang000 eb241de
start trying to make metrics invariant to dp size for megatron
erictang000 772141a
x
erictang000 f66736a
metrics now (mostly) matching for megatron vs fsdp
erictang000 0df4467
Merge branch 'fix_loss_reduction2' of https://github.com/justinvyu/Sk…
erictang000 05054d1
loss scale in fsdp worker correctly
erictang000 155d4af
x
erictang000 c90cc56
Merge branch 'fix_loss_reduction2' of https://github.com/justinvyu/Sk…
erictang000 1d31c66
cleaning
erictang000 4e05912
fixing tests
erictang000 a563148
x
erictang000 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
121 changes: 121 additions & 0 deletions
121
skyrl-train/examples/megatron/run_megatron_dapo_qwen3_1.7b.sh
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| set -x | ||
|
|
||
| # Colocated DAPO training+generation for Qwen3-1.7B-Base on DAPO training data with Megatron. | ||
| # bash examples/algorithms/dapo/prepare_dapo_data.sh | ||
| # bash examples/megatron/run_megatron_dapo_qwen3_1.7b.sh | ||
|
|
||
| MODEL_NAME="Qwen/Qwen3-1.7B-Base" | ||
| DATA_DIR="$HOME/data/dapo" | ||
| TRAIN_FILE="$DATA_DIR/dapo-math-17k-cleaned.parquet" | ||
| TEST_FILE="$DATA_DIR/aime-2024-cleaned.parquet" | ||
| NUM_NODES=1 | ||
| NUM_GPUS_PER_NODE=8 | ||
| NUM_INFERENCE_ENGINES=8 | ||
| INFERENCE_ENGINE_TENSOR_PARALLEL_SIZE=1 | ||
| LOGGER="wandb" # change to "console" to print to stdout | ||
|
|
||
| CLIP_RATIO_LOW=0.2 | ||
| CLIP_RATIO_HIGH=0.28 | ||
| # use token mean loss reduction | ||
| LOSS_REDUCTION="token_mean" | ||
| # applies overlong filtering (but not soft overlong punishment) | ||
| APPLY_OVERLONG_FILTERING=true | ||
| # apply soft overlong punishment with custom trainer impl in main_dapo.py | ||
| OVERLONG_BUFFER_LEN=$((1024 * 4)) | ||
| OVERLONG_BUFFER_PENALTY_FACTOR=1.0 | ||
|
|
||
| # other DAPO parameters | ||
| USE_KL_LOSS=false | ||
| TEMPERATURE=1.0 | ||
| TOP_P=1.0 | ||
| EVAL_TOP_P=0.7 | ||
| CLIP_RATIO_C=10.0 | ||
| MAX_PROMPT_LENGTH=$((1024 * 2)) | ||
| MAX_RESPONSE_LENGTH=$((1024 * 8)) | ||
|
|
||
| # repro run parameters | ||
| TRAIN_BATCH_SIZE=512 | ||
| MINI_BATCH_SIZE=32 | ||
| N_SAMPLES_PER_PROMPT=16 | ||
| EVAL_N_SAMPLES_PER_PROMPT=32 | ||
| ENFORCE_EAGER=true # cuda graphs can cause some instability | ||
| LR=1e-6 | ||
|
|
||
| # megatron config | ||
| MEGATRON_TP=4 | ||
| MEGATRON_PP=2 | ||
| MEGATRON_CP=1 | ||
| MEGATRON_EP=1 | ||
| MEGATRON_ETP=null | ||
|
|
||
|
|
||
| # TIS parameters | ||
| TIS_IMP_RATIO_CAP=2.0 | ||
| TIS_TYPE=token | ||
|
|
||
| uv run --isolated --extra mcore -m examples.algorithms.dapo.main_dapo \ | ||
| data.train_data="['$TRAIN_FILE']" \ | ||
| data.val_data="['$TEST_FILE']" \ | ||
| trainer.algorithm.advantage_estimator="grpo" \ | ||
| trainer.algorithm.policy_loss_type="dual_clip" \ | ||
| +trainer.algorithm.overlong_buffer.len=$OVERLONG_BUFFER_LEN \ | ||
| +trainer.algorithm.overlong_buffer.penalty_factor=$OVERLONG_BUFFER_PENALTY_FACTOR \ | ||
| trainer.algorithm.loss_reduction=$LOSS_REDUCTION \ | ||
| generator.enforce_eager=$ENFORCE_EAGER \ | ||
| generator.apply_overlong_filtering=$APPLY_OVERLONG_FILTERING \ | ||
| generator.sampling_params.temperature=$TEMPERATURE \ | ||
| generator.sampling_params.top_p=$TOP_P \ | ||
| generator.eval_sampling_params.top_p=$EVAL_TOP_P \ | ||
| generator.eval_sampling_params.temperature=$TEMPERATURE \ | ||
| trainer.algorithm.use_kl_loss=$USE_KL_LOSS \ | ||
| trainer.algorithm.clip_ratio_c=$CLIP_RATIO_C \ | ||
| trainer.policy.model.path="$MODEL_NAME" \ | ||
| trainer.placement.colocate_all=true \ | ||
| trainer.strategy=megatron \ | ||
| trainer.placement.policy_num_nodes=$NUM_NODES \ | ||
| trainer.placement.policy_num_gpus_per_node=$NUM_GPUS_PER_NODE \ | ||
| generator.num_inference_engines=$NUM_INFERENCE_ENGINES \ | ||
| generator.inference_engine_tensor_parallel_size=$INFERENCE_ENGINE_TENSOR_PARALLEL_SIZE \ | ||
| trainer.policy.megatron_config.tensor_model_parallel_size=$MEGATRON_TP \ | ||
| trainer.policy.megatron_config.pipeline_model_parallel_size=$MEGATRON_PP \ | ||
| trainer.policy.megatron_config.context_parallel_size=$MEGATRON_CP \ | ||
| trainer.policy.megatron_config.expert_model_parallel_size=$MEGATRON_EP \ | ||
| trainer.policy.megatron_config.expert_tensor_parallel_size=$MEGATRON_ETP \ | ||
| trainer.algorithm.off_policy_correction.tis_ratio_type=$TIS_TYPE \ | ||
| trainer.algorithm.off_policy_correction.token_tis_ratio_clip_high=$TIS_IMP_RATIO_CAP \ | ||
| trainer.epochs=20 \ | ||
| trainer.algorithm.eps_clip_low=$CLIP_RATIO_LOW \ | ||
| trainer.algorithm.eps_clip_high=$CLIP_RATIO_HIGH \ | ||
| trainer.eval_batch_size=1024 \ | ||
| trainer.eval_before_train=true \ | ||
| trainer.eval_interval=5 \ | ||
| trainer.update_epochs_per_batch=1 \ | ||
| trainer.train_batch_size=$TRAIN_BATCH_SIZE \ | ||
| trainer.policy_mini_batch_size=$MINI_BATCH_SIZE \ | ||
| trainer.micro_forward_batch_size_per_gpu=8 \ | ||
| trainer.micro_train_batch_size_per_gpu=8 \ | ||
| trainer.ckpt_interval=10 \ | ||
| trainer.max_prompt_length=$MAX_PROMPT_LENGTH \ | ||
| generator.sampling_params.max_generate_length=$MAX_RESPONSE_LENGTH \ | ||
| trainer.policy.optimizer_config.lr=$LR \ | ||
| trainer.policy.optimizer_config.num_warmup_steps=160 \ | ||
| trainer.policy.optimizer_config.weight_decay=0.1 \ | ||
| trainer.policy.optimizer_config.max_grad_norm=1.0 \ | ||
| generator.backend=vllm \ | ||
| generator.run_engines_locally=true \ | ||
| generator.weight_sync_backend=nccl \ | ||
| generator.async_engine=false \ | ||
| generator.batched=true \ | ||
| environment.env_class=aime \ | ||
| generator.n_samples_per_prompt=$N_SAMPLES_PER_PROMPT \ | ||
| generator.eval_n_samples_per_prompt=$EVAL_N_SAMPLES_PER_PROMPT \ | ||
| generator.gpu_memory_utilization=0.8 \ | ||
| trainer.logger="$LOGGER" \ | ||
| trainer.project_name="dapo_aime" \ | ||
| trainer.run_name="dapo_qwen3_1.7b_base_megatron_tp${MEGATRON_TP}_pp${MEGATRON_PP}_cp${MEGATRON_CP}_loss_sum_dp1" \ | ||
| trainer.export_path="$HOME/exports/dapo_qwen3_1.7b_base_megatron_tp${MEGATRON_TP}_pp${MEGATRON_PP}_cp${MEGATRON_CP}_loss_sum_dp1" \ | ||
| trainer.hf_save_interval=300 \ | ||
| trainer.resume_mode=latest \ | ||
| trainer.max_ckpts_to_keep=3 \ | ||
| trainer.ckpt_path="$HOME/ckpts/dapo_qwen3_1.7b_base_megatron_tp${MEGATRON_TP}_pp${MEGATRON_PP}_cp${MEGATRON_CP}_loss_sum_dp1" \ | ||
| $@ |
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
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Example script references undefined shell variables after commenting out their definitions
In the
run_megatron.shexample script, the torch profiler config variables (ENABLE_TORCH_PROFILER,RANKS_TO_PROFILE,SAVE_PATH) are commented out on lines 20-23, but their references on lines 42-44 remain in theuv runcommand. In bash (withoutset -u), these expand to empty strings, causing the training script to receive empty/invalid values for profiler config options.Detailed Explanation
Lines 20-23 comment out the variable definitions:
But lines 42-44 still reference them:
Impact: The script would pass empty values for these config keys, which could cause config parsing errors or unexpected behavior at runtime.
Prompt for agents
Was this helpful? React with 👍 or 👎 to provide feedback.