Repository navigation
Fix MLA padding and grouped topk routing in the Transformers modelling backend - #49982
Merged
Merged
Conversation
`_match_router` anchored the scorer on the first `topk` in the gate's graph. DeepSeek's group-limited routers run a `topk` over expert *groups* first, so the scorer was looked for upstream of the wrong node and the whole block was declined. Anchor on the last `topk` instead, which is always the routing one. Also allow `e_score_correction_bias` alongside `weight` in the gate's state (DeepSeek-V3 noaux) and carry it onto the rebuilt `ReplicatedLinear`, rather than treating any extra state as unrecognised. `named_state` moves to `transformers/utils.py` as it is no longer MoE-only. Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
`use_grouped_topk` was hard-coded `False` and `scoring_func`, `e_score_correction_bias`, `num_expert_group` and `topk_group` were left unset, so blocks with more than one expert group were excluded from fusion entirely. Infer them from the text config and pass them through. `routed_scaling_factor` is passed too, with `apply_routed_scale_to_output` off when aiter's fused MoE applies it internally. The fp16 `_maybe_apply_routed_scale_to_output` path is skipped for blocks with shared experts, as Transformers decoder layers do not compensate for the division. Shared experts' down projection no longer reduces on its own: FusedMoE owns the reduction once the shared expert runs inside it. Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
`GateLinear` is what the native MoE models use for the router GEMM, and it falls back to `ReplicatedLinear` when no specialized kernel applies, so the fused block picks up the DSV3/cuteDSL/cuBLAS tiers where dimensions allow without changing behaviour elsewhere. `out_dtype` is left unset, matching the native DeepSeek default. Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
MLA models have a narrower `value` than `query`/`key` (128 vs 192 for DeepSeek-V2). Running one through full attention fed the KV cache a `value` of the wrong head size, so DeepSeek could not run under the Transformers backend at all. Pad `value` up to the query/key head size and slice the result back afterwards. This is the naive path: with `VLLM_MLA_DISABLE=1` an MLA model runs as full attention, which is what makes DeepSeek usable as the exemplar for grouped top-k routing. Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
`GateLinear`'s `out_dtype` and `FusedMoE`'s `router_logits_dtype` were both left unset, so a model that routes in fp32 was routed in the activation dtype instead. GLM-4.5 is the live case: its native vLLM implementation hardcodes `router_logits_dtype=torch.float32`, and the Transformers backend fuses that block once the router matcher accepts a score-correction bias. Prefer `moe_router_dtype` from the config. Where no config field names it, read it off the gate's traced graph: routers that need higher precision say so in their forward (`hidden_states.type(torch.float32)`), so the dtype is recoverable without a per-architecture table. Only the cone feeding the scorer is considered, so the cast back to the activation dtype after the top-k is not mistaken for the routing dtype. Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
The fp16 overflow path applies `routed_scaling_factor` by dividing the shared expert output instead of scaling the fused output, and expects the decoder layer to compensate. Transformers decoder layers do not, so such blocks fall back to routing in Transformers -- silently, until now. Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Isotr0py
approved these changes
Jul 27, 2026
hmellor
enabled auto-merge (squash)
July 27, 2026 12:28
michael-gpu
pushed a commit
to practical-inference/vllm-ampere-extended
that referenced
this pull request
Oct 20, 2026
…g backend (vllm-project#49982) Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
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.
topkin the gate's graph — DeepSeek's group-limited routerstopkover expert groups first, so the scorer was sought upstream of the wrong node and the block was declined.e_score_correction_biasin the gate's state (DeepSeek-V3 noaux) and carry it onto the rebuilt gate, rather than rejecting any extra state.use_grouped_topk,num_expert_group,topk_group,scoring_funcande_score_correction_biastoFusedMoE.use_grouped_topkwas hard-codedFalse, excluding every multi-group block from fusion.routed_scaling_factor, withapply_routed_scale_to_outputoff when aiter applies it internally. Shared-expert blocks skip the fp16_maybe_apply_routed_scale_to_outputpath, which Transformers decoder layers don't compensate for.FusedMoEowns the reduction once the shared expert runs inside it.GateLinear, matching the native MoE models and picking up the specialized router-GEMM tiers.GateLinear.out_dtype,FusedMoE.router_logits_dtype), both previously unset:moe_router_dtypewins, else read the cast off the gate's graph, scanning only the scorer's input cone.valueup to the query/key head size invllm_attention_forwardand slice the output back. MLA models have a narrowervalue(128 vs 192 on DeepSeek-V2), which made them unrunnable here; withVLLM_MLA_DISABLE=1they now run as full attention.routed_scaling_factorand shared experts is left unfused — that path divides the shared expert output and expects the decoder layer to compensate, which Transformers layers don't. Previously a silent fallback.named_statetotransformers/utils.py, no longer MoE-only.