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
@@ -61,9 +61,7 @@ class ROCmLatentMoERunner(MoERunner):
|
||||
shared_output: torch.Tensor,
|
||||
trunc_size: int | None,
|
||||
) -> torch.Tensor:
|
||||
"""
|
||||
Tier 2: column-parallel up-projection folded into the final reduce.
|
||||
"""
|
||||
"""Tier 2: column-parallel up-projection folded into the final reduce."""
|
||||
if not self._logged_sharded_tail:
|
||||
self._logged_sharded_tail = True
|
||||
logger.info_once(
|
||||
|
||||
@@ -317,9 +317,7 @@ class KimiMoE(nn.Module):
|
||||
|
||||
|
||||
class KimiMLAAttention(nn.Module):
|
||||
"""
|
||||
Main reference: DeepseekV2 vllm Implementation
|
||||
"""
|
||||
"""Main reference: DeepseekV2 vllm Implementation."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
|
||||
@@ -213,9 +213,17 @@ def fused_kda_chunk(
|
||||
|
||||
Args:
|
||||
qg: ``q * exp2(gk_cumsum)``, ``[1, T, H, 128]``.
|
||||
w: chunk-local WY representation of the gated keys.
|
||||
u: chunk-local WY representation of the values.
|
||||
kg_t: chunk-major transposed gated keys, ``[chunks, H, 128, 64]``.
|
||||
aqk: intra-chunk query-key attention, ``[chunks, H, 64, 64]``.
|
||||
decay: ``exp2`` of each chunk's last gate row, ``[chunks, H, 128]``.
|
||||
out: output buffer, ``[1, T, H, 128]``; may alias ``u``'s source.
|
||||
scale: scale applied to the query-key products.
|
||||
cu_seqlens: int32 cumulative sequence lengths.
|
||||
initial_state: fp32 per-sequence initial recurrent state, or ``None``.
|
||||
output_final_state: whether to return the final recurrent state.
|
||||
chunk_offsets: int32 per-sequence first chunk index.
|
||||
checkpoint_state: destination for the mid-prefill state snapshots,
|
||||
fp32 ``[rows, H, 128, 128]``. Without
|
||||
``checkpoint_state_indices`` it is a staging buffer indexed by
|
||||
@@ -239,6 +247,7 @@ def fused_kda_chunk(
|
||||
has_initial_state: bool ``[N]``; a false entry starts that sequence
|
||||
from a zero state and its cache row is read only, never before the
|
||||
walk writes it.
|
||||
|
||||
"""
|
||||
if state_cache is not None:
|
||||
if initial_state is not None or output_final_state:
|
||||
|
||||
@@ -52,6 +52,22 @@ def chunk_kda_prefill(
|
||||
"""Run chunk KDA from raw gate and beta projections.
|
||||
|
||||
Args:
|
||||
q: query tensor, ``[1, T, H, K]``.
|
||||
k: key tensor, ``[1, T, H, K]``.
|
||||
v: value tensor, ``[1, T, H, V]``.
|
||||
raw_g: raw gate projection, before the activation.
|
||||
raw_beta: raw beta projection, before the activation.
|
||||
A_log: log of the per-head gate decay.
|
||||
g_bias: optional per-head gate bias.
|
||||
scale: scale applied to the query-key products. Defaults to
|
||||
``k.shape[-1] ** -0.5``.
|
||||
initial_state: fp32 per-sequence initial recurrent state, or ``None``.
|
||||
output_final_state: whether to return the final recurrent state.
|
||||
lower_bound: optional floor applied to the gate.
|
||||
use_qk_l2norm_in_kernel: fold the q/k L2 norm into the kernel.
|
||||
cu_seqlens: int32 cumulative sequence lengths.
|
||||
chunk_indices: precomputed chunk indices for ``cu_seqlens``.
|
||||
chunk_offsets: int32 per-sequence first chunk index.
|
||||
use_fused_chunk: request the two-kernel ROCm path. It is used only when
|
||||
every one of its preconditions holds; otherwise the Triton path
|
||||
runs unchanged.
|
||||
@@ -71,6 +87,7 @@ def chunk_kda_prefill(
|
||||
|
||||
Returns:
|
||||
The output and, when requested, the final recurrent state.
|
||||
|
||||
"""
|
||||
if scale is None:
|
||||
scale = k.shape[-1] ** -0.5
|
||||
|
||||
+6
-7
@@ -910,13 +910,12 @@ def fused_kda_gate(
|
||||
threshold: float = 20.0,
|
||||
lower_bound: float | None = None,
|
||||
) -> torch.Tensor:
|
||||
"""
|
||||
Forward pass for KDA gate:
|
||||
input g: [..., H*D]
|
||||
param A: [H] or [1, 1, H, 1]
|
||||
beta: softplus beta parameter
|
||||
threshold: softplus threshold parameter
|
||||
return : [..., H, D]
|
||||
"""Forward pass for KDA gate:
|
||||
input g: [..., H*D]
|
||||
param A: [H] or [1, 1, H, 1]
|
||||
beta: softplus beta parameter
|
||||
threshold: softplus threshold parameter
|
||||
return : [..., H, D]
|
||||
"""
|
||||
orig_shape = g.shape[:-1]
|
||||
|
||||
|
||||
@@ -59,8 +59,7 @@ def chunk_kda_fwd_kernel_inter_solve_fused(
|
||||
USE_SAFE_GATE: tl.constexpr,
|
||||
SOLVE_TRIL_DOT_PRECISION: tl.constexpr,
|
||||
):
|
||||
"""
|
||||
Fused kernel: compute inter-subchunk Akk + solve_tril in one pass.
|
||||
"""Fused kernel: compute inter-subchunk Akk + solve_tril in one pass.
|
||||
Prerequisite: token_parallel has already computed diagonal Akk blocks in Akkd.
|
||||
|
||||
This kernel:
|
||||
|
||||
@@ -151,8 +151,7 @@ def chunk_kda_fwd_intra_token_parallel(
|
||||
chunk_size: int = 64,
|
||||
sub_chunk_size: int = 16,
|
||||
) -> None:
|
||||
"""
|
||||
Token-parallel implementation: each token gets its own thread block.
|
||||
"""Token-parallel implementation: each token gets its own thread block.
|
||||
Supports both fixed-length and variable-length sequences.
|
||||
Reduces wasted computation on padding.
|
||||
|
||||
@@ -164,10 +163,12 @@ def chunk_kda_fwd_intra_token_parallel(
|
||||
gk: [B, T, HV, K] cumsum of gates (HV >= H for GVA)
|
||||
beta: [B, T, HV]
|
||||
Aqk: [B, T, HV, BT] output tensor to write to
|
||||
cu_seqlens: cumulative sequence lengths for variable-length input
|
||||
Akk: [B, T, HV, BC] output tensor for diagonal blocks (fp32)
|
||||
scale: attention scale
|
||||
chunk_size: BT (default 64)
|
||||
sub_chunk_size: BC (default 16)
|
||||
|
||||
"""
|
||||
B, T, H, K, HV = *q.shape, gk.shape[2]
|
||||
N = len(cu_seqlens) - 1 if cu_seqlens is not None else B
|
||||
|
||||
Reference in New Issue
Block a user