Per-channel quantize, scale/zero-point
Hard AdvancedImplement a post-training quantized linear layer using INT8 weights.
1. scale = weight.abs().max(dim=1) / 127
2. weight_int8 = round(weight / scale).clamp(-128, 127).to(int8)
3. Store as register_buffer (not trainable)
4. Forward: dequantize (int8.float() * scale) then matmul
Implement the function below. Use only basic PyTorch operations.
Use this code to debug before submitting.
Try solving it yourself first! Click below to reveal the solution.
For interactive practice with auto-grading, run TorchCode locally:pip install torch-judge then use check("int8_quantization")
Per-channel quantize, scale/zero-point