Add pydocstyle to the ruff rules (#52136)

Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Signed-off-by: Harry Mellor <hej.mellor@gmail.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Harry Mellor
2026-09-16 16:44:29 +00:00
committed by GitHub
co-authored by Claude Opus 5
parent 804e5377aa
commit 8c1557a79c
2002 changed files with 15024 additions and 14269 deletions
@@ -808,7 +808,6 @@ def test_models_fse_init(
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Model construction resolves FSE consistently with Quark quantization."""
quantization_config: dict[str, Any] = (
get_deepseek_v4_quark_config(["layers.0.ffn.shared_experts"] if exclude else [])
if model_type == "deepseek_v4"
@@ -1320,7 +1319,8 @@ def test_fp8_shared_expert_fse_allows_symmetric_ignored_layers() -> None:
def test_fp8_shared_expert_fse_expands_packed_projections() -> None:
"""Both shards of a fused projection ignored is symmetric within that
projection, so the mismatch reported is against the routed experts."""
projection, so the mismatch reported is against the routed experts.
"""
quant_config = _fp8_config(
ignored_layers=[
"model.layers.0.mlp.shared_experts.gate_proj",
@@ -1344,7 +1344,8 @@ def test_fp8_shared_expert_fse_expands_packed_projections() -> None:
def test_fp8_shared_expert_fse_propagates_partial_shard_exclusion() -> None:
"""Half a fused projection excluded is rejected by `is_layer_skipped`
itself, exactly as it is in `Fp8Config.get_quant_method`."""
itself, exactly as it is in `Fp8Config.get_quant_method`.
"""
quant_config = _fp8_config(
ignored_layers=["model.layers.0.mlp.shared_experts.gate_proj"]
)
@@ -346,7 +346,8 @@ def test_deepseek_v32_dispatches_selected_mha(
def test_select_candidate_blocks_tolerates_empty_rows():
"""Full-cudagraph decode pads the batch with seq_len-0 rows. The newest
block pin must not index -1 for them (device-side assert); they select
no candidate blocks and real rows still pin their newest block."""
no candidate blocks and real rows still pin their newest block.
"""
block_size, topk_blocks = 8, 3
logits = torch.zeros(3, 64, device="cuda")
logits[0, 3] = 5.0 # block 0 scores highest for row 0
@@ -457,7 +458,8 @@ def test_candidate_kernels_preserve_packed_bounds_and_padding(
def _make_candidates(lens: torch.Tensor, num_candidates: int, cbk: int):
"""Production-faithful candidates: top min(avail, K) blocks per row —
full coverage for lens <= K*cbk, a fixed-size subset beyond that."""
full coverage for lens <= K*cbk, a fixed-size subset beyond that.
"""
avail = ((lens.cpu() + cbk - 1) // cbk).tolist()
rows = []
for a in avail:
@@ -493,7 +495,8 @@ def _candidate_token_mask(
def _reference_topk(masked: torch.Tensor, topk: int) -> torch.Tensor:
"""Plain ``torch.topk`` over -inf-masked logits; slots past a row's valid
count are -1 (the indexer's "no token" sentinel)."""
count are -1 (the indexer's "no token" sentinel).
"""
values, indices = masked.topk(topk, dim=1)
return torch.where(values > float("-inf"), indices.int(), -1)
@@ -506,7 +509,8 @@ def _assert_same_selection(
) -> None:
"""Both top-k index sets must pick the same multiset of logit values per
row (-1 padding must match too). Indices themselves may differ: the
top-k kernels break ties among equal values in nondeterministic order."""
top-k kernels break ties among equal values in nondeterministic order.
"""
for r in range(logits.shape[0]):
base = int(row_starts[r]) if row_starts is not None else 0
g, e = got[r][got[r] >= 0], expected[r][expected[r] >= 0]
@@ -518,7 +522,8 @@ def _assert_same_selection(
def _sparse_scratch(rows: int, num_sparse: int, topk: int) -> dict:
"""Caller-owned buffers the sparse path writes into (the metadata builder
owns these in production)."""
owns these in production).
"""
i32 = dict(dtype=torch.int32, device="cuda")
return dict(
sparse_indices=torch.zeros(rows, num_sparse, **i32),
@@ -533,7 +538,8 @@ def _expand_candidates_reference(
"""PyTorch reference for `candidate_blocks_to_sparse_indices`: expand
each candidate block into ``cbk // sbk`` sparse blocks, keep those inside
``[0, ke - ks)``, sort ascending, anchor at ``ks // sbk``, pad by
repeating the last valid block, and count the valid sparse columns."""
repeating the last valid block, and count the valid sparse columns.
"""
ratio = cbk // sbk
rows, num_candidates = candidates.shape
num_sparse = num_candidates * ratio
@@ -559,7 +565,8 @@ def _expand_candidates_reference(
@pytest.mark.skipif(not torch.cuda.is_available(), reason="Triton kernel")
def test_candidate_blocks_to_sparse_indices_math():
"""Candidate->sparse-block expansion: ks anchoring, range filtering,
repeat-last padding, and the per-row valid column count (``end``)."""
repeat-last padding, and the per-row valid column count (``end``).
"""
from vllm.model_executor.kernels.attention.dsa.sparse_mqa_logits import (
candidate_blocks_to_sparse_indices,
)
@@ -611,7 +618,8 @@ def test_candidate_blocks_to_sparse_indices_math():
def test_candidate_blocks_to_sparse_indices_matches_reference(cbk: int, sbk: int):
"""The Triton expansion equals the PyTorch reference on production-shaped
random inputs, including strided (column-sliced) candidate rows and
strided output buffers."""
strided output buffers.
"""
from vllm.model_executor.kernels.attention.dsa.sparse_mqa_logits import (
candidate_blocks_to_sparse_indices,
)
@@ -681,7 +689,8 @@ def test_sparse_mqa_logits_prefill_matches_dense_masked(capture: bool):
``torch.topk`` over dense bf16 logits masked to the candidates (the two
DeepGEMM kernels agree bitwise on candidate columns), incl. under CUDA
graph capture, and a later layer reusing the step's expansion/schedule
selects the same values."""
selects the same values.
"""
deep_gemm = _skip_unless_sm100_sparse_kernels()
from vllm.model_executor.kernels.attention.dsa.sparse_mqa_logits import (
sparse_mqa_logits_prefill_chunk,
@@ -771,7 +780,8 @@ def test_sparse_mqa_logits_prefill_matches_dense_masked(capture: bool):
def _build_fp4_paged_cache(req_lens: torch.Tensor, page_kv: int, head_dim: int):
"""MXFP4 paged cache in DeepGEMM's fused layout: per page, all tokens'
fp4 data first, then their packed UE8M0 scales."""
fp4 data first, then their packed UE8M0 scales.
"""
device = req_lens.device
pages_per = (req_lens + page_kv - 1) // page_kv
num_pages, max_pages = int(pages_per.sum()), int(pages_per.max())
@@ -807,7 +817,8 @@ def test_sparse_mqa_logits_paged_matches_dense_masked(next_n: int, capture: bool
"""Paged sparse-MQA decode selects exactly the values ``torch.topk`` picks
from the dense bf16 masked logits, incl. MTP rows (next_n > 1 flattened to
one query row each), CUDA graph capture/replay and schedule reuse by a
later layer."""
later layer.
"""
deep_gemm = _skip_unless_sm100_sparse_kernels()
from vllm.model_executor.kernels.attention.dsa.sparse_mqa_logits import (
sparse_mqa_logits_paged_decode,
@@ -916,7 +927,8 @@ def test_sparse_mqa_logits_paged_matches_dense_masked(next_n: int, capture: bool
def test_sparse_mqa_logits_accuracy_vs_torch():
"""Sparse-kernel numerics vs a PyTorch fp32 reference on the dequantized
MXFP4 inputs."""
MXFP4 inputs.
"""
_skip_unless_sm100_sparse_kernels()
from deep_gemm.utils import cast_back_from_fp4