豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

fix: correct operator precedence in pack_ue8m0_to_int assertion#310

Open
kuishou68 wants to merge 1 commit intodeepseek-ai:mainfrom
kuishou68:fix/issue-309-pack-ue8m0-assertion
Open

fix: correct operator precedence in pack_ue8m0_to_int assertion#310
kuishou68 wants to merge 1 commit intodeepseek-ai:mainfrom
kuishou68:fix/issue-309-pack-ue8m0-assertion

Conversation

@kuishou68
Copy link
Copy Markdown

Closes #309

Problem

In deep_gemm/utils/math.py, the pack_ue8m0_to_int function has an operator precedence bug in its assertion:

assert (x.view(torch.int) & ((1 << 23) - 1) == 0).all()

In Python, the == operator has higher precedence than &. So this is actually parsed as:

assert (x.view(torch.int) & (((1 << 23) - 1) == 0)).all()

((1 << 23) - 1) == 0 evaluates to False (i.e., 0), so x.view(torch.int) & 0 produces a tensor of all zeros. .all() on all zeros returns True.

The assertion always passes, never catching cases where mantissa bits are non-zero.

Fix

Added parentheses to ensure & is applied before ==:

assert ((x.view(torch.int) & ((1 << 23) - 1)) == 0).all()

This correctly verifies that the lower 23 mantissa bits are all zero, which is required for valid UE8M0 format floats.

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.

fix: operator precedence bug in pack_ue8m0_to_int assertion (mantissa check always passes)

1 participant