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
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""
EAGLE3 Acceptance Length Regression Tests.
"""EAGLE3 Acceptance Length Regression Tests.
These tests verify that acceptance lengths for EAGLE3 speculative decoding
do not regress across vLLM commits. Each test runs inference on the MT-Bench
@@ -131,7 +131,8 @@ class TestBackupTokenAsyncSpec:
def test_buggy_code_was_always_off_by_one(self):
"""The original code used seq_len as index, which is always one past
the end of output_token_ids even without async inflation."""
the end of output_token_ids even without async inflation.
"""
req_ids = ["r0"]
requests = {"r0": _FakeRequest([0, 1, 2], [1000, 1001])}
batch = _FakeInputBatch(req_ids, [5])
@@ -39,7 +39,6 @@ def _create_vllm_config_for_dsd(
a schedule covering every query length in ``[1, max_decode_query_len]`` is
generated.
"""
max_decode_query_len = max_spec_tokens + 1
max_capture_tokens = max_num_seqs * max_decode_query_len
@@ -91,7 +90,6 @@ def test_dynamic_sd_full_cudagraph_covers_all_uniform_decode_shapes(monkeypatch)
shapes have been built, dispatch() should pick a FULL graph for every
uniform decode batch shape produced by DSD up to max_num_seqs.
"""
max_num_seqs = 512
max_spec_tokens = 7
max_decode_query_len = max_spec_tokens + 1
@@ -190,7 +188,6 @@ def test_dynamic_sd_non_uniform_batch_falls_back_to_piecewise(monkeypatch):
FULL candidates should be skipped in favor of the mixed-batch PIECEWISE
graph under FULL_AND_PIECEWISE mode.
"""
max_spec_tokens = 4
monkeypatch.setattr(
@@ -236,7 +233,6 @@ def test_prompt_chunks_shaped_like_spec_decode_miss_the_full_graph(monkeypatch):
by coincidence; replaying the FULL graph over them corrupts every request
in the batch. See https://github.com/vllm-project/vllm/issues/49918.
"""
max_spec_tokens = 7
decode_query_len = max_spec_tokens + 1
@@ -307,7 +303,6 @@ def test_basic_sd_does_not_capture_shorter_full_decode_shapes(monkeypatch):
Uniform batches with smaller query lengths should therefore miss the FULL
path entirely when using FULL_AND_PIECEWISE.
"""
max_num_seqs = 512
max_spec_tokens = 7
max_decode_query_len = max_spec_tokens + 1
@@ -368,7 +363,6 @@ def test_dynamic_sd_only_captures_scheduled_query_lengths(monkeypatch):
FULL graphs, while every other query length (e.g. the lower values 1, 2, 3)
must fall back to the mixed-batch PIECEWISE graph.
"""
max_num_seqs = 128
max_spec_tokens = 7
max_decode_query_len = max_spec_tokens + 1
+7 -15
View File
@@ -116,8 +116,7 @@ def _create_proposer(
def test_prepare_next_token_ids():
"""
Test for prepare_next_token_ids_cpu and prepare_next_token_ids_padded.
"""Test for prepare_next_token_ids_cpu and prepare_next_token_ids_padded.
Each will produce a device tensor of next_token_ids, taking as input
either the GPU tensor of sampled_token_ids with -1 for rejected tokens,
or the CPU python list[list[int]] with the rejected tokens removed.
@@ -196,8 +195,7 @@ def test_prepare_next_token_ids():
def test_prepare_inputs():
"""
cu_target_query_lens: [0, a, a + b, a + b + c]
"""cu_target_query_lens: [0, a, a + b, a + b + c]
num_rejected_tokens: [n1, n2, n3]
num_tokens_per_req: [a - n1, b - n2, c - n3]
cu_num_tokens: [0, a - n1, a + b - n1 - n2, a + b + c - n1 - n2 - n3]
@@ -286,8 +284,7 @@ def test_prepare_inputs():
def test_prepare_inputs_padded():
"""
Input scenario is 3 requests with num_speculative_tokens == 2 and:
"""Input scenario is 3 requests with num_speculative_tokens == 2 and:
- Request 1: query_len = 3, rejected = 1
- Request 2: query_len = 3, rejected = 0
- Request 3: query_len = 3, rejected = 2
@@ -297,7 +294,6 @@ def test_prepare_inputs_padded():
Reason: After accounting for rejections, these are the valid token positions
from the original indices to sample from.
"""
device = torch.device(DEVICE_TYPE)
expected_token_indices_to_sample = torch.tensor(
@@ -350,8 +346,7 @@ def test_prepare_inputs_padded():
def test_set_inputs_first_pass_default_eagle():
"""
Test for set_inputs_first_pass without extra input slots (default EAGLE).
"""Test for set_inputs_first_pass without extra input slots (default EAGLE).
This tests the path where needs_extra_input_slots=False, which is the
default EAGLE pathway. In this case:
@@ -436,8 +431,7 @@ def test_set_inputs_first_pass_default_eagle():
def test_set_inputs_first_pass_draft_model():
"""
Test for set_inputs_first_pass with a draft model (extra input slots,
"""Test for set_inputs_first_pass with a draft model (extra input slots,
no shift).
This tests the path where needs_extra_input_slots=True and
@@ -578,8 +572,7 @@ def test_set_inputs_first_pass_draft_model():
def test_set_inputs_first_pass_parallel_drafting():
"""
Test for set_inputs_first_pass with parallel drafting (extra input slots,
"""Test for set_inputs_first_pass with parallel drafting (extra input slots,
with shift).
This tests the path where needs_extra_input_slots=True and
@@ -1107,8 +1100,7 @@ def test_propose_stores_probabilistic_draft_probs(attn_backend, monkeypatch):
def test_set_inputs_first_pass_dflash():
"""
Test for DFlash set_inputs_first_pass.
"""Test for DFlash set_inputs_first_pass.
DFlash uses cross-attention: context tokens become K/V and only
query tokens (bonus + mask) are Q. This tests the DFlash-specific
@@ -105,7 +105,8 @@ def test_build_draft_attn_metadata_sets_seq_lens_cpu_upper_bound():
"""The fix: every per-step ``CommonAttentionMetadata`` carries a non-None
``seq_lens_cpu_upper_bound`` derived from the target-side upper bound plus
the current draft-step offset. Padded entries are zeroed (matching the
main model runner's convention)."""
main model runner's convention).
"""
fake = _make_fake_speculator()
base = torch.tensor([100, 200, 300, 0], dtype=torch.int32)
@@ -126,7 +127,8 @@ def test_build_draft_attn_metadata_sets_seq_lens_cpu_upper_bound():
def test_build_draft_attn_metadata_zeroes_padded_upper_bound_tail():
"""The padded tail of the upper-bound tensor is zeroed, so it stays a
valid tensor of length ``num_reqs_padded`` regardless of padding."""
valid tensor of length ``num_reqs_padded`` regardless of padding.
"""
fake = _make_fake_speculator()
base = torch.zeros(2, dtype=torch.int32)
@@ -141,7 +143,8 @@ def test_build_draft_attn_metadata_zeroes_padded_upper_bound_tail():
def test_build_draft_attn_metadata_clamps_to_max_model_len():
"""The per-request upper bound (target bound + step) is clamped to the
model length so it never exceeds the allocated KV range."""
model length so it never exceeds the allocated KV range.
"""
fake = _make_fake_speculator(max_model_len=1024)
base = torch.tensor([1023, 500], dtype=torch.int32)
@@ -132,7 +132,8 @@ def test_eagle_step_slot_mapping_kernel_exceeds_max():
def test_eagle_step_slot_mapping_kernel_cudagraph_padding():
"""Test that padding threads write PADDING_SLOT_ID when
input_batch_size > batch_size (cudagraph padding)."""
input_batch_size > batch_size (cudagraph padding).
"""
device = torch.device(DEVICE_TYPE)
batch_size = 4
input_batch_size = 8
@@ -130,8 +130,7 @@ def test_proposer_initialization_missing_layer_ids():
def test_prepare_next_token_ids_padded():
"""
Test for prepare_next_token_ids_padded with extract_hidden_states.
"""Test for prepare_next_token_ids_padded with extract_hidden_states.
Since num_speculative_tokens == 1, sampled_token_ids has shape (batch_size, 1).
For each request we either use the sampled token (if valid and not discarded)
@@ -196,8 +195,7 @@ def test_prepare_next_token_ids_padded():
def test_propose():
"""
Test the propose() method of ExtractHiddenStatesProposer.
"""Test the propose() method of ExtractHiddenStatesProposer.
This should:
1. Accept target hidden states and sampled token IDs
@@ -69,7 +69,8 @@ def _make_kv_cache_config(layer_names: set[str]) -> SimpleNamespace:
def test_block_size_uses_kernel_block_size(monkeypatch: pytest.MonkeyPatch):
"""The proposer's slot-mapping math runs against the kernel-granularity
block table, so block_size must come from kernel_block_sizes."""
block table, so block_size must come from kernel_block_sizes.
"""
layer_names = {"draft.0.self_attn.attn"}
proposer = _make_proposer(monkeypatch, layer_names)
@@ -97,7 +98,8 @@ def test_block_size_falls_back_to_kv_cache_spec(monkeypatch: pytest.MonkeyPatch)
def test_draft_layer_iteration_is_deterministic(monkeypatch: pytest.MonkeyPatch):
"""_draft_attn_layer_names is a set; the attention groups built from it
must not depend on its (process-random) iteration order."""
must not depend on its (process-random) iteration order.
"""
layer_names = {"draft.c.attn", "draft.a.attn", "draft.b.attn"}
expected_order = sorted(layer_names)
+2 -1
View File
@@ -93,7 +93,8 @@ def test_eagle_max_len(
@pytest.mark.parametrize("spec_max_model_len", [80, 150])
def test_mtp_speculative_config_max_model_len(spec_max_model_len: int):
"""Regression test for #41456: max_model_len in speculative config
should be respected for the draft model."""
should be respected for the draft model.
"""
model_config = ModelConfig(
model="XiaomiMiMo/MiMo-7B-Base",
runner="generate",
+1 -3
View File
@@ -66,7 +66,6 @@ def _create_mtp_proposer(num_speculative_tokens: int) -> EagleProposer:
@mock.patch("vllm.v1.spec_decode.llm_base_proposer.get_model")
def test_mtp_load_model_unified(mock_get_model, mock_get_layers, mock_get_pp_group):
"""Test MTP-specific model loading with unified model approach."""
# Setup mocks
mock_model = mock.MagicMock()
mock_model.model.embed_tokens.weight.shape = (131072, 4096)
@@ -117,8 +116,7 @@ def test_mtp_load_model_unified(mock_get_model, mock_get_layers, mock_get_pp_gro
@pytest.mark.parametrize("num_speculative_tokens", [1])
def test_mtp_propose(num_speculative_tokens, monkeypatch):
"""Test that MTP's forward method returns hidden states directly"""
"""Test that MTP's forward method returns hidden states directly."""
device = torch.device(DEVICE_TYPE)
batch_size = 2
seq_lens = [5, 3]
@@ -93,8 +93,7 @@ def _assert_distribution_match(
label: str = "",
min_expected: float = 5.0,
):
"""
Assert sampled tokens match the target distribution via a
"""Assert sampled tokens match the target distribution via a
chi-squared goodness-of-fit test. This is done by computing
observed vs expected token counts (target_probs * num_samples),
then checking that the chi-squared statistic is below a conservative
@@ -242,8 +241,7 @@ def test_watermarked_recovery_supports_smaller_draft_vocabulary():
def test_stochastic_rejection_sample(
num_speculative_steps: int, temperature: float, draft_logits_dtype: torch.dtype
):
"""
Verify that rejection sampling produces the target distribution.
"""Verify that rejection sampling produces the target distribution.
This is done by simulating many independent trials of speculative
decoding (from a fixed target and draft distribution). We then
run rejection sample on all of the trials (requests), and verify
@@ -253,7 +251,6 @@ def test_stochastic_rejection_sample(
Parametrized over the draft-logits dtype: storing them in the draft head's
dtype must not bias the output distribution.
"""
torch.manual_seed(42)
device = "cuda"
num_trials = 10 * VOCAB_SIZE
@@ -383,11 +380,9 @@ def test_gumbel_drafted_rejection_sample_is_unbiased(num_speculative_steps: int)
@pytest.mark.parametrize("num_speculative_steps", [1, 3])
def test_greedy_rejection_sample(num_speculative_steps: int):
"""
Verify that greedy (temperature=0) always outputs the target argmax
"""Verify that greedy (temperature=0) always outputs the target argmax
at every accepted position.
"""
torch.manual_seed(42)
device = "cuda"
num_trials = 10 * VOCAB_SIZE
@@ -435,8 +430,7 @@ def test_synthetic_rejection_sample(
temperature: float,
unconditional_rates: list[float],
):
"""
Verify that synthetic rejection sampling produces the expected
"""Verify that synthetic rejection sampling produces the expected
per-position acceptance rates. The unconditional rate at position i
is P(all draft steps 0..i accepted) = product(conditional_rates[0:i+1]).
This is approximately mean(num accepted >= i + 1) over many trials.
@@ -689,14 +683,12 @@ def test_placeholder_blocks_later_draft_tokens(use_block_verification: bool):
def test_block_verification_rejection_sample(
num_speculative_steps: int, temperature: float, has_draft_logits: bool
):
"""
Verify that block verification (Sun et al.) preserves the target
"""Verify that block verification (Sun et al.) preserves the target
distribution at every accepted position, for both the full draft-logits
case and the one-hot (no draft logits) case. Block verification changes
*which* prefix is accepted, but the marginal of every output position must
still match the target distribution p(x).
"""
torch.manual_seed(42)
device = "cuda"
num_trials = 10 * VOCAB_SIZE
@@ -733,12 +725,10 @@ def test_block_verification_rejection_sample(
@pytest.mark.parametrize("num_speculative_steps", [3, 5])
def test_block_verification_accepts_at_least_as_many(num_speculative_steps: int):
"""
Block verification is designed to accept at least as long a prefix as
"""Block verification is designed to accept at least as long a prefix as
token verification in expectation. Verify the mean accepted length is no
worse than the standard method on the same inputs.
"""
torch.manual_seed(0)
device = "cuda"
num_trials = 20 * VOCAB_SIZE
@@ -134,8 +134,7 @@ def print_spec_decode_stats(stats: dict) -> None:
@pytest.mark.parametrize("config", SPECULATOR_CONFIGS)
def test_speculators_model(vllm_runner, example_prompts, monkeypatch, config):
"""
Test speculators model properly initializes speculative decoding.
"""Test speculators model properly initializes speculative decoding.
Verifies:
1. Speculative config is automatically initialized from speculators config
@@ -185,8 +184,7 @@ def test_speculators_model(vllm_runner, example_prompts, monkeypatch, config):
@large_gpu_mark(min_gb=40)
@pytest.mark.parametrize("config", SPECULATOR_CONFIGS)
def test_speculators_correctness(monkeypatch, config):
"""
E2E correctness test via the speculators auto-detect path.
"""E2E correctness test via the speculators auto-detect path.
Evaluates GSM8k accuracy to ensure the speculators-format model produces
correct outputs, and checks that acceptance length does not collapse under
@@ -32,8 +32,7 @@ from vllm.platforms import current_platform
def test_eagle3_speculators_model(
vllm_runner, example_prompts, model_path, monkeypatch
):
"""
Test Eagle3 speculators models properly initialize speculative decoding.
"""Test Eagle3 speculators models properly initialize speculative decoding.
This test verifies:
1. Eagle3 support is detected for the model