MCPcopy Create free account
hub / github.com/tdrussell/diffusion-pipe / __init__

Method __init__

optimizers/optimizer_utils.py:223–232  ·  view source on GitHub ↗
(self, data: Tensor, *args, **kwargs)

Source from the content-addressed store, hash-verified

221
222class Auto8bitTensor:
223 def __init__(self, data: Tensor, *args, **kwargs):
224 if isinstance(data, dict): # Add constructor from state dict
225 self._load_from_state_dict(data)
226 else:
227 abs_max = data.abs().max().item()
228 scale = abs_max / 127.0 if abs_max > 0 else 1.0
229
230 self.quantized = (data / scale).round().clamp(-127, 127).to(torch.int8)
231 self.scale = scale
232 self.orig_dtype = data.dtype
233
234 def dequantize(self) -> Tensor:
235 return self.quantized.to(dtype=torch.float32) * self.scale

Callers

nothing calls this directly

Calls 2

_load_from_state_dictMethod · 0.95
toMethod · 0.45

Tested by

no test coverage detected