Skip to content

[KimiLinear] Fix test_cpu_offload: set num_local_experts=4 in model tester - #48624

Merged
ydshieh merged 3 commits into
mainfrom
fix-kimi-linear-cpu-offload
Sep 8, 2026
Merged

ydshieh merged 3 commits into
mainfrom
fix-kimi-linear-cpu-offload

Conversation

@ydshieh

@ydshieh ydshieh commented Sep 8, 2026 •

Copy link
Copy Markdown
Collaborator

CPU CI GPU run-slow

Summary

Root cause: KimiLinearConfig defaults to num_local_experts=256. The model tester only set self.n_routed_experts=8, which is the wrong attribute name (KimiLinearConfig uses num_local_experts, not n_routed_experts) and was silently ignored. As a general rule, model testers should not rely on large default config values — they must explicitly override them with small values suitable for unit tests.

With 256 experts, layers.1 (the MoE decoder layer) accounts for ~94% of total model size. Since _no_split_modules=["KimiLinearDecoderLayer"] makes it atomic, infer_auto_device_map cannot fit it within any reasonable GPU budget fraction — it puts everything on CPU (single device). dispatch_model is then never called, hf_device_map is never set, and test_cpu_offload raises AttributeError: 'KimiLinearModel' object has no attribute 'hf_device_map'.

Fix:

  • Set self.num_local_experts = 4 in the model tester so the config receives a small expert count, making the MoE layer a proportionate fraction of the model and allowing accelerate to correctly split it across GPU and CPU
  • Remove the dead self.n_routed_experts = 8 attribute which had no effect on the config

Test plan

  • KimiLinearModelTest::test_cpu_offload passes
  • Full KimiLinearModelTest suite: 148 passed, 147 skipped, 0 failures

🤖 Generated with Claude Code

…ester

The KimiLinearConfig defaults to num_local_experts=256, but the model tester
only set self.n_routed_experts=8 which is a wrong attribute name and never
mapped to the config. As a result, the test model used 256 experts, making
layers.1 (the MoE layer) ~94% of total model size. With _no_split_modules
constraining layers.1 to be atomic, infer_auto_device_map could never fit it
within any reasonable GPU budget fraction, placing everything on CPU (single
device). dispatch_model was then never called, so hf_device_map was never set,
causing AttributeError in test_cpu_offload.

Fix: set self.num_local_experts=4 so the config receives a small expert count,
making the MoE layer a proportionate fraction of the model and allowing
accelerate to split it across GPU and CPU as intended.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

[For maintainers] Suggested jobs to run (before merge)

run-slow: kimi_linear

@ydshieh

ydshieh commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator Author

run-slow: kimi_linear

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Workflow Run ⚙️

This comment contains run-slow, running the specified jobs on AMD:

models: ["models/kimi_linear"]

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Workflow Run ⚙️

This comment contains run-slow, running the specified jobs:

models: ["models/kimi_linear"]
quantizations: []

@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

CI Results (AMD)

Workflow Run ⚙️

Commit Info

Context Commit Description
RUN f8980996 workflow commit (merge commit)
PR 2774770a branch commit (from PR)
main 0a959de1 base commit (on main)

✅ No failing test specific to this PR 🎉 👏 !

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

CI Results

Workflow Run ⚙️

Commit Info

Context Commit Description
RUN f8980996 workflow commit (merge commit)
PR 2774770a branch commit (from PR)
main 0a959de1 base commit (on main)

✅ No failing test specific to this PR 🎉 👏 !

KimiLinearConfig has no n_routed_experts field — it uses num_local_experts.
The attribute was silently ignored and had no effect on the config.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

CI recap

Dashboard: View test results in Grafana
Latest run: 34257780699:1
Result: success | Jobs: 8 | Tests: 383 | Failures: 0 | Duration: 4m 18s

@ydshieh
ydshieh merged commit 338b33d into main Sep 8, 2026
35 checks passed
@ydshieh
ydshieh deleted the fix-kimi-linear-cpu-offload branch September 8, 2026 17:53
sbucaille pushed a commit to sbucaille/transformers that referenced this pull request Sep 16, 2026
…ester (huggingface#48624)

* [KimiLinear] Fix test_cpu_offload: set num_local_experts=4 in model tester

The KimiLinearConfig defaults to num_local_experts=256, but the model tester
only set self.n_routed_experts=8 which is a wrong attribute name and never
mapped to the config. As a result, the test model used 256 experts, making
layers.1 (the MoE layer) ~94% of total model size. With _no_split_modules
constraining layers.1 to be atomic, infer_auto_device_map could never fit it
within any reasonable GPU budget fraction, placing everything on CPU (single
device). dispatch_model was then never called, so hf_device_map was never set,
causing AttributeError in test_cpu_offload.

Fix: set self.num_local_experts=4 so the config receives a small expert count,
making the MoE layer a proportionate fraction of the model and allowing
accelerate to split it across GPU and CPU as intended.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>

* [KimiLinear] Add comment explaining why num_local_experts=4

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>

* [KimiLinear] Remove dead n_routed_experts attribute from model tester

KimiLinearConfig has no n_routed_experts field — it uses num_local_experts.
The attribute was silently ignored and had no effect on the config.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>

---------

Co-authored-by: ydshieh <[email protected]>
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