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

Function convert_weight_int8_to_int2

gpu/pack_weight.py:76–98  ·  view source on GitHub ↗
(weight)

Source from the content-addressed store, hash-verified

74
75
76def convert_weight_int8_to_int2(weight):
77 N = weight.shape[0]
78 K = weight.shape[1]
79
80 weight = weight+2
81
82 weight = weight.cpu().numpy()
83
84 # print(weight)
85 # print(torch.max(weight), torch.min(weight))
86
87 # permutated_weight_slow = permutate_weight(weight)
88 permutated_weight = permutate_weight_fastest(weight)
89 # assert np.all(permutated_weight_slow == permutated_weight)
90 # print("Permutation is correct")
91 compressed_weight = compress_int2_to_int8(permutated_weight)
92 interleaved_weight = interleave_weight_int8(compressed_weight, 2)
93
94 ret = torch.from_numpy(interleaved_weight)
95
96 ret = torch.reshape(ret, (N, K // 4))
97
98 return ret

Callers 2

test.pyFile · 0.90
convert_int8_to_int2Function · 0.90

Calls 3

permutate_weight_fastestFunction · 0.85
compress_int2_to_int8Function · 0.85
interleave_weight_int8Function · 0.85

Tested by

no test coverage detected