From 631b36db15f3a6d6e13614321aa700692f3ad97e Mon Sep 17 00:00:00 2001 From: Daniel Han-Chen Date: Wed, 11 Feb 2026 12:16:47 +0000 Subject: [PATCH] Fix dequant global buffer dtype reuse across mixed precision --- unsloth/kernels/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/unsloth/kernels/utils.py b/unsloth/kernels/utils.py index 5dcc7c232c..695264d255 100644 --- a/unsloth/kernels/utils.py +++ b/unsloth/kernels/utils.py @@ -388,7 +388,7 @@ if DEVICE_TYPE == "xpu" and HAS_XPU_STREAM: global ABSMAX_BUFFERS WEIGHT_BUFFER = WEIGHT_BUFFERS[device_index] ABSMAX_BUFFER = ABSMAX_BUFFERS[device_index] - if WEIGHT_BUFFER is None: + if WEIGHT_BUFFER is None or WEIGHT_BUFFER.dtype != dtype: WEIGHT_BUFFERS[device_index] = WEIGHT_BUFFER = torch_empty( size, dtype = dtype, device = device, requires_grad = False ) @@ -498,7 +498,7 @@ elif DEVICE_TYPE in ("cuda", "hip") and HAS_CUDA_STREAM: global ABSMAX_BUFFERS WEIGHT_BUFFER = WEIGHT_BUFFERS[device_index] ABSMAX_BUFFER = ABSMAX_BUFFERS[device_index] - if WEIGHT_BUFFER is None: + if WEIGHT_BUFFER is None or WEIGHT_BUFFER.dtype != dtype: WEIGHT_BUFFERS[device_index] = WEIGHT_BUFFER = torch_empty( size, dtype = dtype, device = device, requires_grad = False )