From 368912f0521f6dbe584bfb2c4f6c27ce84d2f90e Mon Sep 17 00:00:00 2001 From: Shkarupa Alex Date: Fri, 19 Jul 2024 11:10:04 +0300 Subject: [PATCH] Fix padding in tensor packing If "other" size is already dividable by 8 (e.g. 64), original code will pad it by 8: 8 - 64 % 8 = 8 - 0 = 8 So we need one more "mod" --- optiacts/bit_compress.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/optiacts/bit_compress.py b/optiacts/bit_compress.py index 9638190..9c0cdc5 100644 --- a/optiacts/bit_compress.py +++ b/optiacts/bit_compress.py @@ -15,7 +15,7 @@ def to_bool_tensor(data, shape) -> t.Tensor: def from_bool_tensor(other: t.Tensor) -> t.Tensor: other = other.view(-1) if other.numel() % 8 != 0: - other = t.constant_pad_nd(other, (0, 8 - other.numel() % 8), 0) + other = t.constant_pad_nd(other, (0, (8 - other.numel() % 8) % 8), 0) size = len(other) // 8 data = ( other.reshape(size, 8).byte() << t.arange(8, device=other.device, dtype=t.uint8)