-
Notifications
You must be signed in to change notification settings - Fork 173
fix: Megatron static inference and adapt to mcore engine API changes #1488
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
shanmugamr1992
wants to merge
11
commits into
main
Choose a base branch
from
fix_static
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 4 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
327dd7d
Fixed static inference
e4cb2c9
Updated to directly use static engine
3bbee4b
Fixed error
c100103
Merge branch 'main' into fix_static
shanmugamr1992 a52d9d0
Fixed error
ef3b11f
Fixed error
eefecfe
Fixed error
b1d55e5
Fixed error
287e57d
Fixed error
89466fb
Fixed error
d26cc21
Removing unwanted padding in static batching
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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| #!/bin/bash | ||
|
|
||
| SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd) | ||
| PROJECT_ROOT=$(realpath $SCRIPT_DIR/../..) | ||
| # Mark the current repo as safe, since wandb fetches metadata about the repo | ||
| git config --global --add safe.directory $PROJECT_ROOT | ||
|
|
||
| set -eou pipefail | ||
|
|
||
| EXP_NAME=$(basename $0 .sh) | ||
| EXP_DIR=$SCRIPT_DIR/$EXP_NAME | ||
| LOG_DIR=$EXP_DIR/logs | ||
| JSON_METRICS=$EXP_DIR/metrics.json | ||
| RUN_LOG=$EXP_DIR/run.log | ||
| export PYTHONPATH=${PROJECT_ROOT}:${PYTHONPATH:-} | ||
|
|
||
| rm -rf $EXP_DIR $LOG_DIR | ||
| mkdir -p $EXP_DIR $LOG_DIR | ||
|
|
||
| # Using Qwen2.5-0.5B instead of Qwen3-0.6B because the latter is not supported by Megatron yet | ||
| cd $PROJECT_ROOT | ||
| uv run coverage run -a --data-file=$PROJECT_ROOT/tests/.coverage --source=$PROJECT_ROOT/nemo_rl \ | ||
| $PROJECT_ROOT/examples/run_grpo_math.py \ | ||
| --config $PROJECT_ROOT/examples/configs/grpo_math_1B_megatron.yaml \ | ||
| policy.model_name=Qwen/Qwen2.5-0.5B \ | ||
| grpo.num_prompts_per_step=2 \ | ||
| grpo.num_generations_per_prompt=4 \ | ||
| policy.train_global_batch_size=4 \ | ||
| policy.logprob_batch_size=4 \ | ||
| policy.train_micro_batch_size=1 \ | ||
| policy.generation.backend=megatron \ | ||
| cluster.gpus_per_node=2 \ | ||
| grpo.max_num_steps=2 \ | ||
| logger.tensorboard_enabled=true \ | ||
| logger.log_dir=$LOG_DIR \ | ||
| logger.wandb_enabled=false \ | ||
| logger.monitor_gpus=true \ | ||
| checkpointing.enabled=false \ | ||
| $@ \ | ||
| 2>&1 | tee $RUN_LOG | ||
|
|
||
| uv run tests/json_dump_tb_logs.py $LOG_DIR --output_path $JSON_METRICS | ||
|
|
||
| uv run tests/check_metrics.py $JSON_METRICS \ | ||
| 'max(data["train/token_mult_prob_error"]) < 1.05' | ||
|
|
42 changes: 42 additions & 0 deletions
42
tests/test_suites/llm/grpo-llama3.2-1b-instruct-1n8g-megatron_generation.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,42 @@ | ||
| #!/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=500 | ||
| MAX_STEPS=500 | ||
| NUM_RUNS=$(( (MAX_STEPS + STEPS_PER_RUN - 1) / STEPS_PER_RUN )) # Round up | ||
| NUM_MINUTES=180 | ||
| # ===== END CONFIG ===== | ||
|
|
||
| exit_if_max_steps_reached | ||
|
|
||
| # Run the experiment | ||
| cd $PROJECT_ROOT | ||
| uv run examples/run_grpo_math.py \ | ||
| --config $CONFIG_PATH \ | ||
| grpo.max_num_steps=$MAX_STEPS \ | ||
| policy.generation.backend=megatron \ | ||
| 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 | ||
| uv run tests/check_metrics.py $JSON_METRICS \ | ||
| 'mean(data["train/token_mult_prob_error"]) < 1.1' \ | ||
| 'data["train/token_mult_prob_error"]["500"] < 1.1' \ | ||
| 'data["train/reward"]["500"] > 0.1' \ | ||
| 'mean(data["timing/train/total_step_time"], -6, -1) < 10.5' | ||
| 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
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.