(self, input)
| 77 | class BitLinear(nn.Linear): |
| 78 | @torch.compile |
| 79 | def quant_input(self, input): |
| 80 | s = 127 / input.abs().max(dim=-1, keepdim=True).values.clamp_(min=1e-5) |
| 81 | return (input * s).round().clamp(-128, 127) / s |
| 82 | |
| 83 | def forward(self, input): |
| 84 | input = self.quant_input(input) |