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
+2 -1
View File
@@ -1425,7 +1425,8 @@ class DeepseekV4ForCausalLM(nn.Module, SupportsPP, SupportsEagle3):
def get_mtp_target_hidden_states(self) -> torch.Tensor | None:
"""Pre-hc_head 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]:
+1 -2
View File
@@ -496,8 +496,7 @@ class DeepSeekV4MTP(nn.Module):
return loaded_params
def _rewrite_spec_layer_name(self, spec_layer: int, name: str) -> str:
"""
Rewrite the weight name to match the format of the original model.
"""Rewrite the weight name to match the format of the original model.
Add .mtp_block for modules in transformer layer block for spec layer
and rename shared layer weights to be top level.
"""
+1 -3
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."""
from abc import ABC, abstractmethod
from collections.abc import Callable
@@ -91,7 +91,8 @@ def validate_image_sentinel_ids(tokenizer) -> None:
def grid_tokens(best_height, best_width, patch_size, downsample_ratio):
"""Number of LLM tokens the aligner grid occupies (N-layout, including
row/align padding)."""
row/align padding).
"""
n_llm_h = math.ceil((best_height // patch_size) / downsample_ratio)
n_llm_w = math.ceil((best_width // patch_size) / downsample_ratio)
num_tokens = n_llm_h * (n_llm_w + 1) + 2
@@ -196,7 +197,8 @@ def load_image(
def build_image_block(n_llm_h: int, n_llm_w: int, start_pos: int):
"""Builds the N-layout token types (final order) and the aligner-row order
for IMAGE slots."""
for IMAGE slots.
"""
compress_pad = COMPRESS_PAD_TO - 1 - start_pos % COMPRESS_PAD_TO
pad_h = n_llm_h % 2
rows = n_llm_h + pad_h
@@ -239,7 +241,8 @@ def build_image_block_pad_free(n_llm_h: int, n_llm_w: int):
class DeepseekV4VLImageProcessor:
"""Per-image transform (the PIL-input equivalent of the reference
``load_image``)."""
``load_image``).
"""
def __init__(self, config: DeepseekV4Config) -> 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
@@ -61,8 +60,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
@@ -174,8 +172,7 @@ def quantize_and_insert_k_cache(
is_ue8m0: bool = True,
use_fnuz: bool = 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):
- First 64 * 576 = 36864 bytes: Token data
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""
Fused compressor + FP8/MXFP4 UE8M0 quantization + KV cache insert kernels.
"""Fused compressor + FP8/MXFP4 UE8M0 quantization + KV cache insert kernels.
Three specialized kernels:
- _fused_kv_compress_norm_rope_insert_sparse_attn:
@@ -390,7 +389,7 @@ def _compress_gather_split_sparse_attn(
NUM_SPLITS: tl.constexpr,
HEAD_TILE: tl.constexpr, # HEAD_SIZE // NUM_SPLITS
):
"""Stage 1: per-(token, head-split) compress gather, write to fp32 scratch
"""Stage 1: per-(token, head-split) compress gather, write to fp32 scratch.
No-overlap gather (cr>=128) on rows [0, COMPRESS_RATIO)
"""
@@ -639,7 +638,7 @@ def compress_norm_rope_store_two_stage_triton(
num_decode_tokens: int,
compress_scratch: torch.Tensor,
) -> None:
"""Two-stage split compressor dispatch for head=512 cr>=128 (no-overlap)
"""Two-stage split compressor dispatch for head=512 cr>=128 (no-overlap).
Run the occupancy-fanned two-stage split for prefill [num_decodee_tokens:]
to fill the CUs, and use the original single-pass launcher
@@ -312,7 +312,8 @@ class FusedIndexerQRopeQuantTritonKernel(
def _indexer_weights_out_dtypes(vllm_config: Any) -> tuple[torch.dtype, ...]:
"""Weights dtypes the model's indexer layers ask for: fp32 for the dense
scoring kernels, plus bf16 when the DeepSeek V4.1 sparse-logits indexer
(`SparseMQAIndexer`) is enabled."""
(`SparseMQAIndexer`) is enabled.
"""
if vllm_config.attention_config.indexer_sparse_logits:
return (torch.float32, torch.bfloat16)
return (torch.float32,)
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""
Fused inverse RoPE + block-scaled FP8 quantization kernel for DeepseekV4 attention.
"""Fused inverse RoPE + block-scaled FP8 quantization kernel for DeepseekV4 attention.
Output scale format is pre-transformed (MN-major TMA-aligned; FP32 on SM90,
INT32-packed UE8M0 on SM100) so fp8_einsum skips transform_sf_into_required_layout.
@@ -380,6 +379,7 @@ def fused_inv_rope_fp8_quant(
Returns:
Rotated output in [T, G, D] and its FP8 scales. The scale tensor is
empty when quantization is disabled.
"""
from vllm.utils.deep_gemm import get_tma_aligned_size
+1
View File
@@ -263,6 +263,7 @@ def run_dp_sharded_vision_tower(
Returns:
One ``(n_aligner_rows, hidden_size)`` embedding tensor per image.
"""
tp_size = get_tensor_model_parallel_world_size()
tp_rank = get_tensor_model_parallel_rank()
@@ -42,7 +42,8 @@ class DeepseekV4CPUCompressor(DeepseekCompressor):
weight loading (see
``DeepseekV4CPUAttention.process_weights_after_loading``) -- the CPU
kernel requires fp32/contiguous but the checkpoint loads this weight
in bf16, and it never changes after loading."""
in bf16, and it never changes after loading.
"""
self._norm_weight_fp32 = self.norm.weight.to(torch.float32).contiguous()
def forward(
+2 -1
View File
@@ -118,7 +118,8 @@ class DeepseekV4CPUSparseSWAMetadataBuilder(DeepseekSparseSWAMetadataBuilder):
) -> dict[str, FlashMLASchedMeta | None]:
"""CPU never runs the FlashMLA tile-scheduler planner (that's a CUDA
C++ decode-path concern) -- always return the all-``None`` sentinel
the shared base's own CPU branch returns."""
the shared base's own CPU branch returns.
"""
return {
_LAYER_TYPE_SWAONLY: None,
_LAYER_TYPE_C4A: None,
+16 -8
View File
@@ -176,13 +176,15 @@ def _fused_indexer_q_rope_quant_cpu(
class _NoOpEvent:
"""Stand-in for ``torch.cuda.Event`` on CPU: since CPU never sets an aux
stream list, these events are constructed but never actually used."""
stream list, these events are constructed but never actually used.
"""
class DeepseekV4CPUIndexerCache(DeepseekV4IndexerCache):
"""CPU indexer K-cache descriptor: same fields as the shared base, just
pointing ``get_attn_backend()`` at ``DeepseekV4CPUIndexerBackend``
instead of the shared, CUDA/XPU-oriented ``DeepseekV4IndexerBackend``."""
instead of the shared, CUDA/XPU-oriented ``DeepseekV4IndexerBackend``.
"""
def get_attn_backend(self) -> type[AttentionBackend]:
return DeepseekV4CPUIndexerBackend
@@ -209,7 +211,8 @@ class DeepseekV4CPUIndexer(DeepseekV4Indexer):
compressor run straight-line instead of through
``maybe_execute_in_parallel``; the short-context check drops the
CUDA-only ``is_current_stream_capturing()`` guard (always False
here)."""
here).
"""
compressor = self.compressor
attn_metadata = get_forward_context().attn_metadata
@@ -309,7 +312,8 @@ class DeepseekV4CPUAttention(DeepseekV4Attention):
"""Snapshot and pack ``wo_a``'s weight into a bf16 copy for
``bmm_cpu`` before the FP8 kernel's own
``process_weights_after_loading`` VNNI-repacks it in place for
row-major reads ``_o_proj`` never does."""
row-major reads ``_o_proj`` never does.
"""
wo_a = self.wo_a
quant_method = wo_a.quant_method
orig_pwal = quant_method.process_weights_after_loading
@@ -400,7 +404,8 @@ class DeepseekV4CPUAttention(DeepseekV4Attention):
) -> torch.Tensor:
"""CPU override: only the fp8_ds_mla (uint8) SWA cache layout is
supported here, so the base method's bf16/per-tensor-fp8 branches
are dropped."""
are dropped.
"""
if not isinstance(attn_metadata, dict):
# Profile run: kernel doesn't fire; produce a padded tensor so
# downstream FlashMLA gets the right shape.
@@ -445,7 +450,8 @@ class DeepseekV4CPUAttention(DeepseekV4Attention):
) -> tuple[torch.Tensor, torch.Tensor | None, torch.Tensor]:
"""CPU override: two ``RMSNorm`` calls instead of the shared
``fused_q_kv_rmsnorm``, whose raw ``@triton.jit`` kernel fails to
link under triton-cpu (``undefined symbol: __truncdfbf2``)."""
link under triton-cpu (``undefined symbol: __truncdfbf2``).
"""
qr, kv = qr_kv.split([self.q_lora_rank, self.head_dim], dim=-1)
return self.q_norm(qr), None, self.kv_norm(kv)
@@ -463,7 +469,8 @@ class DeepseekV4CPUAttention(DeepseekV4Attention):
) -> None:
"""CPU override: no aux streams, so query-projection+KV-insert, the
indexer, and the compressor run straight-line instead of through
execute_in_parallel/maybe_execute_in_parallel."""
execute_in_parallel/maybe_execute_in_parallel.
"""
attn_metadata = get_forward_context().attn_metadata
indexer = self.indexer
compressor = self.compressor
@@ -512,7 +519,8 @@ class DeepseekV4CPUAttention(DeepseekV4Attention):
out: torch.Tensor,
) -> None:
"""CPU override: identical body, minus ``@eager_break_during_capture``
(this platform never captures a CUDA graph, so it was a no-op)."""
(this platform never captures a CUDA graph, so it was a no-op).
"""
if self.indexer is not None and index_q is not None:
assert index_weights is not None
# index_q_scale is always None on CPU (FP8-only path).
+1
View File
@@ -23,6 +23,7 @@ def map_local_to_global_slots_cpu(
Returns:
[N, K] int64 global slot ids, -1 where ``local_indices`` was invalid.
"""
valid = local_indices >= 0
safe_local = local_indices.clamp(min=0).to(torch.int64)
+2 -1
View File
@@ -907,7 +907,8 @@ class DeepseekV4ForCausalLM(nn.Module, SupportsPP, SupportsEagle3):
def get_mtp_target_hidden_states(self) -> torch.Tensor | None:
"""Pre-hc_head 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
@@ -159,7 +159,8 @@ class DeepseekV4MegaMoEExpertsFI(DeepseekV4MegaMoEExperts):
def _realloc_nvfp4_params(self) -> None:
"""Swap the mx-recipe scale params for the NVFP4 checkpoint's:
fp8-e4m3 per-16 block scales plus the per-tensor second-level
scales (weight_scale_2, input_scale) modelopt exports."""
scales (weight_scale_2, input_scale) modelopt exports.
"""
n_e = self.num_local_experts
inter = self.intermediate_size
hidden = self.hidden_size
@@ -56,7 +56,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:
+2 -1
View File
@@ -1985,7 +1985,8 @@ class DeepseekV4ForCausalLM(
def get_mtp_target_hidden_states(self) -> torch.Tensor | None:
"""Pre-hc_head 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]:
+1 -2
View File
@@ -518,8 +518,7 @@ class DeepSeekV4MTP(nn.Module):
self.finalize_mega_moe_weights()
def _rewrite_spec_layer_name(self, spec_layer: int, name: str) -> str:
"""
Rewrite the weight name to match the format of the original model.
"""Rewrite the weight name to match the format of the original model.
Add .mtp_block for modules in transformer layer block for spec layer
and rename shared layer weights to be top level.
"""
+2 -1
View File
@@ -1378,7 +1378,8 @@ class DeepseekV4ForCausalLM(nn.Module, SupportsPP, SupportsEagle3, SupportsLoRA)
def get_mtp_target_hidden_states(self) -> torch.Tensor | None:
"""Pre-hc_head 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]:
+1 -2
View File
@@ -493,8 +493,7 @@ class DeepSeekV4MTP(nn.Module):
layer.mtp_block.ffn.finalize_mega_moe_weights()
def _rewrite_spec_layer_name(self, spec_layer: int, name: str) -> str:
"""
Rewrite the weight name to match the format of the original model.
"""Rewrite the weight name to match the format of the original model.
Add .mtp_block for modules in transformer layer block for spec layer
and rename shared layer weights to be top level.
"""