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

Function transform_to_i2

utils/convert.py:768–779  ·  view source on GitHub ↗
(x : NDArray)

Source from the content-addressed store, hash-verified

766 return w
767
768def 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
781class UnquantizedTensor(Tensor):
782 def __init__(self, ndarray: NDArray, i2_scale: NDArray = None):

Callers 1

astypeMethod · 0.70

Calls 1

astypeMethod · 0.45

Tested by

no test coverage detected