Skip to content

fix: Stop quantize_blockwise and quantize_4bit from mutating user-provided absmax#1863

Open
TimDettmers wants to merge 3 commits intomainfrom
fix/issue-1587
Open

fix: Stop quantize_blockwise and quantize_4bit from mutating user-provided absmax#1863
TimDettmers wants to merge 3 commits intomainfrom
fix/issue-1587

Conversation

@TimDettmers
Copy link
Collaborator

Summary

  • quantize_blockwise and quantize_4bit silently mutated user-provided absmax tensors via in-place copy_(), overwriting the caller's data as a side effect
  • Removed the mutation — the internally computed absmax is already correctly stored in the returned QuantState, so writing into the user's tensor was unnecessary
  • Added regression tests for both functions (CPU + CUDA, fp4 + nf4)

Fixes #1587

Test plan

  • test_quantize_blockwise_does_not_mutate_absmax — passes on CPU and CUDA
  • test_quantize_4bit_does_not_mutate_absmax — passes on CPU and CUDA for both fp4 and nf4
  • Existing test_dynamic_blockwise_quantization and test_4bit_quant tests still pass

🤖 Generated with Claude Code

TimDettmers and others added 2 commits February 14, 2026 01:28
Worker agents were running the full test suite (10+ min) which is
wasteful when only a small area of code changed. Updated the completion
workflow to instruct agents to run only relevant test files/functions.
The full suite will be run separately later.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…vided absmax

Both `quantize_blockwise` and `quantize_4bit` used `absmax.copy_()` to
write the internally computed absmax into the user-provided tensor,
silently mutating the caller's data. Remove the mutation so user tensors
are left unchanged. The computed absmax is still correctly stored in the
returned QuantState.

Fixes #1587

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

lib.cquantize_blockwise_fp32 mutates absmax

1 participant