Skip to content

Fix sign-extension bug in fbgemm MX4 Python reference dequantize (#5706)#5706

Open
purvisa-at-meta wants to merge 2 commits intopytorch:mainfrom
purvisa-at-meta:export-D102195911
Open

Fix sign-extension bug in fbgemm MX4 Python reference dequantize (#5706)#5706
purvisa-at-meta wants to merge 2 commits intopytorch:mainfrom
purvisa-at-meta:export-D102195911

Conversation

@purvisa-at-meta
Copy link
Copy Markdown

@purvisa-at-meta purvisa-at-meta commented Apr 28, 2026

Summary:
X-link: https://github.com/facebookresearch/FBGEMM/pull/2643

py_dequantize_mx4 viewed packed data as int8 and subtracted
FP32_EXP_BIAS directly. For biased exponents >= 128, the int8 value
is negative, producing incorrect results. Fix by viewing as uint8
then casting to int32 before subtracting the bias.

Same class of bug as D101680517 and the Triton kernel fix.

GH PR: #5706

Reviewed By: q10

Differential Revision: D102195911

@meta-cla meta-cla Bot added the cla signed label Apr 28, 2026
@meta-codesync
Copy link
Copy Markdown
Contributor

meta-codesync Bot commented Apr 28, 2026

@purvisa-at-meta has exported this pull request. If you are a Meta employee, you can view the originating Diff in D102195911.

…h#5705)

Summary:
X-link: facebookresearch/FBGEMM#2642


Scale exponents are stored as uint8 bit patterns in int8 storage.
When cast to int16, biased values >= 128 were incorrectly sign-extended,
producing wildly wrong negative exponents. Apply & 0xFF mask to recover
the original unsigned value before subtracting FP32_EXP_BIAS.

Same fix as D101680517 but for the upstream fbgemm_gpu Triton kernel.

GH PR: pytorch#5705

Reviewed By: q10

Differential Revision: D102195912
…orch#5706)

Summary:
X-link: facebookresearch/FBGEMM#2643


py_dequantize_mx4 viewed packed data as int8 and subtracted
FP32_EXP_BIAS directly. For biased exponents >= 128, the int8 value
is negative, producing incorrect results. Fix by viewing as uint8
then casting to int32 before subtracting the bias.

Same class of bug as D101680517 and the Triton kernel fix.

GH PR: pytorch#5706

Reviewed By: q10

Differential Revision: D102195911
@meta-codesync meta-codesync Bot changed the title Fix sign-extension bug in fbgemm MX4 Python reference dequantize Fix sign-extension bug in fbgemm MX4 Python reference dequantize (#5706) Apr 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant