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
@@ -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