MCPcopy Create free account
hub / github.com/ModelTC/LightX2V / dequantize_tensor

Function dequantize_tensor

lightx2v/utils/ggml_tensor.py:601–616  ·  view source on GitHub ↗
(tensor, dtype=None)

Source from the content-addressed store, hash-verified

599
600
601def dequantize_tensor(tensor, dtype=None):
602 qtype = getattr(tensor, "gguf_type", None)
603 oshape = getattr(tensor, "orig_shape", tensor.data.shape)
604
605 if qtype in TORCH_COMPATIBLE_QTYPES:
606 return tensor.to(dtype)
607 else:
608 if dequantize_c is not None:
609 return dequantize_c(tensor).to(dtype)
610 elif qtype in dequantize_functions:
611 return dequantize(tensor.to_torch().data, qtype, oshape, dtype=dtype).to(dtype)
612 else:
613 # this is incredibly slow
614 logger.warning(f"Falling back to numpy dequant for qtype: {qtype}")
615 new = gguf.quants.dequantize(tensor.cpu().numpy(), qtype)
616 return torch.from_numpy(new).to(tensor.device, dtype=dtype)
617
618
619def dequantize(data, qtype, oshape, dtype=None):

Callers

nothing calls this directly

Calls 7

dequantize_cFunction · 0.85
dequantizeFunction · 0.85
to_torchMethod · 0.80
warningMethod · 0.80
dequantizeMethod · 0.80
cpuMethod · 0.80
toMethod · 0.45

Tested by

no test coverage detected