Repository navigation
feat(gemma4): add CP recipes and 12B support #3911
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 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
065bc5e
feat(gemma4): add CP recipes and 12B support
sharonyu-115 da951da
docs: add Gemma 4 training curves
sharonyu-115 8558a1f
fix(gemma4): address CP recipe review
sharonyu-115 9d4212c
docs(gemma4): add 26B and 31B CP parity curves
sharonyu-115 9e4426e
test(gemma4): add 12B recipe to nightly
sharonyu-115 247e07d
test(gemma4): calibrate recurring metric checks
sharonyu-115 22f4dec
fix(vlm): enable expandable CUDA segments for Gemma 4
sharonyu-115 31e8be4
test(gemma4): address nightly review feedback
sharonyu-115 a304926
fix(vllm): filter Gemma 4 reload weights
sharonyu-115 6c778f4
ci: retry transient vllm wheel fetch
sharonyu-115 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,148 @@ | ||
| # Gemma 4 | ||
|
|
||
| NeMo RL supports post-training the Gemma 4 family with the AutoModel training | ||
| backend and vLLM generation. The reference configurations cover text-only DAPO | ||
| for the E2B, 12B, 26B-A4B, and 31B variants and multimodal GRPO for the E4B | ||
| variant. | ||
|
|
||
| > [!IMPORTANT] | ||
| > **Status: Functionally Ready.** The listed configurations provide short-run | ||
| > functional and CI coverage. They are starting points for post-training, not a | ||
| > claim of long-run convergence on every model and parallel layout. | ||
|
|
||
| ## Support Matrix | ||
|
|
||
| | Model | Task | Training backend | Training parallelism | Generation backend | Status | | ||
| | --- | --- | --- | --- | --- | --- | | ||
| | `google/gemma-4-E2B-it` | Text-only DAPO | AutoModel (FSDP2) | CP1 or CP2 | vLLM | Functionally Ready | | ||
| | `google/gemma-4-E4B-it` | VLM GRPO | AutoModel (FSDP2) | CP1 | vLLM TP4 | Functionally Ready | | ||
| | `google/gemma-4-12B-it` | Text-only DAPO | AutoModel (FSDP2) | CP1 | vLLM TP2 | Functionally Ready | | ||
| | `google/gemma-4-26B-A4B-it` | Text-only DAPO | AutoModel (FSDP2) | EP32 with CP1; EP16 with CP2 | vLLM TP4 | Functionally Ready | | ||
| | `google/gemma-4-31B-it` | Text-only DAPO | AutoModel (FSDP2) | CP1 or CP2 | vLLM TP4 | Functionally Ready | | ||
|
|
||
| ## Reference Recipes | ||
|
|
||
| Recipe YAML files under `examples/configs/recipes/` are the source of truth. | ||
|
|
||
| | Model | Layout | Nodes and GPUs | Recipe | | ||
| | --- | --- | --- | --- | | ||
| | E2B | FSDP2, CP1 | 1n8g | [`dapo-gemma4-e2b-it-1n8g-fsdp2-automodel.yaml`](../../../../examples/configs/recipes/llm/dapo-gemma4-e2b-it-1n8g-fsdp2-automodel.yaml) | | ||
| | E2B | FSDP2, CP2 | 1n8g | [`dapo-gemma4-e2b-it-1n8g-fsdp2cp2-automodel.yaml`](../../../../examples/configs/recipes/llm/dapo-gemma4-e2b-it-1n8g-fsdp2cp2-automodel.yaml) | | ||
| | E4B | VLM FSDP2, CP1 | 1n8g | [`vlm_grpo-gemma4-e4b-geo3k-1n8g-automodel.yaml`](../../../../examples/configs/recipes/vlm/vlm_grpo-gemma4-e4b-geo3k-1n8g-automodel.yaml) | | ||
| | 12B | FSDP2, CP1 | 2n8g | [`dapo-gemma4-12b-it-2n8g-fsdp2-automodel.yaml`](../../../../examples/configs/recipes/llm/dapo-gemma4-12b-it-2n8g-fsdp2-automodel.yaml) | | ||
| | 26B-A4B | FSDP2, EP32, CP1 | 4n8g | [`dapo-gemma4-26ba4b-it-4n8g-fsdp2-automodel.yaml`](../../../../examples/configs/recipes/llm/dapo-gemma4-26ba4b-it-4n8g-fsdp2-automodel.yaml) | | ||
| | 26B-A4B | FSDP2, EP16, CP2 | 4n8g | [`dapo-gemma4-26ba4b-it-4n8g-fsdp2ep16cp2-automodel.yaml`](../../../../examples/configs/recipes/llm/dapo-gemma4-26ba4b-it-4n8g-fsdp2ep16cp2-automodel.yaml) | | ||
| | 31B | FSDP2, CP1 | 4n8g | [`dapo-gemma4-31b-it-4n8g-fsdp2-automodel.yaml`](../../../../examples/configs/recipes/llm/dapo-gemma4-31b-it-4n8g-fsdp2-automodel.yaml) | | ||
| | 31B | FSDP2, CP2 | 4n8g | [`dapo-gemma4-31b-it-4n8g-fsdp2cp2-automodel.yaml`](../../../../examples/configs/recipes/llm/dapo-gemma4-31b-it-4n8g-fsdp2cp2-automodel.yaml) | | ||
|
|
||
| ## Run a Recipe | ||
|
|
||
| From an allocation matching the recipe, launch the standard GRPO entry point. | ||
| For example, run the 12B configuration with: | ||
|
|
||
| ```bash | ||
| uv run examples/run_grpo.py \ | ||
| --config examples/configs/recipes/llm/dapo-gemma4-12b-it-2n8g-fsdp2-automodel.yaml | ||
| ``` | ||
|
|
||
| See the [GRPO guide](../../grpo.md) for algorithm and launch details. | ||
|
|
||
| ## Context Parallel | ||
|
|
||
| Context Parallel support uses the refactored AutoModel CP interface introduced | ||
| by [PR #3498](https://github.com/NVIDIA-NeMo/RL/pull/3498). The E2B and 31B CP2 | ||
| recipes are thin overrides of their CP1 parents that change | ||
| `policy.dtensor_cfg.context_parallel_size` to `2`. The 26B-A4B CP2 recipe also | ||
| changes expert parallelism from EP32 to EP16 so the model-parallel product fits | ||
| on the same four-node allocation. Other model, optimizer, sequence-length, and | ||
| generation settings remain identical to their CP1 parents. | ||
|
|
||
| Context Parallel currently applies to the text-only E2B, 26B-A4B, and 31B | ||
| recipes backed by AutoModel's Gemma 4 model-owned attention. Do not enable it | ||
| for the E4B VLM recipe or the 12B unified checkpoint. The text-only recipes | ||
| freeze the vision and audio towers, disable sequence packing, and configure | ||
| vLLM with `language_model_only: true` where the checkpoint requires it. | ||
|
|
||
| Training and generation parallelism are independent. CP partitions training | ||
| sequences; the `tensor_parallel_size` under `policy.generation.vllm_cfg` | ||
| controls vLLM. The AutoModel model-parallel product must divide the training | ||
| world size. The 26B-A4B CP2 recipe uses EP16 × CP2 across 32 GPUs, provided by | ||
| four nodes with eight GPUs per node. | ||
|
|
||
| ## Validation Curves | ||
|
|
||
| The following plots show raw step-level metrics captured from completed | ||
| validation runs. Validation accuracy is plotted only at validation steps; the | ||
| other metrics are plotted at every recorded training step. | ||
|
|
||
| ### E2B Context Parallel Parity | ||
|
|
||
| The E2B CP1 and CP2 runs use the same 100-step training configuration except | ||
| for `policy.dtensor_cfg.context_parallel_size`. Their trajectories remain close | ||
| across the six metrics: the mean absolute difference in validation accuracy is | ||
| 0.0083 across six aligned validation points, while the mean absolute difference | ||
| in generation KL error is 1.6e-5 across 100 aligned training points. | ||
|
|
||
|  | ||
|
|
||
| ### 26B-A4B Context Parallel Parity | ||
|
|
||
| The 26B-A4B pair keeps the four-node, 32-GPU training world size fixed while | ||
| changing the model-parallel layout from EP32 × CP1 to EP16 × CP2. Both runs | ||
| complete 100 steps. The mean absolute difference in validation accuracy is | ||
| 0.0114 across 20 aligned validation points, while the mean absolute difference | ||
| in generation KL error is 5.6e-5 across 100 aligned training points. The final | ||
| validation accuracies are 0.741 for EP32 × CP1 and 0.751 for EP16 × CP2. | ||
|
|
||
|  | ||
|
|
||
| ### 31B Context Parallel Parity | ||
|
|
||
| The 31B CP1 and CP2 runs use the same four-node training configuration except | ||
| for `policy.dtensor_cfg.context_parallel_size`. Both runs complete 100 steps. | ||
| The mean absolute difference in validation accuracy is 0.0099 across 20 aligned | ||
| validation points, while the mean absolute difference in generation KL error is | ||
| 2.2e-5 across 100 aligned training points. The final validation accuracies are | ||
| 0.823 for CP1 and 0.818 for CP2. | ||
|
|
||
|  | ||
|
|
||
| ### 12B Long Run | ||
|
|
||
| The 12B CP1 run completed 200 steps. Validation accuracy increases from 0.540 | ||
| at step 5 to 0.617 at step 200 and reaches a maximum of 0.631. Training loss | ||
| decreases from 0.166 at step 1 to 0.054 at step 200, while generation KL error | ||
| stays below 6.9e-4. The recorded history contains 199 training-metric rows and | ||
| 39 validation rows; step 125 has no values for the requested metrics, so the | ||
| plot does not interpolate that missing row. | ||
|
|
||
|  | ||
|
|
||
| ## 12B Unified Checkpoint | ||
|
|
||
| The 12B checkpoint reports `model_type: gemma4_unified` and architecture | ||
| `Gemma4UnifiedForConditionalGeneration`. NeMo RL routes it through the | ||
| image-text AutoModel class so the complete checkpoint can load, while the | ||
| reference recipe trains only the language path: | ||
|
|
||
| - The vision and audio towers are frozen. | ||
| - vLLM generation uses `language_model_only: true` and TP2. | ||
| - Weight refits omit the frozen vision/audio tensors because vLLM's text-only | ||
| unified model uses encoder-free multimodal stubs with a different layout. | ||
| - vLLM tokenizer initialization is enabled for the unified architecture. | ||
| - Activation checkpointing and optimizer offload during log-probability | ||
| computation are enabled. | ||
| - Sequence packing and Liger kernels are disabled. | ||
| - The total sequence length is 4,096 tokens, with up to 3,072 generated tokens. | ||
|
|
||
| ## Limitations and Tracking | ||
|
|
||
| - Context Parallel is not supported by the Gemma 4 VLM recipe. | ||
| - The 12B `gemma4_unified` checkpoint currently supports CP1 only; unlike the | ||
| other text variants, it does not use AutoModel's Gemma 4 model-owned CP | ||
| attention implementation. | ||
| - The recipes disable sequence packing; validate any packing change separately. | ||
| - The functional status does not imply long-run convergence for every variant. | ||
| - Gemma 4 CP support is tracked by | ||
| [#2914](https://github.com/NVIDIA-NeMo/RL/issues/2914), and 12B support by | ||
| [#2913](https://github.com/NVIDIA-NeMo/RL/issues/2913). |
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,20 @@ | ||
| # Gemma | ||
|
|
||
| This is the landing page for Gemma model guidance in NeMo RL. It links to | ||
| version-specific pages covering reference recipes, supported parallel layouts, | ||
| and model-specific configuration requirements. | ||
|
|
||
| For the full list of supported models, see | ||
| [Model Support](../../../about/model-support.md). | ||
|
|
||
| ## Version Guides | ||
|
|
||
| - **[Gemma 4](gemma4.md)** — text-only DAPO recipes for the E2B, 12B, 26B-A4B, | ||
| and 31B variants, including AutoModel Context Parallel recipes, plus an E4B | ||
| VLM GRPO recipe. | ||
|
|
||
| ```{toctree} | ||
| :hidden: | ||
|
|
||
| gemma4.md | ||
| ``` |
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
98 changes: 98 additions & 0 deletions
98
examples/configs/recipes/llm/dapo-gemma4-12b-it-2n8g-fsdp2-automodel.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,98 @@ | ||
| defaults: ../../grpo_math_1B.yaml | ||
| grpo: | ||
| batch_multiplier: 3 | ||
| val_period: 5 | ||
| max_val_samples: 960 | ||
| val_batch_size: 960 | ||
| use_leave_one_out_baseline: false | ||
| use_dynamic_sampling: true | ||
| reward_scaling: | ||
| enabled: true | ||
| target_min: -1.0 | ||
| reward_shaping: | ||
| enabled: true | ||
| overlong_buffer_length: 384 | ||
| max_response_length: 3072 | ||
| loss_fn: | ||
| reference_policy_kl_penalty: 0.0 | ||
| use_importance_sampling_correction: true | ||
| truncated_importance_sampling_type: tis | ||
| truncated_importance_sampling_ratio: 2 | ||
| ratio_clip_max: 0.28 | ||
| ratio_clip_c: 10 | ||
| checkpointing: | ||
| checkpoint_dir: results/dapo-gemma4-12b-it-2n8g-fsdp2-automodel | ||
| save_period: 5 | ||
| policy: | ||
| model_name: google/gemma-4-12B-it | ||
| tokenizer: | ||
| name: google/gemma-4-12B-it | ||
| train_micro_batch_size: 1 | ||
| logprob_batch_size: 1 | ||
| max_total_sequence_length: 4096 | ||
| logprob_chunk_size: 4096 | ||
| offload_optimizer_for_logprob: true | ||
| optimizer: | ||
| name: transformer_engine.pytorch.optimizers.fused_adam.FusedAdam | ||
| kwargs: | ||
| lr: 1.0e-06 | ||
| weight_decay: 0.1 | ||
| master_weights: true | ||
| store_param_remainders: true | ||
| exp_avg_dtype: torch.bfloat16 | ||
| exp_avg_sq_dtype: torch.bfloat16 | ||
| scheduler: | ||
| - name: torch.optim.lr_scheduler.LinearLR | ||
| kwargs: | ||
| start_factor: 1.0e-08 | ||
| end_factor: 1.0 | ||
| total_iters: 10 | ||
| - name: torch.optim.lr_scheduler.ConstantLR | ||
| kwargs: | ||
| factor: 1.0 | ||
| total_iters: 10000000000 | ||
| - milestones: | ||
| - 10 | ||
| dtensor_cfg: | ||
| activation_checkpointing: true | ||
| automodel_kwargs: | ||
| use_liger_kernel: false | ||
| use_sdpa_patching: false | ||
| freeze_config: | ||
| freeze_vision_tower: true | ||
| freeze_audio_tower: true | ||
| freeze_language_model: false | ||
| sequence_packing: | ||
| enabled: false | ||
| dynamic_batching: | ||
| enabled: true | ||
| make_sequence_length_divisible_by: 1 | ||
| generation: | ||
| max_new_tokens: 3072 | ||
| vllm_cfg: | ||
| tensor_parallel_size: 2 | ||
| gpu_memory_utilization: 0.5 | ||
| vllm_kwargs: | ||
| language_model_only: true | ||
| data: | ||
| max_input_seq_length: 2048 | ||
| train: | ||
| dataset_name: DAPOMath17K | ||
| validation: | ||
| dataset_name: DAPOMathAIME2024 | ||
| default: | ||
| prompt_file: null | ||
| env: | ||
| math: | ||
| num_workers: 16 | ||
| math_verify_impl: dapo_math_verify | ||
| logger: | ||
| log_dir: logs/dapo-gemma4-12b-it-2n8g-fsdp2-automodel | ||
| wandb_enabled: true | ||
| tensorboard_enabled: true | ||
| wandb: | ||
| project: nemorl-gemma4 | ||
| name: dapo-gemma4-12b-it-2n8g-fsdp2-automodel | ||
| cluster: | ||
| gpus_per_node: 8 | ||
| num_nodes: 2 |
11 changes: 11 additions & 0 deletions
11
examples/configs/recipes/llm/dapo-gemma4-26ba4b-it-4n8g-fsdp2ep16cp2-automodel.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,11 @@ | ||
| defaults: ./dapo-gemma4-26ba4b-it-4n8g-fsdp2-automodel.yaml | ||
| policy: | ||
| dtensor_cfg: | ||
| expert_parallel_size: 16 | ||
| context_parallel_size: 2 | ||
| checkpointing: | ||
| checkpoint_dir: results/dapo-gemma4-26ba4b-it-4n8g-fsdp2ep16cp2-automodel | ||
| logger: | ||
| log_dir: logs/dapo-gemma4-26ba4b-it-4n8g-fsdp2ep16cp2-automodel | ||
| wandb: | ||
| name: dapo-gemma4-26ba4b-it-4n8g-fsdp2ep16cp2-automodel |
10 changes: 10 additions & 0 deletions
10
examples/configs/recipes/llm/dapo-gemma4-31b-it-4n8g-fsdp2cp2-automodel.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,10 @@ | ||
| defaults: ./dapo-gemma4-31b-it-4n8g-fsdp2-automodel.yaml | ||
| policy: | ||
| dtensor_cfg: | ||
| context_parallel_size: 2 | ||
| checkpointing: | ||
| checkpoint_dir: results/dapo-gemma4-31b-it-4n8g-fsdp2cp2-automodel | ||
| logger: | ||
| log_dir: logs/dapo-gemma4-31b-it-4n8g-fsdp2cp2-automodel | ||
| wandb: | ||
| name: dapo-gemma4-31b-it-4n8g-fsdp2cp2-automodel |
10 changes: 10 additions & 0 deletions
10
examples/configs/recipes/llm/dapo-gemma4-e2b-it-1n8g-fsdp2cp2-automodel.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,10 @@ | ||
| defaults: ./dapo-gemma4-e2b-it-1n8g-fsdp2-automodel.yaml | ||
| policy: | ||
| dtensor_cfg: | ||
| context_parallel_size: 2 | ||
| checkpointing: | ||
| checkpoint_dir: results/dapo-gemma4-e2b-it-1n8g-fsdp2cp2-automodel | ||
| logger: | ||
| log_dir: logs/dapo-gemma4-e2b-it-1n8g-fsdp2cp2-automodel | ||
| wandb: | ||
| name: dapo-gemma4-e2b-it-1n8g-fsdp2cp2-automodel |
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.
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.