[MyPy][1/N] Fix mypy errors in some tests/ directories and enforce follow-imports=silent (#49570)

Signed-off-by: Martin Hickey <martin.hickey@ie.ibm.com>
Co-authored-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
This commit is contained in:
Martin Hickey
2026-07-30 05:02:51 -07:00
committed by GitHub
co-authored by Harry Mellor
parent 89d97d9a16
commit 38a267cdd5
30 changed files with 166 additions and 101 deletions
+24 -9
View File
@@ -12,6 +12,7 @@ import vllm._custom_ops as ops
from vllm.model_executor.layers.mamba.ops.cpu import gdn_attention
from vllm.platforms import current_platform
from vllm.utils.torch_utils import set_random_seed
from vllm.v1.attention.backends.gdn_attn import GDNAttentionMetadata
if not current_platform.is_cpu():
pytest.skip("skipping CPU-only tests", allow_module_level=True)
@@ -452,12 +453,17 @@ def test_spec_aware_mixed_routing_preserves_token_order(
spec_indices = torch.tensor([0, 2])
nonspec_indices = torch.tensor([1, 3])
metadata = types.SimpleNamespace(
metadata = GDNAttentionMetadata(
num_prefills=1,
num_prefill_tokens=0,
num_decodes=0,
num_decode_tokens=0,
num_spec_decodes=0,
num_spec_decode_tokens=0,
num_actual_tokens=0,
spec_sequence_masks=torch.ones(1, dtype=torch.bool),
spec_token_indx=spec_indices,
non_spec_token_indx=nonspec_indices,
num_prefills=1,
num_decodes=0,
)
routed = []
@@ -501,13 +507,16 @@ def test_spec_aware_nonspec_materializes_state_indices(
state_indices = block_table[:, 0]
assert not state_indices.is_contiguous()
metadata = types.SimpleNamespace(
non_spec_state_indices_tensor=state_indices,
non_spec_query_start_loc=torch.tensor([0, 2, 4], dtype=torch.int32),
num_decodes=0,
num_decode_tokens=0,
metadata = GDNAttentionMetadata(
num_prefills=2,
num_prefill_tokens=4,
num_decodes=0,
num_decode_tokens=0,
num_spec_decodes=0,
num_spec_decode_tokens=0,
num_actual_tokens=4,
non_spec_state_indices_tensor=state_indices,
non_spec_query_start_loc=torch.tensor([0, 2, 4], dtype=torch.int32),
has_initial_state=torch.tensor([False, False]),
)
@@ -575,8 +584,14 @@ def test_spec_forward_prepares_native_conv_metadata(
state_indices = block_table[:, 0]
accepted_counts = torch.tensor([1, 4], dtype=torch.int32)
assert not state_indices.is_contiguous()
metadata = types.SimpleNamespace(
metadata = GDNAttentionMetadata(
num_prefills=0,
num_prefill_tokens=0,
num_decodes=0,
num_decode_tokens=0,
num_spec_decodes=2,
num_spec_decode_tokens=8,
num_actual_tokens=8,
spec_state_indices_tensor=block_table,
spec_query_start_loc=torch.tensor([0, 4, 8], dtype=torch.int32),
num_accepted_tokens=accepted_counts,
@@ -174,7 +174,9 @@ def test_forward_core_split_matches_unified(
batch = BatchSpec(seq_lens=seq_lens, query_lens=query_lens)
builder = GDNAttentionMetadataBuilder(
kv_cache_spec=MambaSpec(
# GDNAttentionMetadataBuilder declares kv_cache_spec as AttentionSpec but
# asserts isinstance(kv_cache_spec, MambaSpec). MambaSpec is correct here.
kv_cache_spec=MambaSpec( # type: ignore[arg-type]
block_size=BLOCK_SIZE, shapes=((16, 64),), dtypes=(torch.float16,)
),
layer_names=[PREFIX],
@@ -198,6 +200,7 @@ def test_forward_core_split_matches_unified(
# Full-batch chunk metadata for the unified reference path, built the same
# way the builder would for a non-split batch (backend-matched).
cu_full = meta_split.non_spec_query_start_loc
assert cu_full is not None
if builder.gdn_prefill_backend == "cutedsl":
from vllm.model_executor.layers.mamba.ops.gdn_chunk_cutedsl import (
prepare_metadata_cutedsl,
@@ -227,6 +230,7 @@ def test_forward_core_split_matches_unified(
)
# Size the state pools from the indices the builder actually produced.
assert meta_split.non_spec_state_indices_tensor is not None
pool_size = int(meta_split.non_spec_state_indices_tensor.max().item()) + 1
conv_state_shape, temporal_state_shape = (
MambaStateShapeCalculator.gated_delta_net_state_shape(
@@ -21,7 +21,9 @@ The kernel must also no-op when ``src_col < 0`` (fresh request) or
from __future__ import annotations
from collections.abc import Callable
from types import SimpleNamespace
from typing import Any
import numpy as np
import torch
@@ -31,6 +33,8 @@ from vllm.platforms import current_platform
from vllm.v1.worker import mamba_utils as worker_mamba_utils
from vllm.v1.worker.mamba_utils import precopy_mamba_align_fused_kernel
_parametrize: Callable[..., Callable[[Any], Any]]
try:
import pytest
@@ -40,17 +44,18 @@ try:
)
_parametrize = pytest.mark.parametrize
except ModuleNotFoundError: # allow running directly as ``python <thisfile>``
pytest = None
def _cuda_required(fn):
return fn
def _parametrize(_name, _values):
def _no_parametrize(_name, _values):
def _deco(fn):
return fn
return _deco
_parametrize = _no_parametrize
NUM_LAYERS = 3
CONV_WIDTH = 4 # conv_kernel - 1 + num_spec
@@ -308,8 +313,10 @@ def _make_preprocess_case(token_bias):
def test_preprocess_fused_align_matches_scalar_bookkeeping(monkeypatch, token_bias):
block_size = 4
mamba_spec = SimpleNamespace(block_size=block_size, num_speculative_blocks=1)
cache_config = SimpleNamespace(enable_prefix_caching=True)
kv_cache_config = SimpleNamespace()
# Fakes stand in for real config/context objects. The fused path tests
# below only touch the attributes preprocess_mamba actually reads.
cache_config: Any = SimpleNamespace(enable_prefix_caching=True)
kv_cache_config: Any = SimpleNamespace()
scalar_copy_calls = []
def fake_collect(
@@ -340,7 +347,7 @@ def test_preprocess_fused_align_matches_scalar_bookkeeping(monkeypatch, token_bi
scalar_case = _make_preprocess_case(token_bias)
fused_case = _make_preprocess_case(token_bias)
scalar_copy_bufs = SimpleNamespace(
scalar_copy_bufs: Any = SimpleNamespace(
mamba_group_ids=[0],
mamba_spec=mamba_spec,
offset=0,
@@ -357,8 +364,8 @@ def test_preprocess_fused_align_matches_scalar_bookkeeping(monkeypatch, token_bi
copy_bufs=scalar_copy_bufs,
)
ctx = _FakePrecopyContext(len(fused_case[1].req_ids))
fused_copy_bufs = SimpleNamespace(
ctx: Any = _FakePrecopyContext(len(fused_case[1].req_ids))
fused_copy_bufs: Any = SimpleNamespace(
mamba_group_ids=[0],
mamba_spec=mamba_spec,
offset=0,