(weight)
| 74 | |
| 75 | |
| 76 | def 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 |
no test coverage detected