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
@@ -98,7 +98,8 @@ def _kpool_softmax_rotate_write_cache_kernel(
|
||||
BLOCK_D: tl.constexpr,
|
||||
):
|
||||
"""One program per pool. softmax(slot_score+ape)-weighted sum of slot_k ->
|
||||
Hadamard-128 -> per-vector fp8 absmax quant -> write to cache at ``loc``."""
|
||||
Hadamard-128 -> per-vector fp8 absmax quant -> write to cache at ``loc``.
|
||||
"""
|
||||
row = tl.program_id(0)
|
||||
do_write = True
|
||||
if HAS_WRITE_MASK:
|
||||
@@ -212,6 +213,13 @@ def kpool_compress_and_write_cache(
|
||||
slot_score: ``[n_pools, pool_size, head_dim]`` — per-token gate score.
|
||||
ape: ``[pool_size, head_dim]`` fp32 — per-slot position bias.
|
||||
loc: ``[n_pools]`` int64 — flat physical slot per pool.
|
||||
pool_size: Number of tokens compressed into one cache entry.
|
||||
head_dim: Indexer head dimension.
|
||||
write_mask: ``[n_pools]`` bool — pools to write, or None for all.
|
||||
round_scale: Round each fp8 scale down to a power of two.
|
||||
return_compressed: Also return the compressed K and scales.
|
||||
write_cache: Write the compressed result into ``kv_cache``.
|
||||
|
||||
"""
|
||||
assert slot_k.ndim == 3
|
||||
assert slot_score.shape == slot_k.shape
|
||||
@@ -592,6 +600,10 @@ def kpool_decode_update_and_maybe_write_cache_batched(
|
||||
ape: ``[pool_size, head_dim]`` fp32.
|
||||
slot_mapping: ``[num_requests, next_n]`` int32.
|
||||
positions: ``[num_requests, next_n]`` int32.
|
||||
pool_size: Number of tokens compressed into one cache entry.
|
||||
head_dim: Indexer head dimension.
|
||||
round_scale: Round each fp8 scale down to a power of two.
|
||||
|
||||
"""
|
||||
num_requests, next_n = key.shape[0], key.shape[1]
|
||||
if num_requests == 0 or next_n == 0:
|
||||
|
||||
@@ -564,8 +564,7 @@ def fused_recurrent_gated_delta_rule(
|
||||
num_accepted_tokens: torch.Tensor | None = None,
|
||||
use_qk_l2norm_in_kernel: bool = False,
|
||||
) -> tuple[torch.Tensor, torch.Tensor]:
|
||||
r"""
|
||||
Args:
|
||||
r"""Args:
|
||||
q (torch.Tensor):
|
||||
queries of shape `[B, T, H, K]`.
|
||||
k (torch.Tensor):
|
||||
@@ -627,6 +626,7 @@ def fused_recurrent_gated_delta_rule(
|
||||
initial_state=h0,
|
||||
cu_seqlens=cu_seqlens
|
||||
)
|
||||
|
||||
"""
|
||||
if cu_seqlens is not None and q.shape[0] != 1:
|
||||
raise ValueError(
|
||||
|
||||
+17
-12
@@ -406,19 +406,24 @@ def chunk_kda_scaled_dot_kkt_fwd(
|
||||
chunk_size: int = FLA_CHUNK_SIZE,
|
||||
output_dtype: torch.dtype = torch.float32,
|
||||
) -> tuple[torch.Tensor, torch.Tensor]:
|
||||
r"""
|
||||
Compute beta * K * K^T.
|
||||
r"""Compute beta * K * K^T.
|
||||
|
||||
Args:
|
||||
q (torch.Tensor):
|
||||
The query tensor of shape `[B, T, H, K]`.
|
||||
k (torch.Tensor):
|
||||
The key tensor of shape `[B, T, H, K]`.
|
||||
beta (torch.Tensor):
|
||||
The beta tensor of shape `[B, T, H]`.
|
||||
gk (torch.Tensor):
|
||||
The cumulative sum of the gate tensor of shape `[B, T, H, K]` applied to the key tensor. Default: `None`.
|
||||
scale (float):
|
||||
Scale applied to the query-key products. Default: `None`.
|
||||
cu_seqlens (torch.Tensor):
|
||||
The cumulative sequence lengths of the input tensor.
|
||||
Default: None
|
||||
chunk_indices (torch.Tensor):
|
||||
Precomputed chunk indices for `cu_seqlens`. Default: `None`.
|
||||
chunk_size (int):
|
||||
The chunk size. Default: 64.
|
||||
output_dtype (torch.dtype):
|
||||
@@ -426,6 +431,7 @@ def chunk_kda_scaled_dot_kkt_fwd(
|
||||
|
||||
Returns:
|
||||
beta * K * K^T of shape `[B, T, H, BT]` where `BT` is the chunk size.
|
||||
|
||||
"""
|
||||
B, T, H, K = k.shape
|
||||
assert K <= 256
|
||||
@@ -1318,16 +1324,15 @@ def fused_kda_gate(
|
||||
safe_gate: bool = False,
|
||||
lower_bound: float | None = -5.0,
|
||||
) -> torch.Tensor:
|
||||
"""
|
||||
Forward pass for KDA gate:
|
||||
input g: [..., H*D]
|
||||
param A: [H] or [1, 1, H, 1]
|
||||
beta: softplus beta parameter (softplus branch only)
|
||||
threshold: softplus threshold parameter (softplus branch only)
|
||||
safe_gate: when False (default) compute y = -exp(A)*softplus(g+g_bias);
|
||||
when True compute the bounded y = lower_bound*sigmoid(exp(A)*(g+g_bias))
|
||||
lower_bound: floor for the safe_gate branch (default -5.0)
|
||||
return : [..., H, D]
|
||||
"""Forward pass for KDA gate:
|
||||
input g: [..., H*D]
|
||||
param A: [H] or [1, 1, H, 1]
|
||||
beta: softplus beta parameter (softplus branch only)
|
||||
threshold: softplus threshold parameter (softplus branch only)
|
||||
safe_gate: when False (default) compute y = -exp(A)*softplus(g+g_bias);
|
||||
when True compute the bounded y = lower_bound*sigmoid(exp(A)*(g+g_bias))
|
||||
lower_bound: floor for the safe_gate branch (default -5.0)
|
||||
return : [..., H, D]
|
||||
"""
|
||||
orig_shape = g.shape[:-1]
|
||||
|
||||
|
||||
@@ -130,7 +130,8 @@ def _resolve_kda_prefill_backend(
|
||||
"""Pick the chunked-prefill kernel: FlashKDA (fused CUDA, ~2-4x faster on
|
||||
SM90/SM10x/SM12x for bf16, head_dim 128 and a bounded gate) or the Triton
|
||||
``chunk_kda_with_fused_gate`` path. ``backend`` comes from
|
||||
``additional_config.kda_prefill_backend`` (auto / triton / flashkda)."""
|
||||
``additional_config.kda_prefill_backend`` (auto / triton / flashkda).
|
||||
"""
|
||||
if backend not in ("auto", "triton", "flashkda"):
|
||||
raise ValueError(f"Unsupported KDA prefill backend: {backend}")
|
||||
capability = current_platform.get_device_capability()
|
||||
@@ -368,7 +369,8 @@ class Glm5NextLinearAttention(GatedDeltaNetAttention):
|
||||
bounded gate ``lower_bound * sigmoid(exp(A_log) * (g + dt_bias))``,
|
||||
matching ``chunk_kda_with_fused_gate(..., safe_gate=True)``. Writes the
|
||||
attention output into ``out`` (a workspace buffer when ``None``) and
|
||||
returns ``(out, final_state)``."""
|
||||
returns ``(out, final_state)``.
|
||||
"""
|
||||
assert self._flashkda_buffer_specs is not None
|
||||
final_state, workspace, workspace_out = (
|
||||
current_workspace_manager().get_simultaneous(*self._flashkda_buffer_specs)
|
||||
|
||||
@@ -720,7 +720,8 @@ class Glm5NextMultiModalProcessor(Glm4vMultiModalProcessor):
|
||||
(image token repeat, video frame/timestamp structure) is owned by vLLM's
|
||||
prompt-update machinery — the inherited ``_get_prompt_updates`` builds
|
||||
the replacement content and the placeholder scan validates against
|
||||
exactly that."""
|
||||
exactly that.
|
||||
"""
|
||||
|
||||
def _hf_processor_applies_updates(
|
||||
self,
|
||||
|
||||
@@ -138,7 +138,8 @@ def _gather_workspace_shapes(
|
||||
"""Return ((values_shape, values_dtype), (scales_shape, scales_dtype)) for
|
||||
the K-gather workspace. FP8 path: (T, head_dim) fp8 + (T, 4) uint8 fp32
|
||||
scales. MXFP4 path: (T, head_dim // 2) uint8 packed mxfp4 +
|
||||
(T, head_dim // MXFP4_BLOCK_SIZE) uint8 ue8m0 scales."""
|
||||
(T, head_dim // MXFP4_BLOCK_SIZE) uint8 ue8m0 scales.
|
||||
"""
|
||||
if use_fp4_cache:
|
||||
return (
|
||||
((total_seq_lens, head_dim // 2), torch.uint8),
|
||||
@@ -156,7 +157,8 @@ def kv_cache_as_quant_view(
|
||||
use_fp4_cache: bool,
|
||||
) -> torch.Tensor:
|
||||
"""4D ``[num_blocks, block_size, 1, head_width]`` view expected by
|
||||
DeepGEMM, from the 3D indexer kv-cache allocation."""
|
||||
DeepGEMM, from the 3D indexer kv-cache allocation.
|
||||
"""
|
||||
if use_fp4_cache:
|
||||
assert kv_cache.ndim == 3 and kv_cache.dtype == torch.uint8
|
||||
num_blocks, block_size, _ = kv_cache.shape
|
||||
|
||||
@@ -31,7 +31,8 @@ def _fused_eh_norm_kernel(
|
||||
):
|
||||
"""MTP input fusion: zero embeds at position 0, RMSNorm(embeds) with enorm
|
||||
and RMSNorm(prev_hidden) with hnorm, written side-by-side into ``out``
|
||||
([N, 2H]) ready for the eh_proj GEMM. Replaces where + 2x RMSNorm + cat."""
|
||||
([N, 2H]) ready for the eh_proj GEMM. Replaces where + 2x RMSNorm + cat.
|
||||
"""
|
||||
tok = tl.program_id(0)
|
||||
off = tl.arange(0, BLOCK)
|
||||
mask = off < H
|
||||
|
||||
@@ -116,6 +116,7 @@ def fwht128_quant_fp8(q: torch.Tensor) -> tuple[torch.Tensor, torch.Tensor]:
|
||||
|
||||
Returns:
|
||||
(q_fp8 ``[rows, 128]`` float8_e4m3fn, scale ``[rows, 1]`` float32).
|
||||
|
||||
"""
|
||||
assert q.ndim == 2 and q.shape[1] == 128, q.shape
|
||||
assert q.dtype == torch.bfloat16
|
||||
@@ -162,7 +163,8 @@ def _kpool_softmax_rotate_write_cache_kernel(
|
||||
BLOCK_D: tl.constexpr,
|
||||
):
|
||||
"""One program per pool. softmax(slot_score+ape)-weighted sum of slot_k ->
|
||||
Hadamard-128 -> per-vector fp8 absmax quant -> write to cache at ``loc``."""
|
||||
Hadamard-128 -> per-vector fp8 absmax quant -> write to cache at ``loc``.
|
||||
"""
|
||||
row = tl.program_id(0)
|
||||
do_write = True
|
||||
if HAS_WRITE_MASK:
|
||||
@@ -276,6 +278,13 @@ def kpool_compress_and_write_cache(
|
||||
slot_score: ``[n_pools, pool_size, head_dim]`` — per-token gate score.
|
||||
ape: ``[pool_size, head_dim]`` fp32 — per-slot position bias.
|
||||
loc: ``[n_pools]`` int64 — flat physical slot per pool.
|
||||
pool_size: Number of tokens compressed into one cache entry.
|
||||
head_dim: Indexer head dimension.
|
||||
write_mask: ``[n_pools]`` bool — pools to write, or None for all.
|
||||
round_scale: Round each fp8 scale down to a power of two.
|
||||
return_compressed: Also return the compressed K and scales.
|
||||
write_cache: Write the compressed result into ``kv_cache``.
|
||||
|
||||
"""
|
||||
assert slot_k.ndim == 3
|
||||
assert slot_score.shape == slot_k.shape
|
||||
@@ -642,6 +651,10 @@ def kpool_decode_update_and_maybe_write_cache_batched(
|
||||
ape: ``[pool_size, head_dim]`` fp32.
|
||||
slot_mapping: ``[num_requests, next_n]`` int32.
|
||||
positions: ``[num_requests, next_n]`` int32.
|
||||
pool_size: Number of tokens compressed into one cache entry.
|
||||
head_dim: Indexer head dimension.
|
||||
round_scale: Round each fp8 scale down to a power of two.
|
||||
|
||||
"""
|
||||
num_requests, next_n = key.shape[0], key.shape[1]
|
||||
if num_requests == 0 or next_n == 0:
|
||||
|
||||
@@ -590,8 +590,7 @@ def fused_recurrent_gated_delta_rule(
|
||||
num_accepted_tokens: torch.Tensor | None = None,
|
||||
use_qk_l2norm_in_kernel: bool = False,
|
||||
) -> tuple[torch.Tensor, torch.Tensor]:
|
||||
r"""
|
||||
Args:
|
||||
r"""Args:
|
||||
q (torch.Tensor):
|
||||
queries of shape `[B, T, H, K]`.
|
||||
k (torch.Tensor):
|
||||
@@ -653,6 +652,7 @@ def fused_recurrent_gated_delta_rule(
|
||||
initial_state=h0,
|
||||
cu_seqlens=cu_seqlens
|
||||
)
|
||||
|
||||
"""
|
||||
if cu_seqlens is not None and q.shape[0] != 1:
|
||||
raise ValueError(
|
||||
|
||||
+17
-12
@@ -416,19 +416,24 @@ def chunk_kda_scaled_dot_kkt_fwd(
|
||||
chunk_size: int = FLA_CHUNK_SIZE,
|
||||
output_dtype: torch.dtype = torch.float32,
|
||||
) -> tuple[torch.Tensor, torch.Tensor]:
|
||||
r"""
|
||||
Compute beta * K * K^T.
|
||||
r"""Compute beta * K * K^T.
|
||||
|
||||
Args:
|
||||
q (torch.Tensor):
|
||||
The query tensor of shape `[B, T, H, K]`.
|
||||
k (torch.Tensor):
|
||||
The key tensor of shape `[B, T, H, K]`.
|
||||
beta (torch.Tensor):
|
||||
The beta tensor of shape `[B, T, H]`.
|
||||
gk (torch.Tensor):
|
||||
The cumulative sum of the gate tensor of shape `[B, T, H, K]` applied to the key tensor. Default: `None`.
|
||||
scale (float):
|
||||
Scale applied to the query-key products. Default: `None`.
|
||||
cu_seqlens (torch.Tensor):
|
||||
The cumulative sequence lengths of the input tensor.
|
||||
Default: None
|
||||
chunk_indices (torch.Tensor):
|
||||
Precomputed chunk indices for `cu_seqlens`. Default: `None`.
|
||||
chunk_size (int):
|
||||
The chunk size. Default: 64.
|
||||
output_dtype (torch.dtype):
|
||||
@@ -436,6 +441,7 @@ def chunk_kda_scaled_dot_kkt_fwd(
|
||||
|
||||
Returns:
|
||||
beta * K * K^T of shape `[B, T, H, BT]` where `BT` is the chunk size.
|
||||
|
||||
"""
|
||||
B, T, H, K = k.shape
|
||||
assert K <= 256
|
||||
@@ -1328,16 +1334,15 @@ def fused_kda_gate(
|
||||
safe_gate: bool = False,
|
||||
lower_bound: float | None = -5.0,
|
||||
) -> torch.Tensor:
|
||||
"""
|
||||
Forward pass for KDA gate:
|
||||
input g: [..., H*D]
|
||||
param A: [H] or [1, 1, H, 1]
|
||||
beta: softplus beta parameter (softplus branch only)
|
||||
threshold: softplus threshold parameter (softplus branch only)
|
||||
safe_gate: when False (default) compute y = -exp(A)*softplus(g+g_bias);
|
||||
when True compute the bounded y = lower_bound*sigmoid(exp(A)*(g+g_bias))
|
||||
lower_bound: floor for the safe_gate branch (default -5.0)
|
||||
return : [..., H, D]
|
||||
"""Forward pass for KDA gate:
|
||||
input g: [..., H*D]
|
||||
param A: [H] or [1, 1, H, 1]
|
||||
beta: softplus beta parameter (softplus branch only)
|
||||
threshold: softplus threshold parameter (softplus branch only)
|
||||
safe_gate: when False (default) compute y = -exp(A)*softplus(g+g_bias);
|
||||
when True compute the bounded y = lower_bound*sigmoid(exp(A)*(g+g_bias))
|
||||
lower_bound: floor for the safe_gate branch (default -5.0)
|
||||
return : [..., H, D]
|
||||
"""
|
||||
orig_shape = g.shape[:-1]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user