[CI Test] Add specific unit test for mrv2 offloading (#51440)

Signed-off-by: yewentao256 <zhyanwentao@126.com>
This commit is contained in:
Wentao Ye
2026-08-07 22:49:45 +00:00
committed by GitHub
parent a801e71cb8
commit c39076feff
2 changed files with 58 additions and 10 deletions
+57 -4
View File
@@ -3,15 +3,22 @@
import pytest
import vllm.envs as envs
from vllm.model_executor.offloader import (
PrefetchOffloader,
UVAOffloader,
get_offloader,
set_offloader,
)
from vllm.v1.worker.gpu.model_runner import GPUModelRunner
from ..utils import compare_two_settings
@pytest.mark.parametrize("disable_pin_memory", [False, True])
@pytest.mark.parametrize("disable_uva", [False, True])
@pytest.mark.parametrize("use_v2_model_runner", [False, True])
def test_cpu_offload(disable_pin_memory, disable_uva, use_v2_model_runner):
def test_cpu_offload(disable_pin_memory, disable_uva):
env_vars = {
"VLLM_USE_V2_MODEL_RUNNER": str(int(use_v2_model_runner)),
"VLLM_WEIGHT_OFFLOADING_DISABLE_PIN_MEMORY": str(int(disable_pin_memory)),
"VLLM_WEIGHT_OFFLOADING_DISABLE_UVA": str(int(disable_uva)),
}
@@ -26,6 +33,52 @@ def test_cpu_offload(disable_pin_memory, disable_uva, use_v2_model_runner):
model="hmellor/tiny-random-LlamaForCausalLM",
arg1=[],
arg2=args,
env1=env_vars,
env1=None,
env2=env_vars,
)
@pytest.mark.parametrize(
("offload_kwargs", "offloader_type"),
[
({"cpu_offload_gb": 1}, UVAOffloader),
(
{
"offload_group_size": 1,
"offload_num_in_group": 1,
"offload_prefetch_step": 1,
},
PrefetchOffloader,
),
],
)
def test_mrv2_weight_offloading(
vllm_runner, monkeypatch, offload_kwargs, offloader_type
):
monkeypatch.setenv("VLLM_ENABLE_V1_MULTIPROCESSING", "0")
envs.disable_envs_cache()
original_offloader = get_offloader()
try:
with vllm_runner(
"hmellor/tiny-random-LlamaForCausalLM",
enforce_eager=True,
gpu_memory_utilization=0.02,
max_model_len=128,
max_num_seqs=1,
**offload_kwargs,
) as vllm_model:
engine_core = vllm_model.llm.llm_engine.engine_core.engine_core
model_runner = engine_core.model_executor.driver_worker.worker.model_runner
assert isinstance(model_runner, GPUModelRunner)
offloader = get_offloader()
assert isinstance(offloader, offloader_type)
if isinstance(offloader, UVAOffloader):
assert offloader.cpu_offload_bytes > 0
else:
assert offloader.total_offloaded_bytes > 0
assert offloader.buffer_pool is not None
finally:
set_offloader(original_offloader)
envs.disable_envs_cache()
@@ -2,13 +2,10 @@
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""Test prefetch offloading correctness with Llama model."""
import pytest
from ..utils import compare_two_settings
@pytest.mark.parametrize("use_v2_model_runner", [False, True])
def test_prefetch_offload_llama(use_v2_model_runner):
def test_prefetch_offload_llama():
"""Test prefetch CPU offloading with Llama-3.2-1B-Instruct.
Compares outputs between:
@@ -33,6 +30,4 @@ def test_prefetch_offload_llama(use_v2_model_runner):
"down_proj",
],
[], # Baseline: no offloading
env1={"VLLM_USE_V2_MODEL_RUNNER": str(int(use_v2_model_runner))},
env2={"VLLM_USE_V2_MODEL_RUNNER": str(int(use_v2_model_runner))},
)