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 }}
Repository navigation
quantize_blockwise / dequantize_blockwise produce incorrect results for non-contiguous CPU inputs (CPU follow-up to #1690) #1995
Follow-up to #1690 / #1342 — the CPU backend was not covered by the fix.
Those issues were closed by #1859, which added A = A.contiguous() to the CUDA kernels only. The CPU backend still exhibits the silent-corruption bug exactly as described in #1690: quantize_blockwise / dequantize_blockwise return wrong results for non-contiguous inputs instead of either handling them or raising. The MPS backend is unaffected (it copies via reshape).
Both calls quantize mathematically identical data, yet produce completely different results — the non-contiguous call reads the underlying buffer in physical order rather than logical order, and no error is raised.
Verified across fp16 / bf16 / fp32 × blocksize 64 / 128 / 256, for both quantize_blockwise and dequantize_blockwise (18/18 combinations fail). This is the same bug class as #1342 / #1690, now isolated to the CPU backend.
Expected behavior
Quantizing/dequantizing a non-contiguous tensor on CPU should give identical results to its .contiguous() equivalent — matching the CUDA backend's behavior after #1859.
I'd be happy to open a PR for the CPU fix. One question on the preferred approach, since #1690 raised both: should the CPU kernels auto-convert with A = A.contiguous() (matching the CUDA fix in #1859), or raise on non-contiguous input? I'll follow whichever you prefer, and include regression tests (extending TestNonContiguousInputs to CPU).
Activity
matthewdouglas commentedon Jul 9, 2026
Hi,
I think it would be reasonable to do what we're doing on the CUDA backend and use
A.contiguous()here. Thanks!Handle non-contiguous inputs in CPU blockwise quant/dequant
Handle non-contiguous inputs in CPU blockwise quant/dequant (bitsandb…