Skip to content

[OMNIML-6078] [2/2] Add the Kimi-K2.5 expert-parallel adapter - #2748

Closed
shengliangxu wants to merge 23 commits into
shengliangx/hfep-11b0-kimi-vlfrom
shengliangx/hfep-11b-kimi-k25-vl
Closed

shengliangxu wants to merge 23 commits into
shengliangx/hfep-11b0-kimi-vlfrom
shengliangx/hfep-11b-kimi-k25-vl

Conversation

@shengliangxu

@shengliangxu shengliangxu commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator

Note

Split at the reviewers' request (2026-10-30): this PR is now [2/2], the Kimi-K2.5 adapter.

Base: #3138. The diff below is this PR's alone, and it merges after #3138.

Series layout

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_v3 language model as Kimi-VL's does (#3138), through the patch they share, and decompresses the experts as they load (#3137, #2747).

  • Install order. The checkpoint's config.json keeps the compressed-tensors config under text_config, and its config class also copies it to the top level, which the expert-parallel load drops. prepare installs the decompressor first of all, so a checkpoint the decompressor refuses leaves the config and the loader untouched.
  • Which checkpoints decompress. It installs the decompressor only for a checkpoint whose quantization_config declares compressed-tensors, as Kimi-K2.5, K2.6 and K2.7-Code all do.
    • A bf16 checkpoint of the model type loads as Kimi-VL's does.
    • Any other scheme is left to the expert-parallel load's format handling, which reads the copy of quantization_config the config class keeps on the top level.
    • A scheme on text_config alone, with no top-level copy, is refused before anything changes.
  • transformers floor. The spec declares the transformers 5.8 the decompression needs.

prepare now runs only on the expert-parallel route. Before, the plan decision ran a model spec's prepare on 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:

  • the decision reads the plan the spec states (prepared_ep_plan, on text_config for both Kimi specs) and finds the experts through it in the model the checkpoint's own code builds;
  • before that it runs only 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's tie_weights adapted to the keyword arguments post_init passes it. It changes nothing the model computes or loads, and patches no MoE or expert class, config, weight converter or weight-loading hook;
  • only an expert-parallel plan then runs prepare, on every rank, and returns that config; any other plan returns the config as read.

EPSpec.prepare's, prepared_ep_plan's and resolve_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_code builds. Its language model is a native deepseek_v3 with fused experts, so expert parallelism could run on it without these patches. This adapter does not target it, for three reasons:

  • Different names. The port re-implements the vision tower and the projector under other names. Its load-time conversions rename the vision blocks' norms, MLPs and output projection and the projector, and split the fused wqkv into q/k/v. The export would have to map all of them back to the checkpoint's names for vLLM.
  • Not validated. Expert-parallel PTQ has been validated end to end only on the checkpoint's own code.
  • Needed anyway. The adapter is needed from 5.8 either way, before the port exists.

So the adapter refuses the port's config before it changes anything, naming trust_remote_code=True from a checkpoint whose auto_map names its own AutoConfig as 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_patched lives.

  • The VLM class builds its language model from a name it looks up in its module's globals.
  • transformers re-executes or re-imports that module under the loaders that resolve the class.

Usage

Picked automatically by apply_distributed_support for kimi_k25 configs under torchrun; see #2754.

Testing

Before your PR is "Ready for review"

  • Is this change backward compatible?: ✅ Additive; runs only on the expert-parallel path.
  • If you copied code from any other sources or added a new PIP dependency, did you follow guidance in CONTRIBUTING.md: N/A
  • Did you write any new necessary tests?: ✅
  • Did you update Changelog?: N/A. The feature's entry lands with [OMNIML-6085] [3/3] Run expert-parallel PTQ from hf_ptq.py #2754.
  • Did you get Claude approval on this PR?: ❌ Not since the split.

Additional Information

Part of expert-parallel PTQ for Hugging Face MoE models, [2/2] of #2748's split. It merges after #3138.

@copy-pr-bot

copy-pr-bot Bot commented Oct 12, 2026

Copy link
Copy Markdown

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.

@coderabbitai

coderabbitai Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
Walkthrough

Adds model registration and expert-parallel preparation for Kimi-K2.5 and Kimi-VL. Both adapters convert the text configuration to a native DeepSeek-V3 configuration and apply an expert-parallel plan. Kimi-K2.5 also installs expert decompression. Each adapter can patch remote modeling code when a checkpoint path is provided.

Changes: Kimi expert-parallel adapters

