[Bugfix] Move extract_layer_index back inside is_v32 guard (#46199)

Signed-off-by: Tyler Michael Smith <tlrmchlsmth@gmail.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>

Tyler Michael Smith committed Jun 20, 2026 at 17:19 UTC 77148992cfc905ded5fbd34d746553aa7f099da4
1 file changed +23 -17
vllm/model_executor/models/deepseek_v2.py
+23 -17
@@ -1001,24 +1001,30 @@ class DeepseekV2MLAAttention(nn.Module):
1001 # IndexCache config
1002 # Refer: https://arxiv.org/abs/2603.12201 for more details.
1003 _skip_topk = False
1004 - _index_topk_freq = getattr(config, "index_topk_freq", 1)
1005 - _index_topk_pattern = getattr(config, "index_topk_pattern", None)
1006 - _index_skip_topk_offset = getattr(config, "index_skip_topk_offset", 2)
1007 - layer_id = extract_layer_index(prefix)
1008 -
1009 - if _index_topk_pattern is None:
1010 - _skip_topk = (
1011 - max(layer_id - _index_skip_topk_offset + 1, 0) % _index_topk_freq != 0
1004 + is_mtp_layer = False
1005 + if self.is_v32:
1006 + _index_topk_freq = getattr(config, "index_topk_freq", 1)
1007 + _index_topk_pattern = getattr(config, "index_topk_pattern", None)
1008 + _index_skip_topk_offset = getattr(config, "index_skip_topk_offset", 2)
1009 + layer_id = extract_layer_index(prefix)
1010 +
1011 + if _index_topk_pattern is None:
1012 + _skip_topk = (
1013 + max(layer_id - _index_skip_topk_offset + 1, 0) % _index_topk_freq
1014 + != 0
1015 + )
1016 + elif 0 <= layer_id < len(_index_topk_pattern):
1017 + _skip_topk = _index_topk_pattern[layer_id] == "S"
1018 +
1019 + # The skip pattern only governs backbone layers. MTP/nextn
1020 + # layers (layer_id >= num_hidden_layers) always build a full
1021 + # indexer: they compute indices at draft step 0 and toggle
1022 + # at runtime via set_skip_topk
1023 + # (index_share_for_mtp_iteration).
1024 + _num_hidden_layers = getattr(config, "num_hidden_layers", None)
1025 + is_mtp_layer = (
1026 + _num_hidden_layers is not None and layer_id >= _num_hidden_layers
1027 )
1013 - elif 0 <= layer_id < len(_index_topk_pattern):
1014 - _skip_topk = _index_topk_pattern[layer_id] == "S"
1015 -
1016 - # The skip pattern only governs backbone layers. MTP/nextn layers
1017 - # (layer_id >= num_hidden_layers) always build a full indexer: they
1018 - # compute indices at draft step 0 and toggle at runtime via
1019 - # set_skip_topk (index_share_for_mtp_iteration).
1020 - _num_hidden_layers = getattr(config, "num_hidden_layers", None)
1021 - is_mtp_layer = _num_hidden_layers is not None and layer_id >= _num_hidden_layers
1028
1029 if self.is_v32 and (not _skip_topk or is_mtp_layer):
1030 self.indexer_rope_emb = get_rope(