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
-5
View File
@@ -33,7 +33,6 @@ def apply_qsa_rope(
tensor: torch.Tensor,
) -> torch.Tensor:
"""Apply the main attention's exact 1D/MRoPE composition to QSA heads."""
num_tokens, _, head_dim = tensor.shape
rotary_dim = rotary_emb.rotary_dim
cache = rotary_emb._match_cos_sin_cache_dtype(tensor) # noqa: SLF001
@@ -67,7 +66,6 @@ def apply_qsa_rmsnorm(
tensor: torch.Tensor,
) -> torch.Tensor:
"""Use vLLM's portable RMSNorm implementation on ROCm."""
return cast(torch.Tensor, norm(tensor))
@@ -153,7 +151,6 @@ class QSAIndexer(nn.Module):
positions: torch.Tensor,
) -> tuple[torch.Tensor, torch.Tensor]:
"""Project replicated Q/K, normalize+rotate Q, and preserve raw K."""
qk, _ = self.index_qk_proj(hidden_states)
q_raw, token_k = qk.split(
(
@@ -176,7 +173,6 @@ class QSAIndexer(nn.Module):
first_rope_positions: torch.Tensor,
) -> torch.Tensor:
"""Normalize pooled K and apply the first token's exact group position."""
keys = compressed_keys.reshape(-1, self.index_head_dim)
keys = apply_qsa_rmsnorm(self.k_layernorm, keys).reshape(
-1, 1, self.index_head_dim
@@ -284,7 +280,6 @@ class QSAIndexer(nn.Module):
out: torch.Tensor | None = None,
) -> torch.Tensor:
"""Return fixed-width request-relative token indices padded with ``-1``."""
metadata = self._metadata()
if metadata is None:
# Preserve step-0 indices when later MTP steps reuse the buffer.
@@ -11,5 +11,4 @@ def enable_qwen4_exp_low_latency_gemm(
dtype: torch.dtype,
) -> None:
"""Keep the standard vLLM linear methods on AMD ROCm."""
del module, dtype
-2
View File
@@ -87,7 +87,6 @@ def without_modelopt_fp4(
quant_config: QuantizationConfig | None,
) -> QuantizationConfig | None:
"""Return ``None`` for weights excluded from Qwen4Exp ModelOpt-FP4."""
if quant_config is not None and quant_config.get_name() == "modelopt_fp4":
return None
return quant_config
@@ -103,7 +102,6 @@ def _remap_qsa_cache_scale_name(
that cache directly, so only QSA layers need the final path component
moved to the owner's persistent ``_k_scale``/``_v_scale`` buffers.
"""
scale_suffixes = {
"k_proj.k_scale": "_k_scale",
"k_proj.output_scale": "_k_scale",
-4
View File
@@ -91,7 +91,6 @@ def _remap_quantized_layers(
def _remap_mtp_weight_name(name: str) -> str | None:
"""Map Qwen4Exp checkpoint paths into the standalone draft model."""
for checkpoint_prefix in (
"model.language_model.",
"language_model.",
@@ -260,7 +259,6 @@ class Qwen4ExpMultiTokenPredictor(nn.Module):
def _iter_qsa_attentions(self):
"""Yield MTP attention modules that own a QSA indexer."""
for layer in self.layers:
attention = getattr(layer, "self_attn", None)
if (
@@ -271,13 +269,11 @@ class Qwen4ExpMultiTokenPredictor(nn.Module):
def set_skip_topk(self, skip: bool) -> None:
"""Select on MTP step 0 and reuse its QSA indices on later steps."""
for attention in self._iter_qsa_attentions():
attention.indexer.skip_topk = skip
def compact_topk_indices(self, row_indices: torch.Tensor) -> None:
"""Keep each request's target-aligned step-0 sparse-index row."""
num_rows = row_indices.numel()
for attention in self._iter_qsa_attentions():
buffer = attention.topk_indices_buffer
-6
View File
@@ -600,7 +600,6 @@ def qsa_mqa_paged(
score_scale: float | None = None,
) -> tuple[torch.Tensor, torch.Tensor]:
"""Compute QSA scores directly from a paged compressed-key cache."""
_validate_mqa(q)
if not q.is_cuda or not HAS_TRITON:
raise RuntimeError("paged QSA scoring requires a GPU and Triton")
@@ -678,7 +677,6 @@ def expand_qsa_block_indices_cuda(
out: torch.Tensor | None = None,
) -> torch.Tensor:
"""Expand compressed blocks and compact the causal tail of the open group."""
if not block_indices.is_cuda or not HAS_TRITON:
raise RuntimeError("QSA index expansion requires a GPU and Triton")
if token_topk % compress_ratio:
@@ -738,7 +736,6 @@ def qsa_select_paged_tokens(
out: torch.Tensor | None = None,
) -> torch.Tensor:
"""Score, select, and expand QSA indices without host synchronization."""
rows = q.shape[0]
output_width = token_topk + compress_ratio - 1
if out is None:
@@ -829,7 +826,6 @@ def qsa_sparse_paged_attention(
out: torch.Tensor | None = None,
) -> torch.Tensor:
"""Run sparse GQA directly over paged BF16 K/V caches."""
if not q.is_cuda or not HAS_TRITON:
raise RuntimeError("paged QSA sparse attention requires a GPU and Triton")
if q.ndim != 3 or k_cache.ndim != 4 or v_cache.shape != k_cache.shape:
@@ -971,7 +967,6 @@ def qsa_store_cache_rows(
rows: torch.Tensor,
) -> None:
"""Store fixed-width rows in a QSA cache without boolean indexing."""
if not cache.is_cuda or not HAS_TRITON:
raise RuntimeError("QSA cache stores require a GPU and Triton")
if cache.ndim != 4 or cache.shape[2] != 1:
@@ -1017,7 +1012,6 @@ def qsa_compress_groups_with_ratio(
rope_cache: torch.Tensor | None = None,
) -> tuple[torch.Tensor, torch.Tensor]:
"""Pool completed groups from the compressor-state ring and raw token rows."""
if not raw_keys.is_cuda or not HAS_TRITON:
raise RuntimeError("QSA compression requires a GPU and Triton")
rows = token_to_req.numel()
-1
View File
@@ -357,7 +357,6 @@ class Qwen4ExpNGramEmbedding(nn.Module):
def load_weights(self, weights: Iterable[tuple[str, torch.Tensor]]) -> set[str]:
"""Load hash buffers and checkpoint-split embedding rows."""
persistent_buffers = {
"layer_multipliers": self.layer_multipliers,
"ngram_heads_offsets": self.ngram_heads_offsets,
-1
View File
@@ -430,7 +430,6 @@ def qwen4_exp_qsa_with_output(
layer_name: LayerNameType,
) -> None:
"""Run the complete QSA state/update/attend transaction."""
layer_name = _resolve_layer_name(layer_name)
layer = get_forward_context().no_compile_layers[layer_name]
if not isinstance(layer, Qwen4ExpQSAAttention):
-2
View File
@@ -28,7 +28,6 @@ def compute_ple_shard_overlap(
tp_end: int,
) -> PLEShardOverlap | None:
"""Compute the overlap of a checkpoint shard and one TP vocabulary range."""
if checkpoint_start < 0 or checkpoint_rows < 0:
raise ValueError("checkpoint shard bounds must be non-negative")
if tp_start < 0 or tp_end < tp_start:
@@ -54,7 +53,6 @@ def copy_ple_embedding_shard_(
tp_end: int,
) -> int:
"""Copy the overlapping rows of a PLE checkpoint shard into a TP table."""
if destination.ndim == 0 or loaded_weight.ndim != destination.ndim:
raise ValueError("destination and loaded weight must have matching ranks")
if destination.shape[1:] != loaded_weight.shape[1:]:
@@ -47,7 +47,6 @@ from vllm.v1.kv_cache_interface import (
def canonical_qsa_rope_positions(positions: torch.Tensor) -> torch.Tensor:
"""Return exact per-token positions as ``[tokens, 1, 3]`` int64 rows."""
if positions.ndim == 1:
positions = positions.unsqueeze(0).expand(3, -1)
elif positions.ndim != 2 or positions.shape[0] not in (1, 3):
@@ -115,7 +114,6 @@ def circular_qsa_slot_mapping(
out: torch.Tensor | None = None,
) -> torch.Tensor:
"""Map each request to its fixed physical block as a circular token ring."""
if compressor_state_size <= 0:
raise ValueError("QSA circular buffer size must be positive")
if block_table.ndim != 2:
@@ -167,7 +165,6 @@ def compressed_qsa_slot_mapping(
out: torch.Tensor | None = None,
) -> torch.Tensor:
"""Build boundary-only slots for an ``MLAAttentionSpec`` QSA cache."""
if storage_block_size <= 0 or compress_ratio <= 0:
raise ValueError("QSA block size and compression ratio must be positive")
compressed_positions = torch.div(
@@ -32,7 +32,6 @@ def apply_qsa_rope(
tensor: torch.Tensor,
) -> torch.Tensor:
"""Apply the main attention's exact 1D/MRoPE composition to QSA heads."""
num_tokens, _, head_dim = tensor.shape
rotary_dim = rotary_emb.rotary_dim
cache = rotary_emb._match_cos_sin_cache_dtype(tensor) # noqa: SLF001
@@ -245,7 +244,6 @@ class QSAIndexer(nn.Module):
valid-entry count (the attention kernel's loop bound, never a token
index).
"""
metadata = self._metadata()
if metadata is None:
# Preserve step-0 indices when later MTP steps reuse the buffer.
-2
View File
@@ -86,7 +86,6 @@ def without_modelopt_fp4(
quant_config: QuantizationConfig | None,
) -> QuantizationConfig | None:
"""Return ``None`` for weights excluded from Qwen4Exp ModelOpt-FP4."""
if quant_config is not None and quant_config.get_name() == "modelopt_fp4":
return None
return quant_config
@@ -102,7 +101,6 @@ def _remap_qsa_cache_scale_name(
that cache directly, so only QSA layers need the final path component
moved to the owner's persistent ``_k_scale``/``_v_scale`` buffers.
"""
scale_suffixes = {
"k_proj.k_scale": "_k_scale",
"k_proj.output_scale": "_k_scale",
-4
View File
@@ -90,7 +90,6 @@ def _remap_quantized_layers(
def _remap_mtp_weight_name(name: str) -> str | None:
"""Map Qwen4Exp checkpoint paths into the standalone draft model."""
for checkpoint_prefix in (
"model.language_model.",
"language_model.",
@@ -250,7 +249,6 @@ class Qwen4ExpMultiTokenPredictor(nn.Module):
def _iter_qsa_attentions(self):
"""Yield MTP attention modules that own a QSA indexer."""
for layer in self.layers:
attention = getattr(layer, "self_attn", None)
if (
@@ -261,13 +259,11 @@ class Qwen4ExpMultiTokenPredictor(nn.Module):
def set_skip_topk(self, skip: bool) -> None:
"""Select on MTP step 0 and reuse its QSA indices on later steps."""
for attention in self._iter_qsa_attentions():
attention.indexer.skip_topk = skip
def compact_topk_indices(self, row_indices: torch.Tensor) -> None:
"""Keep each request's target-aligned step-0 sparse-index row."""
num_rows = row_indices.numel()
for attention in self._iter_qsa_attentions():
buffer = attention.topk_indices_buffer
@@ -869,7 +869,6 @@ class Qwen4ExpNGramEmbedding(nn.Module):
def load_weights(self, weights: Iterable[tuple[str, torch.Tensor]]) -> set[str]:
"""Load hash buffers and checkpoint-split embedding rows."""
persistent_buffers = {
"layer_multipliers": self.layer_multipliers,
"ngram_heads_offsets": self.ngram_heads_offsets,
-3
View File
@@ -727,7 +727,6 @@ def warmup_qsa_sparse_paged_attention(
selection_width: int,
) -> tuple[tuple[int, int, int], ...]:
"""Compile every production-reachable split-K/merge specialization."""
head_dim = kv_cache.shape[-1] // 2
key_cache, value_cache = kv_cache.transpose(1, 2).split(head_dim, dim=-1)
# An fp8 cache is allocated as uint8 and viewed as e4m3 at attention time.
@@ -870,7 +869,6 @@ def qsa_store_cache_rows(
rows: torch.Tensor,
) -> None:
"""Store fixed-width rows in a QSA cache without boolean indexing."""
if not cache.is_cuda or not HAS_TRITON:
raise RuntimeError("QSA CUDA cache stores require Triton")
if cache.ndim != 4 or cache.shape[2] != 1:
@@ -916,7 +914,6 @@ def qsa_compress_groups_with_ratio(
rope_cache: torch.Tensor | None = None,
) -> tuple[torch.Tensor, torch.Tensor]:
"""Pool completed groups from the compressor-state ring and raw token rows."""
if not raw_keys.is_cuda or not HAS_TRITON:
raise RuntimeError("QSA CUDA compression requires Triton")
rows = token_to_req.numel()
@@ -317,7 +317,6 @@ def warmup_qsa_mqa_paged_decode(
max_num_batched_tokens: int,
) -> tuple[tuple[int, int], ...]:
"""Compile every reachable decode specialization without launching it."""
page_size = k_cache.shape[1]
page_table_width = page_table.shape[1]
columns = page_table_width * page_size
@@ -444,7 +443,6 @@ def expand_qsa_block_indices(
out: torch.Tensor,
) -> None:
"""Expand compressed blocks and compact the causal tail of the open group."""
assert token_topk % compress_ratio == 0
block_topk = token_topk // compress_ratio
output_width = token_topk + compress_ratio - 1
@@ -524,8 +522,8 @@ def qsa_select_paged_decode(
compress_ratio: Number of logical tokens represented by a cache row.
decode_query_len: Number of query tokens per request.
block_indices: Compressed-index output buffer.
"""
"""
assert token_topk % compress_ratio == 0
assert block_indices.shape == (q.shape[0], token_topk // compress_ratio)
assert decode_query_len > 0 and q.shape[0] % decode_query_len == 0
@@ -599,8 +597,8 @@ def qsa_select_paged_prefill(
max_query_len: Maximum number of query tokens in one request.
block_indices: Compressed-index output buffer.
max_seq_len: Longest context length in the batch this step.
"""
"""
assert token_topk % compress_ratio == 0
assert block_indices.shape == (q.shape[0], token_topk // compress_ratio)
assert q.dtype == k_cache.dtype, "Q and the compressed K cache must match"
@@ -146,7 +146,6 @@ class Qwen4ExpPLELayer(nn.Module, MambaBase):
output_dtype: torch.dtype,
) -> torch.Tensor:
"""Dequantize PLE lookup output."""
return self.ple_embedding.ngram_embedding.dequantize(
embeddings,
output_dtype,