[MyPy][2/N] Fix mypy errors in small tests/ dirs (#51043)

Signed-off-by: Martin Hickey <martin.hickey@ie.ibm.com>
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Co-authored-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Martin Hickey
2026-09-29 21:27:45 +01:00
committed by GitHub
co-authored by Harry Mellor Claude Opus 5.5
parent a96ee5935d
commit 5dd693122c
71 changed files with 491 additions and 301 deletions
@@ -17,6 +17,7 @@ import vllm.config as vllm_config_module
from vllm.config import VllmConfig, set_current_vllm_config
from vllm.model_executor.layers.fused_moe import utils as fused_moe_utils
from vllm.model_executor.layers.fused_moe.layer import determine_expert_counts
from vllm.model_executor.layers.quantization.base_config import QuantizationConfig
from vllm.model_executor.layers.quantization.fp8 import Fp8Config
from vllm.model_executor.layers.quantization.quark.quark import QuarkConfig
from vllm.model_executor.layers.quantization.utils.config_utils import (
@@ -140,10 +141,15 @@ def get_deepseek_v4_quark_config(exclude: list[str]) -> dict[str, Any]:
return quantization_config
def _stub_quant_config() -> QuantizationConfig:
return cast(QuantizationConfig, object())
def get_fse_test_model_config(
model_type: str,
quantization_config: dict[str, Any],
) -> tuple[object, type[nn.Module]]:
config: object
if model_type == "minimax_m3":
config = MiniMaxM3TextConfig(
hidden_size=128,
@@ -301,7 +307,7 @@ def test_resolve_layer_fused_shared_expert_skips_compatibility_when_disabled(
)
assert not fused_moe_utils.resolve_layer_fused_shared_expert(
object(), "model.layers.0.mlp"
_stub_quant_config(), "model.layers.0.mlp"
)
@@ -316,7 +322,7 @@ def test_resolve_layer_fused_shared_expert_normalizes_unavailable_aiter(
assert (
fused_moe_utils.resolve_layer_fused_shared_expert(
object(), "model.layers.0.mlp"
_stub_quant_config(), "model.layers.0.mlp"
)
is False
)
@@ -325,7 +331,7 @@ def test_resolve_layer_fused_shared_expert_normalizes_unavailable_aiter(
def test_resolve_layer_fused_shared_expert_passes_module_prefixes(
monkeypatch: pytest.MonkeyPatch,
) -> None:
quant_config = object()
quant_config = _stub_quant_config()
monkeypatch.setattr(
fused_moe_utils.rocm_aiter_ops,
"is_fusion_moe_shared_experts_enabled",
@@ -374,7 +380,7 @@ def test_resolve_layer_fused_shared_expert_rejects_incompatible_quantization(
)
assert not fused_moe_utils.resolve_layer_fused_shared_expert(
object(), "model.layers.0.mlp"
_stub_quant_config(), "model.layers.0.mlp"
)
assert "shared experts are excluded" in caplog.text
@@ -407,7 +413,7 @@ def test_deepseek_v4_shared_expert_fse_uses_mtp_quantization_config_prefix(
)
compatible, reason = is_shared_expert_quant_fse_compatible(
DeepseekV4Config(),
DeepseekV4Config(), # type: ignore[arg-type]
"model.layers.2.ffn.experts",
"model.layers.2.ffn.shared_experts",
)
@@ -818,7 +824,7 @@ def test_models_fse_init(
model_type, quantization_config
)
vllm_config = VllmConfig()
vllm_config.model_config = SimpleNamespace(
vllm_config.model_config = SimpleNamespace( # type: ignore[assignment]
hf_config=config,
hf_text_config=config,
dtype=torch.bfloat16,
@@ -887,7 +893,7 @@ def test_models_fse_init(
DeepSeekV4MTP,
)
vllm_config.speculative_config = SimpleNamespace(
vllm_config.speculative_config = SimpleNamespace( # type: ignore[assignment]
draft_model_config=SimpleNamespace(hf_config=config),
method="mtp",
parallel_drafting=False,
@@ -1214,7 +1220,7 @@ def test_quark_packed_layer_config_must_match_global_config() -> None:
def test_non_quark_shared_expert_fse_is_incompatible() -> None:
compatible, reason = is_shared_expert_quant_fse_compatible(
object(),
_stub_quant_config(),
"model.layers.0.mlp.experts",
"model.layers.0.mlp.shared_experts",
)
@@ -46,7 +46,7 @@ def test_sparse_attention_refreshes_batch_state_inside_eager_segment(
with pytest.raises(BatchStateRefreshed):
DeepseekV32Attention._sparse_indexer_and_attn(
layer,
layer, # type: ignore[arg-type]
torch.empty(1, dtype=torch.long),
torch.empty(1, 1),
torch.empty(1, 1, 1),
@@ -80,7 +80,7 @@ def make_indexer_metadata(
num_decode_tokens=num_decode_tokens,
num_prefills=num_prefills,
num_prefill_tokens=num_prefill_tokens,
prefill=SimpleNamespace(chunks=[]) if num_prefills else None,
prefill=SimpleNamespace(chunks=[]) if num_prefills else None, # type: ignore[arg-type]
)
@@ -129,7 +129,7 @@ def test_short_prefill_updates_k_cache_before_scoring_decision(
slot_mapping=slot_mapping,
)
if indexer_metadata.num_decodes:
indexer_metadata.decode = object()
indexer_metadata.decode = object() # type: ignore[assignment]
mla_metadata = make_mla_metadata(
use_dense_mha=batch_kind != "force_mqa",
num_decode_tokens=mla_num_decode_tokens,
@@ -307,7 +307,7 @@ def test_deepseek_v32_dispatches_selected_mha(
output = torch.empty(2, 2)
DeepseekV32Attention._sparse_indexer_and_attn(
layer,
layer, # type: ignore[arg-type]
torch.arange(2),
torch.empty(2, 2),
q_nope,
@@ -224,11 +224,11 @@ class TestResolveClassifierActFn:
model_config = SimpleNamespace(
hf_config=SimpleNamespace(num_labels=3, problem_type="")
)
result = resolve_classifier_act_fn(model_config, act_fn=None)
result = resolve_classifier_act_fn(model_config, act_fn=None) # type: ignore[arg-type]
assert isinstance(result, PoolerClassify)
assert result.num_labels == 3
def test_passes_through_provided_act_fn(self):
custom = PoolerIdentity()
result = resolve_classifier_act_fn(None, act_fn=custom)
result = resolve_classifier_act_fn(None, act_fn=custom) # type: ignore[arg-type]
assert result is custom
@@ -15,6 +15,7 @@ from vllm.model_executor.layers.pooler.tokwise.heads import (
TokenEmbeddingPoolerHead,
)
from vllm.pooling_params import PoolingParams
from vllm.tasks import PoolingTask
from vllm.v1.pool.metadata import PoolingMetadata, PoolingStates
_HIDDEN = 16
@@ -24,7 +25,7 @@ _BATCH = 3
def _make_params(
n: int,
*,
task: str = "embed",
task: PoolingTask = "embed",
dimensions: int | None = None,
use_activation: bool | None = None,
) -> list[PoolingParams]:
@@ -320,6 +321,7 @@ class TestTokenEmbeddingPoolerHead:
x = torch.randn(5, _HIDDEN)
param = PoolingParams(task="token_embed")
out = head.forward_chunk(x, param)
assert out is not None
assert out.dtype == torch.float16
def test_projector(self):
@@ -328,6 +330,7 @@ class TestTokenEmbeddingPoolerHead:
x = torch.randn(5, _HIDDEN)
param = PoolingParams(task="token_embed")
out = head.forward_chunk(x, param)
assert out is not None
assert out.shape == (5, 8)
assert torch.allclose(out, proj(x))
@@ -336,6 +339,7 @@ class TestTokenEmbeddingPoolerHead:
x = torch.randn(5, _HIDDEN)
param = PoolingParams(task="token_embed", dimensions=4)
out = head.forward_chunk(x, param)
assert out is not None
assert out.shape == (5, 4)
assert torch.equal(out, x[..., :4])
@@ -360,6 +364,7 @@ class TestTokenEmbeddingPoolerHead:
x = torch.randn(5, _HIDDEN)
param = PoolingParams(task="token_embed", dimensions=4)
out = head.forward_chunk(x, param)
assert out is not None
assert out.shape == (5, 4)
assert torch.equal(out, proj(x)[..., :4])
@@ -368,6 +373,7 @@ class TestTokenEmbeddingPoolerHead:
x = torch.randn(5, _HIDDEN)
param = PoolingParams(task="token_embed", dimensions=4, use_activation=True)
out = head.forward_chunk(x, param)
assert out is not None
assert out.shape == (5, 4)
norms = torch.linalg.norm(out, dim=-1)
assert torch.allclose(norms, torch.ones(5), atol=1e-5)
@@ -416,6 +422,7 @@ class TestTokenClassifierPoolerHead:
x = torch.randn(5, _HIDDEN)
param = PoolingParams(task="token_classify")
out = head.forward_chunk(x, param)
assert out is not None
assert out.dtype == torch.float16
def test_classifier(self):
@@ -424,6 +431,7 @@ class TestTokenClassifierPoolerHead:
x = torch.randn(5, _HIDDEN)
param = PoolingParams(task="token_classify")
out = head.forward_chunk(x, param)
assert out is not None
assert out.shape == (5, 3)
assert torch.allclose(out, clf(x))
@@ -26,6 +26,7 @@ from vllm.model_executor.layers.pooler.tokwise.methods import (
get_tok_pooling_method,
)
from vllm.pooling_params import PoolingParams
from vllm.tasks import PoolingTask
from vllm.v1.pool.metadata import PoolingCursor, PoolingMetadata, PoolingStates
_CPU = torch.device("cpu")
@@ -66,7 +67,7 @@ def _make_pooling_cursor(
def _make_metadata(
prompt_lens: list[int],
*,
tasks: list[str] | None = None,
tasks: list[PoolingTask] | None = None,
token_ids: list[list[int]] | None = None,
pooling_params: list[PoolingParams] | None = None,
num_scheduled_tokens: list[int] | None = None,
@@ -319,7 +320,7 @@ def test_dispatch_seq_cls_honors_token_pooling_type(tok_pooling_type):
),
)
classifier = torch.nn.Linear(4, 3)
with set_current_vllm_config(config):
with set_current_vllm_config(config): # type: ignore[arg-type]
pooler = DispatchPooler.for_seq_cls(pooler_config, classifier=classifier)
token_ids = [[2, 99, 3, 99], [4, 99], [5, 6]]