(self, tensor: Tensor)
| 71 | assert False, 'Unsupported quantization bits {}'.format(self.config['num_bits']) |
| 72 | |
| 73 | def _quantize_int8(self, tensor: Tensor) -> Tuple[Tensor, Tensor, Tensor]: |
| 74 | q_range = 2**self.config['num_bits'] - 1 |
| 75 | min_value = tensor.amin(dim=self.config['group_dim'] + 1, keepdim=True) |
| 76 | max_value = tensor.amax(dim=self.config['group_dim'] + 1, keepdim=True) |
| 77 | |
| 78 | scale = q_range / (max_value - min_value) |
| 79 | |
| 80 | tensor = tensor.sub_(min_value).mul_(scale) |
| 81 | tensor = tensor_round(tensor_clamp(tensor, 0, q_range)).to(torch.uint8) |
| 82 | return tensor, scale, min_value |
| 83 | |
| 84 | def _compress_uint8_to_uint4(self, tensor: Tensor) -> Tensor: |
| 85 | assert tensor.shape[-1] % 2 == 0 |
no test coverage detected