(ctx, tensor: torch.Tensor, config: TensorQuantizationConfig)
| 111 | """ |
| 112 | @ staticmethod |
| 113 | def forward(ctx, tensor: torch.Tensor, config: TensorQuantizationConfig) -> torch.Tensor: |
| 114 | from ppq.quantization.observer.range import minmax_to_scale_offset |
| 115 | # solve scale and offset at first. |
| 116 | scales, offsets = minmax_to_scale_offset( |
| 117 | tensor.min().item(), tensor.max().item(), config=config) |
| 118 | print(scales, offsets) |
| 119 | # quantization function, pytorch implmentation |
| 120 | tensor = ppq_tensor_round((tensor / scales), config.rounding) + offsets |
| 121 | tensor = torch.clamp(tensor, config.quant_min, config.quant_max) |
| 122 | tensor = (tensor - offsets) * scales |
| 123 | return tensor |
| 124 | |
| 125 | @ staticmethod |
| 126 | def backward(ctx, dy: torch.Tensor): |
nothing calls this directly
no test coverage detected