[Bugfix][ROCm] Use batch DMA for CPU KV cache loads (#49843)

Signed-off-by: Andreas Karatzas <akaratza@amd.com>
Co-authored-by: OpenAI Codex <noreply@openai.com>
This commit is contained in:
Andreas Karatzas
2026-07-27 02:18:01 -07:00
committed by GitHub
co-authored by OpenAI Codex
parent 7f599d7854
commit 394beb633b
2 changed files with 16 additions and 2 deletions
@@ -7,6 +7,7 @@ import uuid
import pytest
import torch
from vllm import _custom_ops as ops
from vllm.platforms import current_platform
from vllm.utils.math_utils import round_up
from vllm.utils.torch_utils import set_random_seed
@@ -16,6 +17,7 @@ from vllm.v1.kv_offload.base import (
CanonicalKVCacheTensor,
GPULoadStoreSpec,
)
from vllm.v1.kv_offload.cpu import gpu_worker
from vllm.v1.kv_offload.cpu.common import CPULoadStoreSpec
from vllm.v1.kv_offload.cpu.gpu_worker import CPUOffloadingWorker
from vllm.v1.kv_offload.cpu.shared_offload_region import SharedOffloadRegion
@@ -32,6 +34,18 @@ NUM_MAPPINGS = [3]
NUM_MAPPINGS_PER_GROUP = [2]
@pytest.mark.skipif(not current_platform.is_rocm(), reason="ROCm-specific test")
def test_rocm_cpu_to_gpu_uses_dma(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(gpu_worker, "HAS_TRITON", True)
monkeypatch.setattr(gpu_worker.current_platform, "is_xpu", lambda: False)
monkeypatch.setattr(gpu_worker.current_platform, "is_rocm", lambda: True)
refs = [[CanonicalKVCacheRef(tensor_idx=0, page_size_bytes=512)]]
assert gpu_worker._select_swap_blocks_fn(refs, gpu_to_cpu=False) is (
ops.swap_blocks_batch
)
@pytest.mark.parametrize("gpu_to_cpu", [True, False])
@pytest.mark.parametrize("num_mappings", NUM_MAPPINGS)
@pytest.mark.parametrize("gpu_page_size_bytes", GPU_PAGE_SIZES)