Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
37076aa
split AllTaskProcessedDataset, assert_no_double_bos, collate_fn to di…
yuki-97 Sep 1, 2025
d2c9688
move chat_templates.py
yuki-97 Sep 1, 2025
7cff2c5
move pil_to_base64 to utils
yuki-97 Sep 1, 2025
f943179
move eval datasets and remove data_path in config
yuki-97 Sep 1, 2025
caf2cc0
refactor and move response datasets
yuki-97 Sep 1, 2025
0c9f8d7
refactor and move preference datasets
yuki-97 Sep 1, 2025
454a68c
unify ResponseDataset and PreferenceDataset
yuki-97 Sep 1, 2025
6701dbd
merge and fix unit test
yuki-97 Sep 1, 2025
abc4394
fix pyrefly and cleanup
yuki-97 Sep 2, 2025
b7b9581
update doc
yuki-97 Sep 2, 2025
41d1566
fix doc path
yuki-97 Sep 2, 2025
edbf1ba
support from hf
yuki-97 Sep 2, 2025
2ba1edf
fix split key
yuki-97 Sep 2, 2025
2aa48f8
update unit test
yuki-97 Sep 2, 2025
5f108bf
fix train docs
yuki-97 Sep 3, 2025
f4e9814
merge aime
yuki-97 Sep 3, 2025
f962fa8
lint
yuki-97 Sep 3, 2025
e36dc08
split out BinaryPreferenceDataset
yuki-97 Sep 6, 2025
3e3e34c
update doc for BinaryPreferenceDataset
yuki-97 Sep 6, 2025
f2fed5b
lint
yuki-97 Sep 6, 2025
27d3416
update val_split and doc
yuki-97 Sep 10, 2025
42709e7
remove escape
yuki-97 Sep 10, 2025
055e21f
update doc
yuki-97 Sep 10, 2025
fee86cd
address coderabbit
yuki-97 Sep 10, 2025
6c18352
not use chosen-reject and rank
yuki-97 Sep 10, 2025
ff76668
update preference_dataset_type
yuki-97 Sep 10, 2025
e849ddc
remove dataset_type and detect by dataset_name
yuki-97 Sep 10, 2025
34adde2
fix test
yuki-97 Sep 10, 2025
cf56280
fix comment
yuki-97 Sep 10, 2025
2b2460c
train_split default to None and add comments
yuki-97 Sep 13, 2025
0ad77b9
address coderabbit
yuki-97 Sep 13, 2025
45a65af
address coderabbit, remove duplicated
yuki-97 Sep 13, 2025
726ca21
unify Hugging Face to HuggingFace
yuki-97 Sep 16, 2025
e46ed66
add comments for PathToTrainingDataset
yuki-97 Sep 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions docs/guides/dpo.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,31 +91,38 @@ DPO training supports only two completions (where the lowest rank is preferred a
}
```

NeMo RL provides a DPO-compatible implementation of the [HelpSteer3](https://github.com/NVIDIA-NeMo/RL/blob/main/nemo_rl/data/hf_datasets/helpsteer3.py) dataset as an example. This dataset is downloaded from Hugging Face and preprocessed on-the-fly, so there's no need to provide a path to any datasets on disk.
Comment thread
yuki-97 marked this conversation as resolved.
Resolved
By default, NeMo RL has support for [HelpSteer3](../../nemo_rl/data/datasets/preference_datasets/helpsteer3.py) and [Tulu3Preference](../../nemo_rl/data/datasets/preference_datasets/tulu3.py) datasets. Both of these datasets are downloaded from HuggingFace and preprocessed on-the-fly, so there's no need to provide a path to any datasets on disk.

We also provide a [PreferenceDataset](../../nemo_rl/data/hf_datasets/preference_dataset.py) class that is compatible with JSONL-formatted preference datasets. You can modify your config as follows to use such a custom preference dataset:
We provide a [PreferenceDataset](../../nemo_rl/data/datasets/preference_datasets/preference_dataset.py) class that is compatible with jsonl-formatted preference datasets for loading datasets from local path or HuggingFace. You can modify your config as follows to use such a custom preference dataset:
```yaml
data:
dataset_name: PreferenceDataset
train_data_path: <LocalPathToTrainingDataset>
train_data_path: <PathToTrainingDataset> # e.g., /path/to/local/dataset.jsonl or hf_org/hf_dataset_name (HuggingFace)
# multiple validation sets is supported
val_data_paths:
<NameOfValidationDataset>: <LocalPathToValidationDataset>
<NameOfValidationDataset>: <PathToValidationDataset1>
<NameOfValidationDataset2>: <PathToValidationDataset2>
train_split: <TrainSplit>, default is None # used for HuggingFace datasets
val_split: <ValSplit>, default is None # used for HuggingFace datasets
```
with support for multiple validation sets achieved with:

We also provide a [BinaryPreferenceDataset](../../nemo_rl/data/datasets/preference_datasets/binary_preference_dataset.py) class, which is a simplified version of PreferenceDataset for pairwise ranked preference with single turn completions. You can use `prompt_key`, `chosen_key` and `rejected_key` to specify which fields in your data correspond to the question, chosen answer and rejected answer respectively. Here's an example configuration:
```yaml
data:
dataset_name: PreferenceDataset
train_data_path: <LocalPathToTrainingDataset>
val_data_paths:
<NameOfValidationDataset1>: <LocalPathToValidationDataset1>
<NameOfValidationDataset2>: <LocalPathToValidationDataset2>
dataset_name: BinaryPreferenceDataset
train_data_path: <PathToTrainingDataset> # e.g., /path/to/local/dataset.jsonl or hf_org/hf_dataset_name (HuggingFace)
val_data_path: <PathToValidationDataset>
prompt_key: <PromptKey>, default is "prompt"
chosen_key: <ChosenKey>, default is "chosen"
rejected_key: <RejectedKey>, default is "rejected"
train_split: <TrainSplit>, default is None # used for HuggingFace datasets
val_split: <ValSplit>, default is None # used for HuggingFace datasets
```

Please note:
- If you are using a logger, the prefix used for each validation set will be `validation-<NameOfValidationDataset>`. The total validation time, summed across all validation sets, is reported under `timing/validation/total_validation_time`.
- If you are doing checkpointing, the `metric_name` value in your `checkpointing` config should reflect the metric and validation set to be tracked. For example, `validation-<NameOfValidationDataset1>_loss`.

The older [DPODataset](../../nemo_rl/data/hf_datasets/dpo.py) class is deprecated. This class is also compatible with JSONL-formatted preference datsets. It assumes train and validation datasets have been split and processed into the expected format offline. The JSONL files should consist of examples with `prompt`, `chosen_response`, and `rejected_response` keys.
Comment thread
yuki-97 marked this conversation as resolved.
Resolved

## DPO-Specific Parameters

The DPO implementation in NeMo RL supports several key parameters that can be adjusted:
Expand Down
22 changes: 10 additions & 12 deletions docs/guides/eval.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ This document explains how to use an evaluation script for assessing model capab

## Prepare for Evaluation

To prepare for evaluation, first ensure your model is in the correct format, which may involve an optional conversion of PyTorch DCP checkpoints to the Hugging Face format. Following this, you need to prepare the evaluation configuration, which includes defining prompt templates and any custom settings required to run the evaluation.
To prepare for evaluation, first ensure your model is in the correct format, which may involve an optional conversion of PyTorch DCP checkpoints to the HuggingFace format. Following this, you need to prepare the evaluation configuration, which includes defining prompt templates and any custom settings required to run the evaluation.

### Convert DCP to HF (Optional)
If you have trained a model and saved the checkpoint in the Pytorch DCP format, you first need to convert it to the Hugging Face format before running evaluation.
If you have trained a model and saved the checkpoint in the Pytorch DCP format, you first need to convert it to the HuggingFace format before running evaluation.

Use the `examples/converters/convert_dcp_to_hf.py` script. You'll need the path to the training configuration file (`config.yaml`), the DCP checkpoint directory, and specify an output path for the HF format model.

Expand Down Expand Up @@ -37,9 +37,9 @@ For open-source models, we recommend setting `tokenizer.chat_template=default`,

## Run the Evaluation Script

We will use the `run_eval.py` script to run an evaluation using a model directly from the Hugging Face Hub or from a local path that is already in Hugging Face format.
We will use the `run_eval.py` script to run an evaluation using a model directly from the HuggingFace Hub or from a local path that is already in HuggingFace format.

Note that the evaluation script only supports the Hugging Face format model. If you haven't converted your DCP format model, you should back to [Convert DCP to HF](#convert-dcp-to-hf-optional) and follow the guide to convert your model.
Note that the evaluation script only supports the HuggingFace format model. If you haven't converted your DCP format model, you should back to [Convert DCP to HF](#convert-dcp-to-hf-optional) and follow the guide to convert your model.

```sh
# Run evaluation script with default config (examples/configs/evals/eval.yaml)
Expand Down Expand Up @@ -89,12 +89,10 @@ score=0.1000 (3.0/30)

