MCPcopy Create free account
hub / github.com/microsoft/BitNet / BitLinear

Class BitLinear

gpu/model.py:77–85  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

75 return bitnet_int8xint2_linear(input, self.weight, s, self.weight_scale)
76
77class 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
87class Attention(nn.Module):
88 def __init__(

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected