|
| 1 | +# NVIDIA Nemotron 3 Nano 30B-A3B NVFP4 quantization-aware distillation (QAD) via Megatron-Bridge. |
| 2 | +# |
| 3 | +# Four tasks: tokenize the training data, PTQ the student to NVFP4, distill it against the BF16 |
| 4 | +# teacher, and export a deployable unified-HF checkpoint. |
| 5 | +# |
| 6 | +# Training topology: 8 nodes x 4 GPUs, TP=1, PP=1, CP=4, EP=16. That leaves DP=8, so a |
| 7 | +# global-batch-size of 64 at micro-batch-size 1 is 8 gradient-accumulation microbatches per step. |
| 8 | +# 200 iterations x 64 sequences x 32768 tokens = 419M training tokens. |
| 9 | +# |
| 10 | +# Requirements: |
| 11 | +# - HF_TOKEN can access the gated nvidia/Nemotron-Post-Training-Dataset-v2 dataset. |
| 12 | +# |
| 13 | +# Usage from tools/launcher: |
| 14 | +# source .env-slurm |
| 15 | +# uv run launch.py --yaml examples/nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16/mbridge_qad.yaml --yes |
| 16 | + |
| 17 | +job_name: Nemotron-3-Nano-30B-A3B_mbridge_qad_32k_200iter |
| 18 | +pipeline: |
| 19 | + note: "NVFP4 QAD at 32K for 200 iterations on Nemotron-Post-Training-Dataset-v2 chat (Megatron-Bridge)" |
| 20 | + |
| 21 | + global_vars: |
| 22 | + hf_model: nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16 |
| 23 | + data_dir: /cicd/tokenized/nemotron-post-training-v2 |
| 24 | + data_prefix: /cicd/tokenized/nemotron-post-training-v2/nvidia--Nemotron-Post-Training-Dataset-v2_default_chat_messages |
| 25 | + ptq_ckpt: /cicd/megatron-bridge/Nemotron-3-Nano-30B-A3B-NVFP4-ptq |
| 26 | + qad_dir: /cicd/megatron-bridge/Nemotron-3-Nano-30B-A3B-NVFP4-qad |
| 27 | + export_dir: /cicd/export/Nemotron-3-Nano-30B-A3B-NVFP4-qad-hf |
| 28 | + |
| 29 | + # 1) Tokenize the QAD training data into Megatron .bin/.idx, which distill.py reads via |
| 30 | + # --data_paths. megatron_lm_qad.yaml points Megatron-LM's finetune path at a single parquet |
| 31 | + # shard instead; Megatron-Bridge trains from pre-tokenized data, so the split is tokenized |
| 32 | + # once here. --hf_streaming avoids the Arrow cast errors that this dataset's nested tool-call |
| 33 | + # fields trigger in non-streaming mode. No --append_eod: these are chat rows ("messages"), |
| 34 | + # whose chat template already terminates each conversation. |
| 35 | + # CPU-bound and long-running; it needs no GPU beyond the allocation minimum. |
| 36 | + task_0: |
| 37 | + inline: >- |
| 38 | + python -m modelopt.torch.utils.plugins.megatron_preprocess_data |
| 39 | + --hf_dataset nvidia/Nemotron-Post-Training-Dataset-v2 |
| 40 | + --hf_name default |
| 41 | + --hf_split chat |
| 42 | + --hf_streaming |
| 43 | + --json_keys messages |
| 44 | + --tokenizer <<global_vars.hf_model>> |
| 45 | + --output_dir <<global_vars.data_dir>> |
| 46 | + --workers 32 |
| 47 | + --max_sequence_length 256_000 |
| 48 | + slurm_config: |
| 49 | + _factory_: "slurm_factory" |
| 50 | + container: nvcr.io/nvidia/nemo:26.06 |
| 51 | + modelopt_install_path: /opt/venv/lib/python3.12/site-packages/modelopt |
| 52 | + nodes: 1 |
| 53 | + ntasks_per_node: 1 |
| 54 | + gpus_per_node: 1 |
| 55 | + time: "08:00:00" |
| 56 | + |
| 57 | + # 2) NVFP4 PTQ. Produces the quantized Megatron checkpoint that seeds the QAD student. |
| 58 | + # TP=EP=PP=1 leaves pure DP=4, so each rank calibrates on its own shard of the samples. |
| 59 | + # --calib_dataset_name is left unset, which selects the default public text mix. |
| 60 | + task_1: |
| 61 | + environment: |
| 62 | + - LAUNCH_SCRIPT: torchrun --nproc_per_node 4 |
| 63 | + inline: >- |
| 64 | + $LAUNCH_SCRIPT modules/Model-Optimizer/examples/megatron_bridge/quantize.py |
| 65 | + --hf_model_name_or_path <<global_vars.hf_model>> |
| 66 | + --trust_remote_code |
| 67 | + --tp_size 1 |
| 68 | + --pp_size 1 |
| 69 | + --ep_size 1 |
| 70 | + --quant_cfg MAMBA_MOE_NVFP4_CONSERVATIVE_CFG |
| 71 | + --calib_batch_size 1 |
| 72 | + --calib_num_samples 1000 |
| 73 | + --seq_length 32768 |
| 74 | + --skip_generate |
| 75 | + --export_megatron_path <<global_vars.ptq_ckpt>> |
| 76 | + slurm_config: &sc |
| 77 | + _factory_: "slurm_factory" |
| 78 | + container: nvcr.io/nvidia/nemo:26.06 |
| 79 | + modelopt_install_path: /opt/venv/lib/python3.12/site-packages/modelopt |
| 80 | + nodes: 1 |
| 81 | + ntasks_per_node: 4 |
| 82 | + gpus_per_node: 4 |
| 83 | + |
| 84 | + # 3) Distill the NVFP4 student from the BF16 teacher on the tokenized chat data. |
| 85 | + task_2: |
| 86 | + environment: |
| 87 | + - LAUNCH_SCRIPT: torchrun --nproc_per_node 4 |
| 88 | + inline: >- |
| 89 | + $LAUNCH_SCRIPT modules/Model-Optimizer/examples/megatron_bridge/distill.py |
| 90 | + --teacher_hf_path <<global_vars.hf_model>> |
| 91 | + --student_hf_path <<global_vars.hf_model>> |
| 92 | + --student_megatron_path <<global_vars.ptq_ckpt>> |
| 93 | + --trust_remote_code |
| 94 | + --tp_size 1 |
| 95 | + --pp_size 1 |
| 96 | + --cp_size 4 |
| 97 | + --ep_size 16 |
| 98 | + --data_paths <<global_vars.data_prefix>> |
| 99 | + --data_path_to_cache <<global_vars.data_dir>>/cache |
| 100 | + --seq_length 32768 |
| 101 | + --mbs 1 |
| 102 | + --gbs 64 |
| 103 | + --lr 2e-5 |
| 104 | + --min_lr 5e-6 |
| 105 | + --lr_warmup_iters 30 |
| 106 | + --train_iters 200 |
| 107 | + --eval_interval 50 |
| 108 | + --eval_iters 8 |
| 109 | + --log_interval 10 |
| 110 | + --checkpoint_keep_last 2 |
| 111 | + --output_dir <<global_vars.qad_dir>> |
| 112 | + slurm_config: |
| 113 | + <<: *sc |
| 114 | + nodes: 8 |
| 115 | + |
| 116 | + # 4) Export the distilled (still quantized) checkpoint to a deployable unified-HF checkpoint. |
| 117 | + # TP must be 1 -- the HF writer does not gather TP shards -- and PP=4 splits 52 layers 13/stage. |
| 118 | + task_3: |
| 119 | + environment: |
| 120 | + - LAUNCH_SCRIPT: torchrun --nproc_per_node 4 |
| 121 | + inline: >- |
| 122 | + $LAUNCH_SCRIPT modules/Model-Optimizer/examples/megatron_bridge/export_quantized_megatron_to_hf.py |
| 123 | + --hf_model_name_or_path <<global_vars.hf_model>> |
| 124 | + --megatron_path <<global_vars.qad_dir>>/checkpoints |
| 125 | + --trust_remote_code |
| 126 | + --pp_size 4 |
| 127 | + --export_unified_hf_path <<global_vars.export_dir>> |
| 128 | + slurm_config: |
| 129 | + <<: *sc |
0 commit comments