From a57094a3d314e9a4e0c7e87fa7cca987e7bf081c Mon Sep 17 00:00:00 2001 From: City <125218114+city96@users.noreply.github.com> Date: Wed, 17 Dec 2025 15:52:16 +0100 Subject: [PATCH] Fix for scales being in BF16 The main conversion code shouldn't allow this, but apparently some models still end up with quantized 1D tensors, see #383 --- loader.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/loader.py b/loader.py index 72dd010..096ce9f 100644 --- a/loader.py +++ b/loader.py @@ -119,6 +119,10 @@ def gguf_sd_loader(path, handle_prefix="model.diffusion_model.", return_arch=Fal torch_tensor = torch_tensor.view(*shape) state_dict[sd_key] = GGMLTensor(torch_tensor, tensor_type=tensor.tensor_type, tensor_shape=shape) + # 1D tensors shouldn't be quantized, this is a fix for BF16 + if len(shape) <= 1 and is_quantized(state_dict[sd_key]): + state_dict[sd_key] = dequantize_tensor(state_dict[sd_key], dtype=torch.float32) + # keep track of loaded tensor types tensor_type_str = getattr(tensor.tensor_type, "name", repr(tensor.tensor_type)) qtype_dict[tensor_type_str] = qtype_dict.get(tensor_type_str, 0) + 1