Layer / File(s) Summary
Model registration and shared EP plan
modelopt/torch/models/__init__.py, modelopt/torch/models/deepseek_v3/specs.py, modelopt/torch/models/kimi_k25/*, modelopt/torch/models/kimi_vl/*, tests/unit/torch/utils/test_resolve_distribution_plan.py
Registers both Kimi model packages and exposes the DeepSeek-V3 EP plan for their specifications. Tests check specification registration and EP plan resolution for remote Kimi MoE experts.
Kimi-K2.5 preparation
modelopt/torch/models/kimi_k25/ep.py, tests/unit/torch/models/test_kimi_k25_ep.py
Converts text_config, installs expert decompression, and applies the EP plan. When a checkpoint path is provided, replaces the remote modeling class with the native Transformers class. Tests cover config preparation, remote-code patching, and trust validation.
Kimi-VL preparation
modelopt/torch/models/kimi_vl/ep.py, tests/unit/torch/models/test_kimi_vl_ep.py
Adds compatibility shims, converts text_config, and applies the EP plan. When a checkpoint path is provided, replaces the remote modeling class and adapts tie_weights. Tests cover preparation, patching, and validation.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant HFConfig
  participant KimiPrepare
  participant DeepseekV3Config
  participant DeepseekV3EPPlan
  participant RemoteModelingModule
  HFConfig->>KimiPrepare: provide text_config
  KimiPrepare->>DeepseekV3Config: convert text_config
  KimiPrepare->>DeepseekV3EPPlan: apply expert-parallel plan
  opt ckpt_path provided
    KimiPrepare->>RemoteModelingModule: load remote code and replace DeepseekV3ForCausalLM
  end
Loading
Merge Risk: Low · up to e0b3f

This PR registers the Kimi expert-parallel adapters. The remaining concerns are limited to package re-export and Kimi-K2.5 metadata conventions; no resulting user-facing failure is established, so the change is mergeable with bounded follow-up.

Pre-merge checks: Passed 5
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Security Anti-Patterns Passed No listed security anti-pattern was introduced. The Kimi adapters define trust_remote_code: bool = False, reject checkpoint loading when it is false, and pass the caller-controlled value to the dyna…
Title check Passed The title accurately identifies the Kimi-K2.5 expert-parallel adapter, which is a major part of the changeset. It does not mention the additional Kimi-VL adapter, but the title remains clear and relat…
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Security Anti-Patterns

Explanation

No listed security anti-pattern was introduced. The Kimi adapters define trust_remote_code: bool = False, reject checkpoint loading when it is false, and pass the caller-controlled value to the dynamic loader. No added torch.load(..., weights_only=False), numpy.load(..., allow_pickle=True), eval, exec, or # nosec usage appears in the Python diff. No dependency-file changes were made.

Full details: Title check

Explanation

The title accurately identifies the Kimi-K2.5 expert-parallel adapter, which is a major part of the changeset. It does not mention the additional Kimi-VL adapter, but the title remains clear and related.

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
Fix failing CI checks
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.

@shengliangxu
shengliangxu added this pull request to stack #2755 October 12, 2026 00:57
@shengliangxu
shengliangxu force-pushed the shengliangx/hfep-11a-onfly-decompress branch from 95832dd to e243f04 Compare October 12, 2026 02:35
@shengliangxu
shengliangxu force-pushed the shengliangx/hfep-11b-kimi-k25-vl branch from f73bc4f to 0098f3a Compare October 12, 2026 02:35
@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://NVIDIA.github.io/Model-Optimizer/pr-preview/pr-2748/

Built to branch gh-pages at 2026-10-27 00:07 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@codecov

codecov Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.38843% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 62.52%. Comparing base (17f4119) to head (e83762c).

Files with missing lines Patch % Lines
modelopt/torch/models/_kimi.py 84.90% 8 Missing ⚠️
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     
Flag Coverage Δ
unit 62.52% <93.38%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@shengliangxu

Copy link
Copy Markdown
Collaborator Author

/ok to test 0098f3a

@shengliangxu
shengliangxu force-pushed the shengliangx/hfep-11a-onfly-decompress branch from e243f04 to d6afd32 Compare October 12, 2026 08:39
@shengliangxu
shengliangxu force-pushed the shengliangx/hfep-11b-kimi-k25-vl branch from 0098f3a to 3d6fb9d Compare October 12, 2026 08:39
@shengliangxu

Copy link
Copy Markdown
Collaborator Author

/ok to test 3d6fb9d

@shengliangxu shengliangxu changed the title [13/19] Add the Kimi-K2.5 and Kimi-VL expert-parallel adapters [OMNIML-6078] [13/19] Add the Kimi-K2.5 and Kimi-VL expert-parallel adapters Oct 12, 2026
@shengliangxu
shengliangxu force-pushed the shengliangx/hfep-11a-onfly-decompress branch from d6afd32 to 67355f4 Compare October 13, 2026 00:53
@shengliangxu
shengliangxu force-pushed the shengliangx/hfep-11b-kimi-k25-vl branch 2 times, most recently from 1c16b42 to ecf9d71 Compare October 13, 2026 01:32
@shengliangxu
shengliangxu force-pushed the shengliangx/hfep-11a-onfly-decompress branch from 67355f4 to b162532 Compare October 13, 2026 01:32
@shengliangxu

Copy link
Copy Markdown
Collaborator Author

/ok to test ecf9d71

@shengliangxu
shengliangxu removed this pull request from stack #2755 October 13, 2026 17:42
@shengliangxu
shengliangxu added this pull request to stack #2775 October 13, 2026 17:43
@shengliangxu shengliangxu changed the title [OMNIML-6078] [13/19] Add the Kimi-K2.5 and Kimi-VL expert-parallel adapters [OMNIML-6078] [13/20] Add the Kimi-K2.5 and Kimi-VL expert-parallel adapters Oct 13, 2026
@shengliangxu
shengliangxu force-pushed the shengliangx/hfep-11b-kimi-k25-vl branch from ecf9d71 to d525e64 Compare October 13, 2026 19:38
@shengliangxu
shengliangxu removed this pull request from stack #2775 October 13, 2026 19:38
@shengliangxu
shengliangxu added this pull request to stack #2781 October 13, 2026 19:40
@shengliangxu shengliangxu changed the title [OMNIML-6078] [13/20] Add the Kimi-K2.5 and Kimi-VL expert-parallel adapters [OMNIML-6078] [15/21] Add the Kimi-K2.5 and Kimi-VL expert-parallel adapters Oct 13, 2026
@shengliangxu

Copy link
Copy Markdown
Collaborator Author

/ok to test d525e64

@shengliangxu
shengliangxu force-pushed the shengliangx/hfep-11a-onfly-decompress branch from 269d3d2 to dddc2ee Compare October 13, 2026 21:12
@shengliangxu
shengliangxu force-pushed the shengliangx/hfep-11b-kimi-k25-vl branch from d525e64 to 0c39a27 Compare October 13, 2026 21:12
@shengliangxu

Copy link
Copy Markdown
Collaborator Author

/ok to test 0c39a27

@shengliangxu
shengliangxu removed this pull request from stack #2781 October 14, 2026 00:13
@shengliangxu
shengliangxu force-pushed the shengliangx/hfep-11a-onfly-decompress branch from dddc2ee to c668ec2 Compare October 14, 2026 00:14
@shengliangxu

Copy link
Copy Markdown
Collaborator Author

/claude review

Comment on lines +96 to +100
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, (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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), where plan = ep.base_model_ep_plan or (None if prepare else ep.prepared_ep_plan) attaches it (moe.py:278), so _decide_distribution finds the routed experts and can resolve an expert-parallel plan;
  • the "model spec prepared" step then calls apply_distributed_support with prepare=True, where that same expression yields None — nothing is attached — and the returns-a-plan check is inside if prepare and ep.prepare is not None:, so with no prepare it is skipped entirely;
  • load_and_prepare_ep then raises expert-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"
    )

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 — alongside test_a_spec_with_a_prepare_states_its_plan and test_a_spec_with_a_build_step_prepares. Both Kimi specs satisfy all three, and the field defaults to (), so _ep_load_refusal is unchanged for every other spec.
  • Re-traced this round: the "plan"/"build" gate still agrees with when _decide_distribution builds a model (world_size == 1 returns unbuilt, so the gate's world_size > 1 is the right guard), and broadcast_from round-trips the new str payload under weights_only; "model spec prepared" is gated on the broadcast plan, so every rank enters or skips it together; plan_config_attr="text_config" puts prepared_ep_plan where _ep_config reads it, and _routed_expert_modules suffix-matches the backbone-relative globs against the VLM's language_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_plan still returns prepared_ep_plan, so that route finds them too; make_buildable's tie_weights shim goes through _apply, which filters to transformers_modules.*, so transformers' own 5.13 port is left alone; prepared from _sharded_load_kwargs is consulted on the expert-parallel route only, so the FSDP2 route is unaffected by returning the config as read. decompressed_formats is DECOMPRESSED_FORMATS exactly, so the decision and prepare agree on which checkpoints decompress, and load_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_once counts real preparations only, and _one_rank_cannot_apply_the_spec_job gains a prepared step asserting every rank reached the step that prepares a decided plan. No coverage shrank.
  • New files carry LICENSE_HEADER verbatim; ~386 added modelopt/ 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 ⟹ prepare is 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, head bf373955, full scope (bare /claude review), all 15 changed files reviewed.

🤖 Generated with Claude Code

@shengliangxu

Copy link
Copy Markdown
Collaborator Author

/ok to test 5a3092d

@shengliangxu

Copy link
Copy Markdown
Collaborator Author

/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]>
@shengliangxu

Copy link
Copy Markdown
Collaborator Author

/ok to test d24b5f5

@shengliangxu

Copy link
Copy Markdown
Collaborator Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants