[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:
co-authored by
Harry Mellor
parent
89d97d9a16
commit
38a267cdd5
@@ -35,10 +35,12 @@ def _apply_qk_norm_rope(
|
||||
|
||||
q_by_head = q.view(*q.shape[:-1], q.shape[-1] // head_dim, head_dim)
|
||||
q_by_head = q_norm.forward_native(q_by_head)
|
||||
assert isinstance(q_by_head, torch.Tensor)
|
||||
q = q_by_head.view(q.shape)
|
||||
|
||||
k_by_head = k.view(*k.shape[:-1], k.shape[-1] // head_dim, head_dim)
|
||||
k_by_head = k_norm.forward_native(k_by_head)
|
||||
assert isinstance(k_by_head, torch.Tensor)
|
||||
k = k_by_head.view(k.shape)
|
||||
|
||||
q, k = rope.forward_native(positions, q, k)
|
||||
|
||||
@@ -34,10 +34,9 @@ NUM_HEADS = [16]
|
||||
@pytest.fixture
|
||||
def _fp8_attention():
|
||||
"""Create FP8-enabled MMEncoderAttention via config."""
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import patch
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from vllm.config import VllmConfig, set_current_vllm_config
|
||||
from vllm.config import ModelConfig, VllmConfig, set_current_vllm_config
|
||||
from vllm.config.multimodal import MultiModalConfig
|
||||
|
||||
if not is_flashinfer_cudnn_fp8_prefill_attn_supported():
|
||||
@@ -45,7 +44,7 @@ def _fp8_attention():
|
||||
|
||||
mm_config = MultiModalConfig(mm_encoder_attn_dtype="fp8")
|
||||
vllm_config = VllmConfig()
|
||||
vllm_config.model_config = SimpleNamespace(multimodal_config=mm_config)
|
||||
vllm_config.model_config = MagicMock(spec=ModelConfig, multimodal_config=mm_config)
|
||||
|
||||
# MMEncoderAttention reads torch.get_default_dtype() during init
|
||||
# to determine the output dtype. In real model loading this is bf16.
|
||||
|
||||
@@ -4,8 +4,7 @@
|
||||
|
||||
import contextlib
|
||||
import json
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import patch
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
@@ -48,7 +47,7 @@ def _build_attention(mm_config, attn_backend=None):
|
||||
invokes ``process_weights_after_loading`` to simulate the model loader's
|
||||
auto-scan. Yields ``None`` if FlashInfer cuDNN is not available.
|
||||
"""
|
||||
from vllm.config import VllmConfig, set_current_vllm_config
|
||||
from vllm.config import ModelConfig, VllmConfig, set_current_vllm_config
|
||||
from vllm.model_executor.layers.attention.mm_encoder_attention import (
|
||||
MMEncoderAttention,
|
||||
)
|
||||
@@ -65,7 +64,7 @@ def _build_attention(mm_config, attn_backend=None):
|
||||
return
|
||||
|
||||
vllm_config = VllmConfig()
|
||||
vllm_config.model_config = SimpleNamespace(multimodal_config=mm_config)
|
||||
vllm_config.model_config = MagicMock(spec=ModelConfig, multimodal_config=mm_config)
|
||||
|
||||
with (
|
||||
set_current_vllm_config(vllm_config),
|
||||
@@ -212,7 +211,7 @@ def test_aiter_static_scales_loaded(tmp_path) -> None:
|
||||
|
||||
def test_static_scales_missing_layer(tmp_path) -> None:
|
||||
"""Verify error when requested layer is not in the scale file."""
|
||||
from vllm.config import VllmConfig, set_current_vllm_config
|
||||
from vllm.config import ModelConfig, VllmConfig, set_current_vllm_config
|
||||
from vllm.config.multimodal import MultiModalConfig
|
||||
from vllm.v1.attention.backends.registry import AttentionBackendEnum
|
||||
|
||||
@@ -228,7 +227,7 @@ def test_static_scales_missing_layer(tmp_path) -> None:
|
||||
mm_encoder_fp8_scale_path=str(scale_file),
|
||||
)
|
||||
vllm_config = VllmConfig()
|
||||
vllm_config.model_config = SimpleNamespace(multimodal_config=mm_config)
|
||||
vllm_config.model_config = MagicMock(spec=ModelConfig, multimodal_config=mm_config)
|
||||
|
||||
from vllm.model_executor.layers.attention.mm_encoder_attention import (
|
||||
MMEncoderAttention,
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user