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
"""
EPD Correctness Test
"""EPD Correctness Test.
Tests that EPD (Encoder-Prefill-Decode) disaggregation produces the same
outputs as a baseline single instance.
@@ -104,6 +103,7 @@ def check_vllm_server(url: str, timeout=5, retries=10) -> bool:
Returns:
True if the server is ready, False otherwise
"""
for attempt in range(retries):
try:
@@ -138,6 +138,7 @@ def run_chat_completion(
Returns:
Generated text content
"""
with openai.OpenAI(
api_key="EMPTY", base_url=base_url, timeout=120, max_retries=0
@@ -381,7 +381,8 @@ def test_pin_if_ready_none_when_absent():
def test_pin_if_ready_returns_unpinned_entry_when_not_ready():
"""The producer needs "present but not ready" told apart from "absent":
the first is NACKed as retryable, the second as a miss."""
the first is NACKed as retryable, the second as a miss.
"""
cache = EmbeddingCache(num_blocks=4)
cache.alloc("h", 1) # not-ready
entry = cache.pin_if_ready("h")
@@ -131,7 +131,8 @@ def test_has_cache_item_false_when_not_consumer(monkeypatch):
def test_connector_keys_on_identifier_not_mm_hash(monkeypatch):
"""The connector must key the encoder cache on feature.identifier (what
has_cache_item is called with), NOT feature.mm_hash."""
has_cache_item is called with), NOT feature.mm_hash.
"""
s = _make_scheduler(monkeypatch)
req = _Request([_Feature("PROC_KEY", length=1, identifier="ENC_KEY")])
s.update_state_after_alloc(req, 0)
@@ -201,7 +202,8 @@ def test_loads_only_serves_hashes_touched_this_step(monkeypatch):
def test_repeated_reload_same_step_loads_once(monkeypatch):
"""The same mm_hash requested twice in one step must appear in
meta.loads exactly once."""
meta.loads exactly once.
"""
s = _make_scheduler(monkeypatch)
_seed_cached(s, "a", n_blocks=2)
@@ -224,7 +226,8 @@ def test_load_not_emitted_for_uncached_entry(monkeypatch):
def test_load_pin_protects_blocks_until_completion(monkeypatch):
"""Loaded blocks stay pinned until the worker reports the load memcpy
complete. Observable: a save that needs eviction cannot reclaim a
still-pinned loaded entry, but can once the completion report arrives."""
still-pinned loaded entry, but can once the completion report arrives.
"""
# 2 blocks, both occupied by "a" (ready).
s = _make_scheduler(monkeypatch, num_blocks=2)
_seed_cached(s, "a", n_blocks=2)
@@ -251,7 +254,8 @@ def test_load_pin_protects_blocks_until_completion(monkeypatch):
def _can_evict(s: ECCPUScheduler, mm_hash: str, n_blocks: int) -> bool:
"""Whether a new save of `mm_hash` can claim `n_blocks`, i.e. whether the
blocks currently held by other entries are reclaimable."""
blocks currently held by other entries are reclaimable.
"""
s.update_state_after_alloc(_Request([_Feature(mm_hash, length=n_blocks)]), 0)
meta = s.build_connector_meta(scheduler_output=None)
return mm_hash in meta.saves
@@ -311,7 +315,8 @@ def test_late_report_does_not_release_a_later_load_of_same_hash(monkeypatch):
def test_region_full_skips_save_and_never_blocks(monkeypatch):
"""When the region is fully occupied by pinned entries, new saves are
silently skipped and ensure_cache_available never blocks."""
silently skipped and ensure_cache_available never blocks.
"""
s = _make_scheduler(monkeypatch, num_blocks=1)
_seed_cached(s, "pinned", n_blocks=1)
s._cache.pin("pinned")
@@ -330,7 +335,8 @@ def test_region_full_skips_save_and_never_blocks(monkeypatch):
def test_producer_only_never_emits_loads(monkeypatch):
"""A producer-only scheduler must never populate meta.loads, even when
entries are ready."""
entries are ready.
"""
s = _make_scheduler(monkeypatch, ec_role="ec_producer")
req = _Request([_Feature("h1", length=1)])
@@ -372,7 +378,8 @@ def test_consumer_only_has_cache_item(monkeypatch):
def test_save_not_emitted_for_already_cached_entry(monkeypatch):
"""An entry already in the cache (from a prior save) must not trigger
a second allocation or appear in meta.saves again."""
a second allocation or appear in meta.saves again.
"""
s = _make_scheduler(monkeypatch)
req = _Request([_Feature("h1", length=1)])
@@ -393,7 +400,8 @@ def test_save_not_emitted_for_already_cached_entry(monkeypatch):
def test_update_connector_output_ignores_foreign_meta(monkeypatch):
"""A worker output whose payload is not an ECCPUWorkerMetadata is a
no-op — no cache mutation, no crash."""
no-op — no cache mutation, no crash.
"""
s = _make_scheduler(monkeypatch)
_seed_cached(s, "a", n_blocks=1)
@@ -407,7 +415,8 @@ def test_update_connector_output_ignores_foreign_meta(monkeypatch):
def test_update_connector_output_ignores_unknown_report(monkeypatch):
"""Reports for a never-seen save hash or a transfer id this scheduler never
dispatched are dropped rather than mutating unrelated state."""
dispatched are dropped rather than mutating unrelated state.
"""
s = _make_scheduler(monkeypatch)
s.update_connector_output(_WorkerOutput(saves=["gone"], loads=[4242]))
assert s.has_cache_item("gone") is False
@@ -419,7 +428,8 @@ def test_update_connector_output_ignores_unknown_report(monkeypatch):
def test_has_pending_push_work_tracks_inflight_save(monkeypatch):
"""A dispatched-but-unconfirmed save keeps push work pending until the
completion report marks it ready."""
completion report marks it ready.
"""
s = _make_scheduler(monkeypatch)
assert s.has_pending_push_work() is False
@@ -434,7 +444,8 @@ def test_has_pending_push_work_tracks_inflight_save(monkeypatch):
def test_has_pending_push_work_tracks_inflight_load(monkeypatch):
"""A dispatched-but-unconfirmed load keeps push work pending until the
unpin completion report arrives."""
unpin completion report arrives.
"""
s = _make_scheduler(monkeypatch)
_seed_cached(s, "a", n_blocks=1)
assert s.has_pending_push_work() is False # ready + unpinned
@@ -453,7 +464,8 @@ def test_has_pending_push_work_tracks_inflight_load(monkeypatch):
def test_shutdown_disables_roles_and_cleans_region(monkeypatch):
"""After shutdown the scheduler serves no items and the region is
cleaned up."""
cleaned up.
"""
s = _make_scheduler(monkeypatch, num_blocks=2)
_seed_cached(s, "a", n_blocks=2)
assert s.has_cache_item("a") is True
@@ -98,7 +98,8 @@ def test_second_instance_opens_existing_file_and_shares_memory():
def test_only_creator_unlinks_file_on_cleanup():
"""Critical contract: if the non-creator unlinks, the creator's mmap path
becomes a dangling backing file and a third opener would create a new one
out from under the creator."""
out from under the creator.
"""
instance_id = str(uuid.uuid4())
r1 = ECSharedRegion(
engine_id=instance_id,
@@ -215,7 +216,8 @@ def test_madvise_einval_selects_fallback_for_whole_region(monkeypatch):
def test_non_creator_does_not_probe_or_populate(monkeypatch):
"""Only the creator pre-faults. A second opener must not probe the advice
nor re-touch pages the creator already populated."""
nor re-touch pages the creator already populated.
"""
from vllm.distributed.ec_transfer.ec_connector.cpu import ec_shared_region as esr
instance_id = str(uuid.uuid4())
@@ -312,7 +314,8 @@ def test_madvise_unexpected_oserror_propagates(monkeypatch):
def test_pin_memory_success_sets_flag(region):
"""When cudaHostRegister returns 0, _is_pinned flips to True
and cleanup will correspondingly call cudaHostUnregister."""
and cleanup will correspondingly call cudaHostUnregister.
"""
fake_cudart = MagicMock()
success = MagicMock()
success.value = 0
@@ -332,7 +335,8 @@ def test_pin_memory_success_sets_flag(region):
def test_pin_memory_failure_leaves_flag_false():
"""If cudaHostRegister fails (non-zero), don't pretend it succeeded —
cleanup must NOT call cudaHostUnregister on memory we never registered."""
cleanup must NOT call cudaHostUnregister on memory we never registered.
"""
r = _make_region()
try:
fake_cudart = MagicMock()
@@ -363,7 +363,8 @@ def test_save_caches_coalesces_only_adjacent_blocks(
def test_save_caches_noop_when_mm_hash_not_in_saves(make_worker):
"""When the scheduler hasn't pre-allocated blocks for ``mm_hash``,
``save_caches`` + ``flush_saves`` is a pure no-op."""
``save_caches`` + ``flush_saves`` is a pure no-op.
"""
worker = make_worker()
sentinel = 0x42
worker._region.blocks.fill_(sentinel)
@@ -381,7 +382,8 @@ def test_save_caches_noop_when_mm_hash_not_in_saves(make_worker):
)
def test_save_caches_noop_for_non_save_rank(make_worker, tp_rank, pcp_rank):
"""Only TP rank 0 + PCP rank 0 writes to mmap. All other combinations
must skip the save entirely."""
must skip the save entirely.
"""
worker = make_worker(tp_rank=tp_rank, pcp_rank=pcp_rank)
sentinel = 0x42
worker._region.blocks.fill_(sentinel)
@@ -396,7 +398,8 @@ def test_save_caches_noop_for_non_save_rank(make_worker, tp_rank, pcp_rank):
def test_save_caches_raises_when_allocated_blocks_too_small(make_worker):
"""``save_caches`` must raise ``AssertionError`` when the encoder output
is larger than the allocated block space."""
is larger than the allocated block space.
"""
worker = make_worker()
src = torch.zeros(3 * _HIDDEN_DIM, dtype=_DTYPE)
with pytest.raises(AssertionError, match="exceeds allocated blocks"):
@@ -549,7 +552,8 @@ def test_start_load_caches_noop_when_loads_is_empty(make_worker):
def test_start_load_caches_skips_cached_and_loads_new_in_same_step(make_worker):
"""Every hash in ``meta.loads`` is copied from mmap, including one whose
key is already resident in ``encoder_cache`` — there is no worker-side
skip."""
skip.
"""
worker = make_worker()
n_blocks = 3
src_orig = torch.arange(n_blocks * _HIDDEN_DIM, dtype=_DTYPE).reshape(
@@ -778,7 +782,8 @@ def test_buffer_pool_is_reused_across_save_steps(make_worker):
@_requires_accelerator
def test_buffer_pool_is_reused_across_load_steps(make_worker):
"""Once a load copy completes its descriptor buffers return to the pool and
are reused by the next call — no reallocation."""
are reused by the next call — no reallocation.
"""
worker = make_worker()
worker._region.blocks[0].fill_(0x01)
worker._region.blocks[1].fill_(0x02)
@@ -849,7 +854,8 @@ def test_init_pins_memory_when_available(pin_available, expected_pinned):
def test_shutdown_calls_region_cleanup_and_swallows_errors(caplog_vllm):
"""``shutdown`` must always call ``region.cleanup`` — and must never
raise."""
raise.
"""
worker = object.__new__(ECCPUWorker)
mock_region = Mock(spec=ECSharedRegion)
worker._region = mock_region
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""
E2E test for the ECCPUConnector.
"""E2E test for the ECCPUConnector.
Verifies:
- Accuracy: outputs from EC CPU cache match fresh encoder computation.
@@ -1,8 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""
Unit tests for ECExampleConnector.
"""
"""Unit tests for ECExampleConnector."""
import os
from unittest.mock import Mock, patch
@@ -43,7 +43,8 @@ def assign(proxy):
def _drive(assign, e_urls, counts):
"""Feed a sequence of request item-counts through the cursor, as
fanout_encoder_primer does one request at a time."""
fanout_encoder_primer does one request at a time.
"""
cursor = 0
all_urls = []
for count in counts:
+3 -2
View File
@@ -40,7 +40,8 @@ def test_metadata_saves_dict_operations():
def test_metadata_loads_carry_a_transfer_id_and_blocks():
"""Each load entry is a (transfer_id, block_ids) pair, so the worker can
report the transfer rather than the mm_hash."""
report the transfer rather than the mm_hash.
"""
meta = ECCPUConnectorMetadata()
meta.loads["mm_hash_1"] = (0, [5, 6, 7])
@@ -54,7 +55,7 @@ def test_metadata_loads_carry_a_transfer_id_and_blocks():
def test_metadata_saves_and_loads_are_independent():
"""saves and loads dicts are independent."""
"""Saves and loads dicts are independent."""
meta = ECCPUConnectorMetadata()
meta.saves["key"] = [1, 2]
@@ -79,7 +79,8 @@ def test_request_finished_announces_not_ready_entry(monkeypatch):
"""A save whose GPU->mmap copy hasn't been confirmed complete yet is
still announced: the entry can't be evicted before it's ready, and a read
arriving too early is NACKed NACK_NOT_READY for the consumer to retry —
protecting it is not this method's job."""
protecting it is not this method's job.
"""
s = _sched_gate_off(monkeypatch)
s._nixl_enabled = True
s._peer_host, s._peer_port = "1.2.3.4", 5601
+4 -3
View File
@@ -129,7 +129,8 @@ def test_producer_session_grant_nacks_missing_entry():
def test_producer_session_grant_nacks_not_ready_entry_as_retryable():
"""An announced entry whose save is still in flight is distinguished from a
miss, so the consumer retries instead of falling back to local compute."""
miss, so the consumer retries instead of falling back to local compute.
"""
cache = EmbeddingCache(num_blocks=8)
cache.alloc("h1", 2) # not ready
s = _make_producer_session(cache)
@@ -329,7 +330,6 @@ def test_consumer_xfer_quarantined_exception_settles():
def test_consumer_xfer_quarantined_timeout_evicts_blocks():
"""Quarantine timeout should release handle and return READ_FAILED."""
data = _make_data(xfer_state="PROC")
x = _started(data)
# First poll transitions to QUARANTINED (deadline extended by 60s)
@@ -438,7 +438,8 @@ def test_consumer_session_poll_nack_goes_to_tombstoned():
def test_consumer_session_poll_not_ready_nack_goes_to_retryable():
"""A not-ready NACK must not tombstone: tombstoning admits the request with
no embedding, which is fatal once the media has been rewritten away."""
no embedding, which is fatal once the media has been rewritten away.
"""
import msgspec
s = _make_consumer_session()
+1
View File
@@ -45,6 +45,7 @@ def create_ec_vllm_config(
Returns:
A `VllmConfig`-specced mock carrying the configs above.
"""
parallel_config = ParallelConfig(
tensor_parallel_size=tensor_parallel_size,