Commit 67cdc97
Address review: distilled-export layout, hub-id self-check, NVFP4 scale merge
export_distilled_megatron_to_hf.py chose its MoE layout with `use_moe_grouped_gemm`,
but it now rejects quantized checkpoints, so every checkpoint it handles was written by
distill.py's unquantized branch using grouped GEMM. For an architecture with no
`experts.linear_fc1` rule the two disagreed, and the script would have built
SequentialMLP over a grouped-GEMM checkpoint. It mirrors distill.py's choice now.
`_verify_exported_keys` bailed out whenever the source was not a local directory, which
is the documented invocation -- every README and PR snippet passes a hub repo id. The
guard meant to protect user runs on architectures CI never sees was therefore inactive
for exactly those runs. It now fetches just `*.safetensors.index.json`, and still skips
when the source cannot be reached.
The NVFP4 merge kept each expert's block scales but replaced `weight_scale_2` with the
cross-expert maximum, inflating every quieter expert's effective scale by
`scale_2_max / scale_2_i`. Values round-tripped, which is why the reference check passed,
but the FP4 range was wasted. Block scales are now rescaled onto the merged global scale;
measured on the 256-expert half-depth Qwen3.5, worst-case relative error against the
reference drops from 0.16667 to 0.15331. Both packed paths share one helper so they
cannot drift.
Grouped-expert packing only forwarded the four suffixes it names, silently dropping
anything else (`bias` on a future `add_bias_linear` MoE); leftovers now assert.
`load_modelopt_megatron_checkpoint` reads the checkpoint keys already, so it now checks
the stored expert layout against the built model instead of trusting the config.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Signed-off-by: Keval Morabia <28916987+kevalmorabia97@users.noreply.github.com>1 parent 215d4aa commit 67cdc97
3 files changed
Lines changed: 58 additions & 17 deletions
File tree
- examples/megatron_bridge
- modelopt/torch
- export
- utils/plugins
Lines changed: 2 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
72 | | - | |
73 | 72 | | |
74 | 73 | | |
75 | 74 | | |
| |||
256 | 255 | | |
257 | 256 | | |
258 | 257 | | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
| 258 | + | |
| 259 | + | |
264 | 260 | | |
265 | 261 | | |
266 | 262 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
53 | 54 | | |
54 | 55 | | |
55 | 56 | | |
| |||
445 | 446 | | |
446 | 447 | | |
447 | 448 | | |
448 | | - | |
449 | | - | |
450 | | - | |
451 | | - | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
452 | 462 | | |
453 | 463 | | |
454 | 464 | | |
455 | 465 | | |
456 | 466 | | |
457 | | - | |
| 467 | + | |
458 | 468 | | |
459 | 469 | | |
460 | 470 | | |
| |||
1267 | 1277 | | |
1268 | 1278 | | |
1269 | 1279 | | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
1270 | 1285 | | |
1271 | 1286 | | |
1272 | 1287 | | |
| |||
1282 | 1297 | | |
1283 | 1298 | | |
1284 | 1299 | | |
1285 | | - | |
1286 | | - | |
1287 | | - | |
| 1300 | + | |
| 1301 | + | |
1288 | 1302 | | |
1289 | 1303 | | |
1290 | 1304 | | |
| |||
1771 | 1785 | | |
1772 | 1786 | | |
1773 | 1787 | | |
| 1788 | + | |
| 1789 | + | |
| 1790 | + | |
| 1791 | + | |
| 1792 | + | |
| 1793 | + | |
| 1794 | + | |
| 1795 | + | |
| 1796 | + | |
| 1797 | + | |
| 1798 | + | |
| 1799 | + | |
| 1800 | + | |
| 1801 | + | |
1774 | 1802 | | |
1775 | 1803 | | |
1776 | 1804 | | |
| |||
1812 | 1840 | | |
1813 | 1841 | | |
1814 | 1842 | | |
1815 | | - | |
1816 | | - | |
| 1843 | + | |
| 1844 | + | |
| 1845 | + | |
1817 | 1846 | | |
1818 | 1847 | | |
1819 | 1848 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
230 | 230 | | |
231 | 231 | | |
232 | 232 | | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
233 | 249 | | |
234 | 250 | | |
235 | 251 | | |
| |||
0 commit comments