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:
Harry Mellor
2026-09-16 16:44:29 +00:00
committed by GitHub
co-authored by Claude Opus 5
parent 804e5377aa
commit 8c1557a79c
2002 changed files with 15024 additions and 14269 deletions
@@ -118,6 +118,7 @@ def dequant_nvfp4_kv_cache(
Returns:
[..., num_heads, block_size, head_size] float32.
"""
data_dim = head_size // 2
scale_dim = head_size // 16
@@ -304,7 +304,8 @@ def test_hipb_mm_kernel_forward_matches_raw_aiter_hipb_mm(enable_hipb_mm_kernel)
def test_hipb_mm_kernel_forward_accuracy(enable_hipb_mm_kernel):
"""Kernel output should match a dequantized fp32 reference within
fp8 per-token / per-channel quantization noise."""
fp8 per-token / per-channel quantization noise.
"""
weight_shape = (512, 4096) # (N, K)
num_tokens = 32
_check_bpreshuffle_runtime_support(weight_shape, num_tokens=num_tokens)
@@ -45,6 +45,7 @@ def quantize_weight_block_fp8(
Returns:
fp8_weight: [N, K] float8_e4m3fn
scales: [n_tiles, k_tiles] float32
"""
N, K = weight.shape
block_n, block_k = block_size
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""Tests for cutlass kernels
"""Tests for cutlass kernels.
Run `pytest tests/kernels/quantization/test_cutlass_scaled_mm.py`.
"""
@@ -300,8 +300,7 @@ def test_w4a8_cuda_graph():
)
@pytest.mark.parametrize("shape", MNK_SHAPES)
def test_convert_packed_uint4b8_to_signed_int4_inplace(shape):
"""
The W4A16 checkpoints encode the weights as int4b8 packed to int32.
"""The W4A16 checkpoints encode the weights as int4b8 packed to int32.
The CUTLASS kernels expect signed int4 packed to int32.
This tests checks that the runtime int4b8 -> signed int4 conversion
matches the offline conversion step exactly.
@@ -1,8 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""
Tests for the CUTLASS-based W4A8 grouped GEMM kernel and the full MoE layer.
"""
"""Tests for the CUTLASS-based W4A8 grouped GEMM kernel and the full MoE layer."""
import random
from dataclasses import dataclass
@@ -37,8 +35,7 @@ def cutlass_quantize(
group_size: int | None,
zero_points: bool = False,
):
"""
Quantize weights into W4 and compute reference dequantized weights.
"""Quantize weights into W4 and compute reference dequantized weights.
Encoding/reordering of weights and packing of scales is deferred
until after all experts are combined.
@@ -66,13 +63,13 @@ def cutlass_quantize(
def cutlass_preprocess(
w_q_experts: list[torch.Tensor], w_s_experts: list[torch.Tensor]
):
"""
Reorder/encode expert weights and pack scales.
"""Reorder/encode expert weights and pack scales.
Returns:
w_q_packed: Packed/encoded int4 weights for all experts.
w_s_packed: Packed fp8 scales for all experts.
packed_layout: Layout/stride metadata for grouped GEMM.
"""
w_s_packed = ops.cutlass_pack_scale_fp8(torch.stack(w_s_experts))
w_q_packed, packed_layout = ops.cutlass_encode_and_reorder_int4b_grouped(
@@ -130,7 +127,6 @@ def make_moe_test_setup(
random_zero: bool = False,
) -> MoETestSetup:
"""Create a full set of tensors for testing cutlass_w4a8_moe_mm."""
assert K % GROUP_SIZE == 0
# Token counts per expert (multiples of `alignment`).
Ms = [alignment * random.randint(1, max_blocks) for _ in range(num_experts)]
@@ -276,9 +272,7 @@ def test_cutlass_w4a8_moe_mm_end_to_end(shape, random_zero):
class W4A8MoELayer(torch.nn.Module):
"""
Minimal wrapper module to test cuda graphs
"""
"""Minimal wrapper module to test cuda graphs."""
def __init__(self, setup: MoETestSetup):
super().__init__()
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""
Unit tests for the get_fp8_min_max() helper function.
"""Unit tests for the get_fp8_min_max() helper function.
These tests verify the FP8 min/max value logic for both standard
and fnuz (ROCm MI300) dtype handling.
@@ -30,7 +30,8 @@ if current_platform.is_cuda_alike() and not current_platform.has_device_capabili
def native_w8a8_per_token_matmul(A, B, As, Bs, output_dtype=torch.float16):
"""Matrix multiplication function that supports per-token input
quantization and per-column weight quantization"""
quantization and per-column weight quantization
"""
A = A.to(torch.float32)
B = B.to(torch.float32)
@@ -53,8 +54,8 @@ def native_w8a8_per_token_matmul(A, B, As, Bs, output_dtype=torch.float16):
def torch_w8a8_per_column_moe(a, w1, w2, w1_s, w2_s, topk, topk_weight, topk_ids):
"""This function performs fused moe with per-column int8 quantization
using native torch."""
using native torch.
"""
B, D = a.shape
# Perform per-token quantization
a_q, a_s = per_token_quant_int8(a)
@@ -360,7 +360,8 @@ def test_gptq_marlin_padded_round_trip(shape, group_size):
def test_fp8_block_marlin_padded_round_trip(shape):
"""Block-quantized FP8 (e.g. Nemotron NVFP4 checkpoints' FP8 layers):
group_size=128 exercises the lcm K-alignment in marlin_padded_nk and the
weight_scale_inv group-wise scale padding."""
weight_scale_inv group-wise scale padding.
"""
size_n, size_k = shape
block = 128
dtype = torch.float16
@@ -410,7 +411,8 @@ def test_fp8_block_marlin_padded_round_trip(shape):
@pytest.mark.parametrize("shape", [(200, 288), (4640, 512)])
def test_mxfp8_marlin_padded_round_trip(shape):
"""MXFP8 exercises the e8m0 scale path, where padded 0.0 scales clamp to
2^-127 instead of zero and must still contribute nothing."""
2^-127 instead of zero and must still contribute nothing.
"""
size_n, size_k = shape
group_size = 32
# The e8m0-scale Marlin kernels are only instantiated for bf16 activations.
@@ -457,7 +459,8 @@ def test_mxfp8_marlin_padded_round_trip(shape):
@pytest.mark.parametrize("shape", [(200, 512), (4640, 512)])
def test_awq_zp_marlin_padded_round_trip(shape):
"""AWQ-style uint4 with runtime zero-points, padded the way
MarlinLinearKernel does: padded columns rely on (q=0 - zp=0) * scale=0."""
MarlinLinearKernel does: padded columns rely on (q=0 - zp=0) * scale=0.
"""
size_n, size_k = shape
group_size = 128
dtype = torch.float16
@@ -692,7 +695,8 @@ def test_check_moe_marlin_supports_layer_padding():
@pytest.mark.parametrize("shape", [(96, 256, 8), (160, 512, 4)])
def test_fp8_marlin_moe_padded_round_trip(shape, quant):
"""FP8 weight-only MoE: pad a tile-misaligned intermediate and check the
real prepare + fused_marlin_moe against the dequantized reference."""
real prepare + fused_marlin_moe against the dequantized reference.
"""
from tests.kernels.utils import torch_experts
from vllm.config import VllmConfig, set_current_vllm_config
from vllm.model_executor.layers.fused_moe import fused_topk
@@ -777,7 +781,8 @@ def test_fp8_marlin_moe_padded_round_trip(shape, quant):
@pytest.mark.parametrize("shape", [(96, 256, 8), (160, 512, 4)])
def test_mxfp8_marlin_moe_padded_round_trip(shape):
"""MXFP8 weight-only MoE round-trip at a tile-misaligned intermediate, with
unit e8m0 scales so the reference is the exact fp8 dequant."""
unit e8m0 scales so the reference is the exact fp8 dequant.
"""
from tests.kernels.utils import torch_experts
from vllm.config import VllmConfig, set_current_vllm_config
from vllm.model_executor.layers.fused_moe import fused_topk
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""Tests for MXFP4 linear kernel selection logic (CPU-only)
"""Tests for MXFP4 linear kernel selection logic (CPU-only).
Run `pytest tests/kernels/quantization/test_mxfp4_kernel_selection.py`.
"""
@@ -72,7 +72,8 @@ def test_true_w4a4_kernels_reject_unset_activation(kernel_cls):
@pytest.mark.parametrize("kernel_cls", _TRUE_W4A4_KERNELS)
def test_true_w4a4_kernels_reject_explicit_non_mxfp4_activation(kernel_cls):
"""FlashInfer/XPU/Aiter quantize activations to MXFP4 internally, so an
explicit request for a different activation format must be rejected."""
explicit request for a different activation format must be rejected.
"""
config = MxFp4LinearLayerConfig(activation_quant_key=kMxfp6E3M2Dynamic)
can_implement, reason = kernel_cls.can_implement(config)
assert not can_implement
@@ -87,7 +88,8 @@ def test_weight_only_kernels_accept_unquantized_or_mxfp4_activation(
"""Marlin/Humming never quantize activations, so an unset activation key,
or one that already describes MXFP4-shaped data, is tolerated. When an
activation key is explicitly set, a warning must be logged noting that it
is ignored, since these kernels are weight-only (A16)."""
is ignored, since these kernels are weight-only (A16).
"""
config = MxFp4LinearLayerConfig(activation_quant_key=activation_quant_key)
with patch(f"{kernel_cls.__module__}.logger.warning_once") as warning_once:
can_implement, reason = kernel_cls.can_implement(config)
@@ -116,7 +118,8 @@ def test_weight_only_kernels_reject_non_mxfp4_activation(kernel_cls):
)
def test_emulation_kernel_accepts_any_config(activation_quant_key, monkeypatch):
"""EmulationMxfp4LinearKernel is the universal fallback: it must accept
every supported activation format."""
every supported activation format.
"""
# `EmulationMxfp4LinearKernel.can_implement` gates on `has_quark()`,
# which we are not testing here.
monkeypatch.setattr(
@@ -134,7 +137,8 @@ def test_emulation_kernel_accepts_any_config(activation_quant_key, monkeypatch):
def test_emulation_kernel_derives_quant_dequant_func_from_config(monkeypatch):
"""quant_dequant_func must be derived purely from the config's activation
QuantKey, not set externally."""
QuantKey, not set externally.
"""
# `EmulationMxfp4LinearKernel.can_implement` gates on `has_quark()`,
# which we are not testing here.
monkeypatch.setattr(
@@ -158,7 +162,8 @@ def test_emulation_kernel_derives_quant_dequant_func_from_config(monkeypatch):
def test_aiter_kernel_is_supported_requires_native_mx_support():
"""AiterMxfp4LinearKernel must not be selected on platforms without
native MX compute, even if AITER itself is importable."""
native MX compute, even if AITER itself is importable.
"""
with patch(
"vllm.model_executor.kernels.linear.mxfp4.aiter.current_platform.supports_mx",
return_value=False,
@@ -194,7 +199,8 @@ class OOTMxFp4LinearKernel(MxFp4LinearKernel):
@patch("vllm.model_executor.kernels.linear.current_platform")
def test_init_mxfp4_linear_kernel_dispatches_to_registered_kernel(platform_mock):
"""init_mxfp4_linear_kernel should select a registered kernel that
reports itself as supported, and construct it with a fresh config."""
reports itself as supported, and construct it with a fresh config.
"""
platform_mock._enum = PlatformEnum.OOT
register_linear_kernel(OOTMxFp4LinearKernel, PlatformEnum.OOT, "mxfp4")
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""
Tests that triton_kernel_moe_forward correctly applies expert_map
"""Tests that triton_kernel_moe_forward correctly applies expert_map
remapping when expert parallelism (EP) is enabled.
When expert_map is provided, global expert IDs are remapped to local IDs
@@ -17,7 +16,8 @@ import torch
class TestTritonMoeForwardExpertMap:
"""Test that triton_kernel_moe_forward applies expert_map remapping
when expert_map is provided (EP active)."""
when expert_map is provided (EP active).
"""
def test_expert_map_remap(self):
device = "cuda" if torch.cuda.is_available() else "cpu"
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""Tests for MXFP6 linear kernel selection logic (CPU-only)
"""Tests for MXFP6 linear kernel selection logic (CPU-only).
Run `pytest tests/kernels/quantization/test_mxfp6_kernel_selection.py`.
"""
@@ -41,7 +41,8 @@ def test_can_implement_is_abstract():
def test_emulation_kernel_rejects_non_mxfp6_weights():
"""EmulationMxfp6LinearKernel must not implement a non-MXFP6 weight
format."""
format.
"""
config = MxFp6LinearLayerConfig(weight_quant_key=kMxfp4Static)
can_implement, reason = EmulationMxfp6LinearKernel.can_implement(config)
assert not can_implement
@@ -57,7 +58,8 @@ def test_emulation_kernel_accepts_any_supported_config(
weight_quant_key, activation_quant_key
):
"""EmulationMxfp6LinearKernel is the only backend today: it must accept
every supported weight/activation format combination."""
every supported weight/activation format combination.
"""
config = MxFp6LinearLayerConfig(
weight_quant_key=weight_quant_key, activation_quant_key=activation_quant_key
)
@@ -102,7 +104,8 @@ class OOTMxFp6LinearKernel(MxFp6LinearKernel):
def test_init_mxfp6_linear_kernel_dispatches_to_registered_kernel(platform_mock):
"""init_mxfp6_linear_kernel should select a registered kernel that
reports itself as supported/able to implement the given config, and
construct it with that exact config."""
construct it with that exact config.
"""
platform_mock._enum = PlatformEnum.OOT
register_linear_kernel(OOTMxFp6LinearKernel, PlatformEnum.OOT, "mxfp6")
@@ -64,8 +64,7 @@ def loaded_model_files():
class Nvfp4QuantizationEmulationTritonExpertsReference(TritonExperts):
"""
Extension of TritonExperts to support emulated NVFP4 MoE experts.
"""Extension of TritonExperts to support emulated NVFP4 MoE experts.
It may be used for NVFP4 models when the device does not have
native support for this dtype.
@@ -176,8 +176,7 @@ def test_python_util_matches_cpp_allocation(
shape: tuple[int, int],
is_sf_swizzled_layout: bool,
) -> None:
"""
Verify that the Python utility (create_fp4_output_tensors) allocates
"""Verify that the Python utility (create_fp4_output_tensors) allocates
tensors with the same shapes and dtypes as the C++ functional variant
(scaled_fp4_quant_func).
"""
@@ -118,8 +118,8 @@ def test_per_token_group_quant_fp8_packed(
num_tokens, hidden_dim, group_size, poisoned_scales
):
"""Test the packed DeepGEMM quantization kernel against the Triton
reference (row-major, UE8M0 scales)."""
reference (row-major, UE8M0 scales).
"""
device = "cuda"
torch.manual_seed(42)
@@ -206,7 +206,6 @@ def test_per_token_group_quant_fp8_packed_all_zero():
For all-zero input, eps/fp8_max < 1e-10, so the inner fmax clamps back to
1e-10, giving exp2(ceil(log2(1e-10))) = exp2(-33) => UE8M0 byte 0x5E (94).
"""
device = "cuda"
num_tokens, hidden_dim, group_size = 4, 7168, 128
x = torch.zeros((num_tokens, hidden_dim), device=device, dtype=torch.bfloat16)
@@ -258,8 +257,8 @@ def test_per_token_group_quant_fp8_packed_all_zero():
def test_per_token_group_quant_fp8_packed_mantissa_rounds_up():
"""Inputs whose absmax/max_8bit produces a non-power-of-2 force the
mantissa-rounding-up branch (exp_byte += 1). Locks down this behavior
before optimization."""
before optimization.
"""
device = "cuda"
num_tokens, hidden_dim, group_size = 4, 7168, 128
@@ -331,8 +330,8 @@ def test_per_token_group_quant_fp8_packed_zero_fills_padded_output_q(
):
"""When output_q is allocated with shape (tma_aligned_mn, k) instead of
(mn, k), the kernel must overwrite the padded mn rows with zeros so
callers can use ``torch.empty`` instead of ``torch.zeros``."""
callers can use ``torch.empty`` instead of ``torch.zeros``.
"""
device = "cuda"
group_size = 128
torch.manual_seed(42)
@@ -396,7 +395,6 @@ def test_per_token_group_quant_fp8_packed_large_mn():
This is a differential test that compares fp8 output against Triton output
reference when token size sits just above the gridDim.y 2^16 - 1 limit.
"""
device = "cuda"
group_size = 128
# hidden 2048 -> 2048/128 = 16 groups per row -> kx=16, ry=1: one grid row per mn
@@ -1,7 +1,8 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""Tests for the Triton dequant-gather kernel used by
``CompressedTensorsEmbeddingWNA16Int`` (quantized embedding lookup)."""
``CompressedTensorsEmbeddingWNA16Int`` (quantized embedding lookup).
"""
import pytest
import torch
@@ -29,7 +29,8 @@ pytestmark = pytest.mark.skipif(
def test_rocm_aiter_group_fp8_quant_fake_implementation():
"""Test that the fake implementation is correctly
defined for torch.ops.vllm.rocm_aiter_group_fp8_quant."""
defined for torch.ops.vllm.rocm_aiter_group_fp8_quant.
"""
# Create test tensors
M = 128
N = 4096
@@ -49,7 +50,8 @@ def test_rocm_aiter_group_fp8_quant_fake_implementation():
def test_rocm_aiter_group_fp8_quant_torch_compile_with_cudagraph():
"""Test that rocm_aiter_ops.group_fp8_quant
with group size 128 can be used with
torch.compile in cudagraph mode."""
torch.compile in cudagraph mode.
"""
# Create test tensors
M = 128
N = 4096
@@ -209,7 +209,8 @@ def test_rocm_aiter_fp4_enablement_follows_env_and_arch(
@pytest.mark.parametrize("shape", LLAMA_SHAPES)
def test_vllm_quant_dequant_mxfp4_matches_reference_on_large_shapes(shape, dtype):
"""The public vLLM MXFP4 QDQ helper should stay exact against the torch
reference even on larger Llama-like shapes."""
reference even on larger Llama-like shapes.
"""
from vllm.model_executor.layers.quantization.utils.mxfp4_utils import (
quant_dequant_mxfp4,
)
@@ -504,7 +505,7 @@ def test_aiter_fp4_gemm_a4w4_determinism():
],
)
def test_aiter_hardware_fp4_dynamic_quant_format(shape):
"""aiter hardware FP4 dynamic quant produces correct output format.
"""Aiter hardware FP4 dynamic quant produces correct output format.
Tests gfx950 hardware-accelerated FP4 quantization (OCP MXFP4 E2M1).
Parity with B200 scaled_fp4_quant: block_size=32, packed uint8 output.
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""Tests for ScaledMM kernel selection logic (CPU-only)
"""Tests for ScaledMM kernel selection logic (CPU-only).
Run `pytest tests/kernels/quantization/test_scaled_mm_kernel_selection.py`.
"""
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""Tests for the triton_scaled_mm kernel
"""Tests for the triton_scaled_mm kernel.
Run `pytest tests/kernels/quantization/test_triton_scaled_mm.py`.
"""