[Bugfix][HiSparse][NIXL] Import full blocks without tail prefill on D (#57049)

Signed-off-by: NickLucche <nicolo.lucchesi@mistral.ai>
Signed-off-by: Lucas Wilkinson <lwilkins@redhat.com>
Co-authored-by: OpenAI Codex <noreply@openai.com>
Co-authored-by: Lucas Wilkinson <lwilkins@redhat.com>
This commit is contained in:
Nicolò Lucchesi
2026-09-17 15:26:10 -04:00
committed by GitHub
co-authored by OpenAI Codex Lucas Wilkinson
parent 41f9104fa6
commit 67e5b0acc9
8 changed files with 277 additions and 53 deletions
+65
View File
@@ -531,6 +531,71 @@ def test_hisparse_eager_mirror_records_transfer_without_page_copy():
worker._enqueue_transfers.assert_not_called()
@pytest.mark.parametrize("is_host_writer", [False, True])
@pytest.mark.parametrize("device", ["cpu", "cuda"])
def test_hisparse_tail_restore_preserves_imported_rows(
monkeypatch, request, is_host_writer, device
):
"""Restore externally pinned host rows on every rank under sync checking."""
if device == "cuda" and not torch.cuda.is_available():
pytest.skip("CUDA is required for the device copy check")
worker = _make_hisparse_worker()
worker.is_host_writer = is_host_writer
worker.kernel_block_size = 4
worker.host_caches = tuple(
torch.arange(24, dtype=torch.float32).reshape(12, 2) + layer * 100
for layer in range(2)
)
if device == "cuda":
# Match production's cudaHostRegister pool, which torch.is_pinned()
# does not recognize, rather than torch's caching pinned allocator.
host_pool, registered = hisparse_runtime_module.allocate_pinned_host_pool(
sum(cache.nbytes for cache in worker.host_caches)
)
request.addfinalizer(
lambda: hisparse_runtime_module.release_pinned_state([], [registered])
)
host_caches = host_pool.view(torch.float32).view(2, 12, 2).unbind()
for destination, source in zip(host_caches, worker.host_caches):
destination.copy_(source)
worker.host_caches = host_caches
worker.resident_caches = tuple(
torch.full((4, 4, 2), -1.0, device=device) for _ in range(2)
)
worker.cache_handles = [
SimpleNamespace(
runtime=SimpleNamespace(resident_source_index=i, eager_host_mirror=True)
)
for i in range(2)
]
worker._record_transfer_completion = MagicMock()
stream = torch.cuda.current_stream() if device == "cuda" else MagicMock()
monkeypatch.setattr(hisparse_worker_module, "current_stream", lambda: stream)
transfer = SparseKVPageTransfer(7, 2, (1, 3), False, restore=True)
restore_pages = worker._restore_pages
if device == "cuda":
import vllm.utils.gpu_sync_debug as gpu_sync_debug
monkeypatch.setattr(gpu_sync_debug, "_SYNC_CHECK_MODE", "error")
monkeypatch.setattr(gpu_sync_debug, "_sync_check_enabled", False)
gpu_sync_debug.enable_gpu_sync_check()
restore_pages = gpu_sync_debug.with_gpu_sync_check(restore_pages)
restore_pages([transfer])
# Appending into unused capacity must preserve every imported prompt row.
for cache, host, block in zip(
worker.resident_caches, worker.host_caches, transfer.resident_block_ids
):
assert torch.equal(cache[block].cpu(), host[8:12])
cache[block, 2:] = 999
assert torch.equal(cache[block, :2].cpu(), host[8:10])
assert torch.all(cache[0] == -1)
worker._record_transfer_completion.assert_called_once_with(
[transfer], stream=stream
)
def test_hisparse_lazy_mirror_copies_transfer_pages():
worker = _make_hisparse_worker()
worker.cache_handles = [