-
Notifications
You must be signed in to change notification settings - Fork 354
feat: Add linear CE loss fusion for DPO #2139
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
Merged
yuki-97
merged 7 commits into
NVIDIA-NeMo:main
from
pengdurice:peng-add-linear-ce-fusion-v2
Mar 28, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
78247a6
initial commit, add DPO code as well as did local test and confirmed …
pengdurice 7ed04cc
fix test since 300s is not enough for two tests
pengdurice d4c86ef
remove local test setup
pengdurice f7ac212
add documentation
pengdurice eaeb51b
clean up
pengdurice dccf08e
rebase on main and fix conflicts
pengdurice ed54695
add a guardrail which can be removed when seq packing and dpo are com…
pengdurice 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
47 changes: 47 additions & 0 deletions
47
examples/configs/recipes/llm/dpo-qwen2.5-math7b-1n8g-megatron_chunked_linear_ce_loss.yaml
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,47 @@ | ||
| defaults: ../../dpo.yaml | ||
| dpo: | ||
| max_num_steps: 10 | ||
| checkpointing: | ||
| enabled: false | ||
| policy: | ||
| model_name: Qwen/Qwen2.5-Math-7B | ||
| tokenizer: | ||
| name: ${policy.model_name} | ||
| train_global_batch_size: 32 | ||
| train_micro_batch_size: 1 | ||
| max_total_sequence_length: 6000 | ||
| dtensor_cfg: | ||
| enabled: false | ||
| megatron_cfg: | ||
| enabled: true | ||
| use_linear_ce_fusion_loss: true | ||
| linear_ce_fusion_chunk_size: 128 | ||
| tensor_model_parallel_size: 4 | ||
| pipeline_model_parallel_size: 2 | ||
| attention_backend: unfused | ||
| freeze_moe_router: true | ||
| moe_router_bias_update_rate: 0.0 | ||
| moe_permute_fusion: true | ||
| optimizer: | ||
| lr: 1.0e-06 | ||
| min_lr: 1.0e-06 | ||
| adam_beta2: 0.999 | ||
| use_distributed_optimizer: false | ||
| use_precision_aware_optimizer: false | ||
| scheduler: | ||
| lr_warmup_iters: 10 | ||
| lr_warmup_init: 1.0e-11 | ||
| lr_decay_iters: 32 | ||
| make_sequence_length_divisible_by: 8 | ||
| data: | ||
| num_workers: 8 | ||
| logger: | ||
| wandb: | ||
| project: nemo-rl | ||
| name: dpo-qwen2.5-math-7b-megatron-chunked-linear-ce-loss-1n8g | ||
| tensorboard: | ||
| log_dir: tb_logs-dpo-qwen2.5-math-7b-megatron-chunked-linear-ce-loss-1n8g | ||
| mlflow: | ||
| run_name: dpo-qwen2.5-math-7b-megatron-chunked-linear-ce-loss-1n8g | ||
| cluster: | ||
| gpus_per_node: 8 |
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
43 changes: 43 additions & 0 deletions
43
tests/test_suites/llm/dpo-qwen2.5-math7b-1n8g-megatron_chunked_linear_ce_loss.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,43 @@ | ||
| #!/bin/bash | ||
| SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd) | ||
| source $SCRIPT_DIR/common.env | ||
|
|
||
| # ===== BEGIN CONFIG ===== | ||
| NUM_NODES=1 | ||
| STEPS_PER_RUN=10 | ||
| MAX_STEPS=10 | ||
| NUM_RUNS=$(( (MAX_STEPS + STEPS_PER_RUN - 1) / STEPS_PER_RUN )) # Round up | ||
| NUM_MINUTES=25 | ||
| # ===== END CONFIG ===== | ||
|
|
||
| exit_if_max_steps_reached | ||
|
|
||
| # Run the experiment | ||
| cd $PROJECT_ROOT | ||
| uv run examples/run_dpo.py \ | ||
| --config $CONFIG_PATH \ | ||
| dpo.max_num_steps=$MAX_STEPS \ | ||
| logger.log_dir=$LOG_DIR \ | ||
| logger.wandb_enabled=True \ | ||
| logger.wandb.project=nemo-rl \ | ||
| logger.wandb.name=$EXP_NAME \ | ||
| logger.monitor_gpus=True \ | ||
| logger.tensorboard_enabled=True \ | ||
| checkpointing.enabled=true \ | ||
| checkpointing.checkpoint_dir=$CKPT_DIR \ | ||
| $@ \ | ||
| 2>&1 | tee $RUN_LOG | ||
|
|
||
| # Convert tensorboard logs to json | ||
| uv run tests/json_dump_tb_logs.py $LOG_DIR --output_path $JSON_METRICS | ||
|
|
||
| # Only run metrics if the target step is reached | ||
| if [[ $(jq 'to_entries | .[] | select(.key == "train/loss") | .value | keys | map(tonumber) | max' $JSON_METRICS) -ge $MAX_STEPS ]]; then | ||
| # Smoke checks: run completed and loss is finite/reasonable. | ||
| uv run tests/check_metrics.py $JSON_METRICS \ | ||
| 'data["train/loss"]["10"] > 0.0' \ | ||
| 'data["train/loss"]["10"] < 20.0' | ||
|
|
||
| # Clean up checkpoint directory after successful run to save space. | ||
| rm -rf "$CKPT_DIR" | ||
| fi |
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.
Uh oh!
There was an error while loading. Please reload this page.