| 75 | return bitnet_int8xint2_linear(input, self.weight, s, self.weight_scale) |
| 76 | |
| 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) |
| 85 | return F.linear(input, self.weight) |
| 86 | |
| 87 | class Attention(nn.Module): |
| 88 | def __init__( |
nothing calls this directly
no outgoing calls
no test coverage detected