(x : NDArray)
| 766 | return w |
| 767 | |
| 768 | def transform_to_i2(x : NDArray): |
| 769 | x_num = np.prod(x.shape) |
| 770 | tile_x = np.reshape(x, x_num) |
| 771 | scale = 1 |
| 772 | for i in range(x_num): |
| 773 | if tile_x[i] != 0: |
| 774 | scale = tile_x[i] |
| 775 | break |
| 776 | tile_x = np.divide(tile_x, scale) |
| 777 | tile_x = (tile_x.astype(np.int8) + 2).astype(np.uint8) |
| 778 | ans = np.reshape(tile_x, x.shape) |
| 779 | return ans, scale |
| 780 | |
| 781 | class UnquantizedTensor(Tensor): |
| 782 | def __init__(self, ndarray: NDArray, i2_scale: NDArray = None): |