From b8c7c86533d52e70433d9718ddafdd26542191f1 Mon Sep 17 00:00:00 2001 From: Chaojun Zhang Date: Thu, 9 Jul 2026 14:08:30 +0800 Subject: [PATCH] [XPU][LoRA] Fix torch.compile DEVICE_LOST by avoiding view-mutation in LoRA shrink (#47944) Signed-off-by: Chaojun Zhang --- vllm/lora/punica_wrapper/punica_xpu.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/vllm/lora/punica_wrapper/punica_xpu.py b/vllm/lora/punica_wrapper/punica_xpu.py index 72c2e1db09..96b411abd1 100755 --- a/vllm/lora/punica_wrapper/punica_xpu.py +++ b/vllm/lora/punica_wrapper/punica_xpu.py @@ -98,7 +98,14 @@ class PunicaWrapperXPU(PunicaWrapperBase): w_t_all: torch.Tensor, scale: float, ): - bgmv_shrink(x, w_t_all, y, self._get_token_lora_indices(x), scale) + buf = torch.zeros( + x.size(0), + w_t_all.size(-2), + dtype=x.dtype, + device=x.device, + ) + bgmv_shrink(x, w_t_all, buf, self._get_token_lora_indices(x), scale) + y.copy_(buf) def _apply_expand( self, @@ -448,11 +455,17 @@ class PunicaWrapperXPU(PunicaWrapperBase): _, _, lora_ids, - _, + no_lora_flag, num_active_loras, ) = self.token_mapping_meta.meta_args( x.size(0), self.lora_config.specialize_active_lora ) + + assert no_lora_flag.numel() == 1 + if no_lora_flag.item(): + # None of the inputs require LoRA. + return + if token_lora_mapping is None: token_lora_mapping = token_lora_mapping_meta fused_moe_lora(