mirror of
https://github.com/deepseek-ai/DeepGEMM.git
synced 2026-11-05 00:47:26 +00:00
[GH-ISSUE #309] fix: operator precedence bug in pack_ue8m0_to_int assertion (mantissa check always passes) #154
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
deepseek-ai/DeepGEMM#154
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @kuishou68 on GitHub (Apr 19, 2026).
Original GitHub issue: https://github.com/deepseek-ai/DeepGEMM/issues/309
In
deep_gemm/utils/math.py, thepack_ue8m0_to_intfunction has an operator precedence bug that makes the validation assertion ineffective.Bug
In Python,
==has higher precedence than&. So the expression is parsed as:((1 << 23) - 1) == 0evaluates toFalse(which is0numerically), thenx.view(torch.int) & 0gives all zeros, and.all()on all zeros returnsTrue.This means the assertion always passes regardless of whether the mantissa bits are actually zero, so it silently accepts invalid inputs instead of catching them.
Fix
Add parentheses to ensure the AND operation happens before the equality check:
This correctly checks that all mantissa bits (lower 23 bits) are zero, which is the intended behavior for UE8M0 format values.
@kuishou68 commented on GitHub (Apr 19, 2026):
I've opened PR #310 to fix this issue.