(x)
| 3 | from oneflow.nn.parameter import Parameter |
| 4 | |
| 5 | def _pack_int8_to_int4(x): |
| 6 | np_x = x.numpy() |
| 7 | l = np_x[..., 0::2] |
| 8 | r = np_x[..., 1::2] |
| 9 | l = np.left_shift(l, 4) |
| 10 | if x.dtype is np.int8: |
| 11 | even = np.bitwise_and(r, np.int8(0xF)) |
| 12 | packed = torch.tensor(np.bitwise_or(l, r), device=x.device) |
| 13 | return packed |
| 14 | |
| 15 | |
| 16 | def _quantize(num_bits, symmetric, x, group_dim, group_size, quant_type): |