## List of currently supported benchmarks

- [AIME-2024](../../nemo_rl/data/eval_datasets/aime2024.py): the corresponding `data.dataset_name` is `"aime2024"`.
- [AIME-2025](../../nemo_rl/data/eval_datasets/aime2025.py): the corresponding `data.dataset_name` is `"aime2025"`.
- [GPQA and GPQA-diamond](../../nemo_rl/data/eval_datasets/gpqa.py): the corresponding `data.dataset_name` are `"gpqa"` and `"gpqa-diamond"`.
- [MATH and MATH-500](../../nemo_rl/data/eval_datasets/math.py): the corresponding `data.dataset_name` are `"math"` and `"math500"`.
- [MMLU](../../nemo_rl/data/eval_datasets/mmlu.py): this also includes MMMLU (Multilingual MMLU), a total of 14 languages. When `data.dataset_name` is set to `mmlu`, the English version is used. If one wants to run evaluation on another language, `data.dataset_name` should be set to `mmlu_{language}` where `language` is one of following 14 values, `["AR-XY", "BN-BD", "DE-DE", "ES-LA", "FR-FR", "HI-IN", "ID-ID", "IT-IT", "JA-JP", "KO-KR", "PT-BR", "ZH-CN", "SW-KE", "YO-NG"]`.
- [MMLU-Pro](../../nemo_rl/data/eval_datasets/mmlu_pro.py): the corresponding `data.dataset_name` is `"mmlu_pro"`.

