Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Update utils.py

Daniel Hane7a1f0458edf
diff --git a/unsloth/kernels/utils.py b/unsloth/kernels/utils.py
index 165950a9176..0bfd4269b18 100644
--- a/unsloth/kernels/utils.py
+++ b/unsloth/kernels/utils.py
@@ -157,8 +157,8 @@ if HAS_CUDA_STREAM:
global WEIGHT_BUFFER
global ABSMAX_BUFFER
if WEIGHT_BUFFER is None:
- WEIGHT_BUFFER = torch.empty(size, dtype = dtype, device = "cuda:0")
- ABSMAX_BUFFER = torch.empty(n_elements_absmax, dtype = torch.float32, device = "cuda:0")
+ WEIGHT_BUFFER = torch.empty(size, dtype = dtype, device = "cuda:0", requires_grad = False)
+ ABSMAX_BUFFER = torch.empty(n_elements_absmax, dtype = torch.float32, device = "cuda:0", requires_grad = False)
if size > WEIGHT_BUFFER.numel(): WEIGHT_BUFFER.resize_(size)
if n_elements_absmax > ABSMAX_BUFFER.numel(): ABSMAX_BUFFER.resize_(n_elements_absmax)
@@ -167,11 +167,11 @@ if HAS_CUDA_STREAM:
out_absmax = ABSMAX_BUFFER[:n_elements_absmax]
else:
if out is None:
- out = torch.empty(shape, dtype = dtype, device = "cuda:0")
+ out = torch.empty(shape, dtype = dtype, device = "cuda:0", requires_grad = False)
else:
assert(out.shape == shape)
assert(out.dtype == dtype)
- out_absmax = torch.empty(n_elements_absmax, dtype = torch.float32, device = "cuda:0")
+ out_absmax = torch.empty(n_elements_absmax, dtype = torch.float32, device = "cuda:0", requires_grad = False)
pass
# NF4 dequantization of statistics
@@ -224,8 +224,8 @@ else:
global WEIGHT_BUFFER
global ABSMAX_BUFFER
if WEIGHT_BUFFER is None:
- WEIGHT_BUFFER = torch.empty(size, dtype = dtype, device = "cuda:0")
- ABSMAX_BUFFER = torch.empty(n_elements_absmax, dtype = dtype, device = "cuda:0")
+ WEIGHT_BUFFER = torch.empty(size, dtype = dtype, device = "cuda:0", requires_grad = False)
+ ABSMAX_BUFFER = torch.empty(n_elements_absmax, dtype = dtype, device = "cuda:0", requires_grad = False)
if size > WEIGHT_BUFFER.numel(): WEIGHT_BUFFER.resize_(size)
if n_elements_absmax > ABSMAX_BUFFER.numel(): ABSMAX_BUFFER.resize_(n_elements_absmax)
@@ -234,11 +234,11 @@ else:
out_absmax = ABSMAX_BUFFER[:n_elements_absmax]
else:
if out is None:
- out = torch.empty(shape, dtype = dtype, device = "cuda:0")
+ out = torch.empty(shape, dtype = dtype, device = "cuda:0", requires_grad = False)
else:
assert(out.shape == shape)
assert(out.dtype == dtype)
- out_absmax = torch.empty(n_elements_absmax, dtype = torch.float32, device = "cuda:0")
+ out_absmax = torch.empty(n_elements_absmax, dtype = torch.float32, device = "cuda:0", requires_grad = False)
pass
# Do dequantization