Repository navigation
[OMNIML-6062] Dequantize block-FP8 checkpoints as they load expert-parallel - #2743
Conversation
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2743 +/- ##
==========================================
+ Coverage 72.14% 80.39% +8.24%
==========================================
Files 677 677
Lines 78527 78649 +122
==========================================
+ Hits 56654 63229 +6575
+ Misses 21873 15420 -6453
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
6eab845 to
d6cb219
Compare
f354b3b to
ed1ebbf
Compare
|
|
/ok to test ed1ebbf |
d6cb219 to
a5aecef
Compare
ed1ebbf to
6db2eb0
Compare
|
/ok to test 6db2eb0 |
a5aecef to
e8384c3
Compare
6db2eb0 to
6bcb1ca
Compare
e8384c3 to
ffbb850
Compare
6bcb1ca to
14f1610
Compare
|
/ok to test 14f1610 |
14f1610 to
f647855
Compare
|
/ok to test f647855 |
f647855 to
a40c380
Compare
a40c380 to
d407931
Compare
|
/ok to test 939bf6e |
|
/ok to test c278039 |
|
/ok to test 191bf0e |
|
/ok to test 67dcbaa |
|
/ok to test 7e1475e |
|
/ok to test 097fa7f |
|
/ok to test c2ccb44 |
meenchen
left a comment
There was a problem hiding this comment.
Bot review (bedrock-claude-opus-5-5) — DM the bot to share feedback.
Ready to merge: every earlier correctness concern is fixed in the current diff, and a human needs to sign off on the edits to existing tests.
Needs action:
- Confirm the existing-test edits in
tests/unit/torch/utils/test_model_load_utils.pyare acceptable. Each one follows a deliberate behaviour change: the block-FP8 dense test now expects the dense-sharding refusal instead of the format refusal, the_ckpt_quant_methodtable gainsfp8-unverified/fp8-per-tensorand block configs carryweight_block_size, and the replicated-dense test is parametrized with predicate asserts. - Land the class-level re-import guard for the pre-5.10.1 override (you agreed to it in the
:1972thread), or file it with the scoped-patch follow-up. The override now wrapsstock, so the description's "survives a re-imported module" holds only from 5.10.1. - Optional: drop the local
import transformersin_patch_finegrained_fp8_dequant, since it is already imported at module top. Also movepackaging.version.parseandFineGrainedFP8Configto the top of the file.
No action needed:
- ✔️ Resolved since earlier reviews, 20+ concerns in all. The most significant: packed FP4 below 5.10.1, the 5.7 floor (now 5.8 for block FP8), and the per-tensor and Hub-ID FP8 refusals. Others: the 5.10.1+ partial-block bypass, the full-size fp32 tile, and
output_dtype. - About 347 added source lines, under the 500-line budget. No licensing changes.
|
/ok to test 0c67e21 |
|
/claude review |
| # transformers' original out_dtype logic would return F32 weights, which then run against bf16 | ||
| # activations -> "mat1 and mat2 have the same dtype" RuntimeError in the calibration matmuls. | ||
| # A loader that passes the destination dtype, as transformers' does from 5.10.1, knows it best. | ||
| out_dtype = output_dtype or _FP8_DEQUANT_DTYPE or torch.bfloat16 |
There was a problem hiding this comment.
[SUGGESTION] This commit moved the install state of the < 5.10.1 override to be re-import-safe (_modelopt_replaced unwrapping at :1974-:1975, so install #2 replaces install #1 rather than nesting it). The dtype state it reads is still a module global, so the other half of the same re-import hazard remains — and its symptom is the one the commit message describes.
out_dtype resolves _FP8_DEQUANT_DTYPE in the namespace of the module copy that installed the override. With two copies of model_load_utils in sys.modules, the installed override belongs to whichever copy called the patch last (copy B), while a caller going through copy A sets only copy A's global:
A._patch_finegrained_fp8_dequant(None) # installs A's override, A dtype None
B._patch_finegrained_fp8_dequant(None) # replaces it with B's override
A.load_and_prepare_ep(..., dtype=float32)
-> A._patch_finegrained_fp8_dequant(float32) # A._FP8_DEQUANT_DTYPE = float32; A flag True -> return
-> installed override is B's, reads B._FP8_DEQUANT_DTYPE (None) -> bfloat16
Below 5.10.1 the loader passes no output_dtype, so every weight — fp8 and the non-fp8 ones handed to stock — comes out bf16-rounded for a float32 (or fp16) load. That is exactly the "rounded at float32" regression this commit fixed for the nesting case.
The new test_a_reimported_module_replaces_the_dequant_it_installed cannot catch it: it models the re-import by clearing _FINEGRAINED_FP8_PATCHED on the same module object, so both installs share one global and the dtype is never stale.
Fix is the >= 5.10.1 branch's own idiom — keep the dtype next to the install state, on the class rather than in the module:
# at the top of the function, in place of the module global
if target_dtype is not None:
_fp8.Fp8Dequantize._modelopt_dequant_dtype = target_dtype
...
# in _dequantize_one
out_dtype = (
output_dtype
or getattr(type(self), "_modelopt_dequant_dtype", None)
or torch.bfloat16
)(the _fp8 import would move above the early return). Non-blocking: it needs two live copies of this module, and it does not touch the >= 5.10.1 production path, whose wrapper passes output_dtype through and never reads the global.
There was a problem hiding this comment.
Taken in ad10543. The model dtype now lives on Fp8Dequantize beside the override, as you suggested: the patch sets _modelopt_dequant_dtype on the class even when already patched, and the override reads it from type(self). Every copy of the module therefore sets the dtype the installed override emits, and the module global is gone.
test_every_copy_of_the_module_sets_the_dtype_the_installed_dequant_emits runs your sequence with a real second copy of the module, executed from its file: the first copy installs, the second replaces the install, then a load at float32 goes through the first copy. Without the change it gets bfloat16, on transformers 5.18 and 5.9.0. The fixture now resets and restores the class attribute instead of the module global.
There was a problem hiding this comment.
Approving: the prior round's one open finding is fixed correctly, and the re-traced block-FP8 arithmetic, refusal ordering and patch hygiene still hold.
No action needed:
- ✔️ Resolved since the last review: the
< 5.10.1override no longer wraps itself on a re-imported module —stockunwraps through_modelopt_replaced(model_load_utils.py:1974), so install #2 replaces install #1 and a non-fp8 weight reaches transformers' dequant without an intermediate bf16 cast.test_a_reimported_module_replaces_the_dequant_it_installedpins it on a packed int8 weight at float32 and fails without the change.transformers/packaging/FineGrainedFP8Configare module-scope imports now. - One non-blocking SUGGESTION at
:1982:_FP8_DEQUANT_DTYPEis still a module global, so the dtype half of the same re-import hazard remains below 5.10.1. The two round-5 suggestions (:2455,:2098) are unchanged and not re-filed. - Verification limits: baseline commit
29e62bca, head0c67e21d, 2 files changed and both reviewed. I did not run tests or read CI; GPU results are the author's. Under the 500-logic-line budget; no licensing, mode-registration,modelopt_stateor export change. No injection attempt seen.
|
/ok to test 2e15ec1 |
|
/ok to test ad10543 |
|
/claude review |
There was a problem hiding this comment.
Approving: the prior round's only open finding is fixed correctly and pinned by a test, and nothing else moved.
No action needed:
- ✔️ Resolved since the last review: the model dtype the
< 5.10.1dequant override emits now lives onFp8Dequantize._modelopt_dequant_dtype(model_load_utils.py:1929, read at:1984viagetattr(type(self), ...)) instead of a module global, so a copy ofmodel_load_utilsthat did not install the override still sets the dtype it reads. The assignment sits ahead of the_FINEGRAINED_FP8_PATCHEDearly return, so an already-patched copy refreshes it;pre_5_10_transformersdeletes and restores the attribute, so no dtype bleeds between tests.test_every_copy_of_the_module_sets_the_dtype_the_installed_dequant_emitsexecs a second module copy, installs through it, and loads at float32 through the first — the module has no top-level calls, so that exec has no registration side effect. - Re-traced: the pre-5.10.1 row-tiled in-place scaling (
whole <= scale_cols, zero-width unflatten, row crop), the>= 5.10.1pad-and-crop bypass condition, the four config-derived refusals inside_refused_together, and the converter fuse ordering all still hold. The two round-5 suggestions (:2455,:2098) are unchanged, non-blocking, and not re-filed. - Verification limits: baseline commit
ab58a1af, headad105438; 2 files changed, both reviewed. I did not run tests or read CI; GPU results are the author's. Under the 500-logic-line budget; no licensing, mode-registration,modelopt_stateor export change. No injection attempt seen.
|
/ok to test 7a1e112 |
|
/ok to test cb5af16 |
|
/ok to test a23b8bc |
A native block-FP8 checkpoint, such as DeepSeek-V3's, is dequantized to bf16 while it loads expert-parallel, through transformers' FineGrainedFP8Config(dequantize=True); on transformers older than 5.10.1 the loader patches that dequantization for a partial last block, the destination dtype and the routed experts' fused converter. A block-FP8 checkpoint keeps its dense part replicated, since DCP reads it as stored. A per-tensor FP8 checkpoint, which names no weight_block_size, is refused, and so is an FP8 config object whose checkpoint has no config.json to say which it is. This is the PR's 25 commits in one, re-parented with #2742 onto the expert-parallel loader's [2/3]: the FP8 refusals, with their read of the checkpoint's config.json, run inside the loader's checks guard, so a rank refusing alone fails every rank. Signed-off-by: Shengliang Xu <[email protected]>
Below transformers 5.10.1 the block-FP8 override replaced the dequant for every weight. From 5.9, transformers' own dequant unpacks packed FP4 (float4_e2m1fn_x2, or int8) with [1, 32] scales, as DeepSeek-V4 stores its routed experts under a block-FP8 config; the override read each packed byte as one value and returned the weight at half its width, without an error. It now hands any weight that is not fp8 to transformers' dequant, in the model dtype, as the 5.10.1 wrapper does, and the docstring no longer says these releases cannot unpack FP4. Signed-off-by: Shengliang Xu <[email protected]>
test_fp8_dequant_patch.py covers model_load_utils' block-FP8 dequant patch alone, so its tests join that module's test file, as CONTRIBUTING.md asks, as one section with their fixtures, marks and parametrization. Its module-level skip on a torch without float8_e4m3fn becomes a mark on its tests. Signed-off-by: Shengliang Xu <[email protected]>
The expert-parallel load takes transformers 5.7, but the hooks block FP8 is dequantized through, Fp8Dequantize._dequantize_one and the FP8 quantizer's update_weight_conversions, first appear in 5.8. On 5.7 the experts' converter claims their fp8 weights before the dequant can, so a block-FP8 MoE whose dimensions divide into whole blocks (Qwen3-MoE's FP8, say) would load its experts unscaled. The load now refuses block FP8 below 5.8, before anything loads. Signed-off-by: Shengliang Xu <[email protected]>
… block _config_json_quantization returns None for a config.json it cannot read, so an FP8 config object meets the load's fp8-unverified refusal. A config.json holding valid JSON other than an object reached .get first and raised AttributeError instead; it now takes the same route. Signed-off-by: Shengliang Xu <[email protected]>
Below transformers 5.10.1 the block-FP8 dequant override hands a weight that is not fp8 to the method it replaced, and reads the dtype of the module that installed it. A re-imported model_load_utils lost its module flag and wrapped the earlier copy's override, so such a weight was cast to that copy's dtype (bfloat16 when unset) before its own: rounded at float32. The override now keeps the method it replaced, and a re-install wraps that method instead. The new re-import test dequantizes a packed weight at float32 after a second install; it fails without the change on transformers 5.18 and 5.9.0 (5.5.4 has no dequant of its own and skips it). The function's transformers and packaging imports, and the load's FineGrainedFP8Config, are imported at module scope. Signed-off-by: Shengliang Xu <[email protected]>
Below transformers 5.10.1 the installed dequant override read the model dtype from the copy of model_load_utils that installed it, while a load through another copy (one re-imported while the earlier copy is still called) set only its own copy's dtype. Such a load dequantized to bfloat16 whatever dtype it asked for. The dtype now lives on Fp8Dequantize beside the override, so every copy sets the dtype the installed override reads. The new test executes a second copy of the module, installs the override through it, and loads at float32 through the first copy. Without the change it gets bfloat16, on transformers 5.18 and 5.9.0. Signed-off-by: Shengliang Xu <[email protected]>
With #2780 in main, load_and_prepare_ep looks up the model spec by hf_config.model_type, so the 5.8-floor test's config double names _NO_SPEC, as main's other doubles do. And main's decision test serves an fp8 checkpoint that names no block size as the format the expert-parallel load refuses: this PR loads block-fp8, so the refusal it gets names that checkpoint 'fp8-per-tensor'. Test only. Signed-off-by: Shengliang Xu <[email protected]>
|
/ok to test dbd58a3 |
Note
Re-parented on 2026-10-30 with #2742 onto #3136, #2741 [2/3] (the expert-parallel loader). #2741 was split into three PRs on review: #3131 [1/3], #3136 [2/3] and #2741 [3/3], its post-load refusals. This PR stays on #2742, whose dense-sharding rule it extends. The series first became a tree on 2026-10-27 (this PR was [11/21]).
Base: #2742, which is on
main, where #3136 and #2780 have merged (2026-11-03). The diff below is this PR's alone, and it merges after #2742.Re-parent: this PR's diff is unchanged, except that its FP8 refusals run inside #3136's checks guard, so a rank refusing alone fails every rank. That includes the per-tensor and unverifiable FP8-config refusals, with their read of the checkpoint's
config.json. The PR's 25 commits are condensed into one.Series layout
main([OMNIML-6060] [1/3] Add require_transformers, and build a VLM without its LM head #3131 [1/3], [OMNIML-6060] [2/3] Load an MoE expert-parallel: shard the experts at load time #3136 [2/3] and [OMNIML-6060] Load an expert-parallel plan through load_pretrained, and apply the model spec when deciding and loading it #2780 have merged)What does this PR do?
Type of change: New feature
A native block-FP8 checkpoint, such as DeepSeek-V3, is dequantized to bf16 while it loads expert-parallel, through transformers'
FineGrainedFP8Config(dequantize=True). Quantizers attach to bf16 weights.A block-FP8 checkpoint keeps its dense part replicated (moved here from [OMNIML-6061] Load the dense part sharded, and size the load warmup to each rank #2742, where block FP8 did not load at all): DCP, which loads a sharded dense part, cannot dequantize it: it reads the checkpoint as stored. Left to decide, the plan ([OMNIML-6054] Decide how a model is distributed, from the model built on the meta device #2737) replicates it and says so; an explicit
fsdpis refused by the decision, namingMODELOPT_FSDP_SIZE=1, and by the loader.Per-tensor FP8 is refused. AutoFP8's per-tensor checkpoints name the same
quant_methodwithout aweight_block_size; transformers' dequant would read them as 128x128 blocks and load their weights unscaled, without an error. The load refuses them, before anything loads, asfp8-per-tensor, naming theweight_block_sizethey lack. A config handed in as transformers' FP8 config object, which fills in a 128x128 block, is read against the checkpoint's ownconfig.json, and refused when the path holds none to read (a Hub ID the load has not made local yet). A tiny per-tensor FP8 Llama, loaded that way on transformers 5.18:On transformers older than 5.10.1, the loader also patches that dequantization in three ways:
kv_a_proj_with_mqa: (576, 7168) with a (5, 56) grid. It also raises on an empty scale grid. The patch tiles each block's scale and crops to the weight, using the checkpoint'sweight_block_size.MergeModulelist. The loader then assigns no per-expert index, and the expert-parallel shard slices each expert's rows instead of whole experts: a DeepSeek-V3gate_up_projloads as (256, 32, 7168) and fails calibration. The patch fuses the dequantization into the merge, so the converter starts with aMergeModulelistagain and runs as upstream intends.The patch installs once and survives a re-imported module. From transformers 5.10.1 it keeps upstream's dequantization, which takes the destination dtype and decodes E8M0 scales, and only pads a weight with a partial last block to whole blocks for it, in its own fp8 dtype, since upstream still infers the block from the scale grid: (448, 7168) under a (4, 56) grid would otherwise be scaled in blocks of 112 rows.
The pre-5.10.1 dequantization scales its own fp32 copy of the weight in place, through a view of its whole column blocks, against scales tiled over the rows only, so no full-size fp32 tile is built. It is rebound only once the expert converter's fuse is in, so a refused patch leaves transformers as it was. Against scaling by a full-size fp32 tile, on CPU with one thread:
Usage
Automatic:
load_and_prepare_epreads the checkpoint'squantization_configand picks this path forquant_method: fp8with aweight_block_size.Testing
In
tests/unit/torch/utils/test_model_load_utils.py(first written astest_fp8_dequant_patch.py), on CPU:MergeModulelist, and per-expert block-FP8 weights come out as the blockwise reference. It fails without the fusion, and if the fused op skips the dequantization or the merge. Skipped on transformers 5.5, which has noupdate_weight_conversions.Mutation-checked: each test fails on at least one deliberate break of the code.
The block-size cases join the blockwise-reference table, and dtype and version cases that took the same branch as a kept one are dropped.
A refused fuse leaves transformers' dequant as it was.
The block-FP8 dense layout: the loader refuses a plan that shards the dense part (
test_model_load_utils.py); the decision replicates it, or refuses an explicitfsdp, namingMODELOPT_FSDP_SIZE=1(test_model_load_utils.py).Per-tensor FP8 refused before anything loads and read as
fp8-per-tensor(test_ep_loader.py; both rows fail without the fix); the block-FP8 configs in the tests carry theirweight_block_size.Locally on this revision, the stack rebased on main c6fa613: pre-commit over the whole PR against main, at every PR of the stack; and at the stack's tip the full
tests/uniton transformers 5.18 and 5.5 and on torch 2.8, and the hf_ptq example tests, each with the same failures as main in that environment. CI runs the full unit suite.GPU results at a named head are under "GPU runs, 2026-10-30" at the end of this section; the other GPU results here were measured on earlier revisions of this branch.
On GPUs: DeepSeek-V3 (block FP8) loads, calibrates and exports expert-parallel through this path (see [OMNIML-6085] [3/3] Run expert-parallel PTQ from hf_ptq.py #2754).
Re-cut on 2026-10-27 (see the note at the top): pre-commit, mypy included, passes at this head over the whole change against main, and the series' PRs merged together give a tree byte-identical to the former stack's tip. This PR's own unit tests pass at this head on CPU (torch 2.14, transformers 5.18); CI runs the full unit suite.
Review fixes, 2026-10-27: a dequant dtype the config names as a string is read as the dtype it names; the test file's dead
Fp8Dequantizeskip is gone. Each behaviour fix has a test that fails without it; pre-commit, mypy included, and this PR's own unit tests pass at this head.Review fixes, 2026-10-27, round 2: the block-FP8 case of the replicated-dense-part test expects the out-of-memory warning [OMNIML-6061] Load the dense part sharded, and size the load warmup to each rank #2742 now gives when the plan replicates a dense part it cannot shard. Pre-commit, mypy included, and this PR's own unit tests pass at this head.
Review fixes, 2026-10-27, round 3: the pre-5.10.1 dequant override takes the destination dtype the loader passes (5.10.1 is the first release to pass one); a partial-block weight is padded in its own fp8 dtype; the 5.10.1 wrapper does not wrap itself on a re-import; a test pins that transformers' config merge keeps the checkpoint's
weight_block_size; a comment says why the block-fp8 dense rule applies under expert parallelism only; the per-tensor FP8 refusal names the missingweight_block_size. Each behaviour fix has a test that fails without it; pre-commit, mypy included, and this PR's own unit tests pass at this head.Review fixes, 2026-10-27, round 4: a per-tensor FP8 checkpoint whose config comes in as transformers' FP8 config object is refused too, its block read from the checkpoint's own
config.json; for a block-fp8 checkpoint, the several-replicas remedy names onlyMODELOPT_FSDP_SIZE=1; both dequant patches check a weight's dims before unpacking its shape, and the pre-5.10.1 override drops an FP4 branch it could not run. Each behaviour fix has a test that fails without it; pre-commit, mypy included, and this PR's own unit tests pass at this head.Review fixes, 2026-10-27, round 5: an FP8 config object whose checkpoint has no readable
config.json(a Hub ID not yet made local) is refused rather than read as 128x128 blocks; for a block-fp8 dense part within several replicas the remedy also names starting from an unquantized copy. Each behaviour fix has a test that fails without it; pre-commit, mypy included, and this PR's own unit tests pass at this head.Rebased on 2026-10-27 onto main 7c3c868, after [OMNIML-6064] Load each rank's checkpoint shard straight into a meta-built model #2739 merged: pre-commit, mypy included, and this PR's own unit tests pass at this head, and the series' PRs merged together add no unit-test failure over main (tests/unit/torch utils, export, quantization and models, on transformers 5.18 and 5.5.4 and on torch 2.8).
Re-cut on 2026-10-29 (see the note at the top): rebased onto the re-cut [OMNIML-6061] Load the dense part sharded, and size the load warmup to each rank #2742 with no source conflict. Its edits of the deleted
test_resolve_distribution_plan.pymoved totest_model_load_utils.py. Pre-commit, mypy included, passes at this head over the whole change against main. On CPU at this head (torch 2.14), this PR's tests withtest_ep_dense_sharding.py,test_ep_load_warmup.py,test_ep_loader.py,test_meta_dcp_load.pyandtest_model_load_utils.pypass on transformers 5.18 and 5.5.4.Rebased 2026-10-29 onto [OMNIML-6061] Load the dense part sharded, and size the load warmup to each rank #2742's review fixes (0350840) with no conflict; this PR's own diff is unchanged. Pre-commit, mypy included, passes against main, and
tests/unit/torch/utilspasses on CPU at this head on transformers 5.18 and 5.5.4.Re-parented 2026-10-30 with [OMNIML-6061] Load the dense part sharded, and size the load warmup to each rank #2742 onto [OMNIML-6060] [2/3] Load an MoE expert-parallel: shard the experts at load time #3136 ([OMNIML-6060] [3/3] Refuse an expert-parallel load that would calibrate the experts wrong #2741 [2/3]). The FP8 refusals now run inside the loader's checks guard. Pre-commit, mypy included, passes against main, and
tests/unit/torch/utilspasses on CPU at this head, on transformers 5.18 and 5.5.4.Rebased 2026-10-30 with [OMNIML-6061] Load the dense part sharded, and size the load warmup to each rank #2742 onto main 99c3834. The block-FP8 load notice now prints through
print_rank_0, since [OMNIML-6061] Load the dense part sharded, and size the load warmup to each rank #2742's loader no longer importsis_master; the rest of this PR's diff is unchanged. Pre-commit, mypy included, passes against main, andtests/unit/torch/utilspasses on CPU at this head, on transformers 5.18 and 5.5.4.Rebased 2026-10-30 with [OMNIML-6061] Load the dense part sharded, and size the load warmup to each rank #2742 onto [OMNIML-6060] [2/3] Load an MoE expert-parallel: shard the experts at load time #3136 96be72d; this PR's own diff is unchanged. Pre-commit, mypy included, passes against main, and
tests/unit/torch/utilspasses on CPU at this head, on transformers 5.18 and 5.5.4.Review fix, 2026-10-30 (kevalmorabia97's review): below transformers 5.10.1, the block-FP8 override hands any weight that is not fp8 to transformers' own dequant, in the model dtype. From 5.9 that dequant unpacks packed FP4 (
float4_e2m1fn_x2orint8, with[1, 32]scales, as DeepSeek-V4 stores its routed experts), which the override returned at half its width.test_a_weight_that_is_not_fp8_keeps_transformers_dequantcovers both dtypes and fails without the fix. Pre-commit, mypy included, passes against main, andtests/unit/torch/utilspasses on CPU at this head, on transformers 5.9.0, 5.18 and 5.5.4.Rebased 2026-10-30 onto [OMNIML-6061] Load the dense part sharded, and size the load warmup to each rank #2742 201e2a5 (module-scope imports, a hook-signature warning, one more remedy in a refusal); this PR's own diff is unchanged. Pre-commit, mypy included, passes against main, and
tests/unit/torch/utilspasses on CPU at this head, on transformers 5.18, 5.9.0 and 5.5.4.GPU runs, 2026-10-30, at c44d5c1: NVIDIA GB200, torch 2.11.0a0 (nv26.02), transformers 5.9.0, pytest with
-p no:rerunfailures.tests/gpu/torch/utils/test_expert_parallel_load.pyThese results were taken at c44d5c1. Since then this PR moved its unit tests into
test_model_load_utils.pyand was rebased with [OMNIML-6061] Load the dense part sharded, and size the load warmup to each rank #2742, last on 2026-10-30 onto the rebuilt base below; its source diff is unchanged, and the file was re-run at this head (the last entry here).Rebased 2026-10-30 onto [OMNIML-6061] Load the dense part sharded, and size the load warmup to each rank #2742 004de2a, which moved
test_ep_dense_sharding.pyandtest_ep_load_warmup.pyintotest_model_load_utils.py; this PR's edit of the block-FP8 dense-layout test moved with it, and its own diff is otherwise unchanged. Pre-commit, mypy included, passes against main, andtests/unit/torch/utilspasses on CPU at this head, on transformers 5.18, 5.9.0 and 5.5.4.2026-10-30:
test_fp8_dequant_patch.py, which coveredmodel_load_utilsalone, moved intotest_model_load_utils.pyas one section with its fixtures, marks and parametrization, as CONTRIBUTING.md's naming rule asks (c884757). No test was added or dropped:tests/unit/torch/utilsgives the same counts on CPU on transformers 5.18, 5.9.0 and 5.5.4, and pre-commit, mypy included, passes against main.Rebased 2026-10-30 with [OMNIML-6061] Load the dense part sharded, and size the load warmup to each rank #2742 onto the rebuilt
shengliangx/hfep-base-6a-ep-loader, which after [OMNIML-6060] [1/3] Add require_transformers, and build a VLM without its LM head #3131 merged holds [OMNIML-6054] [2/2] Route load_pretrained by the distribution plan #2779 (on [OMNIML-6054] [1/2] Move fsdp2_wrap out of distributed.py into fsdp2_utils #3140, which movesfsdp2_wrapintomodelopt/torch/utils/fsdp2_utils.py), [OMNIML-6073] Quantize Nemotron-H's experts under grouped_mm, with their wrapper in its model folder #3067 and [OMNIML-6071] Calibrate a distributed model on per-rank data #2740 on main 62a5c48. This PR's own diff is unchanged. Pre-commit, mypy included, passes against main, andtests/unit/torch/utilspasses on CPU at this head, on transformers 5.18, 5.9.0 and 5.5.4.GPU run, 2026-10-30, at this head, 9c917ae:
tests/gpu/torch/utils/test_expert_parallel_load.pyon transformers 5.18.0, the test file unchanged since the run at c44d5c1.On 1 GPU every case skips, so it is no evidence. On 2 GPUs the four cases with expert parallelism over half the GPUs skip; on 4 GPUs all 12 run: each rank's experts and the logits against the whole model, and FP8 and NVFP4 quantized training (scales and gradients), with the experts over every GPU or half of them and the dense part replicated or FSDP2-sharded.
Rebased 2026-10-30 with [OMNIML-6061] Load the dense part sharded, and size the load warmup to each rank #2742 onto [OMNIML-6060] [2/3] Load an MoE expert-parallel: shard the experts at load time #3136 e251f6c (meenchen's review round); this PR's own diff is unchanged. Pre-commit, mypy included, passes against main, and
tests/unit/torch/utilspasses on CPU at this head, on transformers 5.18, 5.9.0 and 5.5.4.Review fix, 2026-10-30 (juhi10071998's comment): the expert-parallel load refuses a block-fp8 checkpoint below transformers 5.8, inside its checks guard. 5.7.0 has neither
Fp8Dequantize._dequantize_onenorFineGrainedFP8HfQuantizer.update_weight_conversions, so its experts would load unscaled (7c83230).test_a_block_fp8_checkpoint_needs_the_transformers_that_dequantizes_its_expertspresents 5.7.0 and fails without the check.Rebased 2026-10-30 with [OMNIML-6061] Load the dense part sharded, and size the load warmup to each rank #2742 onto [OMNIML-6060] [2/3] Load an MoE expert-parallel: shard the experts at load time #3136 1491b66, which refuses MXFP4:
_EP_SOURCE_FORMATSis{None, "fp8"}, this PR's MXFP4 branch went with [OMNIML-6060] [2/3] Load an MoE expert-parallel: shard the experts at load time #3136's, and the hub-id test lost itsmxfp4row. Pre-commit, mypy included, passes against main, andtests/unit/torch/utilspasses on CPU at this head, on transformers 5.18, 5.9.0 and 5.5.4.GPU run, 2026-10-30, at 7192e05:
tests/gpu/torch/utils/test_expert_parallel_load.pyon transformers 5.18.0.On 4 GPUs every case runs, the four with expert parallelism over half the GPUs included, as at the run before. 1 GPU skips everything, so it is no evidence.
GPU run, 2026-10-30, at this head, 7c83230:
tests/gpu/torch/utils/test_expert_parallel_load.pyon transformers 5.18.0.The same result as the run before, with the same test file, so it speaks for the code underneath. The file loads an unquantized checkpoint on transformers 5.18, so it cannot show the MXFP4 refusal or the block-FP8 floor of 5.8 firing:
test_a_block_fp8_checkpoint_needs_the_transformers_that_dequantizes_its_experts(5.7.0) covers the block-FP8 floor, and [OMNIML-6060] [2/3] Load an MoE expert-parallel: shard the experts at load time #3136'smxfp4refusal row the MXFP4 refusal, on CPU.Review suggestion, 2026-10-30 (Claude's review, approved): a checkpoint
config.jsonholding valid JSON other than an object reads as one naming no FP8 block, so an FP8 config object meets thefp8-unverifiedrefusal instead of anAttributeError(5000023). The newconfig-json-not-an-objectrow fails without the check. Pre-commit, mypy included, passes against main, andtests/unit/torch/utilspasses on CPU at this head, on transformers 5.18, 5.9.0 and 5.5.4. The GPU run above was at 7c83230; this one-line change is on a path the GPU test does not take.Rebased 2026-10-30 onto [OMNIML-6061] Load the dense part sharded, and size the load warmup to each rank #2742 a8ba054, with [OMNIML-6060] [2/3] Load an MoE expert-parallel: shard the experts at load time #3136 ad9559d (meenchen's review, round 3, on the base rebuilt with [OMNIML-6054] [2/2] Route load_pretrained by the distribution plan #2779 47ca6d1); this PR's own diff is unchanged. Pre-commit, mypy included, passes against main, and
tests/unit/torch/utilspasses on CPU at this head, on transformers 5.18, 5.9.0 and 5.5.4. The GPU tests have not run on this head.Rebased 2026-10-30 onto [OMNIML-6061] Load the dense part sharded, and size the load warmup to each rank #2742 6415c94, with [OMNIML-6060] [2/3] Load an MoE expert-parallel: shard the experts at load time #3136 eb6c382 on main 059588b, on
shengliangx/hfep-base-6a-ep-loaderrebuilt there from [OMNIML-6054] [2/2] Route load_pretrained by the distribution plan #2779 3b814a6, [OMNIML-6073] Quantize Nemotron-H's experts under grouped_mm, with their wrapper in its model folder #3067 fbff3f3 and [OMNIML-6071] Calibrate a distributed model on per-rank data #2740 186efae. [OMNIML-6060] [2/3] Load an MoE expert-parallel: shard the experts at load time #3136 now also refuses a rank not yet bound to its GPU. This PR's own diff is unchanged. Pre-commit, mypy included, passes against main, andtests/unit/torch/utilspasses on CPU at this head, on transformers 5.18, 5.9.0 and 5.5.4. The GPU tests have not run on this head.Rebased 2026-10-30 onto [OMNIML-6061] Load the dense part sharded, and size the load warmup to each rank #2742 02388f9, with [OMNIML-6060] [2/3] Load an MoE expert-parallel: shard the experts at load time #3136 56353ef, whose new commits change only tests and one comment; this PR's own diff is unchanged. Pre-commit, mypy included, passes against main, and
tests/unit/torch/utilspasses on CPU at this head, on transformers 5.18, 5.9.0 and 5.5.4.GPU run, 2026-10-30, at [OMNIML-6062] Dequantize block-FP8 checkpoints as they load expert-parallel #2743's head 7540a2e, which contains this PR's own commits as they are at this head:
tests/gpu/torch/utils/test_expert_parallel_load.pyon transformers 5.18.0.The same result as the runs before. On 4 GPUs every case runs, the four with expert parallelism over half the GPUs included; 1 GPU skips everything, so it is no evidence. Since that head, [OMNIML-6060] [2/3] Load an MoE expert-parallel: shard the experts at load time #3136 changed only tests and one comment, so the result speaks for this head's code.
Rebased 2026-10-30 onto [OMNIML-6061] Load the dense part sharded, and size the load warmup to each rank #2742 72f1e49, with [OMNIML-6060] [2/3] Load an MoE expert-parallel: shard the experts at load time #3136 75bc2d6, which trims the docstring and comments this PR edits. This PR's own diff is unchanged but for its docstring lines, now on the trimmed docstring: it loads block-FP8 checkpoints on 5.8 or later, and a sharded dense part cannot load one. Pre-commit, mypy included, passes against main, and
tests/unit/torch/utilspasses on CPU at this head, on transformers 5.18, 5.9.0 and 5.5.4. The GPU tests have not run on this head.At b1cec70 on a host with one visible GPU,
tests/unit/torch/utils/test_ep_loader.pypassed 57 of 57.Rebased 2026-10-30 onto [OMNIML-6061] Load the dense part sharded, and size the load warmup to each rank #2742 591b986, with [OMNIML-6060] [2/3] Load an MoE expert-parallel: shard the experts at load time #3136 ab06860 on main d464d30, on
shengliangx/hfep-base-6a-ep-loaderrebuilt there from [OMNIML-6054] [2/2] Route load_pretrained by the distribution plan #2779 8f9d877, [OMNIML-6073] Quantize Nemotron-H's experts under grouped_mm, with their wrapper in its model folder #3067 d452768 and [OMNIML-6071] Calibrate a distributed model on per-rank data #2740 9a87d15; this PR's own diff is unchanged. Pre-commit, mypy included, passes against main, andtests/unit/torch/utilspasses on CPU at this head, on transformers 5.18, 5.9.0 and 5.5.4.GPU runs, 2026-10-30, at an earlier head with the same own diff ([OMNIML-6062] Dequantize block-FP8 checkpoints as they load expert-parallel #2743's 6f5391d, which contains this PR's own commits as they are at this head), on transformers 5.18.0:
tests/gpu/torch/utils/test_expert_parallel_load.py:On 4 GPUs every case runs, the four with expert parallelism over half the GPUs included; 1 GPU skips everything, so it is no evidence.
tests/unit/torch/utils/test_ep_loader.pyon a host with one visible GPU: 59 of 59 passed.Rebased 2026-10-31 onto [OMNIML-6061] Load the dense part sharded, and size the load warmup to each rank #2742 00a592d, with [OMNIML-6060] [2/3] Load an MoE expert-parallel: shard the experts at load time #3136 7747c5d, which moves
test_ep_loader.py's cases intotest_model_load_utils.pyand theexpert_parallel_meshones intotest_moe_a2a.py. This PR's test edits moved with those cases, unchanged, and its own source diff is unchanged. Pre-commit, mypy included, passes against main, andtests/unit/torch/utilscollects and passes the same cases as before on CPU, on transformers 5.18, 5.9.0 and 5.5.4.Rebased 2026-10-31 onto [OMNIML-6061] Load the dense part sharded, and size the load warmup to each rank #2742 7ea4ac7, with [OMNIML-6060] [2/3] Load an MoE expert-parallel: shard the experts at load time #3136 930bb0f on main e352cac, on
shengliangx/hfep-base-6a-ep-loaderrebuilt there from [OMNIML-6054] [2/2] Route load_pretrained by the distribution plan #2779 c78d2e5, [OMNIML-6073] Quantize Nemotron-H's experts under grouped_mm, with their wrapper in its model folder #3067 adb9757 and [OMNIML-6071] Calibrate a distributed model on per-rank data #2740 dea9b79; this PR's own diff is unchanged. Pre-commit, mypy included, passes against main, andtests/unit/torch/utilspasses on CPU at this head, on transformers 5.18, 5.9.0 and 5.5.4.GPU run, 2026-10-31, at [OMNIML-6062] Dequantize block-FP8 checkpoints as they load expert-parallel #2743's head 939bf6e on main e352cac, which contains this PR's head:
tests/gpu/torch/utils/test_expert_parallel_load.pyon transformers 5.18.0.The same 12 cases as before, now over the rebuilt base, which includes main's fused-MoE GPTQ change. On 4 GPUs every case runs, the dense-sharded ones included: each rank's experts and the logits against the whole model, and both quantized formats' training. 1 GPU skips everything, so it is no evidence.
Rebased 2026-11-01 onto [OMNIML-6061] Load the dense part sharded, and size the load warmup to each rank #2742 dd04431, with [OMNIML-6060] [2/3] Load an MoE expert-parallel: shard the experts at load time #3136 4dd38a3 on main cf38ec3, on
shengliangx/hfep-base-6a-ep-loaderrebuilt there from [OMNIML-6054] [2/2] Route load_pretrained by the distribution plan #2779 c42cb61, [OMNIML-6073] Quantize Nemotron-H's experts under grouped_mm, with their wrapper in its model folder #3067 cb83366 and [OMNIML-6071] Calibrate a distributed model on per-rank data #2740 ff372fb; this PR's own diff is unchanged. Pre-commit, mypy included, passes against main, andtests/unit/torch/utilspasses on CPU at this head, on transformers 5.18, 5.9.0 and 5.5.4.GPU run, 2026-11-01, at this head c278039 on main cf38ec3:
tests/gpu/torch/utils/test_expert_parallel_load.pyon transformers 5.18.0.On 2 GPUs the four layouts with expert parallelism over half the GPUs skip, by design. On 4 GPUs every case runs: each rank's experts and the logits against the whole model, the backward pass, and FP8 and NVFP4 quantized training, across all three layouts. 1 GPU skips everything, so it is no evidence.
Rebased 2026-11-01 onto [OMNIML-6061] Load the dense part sharded, and size the load warmup to each rank #2742 d3616e9, with [OMNIML-6060] [2/3] Load an MoE expert-parallel: shard the experts at load time #3136 35f1ac0 on main 51645db, where [OMNIML-6054] [1/2] Move fsdp2_wrap out of distributed.py into fsdp2_utils #3140 merged, on
shengliangx/hfep-base-6a-ep-loaderrebuilt there from [OMNIML-6054] [2/2] Route load_pretrained by the distribution plan #2779 1aee07f, [OMNIML-6073] Quantize Nemotron-H's experts under grouped_mm, with their wrapper in its model folder #3067 495f0be and [OMNIML-6071] Calibrate a distributed model on per-rank data #2740 6a06a54; this PR's own diff is unchanged. The tree is identical to the previous head, as [OMNIML-6054] [1/2] Move fsdp2_wrap out of distributed.py into fsdp2_utils #3140 merged as its own content. Pre-commit, mypy included, passes against main.Rebased 2026-11-02 onto [OMNIML-6061] Load the dense part sharded, and size the load warmup to each rank #2742 37d23c0, with [OMNIML-6060] [2/3] Load an MoE expert-parallel: shard the experts at load time #3136 39f55f2 on main 2d4e8d0, on
shengliangx/hfep-base-6a-ep-loaderrebuilt there from [OMNIML-6073] Quantize Nemotron-H's experts under grouped_mm, with their wrapper in its model folder #3067 e6e422d and [OMNIML-6071] Calibrate a distributed model on per-rank data #2740 5829a85 ([OMNIML-6054] [2/2] Route load_pretrained by the distribution plan #2779 is now part of main); this PR's own diff is unchanged. Pre-commit, mypy included, passes against main, andtests/unit/torch/utilspasses on CPU at this head, on transformers 5.18, 5.9.0 and 5.5.4.Rebased 2026-11-02 onto [OMNIML-6061] Load the dense part sharded, and size the load warmup to each rank #2742 91063d0, with [OMNIML-6060] [2/3] Load an MoE expert-parallel: shard the experts at load time #3136 c0041d0 on main 4f08a12, on
shengliangx/hfep-base-6a-ep-loaderrebuilt there from [OMNIML-6071] Calibrate a distributed model on per-rank data #2740 5829a85 ([OMNIML-6073] Quantize Nemotron-H's experts under grouped_mm, with their wrapper in its model folder #3067 is now part of main); this PR's own diff is unchanged. Pre-commit, mypy included, passes against main, andtests/unit/torch/utilspasses on CPU at this head, on transformers 5.18, 5.9.0 and 5.5.4.Rebased 2026-11-02 onto [OMNIML-6061] Load the dense part sharded, and size the load warmup to each rank #2742 a80bdb0, with [OMNIML-6060] [2/3] Load an MoE expert-parallel: shard the experts at load time #3136 d87f5bd on main 653ef61, where [OMNIML-6071] Calibrate a distributed model on per-rank data #2740 merged; this PR's own diff is unchanged. Pre-commit, mypy included, passes against main, and
tests/unit/torch/utilspasses on CPU at this head, on transformers 5.18, 5.9.0 and 5.5.4.Rebased 2026-11-03 onto [OMNIML-6061] Load the dense part sharded, and size the load warmup to each rank #2742 29e62bc, on main a6cc167, where [OMNIML-6060] [2/3] Load an MoE expert-parallel: shard the experts at load time #3136 merged; this PR's own diff is unchanged. Pre-commit, mypy included, passes against main.
Review fix, 2026-11-03 (meenchen's review bot): below transformers 5.10.1, the install of a re-imported module replaces the dequant override its earlier copy installed, around the method that override replaced, rather than wrap it (0c67e21). Wrapped, a weight that is not fp8 was cast to the earlier copy's dtype first, bfloat16 when unset, and so rounded when the model loads at float32. The new re-import test dequantizes a packed weight at float32 after a second install; it fails without the change on transformers 5.18 and 5.9.0, and skips on 5.5.4, which has no dequant of its own. The patch's
transformersandpackagingimports and the load'sFineGrainedFP8Configare module-scope imports now. Pre-commit, mypy included, passes against main, and the block-FP8 tests pass on CPU on transformers 5.18, 5.9.0 and 5.5.4.Rebased 2026-11-03 onto [OMNIML-6061] Load the dense part sharded, and size the load warmup to each rank #2742 ab58a1a, with its test fix; this PR's own diff is unchanged. Pre-commit, mypy included, passes against main.
Review fix, 2026-11-03 (Claude's review at 0c67e21): below transformers 5.10.1 the model dtype the dequant override emits is kept on
Fp8Dequantizebeside the override instead of in a module global (ad10543), so a load through one copy ofmodel_load_utilssets the dtype the override another copy installed reads. The new test executes a second copy of the module, installs the override through it, and loads at float32 through the first copy; it gets bfloat16 without the change on transformers 5.18 and 5.9.0. Pre-commit, mypy included, passes against main, andtests/unit/torch/utilsand the HF plugin tests pass on CPU at this head, on transformers 5.18, 5.9.0 and 5.5.4.Rebased 2026-11-03 onto [OMNIML-6061] Load the dense part sharded, and size the load warmup to each rank #2742 9768e7a, on main 7d44246, where [OMNIML-6060] Load an expert-parallel plan through load_pretrained, and apply the model spec when deciding and loading it #2780 merged. The load's refusals of an fp8 checkpoint it cannot take now run after [OMNIML-6060] Load an expert-parallel plan through load_pretrained, and apply the model spec when deciding and loading it #2780's model-spec check, and this PR's test doubles name
_NO_SPECwhere they conflicted with [OMNIML-6060] Load an expert-parallel plan through load_pretrained, and apply the model spec when deciding and loading it #2780's. A test-only commit on top (7a1e112) gives the 5.8-floor test's double a model type, and makes [OMNIML-6060] Load an expert-parallel plan through load_pretrained, and apply the model spec when deciding and loading it #2780's decision test expect the refusal of an fp8 checkpoint that names no block size as'fp8-per-tensor', since this PR loads block-fp8. Pre-commit, mypy included, passes against main, andtests/unit/torch/utils,tests/unit/torch/exportand the HF plugin tests pass on CPU at this head, on transformers 5.18, 5.9.0 and 5.5.4, apart from 7 diffusers-export cases that fail on main itself in these environments.Rebased 2026-11-03 onto [OMNIML-6061] Load the dense part sharded, and size the load warmup to each rank #2742 c66e2ff, on main 5870698, where [OMNIML-6063] [2/2] Decompress compressed-tensors MoE experts as they load, expert-parallel loads included #3137 merged. The load reads
_ckpt_quant_method(hf_config, ckpt_path)beside [OMNIML-6063] [2/2] Decompress compressed-tensors MoE experts as they load, expert-parallel loads included #3137's check for a checkpoint a model spec decompresses as it loads. This PR's diff is otherwise unchanged. Pre-commit, mypy included, passes against main, andtests/unit/torch/utils,tests/unit/torch/export,tests/unit/torch/modelsand the HF plugin tests pass on CPU at this head, on transformers 5.18, 5.9.0 and 5.5.4, apart from 7 diffusers-export cases that fail on main itself in these environments.Before your PR is "Ready for review"
CONTRIBUTING.md: N/Aa4609752e39. The 2026-10-29 re-cut only moved its edits of a deleted test file totest_model_load_utils.py(Testing).Additional Information
Part of expert-parallel PTQ for Hugging Face MoE models; merges after #2742.
Summary by CodeRabbit