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
@@ -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,