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
@@ -1055,7 +1055,8 @@ CONV_EQUIV_SEQ_LENS = [[1], [7], [64], [65], [1, 2, 3], [63, 64, 65], [128, 129]
|
||||
|
||||
def _conv_fp32_oracle(x, weight, bias, seq_lens, activation="silu"):
|
||||
"""High-precision conv reference: everything in float32, no bf16 rounding.
|
||||
x: [total_tokens, dim] (no initial state). Returns [total_tokens, dim]."""
|
||||
x: [total_tokens, dim] (no initial state). Returns [total_tokens, dim].
|
||||
"""
|
||||
xf = x.float()
|
||||
wf = weight.float().unsqueeze(1)
|
||||
bf = bias.float()
|
||||
@@ -1164,7 +1165,8 @@ def test_conv_cpp_no_worse_than_torch_vs_fp32(seq_lens):
|
||||
def test_conv_cpp_vnni_packed_matches_torch(seq_lens):
|
||||
"""The exact runtime prefill sequence (VNNI-packed weight + SD-layout
|
||||
conv_state view + is_vnni=True) must match the torch fallback. Validates
|
||||
the packing + layout handoff on any AVX-512BF16 CPU."""
|
||||
the packing + layout handoff on any AVX-512BF16 CPU.
|
||||
"""
|
||||
x, weight, bias = _conv_inputs(sum(seq_lens))
|
||||
out_torch, _ = _run_prefill_torch(x, weight, bias, seq_lens)
|
||||
out_vnni, _ = _run_prefill_cpp(x, weight, bias, seq_lens, is_vnni=True)
|
||||
@@ -1178,7 +1180,8 @@ def test_conv_cpp_vnni_packed_matches_torch(seq_lens):
|
||||
@torch.inference_mode()
|
||||
def test_conv_update_cpp_matches_torch(batch):
|
||||
"""Decode conv: causal_conv1d_update_cpu matches causal_conv1d_update_torch,
|
||||
including the in-place conv_state update (the next-step handoff)."""
|
||||
including the in-place conv_state update (the next-step handoff).
|
||||
"""
|
||||
from vllm.model_executor.layers.mamba.ops.cpu.causal_conv1d import (
|
||||
causal_conv1d_update_torch,
|
||||
)
|
||||
|
||||
@@ -36,8 +36,7 @@ def causal_conv1d_ref(
|
||||
final_states_out: torch.Tensor | None = None,
|
||||
activation: str | None = "silu",
|
||||
):
|
||||
"""
|
||||
x: (batch, dim, seqlen)
|
||||
"""x: (batch, dim, seqlen)
|
||||
weight: (dim, width)
|
||||
bias: (dim,)
|
||||
initial_states: (batch, dim, width - 1)
|
||||
@@ -72,8 +71,7 @@ def causal_conv1d_ref(
|
||||
def causal_conv1d_update_ref(
|
||||
x, conv_state, weight, bias=None, activation=None, cache_seqlens=None
|
||||
):
|
||||
"""
|
||||
x: (batch, dim) or (batch, dim, seqlen)
|
||||
"""x: (batch, dim) or (batch, dim, seqlen)
|
||||
conv_state: (batch, dim, state_len), where state_len >= width - 1
|
||||
weight: (dim, width)
|
||||
bias: (dim,)
|
||||
@@ -136,8 +134,7 @@ def causal_conv1d_opcheck_fn(
|
||||
activation: str | None = "silu",
|
||||
null_block_id: int = NULL_BLOCK_ID,
|
||||
):
|
||||
"""
|
||||
x: (batch, dim, seqlen)
|
||||
"""x: (batch, dim, seqlen)
|
||||
weight: (dim, width)
|
||||
bias: (dim,)
|
||||
seq_idx: (batch, seqlen)
|
||||
|
||||
@@ -51,8 +51,7 @@ def selective_scan_ref(
|
||||
prev_state=None,
|
||||
final_state_out=None,
|
||||
):
|
||||
"""
|
||||
u: r(B D L)
|
||||
"""u: r(B D L)
|
||||
delta: r(B D L)
|
||||
A: c(D N) or r(D N)
|
||||
B: c(D N) or r(B N L) or r(B N 2L) or r(B G N L) or (B G N L)
|
||||
@@ -135,7 +134,7 @@ def selective_scan_opcheck_fn(
|
||||
cu_chunk_seqlen=None,
|
||||
last_chunk_indices=None,
|
||||
):
|
||||
"""if return_last_state is True, returns (out, last_state)
|
||||
"""If return_last_state is True, returns (out, last_state)
|
||||
last_state has shape (batch, dim, dstate).
|
||||
"""
|
||||
if u.stride(-1) != 1:
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
"""
|
||||
Unit tests for the JSON-based config loader added to selective_state_update.
|
||||
"""Unit tests for the JSON-based config loader added to selective_state_update.
|
||||
|
||||
Tests cover:
|
||||
- Flat MoE-style filename generation
|
||||
@@ -123,7 +122,8 @@ def test_fallback_when_no_config(monkeypatch, tmp_path):
|
||||
|
||||
def test_nearest_effective_batch_interpolation(monkeypatch, tmp_path):
|
||||
"""When effective_batch = batch*nheads is not an exact key, the closest
|
||||
key should be selected."""
|
||||
key should be selected.
|
||||
"""
|
||||
_write_config(
|
||||
tmp_path,
|
||||
dstate=32,
|
||||
@@ -168,7 +168,8 @@ def test_nearest_effective_batch_interpolation(monkeypatch, tmp_path):
|
||||
|
||||
def test_non_dict_json_returns_none(monkeypatch, tmp_path):
|
||||
"""A valid JSON file that is not a dict (e.g. a list) must be ignored
|
||||
and return None rather than raising AttributeError."""
|
||||
and return None rather than raising AttributeError.
|
||||
"""
|
||||
device_name = get_ssm_device_name()
|
||||
config_path = tmp_path / get_ssm_config_file_name(
|
||||
_HEADDIM, 16, _CACHE_DTYPE, device_name
|
||||
@@ -190,7 +191,8 @@ def test_non_dict_json_returns_none(monkeypatch, tmp_path):
|
||||
|
||||
def test_empty_config_falls_back_to_heuristic(monkeypatch, tmp_path):
|
||||
"""An empty JSON object {} must not crash min() — should fall back
|
||||
to the hard-coded heuristic."""
|
||||
to the hard-coded heuristic.
|
||||
"""
|
||||
_write_config(tmp_path, dstate=64, payload={})
|
||||
|
||||
monkeypatch.setenv("VLLM_TUNED_CONFIG_FOLDER", str(tmp_path))
|
||||
|
||||
@@ -41,14 +41,15 @@ def segsum(x):
|
||||
|
||||
|
||||
def ssd_minimal_discrete(X, A, B, C, block_len, initial_states=None):
|
||||
"""
|
||||
Arguments:
|
||||
"""Arguments:
|
||||
X: (batch, length, n_heads, d_head)
|
||||
A: (batch, length, n_heads)
|
||||
B: (batch, length, n_heads, d_state)
|
||||
C: (batch, length, n_heads, d_state)
|
||||
|
||||
Return:
|
||||
Y: (batch, length, n_heads, d_head)
|
||||
|
||||
"""
|
||||
assert X.dtype == A.dtype == B.dtype == C.dtype
|
||||
assert X.shape[1] % block_len == 0
|
||||
|
||||
@@ -68,7 +68,8 @@ def _run_prefill_decode_equivalence(
|
||||
the exact fp32 recurrence (and each other). All paths use the production dt
|
||||
flow (raw dt + softplus + a per-head dt_bias), so this also checks prefill
|
||||
and decode apply the softplus/bias preprocessing consistently. ``state_dtype``
|
||||
is the recurrent-state precision; ``act_dtype`` the activation/buffer one."""
|
||||
is the recurrent-state precision; ``act_dtype`` the activation/buffer one.
|
||||
"""
|
||||
device = current_platform.device_type
|
||||
rtol, atol = _prefill_tolerances(act_dtype)
|
||||
set_random_seed(seed)
|
||||
|
||||
@@ -95,7 +95,8 @@ def _run_standard_decode(
|
||||
) -> None:
|
||||
"""Drive ``num_steps`` decode steps and check every path against the
|
||||
trusted recurrence. ``state_dtype`` is the recurrent-state precision;
|
||||
``act_dtype`` is the activation/buffer precision."""
|
||||
``act_dtype`` is the activation/buffer precision.
|
||||
"""
|
||||
device = "cuda"
|
||||
both_fp32 = state_dtype == torch.float32 and act_dtype == torch.float32
|
||||
rtol, atol = _tolerances(torch.float32 if both_fp32 else torch.bfloat16)
|
||||
@@ -539,7 +540,8 @@ def test_replayssm_standard_decode_tp_head_shard_equivalence(
|
||||
separable: one run over all heads must equal concatenating ``tp`` independent
|
||||
per-rank runs on ``nheads // tp`` heads and ``ngroups // tp`` groups. This
|
||||
guards the per-rank divisors and group->head mapping the state-shape wiring
|
||||
relies on. The real TP1==TP2 engine check lives in the v1/e2e suite."""
|
||||
relies on. The real TP1==TP2 engine check lives in the v1/e2e suite.
|
||||
"""
|
||||
state_dtype, act_dtype = precision
|
||||
nheads, headdim, dstate, ngroups = geometry
|
||||
assert nheads % tp == 0 and ngroups % tp == 0
|
||||
|
||||
@@ -9,8 +9,7 @@ from einops import rearrange, repeat
|
||||
def selective_state_update_ref(
|
||||
state, x, dt, A, B, C, D=None, z=None, dt_bias=None, dt_softplus=False
|
||||
):
|
||||
"""
|
||||
Argument:
|
||||
"""Argument:
|
||||
state: (batch, dim, dstate) or (batch, nheads, dim, dstate)
|
||||
x: (batch, dim) or (batch, nheads, dim)
|
||||
dt: (batch, dim) or (batch, nheads, dim)
|
||||
@@ -20,8 +19,10 @@ def selective_state_update_ref(
|
||||
D: (dim,) or (nheads, dim)
|
||||
z: (batch, dim) or (batch, nheads, dim)
|
||||
dt_bias: (dim,) or (nheads, dim)
|
||||
|
||||
Return:
|
||||
out: (batch, dim) or (batch, nheads, dim)
|
||||
|
||||
"""
|
||||
has_heads = state.dim() > 3
|
||||
if state.dim() == 3:
|
||||
|
||||
Reference in New Issue
Block a user