diff --git a/vllm/envs.py b/vllm/envs.py index 6abcb4498a..786864b912 100755 --- a/vllm/envs.py +++ b/vllm/envs.py @@ -315,6 +315,7 @@ if TYPE_CHECKING: VLLM_MEMORY_PROFILER_ESTIMATE_CUDAGRAPHS: bool = True VLLM_NIXL_EP_MAX_NUM_RANKS: int = 32 VLLM_XPU_ENABLE_XPU_GRAPH: bool = False + VLLM_XPU_FORCE_N_CONTIG_WEIGHT: bool = False VLLM_XPU_USE_SAMPLER_KERNEL: bool = True VLLM_XPU_INC_WNA16_BACKEND: Literal["auto", "ark", "w4a16", "w4a8"] = "auto" VLLM_LORA_ENABLE_DUAL_STREAM: bool = False @@ -2112,6 +2113,10 @@ environment_variables: dict[str, Callable[[], Any]] = { "VLLM_XPU_ENABLE_XPU_GRAPH": lambda: bool( int(os.getenv("VLLM_XPU_ENABLE_XPU_GRAPH", "0")) ), + # Force N-contiguous weight layout for all XPU unquantized linears. + "VLLM_XPU_FORCE_N_CONTIG_WEIGHT": lambda: bool( + int(os.getenv("VLLM_XPU_FORCE_N_CONTIG_WEIGHT", "0")) + ), # whether use xpu specific sample kernel "VLLM_XPU_USE_SAMPLER_KERNEL": lambda: bool( int(os.getenv("VLLM_XPU_USE_SAMPLER_KERNEL", "1")) diff --git a/vllm/model_executor/layers/linear.py b/vllm/model_executor/layers/linear.py index f51d16c071..817409c0c4 100644 --- a/vllm/model_executor/layers/linear.py +++ b/vllm/model_executor/layers/linear.py @@ -213,6 +213,17 @@ class UnquantizedLinearMethod(LinearMethodBase): from vllm.model_executor.layers.utils import dispatch_cpu_unquantized_gemm dispatch_cpu_unquantized_gemm(layer, remove_weight=True) + elif current_platform.is_xpu(): + # Opt-in: F.linear on XPU is faster with an N-contiguous (N, K) weight + # when K > N, but oneDNN's ab-weights matmul is not run-to-run bitwise + # bitwise reproducible. Off by default. + weight = layer.weight.data + if ( + envs.VLLM_XPU_FORCE_N_CONTIG_WEIGHT + and weight.ndim == 2 + and weight.stride(0) != 1 + ): + layer.weight.data = weight.t().contiguous().t() def apply( self,