Repository navigation
[OMNIML-6078] [2/2] Add the Kimi-K2.5 expert-parallel adapter - #2748
shengliangxu wants to merge 23 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. |
95832dd to
e243f04
Compare
f73bc4f to
0098f3a
Compare
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## shengliangx/hfep-11a-onfly-decompress #2748 +/- ##
=========================================================================
+ Coverage 62.46% 62.52% +0.05%
=========================================================================
Files 658 665 +7
Lines 74106 74227 +121
=========================================================================
+ Hits 46294 46407 +113
- Misses 27812 27820 +8
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:
|
|
/ok to test 0098f3a |
e243f04 to
d6afd32
Compare
0098f3a to
3d6fb9d
Compare
|
/ok to test 3d6fb9d |
d6afd32 to
67355f4
Compare
1c16b42 to
ecf9d71
Compare
67355f4 to
b162532
Compare
|
/ok to test ecf9d71 |
ecf9d71 to
d525e64
Compare
|
/ok to test d525e64 |
269d3d2 to
dddc2ee
Compare
d525e64 to
0c39a27
Compare
|
/ok to test 0c39a27 |
dddc2ee to
c668ec2
Compare
|
/claude review |
| def test_a_spec_with_a_prepare_states_its_plan(model_type): | ||
| """Deciding the plan runs no prepare, so a plan only prepare attaches goes unseen there: the | ||
| decision reads the MoE as dense and plans it without expert parallelism, with no refusal.""" | ||
| ep = get_spec(model_type).ep_spec | ||
| assert not ep.prepare or ep.base_model_ep_plan or ep.prepared_ep_plan, ( |
There was a problem hiding this comment.
[SUGGESTION] The three invariant tests here now pin prepare ⟹ plan, make_buildable ⟹ prepare and decompressed_formats ⟹ prepare. The symmetric prepared_ep_plan ⟹ prepare is the one still unpinned, and this PR is what makes it load-breaking rather than merely inert.
Trace for a spec that states prepared_ep_plan with no prepare:
- the decision's step calls
apply_distributed_support(..., prepare=False), whereplan = ep.base_model_ep_plan or (None if prepare else ep.prepared_ep_plan)attaches it (moe.py:278), so_decide_distributionfinds the routed experts and can resolve an expert-parallel plan; - the "model spec prepared" step then calls
apply_distributed_supportwithprepare=True, where that same expression yieldsNone— nothing is attached — and the returns-a-plan check is insideif prepare and ep.prepare is not None:, so with noprepareit is skipped entirely; load_and_prepare_epthen raisesexpert-parallel PTQ requires the model to declare base_model_ep_plan, after the decision, the checkpoint fetch and the meshes.
On the base this combination was inert (nothing attached the plan at all, so the MoE was simply read as dense); it is only after this PR that the decision plans such a model expert-parallel and the load refuses it. No current spec is in that shape, and the failure is loud rather than silent, so this is non-blocking — but a fourth one-line check would keep the field's contract ("for a model whose plan only prepare supplies") enforced where the other three now are:
@pytest.mark.parametrize("model_type", EP_MODEL_TYPES)
def test_a_spec_states_a_prepared_plan_only_with_a_prepare(model_type):
"""Only prepare attaches prepared_ep_plan: the decision reads it and can plan the model
expert-parallel, but with no prepare the load gets a config with no plan and refuses it."""
ep = get_spec(model_type).ep_spec
assert not ep.prepared_ep_plan or ep.prepare, (
f"{model_type} states prepared_ep_plan and no prepare, so nothing attaches it for the "
"expert-parallel load: state it as base_model_ep_plan, or attach it in a prepare"
)There was a problem hiding this comment.
Taken in 5a3092d: test_a_spec_states_a_prepared_plan_only_with_a_prepare in test_ep_specs.py asserts not ep.prepared_ep_plan or ep.prepare for every spec with an EP section, beside the other three spec-field checks. It fails for Kimi-VL with its prepare dropped.
There was a problem hiding this comment.
Approving: the delta since the last round is the one test that round asked for, and the prepare-behind-the-decision move still traces correctly end to end.
No action needed.
- ✔️ Resolved since the last review:
test_a_spec_decompresses_only_in_a_prepare(test_ep_specs.py:118) pins the last unpinned invariant of the fields this PR adds —decompressed_formats ⟹ prepare— alongsidetest_a_spec_with_a_prepare_states_its_planandtest_a_spec_with_a_build_step_prepares. Both Kimi specs satisfy all three, and the field defaults to(), so_ep_load_refusalis unchanged for every other spec. - Re-traced this round: the
"plan"/"build"gate still agrees with when_decide_distributionbuilds a model (world_size == 1returns unbuilt, so the gate'sworld_size > 1is the right guard), andbroadcast_fromround-trips the newstrpayload underweights_only; "model spec prepared" is gated on the broadcast plan, so every rank enters or skips it together;plan_config_attr="text_config"putsprepared_ep_planwhere_ep_configreads it, and_routed_expert_modulessuffix-matches the backbone-relative globs against the VLM'slanguage_model.model.layers.*names, so the decision counts the 8 experts in the model the checkpoint's own code builds; at an EP degree of 1_spec_ep_planstill returnsprepared_ep_plan, so that route finds them too;make_buildable'stie_weightsshim goes through_apply, which filters totransformers_modules.*, so transformers' own 5.13 port is left alone;preparedfrom_sharded_load_kwargsis consulted on the expert-parallel route only, so the FSDP2 route is unaffected by returning the config as read.decompressed_formatsisDECOMPRESSED_FORMATSexactly, so the decision andprepareagree on which checkpoints decompress, andload_and_prepare_ep's own format check still gates on the decompressor's mark rather than on the spec. - Test edits are justified by the behavior change:
test_a_load_prepares_its_config_oncecounts real preparations only, and_one_rank_cannot_apply_the_spec_jobgains apreparedstep asserting every rank reached the step that prepares a decided plan. No coverage shrank. - New files carry
LICENSE_HEADERverbatim; ~386 addedmodelopt/lines including comments and docstrings, under budget. No text in the diff tries to steer this review. - One non-blocking SUGGESTION inline on
tests/unit/torch/models/test_ep_specs.py:96:prepared_ep_plan ⟹ prepareis the symmetric invariant still unpinned, and this PR is what turns that shape from inert into a load-time refusal. - Verification limits: no tests were run here (pytest was not available to this review) and no CI was consulted; the build step has no GPU coverage, as the description states. Baseline commit
299afb6c35823e02693c21cf19972a7718ef3c15, headbf373955, full scope (bare/claude review), all 15 changed files reviewed.
🤖 Generated with Claude Code
|
/ok to test 5a3092d |
|
/ok to test d19ee63 |
Kimi-K2.5 (and Kimi-K2.6 and Kimi-K2.7-Code, which share its model type) is Kimi-VL's shape with compressed-tensors INT4 experts. Its adapter swaps in transformers' native deepseek_v3 language model as Kimi-VL's does, through the patch they share, and installs the on-the-fly decompressor first of all, so a checkpoint the decompressor refuses leaves the config and the loader untouched. It installs it only for a checkpoint whose quantization_config declares compressed-tensors: bf16 experts load as they are, and any other scheme is left to the expert-parallel load's format handling, which reads the copy of quantization_config Kimi's config class keeps on the top level. A scheme on text_config alone, with no top-level copy, is refused before anything changes. The spec declares the transformers 5.8 the decompression needs, and records that transformers ships its own Kimi-K2.5 port from 5.13, which the adapter refuses: expert parallelism runs on the checkpoint's own code (trust_remote_code=True). The shared adapter tests and the remote-Kimi refusal test run on Kimi-K2.5 too. Moved out of the Kimi adapters change, whose history is archived. Signed-off-by: Shengliang Xu <[email protected]>
… what its missing MoE section skips transformers ships Kimi-K2.5 from 5.13, and the registry pairs a transformers modeling_source with that release, so a remote_code claim would be stale from 5.13 on, though prepare runs the checkpoint's own code. As for Kimi-VL, is_moe does not recognize the native DeepseekV3MoE blocks prepare installs until the sections are shared. Signed-off-by: Shengliang Xu <[email protected]>
The shared adapter tests, run for Kimi-K2.5 too, already check the load and the swap. What is left is Kimi-K2.5's own: the swap, scoped to modeling_kimi_k25, leaves modeling_deepseek's DeepseekV3ForCausalLM alone. The test fails when the scope is dropped. Signed-off-by: Shengliang Xu <[email protected]>
The plan decision ran the model spec's prepare on a copy of the config before the plan was known, wherever it could still be expert-parallel. For the Kimi models prepare patches the checkpoint's own code, the loader and the config for the whole process, so a run whose plan came out FSDP2-sharded, or whole and refused, kept those patches. The decision now reads the plan the spec states (prepared_ep_plan), on the config Kimi's experts are counted from, and finds the experts through it in the model the checkpoint's own code builds; only an expert-parallel plan then runs prepare, on every rank. Signed-off-by: Shengliang Xu <[email protected]>
…epare The plan decision now builds the model the checkpoint's own code builds, before the spec's prepare runs, and Kimi-VL's and Kimi-K2.5's code only imports on current transformers with the names it lost shimmed and its two-deep imports staged. EPSpec.make_importable runs just that, on every rank in the decision's spec step, whatever plan comes out: it patches no class, config, converter or loader hook. Both Kimi specs name the shared step, which their prepare runs too. EPSpec.prepare, prepared_ep_plan and resolve_distribution_plan now say that prepare runs only for an expert-parallel plan, and the end-to-end test runs the real Kimi prepare through the decision: FSDP2-sharded, or left whole and refused, the checkpoint's own language model class, the loader and the config as read are untouched; an expert-parallel plan swaps in the native language model. Signed-off-by: Shengliang Xu <[email protected]>
From ep-routing's review of the move: prepare's doc names the collective step it runs in, on what config, and the load that prepares a handed plan; make_importable's names its gate and why it must be idempotent; prepared_ep_plan's says deciding attaches it with no prepare; and resolve_distribution_plan names both collective steps. Signed-off-by: Shengliang Xu <[email protected]>
…oad takes decision and the expert-parallel load would refuse its checkpoint's format. Kimi-K2.5's compressed-tensors checkpoint reads as such a format on the config the decision sees, before prepare installs the decompressor, so a decided Kimi-K2.5 run planned without expert parallelism. EPSpec.decompressed_formats states the formats a spec's prepare decompresses as the experts load; the decision counts them among those the load takes, and Kimi-K2.5's spec names compressed- tensors. Signed-off-by: Shengliang Xu <[email protected]>
As CONTRIBUTING asks, and as the Kimi-VL adapter's tests now do: the Kimi-K2.5 adapter's tests move to tests/unit/torch/models/kimi_k25/ test_ep.py, mirroring kimi_k25/ep.py. Signed-off-by: Shengliang Xu <[email protected]>
…ision Measured on Kimi-K2.5's own code: since the plan decision builds the checkpoint's own model on the meta device before prepare, the build fails on transformers 5.18, as post_init calls the VLM class's tie_weights with recompute_mapping, which the remote tie_weights does not take. prepare's swap used to adapt it first. EPSpec.make_importable becomes make_buildable(hf_config, ckpt_path=..., trust_remote_code=...): what the checkpoint's own code needs to import and build on the installed transformers, which may adapt a method to the arguments transformers now passes but changes nothing the model computes or loads. Kimi-VL's and Kimi-K2.5's step also loads the code and adapts its VLM class's tie_weights; the contract now names what it may not patch, as Claude's review asked: an MoE or expert class, a config, a weight converter or a weight-loading hook. New test test_the_build_step_lets_the_checkpoint_s_own_vlm_build_on_this_ transformers builds the tiny Kimi-VL remote code through transformers' own loader after the step, and fails with that TypeError without it. Signed-off-by: Shengliang Xu <[email protected]>
From Claude's review: the test expected the decompressor for compressed-tensors by a literal, beside the spec's decompressed_formats that the plan decision reads. It now expects an install exactly for the formats the spec states, so the spec and prepare cannot drift apart without failing it. Signed-off-by: Shengliang Xu <[email protected]>
…epared From Claude's review: the step that prepares a decided expert-parallel plan is a collective of its own, which carries every prepare refusal, and no test reached it with a rank failing alone. The rank-failure test gains a prepared case: rank 1 states the spec as rank 0 does and fails only where prepare runs, and every rank must raise its error; it fails when that step is not a collective. Signed-off-by: Shengliang Xu <[email protected]>
The test imports the tiny Kimi-VL checkpoint's code through transformers' loader, which keeps it in sys.modules; a later test then found it as a loaded modeling_kimi_vl. It now drops the remote modules it loaded. Signed-off-by: Shengliang Xu <[email protected]>
…o build From Claude's review: make_buildable installed the import shims and the staging before the checks that say nothing of the checkpoint's will be built, a config of transformers' own port, no checkpoint path, or code the load may not run. It now returns before them in those cases, so the step leaves the process as it found it. New test test_the_build_step_installs_nothing_when_there_is_nothing_to_build fails with the shims first. The build-step test also checks that the VLM's language model stays the checkpoint's own, per-expert class. Signed-off-by: Shengliang Xu <[email protected]>
From Claude's review: compressed-tensors was written both in prepare's condition for installing the decompressor and in the spec's decompressed_formats, which the plan decision reads before prepare runs. Both now read kimi_k25.ep.DECOMPRESSED_FORMATS. Signed-off-by: Shengliang Xu <[email protected]>
From Claude's review: make_buildable adapted tie_weights on every loaded module whose name ends with the modeling module's, which from transformers 5.13 includes transformers' own Kimi-K2.5 port, transformers.models.kimi_k25.modeling_kimi_k25, whose class a later load of the port would then use with its keyword arguments dropped. It now goes through _remote_code._apply, which reaches remote modules only, as the swap does. test_the_build_step_leaves_transformers_own_port_alone fails with the unscoped scan. Signed-off-by: Shengliang Xu <[email protected]>
Deciding the plan no longer runs prepare, so a spec whose plan only prepare attaches would have its MoE read as dense and planned without expert parallelism, with no refusal. Both Kimi specs state theirs; the test pins it for every EP spec. Signed-off-by: Shengliang Xu <[email protected]>
…mpresses Signed-off-by: Shengliang Xu <[email protected]> #2746 no longer keeps a loadable flag in the decision: it holds the expert-parallel load's refusal against an MoE, and the formats a spec states it decompresses are not among the reasons.
…sm out too An EP degree of 1 skipped the model spec in the plan decision, yet the decision still builds the model on the meta device. A Kimi checkpoint's own VLM class has a tie_weights that takes none of the keyword arguments transformers 5.18's post_init passes, so planning such a checkpoint with MODELOPT_EP_DEGREE=1 or ep_size=1 failed in the build, before the left-whole refusal or an FSDP2 plan. The decision now runs the spec's build step alone at that degree, on every rank, and nothing else of the spec: no floor, no plan, no prepare. The new test plans a tiny Kimi-VL checkpoint built from its own remote code at ep_size=1, refused whole and planned FSDP2, and fails in the meta build without the change. Signed-off-by: Shengliang Xu <[email protected]>
…g it The decision's meta build, and a load off expert parallelism after it, resolve the class from the same local checkpoint path as the build step, so transformers reuses the module the shim went on, re-executing it only if its files change. Keeping the patch would install a loader hook, which the build step never does. Signed-off-by: Shengliang Xu <[email protected]>
…t states Signed-off-by: Shengliang Xu <[email protected]> #3135 now refuses a spec prepare that returns a config with no base_model_ep_plan where the expert-parallel load reads one. The decision test's stand-in returned the config untouched; a helper now puts the spec's prepared plan on the text config, where the real prepare attaches it, as later Kimi tests need too.
… build step At an EP degree of 1 the decision ran the spec's build step on the config it then returns for the load to build from, while the plan arm hands it a copy: the build step changes no config, but it now gets a copy too. The build step runs only where prepare does not, for the decision, so a spec stating one and no prepare would load expert-parallel with nothing making the checkpoint's code build: a test now requires a prepare beside a build step, as one already requires a stated plan beside a prepare. Signed-off-by: Shengliang Xu <[email protected]>
The decision counts a spec's decompressed_formats as formats the expert-parallel load takes, because its prepare installs the decompressor; a spec stating them and no prepare would have a quantized checkpoint planned expert-parallel that nothing decompresses. A test now catches that at the spec, beside the checks that a prepare states its plan and a build step comes with a prepare. Signed-off-by: Shengliang Xu <[email protected]>
The decision reads a spec's prepared_ep_plan and may plan the model expert-parallel on it, but only prepare attaches that plan for the load: a spec stating it and no prepare would have the expert-parallel load refuse the model after the decision, with no plan on its config. A test now catches that at the spec, beside the checks that a prepare states its plan and that a build step and decompressed formats come with a prepare. Signed-off-by: Shengliang Xu <[email protected]>
|
/ok to test d24b5f5 |
|
Folded into #3138, its parent, so the Kimi-VL and Kimi-K2.5 adapters are reviewed as one change. #3138's branch now holds this PR's commits as they are (fast-forwarded to d24b5f5), and its description carries this one's content. The review history stays here; please review the combined change in #3138. The branch is kept, and #2749 now targets #3138's branch. |
Note
Split at the reviewers' request (2026-10-30): this PR is now [2/2], the Kimi-K2.5 adapter.
_kimi.py) and the shared deepseek_v3 plan.keep_patchedmoved to [OMNIML-6063] [1/3] Stage and keep patched a checkpoint's own modeling code #3130.Base: #3138. The diff below is this PR's alone, and it merges after #3138.
Series layout
main([OMNIML-6063] [1/3] Stage and keep patched a checkpoint's own modeling code #3130, [OMNIML-6060] [1/3] Add require_transformers, and build a VLM without its LM head #3131, [OMNIML-6079] [1/2] Fix Kimi-K3's own modeling code for current transformers and fla-core #3132, [OMNIML-6076] [1/3] Describe expert parallelism in the model specs #3134, [OMNIML-6076] [2/3] Prepare a model's config for expert parallelism from its spec #3135, [OMNIML-6054] [1/2] Move fsdp2_wrap out of distributed.py into fsdp2_utils #3140, [OMNIML-6054] [2/2] Route load_pretrained by the distribution plan #2779, [OMNIML-6073] [2/2] Calibrate fused experts on grouped_mm and torch_a2a instead of forcing eager #3074, [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 have merged)prepareon the expert-parallel route only (this PR)What does this PR do?
Type of change: New feature
Kimi-K2.5 (and Kimi-K2.6 and Kimi-K2.7-Code, which share its model type) is Kimi-VL's shape with compressed-tensors INT4 experts. Its adapter swaps in transformers' native
deepseek_v3language model as Kimi-VL's does (#3138), through the patch they share, and decompresses the experts as they load (#3137, #2747).config.jsonkeeps the compressed-tensors config undertext_config, and its config class also copies it to the top level, which the expert-parallel load drops.prepareinstalls the decompressor first of all, so a checkpoint the decompressor refuses leaves the config and the loader untouched.quantization_configdeclares compressed-tensors, as Kimi-K2.5, K2.6 and K2.7-Code all do.quantization_configthe config class keeps on the top level.text_configalone, with no top-level copy, is refused before anything changes.preparenow runs only on the expert-parallel route. Before, the plan decision ran a model spec'sprepareon a copy of the config before the plan was known, and the Kimi patches it made (the swapped language-model class, the decompressor's loader hooks) stayed in the process when the plan came out FSDP2-sharded, or whole and refused. Now:prepared_ep_plan, ontext_configfor both Kimi specs) and finds the experts through it in the model the checkpoint's own code builds;EPSpec.make_buildable, what the checkpoint's own code needs to import and build on the installed transformers: the import shims, the staging of the code's two-deep imports, and the VLM class'stie_weightsadapted to the keyword argumentspost_initpasses it. It changes nothing the model computes or loads, and patches no MoE or expert class, config, weight converter or weight-loading hook;prepare, on every rank, and returns that config; any other plan returns the config as read.EPSpec.prepare's,prepared_ep_plan's andresolve_distribution_plan's docs say so, replacing #2746's interim contract. Kimi-VL's spec (#3138) takes it here too, and Kimi-K3 (#2749), now on this PR, uses it.Why transformers' own Kimi-K2.5 port is refused. transformers 5.13 added a Kimi-K2.5 port, which a load without
trust_remote_codebuilds. Its language model is a nativedeepseek_v3with fused experts, so expert parallelism could run on it without these patches. This adapter does not target it, for three reasons:wqkvinto q/k/v. The export would have to map all of them back to the checkpoint's names for vLLM.So the adapter refuses the port's config before it changes anything, naming
trust_remote_code=Truefrom a checkpoint whoseauto_mapnames its ownAutoConfigas the way in. Supporting the port is a follow-up that needs its own run on the real checkpoints. The spec records the 5.13 release.Why it patches the checkpoint's module, and again on every class resolution: see #3130, where
keep_patchedlives.Usage
Picked automatically by
apply_distributed_supportforkimi_k25configs undertorchrun; see #2754.Testing
tests/unit/torch/models/test_kimi_k25_ep.py, against a stand-in remote module, covers:DeepseekV3Configfor compressed-tensors, bf16 and block-FP8 experts, with the decompressor installed for compressed-tensors ones only. The bf16 and block-FP8 cases fail with an unconditional install.text_configis still present, and a decompressor refusal leavingtext_configand the remote-code staging untouched;The shared adapter tests ([OMNIML-6078] Add the Kimi-VL and Kimi-K2.5 expert-parallel adapters #3138's
test_kimi_vl_ep.py) and the remote-Kimi refusal test intest_model_load_utils.pygain their Kimi-K2.5 cases.Locally at this head:
tests/unit/torch/modelsandtest_model_load_utils.pypass on CPU, torch 2.14, on transformers 5.18 and 5.5.4.GPU tests were not re-run on this revision. Earlier real-model runs (with the module-reload fix, through the decompressor): Kimi-K2.7-Code, expert-parallel over 32 GPUs (8 nodes, EP32), transformers 5.13.0, compressed-tensors 0.17.1, recipe
nvfp4_experts_only_mse-kv_fp8_cast, 4096 calibration samples of 4096 tokens, batch 1. Load, calibration and export completed:DeepseekV3ForCausalLMon the native configRe-cut on 2026-10-29 onto [OMNIML-6076] [3/3] Apply the model spec when deciding and loading expert-parallel #2746 and [OMNIML-6063] [3/3] Load a checkpoint its model spec decompresses through the expert-parallel loader #2747, and split on 2026-10-30; the history before is archived. Review fixes then:
2026-10-30: rebased onto main 99c3834, through the new [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 (which now refuses compressed tensors the model leaves unplaced), [OMNIML-6063] [1/3] Stage and keep patched a checkpoint's own modeling code #3130 and [OMNIML-6079] [1/2] Fix Kimi-K3's own modeling code for current transformers and fla-core #3132, with no conflicts and the own diff unchanged. Pre-commit against main passes, mypy included;
tests/unit/torch/models,test_model_load_utils.pyandtest_ep_loader.pypass on CPU, torch 2.14, on transformers 5.18 and 5.5.4.2026-10-30, review round: the spec's comment says why
modeling_sourcestaystransformers, and its docstring names theis_moegap as Kimi-VL's does; the Kimi-K2.5 swap test keeps only its sibling-module claim (it fails when the patch's suffix scope is dropped), since the shared adapter tests check the swap. Rebased onto [OMNIML-6078] Add the Kimi-VL and Kimi-K2.5 expert-parallel adapters #3138's new head. Pre-commit against main passes, mypy included;tests/unit/torch/models,test_model_load_utils.pyandtest_ep_loader.pypass on CPU, torch 2.14, on transformers 5.18 and 5.5.4.2026-10-30: rebased onto the rebuilt base: main 7168107, where [OMNIML-6063] [1/3] Stage and keep patched a checkpoint's own modeling code #3130 and [OMNIML-6079] [1/2] Fix Kimi-K3's own modeling code for current transformers and fla-core #3132 have merged, joined with [OMNIML-6076] [3/3] Apply the model spec when deciding and loading expert-parallel #2746 5d51cd6 and [OMNIML-6063] [3/3] Load a checkpoint its model spec decompresses through the expert-parallel loader #2747 4494480. There were no conflicts in this PR and its own diff is unchanged. Pre-commit against main passes, mypy included. On CPU, torch 2.14, with transformers 5.18 and 5.5.4, these pass:
tests/unit/torch/models,test_model_load_utils.py,test_ep_loader.py,test_unplaced_source_keys.py.2026-10-30: rebased onto [OMNIML-6078] Add the Kimi-VL and Kimi-K2.5 expert-parallel adapters #3138 9e2cd9a, whose Kimi swap now builds the native language model only from the config
preparemade. Without that, a load kept off expert parallelism after deciding had prepared a copy of the config failed. The own diff is unchanged. [OMNIML-6078] Add the Kimi-VL and Kimi-K2.5 expert-parallel adapters #3138's new test runs for Kimi-K2.5 too. Pre-commit against main passes.tests/unit/torch/models,test_model_load_utils.pyandtest_ep_loader.pypass on CPU, torch 2.14, on transformers 5.18 and 5.5.4.2026-10-30: rebased onto the rebuilt base: [OMNIML-6076] [3/3] Apply the model spec when deciding and loading expert-parallel #2746 ffb58cf joined with [OMNIML-6063] [3/3] Load a checkpoint its model spec decompresses through the expert-parallel loader #2747 0f0570b, whose decompressor ([OMNIML-6063] [2/2] Decompress compressed-tensors MoE experts as they load, expert-parallel loads included #3137) now reverses its converters as the ones it rewrote, so a decompressed checkpoint's export keeps the checkpoint's names. No conflicts in this PR; the own diff is unchanged. Pre-commit against main passes.
tests/unit/torch/models,test_model_load_utils.py,test_ep_loader.pyandtest_unplaced_source_keys.pypass on CPU, torch 2.14: 593 on transformers 5.18, and 451 passed, 57 skipped on 5.5.4.2026-10-30: rebased onto [OMNIML-6078] Add the Kimi-VL and Kimi-K2.5 expert-parallel adapters #3138 9ef474a, on the rebuilt base: [OMNIML-6076] [3/3] Apply the model spec when deciding and loading expert-parallel #2746 d3a058e joined with [OMNIML-6063] [3/3] Load a checkpoint its model spec decompresses through the expert-parallel loader #2747 dc0a618. The own diff is unchanged. Pre-commit against main passes, mypy included. On CPU, torch 2.14,
tests/unit/torch/modelsandtests/unit/torch/utilspass on transformers 5.18 and 5.5.4.2026-10-30: rebased onto [OMNIML-6078] Add the Kimi-VL and Kimi-K2.5 expert-parallel adapters #3138 b4847b8, on the rebuilt base: main 059588b, with [OMNIML-6076] [3/3] Apply the model spec when deciding and loading expert-parallel #2746 0eadf4c joined with [OMNIML-6063] [3/3] Load a checkpoint its model spec decompresses through the expert-parallel loader #2747 23eb10d. The own diff is unchanged. Pre-commit against main passes, mypy included. On CPU, torch 2.14,
tests/unit/torch/modelsandtests/unit/torch/utilspass on transformers 5.18 and 5.5.4.2026-10-31, on the user's decision:
prepareruns only on the expert-parallel route (53fc43c, 1df64fd, 7691431), and a checkpoint a spec decompresses counts as one the expert-parallel load takes (57be464). Rebased onto main d464d30, with [OMNIML-6076] [3/3] Apply the model spec when deciding and loading expert-parallel #2746 9267a0b and [OMNIML-6063] [3/3] Load a checkpoint its model spec decompresses through the expert-parallel loader #2747 7d78ca1:test_only_an_expert_parallel_plan_patches_the_checkpoint_s_code[fsdp2|whole|expert-parallel]runs the real Kimi-VL and Kimi-K2.5preparethrough the decision. FSDP2-sharded, or left whole and refused, the checkpoint's own language-model class, the loader hooks and the config as read are untouched; an expert-parallel plan swaps in the native language model. The fsdp2 and whole cases fail on the old decision;test_a_checkpoint_its_spec_decompresses_is_decided_expert_parallel: a compressed-tensors Kimi-K2.5 checkpoint left to the decision is planned expert-parallel, and a Kimi-VL one is not; the Kimi-K2.5 case fails without the spec's formats;test_a_load_prepares_its_config_oncenow counts real preparations only;tests/unit/torch/modelsandtests/unit/torch/utilspass on transformers 5.18 and 5.5.4;load_pretrainedintests/gpu/torch/utils/test_expert_parallel_load.pytake the new decision: at [OMNIML-6079] [2/3] Add the Kimi-K3 expert-parallel adapter #2749 63c8267, which contains this head, the whole file passed with transformers 5.18.0, on 2 GPUs (4 passed,[ep-half]skipped as it needs 4) and on 4 GPUs (all 5). No GPU case exercises the decision's fallback to no expert parallelism, which the CPU rows above cover.2026-10-31, Claude's review of the move, at 27961b6, rebased onto main d464d30 with [OMNIML-6076] [3/3] Apply the model spec when deciding and loading expert-parallel #2746 77c4117 and [OMNIML-6063] [3/3] Load a checkpoint its model spec decompresses through the expert-parallel loader #2747 7d78ca1:
the decision's meta build of real Kimi-K2.5 code failed on transformers 5.18, because the remote
tie_weightstakes no keyword arguments; the build step (make_buildable, 385d420) adapts it.test_the_build_step_lets_the_checkpoint_s_own_vlm_build_on_this_transformersbuilds the tiny Kimi-VL remote code through transformers' own loader after the step, and fails with that TypeError without it;the decision's cost, measured on the real Kimi-K2.5 code and config (61 layers, 384 routed experts) on the meta device, transformers 5.18, one process; only rank 0 builds:
a rank failing alone in the step that prepares a decided expert-parallel plan fails every rank (
test_a_rank_that_cannot_apply_the_spec_fails_every_rank[prepared]), and the Kimi-K2.5 decompressor test derives its expectation from the spec'sdecompressed_formats;pre-commit against main passes, mypy included; on CPU, torch 2.14,
tests/unit/torch/modelsandtests/unit/torch/utilspass on transformers 5.18 and 5.5.4. At [OMNIML-6079] [2/3] Add the Kimi-K3 expert-parallel adapter #2749 183bf95, which contains this PR, the whole GPU file passed with transformers 5.18.0 and compressed-tensors 0.19.0: on 2 GPUs, 5 passed and[ep-half]skipped, as it needs 4; on 4 GPUs, all 6 passed. Its Kimi cases load through the spec and the loader directly, not through the plan decision, so the build step's coverage is the CPU test above and the measurement on Kimi-K2.5's code.2026-10-31, Claude's review, at 777ac2a: the build step installs nothing when there is nothing of the checkpoint's to build (fab6ddf;
test_the_build_step_installs_nothing_when_there_is_nothing_to_buildfails with the shims first), and Kimi-K2.5's decompressed formats are stated once (777ac2a). Pre-commit against main passes, mypy included;tests/unit/torch/modelsandtests/unit/torch/utilspass on CPU, torch 2.14, on transformers 5.18 and 5.5.4.2026-10-31, at f3df820: at [OMNIML-6079] [2/3] Add the Kimi-K3 expert-parallel adapter #2749 4389363, which contains this PR at 777ac2a, the whole GPU file passed, with transformers 5.18.0 and compressed-tensors 0.19.0: on 2 GPUs, 5 passed and
[ep-half]skipped, as it needs 4; on 4 GPUs, all 6 passed. Its Kimi cases load through the spec and the loader directly, not through the plan decision. Since then, from Claude's review, the build step'stie_weightsshim goes through_remote_code._apply, so it reaches remote modules only and leaves transformers' own Kimi-K2.5 port alone (test_the_build_step_leaves_transformers_own_port_alonefails without it). No GPU case runs the build step. Pre-commit against main passes, mypy included;tests/unit/torch/modelsandtests/unit/torch/utilspass on CPU, torch 2.14, on transformers 5.18 and 5.5.4.2026-10-31, at b88d349: rebased onto [OMNIML-6078] Add the Kimi-VL and Kimi-K2.5 expert-parallel adapters #3138 d2321c1, on main e352cac with [OMNIML-6076] [3/3] Apply the model spec when deciding and loading expert-parallel #2746 d8059b3 and [OMNIML-6063] [3/3] Load a checkpoint its model spec decompresses through the expert-parallel loader #2747 6b87b69. [OMNIML-6076] [3/3] Apply the model spec when deciding and loading expert-parallel #2746 now attaches a spec's plan behind its own existing-plan check, and its
_ep_load_refusalreturns the error and no longer reads the spec; this PR's stated-plan selection keeps that check, and_ep_load_refusalreads the spec only for itsdecompressed_formats. From Claude's review,test_a_spec_with_a_prepare_states_its_plan(7a1f1cf) asserts that every EP spec with apreparestates its plan; it fails for both Kimi specs withprepared_ep_plandropped. At [OMNIML-6079] [2/3] Add the Kimi-K3 expert-parallel adapter #2749 a60c01c, which contains this head, the whole GPU file passed, with transformers 5.18.0 and compressed-tensors 0.19.0: on 2 GPUs, 5 passed and[ep-half]skipped, as it needs 4; on 4 GPUs, all 6 passed. Its Kimi cases load through the spec and the loader directly, not through the plan decision. Pre-commit against main passes, mypy included;tests/unit/torch/modelsandtests/unit/torch/utilspass on CPU, torch 2.14, on transformers 5.18 and 5.5.4.2026-10-31, at 0d86f37: rebased onto [OMNIML-6078] Add the Kimi-VL and Kimi-K2.5 expert-parallel adapters #3138 cb90789, on the rebuilt base whose [OMNIML-6063] [2/2] Decompress compressed-tensors MoE experts as they load, expert-parallel loads included #3137 now refuses a compressed-tensors older than 0.16; no conflicts, and the own diff is unchanged. Pre-commit against main passes, mypy included;
tests/unit/torch/modelsandtests/unit/torch/utilspass on CPU, torch 2.14, on transformers 5.18 and 5.5.4.2026-10-31, at c09680f: rebased onto [OMNIML-6078] Add the Kimi-VL and Kimi-K2.5 expert-parallel adapters #3138 7849516 on the rebuilt base; no conflicts, and the own diff is unchanged. Pre-commit against main passes, mypy included;
tests/unit/torch/modelsandtests/unit/torch/utilspass on CPU, torch 2.14, on transformers 5.18 and 5.5.4.2026-10-31, at 797f2d1, from a review of [OMNIML-6079] [2/3] Add the Kimi-K3 expert-parallel adapter #2749: the plan decision builds the model at an EP degree of 1 too, and a Kimi checkpoint's own VLM class has a
tie_weightswithout the keyword arguments transformers 5.18'spost_initpasses, so planning one atep_size=1(orMODELOPT_EP_DEGREE=1) failed in the meta build, before the left-whole refusal or an FSDP2 plan. The decision now runs the spec's build step alone at that degree, on every rank: no floor, no plan, noprepare.test_an_ep_degree_of_1_builds_the_checkpoint_s_own_vlm_to_decide[whole|fsdp2]plans a tiny Kimi-VL checkpoint atep_size=1through the real meta build of its own remote code, and fails without the change. Pre-commit against main passes, mypy included;tests/unit/torch/modelsandtests/unit/torch/utilspass on CPU, torch 2.14, on transformers 5.18 and 5.5.4.2026-10-31, at 4bbaecd, from Claude's review: a comment records why the build step shims
tie_weightsonce rather than keeping the patch: the builds that follow resolve the class from the same local checkpoint path, so transformers reuses the shimmed module, and keeping it would hook the loader, which the build step never does. Comment only. Pre-commit against main passes, mypy included;tests/unit/torch/modelsandtests/unit/torch/utilspass on CPU, torch 2.14, on transformers 5.18 and 5.5.4.2026-10-31: at [OMNIML-6079] [2/3] Add the Kimi-K3 expert-parallel adapter #2749 76fcf09, which contains this PR at 4bbaecd, the whole GPU file passed, with transformers 5.18.0, compressed-tensors 0.20.1 and torch 2.15: on 2 GPUs, 5 passed and
[ep-half]skipped, as it needs 4; on 4 GPUs, all 6 passed. Its Kimi cases load through the spec and the loader directly, not through the plan decision.2026-11-01, at e3a391d: rebased onto [OMNIML-6078] Add the Kimi-VL and Kimi-K2.5 expert-parallel adapters #3138 e3d66fa on the rebuilt base (main cf38ec3). The same test-placement conflict as [OMNIML-6078] Add the Kimi-VL and Kimi-K2.5 expert-parallel adapters #3138's, resolved the same way; the own diff is unchanged. Pre-commit against main passes, mypy included;
test_model_load_utils.py,tests/unit/torch/models/kimi_k25,kimi_vlandtest_ep_specs.py, run in one process, pass on CPU, torch 2.14, on transformers 5.18 and 5.5.4.2026-11-01, at 11497fe: rebased onto [OMNIML-6078] Add the Kimi-VL and Kimi-K2.5 expert-parallel adapters #3138 4ff7f66 on the rebuilt base, which 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 with a plan where the load reads one. The check stays right after thepreparecall, ahead of this PR's build-step arm. The Kimi-K2.5 decision test's stand-inpreparenow attaches the plan its spec states, where the real one does (_prepares_as_its_spec_states). Pre-commit against main passes, mypy included;test_model_load_utils.py,tests/unit/torch/models/kimi_k25,kimi_vlandtest_ep_specs.py, run in one process, pass on CPU, torch 2.14, on transformers 5.18 and 5.5.4.2026-11-01: at [OMNIML-6079] [2/3] Add the Kimi-K3 expert-parallel adapter #2749 0ea01fe, which contains this PR at 11497fe, the whole GPU file passed, with transformers 5.18.0 and compressed-tensors 0.20.1: on 2 GPUs, 5 passed and
[ep-half]skipped, as it needs 4; on 4 GPUs, all 6 passed, in the file's order and again in reverse, with the Kimi-K3 case first. Its Kimi cases load through the spec and the loader directly, not through the plan decision.2026-11-01, at d997459, from Claude's review: at an EP degree of 1 the decision hands the spec's build step a copy of the config, as the plan arm does, since the config is returned and the load builds from it; and
test_a_spec_with_a_build_step_preparesrequires apreparebeside anymake_buildable, as the build step runs only for the decision (it fails for a Kimi-K2.5 spec with itspreparedropped). Pre-commit against main passes, mypy included;test_model_load_utils.py,tests/unit/torch/models/kimi_k25,kimi_vlandtest_ep_specs.py, run in one process, pass on CPU, torch 2.14, on transformers 5.18 and 5.5.4.2026-11-01, at 811a7e3, from Claude's review:
test_a_spec_decompresses_only_in_a_preparerequires apreparebeside anydecompressed_formats, the third of the spec-field checks intest_ep_specs.py; it fails for a Kimi-K2.5 spec with itspreparedropped. Test only; pre-commit against main passes, andtest_ep_specs.pypasses on CPU, torch 2.14, on transformers 5.18 and 5.5.4.2026-11-02, at bf37395: rebased onto [OMNIML-6078] Add the Kimi-VL and Kimi-K2.5 expert-parallel adapters #3138 299afb6 on the rebuilt base. The base's plan decision now leaves the model spec out under
init_quantized_weightswith the EP degree left to auto; this PR's spec step keeps that as part of its "plan" condition, so in that case only the build step runs, as at an EP degree of 1. The base no longer imports_ep_specintomodel_load_utils, so this PR imports it for the build step. The rest of the own diff is unchanged. Pre-commit against main passes, mypy included;tests/unit/torch/modelsandtests/unit/torch/utils, run in one process, pass on CPU, torch 2.14, on transformers 5.18 and 5.5.4.2026-11-02, at 5a3092d, from Claude's review:
test_a_spec_states_a_prepared_plan_only_with_a_preparerequires apreparebeside anyprepared_ep_plan, the fourth of the spec-field checks intest_ep_specs.py; it fails for a Kimi-VL spec with itspreparedropped. Test only; pre-commit against main passes, andtest_ep_specs.pypasses on CPU, torch 2.14, on transformers 5.18 and 5.5.4.2026-11-02, at d19ee63: rebased onto [OMNIML-6078] Add the Kimi-VL and Kimi-K2.5 expert-parallel adapters #3138 7eb48c0 on the rebuilt base, main 4f08a12. No conflicts; the own diff is unchanged. Pre-commit against main passes, mypy included;
tests/unit/torch/modelsandtests/unit/torch/utils, run in one process, pass on CPU, torch 2.14, on transformers 5.18 and 5.5.4.2026-11-02: at [OMNIML-6079] [2/3] Add the Kimi-K3 expert-parallel adapter #2749 7cfcd54, which contains this PR at d19ee63, the whole GPU file passed, with transformers 5.18.0 and compressed-tensors 0.20.1: on 2 GPUs, 5 passed and
[ep-half]skipped, as it needs 4; on 4 GPUs, all 6 passed, in the file's order and again in reverse. Its Kimi cases load through the spec and the loader directly, not through the plan decision.2026-11-02, at d24b5f5: rebased onto [OMNIML-6078] Add the Kimi-VL and Kimi-K2.5 expert-parallel adapters #3138 0b489fb on the rebuilt base, main 653ef61. No conflicts; the own diff is unchanged. Pre-commit against main passes, mypy included;
tests/unit/torch/modelsandtests/unit/torch/utils, run in one process, pass on CPU, torch 2.14, on transformers 5.18 and 5.5.4.Before your PR is "Ready for review"
CONTRIBUTING.md: N/AAdditional Information
Part of expert-parallel PTQ for Hugging Face MoE models, [2/2] of #2748's split. It merges after #3138.