Skip to content

Respect metadata strides in CPU blockwise quantization - #2140

Draft
Afloat16 wants to merge 2 commits into
bitsandbytes-foundation:mainfrom
Afloat16:fix/cpu-blockwise-metadata-strides-20261113
Draft

Afloat16 wants to merge 2 commits into
bitsandbytes-foundation:mainfrom
Afloat16:fix/cpu-blockwise-metadata-strides-20261113

Conversation

@Afloat16

Copy link
Copy Markdown

Problem

The native CPU blockwise kernels read codebook and absmax pointers as contiguous float arrays. A valid strided codebook or scale tensor therefore produces different values from its contiguous copy. This also affects restored quantized weights and CPU Adam8bit state whose metadata is stored in views.

Changes

Make the codebook contiguous before CPU quantization, and make the codebook and scales contiguous before CPU dequantization. These are local kernel arguments: caller tensors and QuantState metadata retain their original values, storage and identity. Already contiguous metadata, including nonzero storage offsets, keeps the existing path.

Add tests for FP16, BF16 and FP32, strided/offset metadata, partial blocks, caller-provided quantization outputs, saved quantized weights used in a linear layer, and four actual Adam8bit training steps.

Validation

Native CPU source build and tests, source 11527a20279abe05140c9c154eefedba854acbdb:

  • Original source: 22 failed, 9 passed.
  • Patched source: all 31 new cases passed.
  • Existing CPU blockwise and noncontiguous-input coverage: 33 passed, 9 existing CPU skips.
  • Repository pre-commit hooks and git diff --check passed.

Ubuntu 24.04, Python 3.12, PyTorch 2.14.0+cpu. Built the repository's native CPU extension with CMake; no replacement kernel or numerical stub was used. The tests compare actual encoded values, decoded values, saved-weight linear outputs and optimizer continuation.

This is limited to CPU blockwise metadata handling. The existing LUT discretization and unsupported CPU dequantize_blockwise.out overload are unchanged; final fixtures exercise exact interior values and the supported dequantization entry point. GPU execution and model-quality improvements are not claimed.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant