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

Method load_int8_weight

tools/convert/quant/quant.py:32–49  ·  view source on GitHub ↗
(self, w, comfyui_mode=False)

Source from the content-addressed store, hash-verified

30 raise ValueError(f"Only 2D tensors supported. Got {weight.dim()}D tensor")
31 if torch.isnan(weight).any():
32 raise ValueError("Tensor contains NaN values")
33
34 self.weight_quant_func = None
35 self.extra = {}
36
37
38@CONVERT_WEIGHT_REGISTER("int8")
39class QuantWeightINT8(QuantTemplate):
40 def __init__(self, weight):
41 super().__init__(weight)
42 self.weight_quant_func = self.load_int8_weight
43
44 @torch.no_grad()
45 def load_int8_weight(self, w, comfyui_mode=False):
46 org_w_shape = w.shape
47 if not comfyui_mode:
48 max_val = w.abs().amax(dim=1, keepdim=True).clamp(min=1e-5)
49 else:
50 max_val = w.abs().max()
51 qmin, qmax = -128, 127
52 scales = max_val / qmax

Callers

nothing calls this directly

Calls 1

toMethod · 0.45

Tested by

no test coverage detected