More details can be found in [load_eval_dataset](../../nemo_rl/data/eval_datasets/__init__.py).
- [AIME-2024 and AIME-2025](../../nemo_rl/data/datasets/eval_datasets/aime.py): the corresponding `data.dataset_name` are `"aime2024"` and `"aime2025"`.
- [GPQA and GPQA-diamond](../../nemo_rl/data/datasets/eval_datasets/gpqa.py): the corresponding `data.dataset_name` are `"gpqa"` and `"gpqa_diamond"`.
- [MATH and MATH-500](../../nemo_rl/data/datasets/eval_datasets/math.py): the corresponding `data.dataset_name` are `"math"` and `"math500"`.
- [MMLU](../../nemo_rl/data/datasets/eval_datasets/mmlu.py): this also includes MMMLU (Multilingual MMLU), a total of 14 languages. When `data.dataset_name` is set to `mmlu`, the English version is used. If one wants to run evaluation on another language, `data.dataset_name` should be set to `mmlu_{language}` where `language` is one of following 14 values, `["AR-XY", "BN-BD", "DE-DE", "ES-LA", "FR-FR", "HI-IN", "ID-ID", "IT-IT", "JA-JP", "KO-KR", "PT-BR", "ZH-CN", "SW-KE", "YO-NG"]`.
- [MMLU-Pro](../../nemo_rl/data/datasets/eval_datasets/mmlu_pro.py): the corresponding `data.dataset_name` is `"mmlu_pro"`.

More details can be found in [load_eval_dataset](../../nemo_rl/data/datasets/eval_datasets/__init__.py).
16 changes: 16 additions & 0 deletions docs/guides/grpo.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ To support this, we need to know:
* Which data should go to which environments
* How to prepare the data from your dataset into a form we can use

#### Dataset

By default, NeMo RL has support for [OpenMathInstruct-2](../../nemo_rl/data/datasets/response_datasets/openmathinstruct2.py) and [DeepScaler](../../nemo_rl/data/datasets/response_datasets/deepscaler.py) datasets. Both of these datasets are downloaded from HuggingFace and preprocessed on-the-fly, so there's no need to provide a path to any datasets on disk.

