Files
Model-Optimizer/examples/dataset
Keval MorabiaandClaude Sonnet 4.6 bb08094ff1 Add Nemotron-Nano-9B-v2 → Pruned 7B e2e tutorial: Prune + Distill + Eval + Quantize + vLLM deployment (#1325)
## Summary

End-to-end optimization walkthrough for Nemotron-Nano-9B-v2 showing how
ModelOpt techniques stack:

- **Pruning** — Minitron structured pruning 9B → 7B
- **Distillation** — Megatron-Bridge knowledge distillation up to 80B
tokens; near-parity with official 9B on MMLU Pro, GPQA, LCB, AIME, Math
500, IFEval, SciCode
- **Evaluation** - using nemo-evaluator
- **Quantization** — FP8 PTQ via \`hf_ptq.py\`; checkpoint deployable on
vLLM/TRT-LLM/SGLang with no extra flags (quantization auto-detected from
\`config.json\`)
- **vLLM Throughput** — BF16 vs FP8 benchmark on single H100

<img width="2085" height="1740" alt="image"
src="https://github.com/user-attachments/assets/8620a019-5c09-4a6b-a5d2-ca164aaa5d87"
/>

<img width="2085" height="810" alt="image"
src="https://github.com/user-attachments/assets/742c8035-f1fb-4394-b11b-0c6c3ac4e843"
/>


### Files changed

- `examples/pruning/minitron/README.md` — index page for Minitron
end-to-end tutorials
- `examples/pruning/minitron/NVIDIA-Nemotron-Nano-9B-v2/README.md` —
full repro doc with 6 sections: data prep, pruning, distillation,
evaluation, FP8 quantization, vLLM benchmarking
-
`examples/pruning/minitron/NVIDIA-Nemotron-Nano-9B-v2/nemo_evaluator.yaml`
— NeMo Evaluator config used for all benchmark numbers
- `examples/pruning/puzzletron/README.md` — index page for Puzzletron
distillation results
- `examples/pruning/puzzletron/Llama-3.1-8B-Instruct.md` — Puzzletron
distillation results (renamed from puzzletron.md)
- `examples/pruning/README.md` — updated Results section with direct
links to new locations
- `examples/megatron_bridge/README.md` — updated results link to point
to `examples/pruning/`
- `examples/puzzletron/README.md` — updated distillation results link
- `examples/dataset/MEGATRON_DATA_PREP.md` — tokenization commands for
all datasets used in the data blend

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

## Documentation

* **New end-to-end tutorial** for model optimization covering Minitron
pruning, knowledge distillation, FP8 quantization, and vLLM deployment
with reproducibility steps and benchmark results
* **Dataset preparation guide** with ready-to-run tokenization templates
for Nemotron HuggingFace datasets
* **Evaluation configuration** and results documentation including
ablation studies across multiple benchmarks
* **Updated navigation** across pruning, distillation, and dataset
examples to streamline user workflows

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Keval Morabia <28916987+kevalmorabia97@users.noreply.github.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-30 14:47:16 +05:30
..

Dataset Preparation

Section Description Link
Building Chat Datasets Scripts to build conversation datasets from Nemotron and other HuggingFace sources [Link]
Tokenizing for Megatron Frameworks Convert JSONL or HF datasets to Megatron binary format for distillation and pre-training [Link]

Building Chat Datasets

Utilities for building conversation datasets from NVIDIA Nemotron Post-Training collections and other HuggingFace sources. These scripts produce datasets in standard OpenAI chat format ({"messages": [{"role": ..., "content": ...}]}) and can be used for any downstream fine-tuning task — SFT, distillation, speculative decoding draft-model training, etc.

Files

File Description
make_nemotron_ptv3_dataset.py Build a dataset from the Nemotron PT v3 collection using a configurable YAML mix
make_nemotron_ptv2_dataset.py Build a dataset from Nemotron-Post-Training-Dataset-v2
make_dataset.py General-purpose mixer for arbitrary HuggingFace datasets (mtbench, sharegpt, ultrachat, magpie, etc.)
conversation_utils.py Shared utilities: augmentation, role normalization, assistant-turn stripping
add_nemotron_chat.py Add Nemotron v2 chat conversations to an existing dataset
augmentations.yaml Augmentation variants (language redirects, style hints) for make_nemotron_pt*.py
nemotron_ptv3_datasets.yaml Dataset mix config for make_nemotron_ptv3_dataset.py
example_data_config.yaml Example YAML config for make_dataset.py

Quick Start

Install dependencies

pip install nvidia-modelopt[hf]
hf auth login --token <your token> # required for gated datasets

Build a Nemotron PT v3 dataset

# Synthetic data generation inputs (strips last assistant turn so a model can regenerate it)
python make_nemotron_ptv3_dataset.py --output-dir /tmp/ptv3_gen

# Full conversations for direct SFT training
python make_nemotron_ptv3_dataset.py --mode train --output-dir /tmp/ptv3_train

# Use a custom dataset mix
python make_nemotron_ptv3_dataset.py --config my_mix.yaml --output-dir /tmp/ptv3_custom

Build a Nemotron PT v2 dataset

python make_nemotron_ptv2_dataset.py --output-dir /tmp/ptv2_gen
python make_nemotron_ptv2_dataset.py --mode train --output-dir /tmp/ptv2_train

Build a general-purpose mixed dataset

python make_dataset.py --config example_data_config.yaml --output-dir /tmp/mixed

Dataset Modes

Both make_nemotron_pt*.py scripts support two modes:

Mode Description Use case
generate (default) Strips assistant turns, optionally augments prompts Input data for synthetic generation (query a target model to produce training responses)
train Keeps all turns, normalizes to clean OpenAI format Direct SFT / distillation training

Synthetic Generation Pipeline

The generate mode produces conversation skeletons that are fed to a target model via tools/launcher/common/query.py (vLLM or TRT-LLM). The output becomes training data for a draft model (e.g. EAGLE3 speculative decoding) or a distilled student:

make_nemotron_ptv3_dataset.py --mode generate  →  skeleton.jsonl
        ↓
query.py  (target model generates responses turn-by-turn)
        ↓
training data for draft model / student

Augmentations

augmentations.yaml defines language-redirect and style-hint variants that are applied cyclically across the dataset. Each enabled entry produces one augmented copy of the source rows.

To customize augmentations:

  • Disable a variant: add enabled: false
  • Add a language redirect: append a user_suffix entry
  • Add a system prompt: append a system_prompt entry
augmentations:
  - type: user_suffix
    text: " Please reply in French instead of English."
  - type: system_prompt
    content: "You are a helpful assistant."
    enabled: false   # disable without deleting

Dataset Mix Config (nemotron_ptv3_datasets.yaml)

Edit this file to add, remove, or re-weight datasets without touching the script:

datasets:
  - repo_id: nvidia/Nemotron-Math-v2
    splits: [high_part00, high_part01]
    cap_per_split: 200000
    augment: true

  - repo_id: nvidia/OpenMathReasoning-mini
    splits: [train]
    augment: false   # multilingual — skip language-redirect augmentation

Output Format

Every output row is a JSONL object with a single messages key:

{"messages": [
  {"role": "system",    "content": "You are a helpful assistant."},
  {"role": "user",      "content": "What is 2+2?"},
  {"role": "assistant", "content": "4"}
]}

In generate mode, assistant turns are stripped so the row ends with a user turn.

Tokenizing for Megatron Frameworks

See MEGATRON_DATA_PREP.md for full documentation: general usage with JSONL and Hugging Face Hub datasets, handling of Nemotron Post-Training v3 reasoning_content fields, and ready-to-run tokenization commands for all Nemotron Pre/Post-Training datasets.

Synthetic Test Dataset

synthetic_conversations_1k.jsonl is a 1,000-sample dataset in OpenAI messages format (900 single-turn + 100 two-turn conversations) covering writing, reasoning, math, coding, STEM, extraction, humanities, and roleplay categories.

This dataset was synthesized by Claude (Anthropic) and is licensed under Apache-2.0. It is intended for testing and CI regression — not for production training.

{"messages": [{"role": "user", "content": "..."}, {"role": "assistant", "content": "..."}]}