Skip to content

fix: make num_experts BC fallback not override explicit n_routed_experts#47409

Closed
webtecnica wants to merge 1 commit into
huggingface:mainfrom
webtecnica:fix/glm-moe-dsa-num-experts-bc-fallback
Closed

fix: make num_experts BC fallback not override explicit n_routed_experts#47409
webtecnica wants to merge 1 commit into
huggingface:mainfrom
webtecnica:fix/glm-moe-dsa-num-experts-bc-fallback

Conversation

@webtecnica

@webtecnica webtecnica commented Jul 19, 2026

Copy link
Copy Markdown

CI

Description

Fixes #47355

Root cause: In both GlmMoeDsaConfig.__post_init__ and DeepseekV32Config.__post_init__, the backward-compatibility re-route from num_experts (legacy key) to n_routed_experts was unconditional — it could overwrite an explicit n_routed_experts value from the same config.json.

Example: A config with {"n_routed_experts": 168, "num_experts": 256} would silently use 256 experts, causing an OOM downstream (vLLM allocates for 256 experts instead of 168).

Fix: Only apply the BC fallback when n_routed_experts is still at its defining class's default value, which means it was NOT explicitly provided. Since n_routed_experts is a dataclass field consumed by __init__ before __post_init__ runs, we compare self.n_routed_experts against type(self).n_routed_experts.

Files changed:

File Change
modular_deepseek_v32.py Root fix — source that regenerates generated files
configuration_deepseek_v32.py Generated copy of the same fix
configuration_glm_moe_dsa.py Generated copy (unwrapped from modular)
tests/models/glm_moe_dsa/test_config_glm_moe_dsa.py 3 test cases covering the fix + BC preservation

Verification (6 test cases, all pass):

Scenario Expected Result
Both keys provided n_routed_experts=168 wins
Only legacy num_experts BC fallback applies: 128
Only modern n_routed_experts Preserved: 42
DeepseekV32Config parent Same fix: 64
Both keys same value (256) No issue
Not provided either Class default (256)

In GlmMoeDsaConfig and DeepseekV32Config __post_init__, the legacy
num_experts key unconditionally overwrites the modern n_routed_experts
even when the latter was explicitly provided in the config.

Fix: only apply the BC fallback when n_routed_experts is still at the
defining class's default value (meaning it was NOT explicitly set).

Fixes huggingface#47355

Signed-off-by: webtecnica <marcos@webtecnica.com.br>
@github-actions

Copy link
Copy Markdown
Contributor

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

run-slow: deepseek_v32, glm_moe_dsa

@github-actions

Copy link
Copy Markdown
Contributor

CI recap

Dashboard: View test results in Grafana
Latest run: 29672193811
Result: failure | Grafana metrics are not available yet.

Code quality check failed: test jobs were skipped. Fix the code quality issues and push again to run tests.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GlmMoeDsaConfig: legacy num_experts unconditionally overrides explicit n_routed_experts (sibling of #46739)

2 participants