Skip to content

Commit 6f7e010

Browse files
xaguilar-amdakii96
authored andcommitted
[ROCm][MLA] Fix mypy: narrow rotary_emb/slot_mapping on the fused MLA path
The new rotary_emb: nn.Module | None on the base MLAAttention broke mypy (3.10-3.13): guard rotary_emb before use in the fused decode branch, narrow forward_context.slot_mapping to dict, ignore the impl attr assignment, and assert rotary_emb in the DeepseekV32 (nvidia) subclass that inherits the type. co-authored by Claude Signed-off-by: Xavier Aguilar <xavier.aguilarfruto@amd.com>
1 parent 2326276 commit 6f7e010

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

vllm/model_executor/layers/attention/mla_attention.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ def __init__(
513513
self.rotary_emb = rotary_emb
514514
self._fused_rope_cos_sin: tuple[torch.Tensor, torch.Tensor] | None = None
515515
if getattr(self.impl, "use_fused_qk_rope_cache", False) and rotary_emb is None:
516-
self.impl.use_fused_qk_rope_cache = False
516+
self.impl.use_fused_qk_rope_cache = False # type: ignore[attr-defined]
517517

518518
vllm_config = get_current_vllm_config()
519519
parallel_config = vllm_config.parallel_config
@@ -900,8 +900,13 @@ def forward_impl(
900900
"forward positions when impl.use_fused_qk_rope_cache is set."
901901
)
902902
forward_context = get_forward_context()
903-
slot_mapping = forward_context.slot_mapping[self.layer_name].flatten()
903+
fc_slot_mapping = forward_context.slot_mapping
904+
assert isinstance(fc_slot_mapping, dict), (
905+
f"Expected slot_mapping to be a dict, got {type(fc_slot_mapping)}."
906+
)
907+
slot_mapping = fc_slot_mapping[self.layer_name].flatten()
904908
cos_cache, sin_cache = self._get_fused_rope_cos_sin()
909+
assert self.rotary_emb is not None
905910
mqa_q = self.impl.fused_qk_rope_concat_and_cache( # type: ignore[attr-defined]
906911
self,
907912
mqa_ql_nope,

vllm/models/deepseek_v32/nvidia/attention.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ def _fused_attention(
426426
mla_kv_cache = self.kv_cache
427427
mla_k_scale = self._k_scale
428428

429+
assert self.rotary_emb is not None
429430
q_c = fused_norm_rope(
430431
positions,
431432
q_c,

0 commit comments

Comments
 (0)