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
@@ -101,7 +101,8 @@ def test_packed_dsv4_zeroer_zeroes_only_each_layers_page():
|
||||
def test_overlaid_zeroer_dedups_segments_with_max_span():
|
||||
"""Two groups overlay one allocation; the zeroer must emit one segment per distinct
|
||||
byte offset, spanning the widest overlaid page, so a newly allocated block is fully
|
||||
zeroed no matter which group owns it."""
|
||||
zeroed no matter which group owns it.
|
||||
"""
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from vllm.v1.core.kv_cache_utils import get_kv_cache_config_from_groups
|
||||
|
||||
@@ -97,7 +97,8 @@ def test_draft_lookahead_uses_boundary_feature_when_cached():
|
||||
"""The drafter's +1 look-ahead can reach the feature at offset ==
|
||||
processed_end (the next chunk). When its encoder output is already cached
|
||||
(the scheduler encoded it ahead), it is used for the look-ahead position
|
||||
rather than ignored."""
|
||||
rather than ignored.
|
||||
"""
|
||||
f0 = _feature("h0", offset=0, length=8)
|
||||
f1 = _feature("h1", offset=8, length=8) # starts exactly at processed_end
|
||||
runner = _make_runner([f0, f1], cached=[f0, f1])
|
||||
@@ -114,7 +115,8 @@ def test_draft_lookahead_uses_boundary_feature_when_cached():
|
||||
def test_draft_lookahead_tolerates_missing_boundary_feature():
|
||||
"""When the +1 look-ahead feature past the processed boundary is not yet
|
||||
encoded, fall back to the token embedding (the draft token is verified by
|
||||
the target) instead of raising."""
|
||||
the target) instead of raising.
|
||||
"""
|
||||
f0 = _feature("h0", offset=0, length=8)
|
||||
f1 = _feature("h1", offset=8, length=8) # boundary feature, not cached
|
||||
runner = _make_runner([f0, f1], cached=[f0])
|
||||
@@ -131,7 +133,8 @@ def test_draft_lookahead_tolerates_missing_boundary_feature():
|
||||
def test_draft_lookahead_raises_on_interior_miss():
|
||||
"""A miss for a feature within the processed range (not the look-ahead
|
||||
boundary) is a real invariant violation and must fail loudly, even on the
|
||||
drafter path."""
|
||||
drafter path.
|
||||
"""
|
||||
f0 = _feature("h0", offset=0, length=8) # interior, within processed range
|
||||
runner = _make_runner([f0], cached=[])
|
||||
|
||||
@@ -141,7 +144,8 @@ def test_draft_lookahead_raises_on_interior_miss():
|
||||
|
||||
def test_target_path_raises_on_encoder_cache_miss():
|
||||
"""On the target path (no look-ahead) a miss is a real invariant
|
||||
violation and must fail loudly."""
|
||||
violation and must fail loudly.
|
||||
"""
|
||||
f0 = _feature("h0", offset=0, length=8)
|
||||
runner = _make_runner([f0], cached=[])
|
||||
|
||||
@@ -152,7 +156,8 @@ def test_target_path_raises_on_encoder_cache_miss():
|
||||
@pytest.mark.parametrize("draft_lookahead", [0, 1])
|
||||
def test_multi_request_batch_gathers_per_request(draft_lookahead):
|
||||
"""Two prefilling requests in one batch: per-request query bounds must be
|
||||
indexed by request, not applied as whole arrays."""
|
||||
indexed by request, not applied as whole arrays.
|
||||
"""
|
||||
a0 = _feature("a0", offset=0, length=8)
|
||||
b0 = _feature("b0", offset=0, length=8)
|
||||
cache = EncoderCache()
|
||||
|
||||
@@ -73,7 +73,8 @@ def _apply(bad_words_token_ids: list[list[int]]) -> torch.Tensor:
|
||||
|
||||
def test_v2_bad_words_prefix_inside_draft_tokens():
|
||||
"""A prefix matching entirely within the draft tokens must mask the bad
|
||||
word's last token at the draft position that completes the prefix."""
|
||||
word's last token at the draft position that completes the prefix.
|
||||
"""
|
||||
out = _apply([[12, 13, 40]])
|
||||
expected = torch.zeros_like(out)
|
||||
expected[2, 40] = -float("inf")
|
||||
@@ -82,7 +83,8 @@ def test_v2_bad_words_prefix_inside_draft_tokens():
|
||||
|
||||
def test_v2_bad_words_prefix_spanning_committed_and_draft_tokens():
|
||||
"""A prefix spanning the committed/draft boundary must mask at the row
|
||||
where the prefix completes, not one draft position later."""
|
||||
where the prefix completes, not one draft position later.
|
||||
"""
|
||||
out = _apply([[11, 12, 30]])
|
||||
expected = torch.zeros_like(out)
|
||||
expected[1, 30] = -float("inf")
|
||||
@@ -91,7 +93,8 @@ def test_v2_bad_words_prefix_spanning_committed_and_draft_tokens():
|
||||
|
||||
def test_v2_bad_words_no_spurious_match_from_last_committed_token():
|
||||
"""The last committed token must not be double-counted as the first draft
|
||||
token; [11, 11] never occurs in output [10, 11] + drafts [12, 13]."""
|
||||
token; [11, 11] never occurs in output [10, 11] + drafts [12, 13].
|
||||
"""
|
||||
out = _apply([[11, 11, 50]])
|
||||
expected = torch.zeros_like(out)
|
||||
torch.testing.assert_close(out, expected)
|
||||
|
||||
@@ -43,7 +43,8 @@ def _make_batch(
|
||||
slot_pool: np.ndarray | None = None,
|
||||
) -> InputBatch:
|
||||
"""Consistent batch with random unique request slots, 1 + k_i logits
|
||||
rows per request at the tail of each query segment."""
|
||||
rows per request at the tail of each query segment.
|
||||
"""
|
||||
if slot_pool is None:
|
||||
slot_pool = np.arange(max_num_reqs)
|
||||
slots = rng.choice(slot_pool, size=num_reqs, replace=False)
|
||||
@@ -141,7 +142,8 @@ def _owned_rows(cu: np.ndarray, owned: np.ndarray) -> np.ndarray:
|
||||
def test_local_batch_partition(tp_size: int, seed: int):
|
||||
"""Local sub-batches partition the batch by owner, preserve batch order
|
||||
within an owner, and carry exactly the owned requests' entries of every
|
||||
per-request and per-row array."""
|
||||
per-request and per-row array.
|
||||
"""
|
||||
rng = np.random.default_rng(seed)
|
||||
max_num_reqs = 64
|
||||
batch = _make_batch(rng, num_reqs=23, max_num_reqs=max_num_reqs, max_spec=3)
|
||||
@@ -223,7 +225,8 @@ def test_local_batch_partition(tp_size: int, seed: int):
|
||||
def test_all_to_all_reassembly_simulated(tp_size: int):
|
||||
"""Vocab shards computed from owner-sorted hidden states and routed
|
||||
through the simulated all-to-all reassemble into exactly the full-vocab
|
||||
logits of each rank's owned rows."""
|
||||
logits of each rank's owned rows.
|
||||
"""
|
||||
rng = np.random.default_rng(7)
|
||||
max_num_reqs = 32
|
||||
batch = _make_batch(rng, num_reqs=11, max_num_reqs=max_num_reqs, max_spec=4)
|
||||
@@ -261,7 +264,8 @@ def test_all_to_all_reassembly_simulated(tp_size: int):
|
||||
@requires_cuda
|
||||
def test_shard_no_spec():
|
||||
"""Batches without draft tokens (one logits row per request) degenerate
|
||||
cleanly: rows mirror requests."""
|
||||
cleanly: rows mirror requests.
|
||||
"""
|
||||
rng = np.random.default_rng(11)
|
||||
tp_size = 4
|
||||
max_num_reqs = 32
|
||||
@@ -280,7 +284,8 @@ def test_shard_no_spec():
|
||||
@pytest.mark.parametrize("tp_size", [2, 4])
|
||||
def test_shard_grammar_output(tp_size: int):
|
||||
"""The grammar filter keeps exactly the owned requests' bitmask rows, in
|
||||
grammar order, and the per-rank pieces partition the global bitmask."""
|
||||
grammar order, and the per-rank pieces partition the global bitmask.
|
||||
"""
|
||||
rng = np.random.default_rng(5)
|
||||
max_num_reqs = 32
|
||||
num_reqs = 12
|
||||
@@ -335,7 +340,8 @@ def test_shard_grammar_output(tp_size: int):
|
||||
@pytest.mark.parametrize("tp_size", [2, 4])
|
||||
def test_gather_src_indices_round_trip(tp_size: int):
|
||||
"""Padded per-rank result blocks indexed by gathered_src_indices restore
|
||||
batch order, including when some rank owns zero requests."""
|
||||
batch order, including when some rank owns zero requests.
|
||||
"""
|
||||
rng = np.random.default_rng(3)
|
||||
max_num_reqs = 40
|
||||
all_slots = np.arange(max_num_reqs)
|
||||
@@ -370,7 +376,8 @@ def test_gather_src_indices_round_trip(tp_size: int):
|
||||
def test_gather_sampler_output_kernels(tp_size: int):
|
||||
"""The fused pack/unpack kernels round-trip per-rank sampler results
|
||||
into batch order: token ids zero-filled past the local width, counts
|
||||
cast back to int32, identical on every rank."""
|
||||
cast back to int32, identical on every rank.
|
||||
"""
|
||||
from dataclasses import replace as dc_replace
|
||||
|
||||
from vllm.v1.worker.gpu.sample.output import SamplerOutput
|
||||
@@ -465,7 +472,8 @@ def test_gather_sampler_output_kernels(tp_size: int):
|
||||
def test_gather_sampler_output_logprobs_and_nans():
|
||||
"""num_nans is reduced per request and gathered; LogprobsTensors are
|
||||
packed into fixed per-request blocks, width-aligned across ranks (pad
|
||||
and truncate paths), and restored to global row order."""
|
||||
and truncate paths), and restored to global row order.
|
||||
"""
|
||||
from dataclasses import replace as dc_replace
|
||||
|
||||
from vllm.v1.outputs import LogprobsTensors
|
||||
@@ -598,7 +606,8 @@ def test_gather_sampler_output_logprobs_and_nans():
|
||||
def test_finish_requests_frees_slots_in_sorted_order():
|
||||
"""Request slots must be freed in the same order on every TP rank:
|
||||
ownership derives from slot indices, and `finished_req_ids` is a set
|
||||
whose iteration order is per-process hash-randomized."""
|
||||
whose iteration order is per-process hash-randomized.
|
||||
"""
|
||||
from vllm.v1.worker.gpu.model_runner import GPUModelRunner
|
||||
|
||||
removed: list[str] = []
|
||||
|
||||
@@ -217,7 +217,8 @@ def test_v1_block_table_move_row_clears_vacated_row():
|
||||
not keep stale block ids. Padded dummy-run batches dereference stale rows
|
||||
as mamba state slots (bypassing the NULL_BLOCK_ID fill of real decode
|
||||
padding) and write state in place there — corrupting the blocks' new
|
||||
owner once they are reallocated, e.g. to an in-flight NIXL load."""
|
||||
owner once they are reallocated, e.g. to an in-flight NIXL load.
|
||||
"""
|
||||
from vllm.v1.worker.block_table import BlockTable
|
||||
|
||||
block_table = BlockTable(
|
||||
@@ -249,7 +250,8 @@ def test_get_dummy_block_tables_returns_zeroed_rows():
|
||||
PAD-filled, state indices are not), so stale rows would direct dummy
|
||||
state writes at freed — possibly reallocated — blocks.
|
||||
get_dummy_block_tables must hand out zeroed (null block) rows while
|
||||
preserving the persistent storage address for CUDA graphs."""
|
||||
preserving the persistent storage address for CUDA graphs.
|
||||
"""
|
||||
device = torch.device("cuda")
|
||||
block_tables = BlockTables(
|
||||
block_sizes=[16],
|
||||
|
||||
@@ -331,7 +331,7 @@ def test_drafting_uses_a_separate_noise_stream():
|
||||
|
||||
|
||||
def test_greedy_temperature_zero_returns_argmax():
|
||||
"""temperature == 0 skips Gumbel noise and returns the exact argmax."""
|
||||
"""Temperature == 0 skips Gumbel noise and returns the exact argmax."""
|
||||
torch.manual_seed(0)
|
||||
num_reqs = 128
|
||||
logits = torch.randn(num_reqs, VOCAB_SIZE, device=DEVICE, dtype=torch.float32)
|
||||
|
||||
@@ -66,11 +66,9 @@ def _compare_objs(obj1, obj2, skip: Sequence = ("logitsprocs", "batch_update_bui
|
||||
def _remove_requests(
|
||||
input_batch: InputBatch, batch_size: int, reqs: list[CachedRequestState]
|
||||
) -> set[str]:
|
||||
"""
|
||||
Remove some requests randomly from the batch and returns
|
||||
"""Remove some requests randomly from the batch and returns
|
||||
set of request removed
|
||||
"""
|
||||
|
||||
num_reqs_to_remove = np.random.randint(0, batch_size)
|
||||
req_indices_to_remove: set[int] = set()
|
||||
for _ in range(num_reqs_to_remove):
|
||||
@@ -90,8 +88,7 @@ def _construct_expected_sampling_metadata(
|
||||
req_id_index_in_input_batch: dict[str, int],
|
||||
device: torch.device,
|
||||
) -> SamplingMetadata:
|
||||
"""
|
||||
Constructs and returns the expected SamplingMetadata for this
|
||||
"""Constructs and returns the expected SamplingMetadata for this
|
||||
batch.
|
||||
"""
|
||||
num_reqs = len(req_ids_retained)
|
||||
@@ -219,8 +216,7 @@ def _construct_cached_request_state(req_id_suffix: int):
|
||||
@pytest.mark.parametrize("device", DEVICES)
|
||||
@pytest.mark.parametrize("batch_size", [1, 2, 32, 64])
|
||||
def test_sampling_metadata_in_input_batch(device: str, batch_size: int):
|
||||
"""
|
||||
Tests the logic for managing sampling metadata in the InputBatch.
|
||||
"""Tests the logic for managing sampling metadata in the InputBatch.
|
||||
|
||||
This test involves adding a set of requests to the InputBatch,
|
||||
followed by removing a subset of them. Afterward, the batch is compacted,
|
||||
@@ -314,8 +310,7 @@ def test_sampling_metadata_in_input_batch(device: str, batch_size: int):
|
||||
@pytest.mark.parametrize("batch_size", [32])
|
||||
@pytest.mark.parametrize("swap_list", [((0, 1),)])
|
||||
def test_swap_states_in_input_batch(device: str, batch_size: int, swap_list: list):
|
||||
"""
|
||||
Tests the logic for managing sampling metadata in the InputBatch.
|
||||
"""Tests the logic for managing sampling metadata in the InputBatch.
|
||||
|
||||
This test involves adding a set of requests to the InputBatch,
|
||||
followed by removing a subset of them. Afterward, the batch is compacted,
|
||||
|
||||
@@ -85,7 +85,8 @@ def test_v2_min_tokens_keeps_masking_when_other_candidates_remain():
|
||||
|
||||
def test_v2_min_tokens_mixed_batch_gates_restore_per_request():
|
||||
"""CHECK_ALL_MASKED_ROWS is a batch-wide constexpr, so a mixed batch must
|
||||
still consult the per-request flag."""
|
||||
still consult the per-request flag.
|
||||
"""
|
||||
out = _apply(_only_stop_token_left(2), structured=[True, False])
|
||||
|
||||
assert out[0, STOP_TOKEN] == 1.0
|
||||
|
||||
@@ -73,16 +73,15 @@ DEVICE_TYPE = current_platform.device_type
|
||||
def _restore_default_dtype():
|
||||
"""Several tests here set the process-wide default dtype to float16 and
|
||||
previously leaked it, corrupting later float-sensitive tests in the same
|
||||
pytest process (torch.randn silently produced fp16)."""
|
||||
pytest process (torch.randn silently produced fp16).
|
||||
"""
|
||||
old = torch.get_default_dtype()
|
||||
yield
|
||||
torch.set_default_dtype(old)
|
||||
|
||||
|
||||
def initialize_kv_cache(runner: GPUModelRunner):
|
||||
"""
|
||||
Only perform necessary steps in GPUModelRunner.initialize_kv_cache()
|
||||
"""
|
||||
"""Only perform necessary steps in GPUModelRunner.initialize_kv_cache()."""
|
||||
attn_spec = FullAttentionSpec(
|
||||
block_size=BLOCK_SIZE,
|
||||
num_kv_heads=runner.model_config.get_num_kv_heads(runner.parallel_config),
|
||||
@@ -1193,14 +1192,12 @@ def test_init_kv_cache_with_kv_sharing_valid(default_vllm_config):
|
||||
reason="Attention backend FLASHINFER is only supported on CUDA.",
|
||||
)
|
||||
def test_hybrid_attention_mamba_tensor_shapes():
|
||||
"""
|
||||
The GPU model runner creates different views into the
|
||||
"""The GPU model runner creates different views into the
|
||||
KVCacheTensors for the attention and mamba layers
|
||||
(via _allocate_kv_caches). This test verifies
|
||||
that the views are compatible: writing a mamba block
|
||||
will not corrupt an attention block and vice versa
|
||||
"""
|
||||
|
||||
set_random_seed(42)
|
||||
|
||||
update_environment_variables(
|
||||
@@ -1457,7 +1454,8 @@ def test_v2_runner_snapshots_late_interleave_adjustment(monkeypatch):
|
||||
|
||||
def test_hybrid_block_table_initialization():
|
||||
"""Test hybrid block table with different kernel and kvcache_manager block
|
||||
sizes."""
|
||||
sizes.
|
||||
"""
|
||||
from vllm.v1.worker.block_table import BlockTable
|
||||
|
||||
# Test configuration: kvcache_manager block size = 32,
|
||||
|
||||
@@ -62,7 +62,8 @@ def _gather(features, cached, *, num_scheduled, shift, num_computed=0):
|
||||
def test_draft_shift_uses_boundary_feature_when_cached():
|
||||
"""The drafter's +1 look-ahead reaches the feature at offset ==
|
||||
processed_end; when it is already cached it is used for the look-ahead
|
||||
position rather than ignored."""
|
||||
position rather than ignored.
|
||||
"""
|
||||
f0 = _feature("h0", offset=0, length=8)
|
||||
f1 = _feature("h1", offset=8, length=8) # starts exactly at processed_end
|
||||
mm_embeds, is_mm_embed = _gather([f0, f1], [f0, f1], num_scheduled=8, shift=1)
|
||||
@@ -75,7 +76,8 @@ def test_draft_shift_uses_boundary_feature_when_cached():
|
||||
|
||||
def test_draft_shift_tolerates_missing_boundary_feature():
|
||||
"""When the +1 look-ahead feature past the processed boundary is not yet
|
||||
encoded, fall back to the token embedding instead of raising."""
|
||||
encoded, fall back to the token embedding instead of raising.
|
||||
"""
|
||||
f0 = _feature("h0", offset=0, length=8)
|
||||
f1 = _feature("h1", offset=8, length=8) # boundary feature, not cached
|
||||
mm_embeds, is_mm_embed = _gather([f0, f1], [f0], num_scheduled=8, shift=1)
|
||||
@@ -87,7 +89,8 @@ def test_draft_shift_tolerates_missing_boundary_feature():
|
||||
|
||||
def test_draft_shift_raises_on_interior_miss():
|
||||
"""A miss for a feature within the processed range (not the look-ahead
|
||||
boundary) is a real invariant violation, even on the drafter path."""
|
||||
boundary) is a real invariant violation, even on the drafter path.
|
||||
"""
|
||||
f0 = _feature("h0", offset=0, length=8) # interior, within processed range
|
||||
with pytest.raises(RuntimeError, match="Encoder cache miss"):
|
||||
_gather([f0], [], num_scheduled=8, shift=1)
|
||||
|
||||
@@ -126,7 +126,6 @@ def test_initialize_kv_cache_does_not_dcp_shard_mamba_block_table(
|
||||
expected: int,
|
||||
):
|
||||
"""Mamba/GDN block-table rows index global positions, unlike DCP KV."""
|
||||
|
||||
max_model_len = 1_048_576
|
||||
attention_block_size = 1_536
|
||||
mamba_block_size = 16
|
||||
@@ -220,7 +219,8 @@ def test_append_block_ids_rejects_write_past_row_capacity():
|
||||
|
||||
def _make_capture_runner(captured: bool) -> GPUModelRunner:
|
||||
"""Minimal V2 runner for capture_model: fakes everything except the
|
||||
cudagraph_manager's needs_capture decision."""
|
||||
cudagraph_manager's needs_capture decision.
|
||||
"""
|
||||
runner = GPUModelRunner.__new__(GPUModelRunner)
|
||||
runner.model_state = SimpleNamespace(supports_mm_inputs=False)
|
||||
runner.cudagraph_manager = SimpleNamespace(
|
||||
@@ -246,7 +246,8 @@ def _make_capture_runner(captured: bool) -> GPUModelRunner:
|
||||
def test_capture_model_locks_workspace_after_capture(monkeypatch):
|
||||
"""A workspace resize after capture frees the buffer the captured graphs
|
||||
baked in, so capture_model must lock the workspace before returning
|
||||
(https://github.com/vllm-project/vllm/issues/55336)."""
|
||||
(https://github.com/vllm-project/vllm/issues/55336).
|
||||
"""
|
||||
runner = _make_capture_runner(captured=True)
|
||||
monkeypatch.setattr(
|
||||
model_runner_module, "freeze_gc_for_cudagraph_capture", contextlib.nullcontext
|
||||
@@ -267,7 +268,8 @@ def test_capture_model_locks_workspace_after_capture(monkeypatch):
|
||||
|
||||
def test_capture_model_skips_lock_when_nothing_captured(monkeypatch):
|
||||
"""With no graphs to capture (e.g. enforce_eager) there is nothing baked
|
||||
into the workspace, so the early return must not lock it."""
|
||||
into the workspace, so the early return must not lock it.
|
||||
"""
|
||||
runner = _make_capture_runner(captured=False)
|
||||
lock_calls = []
|
||||
monkeypatch.setattr(
|
||||
@@ -281,7 +283,8 @@ def test_capture_model_skips_lock_when_nothing_captured(monkeypatch):
|
||||
def test_capture_model_profile_only_skips_lock(monkeypatch):
|
||||
"""The memory-profiling capture pass runs before kernel warmup and the
|
||||
real capture; locking there would stop the warmup from growing the
|
||||
workspace to its scheduler-realistic size."""
|
||||
workspace to its scheduler-realistic size.
|
||||
"""
|
||||
runner = _make_capture_runner(captured=True)
|
||||
monkeypatch.setattr(
|
||||
model_runner_module, "freeze_gc_for_cudagraph_capture", contextlib.nullcontext
|
||||
|
||||
@@ -82,7 +82,8 @@ def _make_profiling_runner(
|
||||
|
||||
class _FakePlatform:
|
||||
"""Stands in for current_platform; the global graph pool is a class attr,
|
||||
matching vllm.platforms.Platform's lazy singleton."""
|
||||
matching vllm.platforms.Platform's lazy singleton.
|
||||
"""
|
||||
|
||||
_global_graph_pool: Any = GLOBAL_POOL
|
||||
|
||||
|
||||
@@ -24,9 +24,7 @@ from vllm.v1.worker.gpu_worker import Worker
|
||||
|
||||
|
||||
class ConcreteWorkerProfiler(WorkerProfiler):
|
||||
"""
|
||||
A basic implementation of a worker profiler for testing purposes.
|
||||
"""
|
||||
"""A basic implementation of a worker profiler for testing purposes."""
|
||||
|
||||
def __init__(self, profiler_config: ProfilerConfig):
|
||||
self.start_call_count = 0
|
||||
@@ -122,7 +120,8 @@ def test_max_iterations(default_profiler_config):
|
||||
def test_restart_after_max_iterations(default_profiler_config):
|
||||
"""A start_profile after an auto-stop must actually restart, not be
|
||||
silently ignored (regression test: auto-stop used to leave _active
|
||||
True forever, so start() always bailed out early)."""
|
||||
True forever, so start() always bailed out early).
|
||||
"""
|
||||
default_profiler_config.max_iterations = 2
|
||||
profiler = ConcreteWorkerProfiler(default_profiler_config)
|
||||
|
||||
@@ -333,7 +332,8 @@ class TestAnnotateProfile:
|
||||
|
||||
def test_profiler_entered_during_capture():
|
||||
"""Profiler is used as a context manager in _warmup_and_capture,
|
||||
confirming it is active during the actual graph capture run."""
|
||||
confirming it is active during the actual graph capture run.
|
||||
"""
|
||||
runner = MagicMock()
|
||||
runner.compilation_config.cudagraph_num_of_warmups = 0
|
||||
mock_profiler = MagicMock()
|
||||
|
||||
@@ -34,7 +34,8 @@ def _run(
|
||||
) -> tuple[torch.Tensor, torch.Tensor]:
|
||||
"""Run rejection_sample on a batch of uniform k=2 requests, with the
|
||||
request under test at request index `roi_req` and draft-logits row
|
||||
`req_state_idx`. Returns that request's (sampled, num_sampled)."""
|
||||
`req_state_idx`. Returns that request's (sampled, num_sampled).
|
||||
"""
|
||||
num_logits = num_reqs * LOGITS_PER_REQ
|
||||
roi_row = roi_req * LOGITS_PER_REQ
|
||||
|
||||
|
||||
@@ -288,7 +288,8 @@ def test_v2_thinking_budget_clamps_oversized_budget():
|
||||
|
||||
def test_v2_thinking_budget_continues_end_prefix_from_prompt():
|
||||
"""A resumed prompt ending with a partial forced-end marker must not
|
||||
restart the marker sequence and duplicate its first token."""
|
||||
restart the marker sequence and duplicate its first token.
|
||||
"""
|
||||
req_states = _make_req_states([1, START, 10, 11, END_A], prompt_len=5)
|
||||
state = ThinkingBudgetState(req_states, MockMultiTokenEndReasoningConfig())
|
||||
state.add_request(3, SamplingParams(thinking_token_budget=3))
|
||||
|
||||
@@ -701,7 +701,8 @@ def test_microbatches_recompute_dcp_lens_from_truncated_seq_lens(dcp_rank: int):
|
||||
@pytest.mark.skipif(not torch.cuda.is_available(), reason="triton kernel needs CUDA")
|
||||
def test_each_microbatch_owns_its_dcp_buffer():
|
||||
"""Microbatch DCP lengths live in per-microbatch persistent buffers so
|
||||
CPU-visible shapes stay valid under CUDA graph capture and replay."""
|
||||
CPU-visible shapes stay valid under CUDA graph capture and replay.
|
||||
"""
|
||||
input_batch, _ = _make_cuda_input_batch([4, 4, 4, 4], [8, 9, 10, 11])
|
||||
|
||||
ubatches, dcp_buffers = _slice_with_dcp(input_batch, dcp_rank=0)
|
||||
|
||||
@@ -49,7 +49,8 @@ def plan_env(monkeypatch: pytest.MonkeyPatch, tmp_path):
|
||||
|
||||
def test_startup_plan_fingerprint_sensitivity(plan_env):
|
||||
"""The fingerprint is the OOM-safety key: stable for identical inputs,
|
||||
different for anything the profiled value depends on."""
|
||||
different for anything the profiled value depends on.
|
||||
"""
|
||||
fp = startup_plan.compute_plan_fingerprint
|
||||
base = fp(_plan_worker().vllm_config, 0, 1)
|
||||
assert base == fp(_plan_worker().vllm_config, 0, 1)
|
||||
@@ -97,7 +98,8 @@ def _snapshot(free_memory, torch_memory=0):
|
||||
|
||||
def _profile_result(consumed, reserved_before=0, reserved_after=0):
|
||||
"""A result whose free-memory readings agree with `consumed`, which
|
||||
`memory_profiling` derives as the drop in free memory, negative when it grew."""
|
||||
`memory_profiling` derives as the drop in free memory, negative when it grew.
|
||||
"""
|
||||
return SimpleNamespace(
|
||||
total_consumed=consumed,
|
||||
transient_peak_headroom=0,
|
||||
@@ -125,7 +127,8 @@ def test_profiling_fallback_declines_when_free_memory_dropped(rocm):
|
||||
@pytest.mark.parametrize("rocm", [True], indirect=True)
|
||||
def test_profiling_fallback_replaces_a_released_measurement(rocm):
|
||||
"""A negative measurement describes the rest of the device, so it is replaced
|
||||
by this process's reservation, which the rest of the device cannot move."""
|
||||
by this process's reservation, which the rest of the device cannot move.
|
||||
"""
|
||||
result = _profile_result(
|
||||
consumed=-RELEASED_BY_OTHERS,
|
||||
reserved_after=TORCH_RESERVED,
|
||||
@@ -149,7 +152,8 @@ def test_profiling_fallback_never_returns_a_negative_amount(rocm):
|
||||
@pytest.mark.parametrize("rocm", [False], indirect=True)
|
||||
def test_profiling_fallback_declines_off_rocm(rocm):
|
||||
"""Platforms that account frees eagerly keep reporting the error, so the
|
||||
caller's assertion stays reachable there."""
|
||||
caller's assertion stays reachable there.
|
||||
"""
|
||||
result = _profile_result(consumed=-RELEASED_BY_OTHERS)
|
||||
|
||||
assert maybe_rocm_profiling_fallback(result) is None
|
||||
@@ -173,7 +177,8 @@ def test_execute_model_waits_previous_pp_send_before_forward(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
):
|
||||
"""Previous device handles are waited before the forward pass; the
|
||||
metadata handle is left to the GroupCoordinator's reaper."""
|
||||
metadata handle is left to the GroupCoordinator's reaper.
|
||||
"""
|
||||
import torch
|
||||
|
||||
from vllm.sequence import IntermediateTensors
|
||||
|
||||
@@ -358,7 +358,8 @@ def test_warmup_respects_available_block_count():
|
||||
def test_zeroes_exactly_one_block_per_layer(layout: KVCacheLayout):
|
||||
"""The zeroer must zero every byte of the target block in every layer and nothing
|
||||
outside it — per head-group region under LHBNC, and never past the target block's
|
||||
tile under block-major layouts (no out-of-bounds writes, no clobbering)."""
|
||||
tile under block-major layouts (no out-of-bounds writes, no clobbering).
|
||||
"""
|
||||
device = torch.device("cuda")
|
||||
num_blocks, num_layers = 4, 2
|
||||
spec = FullAttentionSpec(
|
||||
|
||||
@@ -645,7 +645,8 @@ def test_mamba_groups_support_mixed_specs_in_uniform_group():
|
||||
|
||||
def _make_staging_ctx(max_num_reqs: int, device: torch.device) -> MagicMock:
|
||||
"""Build a MambaSpecDecodeGPUContext stand-in exposing only the four
|
||||
per-request staging buffers touched by stage_postprocess_inputs_to_gpu."""
|
||||
per-request staging buffers touched by stage_postprocess_inputs_to_gpu.
|
||||
"""
|
||||
ctx = MagicMock()
|
||||
ctx.mamba_state_idx_buf = _MockCpuGpuBuffer(max_num_reqs, torch.int32, device)
|
||||
ctx.num_scheduled_tokens_buf = _MockCpuGpuBuffer(max_num_reqs, torch.int32, device)
|
||||
@@ -657,7 +658,8 @@ def _make_staging_ctx(max_num_reqs: int, device: torch.device) -> MagicMock:
|
||||
def test_stage_postprocess_inputs_to_gpu_fills_pinned_views():
|
||||
"""stage_postprocess_inputs_to_gpu writes each request's state_idx and
|
||||
scheduled/computed/draft counts into slot `i` for `req_ids[i]`, leaves
|
||||
slots past `num_reqs` untouched, and mirrors the values to the GPU buffers."""
|
||||
slots past `num_reqs` untouched, and mirrors the values to the GPU buffers.
|
||||
"""
|
||||
device = torch.device("cpu")
|
||||
max_num_reqs = 8
|
||||
ctx = _make_staging_ctx(max_num_reqs, device)
|
||||
@@ -729,7 +731,8 @@ def test_stage_postprocess_inputs_to_gpu_fills_pinned_views():
|
||||
|
||||
def test_stage_postprocess_inputs_to_gpu_asserts_on_missing_state_idx():
|
||||
"""If preprocess_mamba didn't populate mamba_state_idx for a req in the
|
||||
batch, staging must fail loudly rather than silently writing a stale index."""
|
||||
batch, staging must fail loudly rather than silently writing a stale index.
|
||||
"""
|
||||
device = torch.device("cpu")
|
||||
ctx = _make_staging_ctx(max_num_reqs=4, device=device)
|
||||
scheduler_output = _make_postprocess_scheduler_output(
|
||||
@@ -807,7 +810,8 @@ def _run_gpu_postprocess(
|
||||
device: torch.device,
|
||||
) -> None:
|
||||
"""Initialize the GPU context against `block_table`, run the fused
|
||||
postprocess kernel for `req_ids`, and synchronize."""
|
||||
postprocess kernel for `req_ids`, and synchronize.
|
||||
"""
|
||||
|
||||
def t(values):
|
||||
return torch.tensor(values, dtype=torch.int32, device=device)
|
||||
@@ -867,8 +871,7 @@ class TestPostprocessMambaFusedKernel:
|
||||
torch.testing.assert_close(state, expected, rtol=0, atol=0)
|
||||
|
||||
def test_matches_python_postprocess_mamba(self, device, test_config):
|
||||
"""
|
||||
Golden test: GPU kernel produces identical results to Python impl.
|
||||
"""Golden test: GPU kernel produces identical results to Python impl.
|
||||
|
||||
This test:
|
||||
1. Sets up identical initial state for both paths
|
||||
@@ -1146,8 +1149,7 @@ class TestPostprocessMambaFusedKernel:
|
||||
)
|
||||
|
||||
def test_block_table_with_realistic_stride(self, device, test_config):
|
||||
"""
|
||||
Test kernel with realistic block table strides.
|
||||
"""Test kernel with realistic block table strides.
|
||||
|
||||
In real usage, the block table is pre-allocated with shape
|
||||
[max_num_reqs, max_num_blocks_per_req] and then sliced to
|
||||
@@ -1275,8 +1277,7 @@ class TestPostprocessMambaFusedKernel:
|
||||
def test_src_addr_equals_dst_addr_skips_copy_and_sets_accepted_to_1(
|
||||
self, device, test_config
|
||||
):
|
||||
"""
|
||||
Test the ``src_addr == dst_addr`` early-return path in
|
||||
"""Test the ``src_addr == dst_addr`` early-return path in
|
||||
postprocess_mamba_fused_kernel matches Python behavior.
|
||||
|
||||
When src_addr == dst_addr (source and destination memory addresses are
|
||||
@@ -1419,8 +1420,7 @@ class TestPostprocessMambaFusedKernel:
|
||||
def test_same_block_idx_with_offset_copies_then_sets_accepted_to_1(
|
||||
self, device, test_config
|
||||
):
|
||||
"""
|
||||
Test the ``src_block_idx == dest_block_idx`` post-copy update in
|
||||
"""Test the ``src_block_idx == dest_block_idx`` post-copy update in
|
||||
postprocess_mamba_fused_kernel matches Python behavior.
|
||||
|
||||
When src_block_idx == dest_block_idx but accept_token_bias > 0, both
|
||||
@@ -1583,8 +1583,7 @@ class TestPostprocessMambaFusedKernel:
|
||||
def test_different_block_idx_copies_without_setting_accepted_to_1(
|
||||
self, device, test_config
|
||||
):
|
||||
"""
|
||||
Test that neither special-case path triggers when
|
||||
"""Test that neither special-case path triggers when
|
||||
src_block_idx != dest_block_idx, and GPU matches Python behavior.
|
||||
|
||||
When copying between different blocks:
|
||||
@@ -1716,8 +1715,7 @@ class TestPostprocessMambaFusedKernel:
|
||||
def test_prefix_caching_shared_block_does_not_set_accepted_to_1(
|
||||
self, device, test_config
|
||||
):
|
||||
"""
|
||||
Regression test: with prefix caching, different logical block indices
|
||||
"""Regression test: with prefix caching, different logical block indices
|
||||
can map to the same physical block. The kernel must NOT set
|
||||
num_accepted_tokens to 1 in that case.
|
||||
|
||||
@@ -1849,8 +1847,7 @@ class TestPostprocessMambaFusedKernel:
|
||||
)
|
||||
|
||||
def test_prefix_caching_nonsequential_block_ids_boundary(self, device, test_config):
|
||||
"""
|
||||
Regression test: non-sequential physical block IDs under prefix caching
|
||||
"""Regression test: non-sequential physical block IDs under prefix caching
|
||||
with the needs_copy boundary at exact equality.
|
||||
|
||||
Under PC, the block allocator assigns physical block IDs in arbitrary
|
||||
@@ -2000,8 +1997,7 @@ class TestPostprocessMambaFusedKernel:
|
||||
assert input_batch_py.num_accepted_tokens_cpu[1] == num_accepted_tokens[1]
|
||||
|
||||
def test_prefix_caching_mixed_shared_and_distinct_blocks(self, device, test_config):
|
||||
"""
|
||||
Regression test: mixed batch under prefix caching where some requests
|
||||
"""Regression test: mixed batch under prefix caching where some requests
|
||||
have shared physical blocks (aliased) and others have distinct blocks,
|
||||
with the needs_copy boundary at various positions.
|
||||
|
||||
@@ -2166,8 +2162,7 @@ class TestPostprocessMambaFusedKernel:
|
||||
def test_pc_aliased_blocks_skip_must_use_logical_idx_not_addr(
|
||||
self, device, test_config
|
||||
):
|
||||
"""
|
||||
Regression test for 6466ce0d vs 959ca0fd: the kernel's early-return
|
||||
"""Regression test for 6466ce0d vs 959ca0fd: the kernel's early-return
|
||||
guard must compare logical block indices, not physical addresses.
|
||||
|
||||
Under prefix caching, different logical blocks (src_block_idx=0,
|
||||
@@ -2299,8 +2294,7 @@ class TestPostprocessMambaFusedKernel:
|
||||
)
|
||||
|
||||
def test_as_strided_temporal_copy_size(self, device, test_config):
|
||||
"""
|
||||
Regression test for 240723d46: temporal copy_size must be
|
||||
"""Regression test for 240723d46: temporal copy_size must be
|
||||
inner_size * elem_size, not state_block_stride.
|
||||
|
||||
In production (gpu_model_runner.py), conv and temporal states share
|
||||
@@ -2458,8 +2452,7 @@ class TestPostprocessMambaFusedKernel:
|
||||
)
|
||||
|
||||
def test_temporal_copy_with_bias_ge_2(self, device, test_config):
|
||||
"""
|
||||
Coverage test for the temporal-state block-table stride arithmetic
|
||||
"""Coverage test for the temporal-state block-table stride arithmetic
|
||||
when ``accept_token_bias >= 2``.
|
||||
|
||||
The kernel computes, for temporal (non-conv) states::
|
||||
|
||||
@@ -17,7 +17,8 @@ def _fail(*args, **kwargs):
|
||||
@pytest.mark.parametrize("max_num_reqs", [1, 0])
|
||||
def test_mixed_warmup_skipped_for_single_seq(max_num_reqs):
|
||||
"""A mixed prefill+decode step needs >=2 requests; with max_num_reqs < 2
|
||||
the warmup must be skipped without touching the worker callbacks."""
|
||||
the warmup must be skipped without touching the worker callbacks.
|
||||
"""
|
||||
runner = SimpleNamespace(is_pooling_model=False, max_num_reqs=max_num_reqs)
|
||||
|
||||
assert (
|
||||
|
||||
@@ -78,7 +78,8 @@ def _apply(
|
||||
def test_overlay_chunked_prefill_and_decode():
|
||||
"""Rows within the embeds range come from prompt_embeds at the
|
||||
num_computed offset; requests without embeds and requests past their
|
||||
embeds length (decode) keep the base embedding."""
|
||||
embeds length (decode) keep the base embedding.
|
||||
"""
|
||||
state = _make_state()
|
||||
embeds_a = torch.randn(6, HIDDEN, dtype=torch.float32)
|
||||
embeds_b = torch.randn(5, HIDDEN, dtype=torch.float32)
|
||||
@@ -97,7 +98,8 @@ def test_overlay_chunked_prefill_and_decode():
|
||||
|
||||
def test_overlay_clamps_to_embeds_length():
|
||||
"""A window straddling the end of the prompt embeds writes only the
|
||||
in-range rows (e.g. final prefill chunk + sampled token)."""
|
||||
in-range rows (e.g. final prefill chunk + sampled token).
|
||||
"""
|
||||
state = _make_state()
|
||||
embeds = torch.randn(4, HIDDEN, dtype=torch.float32)
|
||||
state.add_request(3, _NewReqData("a", embeds))
|
||||
@@ -112,7 +114,8 @@ def test_overlay_clamps_to_embeds_length():
|
||||
|
||||
def test_overlay_respects_is_token_ids_mask():
|
||||
"""Mixed mode: positions marked as real token ids keep the base
|
||||
embedding; only embed positions are overwritten."""
|
||||
embedding; only embed positions are overwritten.
|
||||
"""
|
||||
state = _make_state()
|
||||
embeds = torch.randn(5, HIDDEN, dtype=torch.float32)
|
||||
is_token_ids = [True, False, False, True, False]
|
||||
@@ -130,7 +133,8 @@ def test_overlay_respects_is_token_ids_mask():
|
||||
|
||||
def test_index_reuse_clears_stale_entry():
|
||||
"""A request added at a previously-used index without embeds must not
|
||||
inherit the prior occupant's pointer-table entry."""
|
||||
inherit the prior occupant's pointer-table entry.
|
||||
"""
|
||||
state = _make_state()
|
||||
state.add_request(0, _NewReqData("a", torch.randn(4, HIDDEN, dtype=torch.float32)))
|
||||
# A second live embeds request so the kernel actually launches (the
|
||||
|
||||
@@ -35,6 +35,7 @@ def make_operation_tracker(operation_name: str, original_func):
|
||||
|
||||
Returns:
|
||||
A wrapper function that tracks the operation and calls the original
|
||||
|
||||
"""
|
||||
|
||||
def wrapper(*args, **kwargs):
|
||||
|
||||
@@ -84,7 +84,8 @@ def test_workspace_lanes_compose_with_ubatches(monkeypatch) -> None:
|
||||
|
||||
def test_workspace_lock_blocks_growth_and_unlock_restores(monkeypatch) -> None:
|
||||
"""Once locked, oversized requests fail loudly instead of reallocating the
|
||||
buffer that captured CUDA graphs point at; unlock restores growth."""
|
||||
buffer that captured CUDA graphs point at; unlock restores growth.
|
||||
"""
|
||||
monkeypatch.setattr(workspace, "dbo_current_ubatch_id", lambda: 0)
|
||||
manager = workspace.WorkspaceManager(torch.device("cpu"), num_lanes=1)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user