| 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": |