MCPcopy
hub / github.com/city96/ComfyUI-GGUF / dequantize_tensor

Function dequantize_tensor

dequant.py:15–28  ·  view source on GitHub ↗
(tensor, dtype=None, dequant_dtype=None)

Source from the content-addressed store, hash-verified

13 return not is_torch_compatible(tensor)
14
15def dequantize_tensor(tensor, dtype=None, dequant_dtype=None):
16 qtype = getattr(tensor, "tensor_type", None)
17 oshape = getattr(tensor, "tensor_shape", tensor.shape)
18
19 if qtype in TORCH_COMPATIBLE_QTYPES:
20 return tensor.to(dtype)
21 elif qtype in dequantize_functions:
22 dequant_dtype = dtype if dequant_dtype == "target" else dequant_dtype
23 return dequantize(tensor.data, qtype, oshape, dtype=dequant_dtype).to(dtype)
24 else:
25 # this is incredibly slow
26 tqdm.write(f"Falling back to numpy dequant for qtype: {getattr(qtype, 'name', repr(qtype))}")
27 new = gguf.quants.dequantize(tensor.cpu().numpy(), qtype)
28 return torch.from_numpy(new).to(tensor.device, dtype=dtype)
29
30def dequantize(data, qtype, oshape, dtype=None):
31 """

Callers 5

gguf_sd_loaderFunction · 0.85
gemma3_norm_correctionsFunction · 0.85
gguf_mmproj_loaderFunction · 0.85
gguf_clip_loaderFunction · 0.85
get_weightMethod · 0.85

Calls 2

dequantizeFunction · 0.85
toMethod · 0.80

Tested by

no test coverage detected