Repository navigation
feat: Add YaRN rope scaling support on Magatron-Bridge #2188
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 all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
9156ee4
feat: Add force reimport model option to Megatron configuration
RayenTian 8c12200
Validate and enforce yarn rope_scaling configuration in GRPO and Meg…
RayenTian 6d9f701
feat: add NemotronCascade2SFTMathDataset to response datasets
RayenTian 6588130
Remove yarn rope_scaling checks from GRPO setup and enforce validatio…
RayenTian 6b3ac15
add SFT configuration and test script for Qwen3-0.6B model with Megat…
RayenTian b4a6f99
add GRPO configuration and test script for Qwen3-0.6B model with Mega…
RayenTian 176e99e
Update GRPO configuration for Qwen3-0.6B model: increase max steps to…
RayenTian 2b30a6d
Add new test scripts for Qwen3-0.6B model with Yarn support and adjus…
RayenTian 5a7c0d0
Refactor model import configuration: rename 'force_reimport_model' to…
RayenTian 88bdbc4
add 256k recipe
RayenTian 7e65c39
Add GRPO configuration and test script for Qwen2.5-Math-1.5B model wi…
RayenTian d151c31
Add 'nemotron_cascade2_sft.py' to project includes in pyrefly.toml fo…
RayenTian 73b6036
Add vllm_kwargs configuration to distillation_math.yaml for enhanced …
RayenTian f68a102
Remove max generation tokens check from Qwen2.5 test script.
RayenTian 1dce969
Remove Qwen2.5-Math-1.5B instruct test script
RayenTian 9cc6bf3
fix comments
RayenTian 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
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
32 changes: 32 additions & 0 deletions
32
examples/configs/recipes/llm/grpo-qwen2.5-1.5B-4n8g-megatron-yarn-256k.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,32 @@ | ||
| defaults: ../../grpo_math_1B_megatron.yaml | ||
| grpo: | ||
| max_num_steps: 100 | ||
| num_prompts_per_step: 2 | ||
| checkpointing: | ||
| checkpoint_dir: results/grpo-qwen2.5-1.5B-4n8g-megatron-yarn-256k | ||
| save_period: 20 | ||
| policy: | ||
| train_global_batch_size: 32 | ||
| train_micro_batch_size: 1 | ||
| max_total_sequence_length: 262144 | ||
| make_sequence_length_divisible_by: 64 | ||
| megatron_cfg: | ||
| context_parallel_size: 32 | ||
| hf_config_overrides: | ||
| rope_scaling: | ||
| rope_type: yarn | ||
| rope_theta: 1000000 | ||
| factor: ${div:${policy.max_total_sequence_length},${policy.hf_config_overrides.rope_scaling.original_max_position_embeddings}} | ||
| original_max_position_embeddings: 131072 | ||
| truncate: true | ||
| beta_fast: 32 | ||
| beta_slow: 1 | ||
| mscale: 1 | ||
| mscale_all_dim: 0 | ||
| logger: | ||
| wandb: | ||
| project: yarn | ||
| name: grpo-qwen2.5-1.5B-4n8g-megatron-yarn-256k | ||
| cluster: | ||
| gpus_per_node: 8 | ||
| num_nodes: 4 |
58 changes: 58 additions & 0 deletions
58
examples/configs/recipes/llm/sft-qwen3-0.6B-1n8g-megatron-yarn-64k.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,58 @@ | ||
| defaults: ../../sft.yaml | ||
| sft: | ||
| max_num_steps: 100 | ||
| checkpointing: | ||
| checkpoint_dir: results/sft-qwen3-0.6B-1n8g-megatron-yarn-64k | ||
| save_period: 20 | ||
| policy: | ||
| model_name: Qwen/Qwen3-0.6B | ||
| train_global_batch_size: 16 | ||
| max_total_sequence_length: 65536 | ||
| dtensor_cfg: | ||
| enabled: false | ||
| megatron_cfg: | ||
| enabled: true | ||
| context_parallel_size: 8 | ||
| distributed_data_parallel_config: | ||
| grad_reduce_in_fp32: true | ||
| optimizer: | ||
| lr: 2.0e-05 | ||
| min_lr: 2.0e-05 | ||
| weight_decay: 0.01 | ||
| adam_eps: 1.0e-08 | ||
| clip_grad: 0 | ||
| params_dtype: bfloat16 | ||
| use_precision_aware_optimizer: false | ||
| scheduler: | ||
| lr_warmup_iters: 1 | ||
| lr_warmup_init: 1.999999e-05 | ||
| sequence_packing: | ||
| enabled: true | ||
| make_sequence_length_divisible_by: 16 | ||
| optimizer: null | ||
| hf_config_overrides: | ||
| rope_scaling: | ||
| rope_type: yarn | ||
| rope_theta: 1000000 | ||
| factor: 1.6 | ||
| original_max_position_embeddings: 40960 | ||
| truncate: true | ||
| beta_fast: 32 | ||
| beta_slow: 1 | ||
| mscale: 1 | ||
| mscale_all_dim: 0 | ||
| data: | ||
| add_generation_prompt: true | ||
| train: | ||
| dataset_name: Nemotron-Cascade-2-SFT-Math | ||
| split_validation_size: 0.05 | ||
| max_samples: 100000 | ||
| validation: null | ||
| logger: | ||
| wandb: | ||
| project: yarn | ||
| name: sft-qwen3-0.6B-1n8g-megatron-yarn-64k | ||
| tensorboard: | ||
| log_dir: tb_logs-sft-qwen3-0.6B-1n8g-megatron-yarn-64k | ||
| 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
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
80 changes: 80 additions & 0 deletions
80
nemo_rl/data/datasets/response_datasets/nemotron_cascade2_sft.py
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,80 @@ | ||
| # Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from typing import Any | ||
|
|
||
| from datasets import load_dataset | ||
|
|
||
| from nemo_rl.data.datasets.raw_dataset import RawDataset | ||
|
|
||
|
|
||
| class NemotronCascade2SFTMathDataset(RawDataset): | ||
| """Simple wrapper around the Nemotron-Cascade-2-SFT-Data math split. | ||
|
|
||
| Loads the ``math`` subset of ``nvidia/Nemotron-Cascade-2-SFT-Data`` from | ||
| HuggingFace. Each example already contains a ``messages`` field in | ||
| OpenAI chat format (system / user / assistant turns), so no heavy | ||
| reformatting is needed. | ||
|
|
||
| Args: | ||
| split: HuggingFace dataset split to load, default is "train" | ||
| split_validation_size: Fraction of data held out for validation when | ||
| no dedicated validation split exists, default is 0.05 | ||
| seed: Random seed used when shuffling before selecting max_samples and | ||
| when creating the train/validation split, default is 42 | ||
| max_samples: If set, randomly sample this many examples from the | ||
| dataset before any train/validation split, default is None (use all) | ||
| """ | ||
|
|
||
| def __init__( | ||
| self, | ||
| split: str = "train", | ||
| split_validation_size: float = 0.05, | ||
| seed: int = 42, | ||
| max_samples: int | None = None, | ||
| **kwargs, | ||
| ) -> None: | ||
| self.task_name = "Nemotron-Cascade-2-SFT-Math" | ||
|
|
||
| self.dataset = load_dataset( | ||
| "nvidia/Nemotron-Cascade-2-SFT-Data", | ||
| "math", | ||
| split=split, | ||
| ) | ||
|
|
||
| if max_samples is not None and max_samples > 0: | ||
| self.dataset = self.dataset.shuffle(seed=seed).select( | ||
| range(min(max_samples, len(self.dataset))) | ||
| ) | ||
|
|
||
| self.dataset = self.dataset.map( | ||
| self.format_data, | ||
| remove_columns=self.dataset.column_names, | ||
| ) | ||
|
|
||
| self.val_dataset = None | ||
| self.split_train_validation(split_validation_size, seed) | ||
|
|
||
| def format_data(self, data: dict[str, Any]) -> dict[str, Any]: | ||
| messages = data["messages"] | ||
|
|
||
| if not messages or messages[-1]["role"] != "assistant": | ||
| raise ValueError( | ||
| f"Expected last message to be from assistant, got: {messages}" | ||
| ) | ||
|
|
||
| return { | ||
| "messages": messages, | ||
| "task_name": self.task_name, | ||
| } |
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.