Repository navigation
[KimiLinear] Fix test_cpu_offload: set num_local_experts=4 in model tester - #48624
Merged
Merged
Conversation
…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]>
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: kimi_linear |
Collaborator
Author
|
run-slow: kimi_linear |
Contributor
|
This comment contains models: ["models/kimi_linear"] |
Contributor
|
This comment contains models: ["models/kimi_linear"] |
|
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. |
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
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]>
Contributor
CI recapDashboard: View test results in Grafana |
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Root cause:
KimiLinearConfigdefaults tonum_local_experts=256. The model tester only setself.n_routed_experts=8, which is the wrong attribute name (KimiLinearConfigusesnum_local_experts, notn_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_mapcannot fit it within any reasonable GPU budget fraction — it puts everything on CPU (single device).dispatch_modelis then never called,hf_device_mapis never set, andtest_cpu_offloadraisesAttributeError: 'KimiLinearModel' object has no attribute 'hf_device_map'.Fix:
self.num_local_experts = 4in 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 CPUself.n_routed_experts = 8attribute which had no effect on the configTest plan
KimiLinearModelTest::test_cpu_offloadpassesKimiLinearModelTestsuite: 148 passed, 147 skipped, 0 failures🤖 Generated with Claude Code