|
| 1 | +--- |
| 2 | +name: qad |
| 3 | +description: >- |
| 4 | + Run explicitly requested ModelOpt Quantization-Aware Distillation (QAD) on |
| 5 | + Slurm through Megatron Bridge to recover a measured BF16-to-PTQ accuracy gap. |
| 6 | + Use only when the user explicitly asks for QAD, including its topology, data |
| 7 | + preparation, Slurm launch, resume, checkpoint export, or recovery decisions. |
| 8 | +--- |
| 9 | + |
| 10 | +# ModelOpt Quantization-Aware Distillation |
| 11 | + |
| 12 | +QAD is expensive. Run it only when the user explicitly authorizes QAD for the |
| 13 | +target model or run. A Day-0, PTQ, evaluation, comparison, or recipe-search |
| 14 | +request alone is not authorization to start QAD. |
| 15 | + |
| 16 | +## Follow the supported workflow |
| 17 | + |
| 18 | +Before constructing commands, read: |
| 19 | + |
| 20 | +- `examples/megatron_bridge/README.md`, especially PTQ, data preparation, QAD, |
| 21 | + export, and Slurm usage |
| 22 | +- `examples/megatron_bridge/{quantize.py,distill.py}` via `--help` |
| 23 | +- `skills/common/{environment-setup,workspace-management,slurm-setup}.md`; also |
| 24 | + `skills/common/remote-execution.md` for remote Slurm |
| 25 | + |
| 26 | +Treat the example README and `--help` output as authoritative for mutable flags, |
| 27 | +commands, containers, and checkpoint formats. This skill supports Slurm only. |
| 28 | + |
| 29 | +## Execute in this order |
| 30 | + |
| 31 | +1. **Confirm the gap.** Reuse only validated, comparable BF16/PTQ results and |
| 32 | + the exact benchmark configuration from preceding evaluation or recipe |
| 33 | + search; run missing, invalid, or non-comparable baselines. Confirm the target |
| 34 | + benchmarks and their context-length needs. Stop if the PTQ gap to BF16 is |
| 35 | + already below 1%. |
| 36 | +2. **Reproduce PTQ and verify compatibility.** In the target runtime, require |
| 37 | + `AutoBridge.can_handle()` for the target model and PTQ through `quantize.py` |
| 38 | + to succeed while preserving the exact preceding PTQ config or recipe: |
| 39 | + format, layer selection, calibration data/count, sequence length, and seed. |
| 40 | + A changed quantization setting is a new PTQ candidate and must be evaluated |
| 41 | + before QAD. In the master-rank `.quant_summary.txt`, require finite positive |
| 42 | + `amax` for enabled static quantizers; accept `dynamic`/format-defined `None` |
| 43 | + only when the recipe intends it. Treat the summary as rank-local under model |
| 44 | + parallelism. |
| 45 | +3. **Choose topology explicitly.** Derive the smallest fitting node count and |
| 46 | + TP/PP/CP/EP from student and teacher architecture, the chosen sequence length, |
| 47 | + and available GPU memory. Prefer CP before TP for small long-context models; |
| 48 | + keep EP=1 for dense models and ETP=1 because the current `distill.py` |
| 49 | + workflow does not support expert tensor parallelism. For MoE require: |
| 50 | + |
| 51 | + - `DP = world_size / (TP * PP * CP)` |
| 52 | + - `EDP = world_size / (EP * PP)` |
| 53 | + - integral DP/EDP, `num_experts % EP == 0`, and |
| 54 | + `GBS % (MBS * DP) == 0` |
| 55 | + |
| 56 | +4. **Prepare the full capped dataset once.** Use suitable user-provided data, or |
| 57 | + copy `examples/megatron_bridge/data/nemotron-cascade-2-blend.yaml` as the |
| 58 | + default. Set the target tokenizer and workspace path, then materialize the |
| 59 | + randomly sampled subset before training. Pack the chosen sequence length; |
| 60 | + Megatron's `99,1,0` split creates the 1% validation holdout from the same |
| 61 | + data. |
| 62 | +5. **Run and monitor QAD.** Run one QAD training job at a time and fold startup |
| 63 | + validation into it; do not submit separate GPU preflight jobs or split at |
| 64 | + recovery iterations. Let training continue while evaluating saved |
| 65 | + checkpoints, and cancel it when a stop condition below is met. |
| 66 | + |
| 67 | +## Default training policy |
| 68 | + |
| 69 | +| Setting | Default | |
| 70 | +| --- | --- | |
| 71 | +| Sequence length | 32768; adjust for target benchmarks | |
| 72 | +| Peak / minimum LR | `1e-5` / `1e-6` | |
| 73 | +| LR schedule | cosine | |
| 74 | +| Training cap | 1000 iterations | |
| 75 | +| Global batch size | 512 | |
| 76 | +| Dataset | `nvidia/Nemotron-Cascade-2-SFT-Data` by default | |
| 77 | +| Materialized token budget | 17.3B at 32K; cover the full cap at the chosen length | |
| 78 | +| Training validation | every 25 iterations; deterministic 1% holdout; 2 batches | |
| 79 | +| Checkpoint interval | 50 iterations | |
| 80 | +| Loss logging | every 10 iterations | |
| 81 | +| Recovery benchmark | 150, then every 100 iterations while training runs | |
| 82 | +| Slurm duration exit | 220 minutes for a 4-hour allocation | |
| 83 | + |
| 84 | +## Run policy |
| 85 | + |
| 86 | +- Keep `train_iters=1000` and leave `exit_interval` unset. |
| 87 | +- From initial step timing, submit only enough sequential jobs to reach |
| 88 | + checkpoint 150; never submit through iteration 1000 upfront. At each recovery |
| 89 | + checkpoint, submit to the next only after its targeted evaluation and any |
| 90 | + triggered full suite, and only if the BF16 gap remains at least 1% and |
| 91 | + recovery has neither plateaued nor regressed. |
| 92 | +- Give all training jobs the same run-specific job name and |
| 93 | + `--dependency=singleton`; record job IDs and, on any stop, cancel pending jobs |
| 94 | + before the active job. |
| 95 | +- Cancel on non-finite loss, repeated skipped iterations, or a sustained spike. |
| 96 | + At iteration 50, require the loss aggregate to be lower than at iteration 10. |
| 97 | +- At each recovery checkpoint, first evaluate the one to three benchmarks with |
| 98 | + the largest PTQ drops. Run the remaining original PTQ suite at that checkpoint |
| 99 | + only after recovery beyond run noise. |
| 100 | +- Cancel when the full-suite gap to BF16 is below 1%, benchmark recovery |
| 101 | + regresses beyond run noise, or benchmark recovery and loss both plateau. |
| 102 | +- After a duration exit, resume the latest QAD checkpoint in the same output |
| 103 | + directory with unchanged prepared data paths/cache, seed, topology, optimizer, |
| 104 | + scheduler, iteration, and consumed-sample state; do not restart from PTQ. |
| 105 | +- Report the PTQ recipe, data sample, Slurm topology, loss/state, checkpoints, |
| 106 | + and comparable BF16/PTQ/QAD results. |
0 commit comments