[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
+23 -46
View File
@@ -251,8 +251,7 @@ class UnderscoreInplaceParallelLinears(FourParallelLinears):
class PlainQKV(nn.Module):
"""q/k/v returned as a bare tuple: no reshape stands between the calls and
the return, so both QKVFuser and MergedColumnParallelFuser can rewrite it.
"""
the return, so both QKVFuser and MergedColumnParallelFuser can rewrite it."""
def __init__(self, hidden: int = 32, heads: int = 4, head_dim: int = 8):
super().__init__()
@@ -339,8 +338,7 @@ class GuardedVAttention(FakeAttention):
"""Gemma 4-style: `v_proj` is called once but also read in a `None` guard.
The guard is a fusion invariant (the fuser only binds instances where the
projection exists), so it folds to `True` and the call still fuses.
"""
projection exists), so it folds to `True` and the call still fuses."""
def forward(
self, hidden_states, attention_mask=None, past_key_values=None, **kwargs
@@ -370,8 +368,7 @@ class TruthyGuardAttention(FakeAttention):
An `nn.Linear` is always truthy, so the guard folds to `True` and the call
still fuses (the projection is a proven invariant, exactly as for a `None`
guard).
"""
guard)."""
def forward(
self, hidden_states, attention_mask=None, past_key_values=None, **kwargs
@@ -402,8 +399,7 @@ class StatementGuardVAttention(FakeAttention):
The `if`'s test is not an `ast.Compare`, so the identity-check scan skips it;
`_in_boolean_context` folds the test to `True` (an `nn.Linear` is always
truthy) and the call inside the now-`if True:` body still fuses, with the
live `else` surviving the rewrite.
"""
live `else` surviving the rewrite."""
def forward(
self, hidden_states, attention_mask=None, past_key_values=None, **kwargs
@@ -432,8 +428,7 @@ class BranchedKVAttention(FakeAttention):
The three calls do not share a block, so the fused GEMM must be hoisted to
the innermost block that dominates all of them (the function body). The
live `if`/`else` must survive the rewrite.
"""
live `if`/`else` must survive the rewrite."""
is_kv_shared_layer = False
@@ -464,8 +459,7 @@ class RebindArgAttention(FakeAttention):
The branch is dead at trace time so the match succeeds, but the source
rewrite must refuse: hoisting the GEMM above the rebind would feed k/v a
different input. Result: no fusion.
"""
different input. Result: no fusion."""
recompute = False
@@ -496,8 +490,7 @@ class InPlaceMutatedArgAttention(FakeAttention):
Like `RebindArgAttention`, but the mutation keeps the name in a `Load`
context (`hidden_states.mul_(2)`), so a bare `Name`-store check would miss it.
The rewrite must still refuse: hoisting the GEMM above the mutation changes
the value k/v see. Result: no fusion.
"""
the value k/v see. Result: no fusion."""
recompute = False
@@ -527,8 +520,7 @@ class AliasMutatedArgAttention(FakeAttention):
`hidden_states.view(-1)` shares storage with its base, so `alias.mul_(2)`
changes what k/v read without ever naming `hidden_states` as a target. Only
tracking names that may alias the input catches it. Result: no fusion.
"""
tracking names that may alias the input catches it. Result: no fusion."""
recompute = False
@@ -559,8 +551,7 @@ class FunctionalInplaceArgAttention(FakeAttention):
`F.relu(hidden_states, inplace=True)` writes through an argument, so the
name appears only in a `Load` context inside a call that is not a method on
it -- invisible to a trailing-underscore method check. Result: no fusion.
"""
it -- invisible to a trailing-underscore method check. Result: no fusion."""
recompute = False
@@ -590,8 +581,7 @@ class SubscriptMutatedArgAttention(FakeAttention):
`hidden_states[..., 0] = 0` leaves the name in a `Load` context on the
subscript's value, so it too evades a bare `Name`-store check. The rewrite
must refuse for the same reason. Result: no fusion.
"""
must refuse for the same reason. Result: no fusion."""
recompute = False
@@ -621,8 +611,7 @@ class NonFoldableRefAttention(FakeAttention):
Deleting `v_proj` would break `isinstance(self.v_proj, nn.Linear)`: it reads
the projection's type, not just whether it exists, so the fuser cannot fold
it and must refuse rather than rewrite it.
"""
it and must refuse rather than rewrite it."""
def forward(
self, hidden_states, attention_mask=None, past_key_values=None, **kwargs
@@ -847,8 +836,7 @@ def test_glu_identifies_down_projection():
It is forced to `RowParallelLinear` in `update_attrs` so its sharded input
matches the column-parallel merged gate/up; `None` when there is no such
projection to force (fusion of gate/up still applies).
"""
projection to force (fusion of gate/up still applies)."""
with torch.device("meta"):
assert get_fuser(GLUMLP(), GLUFuser).down_name == "down_proj"
assert get_fuser(ReversedGLUMLP(), GLUFuser).down_name == "down_proj"
@@ -1009,8 +997,7 @@ def test_bypass_existence_guard_folds_identity_none_check(expr, expected):
The projection is a proven invariant (it exists as an `nn.Linear`), so an
`is (not) None` guard has a constant truth value; folding it lets the call be
rewritten away without changing the guard's outcome. `==`/`!=` are excluded
(see the refusal test) because a subclass may override `__eq__`/`__ne__`.
"""
(see the refusal test) because a subclass may override `__eq__`/`__ne__`."""
funcdef, ref = _guard_funcdef(expr)
bypass_existence_guard(funcdef, ref, "v_proj")
test = next(node for node in ast.walk(funcdef) if isinstance(node, ast.IfExp)).test
@@ -1029,8 +1016,7 @@ def test_bypass_existence_guard_folds_bare_truthiness(expr):
An `nn.Linear` has no `__bool__`/`__len__`, so it is always truthy; in a pure
boolean position (a test, or a `not` operand) the reference can be replaced by
`True`, letting the projection be deleted.
"""
`True`, letting the projection be deleted."""
funcdef, ref = _guard_funcdef(expr)
bypass_existence_guard(funcdef, ref, "v_proj")
# No `self.v_proj` reference survives; a literal `True` took its place.
@@ -1045,8 +1031,7 @@ def test_bypass_existence_guard_folds_bare_if_statement():
The `len(node.ops) == 1` `Compare` scan skips it (it is not a comparison at
all); `_in_boolean_context` then matches the `if`'s test and folds it, so the
bare-truthiness statement form is handled, not silently dropped.
"""
bare-truthiness statement form is handled, not silently dropped."""
funcdef = ast.parse(
"def f(self, a, b):\n if self.v_proj:\n return a\n return b"
).body[0]
@@ -1078,8 +1063,7 @@ def test_bypass_existence_guard_refuses_non_guard_reference(expr):
Rewriting it is unsafe (its value depends on more than the projection's
existence), so the fuser refuses rather than change semantics. `==`/`!=` are
refused too: `is_linear` accepts `nn.Linear` subclasses that could override
`__eq__`/`__ne__`, so equality need not agree with `is (not) None`.
"""
`__eq__`/`__ne__`, so equality need not agree with `is (not) None`."""
funcdef, ref = _guard_funcdef(expr)
with pytest.raises(ValueError, match="outside an existence guard"):
bypass_existence_guard(funcdef, ref, "v_proj")
@@ -1119,8 +1103,7 @@ def test_merged_column_fuser_folds_existence_guard():
Guard folding lives on `StackedFuser`, not just `QKVFuser`, because every
stacked fuser deletes the projections it merges -- a surviving reference to
one would fail at runtime.
"""
one would fail at runtime."""
with torch.device("meta"):
module = GuardedParallelLinears()
fuser = MergedColumnParallelFuser.match(trace(module), module)
@@ -1146,8 +1129,7 @@ def test_merged_column_fuser_rejects_input_mutation(cls):
The mutation may be direct (`x.add_(1)`), through a view that shares the
input's storage, or through a call that writes an argument in place
(`F.relu(x, inplace=True)`, `torch.relu_(x)`). Each one silently changes the
fused result, so the rewrite must refuse rather than fuse.
"""
fused result, so the rewrite must refuse rather than fuse."""
with torch.device("meta"):
module = cls()
fuser = MergedColumnParallelFuser.match(trace(module), module)
@@ -1205,8 +1187,7 @@ def test_merged_column_fuser_supports_any_number_of_linears(
def test_merged_name_is_unique_per_linear_names():
"""The computed name must not collide across different projections, so
stacking two unrelated fusions can never clobber packed_modules_mapping.
"""
stacking two unrelated fusions can never clobber packed_modules_mapping."""
ab_c = MergedColumnParallelFuser(source_cls="M", linear_names=("a_b", "c"))
a_bc = MergedColumnParallelFuser(source_cls="M", linear_names=("a", "b_c"))
assert ab_c.merged_name != a_bc.merged_name
@@ -1222,8 +1203,7 @@ def test_heterogeneous_instances_fall_back_to_merged_column_fuser(
layer whose out_features aren't a multiple of its own head_dim (as a
misconfigured or heterogeneous checkpoint might have) fails QKVFuser's
validation and must still fuse via the generic fallback, while a
well-formed sibling of the same class keeps using QKVFuser.
"""
well-formed sibling of the same class keeps using QKVFuser."""
with torch.device("meta"):
container = nn.Module()
container.compatible = PlainQKV(head_dim=8)
@@ -1244,8 +1224,7 @@ def test_detects_and_rewrites_packed_qkv(kv_heads):
"""A single projection split into q/k/v must be re-sharded, not merged.
Only the split sizes change: `QKVParallelLinear` loads the packed
checkpoint weight as-is, and shards q by heads while replicating k/v.
"""
checkpoint weight as-is, and shards q by heads while replicating k/v."""
with torch.device("meta"):
meta = PackedQKVAttention(kv_heads=kv_heads)
fuser = get_fuser(meta, PackedQKVFuser)
@@ -1276,8 +1255,7 @@ def test_detects_and_rewrites_packed_qkv(kv_heads):
def test_per_head_split_is_not_packed_qkv():
"""The split must consume the whole projection, else its sizes are head
widths and re-sharding by them would be wrong.
"""
widths and re-sharding by them would be wrong."""
with torch.device("meta"):
assert get_fuser(PerHeadSplitAttention(), PackedQKVFuser) is None
@@ -1397,8 +1375,7 @@ def test_act_and_mul_derived_from_module(default_vllm_config):
def _wider_model_config(head_dim: int) -> SimpleNamespace:
"""A model whose global head size is twice `head_dim`, as a wider layer
elsewhere in a heterogeneous checkpoint would make it.
"""
elsewhere in a heterogeneous checkpoint would make it."""
return SimpleNamespace(
model_config=SimpleNamespace(get_head_size=lambda: 2 * head_dim),
quant_config=None,
+5 -10
View File
@@ -45,8 +45,7 @@ def _attention(q_lora_rank: int | None):
def _match(q_lora_rank: int | None) -> MLAFuser | None:
"""Match a meta `DeepseekV2Attention` directly (bypassing the per-class
`get_fuser` cache, so both q_lora variants of the same class are seen).
"""
`get_fuser` cache, so both q_lora variants of the same class are seen)."""
attn = _attention(q_lora_rank)
return MLAFuser.match(trace(attn), attn)
@@ -82,8 +81,7 @@ def test_discovers_modules_with_q_lora():
def test_q_lora_stacks_qkv_a_proj():
"""The MLA layer reads `q_a_proj` and `kv_a_proj_with_mqa` fused into one
down-projection, so both checkpoint weights must remap into it.
"""
down-projection, so both checkpoint weights must remap into it."""
fuser = _match(q_lora_rank=64)
assert isinstance(fuser, MLAFuser)
prefix = "model.layers.0.self_attn"
@@ -104,8 +102,7 @@ def test_update_forward_rewrites_real_attention(q_lora_rank):
The q-LoRA path hoists the merged down-projection to a top-level statement
while its calls sit inside the `q_lora_rank` branches, so the region it
spans is wide; a check that over-approximates aliasing would silently refuse
here and cost the fusion rather than fail loudly.
"""
here and cost the fusion rather than fail loudly."""
fuser = _match(q_lora_rank)
assert isinstance(fuser, MLAFuser)
fuser.update_forward(_attention(q_lora_rank))
@@ -129,8 +126,7 @@ class _Norm(nn.Module):
class RenamedMLA(nn.Module):
"""An MLA-shaped attention whose children have non-standard names, proving
discovery is by structure and not attribute name.
"""
discovery is by structure and not attribute name."""
def __init__(self):
super().__init__()
@@ -157,8 +153,7 @@ class RenamedMLA(nn.Module):
def test_discovers_modules_under_arbitrary_names():
"""Discovery is purely structural: `RenamedMLA` gives its children non-standard
names, and `match` still locates each projection by dataflow.
"""
names, and `match` still locates each projection by dataflow."""
with torch.device("meta"):
module = RenamedMLA()
fuser = MLAFuser.match(trace(module), module)
+6 -12
View File
@@ -277,8 +277,7 @@ def test_moe_fuser_matches_scaled_router():
def test_moe_fuser_matches_grouped_router():
"""Group masking between the score and the routing top-k still matches: the
scorer is anchored on the routing (last) top-k, not the group one.
"""
scorer is anchored on the routing (last) top-k, not the group one."""
with torch.device("meta"):
block = MoEBlock(GroupedRouter)
fuser = MoEBlockFuser.match(block, "experts")
@@ -288,8 +287,7 @@ def test_moe_fuser_matches_grouped_router():
def test_moe_fuser_matches_correction_router():
"""A score-correction bias buffer (DeepSeek-V3 noaux) is allowed; the
rebuilt gate carries it in fp32 for FusedMoE's biased routers.
"""
rebuilt gate carries it in fp32 for FusedMoE's biased routers."""
with torch.device("meta"):
block = MoEBlock(CorrectionRouter)
fuser = MoEBlockFuser.match(block, "experts")
@@ -300,8 +298,7 @@ def test_moe_fuser_matches_correction_router():
def test_moe_fuser_reads_router_dtype_from_the_gate():
"""A router that computes its logits in fp32 must keep routing in fp32 when
rebuilt, even though no config field names the dtype. The cast back to the
activation dtype after the top-k must not be mistaken for the routing dtype.
"""
activation dtype after the top-k must not be mistaken for the routing dtype."""
with torch.device("meta"):
fp32 = MoEBlockFuser.match(MoEBlock(Fp32Router), "experts")
default = MoEBlockFuser.match(MoEBlock(TopKRouter), "experts")
@@ -320,8 +317,7 @@ def test_moe_fuser_detects_shared_experts():
def test_moe_fuser_skips_shared_detection_without_extra_children():
"""With only experts and gate, shared-expert detection (and its block trace)
is skipped, so a gate-derived add is not misread as a shared expert.
"""
is skipped, so a gate-derived add is not misread as a shared expert."""
with torch.device("meta"):
block = MoEBlockNoShared()
fuser = MoEBlockFuser.match(block, "experts")
@@ -366,8 +362,7 @@ def test_moe_fuser_declines_unsupported(block_cls):
def test_moe_fuser_ignores_nested_returns():
"""A tuple `return` inside a nested helper must not decline a block whose own
forward returns a single tensor.
"""
forward returns a single tensor."""
with torch.device("meta"):
block = MoEBlockNestedTupleReturn()
assert isinstance(MoEBlockFuser.match(block, "experts"), MoEBlockFuser)
@@ -375,8 +370,7 @@ def test_moe_fuser_ignores_nested_returns():
def test_moe_fuser_router_requires_connected_dataflow():
"""A gate with linear + softmax + top-k present but not wired as a router
(top-k selects over the input, not the scored logits) is not detected.
"""
(top-k selects over the input, not the scored logits) is not detected."""
with torch.device("meta"):
block = MoEBlock(DisconnectedRouter)
assert MoEBlockFuser.match(block, "experts") is None
@@ -83,8 +83,7 @@ class ToleranceRMSNorm(NamedEpsRMSNorm):
class LiteralEpsRMSNorm(RMSNorm):
"""eps is a literal in the source, and an unrelated attribute happens to
hold the same value: matching on the value alone would bind to it.
"""
hold the same value: matching on the value alone would bind to it."""
def __init__(self, hidden: int = 16, eps: float = 1e-5):
super().__init__(hidden, eps)
@@ -96,8 +95,7 @@ class LiteralEpsRMSNorm(RMSNorm):
class AmbiguousEpsRMSNorm(nn.Module):
"""Two attributes hold the eps value, and the forward reads the second, so
their order cannot pick it.
"""
their order cannot pick it."""
def __init__(self, hidden: int = 16, eps: float = 1e-6):
super().__init__()
@@ -233,8 +231,7 @@ def test_weightless_norm_has_no_hidden_size(default_vllm_config):
def test_fused_rms_norm_op_default_eps(default_vllm_config):
"""`torch.nn.RMSNorm` (a single `F.rms_norm` call) matches via the fast path;
its default `eps=None` resolves to `finfo(dtype).eps` in `fuse`.
"""
its default `eps=None` resolves to `finfo(dtype).eps` in `fuse`."""
from vllm.model_executor.layers.layernorm import RMSNorm as VLLMRMSNorm
with torch.device("meta"):
@@ -250,8 +247,7 @@ def test_fused_rms_norm_op_default_eps(default_vllm_config):
def test_eps_is_derived_per_instance(default_vllm_config):
"""Two instances of the same norm class with different eps must fuse to their
own eps: the type-cached fuser holds only structure, not this value.
"""
own eps: the type-cached fuser holds only structure, not this value."""
with torch.device("meta"):
for eps in (1e-5, 1e-6):
module = RMSNorm(16, eps=eps)
@@ -263,8 +259,7 @@ def test_eps_is_derived_per_instance(default_vllm_config):
@pytest.mark.parametrize("cls", [NamedEpsRMSNorm, ToleranceRMSNorm])
def test_eps_attr_is_found_by_value_not_name(cls, default_vllm_config):
"""The eps attribute is identified by holding the traced value, so a norm
stays per-instance correct whatever it names it.
"""
stays per-instance correct whatever it names it."""
with torch.device("meta"):
for eps in (1e-5, 1e-6):
module = cls(16, eps=eps)
@@ -276,8 +271,7 @@ def test_eps_attr_is_found_by_value_not_name(cls, default_vllm_config):
def test_literal_eps_is_not_mistaken_for_an_attribute(default_vllm_config, caplog):
"""A literal eps is recognised as coming from no attribute, even when one
holds the same value, and is taken from the traced source instead.
"""
holds the same value, and is taken from the traced source instead."""
logger = "vllm.model_executor.models.transformers.fusers.rms_norm"
with caplog.at_level("DEBUG", logger=logger), torch.device("meta"):
module = LiteralEpsRMSNorm()
@@ -290,8 +284,7 @@ def test_literal_eps_is_not_mistaken_for_an_attribute(default_vllm_config, caplo
def test_ambiguous_eps_attrs_are_disambiguated(default_vllm_config):
"""When several attributes hold the eps value, the one the forward actually
reads is identified, and they are all left as they were found.
"""
reads is identified, and they are all left as they were found."""
with torch.device("meta"):
module = AmbiguousEpsRMSNorm(16, eps=1e-6)
before = dict(vars(module))
@@ -308,8 +301,7 @@ def test_ambiguous_eps_attrs_are_disambiguated(default_vllm_config):
def test_fused_norm_is_gather_capable(default_vllm_config):
"""Every weighted fused norm is emitted gather-capable, so a norm on a head-sharded
projection (OLMoE-style) self-corrects at runtime with no QKV-specific
plumbing. A full-width input skips the gather and equals a plain norm.
"""
plumbing. A full-width input skips the gather and equals a plain norm."""
from vllm.model_executor.layers.layernorm import GemmaRMSNorm, RMSNorm
from vllm.model_executor.models.transformers.fusers import rms_norm
@@ -331,8 +323,7 @@ def test_fused_norm_is_gather_capable(default_vllm_config):
def test_gathered_norm_rejects_uneven_sharding(default_vllm_config):
"""A sharded input (narrower than the full-width weight) that does not tile
the weight evenly across ranks is rejected before any collective.
"""
the weight evenly across ranks is rejected before any collective."""
from vllm.model_executor.models.transformers.fusers import rms_norm
norm = rms_norm.TPAwareRMSNorm(hidden_size=8, eps=1e-6)
@@ -28,8 +28,7 @@ def fake_hw_layernorm(monkeypatch):
A `SimpleNamespace` stands in for the module: `importlib.import_module`
returns it from `sys.modules` and `getattr` resolves `RMSNorm`, while its
attributes are set at construction (no `ModuleType` attribute-set that mypy
rejects, no constant `setattr` that ruff rejects).
"""
rejects, no constant `setattr` that ruff rejects)."""
module = types.SimpleNamespace(RMSNorm=type("HwRMSNorm", (), {}))
monkeypatch.setitem(sys.modules, HW_MODULE, module)
return module
@@ -82,8 +81,7 @@ def test_act_and_mul_falls_back_for_unknown_activation(
@pytest.fixture(scope="module")
def tiny_llama_path(tmp_path_factory):
"""A randomly-initialized microscopic Llama saved to disk (with an ungated
tokenizer) so vLLM can load it like any local checkpoint.
"""
tokenizer) so vLLM can load it like any local checkpoint."""
from transformers import AutoTokenizer, LlamaConfig, LlamaForCausalLM
tokenizer = AutoTokenizer.from_pretrained("hf-internal-testing/llama-tokenizer")