()
| 107 | |
| 108 | |
| 109 | def test_bitlinear_weight_group_scaling(): |
| 110 | layer = BitLinear(10, 20, groups=5) |
| 111 | weight = layer.weight.view(layer.groups, -1) |
| 112 | beta = torch.abs(weight).sum(dim=1, keepdim=True) / ( |
| 113 | weight.shape[0] * weight.shape[1] |
| 114 | ) |
| 115 | scaled_weight = weight * beta |
| 116 | assert torch.allclose(scaled_weight, layer.weight.view(20, 10)) |
| 117 | |
| 118 | |
| 119 | def test_bitlinear_input_quantization(random_tensor): |