-
Notifications
You must be signed in to change notification settings - Fork 438
feat: GSPO #859
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
feat: GSPO #859
Changes from 27 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
d5731a8
Added gspo
ertkonuk e6ba491
Port GSPO ratio clip from dev branch.
pjin-nvidia ce337d8
Micro batch size.
pjin-nvidia ddc6137
Merge branch 'main' into pjin/gspo-algo
pjin-nvidia 76c842d
Example GSPO config.
pjin-nvidia 8b65703
Cleaner impl.
pjin-nvidia 7938879
GSPO version of deepscaler example (WIP).
pjin-nvidia fef9120
Merge remote-tracking branch 'origin/main' into pjin/gspo-algo
pjin-nvidia 9782097
Alternative 2-node TP=2 deepscaler GSPO config (WIP).
pjin-nvidia 95867ed
Remove Qwen3 GSPO config (will take too long to test).
pjin-nvidia 4d0568d
Merge remote-tracking branch 'origin/main' into pjin/gspo-algo
pjin-nvidia c536aff
Rename sequence_level_importance_sampling => sequence_level_importanc…
pjin-nvidia 2cbc0ca
Merge remote-tracking branch 'origin/main' into pjin/gspo-algo
pjin-nvidia 5e384dc
Using the new deepscaler config.
pjin-nvidia 8882bfe
Restore comment.
pjin-nvidia b795e65
Restore comment.
pjin-nvidia 808953e
Merge remote-tracking branch 'origin/main' into pjin/gspo-algo
pjin-nvidia 446b44d
Merge remote-tracking branch 'origin/main' into pjin/gspo-algo
pjin-nvidia b9127f4
Merge remote-tracking branch 'origin/main' into pjin/gspo-algo
pjin-nvidia b6598df
Merge remote-tracking branch 'origin/main' into pjin/gspo-algo
pjin-nvidia 931b744
Minor fix.
pjin-nvidia b90ea62
Remove inaccurate comment.
pjin-nvidia e87d144
Merge remote-tracking branch 'origin/main' into pjin/gspo-algo
pjin-nvidia dfbd89d
GSPO config test.
pjin-nvidia 825f8a7
Merge remote-tracking branch 'origin/main' into pjin/gspo-algo
pjin-nvidia 15b234c
Merge remote-tracking branch 'origin/main' into pjin/gspo-algo
pjin-nvidia 3d80fb0
Merge remote-tracking branch 'origin/main' into HEAD
pjin-nvidia d95dea0
Batch size = 1 GSPO unit tests (should be equivalent to GRPO).
pjin-nvidia c957966
Clipped PG loss unit tests support for batch size > 1.
pjin-nvidia a28c974
GSPO unit tests.
pjin-nvidia 969cc88
Merge remote-tracking branch 'origin/main' into pjin/gspo-algo
pjin-nvidia c69ae82
Loop var name. Format.
pjin-nvidia 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
146 changes: 146 additions & 0 deletions
146
examples/configs/recipes/llm/gspo-deepscaler-1.5b-8K.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,146 @@ | ||
| # GRPO Algorithm Configuration | ||
| grpo: | ||
| num_prompts_per_step: 128 | ||
| num_generations_per_prompt: 8 | ||
| max_rollout_turns: 1 # for multi-turn rollouts. Math Environments just have 1 turn (answering the question) | ||
| max_num_steps: 1000000 | ||
| normalize_rewards: true | ||
| use_leave_one_out_baseline: true | ||
| val_period: 10 | ||
| val_at_start: false | ||
| max_val_samples: 480 | ||
| val_batch_size: 32 | ||
| seed: 42 | ||
|
|
||
| loss_fn: | ||
| reference_policy_kl_penalty: 0.0 | ||
| ratio_clip_min: 0.2 | ||
| ratio_clip_max: 0.2 | ||
| ratio_clip_c: null | ||
| # (default off) loss formulation improvements (docs/guides/grpo.md#loss) | ||
| use_on_policy_kl_approximation: false | ||
| use_importance_sampling_correction: false | ||
| sequence_level_importance_ratios: true | ||
| token_level_loss: false | ||
|
|
||
| checkpointing: | ||
| enabled: true | ||
| checkpoint_dir: "results/grpo" | ||
| metric_name: "val_reward" | ||
| higher_is_better: true | ||
| keep_top_k: 10 | ||
| save_period: 10 | ||
| checkpoint_must_save_by: null | ||
|
|
||
| policy: | ||
| model_name: "deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B" | ||
| tokenizer: | ||
| name: ${policy.model_name} ## specify if you'd like to use a tokenizer different from the model's default | ||
| train_global_batch_size: 64 | ||
| train_micro_batch_size: 1 | ||
| generation_batch_size: 32 # Only used when generating using HF backend | ||
| logprob_batch_size: 4 | ||
| max_total_sequence_length: 8192 | ||
| precision: "bfloat16" | ||
|
|
||
| dtensor_cfg: | ||
| enabled: true | ||
| cpu_offload: true | ||
| sequence_parallel: true | ||
| activation_checkpointing: true | ||
| tensor_parallel_size: 1 | ||
| context_parallel_size: 1 | ||
| custom_parallel_plan: null | ||
|
|
||
| dynamic_batching: | ||
| enabled: False | ||
|
|
||
| sequence_packing: | ||
| enabled: False | ||
|
|
||
| # makes the training sequence length divisible by the tensor parallel size | ||
| # this is useful for sequence parallel training | ||
| make_sequence_length_divisible_by: ${policy.dtensor_cfg.tensor_parallel_size} | ||
| max_grad_norm: 1.0 | ||
|
|
||
| optimizer: | ||
| name: "torch.optim.AdamW" | ||
| kwargs: | ||
| lr: 2.0e-6 | ||
| weight_decay: 0.01 | ||
| betas: [0.9, 0.999] | ||
| eps: 1e-8 | ||
| # when using Dtensor, we need to set foreach | ||
| # and fused to False | ||
| foreach: False | ||
| fused: False | ||
|
|
||
| scheduler: | ||
| - name: "torch.optim.lr_scheduler.LinearLR" | ||
| kwargs: | ||
| start_factor: 0.1 | ||
| end_factor: 1.0 | ||
| total_iters: 50 | ||
| - name: "torch.optim.lr_scheduler.ConstantLR" | ||
| kwargs: | ||
| factor: 1.0 | ||
| total_iters: 10000000000 | ||
| - milestones: [50] | ||
|
|
||
| generation: | ||
| backend: "vllm" | ||
| max_new_tokens: ${policy.max_total_sequence_length} | ||
| temperature: 1.0 | ||
| top_p: 1.0 | ||
| top_k: null | ||
| stop_token_ids: null | ||
| stop_strings: null | ||
| vllm_cfg: | ||
| async_engine: false | ||
| precision: ${policy.precision} | ||
| tensor_parallel_size: 1 | ||
| pipeline_parallel_size: 1 | ||
| gpu_memory_utilization: 0.6 | ||
| max_model_len: ${policy.max_total_sequence_length} | ||
| enforce_eager: True | ||
| colocated: | ||
| # true: generation shares training GPUs | ||
| # false: uses dedicated generation resources | ||
| enabled: true | ||
| # only relevant when enabled is false | ||
| resources: | ||
| gpus_per_node: null # Decides num gpus to be dedicated to generation when there is one node in the cluster i.e cluster.num_nodes == 1 | ||
| num_nodes: null # Decides number of nodes to be dedicated to generation | ||
|
|
||
| data: | ||
| max_input_seq_length: ${policy.max_total_sequence_length} # upper bound, real truncation occurs at vllm.max_model_len | ||
| prompt_file: "examples/prompts/cot.txt" | ||
| system_prompt_file: null | ||
| dataset_name: "DeepScaler" | ||
| shuffle: true | ||
|
|
||
| env: | ||
| math: | ||
| num_workers: 16 | ||
|
|
||
| logger: | ||
| log_dir: "logs" # Base directory for all logs | ||
| num_val_samples_to_print: 0 # Number of validation samples to pretty print on terminal | ||
| wandb_enabled: false | ||
| tensorboard_enabled: false | ||
| mlflow_enabled: false | ||
| monitor_gpus: false # If true, will monitor GPU usage and log to wandb and/or tensorboard | ||
| wandb: | ||
| project: "grpo-dev" | ||
| name: "grpo-dev-logger" | ||
| tensorboard: {} | ||
| mlflow: | ||
| experiment_name: "grpo-dev" | ||
| run_name: "grpo-dev-logger" | ||
| gpu_monitoring: | ||
| collection_interval: 10 # How often to collect GPU usage metrics (in seconds) | ||
| flush_interval: 10 # How often to flush GPU usage metrics to the loggers (in seconds) | ||
|
|
||
| cluster: | ||
| gpus_per_node: 8 | ||
| num_nodes: 1 |
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,67 @@ | ||
| #!/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=40 | ||
| MAX_STEPS=40 | ||
| NUM_RUNS=$(( (MAX_STEPS + STEPS_PER_RUN - 1) / STEPS_PER_RUN )) # Round up | ||
| NUM_MINUTES=240 | ||
| # ===== 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 \ | ||
| 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']['$MAX_STEPS'] < 1.1" | ||
| fi | ||
|
|
||
| # TODO: enable in subsequent PR to do a quick accuracy check | ||
| ## Convert 8k checkpoint | ||
| #uv run examples/converters/convert_dcp_to_hf.py \ | ||
| # --config=$CKPT_DIR/step_${MAX_STEPS}/config.yaml \ | ||
| # --dcp-ckpt-path=$CKPT_DIR/step_${MAX_STEPS}/policy/weights \ | ||
| # --hf-ckpt-path=$CKPT_DIR/gspo-deepscaler-8k-${MAX_STEPS}-hf | ||
| # | ||
| ## Run eval | ||
| #uv run examples/run_eval.py \ | ||
| # generation.model_name=$CKPT_DIR/gspo-deepscaler-8k-${MAX_STEPS}-hf \ | ||
| # data.prompt_file=examples/prompts/cot.txt \ | ||
| # generation.vllm_cfg.max_model_len=32768 2>&1 | tee ${RUN_LOG}.aime-8k | ||
| # | ||
| #cat ${RUN_LOG}.aime-8k | grep "score=" | sed 's/.*score=\([^ ]*\).*/{"score": \1}/' > ${RUN_LOG}-8k-metric.json | ||
| # | ||
| #uv run tests/check_metrics.py ${RUN_LOG}-8k-metric.json \ | ||
| # 'data["score"] >= 0.25' \ | ||
| # | ||
| ##uv run examples/run_eval.py \ | ||
| ## generation.model_name=deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B \ | ||
| ## data.prompt_file=examples/prompts/cot.txt \ | ||
| ## generation.vllm_cfg.max_model_len=32768 2>&1 | tee ${RUN_LOG}.aime-baseline | ||
| # | ||
| ##cat ${RUN_LOG}.aime-baseline | grep "score=" | sed 's/.*score=\([^ ]*\).*/{"score": \1}/' > ${RUN_LOG}-baseline-metric.json | ||
| # | ||
| ##uv run tests/check_metrics.py ${RUN_LOG}-baseline-metric.json \ | ||
| ## 'data["score"] == 0.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
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.