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

Method __init__

lightx2v/utils/quant_utils.py:155–175  ·  view source on GitHub ↗
(self, bit, symmetric, granularity, **kwargs)

Source from the content-addressed store, hash-verified

153
154class FloatQuantizer(BaseQuantizer):
155 def __init__(self, bit, symmetric, granularity, **kwargs):
156 super().__init__(bit, symmetric, granularity, **kwargs)
157 assert self.bit in ["e4m3", "e5m2"], f"Unsupported bit configuration: {self.bit}"
158 assert self.sym
159
160 if self.bit == "e4m3":
161 self.e_bits = 4
162 self.m_bits = 3
163 self.fp_dtype = torch.float8_e4m3fn
164 elif self.bit == "e5m2":
165 self.e_bits = 5
166 self.m_bits = 2
167 self.fp_dtype = torch.float8_e5m2
168 else:
169 raise ValueError(f"Unsupported bit configuration: {self.bit}")
170
171 finfo = torch.finfo(self.fp_dtype)
172 self.qmin, self.qmax = finfo.min, finfo.max
173
174 self.qmax = torch.tensor(self.qmax)
175 self.qmin = torch.tensor(self.qmin)
176
177 def quant(self, tensor, scales, zeros, qmax, qmin):
178 scaled_tensor = tensor / scales + zeros

Callers

nothing calls this directly

Calls 1

__init__Method · 0.45

Tested by

no test coverage detected