We provide a [ResponseDataset](../../nemo_rl/data/datasets/response_datasets/response_dataset.py) class that is compatible with jsonl-formatted response datasets for loading datasets from local path or HuggingFace. You can use `input_key`, `output_key` to specify which fields in your data correspond to the question and answer respectively. Here's an example configuration:
```yaml
data:
dataset_name: ResponseDataset
train_data_path: <PathToTrainingDataset> # e.g., /path/to/local/dataset.jsonl or hf_org/hf_dataset_name (HuggingFace)
val_data_path: <PathToValidationDataset>
input_key: <QuestionKey>, default is "input"
output_key: <AnswerKey>, default is "output"
train_split: <TrainSplit>, default is None # used for HuggingFace datasets
val_split: <ValSplit>, default is None # used for HuggingFace datasets
```

#### Common Data Format

We define a [DatumSpec](../../nemo_rl/data/interfaces.py) that holds all relevant information for each training example:
Expand Down
31 changes: 20 additions & 11 deletions docs/guides/rm.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,25 +80,34 @@ Currently, RM training supports only two completions (where the lowest rank is p
}
```

NeMo RL provides a RM-compatible implementation of the [HelpSteer3](https://github.com/NVIDIA-NeMo/RL/blob/main/nemo_rl/data/hf_datasets/helpsteer3.py) dataset as an example. This dataset is downloaded from Hugging Face and preprocessed on-the-fly, so there's no need to provide a path to any datasets on disk.
By default, NeMo RL has support for [HelpSteer3](../../nemo_rl/data/datasets/preference_datasets/helpsteer3.py) and [Tulu3Preference](../../nemo_rl/data/datasets/preference_datasets/tulu3.py) datasets. Both of these datasets are downloaded from HuggingFace and preprocessed on-the-fly, so there's no need to provide a path to any datasets on disk.

We also provide a [PreferenceDataset](../../nemo_rl/data/hf_datasets/preference_dataset.py) class that is compatible with JSONL-formatted preference datasets. You can modify your config as follows to use such a custom preference dataset:
We provide a [PreferenceDataset](../../nemo_rl/data/datasets/preference_datasets/preference_dataset.py) class that is compatible with jsonl-formatted preference datasets for loading datasets from local path or HuggingFace.. You can modify your config as follows to use such a custom preference dataset:
```yaml
data:
dataset_name: PreferenceDataset
train_data_path: <LocalPathToTrainingDataset>
train_data_path: <PathToTrainingDataset> # e.g., /path/to/local/dataset.jsonl or hf_org/hf_dataset_name (HuggingFace)
# multiple validation sets is supported
val_data_paths:
<NameOfValidationDataset>: <LocalPathToValidationDataset>
<NameOfValidationDataset>: <PathToValidationDataset1>
<NameOfValidationDataset2>: <PathToValidationDataset2>
train_split: <TrainSplit>, default is None # used for HuggingFace datasets
val_split: <ValSplit>, default is None # used for HuggingFace datasets
```
with support for multiple validation sets achieved with:

We also provide a [BinaryPreferenceDataset](../../nemo_rl/data/datasets/preference_datasets/binary_preference_dataset.py) class, which is a simplified version of PreferenceDataset for pairwise ranked preference with single turn completions. You can use `prompt_key`, `chosen_key` and `rejected_key` to specify which fields in your data correspond to the question, chosen answer and rejected answer respectively. Here's an example configuration:
```yaml
data:
dataset_name: PreferenceDataset
train_data_path: <LocalPathToTrainingDataset>
val_data_paths:
<NameOfValidationDataset1>: <LocalPathToValidationDataset1>
<NameOfValidationDataset2>: <LocalPathToValidationDataset2>
dataset_name: BinaryPreferenceDataset
train_data_path: <PathToTrainingDataset> # e.g., /path/to/local/dataset.jsonl or hf_org/hf_dataset_name (HuggingFace)
val_data_path: <PathToValidationDataset>
prompt_key: <PromptKey>, default is "prompt"
chosen_key: <ChosenKey>, default is "chosen"
rejected_key: <RejectedKey>, default is "rejected"
train_split: <TrainSplit>, default is None # used for HuggingFace datasets
val_split: <ValSplit>, default is None # used for HuggingFace datasets
```

Please note:
- If you are using a logger, the prefix used for each validation set will be `validation-<NameOfValidationDataset>`. The total validation time, summed across all validation sets, is reported under `timing/validation/total_validation_time`.
- If you are doing checkpointing, the `metric_name` value in your `checkpointing` config should reflect the metric and validation set to be tracked. For example, `validation-<NameOfValidationDataset1>_loss`.
- If you are doing checkpointing, the `metric_name` value in your `checkpointing` config should reflect the metric and validation set to be tracked. For example, `validation-<NameOfValidationDataset1>_loss`.
19 changes: 15 additions & 4 deletions docs/guides/sft.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ SFT datasets in NeMo RL are encapsulated using classes. Each SFT data class is e
1. `formatted_ds`: The dictionary of formatted datasets. This dictionary should contain `train` and `validation` splits, and each split should conform to the format described below.
2. `task_spec`: The `TaskDataSpec` for this dataset. This should specify the name you choose for this dataset.

SFT datasets are expected to follow the Hugging Face chat format. Refer to the [chat dataset document](../design-docs/chat-datasets.md) for details. If your data is not in the correct format, simply write a preprocessing script to convert the data into this format. [data/hf_datasets/squad.py](../../nemo_rl/data/hf_datasets/squad.py) has an example:
SFT datasets are expected to follow the HuggingFace chat format. Refer to the [chat dataset document](../design-docs/chat-datasets.md) for details. If your data is not in the correct format, simply write a preprocessing script to convert the data into this format. [response_datasets/squad.py](../../nemo_rl/data/datasets/response_datasets/squad.py) has an example:

```python
def format_squad(data):
Expand All @@ -56,7 +56,7 @@ def format_squad(data):
}
```

NeMo RL SFT uses Hugging Face chat templates to format the individual examples. Three types of chat templates are supported, which can be configured via `tokenizer.chat_template` in your yaml config (see [sft.yaml](../../examples/configs/sft.yaml) for an example):
NeMo RL SFT uses HuggingFace chat templates to format the individual examples. Three types of chat templates are supported, which can be configured via `tokenizer.chat_template` in your yaml config (see [sft.yaml](../../examples/configs/sft.yaml) for an example):

1. Apply the tokenizer's default chat template. To use the tokenizer's default, either omit `tokenizer.chat_template` from the config altogether, or set `tokenizer.chat_template="default"`.
2. Use a "passthrough" template which simply concatenates all messages. This is desirable if the chat template has been applied to your dataset as an offline preprocessing step. In this case, you should set `tokenizer.chat_template` to None as follows:
Expand All @@ -71,8 +71,19 @@ NeMo RL SFT uses Hugging Face chat templates to format the individual examples.
custom_template: "{% for message in messages %}{%- if message['role'] == 'system' %}{{'Context: ' + message['content'].strip()}}{%- elif message['role'] == 'user' %}{{' Question: ' + message['content'].strip() + ' Answer: '}}{%- elif message['role'] == 'assistant' %}{{message['content'].strip()}}{%- endif %}{% endfor %}"
```


