Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
horheynm committed Dec 2, 2024
1 parent 568a4ac commit e5ea1c4
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ def pack_to_int32(value: torch.Tensor, num_bits: int) -> torch.Tensor:
if num_bits > 8:
raise ValueError("Packing is only supported for less than 8 bits")

if num_bits < 1:
raise ValueError(f"num_bits must be at least 1, got {num_bits}")

# convert to unsigned for packing
offset = 1 << (num_bits - 1)
value = (value + offset).to(torch.uint8)
Expand All @@ -184,7 +187,7 @@ def unpack_from_int32(
) -> torch.Tensor:
"""
Unpacks a tensor of packed int32 weights into individual int8s, maintaining the
original their bit range.
original bit range.
Return tensors in int8
Expand Down

0 comments on commit e5ea1c4

Please sign in to comment.