[Attention] Fetch MLA prefill workspace at use instead of init (#60654)
Signed-off-by: Matthew Bonanni <mbonanni@redhat.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
e83222396f
commit
624a5ddafd
@@ -2,14 +2,26 @@
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
"""Tests for MLA prefill backend registry."""
|
||||
|
||||
import gc
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
|
||||
from vllm.v1.attention.backends.mla.prefill.base import MLAPrefillBackend
|
||||
from vllm.v1.attention.backends.mla.prefill.flashinfer import FlashInferPrefillBackend
|
||||
from vllm.v1.attention.backends.mla.prefill.registry import (
|
||||
MLAPrefillBackendEnum,
|
||||
register_mla_prefill_backend,
|
||||
)
|
||||
from vllm.v1.attention.backends.mla.prefill.trtllm_ragged import (
|
||||
TrtllmRaggedPrefillBackend,
|
||||
)
|
||||
from vllm.v1.worker.workspace import (
|
||||
current_workspace_manager,
|
||||
init_workspace_manager,
|
||||
reset_workspace_manager,
|
||||
)
|
||||
|
||||
|
||||
class CustomMLAPrefillBackend(MLAPrefillBackend):
|
||||
@@ -50,6 +62,38 @@ def test_prefill_backend_clone_has_isolated_metadata():
|
||||
assert clone._prefill_metadata is not backend._prefill_metadata
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"backend_cls", [TrtllmRaggedPrefillBackend, FlashInferPrefillBackend]
|
||||
)
|
||||
def test_prefill_backend_does_not_pin_grown_workspace(monkeypatch, backend_cls):
|
||||
"""Reserving workspace at init must not keep a view of it: when another user
|
||||
grows the shared workspace, the old buffer must be freed."""
|
||||
monkeypatch.setenv("VLLM_FLASHINFER_WORKSPACE_BUFFER_SIZE", "4096")
|
||||
init_workspace_manager(torch.device("cpu"))
|
||||
try:
|
||||
manager = current_workspace_manager()
|
||||
backend = backend_cls(
|
||||
num_heads=4,
|
||||
scale=0.5,
|
||||
kv_lora_rank=8,
|
||||
qk_nope_head_dim=16,
|
||||
qk_rope_head_dim=8,
|
||||
v_head_dim=32,
|
||||
vllm_config=MagicMock(),
|
||||
)
|
||||
(view,) = manager.get_simultaneous(((1,), torch.uint8))
|
||||
old_storage = view.untyped_storage()._weak_ref()
|
||||
del view
|
||||
|
||||
manager.get_simultaneous(((1 << 20,), torch.uint8))
|
||||
gc.collect()
|
||||
|
||||
assert torch.UntypedStorage._expired(old_storage)
|
||||
del backend
|
||||
finally:
|
||||
reset_workspace_manager()
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def cleanup_overrides():
|
||||
"""Clear any overrides after each test."""
|
||||
|
||||
Reference in New Issue
Block a user