-
Notifications
You must be signed in to change notification settings - Fork 356
feat: Use openmathinstruct2 training in grpo math example #18
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
11 commits
Select commit
Hold shift + click to select a range
43b5e82
feat: Use openmathinstruct2 training in grpo math example
parthchadha 240c48d
Fix warning message
parthchadha 79e90b0
feat: lots of fixes (#17)
terrykong 0d37758
feat: Configurable precision (#19)
SahilJain314 2e7b4fc
ci: OPTIONAL -> IS_OPTIONAL (#22)
terrykong f8947c3
feat: disable ray usage collection stats be default (#24)
terrykong cc6cfcb
docs: refresh our PR template (#23)
terrykong 2432bbf
docs: micro doc update with a helpful reminder on environment variabl…
SahilJain314 2d0f943
Update readme; add dataset key to config
parthchadha e40d315
Merge remote-tracking branch 'origin/main' into pchadha/openmathinstr…
parthchadha 23c0008
Merge remote-tracking branch 'origin/main' into pchadha/openmathinstr…
parthchadha 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,4 +36,4 @@ policy: | |
|
|
||
| cluster: | ||
| gpus_per_node: 8 | ||
| num_nodes: 1 | ||
| 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
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,87 @@ | ||
| # 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 Optional | ||
| from datasets import load_dataset | ||
| from nemo_reinforcer.data.hf_datasets.interfaces import HfDataset | ||
| from dataclasses import dataclass | ||
|
|
||
|
|
||
| def format_math(data): | ||
| return { | ||
| "messages": [ | ||
| { | ||
| "role": "user", | ||
| "content": data["problem"], | ||
| }, | ||
| { | ||
| "role": "assistant", | ||
| "content": data["expected_answer"], | ||
| }, | ||
| ], | ||
| # For v0.1 release, reinforcer datasets require a task_name key such that user can map a task processor per unique task. | ||
| "task_name": "math", | ||
| } | ||
|
|
||
|
|
||
| def prepare_openinstructmath2_dataset(split: str = "train_1M", seed=42, test_size=0.05): | ||
| """Load and split the OpenMathInstruct-2 dataset into train and validation sets using HF's train_test_split.""" | ||
| print( | ||
| f"WARNING: For reproducible experiments, preprocess the dataset once and define your own HfDataset subclass that directly uses the preprocessed datasets." | ||
| ) | ||
|
|
||
| # Load the original dataset | ||
| original_ds = load_dataset("nvidia/OpenMathInstruct-2", split=split) | ||
|
|
||
| # Split into train and validation sets using HF's train_test_split | ||
| split_ds = original_ds.train_test_split(test_size=test_size, seed=seed) | ||
|
|
||
| # Format the examples, removing original columns | ||
| train_formatted = split_ds["train"].map( | ||
| format_math, remove_columns=split_ds["train"].column_names | ||
| ) | ||
| val_formatted = split_ds["test"].map( | ||
| format_math, remove_columns=split_ds["test"].column_names | ||
| ) | ||
|
|
||
| return { | ||
| "train": train_formatted, | ||
| "validation": val_formatted, | ||
| } | ||
|
|
||
|
|
||
| @dataclass | ||
| class OpenMathInstruct2Dataset(HfDataset): | ||
| def __init__( | ||
| self, split: str = "train_1M", seed: int = 42, test_size: float = 0.05 | ||
| ): | ||
| """Initialize the OpenMathInstruct2 dataset with train/validation split. | ||
|
|
||
| Args: | ||
| seed: Random seed for reproducible splitting | ||
| test_size: Proportion of data to use for validation (0.0-1.0) | ||
| """ | ||
| # train, train_1M, train_2M, and train_5M are supported splits. | ||
| if split not in ["train", "train_1M", "train_2M", "train_5M"]: | ||
| raise ValueError( | ||
| f"Invalid split: {split}. Please use 'train', 'train_1M', 'train_2M', or 'train_5M'." | ||
| ) | ||
|
|
||
| self.formatted_ds = prepare_openinstructmath2_dataset( | ||
| split=split, seed=seed, test_size=test_size | ||
| ) | ||
|
|
||
| super().__init__( | ||
| dataset_name="OpenMathInstruct-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.