[XPU] Ensure unquantized linear weight is N-contiguous (#53536)

Signed-off-by: Zhu, Zufang <zufang.zhu@intel.com> Co-authored-by: opencode <noreply@opencode.ai>

zofia committed Aug 31, 2026 at 16:01 UTC 2a61f060d342afb680f5a8937ed614b774bf9305
2 files changed +16
vllm/envs.py
+5
@@ -315,6 +315,7 @@ if TYPE_CHECKING:
315 VLLM_MEMORY_PROFILER_ESTIMATE_CUDAGRAPHS: bool = True
316 VLLM_NIXL_EP_MAX_NUM_RANKS: int = 32
317 VLLM_XPU_ENABLE_XPU_GRAPH: bool = False
318 + VLLM_XPU_FORCE_N_CONTIG_WEIGHT: bool = False
319 VLLM_XPU_USE_SAMPLER_KERNEL: bool = True
320 VLLM_XPU_INC_WNA16_BACKEND: Literal["auto", "ark", "w4a16", "w4a8"] = "auto"
321 VLLM_LORA_ENABLE_DUAL_STREAM: bool = False
@@ -2112,6 +2113,10 @@ environment_variables: dict[str, Callable[[], Any]] = {
2113 "VLLM_XPU_ENABLE_XPU_GRAPH": lambda: bool(
2114 int(os.getenv("VLLM_XPU_ENABLE_XPU_GRAPH", "0"))
2115 ),
2116 + # Force N-contiguous weight layout for all XPU unquantized linears.
2117 + "VLLM_XPU_FORCE_N_CONTIG_WEIGHT": lambda: bool(
2118 + int(os.getenv("VLLM_XPU_FORCE_N_CONTIG_WEIGHT", "0"))
2119 + ),
2120 # whether use xpu specific sample kernel
2121 "VLLM_XPU_USE_SAMPLER_KERNEL": lambda: bool(
2122 int(os.getenv("VLLM_XPU_USE_SAMPLER_KERNEL", "1"))
vllm/model_executor/layers/linear.py
+11
@@ -213,6 +213,17 @@ class UnquantizedLinearMethod(LinearMethodBase):
213 from vllm.model_executor.layers.utils import dispatch_cpu_unquantized_gemm
214
215 dispatch_cpu_unquantized_gemm(layer, remove_weight=True)
216 + elif current_platform.is_xpu():
217 + # Opt-in: F.linear on XPU is faster with an N-contiguous (N, K) weight
218 + # when K > N, but oneDNN's ab-weights matmul is not run-to-run bitwise
219 + # bitwise reproducible. Off by default.
220 + weight = layer.weight.data
221 + if (
222 + envs.VLLM_XPU_FORCE_N_CONTIG_WEIGHT
223 + and weight.ndim == 2
224 + and weight.stride(0) != 1
225 + ):
226 + layer.weight.data = weight.t().contiguous().t()
227
228 def apply(
229 self,