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

Method get_qparams

lightx2v/utils/quant_utils.py:63–75  ·  view source on GitHub ↗
(self, tensor_range, device)

Source from the content-addressed store, hash-verified

61 raise NotImplementedError
62
63 def get_qparams(self, tensor_range, device):
64 min_val, max_val = tensor_range[0], tensor_range[1]
65 qmin = self.qmin.to(device)
66 qmax = self.qmax.to(device)
67 if self.sym:
68 abs_max = torch.max(max_val.abs(), min_val.abs())
69 abs_max = abs_max.clamp(min=1e-5)
70 scales = abs_max / qmax
71 zeros = torch.tensor(0.0)
72 else:
73 scales = (max_val - min_val).clamp(min=1e-5) / (qmax - qmin)
74 zeros = (qmin - torch.round(min_val / scales)).clamp(qmin, qmax)
75 return scales, zeros, qmax, qmin
76
77 def reshape_tensor(self, tensor, allow_padding=False):
78 if self.granularity == "per_group":

Callers 1

get_tensor_qparamsMethod · 0.95

Calls 1

toMethod · 0.45

Tested by

no test coverage detected