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:
co-authored by
Claude Opus 5
parent
804e5377aa
commit
8c1557a79c
@@ -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
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user