| 56 | self.qmax = int(2 ** (n_bits) - 1) |
| 57 | |
| 58 | def fake_quant(self, x): |
| 59 | scale = clamp_ste(self.scale,1e-4, 1e4) |
| 60 | round_zero_point = clamp_ste(round_ste(self.zero_point), self.qmin, self.qmax) |
| 61 | |
| 62 | dim1, dim2 = x.shape |
| 63 | x = x.reshape(-1, self.group_size) |
| 64 | x_int = round_ste(x / scale) |
| 65 | if round_zero_point is not None: |
| 66 | x_int = x_int.add(round_zero_point) |
| 67 | x_int = x_int.clamp(self.qmin, self.qmax) |
| 68 | x_dequant = x_int |
| 69 | if round_zero_point is not None: |
| 70 | x_dequant = x_dequant.sub(round_zero_point) |
| 71 | x_dequant = x_dequant.mul(scale) |
| 72 | if self.group_size: |
| 73 | x_dequant = x_dequant.reshape(dim1, dim2) |
| 74 | return x_dequant |
| 75 | |
| 76 | |
| 77 | def forward(self, x: torch.Tensor): |