Repository navigation
[OMNIML-6060] Load an expert-parallel plan through load_pretrained, and apply the model spec when deciding and loading it - #2780
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. |
|
2f18815 to
d68e7ff
Compare
68f620d to
5c5cde0
Compare
d68e7ff to
da76af0
Compare
5c5cde0 to
c892568
Compare
da76af0 to
646405a
Compare
c892568 to
596bb8f
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2780 +/- ##
==========================================
+ Coverage 71.98% 81.67% +9.69%
==========================================
Files 676 664 -12
Lines 77844 76076 -1768
==========================================
+ Hits 56036 62136 +6100
+ Misses 21808 13940 -7868
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:
|
596bb8f to
8c34d8d
Compare
646405a to
678d634
Compare
|
/ok to test 8c34d8d |
8c34d8d to
d2db2ee
Compare
22676c9 to
df0496c
Compare
06fdac7 to
cd46f22
Compare
|
/ok to test cd46f22 |
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]>
|
/ok to test e2d81c9 |
|
/ok to test 22b6d23 |
|
/claude review |
|
|
||
| ``init_quantized_weights`` (see :doc:`_compress_quantized_models`) quantizes and compresses the | ||
| model in the ``from_pretrained`` it patches, which the FSDP2 load never calls. Inside it, a plan | ||
| model in the ``from_pretrained`` it patches, which the sharded loads never call. Inside it, a plan |
There was a problem hiding this comment.
[SUGGESTION] This says the sharded loads never call from_pretrained, but the expert-parallel load does: load_and_prepare_ep builds the model with loader.from_pretrained(ckpt_path, **from_pretrained_kwargs) (modelopt/torch/utils/plugins/model_load_utils.py:2277), and loader is AutoModelForCausalLM for a plain causal LM — exactly the method init_quantized_weights patches. The same claim is the stated reason in the refusal itself, at model_load_utils.py:598: "The {route} load builds the model without from_pretrained, so it would skip init_quantized_weights' quantization".
Why it matters: the refusal is right (the EP load hands from_pretrained its own config, mesh and distributed_config, so init_quantized_weights' device map and compression cannot apply, and _refuse_sharded_load_options is reached on every EP route — test_an_expert_parallel_load_is_refused_inside_init_quantized_weights pins it), but the reason a user reads is false for the route they hit, so it points them at the wrong thing. Only the FSDP2 load genuinely bypasses from_pretrained, via from_config.
Suggestion: make the reason route-specific — e.g. for the expert-parallel route, "builds the model through from_pretrained with its own config and device mesh, so init_quantized_weights' placement and compression do not apply", and narrow this guide sentence to the FSDP2 load (or say the loads do not call it in a way init_quantized_weights can drive).
There was a problem hiding this comment.
Done in c9f3a2d. The refusal now gives each route its own reason:
- The expert-parallel load "builds the model through from_pretrained with its own config and device mesh, so init_quantized_weights' placement and compression do not apply".
- The FSDP2 load's text is unchanged, as it does build without
from_pretrained.
The guide's sentence now names the FSDP2 load as the one that never calls from_pretrained, and says the expert-parallel load calls it with its own config and device mesh. The expert-parallel case's test docstring, which repeated the claim, is fixed too. test_an_expert_parallel_load_is_refused_inside_init_quantized_weights still matches the new text.
There was a problem hiding this comment.
Claude review — LGTM: the folded-in spec-application work is correct and well covered, and I found no defect; a human signs off only because existing tests are replaced.
Baseline: .agents/review-guidelines/code-review.md at base a6cc1673fb6. Reviewed head 22b6d23f, full scope (the trigger carried no scoping instructions); all 7 changed files opened, nothing skipped. ~350 added core-logic lines in one module, inside the size budget. I ran no tests and report no CI result — findings are from source only.
Needs action:
- Confirm the replaced tests as a maintainer:
test_no_ep_degree_dividing_the_experts_leaves_them_whole,test_an_expert_parallel_plan_is_refused,test_a_load_it_decides_keeps_the_experts_whole, thehf_config is servedidentity assertion and the loosenedset-to-1rows match all pinned behaviour this PR replaces. Justified from the diff — EP plans now load rather than being refused — but a bot cannot auto-approve a test removal. - Fix the
init_quantized_weightsrefusal's stated reason atmodel_load_utils.py:598and the matching guide line, which say the sharded loads never callfrom_pretrained— the expert-parallel load does (inline). Non-blocking; the refusal itself is right.
No action needed:
- Traced clean this round (the content folded in from #2746 [3/3] is new to this PR): the spec gate in
resolve_distribution_planis decided by rank 0 throughbroadcast_fromand applied underall_reduce(..., all), so no rank can skip the spec while the others apply it;_ep_degree's auto-to-1 for a spec-refusing model keeps a dense or sub-5.7 FSDP2 load from ever reachingcheck_distributed_support;preparedisTrueonly wherehf_configreally came from the decision or the caller, and thehf_config is None or not preparedbranch covers the explicit-model_typegap, so the spec is applied exactly once;_decide_distributionresolvesrefusalbefore the auto give-aways, so a refused MoE can hit neither the left-wholeValueErrornor the FSDP2 give-way;_spec_ep_planis consulted only atep_size == 1, where the spec was skipped;ep_askedmatches_ep_degree's own_EP_AUTOparse andenv.ep_degree()returns"auto"when unset, so an unset knob is not read as asked-for;_declared_ep_planreads the file afterensure_local_checkpointand inside_refused_together, resolves a nestedep_cfgby identity against_SUB_CONFIG_ATTRS, and its_UNDECLAREDsentinel now distinguishes a declarednullfrom an absent key;hub_optionsreaches the download, the config read andfrom_pretrained, andsubfolderis already joined intockpt_pathupstream.kept_styles,swap,plan,freezeandrequire_lm_headall have live use paths. - No registered spec defines
prepareyet, so the newEPSpec.preparecontract (idempotent, and harmless for a whole or FSDP2-sharded load) is forward-looking rather than a latent regression in a merged spec. - The new GPU test asserts numerical equivalence against a whole-model reference for both plan sources (config-shipped and spec-only), and the unit suite covers the one-rank-cannot-apply-the-spec and unreadable-
config.jsoncollective paths. CHANGELOG.rstamends the same unreleased entries rather than adding new ones.- No prompt-injection attempt found in the PR body, diff or comments.
🤖 Generated with Claude Code
The refusal of a sharded load inside init_quantized_weights gave one reason for both loads, that they build the model without from_pretrained, as did the guide and the expert-parallel case's test. That holds for the FSDP2 load, which builds from the config. The expert-parallel load calls from_pretrained, with its own config and device mesh, so the patch's placement and compression do not apply to it. Each route now says its own reason; the FSDP2 load's words are unchanged. Signed-off-by: Shengliang Xu <[email protected]>
|
/ok to test c9f3a2d |
meenchen
left a comment
There was a problem hiding this comment.
Bot review (bedrock-claude-opus-5-5) — DM the bot to share feedback.
I'm marking this nudge: there are no new correctness defects, but folding in #2746 [3/3] raised the PR to 570 added lines of core logic, over the 500-line budget.
Needs action:
- ✂️ Split this PR into stacked
[x/N]PRs.model_load_utils.pyalone adds 506 lines, so split by feature and undo the fold. Suggested:[1/2] Route an expert-parallel plan through load_pretrained(the pre-fold heade2d81c9dbe6, plus thec9f3a2df3a0wording fix). Then[2/2] Apply the model spec when deciding and loading expert-parallel(#2746's commits: themoe.py_spec_refusal/_ep_floorrefactor, theEPSpec.preparecontract, the spec broadcast inresolve_distribution_plan, and the newprepared,_spec_ep_planand_declared_ep_plancode). Each PR needs its own tests and green CI, and should link the other. - Get a reviewer other than the author to sign off on the replaced tests. These are
test_no_ep_degree_dividing_the_experts_leaves_them_whole,test_an_expert_parallel_plan_is_refused,test_a_load_it_decides_keeps_the_experts_whole, the loosenedep-knobmatch and thehf_config is servedassertion. Each pinned behaviour this PR changes on purpose, so the edits look justified. - Consider shortening the new Backward Breaking
CHANGELOG.rstentry. It is one sentence with eight clauses, which strains the AGENTS.md rule of "one or two sentences" for external users.
No action needed:
- ✔️ Resolved since the last review: the
init_quantized_weightsrefusal now gives each sharded load its own reason, and the guide matches. - The design question is settled: the PR extends the existing
_route/_SHARDED_LOAD_OPTIONSmechanism rather than adding a second one.
The Backward Breaking entry had grown to one sentence of eight clauses. It now says in two what changed for a run on several ranks, and how to keep loading the model whole on every rank. Signed-off-by: Shengliang Xu <[email protected]>
|
Thanks. By
The 570 counts every added line in those files, so I'd keep this as one PR. The CHANGELOG entry is shortened in 275ce95. |
|
/ok to test 275ce95 |
kevalmorabia97
left a comment
There was a problem hiding this comment.
LGTM. No correctness or distributed issues found; unit and 2-GPU decided-load tests pass, and mutating the key logic fails its tests. Small doc fix: the expert-parallel route in _distributed_loading.rst needs both distribution= and MODELOPT_FSDP_SIZE=1 to keep the load whole.
kevalmorabia97
left a comment
There was a problem hiding this comment.
One required doc fix; no code issues found.
Required
docs/source/guides/_distributed_loading.rst, the "A call that places the model…" paragraph, says to passdistribution=or setMODELOPT_FSDP_SIZE=1to keep the load whole. On the expert-parallel route,MODELOPT_FSDP_SIZE=1alone still leaves the EP degree on auto, so the experts still shard. The doc must name both knobs, which is what the code's own message does (_whole_instead(decided, route)).
The guide's paragraph on calls that place the model said that MODELOPT_FSDP_SIZE=1 keeps the load whole. For an MoE whose experts the decision shards, that knob alone leaves the EP degree to the decision, which still shards the experts. The paragraph now names the ways out the refusal itself gives, by route: MODELOPT_FSDP_SIZE=1 or a replicated plan for the FSDP2 load, and MODELOPT_EP_DEGREE=1 with MODELOPT_FSDP_SIZE=1, or a plan with an EP degree of 1, for the expert-parallel one. Signed-off-by: Shengliang Xu <[email protected]>
|
@kevalmorabia97 Thanks, fixed in 0476abb. The guide's paragraph on calls that place the model now gives the same ways out as the refusal (
I checked the rest of the guide and the CHANGELOG for the same one-knob claim. The guide's section on refusals already names both knobs for an expert-parallel plan. The CHANGELOG's Backward Breaking entry also names both. |
|
/ok to test 0476abb |
kevalmorabia97
left a comment
There was a problem hiding this comment.
LGTM. The doc fix is in (both knobs named for a whole expert-parallel load); no code changes since my last review.
Note
Folded in #2746 [3/3] on 2026-11-03, at the user's request: this PR now also applies the model spec when deciding and loading expert-parallel. #2746's commits are here unchanged (this PR's head is #2746's last head, 22b6d23); #2746 keeps their review history, and this PR covers its Jira ticket, OMNIML-6076, too.
Re-parented on 2026-10-30 onto #2741 [2/3] (#3136), the expert-parallel loader's core, when #2741 was split. This PR also adopts #2779's newer collective load checks; see the end of Testing.
Base:
main, since #2741 [2/3] (#3136) merged on 2026-11-03. The diff below is this PR's alone. It merges after #2741 [3/3] (#2741), whose refusals keepload_pretrained's new expert-parallel route from quantizing unsupported experts wrong.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-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's commits, now in this PR, + [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's commits, now in this PR, + [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
#2779 routes
load_pretrainedby aDistributionPlan, but refuses a plan that shards the routed experts: the expert-parallel loader (#2741) comes later in the series. With it in, this PR adds that route, and applies the model's spec (#3134), through the applier (#3135), when deciding and loading it:load_and_prepare_ep, handed the plan itself. Its arguments are checked with the FSDP2 load's, in_sharded_load_kwargsinside [OMNIML-6054] [2/2] Route load_pretrained by the distribution plan #2779's collective "load checks" block;_load_shardedthen runs the load. That load replicates the dense part; FSDP2-sharding it comes with [OMNIML-6061] Load the dense part sharded, and size the load warmup to each rank #2742, a sibling of this PR. Itsfreezeandrequire_lm_headoptions pass through, and so do the Hub options (token,cache_dir,local_files_only), which its config read andfrom_pretraineduse. The sharded loads' refusals from [OMNIML-6054] [2/2] Route load_pretrained by the distribution plan #2779 cover it too: a Nemotron-H checkpoint's MTP head, whichload_and_prepare_epdoes not build, is refused rather than exported unquantized. Until [OMNIML-6061] Load the dense part sharded, and size the load warmup to each rank #2742 is in, an expert-parallel plan that also shards the dense part is refused before anything loads, naming the ways out: replicate it anyway, or FSDP2-shard the whole model. A plan left to decide shards the dense part when a whole copy of it and a rank's share of the experts would exceed 60% of a GPU.MODELOPT_EP_DEGREE=1withMODELOPT_FSDP_SIZE=1, or a replicated plan handed toload_pretrained, which skips the decision. A replication both knobs ask for loads, with a note that every rank holds the whole MoE. So [OMNIML-6054] Decide how a model is distributed, from the model built on the meta device #2737's refusals of routed experts the decision can neither count nor shard by now adviseMODELOPT_EP_DEGREE=1withMODELOPT_FSDP_SIZE=1(ep_size=1withdense='replicate'for a caller passing the arguments): an EP degree of 1 alone now meets the refusal above.The model spec in the decision and the load (folded in from #2746). Without it, 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.This closes the series' second phase: an MoE whose expert-parallel plan ships with transformers, such as Qwen3-MoE, or that only its spec makes expert-parallel, such as DeepSeek-V3, now loads expert-parallel through
load_pretrainedand calibrates.Usage
Either model's routed experts are sharded over the 8 ranks. The DeepSeek-V3 path is an unquantized (BF16) copy. 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(where [OMNIML-6054] Decide how a model is distributed, from the model built on the meta device #2737 moved the decision's tests) gains the refusal to replicate an expert-parallel MoE, when no degree divides its experts or an explicit EP degree of 1 leaves the dense part to auto, FSDP2 allowed instead, and the replication both knobs ask for loading. Qwen3-MoE shows it, whose plan ships with transformers 5.7.test_no_ep_degree_dividing_the_experts_leaves_them_wholegoes: the refusal replaces it. [OMNIML-6054] Decide how a model is distributed, from the model built on the meta device #2737's two refusal tests now setMODELOPT_FSDP_SIZE=1in theirset-to-1rows and check the refusals name it.tests/unit/torch/utils/test_load_pretrained_distribution.py([OMNIML-6054] [2/2] Route load_pretrained by the distribution plan #2779) gains the load's cases:load_and_prepare_epwith the plan, records the plan, and goes through no other loader;Mutation-checked: routing an expert-parallel plan elsewhere, dropping the replicated-MoE refusal, and applying it to a sharded plan each fail a test.
tests/gpu/torch/utils/test_load_pretrained_distribution.pygains a Qwen3-MoE case: left to decide,load_pretrainedshards its experts, each rank holding its contiguous share and the rest whole, and records the expert-parallel plan. Not run locally; CI's GPU workflow runs it.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.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: the refusal names no EP degree when the config hides the expert count. 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: a replication both distribution knobs ask for loads, with a note; the refusal offers an EP degree only when one divides both the experts and the world; the Hub options reach the expert-parallel load. 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).
Review suggestions, 2026-10-27 evening: the expert-parallel load passes the Hub options to the checkpoint download too.
Re-cut on 2026-10-29 onto [OMNIML-6060] [3/3] Refuse an expert-parallel load that would calibrate the experts wrong #2741 (was on [OMNIML-6062] Dequantize block-FP8 checkpoints as they load expert-parallel #2743), with three follow-ups:
test_resolve_distribution_plan.py, which [OMNIML-6054] Decide how a model is distributed, from the model built on the meta device #2737 deleted, intotest_model_load_utils.py;MODELOPT_FSDP_SIZE=1too;load_pretraineddocstring says the expert-parallel route replicates the dense part.Pre-commit, mypy included, passes against main. On CPU (torch 2.14, transformers 5.18 and 5.5.4), these pass at this head:
test_model_load_utils.py,test_load_pretrained_distribution.py,test_ep_loader.py,test_moe_a2a.pyandtest_distributed.py.Review fix, 2026-10-29, from the re-review after the re-cut: on [OMNIML-6060] [3/3] Refuse an expert-parallel load that would calibrate the experts wrong #2741 the expert-parallel load refuses a sharded dense part, so
_routenow refuses an expert-parallel plan that also FSDP2-shards it, before anything loads, naming the ways out. The routing test runs both dense layouts; the refused one fails without the fix. Pre-commit passes against main, and the unit-test files above pass on transformers 5.18 and 5.5.4.Review suggestion, 2026-10-29: the refusal says that sharding the dense part under expert parallelism is not supported yet (message only). Pre-commit passes against main.
Re-parented on 2026-10-30 onto [OMNIML-6060] [3/3] Refuse an expert-parallel load that would calibrate the experts wrong #2741 [2/3] ([OMNIML-6060] [2/3] Load an MoE expert-parallel: shard the experts at load time #3136); the former head is pinned.
_sharded_load_kwargs, inside the collective "load checks" block, and its load in_load_sharded.test_load_pretrained_distribution.pyfiles moved intotest_model_load_utils.py(unit and GPU), where [OMNIML-6054] [2/2] Route load_pretrained by the distribution plan #2779 moved the load tests._route's does (effe11d).Pre-commit, mypy included, passes against main. CPU tests (
test_model_load_utils.py,test_ep_loader.py,test_moe_a2a.py; torch 2.14):device_map), it names its way to a whole model,MODELOPT_EP_DEGREE=1withMODELOPT_FSDP_SIZE=1or a replicated plan; the FSDP2 load's text is unchanged. A test row checks it and fails without the change. Pre-commit passes against main;test_model_load_utils.pyandtest_ep_loader.pypass on transformers 5.18 (161) and 5.5.4 (139, 22 skipped).test_model_load_utils.py,test_ep_loader.py,test_moe_a2a.pyandtests/unit/torch/modelspass on transformers 5.18 (405) and 5.5.4 (376, 29 skipped).its-own-plan) oftest_an_expert_parallel_moe_loads_with_its_experts_shardedat [OMNIML-6076] [3/3] Apply the model spec when deciding and loading expert-parallel #2746 [3/3]'s ae518d6, passed. That version of the test also compares each rank's logits with the whole model's. [OMNIML-6076] [3/3] Apply the model spec when deciding and loading expert-parallel #2746's spec-plan row and the two denseload_pretrainedtests passed beside it, 4 tests in all. NVIDIA GB200, torch 2.11.0a0, transformers 5.9.0, reruns disabled:_load_shardedtakes the route beside [OMNIML-6054] [2/2] Route load_pretrained by the distribution plan #2779's new_has_own_gpu.load_pretrained's docstring: the expert-parallel bullet goes before [OMNIML-6054] [2/2] Route load_pretrained by the distribution plan #2779's reworded FSDP2 bullet, and the dropped "anep_size > 1plan raises" sentence leaves the rest of [OMNIML-6054] [2/2] Route load_pretrained by the distribution plan #2779's paragraph as it is.CHANGELOG.rstline keeps this PR's wording.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 (425, 31 skipped).mp_policyfor the FSDP2 load only (90c914a).test_a_sharded_load_refuses_what_it_cannot_honorgains ano_gpurow and anmp_policyassertion. Each fails without its change.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 (427, 31 skipped).freeze,require_lm_head) before anything loads, naming that load. Before, they reachedfrom_pretrainedand failed inside transformers.test_a_load_refuses_what_it_cannot_loadgainsep-option-on-a-whole-load, which fails without the change.test_model_load_utils.py,test_ep_loader.py,test_moe_a2a.pyandtests/unit/torch/modelspass on transformers 5.18 (470) and 5.5.4 (428, 31 skipped).ep_size/densearguments, which override the environment knobs, or the knobs (b1f5d8c). A newexplicit_degree_one_as_an_argumentrow fails without it.freeze=False, unlike the other loads (1072e8f).test_model_load_utils.py,test_ep_loader.py,test_moe_a2a.pyandtests/unit/torch/modelspass on transformers 5.18 (471) and 5.5.4 (428, 32 skipped).ValueError, like the decision's other refusals of what its inputs resolve to (d0a63ff).test_model_load_utils.py,test_ep_loader.py,test_moe_a2a.pyandtests/unit/torch/modelspass on transformers 5.18 (471) and 5.5.4 (428, 32 skipped).freezeorrequire_lm_headpassed asNoneasks nothing, as other options passed asNonedo, rather than reading as False and dropping the LM head (83d9ce0).freeze=True, as the other routes do (69e56a9).test_model_load_utils.py,test_ep_loader.py,test_moe_a2a.pyandtests/unit/torch/modelspass on transformers 5.18 (472) and 5.5.4 (428, 33 skipped).freezeandrequire_lm_head, rather than refusing them as a whole-model placement (1db4cc3). A newits-own-optionsrow fails without the change._refuse_a_rank_without_its_gpusays what the check adds beside [OMNIML-6060] [2/3] Load an MoE expert-parallel: shard the experts at load time #3136's GPU check in the expert-parallel load, which now refuses a run where only some ranks have a GPU (8f9c8d9).test_model_load_utils.py,test_ep_loader.py,test_moe_a2a.pyandtests/unit/torch/modelspass on transformers 5.18 (476) and 5.5.4 (430, 35 skipped).broadcast_chunk_size=Noneasks the FSDP2 load to broadcast every layer at once. The expert-parallel load used to drop it silently and now refuses it as the FSDP2 load's option. The two new rows oftest_a_load_refuses_what_it_cannot_loadeach fail without the change.test_model_load_utils.py,test_ep_loader.py,test_moe_a2a.pyandtests/unit/torch/modelspass on transformers 5.18 (478) and 5.5.4 (432, 35 skipped).test_a_load_it_decides_shards_the_expertsreplaces [OMNIML-6054] [2/2] Route load_pretrained by the distribution plan #2779'stest_a_load_it_decides_keeps_the_experts_whole._whole_instead, which now takes the route. For a plan handed in, the refusal names a plan with an EP degree of 1; for a decided plan, it also names the knobs.measuredrefusal, which this PR extends to that layout. Only options that neither sharded load takes count as placement._ASKS_NOTHING. On the expert-parallel load,broadcast_chunk_size=Noneis refused as an FSDP2 option, andcpu_offload=Falseasks for nothing.test_model_load_utils.py,test_ep_loader.py,test_moe_a2a.pyandtests/unit/torch/modelspass on transformers 5.18 (513) and 5.5.4 (463, 39 skipped).test_what_a_rank_holds_with_the_dense_part_replicated_must_fitasserts both outcomes, and its decided case fails without the change.load_and_prepare_epdocstring and comments, plus this PR's sentence onhub_options.test_model_load_utils.py,test_ep_loader.py,test_moe_a2a.pyandtests/unit/torch/modelspass on transformers 5.18 (515) and 5.5.4 (463, 41 skipped)._ep_plan_refusal) or by its checkpoint format. Such an MoE is not refused for being left whole either (9cc4589).test_an_moe_the_expert_parallel_load_refuses_is_decided_without_itfails without the change in both of its cases.test_model_load_utils.py,test_ep_loader.py,test_moe_a2a.pyandtests/unit/torch/modelspass on transformers 5.18 (519) and 5.5.4 (464, 44 skipped).its-specandits-transformerscases fail without the change.test_model_load_utils.py,test_ep_loader.py,test_moe_a2a.pyandtests/unit/torch/modelspass on transformers 5.18 (521) and 5.5.4 (464, 46 skipped).test_ep_loader.pyintotest_model_load_utils.py. This PR's one change to that file, the Hub-options checks intest_the_weights_load_in_the_checkpoints_dtype_through_its_class, now sits in the moved section. Its own diff is otherwise unchanged. Pre-commit passes against main.test_model_load_utils.py,test_moe_a2a.pyandtests/unit/torch/modelspass on transformers 5.18 (521) and 5.5.4 (464, 46 skipped)._EP_MIN_TRANSFORMERS, that the decision and the load both read (6210606).MODELOPT_EP_DEGREE=1, and theset-to-1cases fail without the change.test_model_load_utils.py,test_moe_a2a.pyandtests/unit/torch/modelspass on transformers 5.18 (525) and 5.5.4 (464, 50 skipped).load_and_prepare_eprefuses what the plan decision gives way for (_ep_load_refusal), after its own floor and format checks. An EP degree asked for, or a plan handed in, no longer loads a model whose spec rules expert parallelism out. The load test's new GPT-OSS case fails without the change.test_model_load_utils.py,test_moe_a2a.pyandtests/unit/torch/modelspass on transformers 5.18 (526) and 5.5.4 (465, 50 skipped).init_quantized_weightsrefusal names the expert-parallel route's own way to a whole model, and a new test covers both a knob and a handed plan; the plain FSDP2 wording fails it. The loading guide [OMNIML-6054] [2/2] Route load_pretrained by the distribution plan #2779 added now describes the expert-parallel route, which this PR's docstring paragraphs moved into (5455a0c). The decided EP degree is no longer forced to 1 inload_pretrained._ep_load_refusalreturns the error itself, so a floor refusal is aRuntimeErrorwhichever floor it trips (eda4c88). A spec's floor above the load's own is tested (608b0b8). Both cases fail without their change.test_model_load_utils.py,test_moe_a2a.pyandtests/unit/torch/modelspass on transformers 5.18 (536) and 5.5.4 (471, 54 skipped).test_model_load_utils.py,test_moe_a2a.pyandtests/unit/torch/modelspass on transformers 5.18 (538) and 5.5.4 (472, 55 skipped).test_model_load_utils.py,test_moe_a2a.pyandtests/unit/torch/modelspass on transformers 5.18 (538) and 5.5.4 (472, 55 skipped).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 (572) and 5.5.4 (486, 75 skipped).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.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 (see [OMNIML-6076] [3/3] Apply the model spec when deciding and loading expert-parallel #2746's Testing).test_an_expert_parallel_moe_loads_with_its_experts_shardedintests/gpu/torch/utils/test_model_load_utils.pyruns Qwen3-MoE (its-own-plan) and DeepSeek-V3 saved with no plan of its own (its-spec-plan) through the realload_pretrained, with the plan left to decide. It checks each rank's expert slices and its own batch's logits against the whole model. It and the two denseload_pretrainedtests passed on 2 NVIDIA GB200 GPUs (torch 2.11.0a0, transformers 5.9.0, reruns disabled).init_quantized_weightsgives each route its own reason. The expert-parallel load callsfrom_pretrainedwith its own config and device mesh, and the FSDP2 load's text is unchanged; the guide and a test docstring follow. Pre-commit passes against main. The same CPU tests pass on transformers 5.18 (594) and 5.5.4 (495, 88 skipped).load_pretraineddistributes a model is cut to two sentences, what changed and how to keep loading it whole on every rank. Pre-commit passes against main.MODELOPT_EP_DEGREE=1withMODELOPT_FSDP_SIZE=1, or a plan with an EP degree of 1. Pre-commit passes against main.Before your PR is "Ready for review"
CONTRIBUTING.md: N/AAdditional Information
Part of expert-parallel PTQ for Hugging Face MoE models; merges after #2741 [3/3] (#2741). Split from #2774, which first routed every load in one PR and whose non-expert-parallel half is now #2779: this half needs the expert-parallel loader, so it lands after it. Applying the model spec in the decision and the load, which this PR carried before the series was reordered, moved to #2746 with the specs, and came back here when #2746 was folded in on 2026-11-03.
Summary by CodeRabbit
torchrun. Distribution plans also support FSDP2 sharding or loading a full copy on each rank.