By default, NeMo RL has support for `Squad` and `OpenAssistant` datasets. Both of these datasets are downloaded from Hugging Face and preprocessed on-the-fly, so there's no need to provide a path to any datasets on disk.
By default, NeMo RL has support for [OpenAssistant](../../nemo_rl/data/datasets/response_datasets/oasst.py), [Squad](../../nemo_rl/data/datasets/response_datasets/squad.py) and [OpenMathInstruct-2](../../nemo_rl/data/datasets/response_datasets/openmathinstruct2.py) datasets. All of these datasets are downloaded from HuggingFace and preprocessed on-the-fly, so there's no need to provide a path to any datasets on disk.

We provide a [ResponseDataset](../../nemo_rl/data/datasets/response_datasets/response_dataset.py) class that is compatible with jsonl-formatted response datasets for loading datasets from local path or HuggingFace. You can use `input_key`, `output_key` to specify which fields in your data correspond to the question and answer respectively. Here's an example configuration:
```yaml
data:
dataset_name: ResponseDataset
train_data_path: <PathToTrainingDataset> # e.g., /path/to/local/dataset.jsonl or hf_org/hf_dataset_name (HuggingFace)
val_data_path: <PathToValidationDataset>
input_key: <QuestionKey>, default is "input"
output_key: <AnswerKey>, default is "output"
train_split: <TrainSplit>, default is None # used for HuggingFace datasets
val_split: <ValSplit>, default is None # used for HuggingFace datasets
```

Adding a new dataset is a straightforward process.
As long as your custom dataset has the `formatted_ds` and `task_spec` attributes described above, it can serve as a drop-in replacement for Squad and OpenAssistant.
Expand Down
Loading
Loading