[XPU] Fix lora bugs & enable UTs under tests/lora (#38206)

Signed-off-by: chaojun-zhang <chaojun.zhang@intel.com>
This commit is contained in:
Chaojun Zhang
2026-05-07 05:58:00 -07:00
committed by GitHub
parent 75f0d516c4
commit 805e9f7b77
8 changed files with 313 additions and 30 deletions
+2 -6
View File
@@ -62,9 +62,7 @@ def dist_init():
temp_file = tempfile.mkstemp()[1]
backend = "nccl"
if current_platform.is_cpu() or current_platform.is_tpu():
backend = "gloo"
backend = "gloo" if current_platform.is_tpu() else current_platform.dist_backend
with ensure_current_vllm_config():
init_distributed_environment(
@@ -83,9 +81,7 @@ def dist_init():
def dist_init_torch_only():
if torch.distributed.is_initialized():
return
backend = "nccl"
if current_platform.is_cpu():
backend = "gloo"
backend = current_platform.dist_backend
temp_file = tempfile.mkstemp()[1]
torch.distributed.init_process_group(
+1
View File
@@ -647,6 +647,7 @@ def use_fused_moe_lora_kernel_tensor_parallel(
rank=local_rank,
local_rank=local_rank,
distributed_init_method=init_method,
backend=current_platform.dist_backend,
)
with ensure_current_vllm_config():
initialize_model_parallel(world_size, 1)
+30 -14
View File
@@ -57,7 +57,11 @@ TOLERANCES = {
}
pytestmark = pytest.mark.skipif(
not (current_platform.is_cuda_alike() or current_platform.is_cpu()),
not (
current_platform.is_cuda_alike()
or current_platform.is_cpu()
or current_platform.is_xpu()
),
reason="Backend not supported",
)
@@ -67,7 +71,7 @@ DEVICES = (
f"{DEVICE_TYPE}:{i}"
for i in range(1 if torch.accelerator.device_count() == 1 else 2)
]
if current_platform.is_cuda_alike()
if (current_platform.is_cuda_alike() or current_platform.is_xpu())
else ["cpu"]
)
@@ -96,7 +100,7 @@ def skip_cuda_with_stage_false(request):
On cuda-like platforms, we use the same kernels for prefill and decode
stage, and 'stage' is generally ignored, so we only need to test once.
"""
if current_platform.is_cuda_alike():
if current_platform.is_cuda_alike() or current_platform.is_xpu():
try:
if hasattr(request.node, "callspec") and hasattr(
request.node.callspec, "params"
@@ -249,6 +253,10 @@ def check_punica_wrapper(punica_wrapper) -> bool:
from vllm.lora.punica_wrapper.punica_cpu import PunicaWrapperCPU
return type(punica_wrapper) is PunicaWrapperCPU
elif current_platform.is_xpu():
from vllm.lora.punica_wrapper.punica_xpu import PunicaWrapperXPU
return type(punica_wrapper) is PunicaWrapperXPU
else:
return False
@@ -264,7 +272,7 @@ def test_embeddings(
# For multi-GPU testing of Triton kernel, we must explicitly set the CUDA
# device, see: https://github.com/triton-lang/triton/issues/2925
# Same below.
if current_platform.is_cuda_alike():
if current_platform.is_cuda_alike() or current_platform.is_xpu():
torch.accelerator.set_device_index(device)
torch.set_default_device(device)
@@ -363,7 +371,7 @@ def test_embeddings(
def test_lm_head_logits_processor(
default_vllm_config, dist_init, num_loras, device, vocab_size, stage
) -> None:
if current_platform.is_cuda_alike():
if current_platform.is_cuda_alike() or current_platform.is_xpu():
torch.accelerator.set_device_index(device)
torch.set_default_device(device)
@@ -480,7 +488,7 @@ def test_lm_head_logits_processor_invalid_vocab_size(
default_vllm_config, dist_init, vocab_size, device
) -> None:
"""Test that LogitsProcessorWithLoRA raises ValueError for invalid vocab sizes."""
if current_platform.is_cuda_alike():
if current_platform.is_cuda_alike() or current_platform.is_xpu():
torch.accelerator.set_device_index(device)
torch.set_default_device(device)
@@ -509,7 +517,7 @@ def test_linear_replicated(
device,
stage,
) -> None:
if current_platform.is_cuda_alike():
if current_platform.is_cuda_alike() or current_platform.is_xpu():
torch.accelerator.set_device_index(device)
max_loras = 8
@@ -618,7 +626,7 @@ def test_linear_replicated(
def test_linear_parallel(
default_vllm_config, dist_init, num_loras, orientation, fully_shard, device, stage
) -> None:
if current_platform.is_cuda_alike():
if current_platform.is_cuda_alike() or current_platform.is_xpu():
torch.accelerator.set_device_index(device)
max_loras = 8
@@ -751,7 +759,7 @@ def test_linear_parallel(
def test_column_parallel_packed(
default_vllm_config, dist_init, num_loras, repeats, fully_shard, device, stage
) -> None:
if current_platform.is_cuda_alike():
if current_platform.is_cuda_alike() or current_platform.is_xpu():
torch.accelerator.set_device_index(device)
max_loras = 8
@@ -913,7 +921,7 @@ def test_column_parallel_packed(
def test_merged_column_parallel_variable_slice(
default_vllm_config, dist_init, num_loras, num_slices, device, stage
) -> None:
if current_platform.is_cuda_alike():
if current_platform.is_cuda_alike() or current_platform.is_xpu():
torch.accelerator.set_device_index(device)
max_loras = 8
@@ -1600,11 +1608,15 @@ def test_get_and_maybe_dequant_weights_accepts_lora_wrappers(dist_init, wrapper_
def test_deepseek_fused_qkv_a_proj_lora_preserves_base_forward(
default_vllm_config, dist_init, device, stage, fully_sharded
):
if current_platform.is_cuda_alike():
if current_platform.is_cuda_alike() or current_platform.is_xpu():
torch.accelerator.set_device_index(device)
torch.set_default_device(device)
dtype = torch.float16 if current_platform.is_cuda_alike() else torch.float32
dtype = (
torch.float16
if (current_platform.is_cuda_alike() or current_platform.is_xpu())
else torch.float32
)
max_loras = 8
lora_config = LoRAConfig(
max_loras=max_loras,
@@ -1683,11 +1695,15 @@ def test_deepseek_fused_qkv_a_proj_lora_preserves_base_forward(
def test_replicated_lora_preserves_base_forward_for_subclasses(
default_vllm_config, dist_init, device, stage
):
if current_platform.is_cuda_alike():
if current_platform.is_cuda_alike() or current_platform.is_xpu():
torch.accelerator.set_device_index(device)
torch.set_default_device(device)
dtype = torch.float16 if current_platform.is_cuda_alike() else torch.float32
dtype = (
torch.float16
if current_platform.is_cuda_alike() or current_platform.is_xpu()
else torch.float32
)
max_loras = 8
lora_config = LoRAConfig(max_loras=max_loras, max_lora_rank=8, lora_dtype=dtype)
punica_wrapper = get_punica_wrapper(8192, 256, device, lora_config=lora_config)
+4
View File
@@ -224,6 +224,10 @@ def test_tp2_serialize_and_deserialize_lora(
max_model_len=1024,
tensor_parallel_size=2,
max_loras=2,
# Leave headroom for LoRA adapter loading and Triton JIT
# compilation, which can allocate GPU memory concurrently
# during the first inference step.
gpu_memory_utilization=0.85,
)
tc_as_dict = tensorizer_config.to_serializable()
+1 -1
View File
@@ -40,7 +40,7 @@ EMBEDDING_MODULES = {
DEVICE_TYPE = current_platform.device_type
DEVICES = (
[f"{DEVICE_TYPE}:{i}" for i in range(min(torch.accelerator.device_count(), 2))]
if current_platform.is_cuda_alike()
if (current_platform.is_cuda_alike() or current_platform.is_xpu())
else ["cpu"]
)
+5 -1
View File
@@ -20,7 +20,11 @@ from vllm.config.lora import LoRAConfig
from vllm.lora.model_manager import LoRAMapping
from vllm.lora.request import LoRARequest
from vllm.platforms import current_platform
from vllm.v1.worker.gpu_worker import Worker
if current_platform.is_xpu():
from vllm.v1.worker.xpu_worker import XPUWorker as Worker
else:
from vllm.v1.worker.gpu_worker import Worker
MODEL_PATH = "Qwen/Qwen3-0.6B"
NUM_LORAS = 16