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
@@ -178,6 +178,7 @@ def pack_seq_triton(
|
||||
|
||||
Returns:
|
||||
packed: [B, Lmax, ...] — packed tensor.
|
||||
|
||||
"""
|
||||
is_uint8 = x.dtype == torch.uint8
|
||||
if is_uint8:
|
||||
@@ -334,8 +335,7 @@ def unpack_seq_triton(
|
||||
block_t: int = 64,
|
||||
block_d: int = 64,
|
||||
) -> torch.Tensor:
|
||||
"""
|
||||
Unpack a packed decode query tensor back to the original format.
|
||||
"""Unpack a packed decode query tensor back to the original format.
|
||||
Efficient Triton implementation.
|
||||
|
||||
Args:
|
||||
@@ -346,8 +346,8 @@ def unpack_seq_triton(
|
||||
|
||||
Returns:
|
||||
unpacked_tensor: [N, ...] where N = sum(lengths)
|
||||
"""
|
||||
|
||||
"""
|
||||
# Handle multi-dimensional input by reshaping to (B, Lmax, -1)
|
||||
original_shape = packed_tensor.shape
|
||||
if len(original_shape) > 3:
|
||||
|
||||
@@ -133,8 +133,7 @@ class CorrectAttnCPOutKernel(VllmTritonJitKernel["CorrectAttnCPOutKernel.Compile
|
||||
N_ROUNDED: tl.constexpr,
|
||||
IS_BASE_E: tl.constexpr,
|
||||
):
|
||||
"""
|
||||
Apply the all-gathered lses to correct each local rank's attention
|
||||
"""Apply the all-gathered lses to correct each local rank's attention
|
||||
output. we still need perform a cross-rank reduction to obtain the
|
||||
final attention output.
|
||||
|
||||
@@ -147,6 +146,17 @@ class CorrectAttnCPOutKernel(VllmTritonJitKernel["CorrectAttnCPOutKernel.Compile
|
||||
Pointer to output tensor of shape [ B, H, D ]
|
||||
vlse_ptr (triton.PointerType):
|
||||
Pointer to output tensor of shape [ B, H ]
|
||||
outputs_stride_B (int): Batch stride of ``outputs_ptr``
|
||||
outputs_stride_H (int): Head stride of ``outputs_ptr``
|
||||
outputs_stride_D (int): Head-dim stride of ``outputs_ptr``
|
||||
lses_stride_N (int): Rank stride of ``lses_ptr``
|
||||
lses_stride_B (int): Batch stride of ``lses_ptr``
|
||||
lses_stride_H (int): Head stride of ``lses_ptr``
|
||||
lse_idx (int): Index of this rank's lse within the all-gathered tensor
|
||||
HEAD_DIM: Head dimension, as a constexpr
|
||||
N_ROUNDED: Rank count rounded to a power of two, as a constexpr
|
||||
IS_BASE_E: Whether the lses are natural-log based, as a constexpr
|
||||
|
||||
"""
|
||||
batch_idx = tl.program_id(axis=0).to(tl.int64)
|
||||
head_idx = tl.program_id(axis=1).to(tl.int64)
|
||||
@@ -376,9 +386,11 @@ def correct_attn_out(
|
||||
lses: Tensor of shape [ N, B, H ]
|
||||
cp_rank: Current rank in the context-parallel group
|
||||
ctx: Triton context to avoid recompilation
|
||||
is_lse_base_on_e: Whether the lses use base e rather than base 2
|
||||
|
||||
Returns:
|
||||
Tuple of (out, lse) with corrected attention and final log-sum-exp.
|
||||
|
||||
"""
|
||||
if ctx is None:
|
||||
ctx = CPTritonContext()
|
||||
@@ -431,8 +443,7 @@ def _cp_lse_common(
|
||||
seq_lens: torch.Tensor | None = None,
|
||||
query_start_loc: torch.Tensor | None = None,
|
||||
):
|
||||
"""
|
||||
cp_attn_out: [ B, H, D ]
|
||||
"""cp_attn_out: [ B, H, D ]
|
||||
cp_attn_lse: [ B, H ]
|
||||
"""
|
||||
if cp_group.world_size == 1:
|
||||
@@ -466,8 +477,7 @@ def cp_lse_ag_out_rs(
|
||||
seq_lens: torch.Tensor | None = None,
|
||||
query_start_loc: torch.Tensor | None = None,
|
||||
):
|
||||
"""
|
||||
cp_attn_out: [ B, H, D ]
|
||||
"""cp_attn_out: [ B, H, D ]
|
||||
cp_attn_lse: [ B, H ]
|
||||
"""
|
||||
out, lse = _cp_lse_common(
|
||||
@@ -499,8 +509,7 @@ def cp_lse_ag_out_ar(
|
||||
seq_lens: torch.Tensor | None = None,
|
||||
query_start_loc: torch.Tensor | None = None,
|
||||
):
|
||||
"""
|
||||
cp_attn_out: [ B, H, D ]
|
||||
"""cp_attn_out: [ B, H, D ]
|
||||
cp_attn_lse: [ B, H ]
|
||||
"""
|
||||
out, lse = _cp_lse_common(
|
||||
@@ -528,8 +537,7 @@ def _lse_weighted_combine(
|
||||
return_lse: bool = False,
|
||||
is_lse_base_on_e: bool = True,
|
||||
) -> torch.Tensor | tuple[torch.Tensor, torch.Tensor]:
|
||||
"""
|
||||
CPU reference implementation for LSE-weighted combination.
|
||||
"""CPU reference implementation for LSE-weighted combination.
|
||||
|
||||
This is a pure PyTorch implementation used for testing and validation.
|
||||
|
||||
@@ -545,6 +553,7 @@ def _lse_weighted_combine(
|
||||
|
||||
Returns:
|
||||
Combined output [B, H, D], and optionally global LSE [B, H]
|
||||
|
||||
"""
|
||||
N, B, H, D = outputs.shape
|
||||
|
||||
@@ -936,8 +945,7 @@ def dcp_a2a_lse_reduce(
|
||||
seq_lens: torch.Tensor | None = None,
|
||||
query_start_loc: torch.Tensor | None = None,
|
||||
) -> torch.Tensor | tuple[torch.Tensor, torch.Tensor]:
|
||||
"""
|
||||
Combine partial attention outputs across DCP ranks using All-to-All.
|
||||
"""Combine partial attention outputs across DCP ranks using All-to-All.
|
||||
|
||||
The output and LSE are packed into a single output-dtype buffer, sent
|
||||
with one All-to-All, then unpacked and combined with exact LSE weighting.
|
||||
@@ -955,6 +963,7 @@ def dcp_a2a_lse_reduce(
|
||||
Returns:
|
||||
Combined output [B, H/N, D] (head-scattered)
|
||||
If return_lse=True, also returns global_lse [B, H/N]
|
||||
|
||||
"""
|
||||
world_size = cp_group.world_size
|
||||
|
||||
|
||||
@@ -49,9 +49,7 @@ def _is_flashmla_available() -> tuple[bool, str | None]:
|
||||
|
||||
|
||||
def is_flashmla_dense_supported() -> tuple[bool, str | None]:
|
||||
"""
|
||||
Return: is_supported_flag, unsupported_reason (optional).
|
||||
"""
|
||||
"""Return: is_supported_flag, unsupported_reason (optional)."""
|
||||
is_available, maybe_reason = _is_flashmla_available()
|
||||
if not is_available:
|
||||
return False, maybe_reason
|
||||
@@ -61,9 +59,7 @@ def is_flashmla_dense_supported() -> tuple[bool, str | None]:
|
||||
|
||||
|
||||
def is_flashmla_sparse_supported() -> tuple[bool, str | None]:
|
||||
"""
|
||||
Return: is_supported_flag, unsupported_reason (optional).
|
||||
"""
|
||||
"""Return: is_supported_flag, unsupported_reason (optional)."""
|
||||
is_available, maybe_reason = _is_flashmla_available()
|
||||
if not is_available:
|
||||
return False, maybe_reason
|
||||
|
||||
@@ -106,8 +106,8 @@ def merge_attn_states(
|
||||
are treated as having context.
|
||||
output_scale: Optional scalar tensor for FP8 static quantization.
|
||||
When provided, output must be FP8 dtype.
|
||||
"""
|
||||
|
||||
"""
|
||||
# Both the CUDA and Triton kernels derive the suffix head stride from
|
||||
# prefix_output, so suffix_output must share the same head stride.
|
||||
assert prefix_output.stride(1) == suffix_output.stride(1), (
|
||||
|
||||
@@ -654,6 +654,7 @@ def rocm_fp8_paged_mqa_logits(
|
||||
Returns:
|
||||
Logits tensor of shape [B * next_n, max_model_len], dtype
|
||||
`torch.float32`.
|
||||
|
||||
"""
|
||||
from vllm._aiter_ops import rocm_aiter_ops
|
||||
|
||||
@@ -737,6 +738,7 @@ def fp8_mqa_logits_torch(
|
||||
|
||||
Returns:
|
||||
Logits tensor of shape [M, N], dtype `torch.float32`.
|
||||
|
||||
"""
|
||||
k_fp8, scale = kv
|
||||
seq_len_kv = k_fp8.shape[0]
|
||||
@@ -805,8 +807,8 @@ def rocm_fp8_mqa_logits(
|
||||
|
||||
Returns:
|
||||
Logits tensor of shape [M, N], dtype `torch.float32`.
|
||||
"""
|
||||
|
||||
"""
|
||||
from vllm._aiter_ops import rocm_aiter_ops
|
||||
|
||||
k_fp8, scale = kv
|
||||
|
||||
@@ -24,8 +24,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""
|
||||
Memory-efficient attention for decoding.
|
||||
"""Memory-efficient attention for decoding.
|
||||
It supports page size >= 1.
|
||||
"""
|
||||
|
||||
|
||||
@@ -19,8 +19,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ==============================================================================
|
||||
"""
|
||||
Memory-efficient attention for prefill.
|
||||
"""Memory-efficient attention for prefill.
|
||||
It supports page size = 1.
|
||||
"""
|
||||
|
||||
@@ -229,8 +228,7 @@ def context_attention_fwd(
|
||||
sinks: torch.Tensor | None = None,
|
||||
sinks_bias_key0: bool = False,
|
||||
):
|
||||
"""
|
||||
q, k, v: [b * s, head, head_dim]
|
||||
"""q, k, v: [b * s, head, head_dim]
|
||||
b_start_loc: [b]
|
||||
b_seq_len: [b]
|
||||
out: [b * s, head, head_dim]
|
||||
|
||||
@@ -45,7 +45,8 @@ def _store_quantized_value(
|
||||
BLOCK_GRP: tl.constexpr,
|
||||
):
|
||||
"""Uniform quantization of values to VQB bits, pack, and store with
|
||||
scale/zero in the per-block SoA metadata region (Opt#3 layout)."""
|
||||
scale/zero in the per-block SoA metadata region (Opt#3 layout).
|
||||
"""
|
||||
if VQB == 3:
|
||||
val_vec = tl.load(Value_ptr + base + d_offs, mask=d_mask, other=0.0).to(
|
||||
tl.float32
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
"""
|
||||
This file contains ops for ViT attention to be compatible with torch.compile
|
||||
"""This file contains ops for ViT attention to be compatible with torch.compile
|
||||
as there are operations here not supported by torch.compile (for instance,
|
||||
`.item()` in flash attention)
|
||||
|
||||
@@ -238,8 +237,7 @@ def apply_sdpa(
|
||||
scale: float | None = None,
|
||||
enable_gqa: bool = False,
|
||||
) -> torch.Tensor:
|
||||
"""
|
||||
Input shape:
|
||||
"""Input shape:
|
||||
(batch_size x seq_len x num_heads x head_size)
|
||||
"""
|
||||
q, k, v = (einops.rearrange(x, "b s h d -> b h s d") for x in [q, k, v])
|
||||
|
||||
@@ -185,15 +185,20 @@ def triton_bf16_mla_sparse_interface(
|
||||
d_v: int = 512,
|
||||
block_dpe: int = 64,
|
||||
) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
|
||||
"""
|
||||
out : [num_tokens, num_heads_q, d_v]
|
||||
"""Out : [num_tokens, num_heads_q, d_v]
|
||||
max_logits : [num_tokens, num_heads_q]
|
||||
lse : logsumexp, [num_tokens, num_heads_q]
|
||||
|
||||
Args:
|
||||
q: Query tensor, [num_tokens, num_heads_q, dim_qk].
|
||||
kv: Latent KV cache tensor.
|
||||
indices: Sparse KV indices selected for each query token.
|
||||
sm_scale: Softmax scale applied to the QK product.
|
||||
d_v: Size of the value dimension.
|
||||
block_dpe: Size of positional embedding portion of dim_qk.
|
||||
Set to 0 when q/kv contain only the nope latent (e.g. DSv4
|
||||
prefill where RoPE is not split out).
|
||||
|
||||
"""
|
||||
num_tokens, num_heads_q, dim_qk = q.shape
|
||||
_, num_heads_kv, _ = kv.shape
|
||||
|
||||
Reference in New Issue
Block a user