From 09d498686bffcd7d2e9512ad3ec586ac8f5ed65b Mon Sep 17 00:00:00 2001 From: Log-Dog012 Date: Thu, 23 Jul 2026 18:48:21 +0800 Subject: [PATCH] feat(ops): add GGMLTensor.dequantize() for generic core cast path Expose a dequantize(dtype=None) method on GGMLTensor that delegates to dequantize_tensor, mirroring what GGMLLayer.get_weight already does. This lets ComfyUI core's generic comfy.ops.cast_bias_weight dequantize GGUF weights instead of leaking the block-packed storage into matmul (which crashes on a shape mismatch for e.g. Qwen2.5-VL generate()). --- ops.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ops.py b/ops.py index 88a352e..a4c8f6e 100644 --- a/ops.py +++ b/ops.py @@ -90,6 +90,21 @@ def shape(self): self.tensor_shape = self.size() return self.tensor_shape + def dequantize(self, dtype=None): + """Return a plain (un-packed) torch.Tensor of the real weights. + + ComfyUI core's generic ``comfy.ops.cast_bias_weight`` only dequantizes + ``QuantizedTensor`` weights, so a GGUF ``GGMLTensor`` slips through + un-dequantized and reaches ``F.linear`` with its block-packed storage + shape, which crashes on a shape mismatch. Exposing this method lets the + generic path dequantize GGUF weights the same way ``GGMLLayer.get_weight`` + already does, without core having to know about the GGUF types. + """ + dt = dtype if dtype is not None else torch.float32 + w = dequantize_tensor(self, dt, None) + # prevent propagating the custom tensor class + return torch.Tensor(w) + class GGMLLayer(torch.nn.Module): """ This (should) be responsible for de-quantizing on the fly