You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Bitpacking default pack and unpack dimensions do not round-trip multidimensional tensors #4815
The optimized pack() and unpack() helpers have incompatible default dimensions: pack(..., dim=-1) packs the last dimension, while unpack(..., dim=0) expands the first dimension. As a result, the documented default round trip only works for one-dimensional tensors.
The CPU reference pair (pack_cpu / unpack_cpu) already uses dim=-1 consistently, and TorchAO's internal UIntxTensor callers pass an explicit dimension.
Proposed fix
Change unpack()'s default to dim=-1 so the optimized pair has the same default contract as the CPU pair, and add a multidimensional round-trip regression covering bit widths 1 through 7. I have this small fix ready.
Hi! I reproduced this issue on CPU using TorchAO's main branch (commit c54ce72).
When calling unpack(pack(x, 4), 4) on a tensor of shape (8, 16), the resulting tensor has shape (16, 8), and the round-trip equality check fails.
Explicitly specifying dim=-1 in both calls fixes the issue.
I noticed you mentioned having a fix ready. Are you planning to submit a PR? If not, I'd be happy to work on the fix and add regression tests.
Thank you!
Activity
Pratyush439 commentedon Oct 11, 2026
Hi! I reproduced this issue on CPU using TorchAO's main branch (commit c54ce72).
When calling unpack(pack(x, 4), 4) on a tensor of shape (8, 16), the resulting tensor has shape (16, 8), and the round-trip equality check fails.
Explicitly specifying dim=-1 in both calls fixes the issue.
I noticed you mentioned having a fix ready. Are you planning to submit a PR? If not, I'd be happy to work on the fix and add regression tests.
Thank you!