(self, data: Tensor, *args, **kwargs)
| 221 | |
| 222 | class 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 |
nothing calls this directly
no test coverage detected