[CI] Ignore ruff D209, rejoin the docstrings it split, and silence incompatible-rule warnings (#57212)

Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Harry Mellor
2026-09-16 10:57:24 -07:00
committed by GitHub
co-authored by Claude Opus 5
parent 1085b64425
commit 651a88c09a
693 changed files with 2088 additions and 4171 deletions
@@ -46,24 +46,21 @@ class QuantizeMethodBase(ABC):
):
"""Create weights for a layer.
The weights will be set as attributes of the layer.
"""
The weights will be set as attributes of the layer."""
raise NotImplementedError
@abstractmethod
def apply(self, layer: torch.nn.Module, *args, **kwargs) -> torch.Tensor:
"""Apply the weights in layer to the input tensor.
Expects create_weights to have been called before on the layer.
"""
Expects create_weights to have been called before on the layer."""
raise NotImplementedError
# Not required functions
def embedding(self, layer: torch.nn.Module, *args, **kwargs) -> torch.Tensor:
"""Gather embeddings in the layer based on indices in the input tensor.
Expects create_weights to have been called before on the layer.
"""
Expects create_weights to have been called before on the layer."""
raise NotImplementedError
# Not required functions
@@ -76,8 +73,7 @@ class QuantizeMethodBase(ABC):
Quantization methods that need special weight handling (e.g. repacked
weights) override this.
Expects create_weights to have been called before on the layer.
"""
Expects create_weights to have been called before on the layer."""
layer.weight = embed_tokens.weight
return layer
@@ -665,8 +665,7 @@ class CompressedTensorsConfig(QuantizationConfig):
) -> bool:
"""Weight N-bit INT (pack-quantized for sub-byte, int-quantized for 8-bit)
with static per-tensor INT8 input/output activation quant, applied as a float
fake-quant around a weight-only matmul.
"""
fake-quant around a weight-only matmul."""
is_int_pack_format = format in (
CompressionFormat.pack_quantized.value,
CompressionFormat.int_quantized.value,
@@ -702,8 +701,7 @@ class CompressedTensorsConfig(QuantizationConfig):
format: str | None,
) -> bool:
"""Weight N-bit INT with symmetric dynamic INT activation quant
via Humming kernel.
"""
via Humming kernel."""
if input_quant is None:
return False
is_pack_format = format == CompressionFormat.pack_quantized.value
@@ -37,8 +37,7 @@ def _dequant_gather_kernel(
BLOCK: tl.constexpr,
):
"""Gather embedding rows by token id, unpack int32-packed INT weights, and
dequantize to ``out`` dtype in one pass (no int8 intermediate).
"""
dequantize to ``out`` dtype in one pass (no int8 intermediate)."""
row = tl.program_id(0)
col = tl.program_id(1) * BLOCK + tl.arange(0, BLOCK)
col_mask = col < hidden
@@ -211,8 +211,7 @@ class CompressedTensorsWNA8O8Int(CompressedTensorsScheme):
def _pack_int_quantized_weight(self, layer: torch.nn.Module) -> None:
"""Normalize an int-quantized (plain int8) weight to the canonical
``weight_packed`` int32 + ``weight_shape`` layout the MP kernels expect.
"""
``weight_packed`` int32 + ``weight_shape`` layout the MP kernels expect."""
weight = layer.weight
out_features, in_features = weight.shape
packed = pack_to_int32(weight.data.contiguous(), self.num_bits)
@@ -86,8 +86,7 @@ class INCConfigParser:
def is_explicitly_configured(name: str) -> bool:
"""Return True if *name* has an explicit entry in extra_config,
either via exact key match or via a regex pattern key.
"""
either via exact key match or via a regex pattern key."""
if not self._config.extra_config:
return False
if name in self._config.extra_config:
@@ -48,8 +48,7 @@ class INCScheme(ABC):
layer_config: "INCLayerConfig",
) -> "FusedMoEMethodBase | None":
"""Optional. Override if this scheme supports MoE.
Default raises NotImplementedError.
"""
Default raises NotImplementedError."""
raise NotImplementedError(
f"{type(self).__name__} does not support MoE layers. "
f"Layer config: {layer_config}"
@@ -1988,8 +1988,7 @@ class KNvfp4Static(QuantKeyScheme):
class KNvfp4Dynamic(QuantKeyScheme):
"""NVFP4 activation scheme (W4A4). Has a static global input scale on disk;
the per-group scale is computed at runtime inside the kernel.
"""
the per-group scale is computed at runtime inside the kernel."""
key = kNvfp4Dynamic
@@ -2026,8 +2025,7 @@ class KNvfp4Dynamic(QuantKeyScheme):
class KFp8StaticTensor(QuantKeyScheme):
"""Plain per-tensor static FP8 — bivalent: serves BOTH the weight slot and
the activation slot (W8A8). One key in both QuantSpec slots.
"""
the activation slot (W8A8). One key in both QuantSpec slots."""
key = kFp8StaticTensorSym
@@ -2097,8 +2095,7 @@ class KFp8StaticTensor(QuantKeyScheme):
class KFp8StaticChannel(QuantKeyScheme):
"""Per-channel static FP8 weight (the 'PcPt' weight). Weight-role only —
there is no static per-channel *activation* today.
"""
there is no static per-channel *activation* today."""
key = kFp8StaticTokenSym
@@ -2139,8 +2136,7 @@ class KFp8StaticChannel(QuantKeyScheme):
class KFp8Block128(QuantKeyScheme):
"""128x128 block-static FP8 weight ('PbWo'). Weight-role only. ModelOpt
exports the scale 4-D [out_blk,1,in_blk,1]; process squeezes to 2-D.
No transpose (block kernel keeps [out,in]).
"""
No transpose (block kernel keeps [out,in])."""
key = kFp8Static128BlockSym
@@ -2196,8 +2192,7 @@ class KFp8Block128(QuantKeyScheme):
class KMxfp8Static(QuantKeyScheme):
"""MXFP8 weight: fp8-e4m3 values + per-32-block e8m0 (uint8) scale.
Weight-role only. process is validate-only plus an idempotency guard.
"""
Weight-role only. process is validate-only plus an idempotency guard."""
key = kMxfp8Static
@@ -2272,8 +2267,7 @@ class KDynamicNoParam(QuantKeyScheme):
"""Dynamic activation with no stored scale (W8A8): quantized at runtime in
the kernel. NOT the same as activation=None (weight-only) — init_fp8 needs a
non-None activation key. Activation-role only. Serves the fp8 per-token, fp8
per-block, and mxfp8 dynamic activation keys.
"""
per-block, and mxfp8 dynamic activation keys."""
def create_weights(self, layer, role, ctx, shapes, wl) -> None:
if role is not ACT:
@@ -79,8 +79,7 @@ class Mxfp4Config(QuantizationConfig):
def _make_moe_method(self, moe: FusedMoEConfig) -> FusedMoEMethodBase:
"""MoE method for RoutedExperts. Subclasses override to pick a
checkpoint-specific kernel family.
"""
checkpoint-specific kernel family."""
return Mxfp4MoEMethod(moe)
def get_quant_method(
@@ -139,8 +139,7 @@ def _find_matching_targets(
class OnlineQuantizationConfig(QuantizationConfig):
"""Model-level config for online quantization (quantize fp16/bf16 weights
during model loading, without requiring a pre-quantized checkpoint).
"""
during model loading, without requiring a pre-quantized checkpoint)."""
def __init__(
self,
@@ -118,8 +118,7 @@ def _is_tp_sharded(layer: Module, *, reduces_output_dim: bool = True) -> bool:
class OnlineLinearBase(LinearMethodBase):
"""Shared base for online FP8 linear methods. Loads fp16/bf16 checkpoint
weights onto meta device and materializes them just-in-time.
"""
weights onto meta device and materializes them just-in-time."""
uses_meta_device: bool = True
@@ -163,8 +162,7 @@ class OnlineLinearBase(LinearMethodBase):
class Fp8PerTensorOnlineLinearMethod(OnlineLinearBase):
"""Online tensorwise FP8 linear quantization.
Loads fp16/bf16 weights and quantizes them per-tensor during loading.
"""
Loads fp16/bf16 weights and quantizes them per-tensor during loading."""
def __init__(self):
super().__init__()
@@ -265,8 +263,7 @@ class Fp8PerTensorOnlineLinearMethod(OnlineLinearBase):
class Fp8PerBlockOnlineLinearMethod(OnlineLinearBase):
"""Online blockwise FP8 linear quantization.
Loads fp16/bf16 weights and quantizes them per-block during loading.
"""
Loads fp16/bf16 weights and quantizes them per-block during loading."""
def __init__(self):
super().__init__()
@@ -440,8 +437,7 @@ class Fp8PtpcOnlineLinearMethod(OnlineLinearBase):
class _Fp8OnlineMoEBase(OnlineMoEMethodBase):
"""Shared base for online FP8 MoE methods. Loads fp16/bf16 checkpoint
weights onto meta device and materializes them just-in-time.
"""
weights onto meta device and materializes them just-in-time."""
# Declared here for mypy; actual values are set in __init__.
fp8_backend: "Fp8MoeBackend"
@@ -562,8 +558,7 @@ class _Fp8OnlineMoEBase(OnlineMoEMethodBase):
class Fp8PerTensorOnlineMoEMethod(_Fp8OnlineMoEBase):
"""Online tensorwise FP8 MoE quantization.
Loads fp16/bf16 weights and quantizes them per-tensor during loading.
"""
Loads fp16/bf16 weights and quantizes them per-tensor during loading."""
def __init__(
self,
@@ -620,8 +615,7 @@ class Fp8PerTensorOnlineMoEMethod(_Fp8OnlineMoEBase):
class Fp8PerBlockOnlineMoEMethod(_Fp8OnlineMoEBase):
"""Online blockwise FP8 MoE quantization.
Loads fp16/bf16 weights and quantizes them per-block during loading.
"""
Loads fp16/bf16 weights and quantizes them per-block during loading."""
def __init__(
self,
@@ -69,8 +69,7 @@ def input_to_float8(
x: torch.Tensor, dtype: torch.dtype | None = None
) -> tuple[torch.Tensor, torch.Tensor]:
"""This function quantizes input values to float8 values "
"with tensor-wise quantization.
"""
"with tensor-wise quantization."""
dtype = current_platform.fp8_dtype() if dtype is None else dtype
finfo = torch.finfo(dtype)
min_val, max_val = x.aminmax()
@@ -1195,8 +1194,7 @@ def prepare_fp8_moe_layer_for_deepgemm(
def _maybe_pad_fp8_weight(weight: torch.Tensor) -> torch.Tensor:
"""Pad the weight tensor. This is an optimization on ROCm platform, which
can benefit from tensors located far enough from one another in memory
"""
can benefit from tensors located far enough from one another in memory"""
if (
envs.VLLM_ROCM_FP8_PADDING
and current_platform.is_rocm()
@@ -297,8 +297,7 @@ def _humming_input_schema_to_quant_key(
schema: "HummingInputSchema",
) -> QuantKey | None:
"""Convert a HummingInputSchema to a QuantKey. Returns None if
the schema represents unquantized (bf16/fp16) inputs.
"""
the schema represents unquantized (bf16/fp16) inputs."""
if schema.a_dtype is None or schema.a_dtype.num_bits >= 16:
return None
@@ -427,8 +426,7 @@ def convert_linear_layer_to_humming_standard(
):
"""Rename/reshape a linear layer's quantized params (the canonical MPLinear
layout: ``weight_packed`` int32 + ``weight_scale``) into the parameter names
and layout humming's weight schema expects (``weight`` / ``weight_scale``).
"""
and layout humming's weight schema expects (``weight`` / ``weight_scale``)."""
for name, checkpoint_name in name_map.items():
tensor = getattr(layer, checkpoint_name)
delattr(layer, checkpoint_name)
@@ -245,8 +245,7 @@ def marlin_padded_nk(size_n: int, size_k: int, group_size: int = -1) -> tuple[in
def marlin_repacked_nk(qweight: torch.Tensor, num_bits: int) -> tuple[int, int]:
"""Recover the (size_n, size_k) a Marlin weight was repacked with
(including any tile padding) from its packed shape.
"""
(including any tile padding) from its packed shape."""
pack_factor = 32 // num_bits
size_k = qweight.size(0) * GPTQ_MARLIN_TILE
size_n = qweight.size(1) * pack_factor // GPTQ_MARLIN_TILE
@@ -257,8 +256,7 @@ def marlin_pad_qweight(
qweight: torch.Tensor, size_n: int, size_k: int, padded_n: int, padded_k: int
) -> torch.Tensor:
"""Zero-pad a GPTQ-layout packed weight (size_k / pack, size_n) for
gptq_marlin_repack.
"""
gptq_marlin_repack."""
if (padded_n, padded_k) == (size_n, size_k):
return qweight
pack_factor = size_k // qweight.size(0)
@@ -276,8 +274,7 @@ def marlin_pad_scales(
group_size: int,
) -> torch.Tensor:
"""Zero-pad weight scales (num_groups, size_n); call before
marlin_permute_scales and pass the padded extents to it.
"""
marlin_permute_scales and pass the padded extents to it."""
if (padded_n, padded_k) == (size_n, size_k):
return scales
pad_rows = padded_k // group_size - scales.size(0) if group_size > 0 else 0
@@ -41,8 +41,7 @@ def _nvfp4_compute_scale_factor(
) -> float:
"""Compute the power-of-2 scale_factor needed so that all non-zero
values in marlin_scales * 2^7 are >= 2 after rescaling.
Returns a Python float (power of 2, >= 1.0).
"""
Returns a Python float (power of 2, >= 1.0)."""
# Since half has a smaller dynamic range compared to bfloat16,
# no rescaling is applied here if active dtype is half.
if a_dtype is not None and a_dtype == torch.half:
@@ -376,8 +375,7 @@ def prepare_nvfp4_moe_layer_for_marlin(
def pad_w13(x: torch.Tensor) -> torch.Tensor:
"""Zero-pad each gate/up shard of a (E, num_shards * N, cols)
tensor to padded_N rows.
"""
tensor to padded_N rows."""
if padded_N == N:
return x
x = x.view(E, num_shards, N, x.size(-1))
@@ -386,8 +384,7 @@ def prepare_nvfp4_moe_layer_for_marlin(
def pad_w2(x: torch.Tensor, packing: int) -> torch.Tensor:
"""Zero-pad the packed N (last) dim of a (E, K, N / packing)
tensor.
"""
tensor."""
if padded_N == N:
return x
return torch.nn.functional.pad(x, (0, (padded_N - N) // packing))
@@ -217,8 +217,7 @@ def prepare_fp8_layer_for_marlin(
def _moe_pad_shard_rows(x: torch.Tensor, n: int, padded_n: int) -> torch.Tensor:
"""Zero-pad each gate/up shard of a ``(E, 2 * n, ...)`` tensor to padded_n
rows. FP8 zero decodes to 0.0, so the padded rows contribute nothing.
"""
rows. FP8 zero decodes to 0.0, so the padded rows contribute nothing."""
if padded_n == n:
return x
e = x.size(0)