Repository navigation
[OMNIML-6076] [3/3] Apply the model spec when deciding and loading expert-parallel - #2746
Closed
shengliangxu wants to merge 33 commits into
Closed
shengliangxu wants to merge 33 commits into
shengliangxu wants to merge 33 commits into
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. |
Contributor
shengliangxu
force-pushed
the
shengliangx/hfep-8-fused-experts
branch
from
October 12, 2026 02:35
6e6ac9c to
bad2de9
Compare
shengliangxu
force-pushed
the
shengliangx/hfep-9-ep-model-specs
branch
from
October 12, 2026 02:35
2142693 to
2e134ec
Compare
Contributor
|
Collaborator
Author
|
/ok to test 2e134ec |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## shengliangx/hfep-9b-ep-load-routing #2746 +/- ##
======================================================================
Coverage ? 61.91%
======================================================================
Files ? 655
Lines ? 73164
Branches ? 0
======================================================================
Hits ? 45301
Misses ? 27863
Partials ? 0
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:
|
shengliangxu
force-pushed
the
shengliangx/hfep-9-ep-model-specs
branch
from
October 12, 2026 08:39
2e134ec to
fdd217a
Compare
Collaborator
Author
|
/ok to test fdd217a |
shengliangxu
force-pushed
the
shengliangx/hfep-8-fused-experts
branch
from
October 13, 2026 00:53
16e5c17 to
5c0d5fa
Compare
shengliangxu
force-pushed
the
shengliangx/hfep-9-ep-model-specs
branch
from
October 13, 2026 00:53
fdd217a to
0a3e056
Compare
shengliangxu
force-pushed
the
shengliangx/hfep-8-fused-experts
branch
from
October 13, 2026 01:32
5c0d5fa to
698f459
Compare
shengliangxu
force-pushed
the
shengliangx/hfep-9-ep-model-specs
branch
from
October 13, 2026 01:32
0a3e056 to
67f1c8f
Compare
Collaborator
Author
|
/ok to test 67f1c8f |
shengliangxu
force-pushed
the
shengliangx/hfep-8-fused-experts
branch
from
October 13, 2026 19:38
698f459 to
eaa41c2
Compare
shengliangxu
force-pushed
the
shengliangx/hfep-9-ep-model-specs
branch
from
October 13, 2026 19:38
67f1c8f to
2f18815
Compare
Collaborator
Author
|
/ok to test 2f18815 |
shengliangxu
force-pushed
the
shengliangx/hfep-9-ep-model-specs
branch
from
October 14, 2026 00:14
2f18815 to
d68e7ff
Compare
shengliangxu
force-pushed
the
shengliangx/hfep-9-ep-model-specs
branch
from
October 14, 2026 01:47
d68e7ff to
da76af0
Compare
The expert-parallel load reads the plan the checkpoint declares from its config.json. For a handed config whose plan sits on a nested config, a config.json that is no JSON object made the nested lookup raise on that rank alone, outside the load's collective refusal, so the other ranks went on into the load and waited for it. A file a rank cannot read as a JSON object now declares no plan, and the read runs inside the expert-parallel load's refusal block, so anything else it raises reaches every rank. Signed-off-by: Shengliang Xu <[email protected]>
A config.json the expert-parallel load cannot read, or that is no JSON object, declares no plan to keep, so the loaded model keeps none and an export writes none, whatever the checkpoint declared. That loss is now a warning instead of silence. The call-site comment says the read no longer raises on the file, and why it stays in the collective block. Signed-off-by: Shengliang Xu <[email protected]>
Left whole on every rank, a model whose spec marks expert parallelism unsupported was refused with a RuntimeError, while the load refuses the same spec with check_distributed_support's NotImplementedError. Raise the same type on both, which is still a RuntimeError. Signed-off-by: Shengliang Xu <[email protected]>
The warning for a config.json the load cannot read went through warn_rank_0, so a rank other than 0 failing alone dropped the plan from its model's config with no warning anywhere. Each rank now warns for itself and names its rank. Signed-off-by: Shengliang Xu <[email protected]>
Below the release a model's expert parallelism needs, an MoE left whole on every rank was refused with "Upgrade transformers" and no release, though the spec's own refusal names it. Both now read the release from one place, moe._ep_floor: the expert-parallel load's own, or the spec's when that is later. Signed-off-by: Shengliang Xu <[email protected]>
Below the release a model's expert parallelism needs, an MoE left whole on every rank was told to upgrade transformers to shard its experts, even when no EP degree divides both its experts and the world size, or its config names no count: there an upgrade shards nothing, and the next run meets the refusal that names the real obstacle. Offer the upgrade only where a degree exists, and let the other cases name what stands in the way. Signed-off-by: Shengliang Xu <[email protected]>
Below the release a model's expert parallelism needs, the left-whole refusal tells the caller to upgrade transformers to shard the experts. With the EP degree set to 1 by the caller, an upgrade alone leaves it at 1, and the next run meets the refusal again. Name raising the degree as well there, with the knob the caller set it by. Signed-off-by: Shengliang Xu <[email protected]>
The left-whole refusal test checked for a ValueError by the word "divid" in the expected pattern, which the pattern for an EP degree to raise beside an upgrade contains too, though that refusal stays a RuntimeError. Check by the pattern of the decision's own refusal. Signed-off-by: Shengliang Xu <[email protected]>
With no ranks to shard over, the plan holds the whole model whatever the model is, but the EP degree argument was still parsed with the model type, which consults the model's spec and its transformers floor for a result that cannot change. Parse it without. Signed-off-by: Shengliang Xu <[email protected]>
resolve_distribution_plan applied the model's spec whenever the world and the EP degree left room for expert parallelism, whatever class the load builds the model with. A class the sharded loads refuse is planned whole on every rank, or refused, so it is never expert-parallel, yet every rank ran the spec's prepare first: a prepare that raises failed a load that loaded the whole model on every rank before, and one that patches the process did so for a load that never uses it. Skip the spec for such a class, as the decision does. Signed-off-by: Shengliang Xu <[email protected]>
With an expert-parallel plan handed in, the expert-parallel load prepares its copy of a config= passed for the load once its own checks pass, the rank's-own-GPU refusal among them, so a rank that cannot load runs no spec prepare, which can import the checkpoint's code. A row of test_a_sharded_load_refuses_what_it_cannot_honor holds it: its spec applier fails if a rank without a GPU prepares anything. Signed-off-by: Shengliang Xu <[email protected]>
The expert-parallel load keeps on the loaded model's config the plan the checkpoint's config.json declares, read from the file. A plan set on a config passed for the load, and not declared there, is not kept, so an export writes out what the checkpoint declares; the docstring said only the spec's and the config class's plans were left out. Signed-off-by: Shengliang Xu <[email protected]>
check_distributed_support and the refusal of an MoE left whole on every rank both offered FSDP2 with the same caveat, what the FSDP2 load takes, in two wordings that each round had to keep in step. Both now take it from one helper in moe, with the knob spelled as the caller set it. Signed-off-by: Shengliang Xu <[email protected]>
…allel The plan decision applies the model's spec, prepare included, before it knows the plan, wherever the plan could still be expert-parallel, so a run whose auto EP degree comes out at 1 has run prepare too. That is now the documented contract of EPSpec.prepare: it must leave a whole-model or FSDP2 load as it would be without it, and may run more than once. Signed-off-by: Shengliang Xu <[email protected]>
_sharded_load_kwargs took an hf_config as prepared by the model's spec unless told otherwise, so a caller that left prepared out would skip the spec for a config that needs it: DeepSeek-V3 below transformers 5.13 would load sharding nothing. Left out, it is now taken as not prepared; preparing again is harmless by EPSpec.prepare's contract, skipping it is not. Signed-off-by: Shengliang Xu <[email protected]>
The plan decision now gives an EP degree it chose way to FSDP2 for the whole model when the dense part is FSDP2-sharded, so the routing test's case for the refusal of an expert-parallel plan that FSDP2-shards the dense part asks for the EP degree, as a caller meeting that refusal has. Signed-off-by: Shengliang Xu <[email protected]>
The plan decision's refusal of an MoE its spec rules out read the spec's unsupported text to decide, then left it out, so a run that set nothing, the one most users reach as auto resolves to 1 for these models, learned only that the model cannot be expert-parallel. It now says why, as the load's own refusal of the same spec does. Signed-off-by: Shengliang Xu <[email protected]>
The plan decision asks the model spec (_spec_refuses_ep) before the expert-parallel load's refusal: auto resolves to an EP degree of 1 for a model whose spec refuses expert parallelism or needs a later transformers, and the left-whole refusal says why. The load refusal's own spec and floor checks could no longer change a plan, so they are gone, with the floor they spelled out beside _ep_floor's. The give-way test's model-spec case patched a spec lookup the decision no longer reads; GPT-OSS's left-whole case covers that refusal, now with the MXFP4 checkpoint format its releases have, which the load refuses as well. Signed-off-by: Shengliang Xu <[email protected]>
and floor checks this PR leaves to the spec-aware decision. A plan handed to the load reaches it without that decision, so the load asks the spec itself, as load_pretrained's expert-parallel route does, and refuses with the same NotImplementedError or RuntimeError. Signed-off-by: Shengliang Xu <[email protected]>
transformers writes config.json as UTF-8. Read in the locale's encoding, a non-ASCII byte under a non-UTF-8 locale raised UnicodeDecodeError, which the plan-provenance read took for an unreadable file and dropped the plan the checkpoint declares. Signed-off-by: Shengliang Xu <[email protected]>
The load asked the spec only past its format check and its no-plan guard, so a direct call for a model whose plan only its spec supplies, or whose MXFP4 checkpoint the load refuses as well (GPT-OSS's), reported those instead of the spec's reason, whose remedy is the one that loads. It now asks the spec as soon as it has the config, as load_pretrained does. Signed-off-by: Shengliang Xu <[email protected]>
…ing why The left-whole refusal had arms of its own for an MoE whose spec refuses expert parallelism (NotImplementedError) or whose transformers is below the release its expert parallelism needs (RuntimeError, naming the upgrade), where #2780 loads an MoE the expert-parallel load refuses for its checkpoint or plan as a dense model does, with a rank-0 warning. The spec's refusal (_spec_refusal, check_distributed_support's error) now joins that refusal: such an MoE loads as a dense model does at an EP degree left to auto or set to 1, and the warning carries the spec's reason or the upgrade. Its arms and their texts are gone; an EP degree above 1 asked for it is still refused as before. The left-whole test keeps the MoEs that could be expert-parallel, on a transformers at the floor, and a new test loads GPT-OSS and DeepSeek-V3 below the floor with the warning. Signed-off-by: Shengliang Xu <[email protected]>
A plan that loads an MoE without expert parallelism, as its spec rules it out or its transformers is below the floor, warned with check_distributed_support's whole refusal, whose way around expert parallelism is the very load the warning announces. _spec_refusal moves into moe.py beside check_distributed_support and gives the reason alone. check_distributed_support refuses with that reason and the way out, in the words it used before, and _spec_refuses_ep is whether there is a reason, so one except catches the floor's error. Signed-off-by: Shengliang Xu <[email protected]>
The check for a replication the caller asked for read ep_size=" auto " as auto, while _ep_degree refused it as no EP degree. MODELOPT_EP_DEGREE reaches both stripped already; an argument now does too, as int() takes a padded number. Signed-off-by: Shengliang Xu <[email protected]>
_spec_ep_plan's docstring still said a run holding such a model's experts whole on every rank is refused; it now loads as a dense model, and the plan is what lets the decision find its experts and warn why. Signed-off-by: Shengliang Xu <[email protected]>
The decision plans the whole model, unbuilt, for a model class the sharded loads refuse or under init_quantized_weights, but the spec gate before it mirrored only the model class: an init_quantized_weights run with nothing asking to shard applied the model's spec, prepare included, for a load that never shards. The gate now skips the spec there too. An EP degree asked for under init_quantized_weights still takes it: without the spec's plan the decision finds none of the experts of an MoE whose plan only its spec supplies, and refuses the degree for dividing no experts, before the load refuses init_quantized_weights itself. Signed-off-by: Shengliang Xu <[email protected]>
It sets transformers.__version__ to 5.7.0 itself, so the expert-parallel load's floor never stood in its way: needs_ep_transformers only skipped it below 5.7, where it passes. Signed-off-by: Shengliang Xu <[email protected]>
The refusal of an MoE left whole on every rank listed FSDP2 with the caveat on what the FSDP2 load takes, a trailing relative clause, in the middle of its ways out, so the single process and the replication that followed read as part of that clause. The ways out are now four short items, and the caveat follows them as a sentence of its own. _FSDP2_TAKES holds the caveat for both refusals that offer FSDP2. check_distributed_support's refusal, where the clause ends the sentence, reads as before. Signed-off-by: Shengliang Xu <[email protected]>
Collaborator
Author
|
/ok to test 22b6d23 |
Collaborator
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
Slice [3/3] of this PR's split (2026-10-30), so the model-spec work is reviewed and merged in pieces under the 500-line budget:
EPSpecand every model's data), merged;apply_distributed_supportand its checks), merged;Base:
shengliangx/hfep-base-9-specs, a branch (not a PR) that holds #2780, the PR this one builds on. #3135 and #3136 are inmain. The diff below is this PR's alone. It merges after #2780, then sits onmain.Re-cut: split from the former whole PR (head 2489583, pinned). Also adapted to #2779's collective load checks; see the end of Testing.
Series layout
main, with [OMNIML-6060] [1/3] Add require_transformers, and build a VLM without its LM head #3131 [OMNIML-6060] [3/3] Refuse an expert-parallel load that would calibrate the experts wrong #2741 [1/3], [OMNIML-6076] [1/3] Describe expert parallelism in the model specs #3134 [OMNIML-6076] [3/3] Apply the model spec when deciding and loading expert-parallel #2746 [1/3], [OMNIML-6076] [2/3] Prepare a model's config for expert parallelism from its spec #3135 [OMNIML-6076] [3/3] Apply the model spec when deciding and loading expert-parallel #2746 [2/3], [OMNIML-6054] [2/2] Route load_pretrained by the distribution plan #2779, [OMNIML-6073] Quantize Nemotron-H's experts under grouped_mm, with their wrapper in its model folder #3067, [OMNIML-6071] Calibrate a distributed model on per-rank data #2740 and [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] mergedhfep-base-9-specs([OMNIML-6060] Load an expert-parallel plan through load_pretrained, and apply the model spec when deciding and loading it #2780)hfep-base-11a-decompress([OMNIML-6063] [2/2] Decompress compressed-tensors MoE experts as they load, expert-parallel loads included #3137) → [OMNIML-6063] [3/3] Load a checkpoint its model spec decompresses through the expert-parallel loader #2747 on-the-fly decompressionhfep-base-11b-kimi([OMNIML-6076] [3/3] Apply the model spec when deciding and loading expert-parallel #2746 + [OMNIML-6063] [3/3] Load a checkpoint its model spec decompresses through the expert-parallel loader #2747) → [OMNIML-6078] Add the Kimi-VL and Kimi-K2.5 expert-parallel adapters #3138 → [OMNIML-6078] [2/2] Add the Kimi-K2.5 expert-parallel adapter #2748 → [OMNIML-6079] [2/3] Add the Kimi-K3 expert-parallel adapter #2749hfep-base-14-hf-ptq([OMNIML-6076] [3/3] Apply the model spec when deciding and loading expert-parallel #2746 + [OMNIML-6061] Load the dense part sharded, and size the load warmup to each rank #2742 + [OMNIML-6084] Export an expert-parallel model through the no-gather writer #2753 + [OMNIML-6085] [1/3] Add forward= to distributed_forward_loop, and fix the GPU memory monitor's NVML probe #3133) → [OMNIML-6085] Run expert-parallel PTQ from hf_ptq.py, with lockstep previews #3139 → [OMNIML-6085] [3/3] Run expert-parallel PTQ from hf_ptq.py #2754What does this PR do?
Type of change: New feature
The plan decision and the expert-parallel load apply the model's spec (#3134), through the applier (#3135). Without them, an MoE that only its spec makes expert-parallel, such as DeepSeek-V3 before transformers 5.13, is decided as dense.
resolve_distribution_planapplies the model's spec to a copy of the config before rank 0 builds the model on meta._spec_refuses_ep).MODELOPT_FSDP_SIZE=worldalone plans FSDP2 for GPT-OSS, and for Qwen3-MoE on transformers 5.5.prepareattaches), without applying anything.moe._spec_refusal). An EP degree above 1 asked for such a model is still refused, with the way around expert parallelism added (check_distributed_support).check_distributed_support).config=passed for the load with a plan handed in is the caller's own, so an expert-parallel load prepares a copy of it, once.prepareruns before deciding here, and where it goes in [OMNIML-6078] [2/2] Add the Kimi-K2.5 expert-parallel adapter #2748. The decision builds the model on the meta device and finds and counts its routed experts through the plan. For a model whose plan only its spec supplies, the spec must therefore be applied first. This PR applies the whole spec there,prepareincluded, and documents the interim contract onEPSpec.prepare: it must leave a whole-model or FSDP2 load as it would be without it, and may run more than once. No spec in this PR setsprepare.EPSpec.make_importable) and attaches the spec's stated plan (prepared_ep_plan) with nopreparerun.preparethen runs only once the plan is decided expert-parallel: in a collective step after the decision, or in the load after its own checks for a plan handed in.preparewheremodels/hf.py'sprepare_for_loadinghooks already run: on the route that loads the model it prepares, never on one that does not. The hooks are scoped to the load as a context;prepareonly runs on that route.Usage
The path is an unquantized (BF16) copy of DeepSeek-V3. The published
deepseek-ai/DeepSeek-V3checkpoint is FP8, which this PR refuses before anything loads. The expert-parallel load dequantizes FP8 checkpoints from #2743 on.Testing
tests/unit/torch/utils/test_model_load_utils.py(the decision's and the loads' tests) gains the spec's cases:MODELOPT_EP_DEGREE=1;ep_size=2meets the refusal;config=with a handed plan; GPT-OSS is refused with its config handed in, without preparing it.Mutation-checked (earlier rounds): skipping the spec or applying it without expert parallelism, ignoring the EP knob, letting each rank decide the spec for itself, preparing a handed config twice or not at all, ignoring the spec's plan at an EP degree of 1, letting auto pick an EP degree for a model whose spec refuses expert parallelism or below a floor, and offering an EP degree below the floor each fail a test.
Checked locally, at the stack's tip: DeepSeek-V3, Nemotron-H and Nemotron-H-Omni configs prepared by their specs and swapped to the
torch_a2astyles are written by the expert-parallel export with nobase_model_ep_plan, as their sources have none. There the export writer itself puts back the sourceconfig.json's values ([OMNIML-6084] Export an expert-parallel model through the no-gather writer #2753). The loaded model's own config holds no spec plan only since b51123a (below).On GPUs (1 node, EP4, an earlier revision): gpt-oss-20b under
torchrunstopped at the plan decision, before any weights load.2026-10-30, split and re-parented:
prepareitem is [OMNIML-6076] [2/3] Prepare a model's config for expert parallelism from its spec #3135's, the declined version-claims item [OMNIML-6076] [1/3] Describe expert parallelism in the model specs #3134's).test_load_pretrained_distribution.pymoved intotest_model_load_utils.py, where [OMNIML-6054] [2/2] Route load_pretrained by the distribution plan #2779 moved the load tests.Pre-commit, mypy included, passes against main. CPU tests (
test_model_load_utils.py,test_ep_loader.py,test_moe_a2a.py,tests/unit/torch/models; torch 2.14):hfep-base-9-specs([OMNIML-6060] Load an expert-parallel plan through load_pretrained, and apply the model spec when deciding and loading it #2780 1bec6da + [OMNIML-6076] [2/3] Prepare a model's config for expert parallelism from its spec #3135 fe16583); no conflicts, this PR's own diff unchanged. Pre-commit passes against main;test_model_load_utils.py,test_ep_loader.py,test_moe_a2a.pyandtests/unit/torch/modelspass on transformers 5.18 (467) and 5.5.4 (411, 56 skipped).moeinstead._EP_MIN_TRANSFORMERScomes in with the module-scope import frommoe.test_an_expert_parallel_moe_loads_with_its_experts_shardedintests/gpu/torch/utils/test_model_load_utils.pyruns for two models.its-own-planis Qwen3-MoE.its-spec-planis DeepSeek-V3 saved with no plan of its own, so the plan comes only from its spec. Both run the realload_pretrainedwith the plan left to decide, and check each rank's expert slices and its own batch's logits against the whole model. The test is gated on 2 GPUs and transformers >= 5.7.DistributionPlan(2, ep_size=2)with the spec's plan. The whole model builds and runs.test_model_load_utils.py,test_ep_loader.py,test_moe_a2a.pyandtests/unit/torch/modelspass on transformers 5.18 (467) and 5.5.4 (411, 56 skipped).load_pretrainedtests intests/gpu/torch/utils/test_model_load_utils.pypassed: both expert-parallel rows (its-spec-plan,its-own-plan) and the two dense tests. NVIDIA GB200, torch 2.11.0a0, transformers 5.9.0, reruns disabled:Review round, 2026-10-30 (b51123a): the expert-parallel load put a plan the model spec attached back on the loaded model's config, where an export would write it into
config.json. That affected Nemotron-H, Nemotron-H-Omni, DeepSeek-V3 below transformers 5.13, and anyconfig.jsonpinning the plan tonull. The load now reads the declared plan from the checkpoint'sconfig.json. The kept config gets exactly that, or no plan of its own.test_the_model_keeps_the_plan_its_checkpoint_declares(test_ep_loader.py) is parametrized over a plan declared by the checkpoint, a class default, and one attached by the spec. It asserts onvars(model.config)and on the writtenconfig.json. The spec-attached case fails without the fix.test_model_load_utils.py,test_ep_loader.py,test_moe_a2a.pyandtests/unit/torch/modelspass on transformers 5.18 (468) and 5.5.4 (412, 56 skipped).model.tp_plan, copied at build.Review round, 2026-10-30 (fa2d2f5): a
config.jsonthat one rank cannot read as a JSON object now declares no plan to keep, instead of raising in the nested lookup on that rank alone. The read of the declared plan runs inside the expert-parallel load's collective refusal block.test_a_load_failing_on_one_rank_fails_every_rankgainsunreadable-plan-provenance, on two gloo ranks: a handed config with the plan ontext_config, and rank 1 alone reading aconfig.jsonthat parses to[]. Both ranks reach the load, stood in by a bounded barrier. The previous code, and the move without the type check, each fail it in under 20 s.test_model_load_utils.py,test_ep_loader.py,test_moe_a2a.pyandtests/unit/torch/modelspass on transformers 5.18 (469) and 5.5.4 (412, 57 skipped).Review round, 2026-10-30 (2205949):
config.jsonthe load cannot read as a JSON object still declares no plan to keep, but now with a warning, since an export then writes none (3f1b031). A row intest_the_model_keeps_the_plan_its_checkpoint_declaresasserts the warning.NotImplementedError, as the load side does (2205949). It is still aRuntimeError, andtest_an_ep_capable_moe_left_whole_on_every_rank_is_an_errorasserts the type.Rebased on 2026-10-30 (d7e5fde) onto the rebuilt
hfep-base-9-specs(52b6cf9 = [OMNIML-6060] Load an expert-parallel plan through load_pretrained, and apply the model spec when deciding and loading it #2780 d78aaf8 + [OMNIML-6076] [2/3] Prepare a model's config for expert parallelism from its spec #3135 da3aeca), after [OMNIML-6060] [1/3] Add require_transformers, and build a VLM without its LM head #3131 merged to main (62a5c48). What moved underneath conflicted in 7 hunks (3 source, 4 test): [OMNIML-6054] [2/2] Route load_pretrained by the distribution plan #2779's newer round under [OMNIML-6060] [2/3] Load an MoE expert-parallel: shard the experts at load time #3136, and [OMNIML-6060] [2/3] Load an MoE expert-parallel: shard the experts at load time #3136's two latest commits. Each is resolved by applying this PR's change to the new text:_ep_degreekeeps [OMNIML-6054] [2/2] Route load_pretrained by the distribution plan #2779's whitespace strip. Itsmodel_typeis now optional, because [OMNIML-6054] [2/2] Route load_pretrained by the distribution plan #2779 reads the knob through it before any config is read (a launch without a process group), where auto stays auto.ep_askedstrips the knob too, so every reading of_EP_AUTOagrees.load_pretrained's docstring says aconfigpath is prepared too.test_model_load_utils.py,test_ep_loader.py,test_moe_a2a.pyandtests/unit/torch/modelspass on transformers 5.18 (532) and 5.5.4 (462, 59 skipped).Review round, 2026-10-30 (ffb58cf), on the helper rebuilt from [OMNIML-6060] Load an expert-parallel plan through load_pretrained, and apply the model spec when deciding and loading it #2780 50e64f0 (7ca9934):
config.jsona rank cannot read is per rank and names the rank (89f8845). Theunreadable-plan-provenancerow asserts rank 1 alone warns.moe._ep_floor, whichcheck_distributed_supportnow uses too (ffb58cf)._NEEDS_LATERasserts it.Review round, 2026-10-30 (bfd26e8), on the helper rebuilt from [OMNIML-6060] Load an expert-parallel plan through load_pretrained, and apply the model spec when deciding and loading it #2780 3c353af (7146e4f):
test_an_ep_capable_moe_left_whole_on_every_rank_is_an_errorgainsbelow_the_ep_floor_no_degree, which fails without the change.Review round, 2026-10-30 (7041b61), on the helper rebuilt from [OMNIML-6060] Load an expert-parallel plan through load_pretrained, and apply the model spec when deciding and loading it #2780 b1f5d8c (ef0cb85):
{knob},{replicate}and the FSDP2 setting as the caller set them. The restack resolved the conflicts that way, along with [OMNIML-6060] Load an expert-parallel plan through load_pretrained, and apply the model spec when deciding and loading it #2780's new test row.below_the_ep_floor_explicit_degree_onerow fails without it.Review round, 2026-10-30 (2f90895), on the helper rebuilt from [OMNIML-6060] Load an expert-parallel plan through load_pretrained, and apply the model spec when deciding and loading it #2780 4a1e020 (ce39f86):
_sharded_load_kwargs(..., prepared=False)) rather than reading it again. This still happens after its option, MTP and GPU checks.test_a_load_prepares_its_config_once[planned]asserts one read.ValueErrorwith [OMNIML-6060] Load an expert-parallel plan through load_pretrained, and apply the model spec when deciding and loading it #2780. The unsupported arm keepsNotImplementedErrorand the below-the-floor armRuntimeError, and the test asserts each type.Review round, 2026-10-30 (6342161), on the helper rebuilt from [OMNIML-6060] Load an expert-parallel plan through load_pretrained, and apply the model spec when deciding and loading it #2780 4040ea3 (2a26182):
test_a_single_process_holds_the_whole_modelasserts it.freezedefault beside this PR's spec step in the expert-parallel branch.Restack and review round, 2026-10-30 (03f7985), on the helper rebuilt from [OMNIML-6060] Load an expert-parallel plan through load_pretrained, and apply the model spec when deciding and loading it #2780 8f9c8d9 (f306d9f):
preparethat raised failed a load that used to work.test_a_model_class_of_the_callers_own_loads_wholenow makes the spec applier fail if it is called. All three of its cases fail without the change, on transformers 5.18 and 5.5.4._EP_MIN_TRANSFORMERSto that module-scope import directly, and the commit that moved it there is dropped. The other restack conflicts were in import lists and in the one-rank-failure test, which now keeps both [OMNIML-6060] [2/3] Load an MoE expert-parallel: shard the experts at load time #3136'sno-gpurow and this PR's plan-provenance row.Review round, 2026-10-30 (d3a058e), on the helper rebuilt from [OMNIML-6060] Load an expert-parallel plan through load_pretrained, and apply the model spec when deciding and loading it #2780 d466147 (c312093). The restack had no conflicts, and the blocker fix above is now efe745e.
config=, the expert-parallel load now prepares its copy of that config after its own checks. This puts the spec step after the rank's-own-GPU refusal and runs it once (c6fd67f). A newno_gpu_config_passedrow fails without the change._declared_ep_plannow says that a plan set on a config passed to the load is not kept either (681fbc3).moe._fsdp2_way_out, and bothcheck_distributed_supportand the left-whole refusal use it (d3a058e).Restack round, 2026-10-30 (0eadf4c), on the helper rebuilt from [OMNIML-6060] Load an expert-parallel plan through load_pretrained, and apply the model spec when deciding and loading it #2780 b692242 and [OMNIML-6076] [2/3] Prepare a model's config for expert parallelism from its spec #3135 85885c3 (9992be8), on main 059588b:
config=passed for a sharded load before reading the model type. The first commit therefore takes the final design directly: the expert-parallel load prepares that copy once its own checks pass. The commit that previously made that change now holds only its test row.preparemay run for a plan that ends up not expert-parallel.EPSpec.preparenow documents this as its contract (0eadf4c).Review round, 2026-10-30 (4ed85b3), on the helper rebuilt from [OMNIML-6060] Load an expert-parallel plan through load_pretrained, and apply the model spec when deciding and loading it #2780 1692141 (5aed81c):
_sharded_load_kwargsnow treats anhf_configpassed withoutpreparedas not prepared, so the load applies the spec to it (6cec3dd).Restack round, 2026-10-30 (9267a0b), on the helper rebuilt from [OMNIML-6060] Load an expert-parallel plan through load_pretrained, and apply the model spec when deciding and loading it #2780 093c652 and [OMNIML-6076] [2/3] Prepare a model's config for expert parallelism from its spec #3135 8d2bd3c (8c36e1e), on main d464d30:
_ep_degreereads the knob unstripped, as [OMNIML-6054] [2/2] Route load_pretrained by the distribution plan #2779's environment parsing now strips it.Review round, 2026-10-31 (77c4117), on the helper rebuilt from [OMNIML-6060] Load an expert-parallel plan through load_pretrained, and apply the model spec when deciding and loading it #2780 1960174 and [OMNIML-6076] [2/3] Prepare a model's config for expert parallelism from its spec #3135 41b8a6a (e887676):
Restacked on 2026-10-31 (c39129d) on the helper rebuilt from [OMNIML-6060] Load an expert-parallel plan through load_pretrained, and apply the model spec when deciding and loading it #2780 fac2c56 and [OMNIML-6076] [2/3] Prepare a model's config for expert parallelism from its spec #3135 7c0be5b (3abc574). [OMNIML-6060] [2/3] Load an MoE expert-parallel: shard the experts at load time #3136 moved
test_ep_loader.pyintotest_model_load_utils.py, so this PR's four commits that changed that file now make the same changes in the moved section; their imports go into that file's import block. Its own diff is otherwise unchanged. Pre-commit passes against main. The same CPU tests pass on transformers 5.18 (573) and 5.5.4 (486, 76 skipped).Review round, 2026-10-31 (c7619f8), on the helper rebuilt from [OMNIML-6060] Load an expert-parallel plan through load_pretrained, and apply the model spec when deciding and loading it #2780 3fc02b8 and [OMNIML-6076] [2/3] Prepare a model's config for expert parallelism from its spec #3135 7c0be5b (604c3f5):
_ep_load_refusalno longer checks the spec and the transformers floor, which the decision asks the spec about first, and the give-way test drops the case that patched a spec lookup the decision no longer reads (c7619f8). GPT-OSS's left-whole case now has the MXFP4 format, and it fails without the spec clause.Review round, 2026-10-31 (3b10775), on the helper rebuilt from [OMNIML-6060] Load an expert-parallel plan through load_pretrained, and apply the model spec when deciding and loading it #2780 3c40b57 and [OMNIML-6076] [2/3] Prepare a model's config for expert parallelism from its spec #3135 7c0be5b (c76a6b8):
check_distributed_supportitself, asload_pretrained's expert-parallel route does. A plan handed to it is refused for a model its spec refuses, now that_ep_load_refusalleaves the spec to the decision (85ff59b). [OMNIML-6060] Load an expert-parallel plan through load_pretrained, and apply the model spec when deciding and loading it #2780's GPT-OSS case in the load test expects thatNotImplementedErrorhere, and fails without the call.config.jsonis read as UTF-8 (3b10775). Checked by hand underLC_ALL=Cwith a non-ASCII field; there is no unit test for it.Restacked on 2026-10-31 (d8059b3) on the helper rebuilt from [OMNIML-6060] Load an expert-parallel plan through load_pretrained, and apply the model spec when deciding and loading it #2780 c2d18e6 and [OMNIML-6076] [2/3] Prepare a model's config for expert parallelism from its spec #3135 2b3dfc6 (c4cc146), on main e352cac:
confignote in theload_pretraineddocstring moved to the loading guide's Configs section, as [OMNIML-6054] [2/2] Route load_pretrained by the distribution plan #2779 shortened the docstring.Restacked on 2026-11-01 (997f9a6) on the helper rebuilt from [OMNIML-6060] Load an expert-parallel plan through load_pretrained, and apply the model spec when deciding and loading it #2780 36863bc and [OMNIML-6076] [2/3] Prepare a model's config for expert parallelism from its spec #3135 289b626 (29647ff), on main cf38ec3. [OMNIML-6060] Load an expert-parallel plan through load_pretrained, and apply the model spec when deciding and loading it #2780's new dense-sharding case, with the EP degree left to the decision, is added to this PR's DeepSeek-V3 version of that test; it fails if only rank 0's GPU memory may make the decided degree give way. Its own diff is otherwise unchanged. Pre-commit passes against main. The same CPU tests pass on transformers 5.18 (586) and 5.5.4 (495, 80 skipped).
Restacked on 2026-11-01 (fce7da4) on the helper rebuilt from [OMNIML-6060] Load an expert-parallel plan through load_pretrained, and apply the model spec when deciding and loading it #2780 8e19843 and [OMNIML-6076] [2/3] Prepare a model's config for expert parallelism from its spec #3135 4cfbddf (255cb02), on main 51645db, without conflicts; its own diff is unchanged. The helper now carries [OMNIML-6076] [2/3] Prepare a model's config for expert parallelism from its spec #3135's check that a spec's
preparereturns a config the load can read. Pre-commit passes against main. The same CPU tests pass on transformers 5.18 (588) and 5.5.4 (495, 82 skipped).Design change, 2026-11-01 (ce38100), on the helper rebuilt from [OMNIML-6060] Load an expert-parallel plan through load_pretrained, and apply the model spec when deciding and loading it #2780 e20bd19 and [OMNIML-6076] [2/3] Prepare a model's config for expert parallelism from its spec #3135 4cfbddf (6b4130a): an MoE its spec rules out, or below the transformers its expert parallelism needs, now loads as a dense model does with [OMNIML-6060] Load an expert-parallel plan through load_pretrained, and apply the model spec when deciding and loading it #2780's rank-0 warning, instead of being refused for being left whole. The spec's refusal joins the expert-parallel load's (
_spec_refusal), the left-whole refusal's spec and floor arms and their texts are gone, and the restack drops the commit that made the floor case a refusal.test_an_moe_its_spec_or_transformers_rules_out_loads_as_a_dense_model(GPT-OSS MXFP4, and DeepSeek-V3 on transformers 5.6.2; auto, set to 1, dense replicated) fails without it. Pre-commit passes against main. The same CPU tests pass on transformers 5.18 (589) and 5.5.4 (494, 84 skipped).Review fixes, 2026-11-01 (71ea9ed), on the helper rebuilt from [OMNIML-6060] Load an expert-parallel plan through load_pretrained, and apply the model spec when deciding and loading it #2780 edf3b61 and [OMNIML-6076] [2/3] Prepare a model's config for expert parallelism from its spec #3135 4cfbddf (0625cbc):
check_distributed_support's refusal adds._spec_refusalmoved tomoe.py, and_spec_refuses_epreads it (85b08ef). The spec test's six rows fail without it.ep_size=" auto "now resolves as auto, asMODELOPT_EP_DEGREEdoes (620040a). The padded-argument case fails without it.Review fixes, 2026-11-01 (04a197e), fast-forward of 71ea9ed:
init_quantized_weights, with the EP degree left to auto, the decision no longer applies the model's spec, whosepreparewould run for a load that never shards (55af217). An EP degree the caller asks for still applies it, so the decision finds the experts of an MoE whose plan only its spec supplies, and the load refusesinit_quantized_weightsitself.test_a_load_it_decides_inside_init_quantized_weights_is_whole_and_unplacedfails with the old gate. The new DeepSeek-V3 case oftest_an_expert_parallel_load_is_refused_inside_init_quantized_weightsfails if an asked EP degree skips the spec too.test_the_expert_count_is_read_from_the_config_holding_the_planruns below transformers 5.7 again (04a197e). It sets the version itself, so itsneeds_ep_transformersmark only skipped it.Review fix, 2026-11-01 (bf5ca2e), fast-forward of 04a197e: the refusal of an MoE left whole on every rank lists its four ways out as short items, and the FSDP2 load's caveat (an unquantized causal LM with no MTP head it cannot build) follows them as a sentence of its own.
check_distributed_support's refusal reads as before. Pre-commit passes against main. The same CPU tests pass on transformers 5.18 (594) and 5.5.4 (495, 88 skipped).Restacked on 2026-11-02 (55413f3) on [OMNIML-6060] Load an expert-parallel plan through load_pretrained, and apply the model spec when deciding and loading it #2780 301f97d, on main 2d4e8d0, where [OMNIML-6076] [2/3] Prepare a model's config for expert parallelism from its spec #3135 merged. The base branch now holds [OMNIML-6060] Load an expert-parallel plan through load_pretrained, and apply the model spec when deciding and loading it #2780 alone, since [OMNIML-6076] [2/3] Prepare a model's config for expert parallelism from its spec #3135 is in main. There were no conflicts, and the PR's own diff is unchanged. Pre-commit passes against main. The same CPU tests pass on transformers 5.18 (594) and 5.5.4 (495, 88 skipped).
Restacked on 2026-11-02 (e6efb94) on [OMNIML-6060] Load an expert-parallel plan through load_pretrained, and apply the model spec when deciding and loading it #2780 09322c1, on main 4f08a12. There were no conflicts, and the PR's own diff is unchanged. Pre-commit passes against main. The same CPU tests pass on transformers 5.18 (594) and 5.5.4 (495, 88 skipped).
Restacked on 2026-11-02 (f3503ff) on [OMNIML-6060] Load an expert-parallel plan through load_pretrained, and apply the model spec when deciding and loading it #2780 7653ddf, on main 653ef61. There were no conflicts, and the PR's own diff is unchanged. Pre-commit passes against main. The same CPU tests pass on transformers 5.18 (594) and 5.5.4 (495, 88 skipped).
Rebased on 2026-11-03 (22b6d23) onto [OMNIML-6060] Load an expert-parallel plan through load_pretrained, and apply the model spec when deciding and loading it #2780 e2d81c9, on main a6cc167, where [OMNIML-6060] [2/3] Load an MoE expert-parallel: shard the experts at load time #3136 merged. There were no conflicts, and the PR's own diff is unchanged. Pre-commit passes against main. The same CPU tests pass on transformers 5.18 (594) and 5.5.4 (495, 88 skipped).
Before your PR is "Ready for review"
CONTRIBUTING.md: N/AAdditional Information
Part of expert-parallel PTQ for Hugging Face MoE models; merges after #2780 and #3135. The former whole PR's history (Llama-4 and MiniMax-M3 adapters added and then removed, review rounds) is pinned with its last head; the slices carry the net change.