-
Notifications
You must be signed in to change notification settings - Fork 442
fix: Fixes to make Megatron backend match dtensor #1389
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
Merged
Changes from 16 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
ce6fd8a
enable megatron calculate_per_token_loss
ashors1 bdcee3c
remove unneeded import
ashors1 408900a
TP bug fix and add WIP unit test
ashors1 d8348d1
fixes
ashors1 9d0c410
lint
ashors1 72a5c73
add tensor parallel attributes check
ashors1 dcdd016
add convergence test
ashors1 9f99d53
address comment
ashors1 5cfad4a
Merge branch 'main' of github.com:NVIDIA-NeMo/RL into ashors/fix-mcor…
ashors1 3007940
improve unit test
ashors1 ba86f3a
minimize config
ashors1 37d57d6
fix permissions
ashors1 7a65797
fix convergence test
ashors1 198027a
minimize config
ashors1 64594d0
fix unit test
ashors1 f2cb2ba
remove more occurrences of average_in_collective
ashors1 cc8b6d7
link to GH issue
ashors1 d88f478
Merge branch 'main' of github.com:NVIDIA-NeMo/RL into ashors/fix-mcor…
ashors1 f12e113
fix test failure
ashors1 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
53 changes: 53 additions & 0 deletions
53
examples/configs/recipes/llm/sft-qwen2.5-math-7b-megatron.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,53 @@ | ||
| defaults: ../../sft.yaml | ||
| sft: | ||
| max_num_steps: 80 | ||
| checkpointing: | ||
| enabled: false | ||
| policy: | ||
| model_name: Qwen/Qwen2.5-Math-7B | ||
| train_global_batch_size: 512 | ||
| max_total_sequence_length: 16384 | ||
| dtensor_cfg: | ||
| enabled: false | ||
| megatron_cfg: | ||
| enabled: true | ||
| tensor_model_parallel_size: 4 | ||
| context_parallel_size: 2 | ||
| sequence_parallel: true | ||
| freeze_moe_router: true | ||
| moe_router_dtype: fp64 | ||
| moe_router_bias_update_rate: 0.0 | ||
| moe_permute_fusion: true | ||
| optimizer: | ||
| lr: 1.0e-06 | ||
| min_lr: 1.0e-06 | ||
| bf16: true | ||
| adam_beta2: 0.999 | ||
| adam_eps: 1.0e-08 | ||
| use_distributed_optimizer: false | ||
| use_precision_aware_optimizer: false | ||
| scheduler: | ||
| lr_decay_iters: null | ||
| lr_warmup_iters: 10 | ||
| lr_warmup_init: 1.0e-11 | ||
| sequence_packing: | ||
| enabled: true | ||
| make_sequence_length_divisible_by: 32 | ||
| data: | ||
| dataset_name: openmathinstruct2 | ||
| prompt_file: examples/prompts/math.txt | ||
| split: train_1M | ||
| add_generation_prompt: true | ||
| output_key: generated_solution | ||
| num_workers: 8 | ||
| logger: | ||
| wandb: | ||
| project: nemo-rl | ||
| name: sft-qwen2.5-math-7b-megatron | ||
| tensorboard: | ||
| log_dir: tb_logs-sft-qwen2.5-math-7b-megatron | ||
| mlflow: | ||
| run_name: sft-qwen2.5-math-7b-megatron | ||
| cluster: | ||
| gpus_per_node: 8 | ||
| num_nodes: 2 |
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
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
| 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 | ||
|
|
||
| # TODO: this config can crash on OOM | ||
| # https://github.com/NVIDIA-NeMo/RL/issues/263 | ||
|
|
||
| # ===== BEGIN CONFIG ===== | ||
| NUM_NODES=2 | ||
| STEPS_PER_RUN=80 # step_time ~ 29sec | ||
| MAX_STEPS=80 | ||
| NUM_RUNS=$(( (MAX_STEPS + STEPS_PER_RUN - 1) / STEPS_PER_RUN )) # Round up | ||
| NUM_MINUTES=30 | ||
| # ===== END CONFIG ===== | ||
|
|
||
| exit_if_max_steps_reached | ||
|
|
||
| # Run the experiment | ||
| cd $PROJECT_ROOT | ||
| uv run examples/run_sft.py \ | ||
| --config $CONFIG_PATH \ | ||
| sft.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 \ | ||
| ~policy.tokenizer.chat_template \ | ||
| $@ \ | ||
| 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 | ||
| uv run tests/check_metrics.py $JSON_METRICS \ | ||
| 'data["train/loss"]["80"] < 0.301' \ | ||
| 'data["validation/val_loss"]["80"] < 0.304' | ||
| 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.
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.