Skip to content

Fix truncated FP4 constant in Triton dequantize_fp4_tree - #2026

Merged
matthewdouglas merged 3 commits into
bitsandbytes-foundation:mainfrom
Anai-Guo:fix-triton-fp4-constant
Jul 29, 2026
Merged

Fix truncated FP4 constant in Triton dequantize_fp4_tree#2026
matthewdouglas merged 3 commits into
bitsandbytes-foundation:mainfrom
Anai-Guo:fix-triton-fp4-constant

Conversation

@Anai-Guo

Copy link
Copy Markdown
Contributor

Summary

dequantize_fp4_tree in the Triton backend writes the smallest nonzero FP4 magnitude (4-bit codes 0b0001/0b1001) as the literal 0.00520833. That rounds to 0x3BAAAAA4 in float32, which is 7 ULP away from the value every other FP4 table in the repo uses:

source literal float32 bits
csrc/kernels.cu fp4_dequantization_lut 0.005208333333f 0x3BAAAAAB
csrc/gemm_4bit_common.cuh FP4_LUT_F32 0.005208333333f 0x3BAAAAAB
csrc/cpu_ops.cpp fp4_lut / AVX-512 LUT 0.005208333333f 0x3BAAAAAB
functional.py get_4bit_type("fp4") 0.0625 / 12 0x3BAAAAAB
backends/triton/kernels_4bit.py (before) 0.00520833 0x3BAAAAA4

The intended value is 1/192 (0.0625 / 12: the FP4 subnormal 0.0625 normalized by the format absmax of 12). This PR restores the full-precision literal so the Triton/XPU path dequantizes codes 1 and 9 bit-for-bit identically to the CUDA and CPU backends.

One-character-class change; no behavior change for any other code.

Fixes #2025

🤖 Generated with Claude Code

The magnitude of the smallest nonzero FP4 level (codes 0b0001/0b1001) was
written as 0.00520833, which rounds to a different float32 (0x3BAAAAA4)
than every other FP4 table in the repository. The CUDA kernel, CPU kernel,
4-bit GEMM LUT, and the get_4bit_type("fp4") Python table all use
1/192 = 0.005208333333 (0x3BAAAAAB). Use the full-precision literal so the
Triton backend agrees with the other backends bit-for-bit.

Fixes bitsandbytes-foundation#2025
@matthewdouglas matthewdouglas added this to the v0.50.1 milestone Jul 29, 2026
@github-actions

Copy link
Copy Markdown

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.

@matthewdouglas

Copy link
Copy Markdown
Member

Thanks. This is reasonable. I can merge it if you'll fix the end of line issue from the lint check.

@Anai-Guo

Copy link
Copy Markdown
Contributor Author

Thanks @matthewdouglas! Fixed the missing end-of-file newline that ruff (W292) flagged — should be green now.

@matthewdouglas
matthewdouglas merged commit a2b90e6 into bitsandbytes-foundation:main Jul 29, 2026
86 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Triton FP4 dequantization has a truncated constant, disagreeing with CUDA/CPU by 7 ULP

2 participants