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
+4 -2
View File
@@ -1062,7 +1062,8 @@ class DeepseekV41LLMForCausalLM(
@property
def token_lookback_depth(self) -> int:
"""Tokens before a chunk start the engram hash needs; the model runner
passes them as `lookback_token_ids`."""
passes them as `lookback_token_ids`.
"""
engram_hash = self.model.engram_hash
return engram_hash.lookback_depth if engram_hash is not None else 0
@@ -1086,7 +1087,8 @@ class DeepseekV41LLMForCausalLM(
def get_mtp_target_hidden_states(self) -> torch.Tensor | None:
"""Pre-collapse residual stream buffer (max_num_batched_tokens,
hc_mult * hidden_size) for the MTP draft model. Populated by
forward(); valid after each target step."""
forward(); valid after each target step.
"""
return getattr(self.model, "_mtp_hidden_buffer", None)
def load_weights(self, weights: Iterable[tuple[str, torch.Tensor]]) -> set[str]:
+2 -1
View File
@@ -209,7 +209,8 @@ class DeepseekV41ForCausalLM(nn.Module, SupportsMultiModal, SupportsPP, Supports
self, image_embeds: torch.Tensor, types: torch.Tensor
) -> torch.Tensor:
"""Full image span: aligner rows at IMAGE slots, the learned
delimiter vectors at IMAGE_START/IMAGE_NEW_LINE/IMAGE_END."""
delimiter vectors at IMAGE_START/IMAGE_NEW_LINE/IMAGE_END.
"""
types = types.to(image_embeds.device)
span = image_embeds.new_empty(types.numel(), image_embeds.shape[-1])
dtype = image_embeds.dtype
+3 -4
View File
@@ -1,8 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""
DeepseekV4 MLA Attention Layer
"""
"""DeepseekV4 MLA Attention Layer"""
import math
from abc import ABC, abstractmethod
@@ -1068,7 +1066,8 @@ class DeepseekV4Attention(nn.Module, AttentionLayerBase, ABC):
def _compressed_kv_cache(self) -> torch.Tensor:
"""The compressed-KV cache tensor of this layer's kv source (own
cache for kv-source layers)."""
cache for kv-source layers).
"""
if self.is_kv_source:
return self.kv_cache
assert self.compressed_cache_prefix is not None
+6 -3
View File
@@ -564,7 +564,8 @@ def _engram_head_shard_weight_loader(
param: torch.nn.Parameter, loaded_weight: torch.Tensor
) -> None:
"""Load this rank's complete head buckets. ue8m0 scales arrive as
float8_e8m0fnu; keep the raw bytes (the param stores uint8)."""
float8_e8m0fnu; keep the raw bytes (the param stores uint8).
"""
part_rows = param.shape[0]
if loaded_weight.dtype == torch.float8_e8m0fnu:
loaded_weight = loaded_weight.view(torch.uint8)
@@ -739,7 +740,8 @@ class ParallelEngramEmbedding(nn.Module):
def forward(self, indices: torch.Tensor) -> torch.Tensor:
"""indices: [num_tokens, n_hash_cols] -> [num_tokens, n_hash_cols, dim]
bf16, gathered from all shards for this replica's tokens."""
bf16, gathered from all shards for this replica's tokens.
"""
out = torch.empty(
(indices.shape[0], self.part_n_hash_cols, self.dim),
dtype=torch.bfloat16,
@@ -1000,7 +1002,8 @@ class Engram(nn.Module):
) -> torch.Tensor:
"""hidden_states: [T, hc_mult, dim]; hash_ids: [T, n_hash_cols] (all
tokens, pre sequence-parallel shard); token_mask: [T], False shuts
the gate so those positions pass through untouched."""
the gate so those positions pass through untouched.
"""
kv = self.wkv(self.embed(hash_ids).flatten(-2))
num_kv_tokens = hash_ids.shape[0]
assert token_mask is None or token_mask.shape == (num_kv_tokens,)
@@ -82,7 +82,8 @@ def num_image_tokens(n_llm_h: int, n_llm_w: int) -> int:
def solve_resize_ratio(height, width, patch_size, downsample_ratio, max_n_token):
"""Largest aspect-preserving pixel size whose token grid still fits in
max_n_token. Returns (best_height, best_width)."""
max_n_token. Returns (best_height, best_width).
"""
r = height / width
max_w_float = math.sqrt((max_n_token - 2) / r + 0.25) - 0.5
max_h_float = max_w_float * r
@@ -105,7 +106,8 @@ def safe_resize(
height, width, best_height, best_width, patch_size, downsample_ratio, max_n_token
):
"""Shrink the pixel size until the image costs at most max_n_token LLM
tokens."""
tokens.
"""
n_llm_h, n_llm_w = llm_grid(best_height, best_width, patch_size, downsample_ratio)
if num_image_tokens(n_llm_h, n_llm_w) > max_n_token:
best_height, best_width = solve_resize_ratio(
@@ -171,7 +173,8 @@ def image_token_types(n_llm_h: int, n_llm_w: int) -> torch.Tensor:
class DeepseekV4VLImageProcessor:
"""Per-image transform (the PIL-input equivalent of the reference
``load_image``)."""
``load_image``).
"""
def __init__(self, config: DeepseekV41Config) -> None:
super().__init__()
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""
Triton kernels for DeepseekV4 paged K-cache management and sparse-attention index
"""Triton kernels for DeepseekV4 paged K-cache management and sparse-attention index
preparation.
- quantize_and_insert_k_cache: quantize bf16 K to UE8M0 FP8 and insert into
@@ -76,8 +75,7 @@ def quantize_and_insert_k_kernel(
n_quant_blocks: tl.constexpr, # 8 (7 real + 1 padding)
use_fnuz: tl.constexpr = False,
):
"""
Quantize K tensor and insert into paged K cache.
"""Quantize K tensor and insert into paged K cache.
K Cache block layout (block_size=64 tokens):
- [0, 64*576): Token data, each token has 448 fp8 + 128 bf16
@@ -251,8 +249,7 @@ def quantize_and_insert_k_cache(
use_fnuz: bool = False,
bytes_per_token: int = V4_BYTES_PER_TOKEN,
):
"""
Quantize K tensor and insert into paged K cache.
"""Quantize K tensor and insert into paged K cache.
``bytes_per_token`` picks the record (see the module header): the V4 one,
or V4.1's all-dims MXFP8 one.
@@ -58,6 +58,7 @@ def fused_save_compress_norm(
rms_norm_eps: RMSNorm epsilon.
compress_ratio: Group size, either 1 or 2.
latent_out: BF16 [tokens, 512], written only at valid group boundaries.
"""
assert compress_ratio in (1, 2)
assert kv_score.dtype == torch.float32
@@ -46,11 +46,13 @@ def indexer_k_norm_rope_store(
cos_sin_cache: [max_pos, rope_head_dim] GPT-J layout (cos half, then
sin half), from the layer's compress-RoPE instance.
rms_norm_weight: [128] k_norm weight.
rms_norm_eps: Epsilon of the k_norm RMSNorm.
k_cache: uint8 paged indexer cache [num_blocks, block_size, row_bytes].
kv_slot_mapping: [num_tokens] slots in the indexer cache (-1 = skip).
compress_ratio: group size; keys are emitted at group boundaries.
use_fp4_cache: MXFP4 (2 nibbles/byte + ue8m0 per 32) when True, else
per-token FP8 with a single fp32 scale.
"""
num_tokens = kv_slot_mapping.numel()
assert k_pre.ndim == 2 and k_pre.shape[1] == 128
@@ -54,7 +54,8 @@ def _get_flashinfer_dsv4_workspace(device: torch.device) -> torch.Tensor:
def _packed_block_span(pool: torch.Tensor) -> int:
"""Per-block stride of ``pool`` in tokens (``stride(0)//stride(-2)``): ==
block_size for unpacked KV, larger when packed (#44577). Raises if not
token-aligned."""
token-aligned.
"""
block_stride = pool.stride(0)
token_stride = pool.stride(-2)
if block_stride % token_stride != 0:
+4 -2
View File
@@ -1179,7 +1179,8 @@ class DeepseekV41LLMForCausalLM(
@property
def token_lookback_depth(self) -> int:
"""Tokens before a chunk start the engram hash needs; the model runner
passes them as `lookback_token_ids`."""
passes them as `lookback_token_ids`.
"""
engram_hash = self.model.engram_hash
return engram_hash.lookback_depth if engram_hash is not None else 0
@@ -1203,7 +1204,8 @@ class DeepseekV41LLMForCausalLM(
def get_mtp_target_hidden_states(self) -> torch.Tensor | None:
"""Pre-collapse residual stream buffer (max_num_batched_tokens,
hc_mult * hidden_size) for the MTP draft model. Populated by
forward(); valid after each target step."""
forward(); valid after each target step.
"""
return getattr(self.model, "_mtp_hidden_buffer", None)
def load_weights(self, weights: Iterable[tuple[str, torch.Tensor]]) -> set[str]:
+2 -1
View File
@@ -209,7 +209,8 @@ class DeepseekV41ForCausalLM(nn.Module, SupportsMultiModal, SupportsPP, Supports
self, image_embeds: torch.Tensor, types: torch.Tensor
) -> torch.Tensor:
"""Full image span: aligner rows at IMAGE slots, the learned
delimiter vectors at IMAGE_START/IMAGE_NEW_LINE/IMAGE_END."""
delimiter vectors at IMAGE_START/IMAGE_NEW_LINE/IMAGE_END.
"""
types = types.to(image_embeds.device)
span = image_embeds.new_empty(types.numel(), image_embeds.shape[-1])
dtype = image_embeds.dtype