[EC Connector] P2P NIXL + CPU EC Connector (#47941)
Signed-off-by: omerpaz95 <omerpaz95@gmail.com> Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
69cf055936
commit
8a0a7ee40a
@@ -333,3 +333,57 @@ def test_concurrent_alloc_evict():
|
||||
t.join()
|
||||
|
||||
assert not errors, errors
|
||||
|
||||
|
||||
# ── discard ──────────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
def test_discard_not_ready_returns_blocks():
|
||||
cache = EmbeddingCache(num_blocks=4)
|
||||
entry = cache.alloc("h", 3)
|
||||
assert entry is not None
|
||||
cache.discard("h")
|
||||
assert cache.get("h") is None
|
||||
# All blocks reclaimed: a fresh 4-block alloc now fits.
|
||||
assert cache.alloc("h2", 4) is not None
|
||||
|
||||
|
||||
def test_discard_rejects_ready_entry():
|
||||
cache = EmbeddingCache(num_blocks=4)
|
||||
cache.alloc("h", 1)
|
||||
cache.mark_ready("h")
|
||||
with pytest.raises(AssertionError):
|
||||
cache.discard("h")
|
||||
|
||||
|
||||
def test_discard_rejects_absent_key():
|
||||
cache = EmbeddingCache(num_blocks=4)
|
||||
with pytest.raises(KeyError):
|
||||
cache.discard("nope")
|
||||
|
||||
|
||||
# ── pin_if_ready ─────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
def test_pin_if_ready_pins_and_returns_entry():
|
||||
cache = EmbeddingCache(num_blocks=4)
|
||||
cache.alloc("h", 2)
|
||||
cache.mark_ready("h")
|
||||
entry = cache.pin_if_ready("h")
|
||||
assert entry is not None and entry.ready and len(entry.block_ids) == 2
|
||||
assert cache.alloc("h2", 4) is None # pinned ⇒ not evictable
|
||||
|
||||
|
||||
def test_pin_if_ready_none_when_absent():
|
||||
cache = EmbeddingCache(num_blocks=4)
|
||||
assert cache.pin_if_ready("nope") is None
|
||||
|
||||
|
||||
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."""
|
||||
cache = EmbeddingCache(num_blocks=4)
|
||||
cache.alloc("h", 1) # not-ready
|
||||
entry = cache.pin_if_ready("h")
|
||||
assert entry is not None and not entry.ready
|
||||
assert cache.alloc("h2", 4) is None # not-ready ⇒ still not evictable
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
from vllm.distributed.ec_transfer.ec_connector.base import ECConnectorRole
|
||||
from vllm.distributed.ec_transfer.ec_connector.cpu.connector import ECCPUConnector
|
||||
from vllm.distributed.ec_transfer.ec_connector.factory import ECConnectorFactory
|
||||
@@ -34,14 +36,36 @@ def test_worker_role_builds_only_worker(monkeypatch):
|
||||
assert c.connector_scheduler is None
|
||||
|
||||
|
||||
def test_request_finished_inherited_noop(monkeypatch):
|
||||
@pytest.mark.parametrize("role", [ECConnectorRole.SCHEDULER, ECConnectorRole.WORKER])
|
||||
def test_v1_model_runner_is_rejected(monkeypatch, role):
|
||||
"""The V1 runner never reports save completions, so refuse to start."""
|
||||
monkeypatch.setattr(
|
||||
ECCPUConnector, "_make_scheduler", lambda self, cfg: MagicMock()
|
||||
)
|
||||
c = ECCPUConnector(_cfg(), ECConnectorRole.SCHEDULER)
|
||||
assert c.request_finished(MagicMock()) == (False, None)
|
||||
monkeypatch.setattr(ECCPUConnector, "_make_worker", lambda self, cfg: MagicMock())
|
||||
cfg = _cfg()
|
||||
cfg.use_v2_model_runner = False
|
||||
|
||||
with pytest.raises(ValueError, match="V2 model runner"):
|
||||
ECCPUConnector(cfg, role)
|
||||
|
||||
|
||||
def test_factory_registered():
|
||||
cls = ECConnectorFactory._registry["ECCPUConnector"]()
|
||||
assert cls is ECCPUConnector
|
||||
|
||||
|
||||
def test_request_finished_forwards_to_scheduler(monkeypatch):
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import vllm.distributed.ec_transfer.ec_connector.cpu.connector as conn_mod # noqa: F401
|
||||
from vllm.distributed.ec_transfer.ec_connector.base import ECConnectorRole
|
||||
from vllm.distributed.ec_transfer.ec_connector.cpu.connector import ECCPUConnector
|
||||
|
||||
fake_sched = MagicMock()
|
||||
fake_sched.request_finished.return_value = (False, {"h1": {"peer_port": 1}})
|
||||
monkeypatch.setattr(ECCPUConnector, "_make_scheduler", lambda self, cfg: fake_sched)
|
||||
c = ECCPUConnector(_cfg(), ECConnectorRole.SCHEDULER)
|
||||
req = MagicMock()
|
||||
assert c.request_finished(req) == (False, {"h1": {"peer_port": 1}})
|
||||
fake_sched.request_finished.assert_called_once_with(req)
|
||||
|
||||
@@ -64,6 +64,14 @@ _requires_cuda_alike = pytest.mark.skipif(
|
||||
reason="stalling the compute stream requires a CUDA-like platform",
|
||||
)
|
||||
|
||||
_requires_swap_blocks_batch = pytest.mark.skipif(
|
||||
not hasattr(torch.ops._C_cache_ops, "swap_blocks_batch"),
|
||||
reason=(
|
||||
"installed vllm C++ extension predates the swap_blocks_batch op "
|
||||
"flush_saves/start_load_caches use; rebuild the extension to run this"
|
||||
),
|
||||
)
|
||||
|
||||
# Cycles to stall the compute stream for. Must comfortably outlast the host-side
|
||||
# work the lifetime tests do while a copy is deliberately held back — ~0.5 s on
|
||||
# a current datacenter GPU.
|
||||
@@ -194,6 +202,7 @@ def _warm_up_stream_pools(worker: ECCPUWorker) -> None:
|
||||
# ── save_caches ──────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
@_requires_swap_blocks_batch
|
||||
@_requires_accelerator
|
||||
@pytest.mark.parametrize(
|
||||
"n_elements,block_ids",
|
||||
@@ -326,6 +335,7 @@ def test_save_caches_raises_when_allocated_blocks_too_small(make_worker):
|
||||
worker.save_caches({"h": src}, "h", _meta(saves={"h": [0, 1]}))
|
||||
|
||||
|
||||
@_requires_swap_blocks_batch
|
||||
@_requires_accelerator
|
||||
def test_save_caches_batches_multiple_hashes(make_worker):
|
||||
"""Multiple save_caches calls are batched into a single flush."""
|
||||
@@ -401,6 +411,7 @@ def test_save_descriptors_hold_high_bit_source_addresses(make_worker):
|
||||
# ── start_load_caches ────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
@_requires_swap_blocks_batch
|
||||
@_requires_accelerator
|
||||
def test_start_load_caches_copies_with_correct_shape_dtype_and_bytes(make_worker):
|
||||
"""Single batched load across all hashes with correct byte→dtype→shape."""
|
||||
@@ -465,6 +476,7 @@ def test_start_load_caches_noop_when_loads_is_empty(make_worker):
|
||||
assert encoder_cache == {}
|
||||
|
||||
|
||||
@_requires_swap_blocks_batch
|
||||
@_requires_accelerator
|
||||
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
|
||||
@@ -497,6 +509,7 @@ def test_start_load_caches_skips_cached_and_loads_new_in_same_step(make_worker):
|
||||
assert torch.equal(new.cpu(), src_orig[1:])
|
||||
|
||||
|
||||
@_requires_swap_blocks_batch
|
||||
@_requires_accelerator
|
||||
@pytest.mark.parametrize(
|
||||
"tp_rank,pcp_rank",
|
||||
@@ -526,6 +539,7 @@ def test_start_load_caches_works_on_all_ranks(make_worker, tp_rank, pcp_rank):
|
||||
# ── round-trip ───────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
@_requires_swap_blocks_batch
|
||||
@_requires_accelerator
|
||||
def test_save_then_load_round_trips_bytes(make_worker):
|
||||
"""Full producer→mmap→consumer byte path in one shot."""
|
||||
@@ -552,6 +566,7 @@ def test_save_then_load_round_trips_bytes(make_worker):
|
||||
# ── memory lifetime across in-flight copies ─────────────────────────────────
|
||||
|
||||
|
||||
@_requires_swap_blocks_batch
|
||||
@_requires_cuda_alike
|
||||
def test_save_survives_encoder_cache_free_before_copy_runs(make_worker):
|
||||
"""The bytes handed to ``save_caches`` must reach the mmap intact even when
|
||||
@@ -612,6 +627,7 @@ def test_save_survives_encoder_cache_free_before_copy_runs(make_worker):
|
||||
)
|
||||
|
||||
|
||||
@_requires_swap_blocks_batch
|
||||
@_requires_cuda_alike
|
||||
def test_load_buffer_survives_eviction_while_consumer_read_is_queued(make_worker):
|
||||
"""A loaded encoder cache entry must keep its bytes for a consumer already
|
||||
@@ -662,6 +678,7 @@ def test_load_buffer_survives_eviction_while_consumer_read_is_queued(make_worker
|
||||
# ── buffer recycling ────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
@_requires_swap_blocks_batch
|
||||
@_requires_accelerator
|
||||
def test_buffer_pool_is_reused_across_save_steps(make_worker):
|
||||
"""Once a save copy completes its descriptor buffers return to the pool and
|
||||
@@ -689,6 +706,7 @@ def test_buffer_pool_is_reused_across_save_steps(make_worker):
|
||||
assert id(worker._buf_pool._pool[0].src_ptrs) == buf_id
|
||||
|
||||
|
||||
@_requires_swap_blocks_batch
|
||||
@_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
|
||||
@@ -793,6 +811,7 @@ def test_shutdown_calls_region_cleanup_and_swallows_errors(caplog_vllm):
|
||||
# ── e2e: scheduler + worker pipeline ────────────────────────────────────────
|
||||
|
||||
|
||||
@_requires_swap_blocks_batch
|
||||
@_requires_accelerator
|
||||
def test_e2e_scheduler_worker_save_then_load(make_worker, monkeypatch):
|
||||
"""Full pipeline: scheduler allocates blocks, worker saves a GPU tensor to
|
||||
|
||||
Reference in New Issue
Block a user