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
+10 -5
View File
@@ -62,7 +62,8 @@ class AttentionState(NamedTuple):
@dataclass(frozen=True)
class BatchExecutionDescriptor:
"""Describes the shape of the batch and CG mode to run; this is used to make shape
matches between the capture and runtime."""
matches between the capture and runtime.
"""
cg_mode: CUDAGraphMode
num_tokens: int
@@ -90,7 +91,8 @@ def make_cudagraph_stats(
class CreateForwardFn(Protocol):
"""Factory that prepares inputs (OUTSIDE the graph) and returns a
forward_fn. Called with warmup=True for the warmup pass and warmup=False
for the captured pass."""
for the captured pass.
"""
def __call__(
self,
@@ -408,6 +410,8 @@ class CudaGraphManager:
it is invoked once with warmup=True and again with warmup=False
because attention backends may mutate or lazily initialize
metadata during warmup.
progress_bar_desc: Description shown on the capture progress bar.
"""
with graph_capture(device=self.device), ExitStack() as stack:
if self.ubatch_runner is not None:
@@ -503,7 +507,6 @@ class CudaGraphManager:
num_ubatches: int = 1,
) -> BatchExecutionDescriptor:
"""Find matching cudagraph descriptor from priority-ordered candidates."""
effective_loras = self._resolve_effective_loras(num_active_loras)
key = (num_tokens, effective_loras)
if self._graphs_captured and num_tokens > 0 and key in self._candidates:
@@ -952,7 +955,8 @@ def profile_cudagraph_memory(runner: "GPUModelRunner") -> int:
def _extrapolate_full_graph_memory(mem_samples: list[int], total_graphs: int) -> int:
"""Extrapolate the total FULL capture cost from samples of the largest
graphs. The first capture allocates the pool baseline; later graphs mostly
reuse it, so the second sample is taken as the per-graph cost."""
reuse it, so the second sample is taken as the per-graph cost.
"""
if not mem_samples:
return 0
first_capture = mem_samples[0]
@@ -989,7 +993,8 @@ def _init_minimal_kv_cache_for_profiling(runner: "GPUModelRunner") -> None:
def _teardown_profiling_state(runner: "GPUModelRunner") -> None:
"""Release the profiling KV cache and captured graphs while keeping model
weights, so the real ``initialize_kv_cache`` starts from a clean slate."""
weights, so the real ``initialize_kv_cache`` starts from a clean slate.
"""
torch.accelerator.synchronize()
if hasattr(runner.model_state, "_mamba_ctx"):
runner.model_state._mamba_ctx = None
+8 -2
View File
@@ -55,8 +55,7 @@ def sync_cudagraph_and_dp_padding(
allow_ubatching: bool = False,
uniform_decode: bool = False,
) -> tuple[BatchExecutionDescriptor, DPSyncState | None]:
"""
Coordinates the batch descriptor and DP padding across all ranks.
"""Coordinates the batch descriptor and DP padding across all ranks.
`parallel_config` is only needed to decide whether to microbatch, so callers
that never do (`allow_ubatching=False`) can leave it out.
@@ -248,6 +247,12 @@ def dispatch_cg_and_sync_dp(
need_eager: Force `CUDAGraphMode.NONE` instead of dispatching.
num_active_loras: Active LoRA count for this rank. Does not need
cross-rank agreement; it never changes a bucket's token count.
parallel_config: Only needed to decide whether to microbatch, so
callers that never do (`allow_ubatching=False`) can leave it out.
allow_ubatching: Whether this rank's batch may be split into
microbatches. Agreed across ranks before it takes effect.
uniform_decode: Whether this rank's batch is a uniform decode, used
to pick the microbatching split.
dp_sync: Agreement from a prior dispatch over this same batch, to reuse.
Must come from a batch with this same padded `num_tokens` and the
same `uniform_token_count`; `num_reqs` may differ, as neither
@@ -257,6 +262,7 @@ def dispatch_cg_and_sync_dp(
Returns:
(batch_desc, sync), where `sync` is this batch's agreement for a later
dispatch to reuse. It is None when `dp_size` is 1 or no rank has work.
"""
reuse_eager = dp_sync is not None and dp_sync.eager
+1 -2
View File
@@ -21,8 +21,7 @@ def get_lora_capture_cases(
lora_config: "LoRAConfig | None",
compilation_config: "CompilationConfig",
) -> list[int]:
"""
Return num_active_loras values for cudagraph capture.
"""Return num_active_loras values for cudagraph capture.
When cudagraph_specialize_lora=True: powers of 2 up to max_loras, plus
max_loras+1. When False: [0, max_loras+1]. When LoRA disabled: [0].
+1 -2
View File
@@ -24,8 +24,7 @@ class EncoderCache:
self.mm_features.pop(req_id, None)
def reset_mm_cache(self) -> None:
"""
Clear the multi-modal cache that was used during profiling,
"""Clear the multi-modal cache that was used during profiling,
but no longer needed during inference.
"""
# NOTE: v2 encoder cache profiling skips the multi-modal cache
+3 -3
View File
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""
NOTE: Coding style guide for this file:
"""NOTE: Coding style guide for this file:
This model runner is shared by all models: text and multimodal, generative
and embedding, public and private. As a result, this file must only contain
code that is common to every model. Model-specific behavior belongs in the
@@ -2229,7 +2228,8 @@ class GPUModelRunner(LoRAModelRunnerMixin):
def shutdown(self) -> None:
"""Release GPU tensors (model weights, KV caches, workspace) so that
memory is reclaimable when running in the same process."""
memory is reclaimable when running in the same process.
"""
torch.accelerator.synchronize()
self.cudagraph_manager = None
self.fast_prefill = None
+2 -1
View File
@@ -144,7 +144,8 @@ class ModelState(ABC):
) -> None:
"""Hook run on real batches before the forward pass (after block tables
are gathered). Used by mamba "align" prefix caching to pre-copy state
across block boundaries. No-op by default."""
across block boundaries. No-op by default.
"""
return None
def postprocess_state(
+4 -3
View File
@@ -38,8 +38,8 @@ def compute_need_sampled_mask(input_batch: InputBatch) -> np.ndarray | None:
"""Return a bool array of shape `[input_batch.num_reqs]` marking requests
that produce a sampled token this step, and therefore must have that token
(and the draft block proposed from it) propagated to the earlier PP stages.
Returns None if no request in the batch produces a sample."""
Returns None if no request in the batch produces a sample.
"""
old_computed = input_batch.num_computed_tokens_np
prefill_len = input_batch.prefill_len_np
# Exclude non-final prefill chunks (they don't produce a sample).
@@ -179,7 +179,8 @@ class PPHandler:
def receive(self, input_batch: InputBatch) -> bool:
"""Returns True iff sampled tokens need to be gathered from *all*
requests in the batch."""
requests in the batch.
"""
assert not self.is_last_rank
need_sampled_mask = compute_need_sampled_mask(input_batch)
if need_sampled_mask is None:
+2 -1
View File
@@ -76,7 +76,8 @@ MAX_COMPACT_SUPPORT = 2048
class SamplingMaskTensors(NamedTuple):
"""Device-side masks pending async D2H: compact ids, plus the bitmask as
the exact fallback for rows wider than ``max_num_kept``."""
the exact fallback for rows wider than ``max_num_kept``.
"""
# [num_requests, max_num_kept]
token_ids: torch.Tensor
+2 -1
View File
@@ -107,7 +107,8 @@ class Sampler:
self, idx_mapping_np: np.ndarray, include_token_ids: bool = True
) -> tuple[int, int] | None:
"""(num_logprobs, max_per_req_token_ids) for the given requests, or
None when none of them want logprobs."""
None when none of them want logprobs.
"""
max_num_logprobs = self.sampling_states.max_num_logprobs(idx_mapping_np)
max_token_ids = (
self.logprob_token_ids_state.max_num_token_ids(idx_mapping_np)
+1
View File
@@ -163,6 +163,7 @@ def repeated_context_mask(
include_prompt: Search the prompt as well as the generated tokens.
skip_partial_context: Mark contexts containing start padding so they use
ordinary sampling.
"""
if max_history is not None and max_history < 1:
raise ValueError("max_history must be positive or None")
@@ -88,9 +88,14 @@ def build_cost_tables_from_curves(
"""Build cost tables: graph-padded below the capture limit, smooth above.
Args:
draft_curve: (size, cost) samples for the draft model.
verify_curve: (size, cost) samples for the verify model.
max_num_reqs: Largest request count to build a table for.
max_batch_tokens: Largest token count to build a table for.
cudagraph_limit: Largest cudagraph-captured size. At or below it,
execution pads up to the next captured size, so cost is a step
function. Above it there is no padding, so cost is continuous.
"""
def build_table(limit: int, curve: list[tuple[int, float]]) -> np.ndarray:
@@ -185,7 +190,8 @@ class AdaptiveVerificationManager:
"""Dummy-run kwargs whose step timings seed the cost tables.
Run these inside StepTimingCollector.collect(), then hand the block's
timings to set_initial_cost_curves."""
timings to set_initial_cost_curves.
"""
max_num_tokens = self.req_states.max_num_batched_tokens
size = self._cudagraph_limit = capture_sizes[-1] if capture_sizes else 0
# Also profile beyond the capture limit: real steps run there
@@ -255,7 +261,8 @@ class AdaptiveVerificationManager:
input_batch: "InputBatch",
) -> None:
"""Publish this step's raw confidences for the ranking kernel and start
copying them to the CPU, where a later step's budget reads them."""
copying them to the CPU, where a later step's budget reads them.
"""
num_reqs = input_batch.num_reqs
ready_idx = self._stale_idx ^ 1
with gpu_sync_allowed():
@@ -73,8 +73,7 @@ class AutoRegressiveSpeculator(DraftModelSpeculator):
@property
def advance_draft_positions(self) -> bool:
"""
Whether to increment positions and seq_lens between draft steps.
"""Whether to increment positions and seq_lens between draft steps.
True for Eagle/standard MTP (each step produces new KV).
False for Gemma4 MTP (Q-only, shares target KV, constant positions).
@@ -72,7 +72,8 @@ def _prepare_dflash_inputs_to_capture(
class DFlashCudaGraphManager(CudaGraphManager):
"""DFlash CudaGraphManager for the parallel-drafting query forward,
building its own attention metadata from scratch."""
building its own attention metadata from scratch.
"""
def capture(
self,
@@ -13,7 +13,6 @@ from vllm.v1.worker.gpu.spec_decode.utils import get_pp_safe_draft_load_config
def _should_share(eagle: nn.Module, flag: str, draft, target) -> bool:
"""Share when the draft has no own copy, or its copy matches the target."""
if not getattr(eagle, flag, False) or draft is None:
return True
if target is None:
@@ -29,7 +28,8 @@ def _should_share(eagle: nn.Module, flag: str, draft, target) -> bool:
def get_target_lm_head(target_model: nn.Module, target_language_model: nn.Module):
"""The target's lm_head — from get_language_model() for
*ForConditionalGeneration targets, else the top-level module."""
*ForConditionalGeneration targets, else the top-level module.
"""
return getattr(target_language_model, "lm_head", None) or getattr(
target_model, "lm_head", None
)
+2 -1
View File
@@ -268,7 +268,8 @@ class DraftModelSpeculator(BaseSpeculator):
@property
def attn_vllm_config(self) -> VllmConfig:
"""Config for the draft's attention metadata builders. Overridden by
speculators whose attention mode differs from the target's."""
speculators whose attention mode differs from the target's.
"""
return self.vllm_config
def set_attn(