[PR #310] fix: correct operator precedence in pack_ue8m0_to_int assertion #356

Open
opened 2026-10-26 21:16:38 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/deepseek-ai/DeepGEMM/pull/310
Author: @kuishou68
Created: 4/19/2026
Status: 🔄 Open

Base: main ← Head: fix/issue-309-pack-ue8m0-assertion


📝 Commits (1)

  • 1436d10 fix: correct operator precedence in pack_ue8m0_to_int assertion (Closes #309)

📊 Changes

1 file changed (+1 additions, -1 deletions)

View changed files

📝 deep_gemm/utils/math.py (+1 -1)

📄 Description

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.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/deepseek-ai/DeepGEMM/pull/310 **Author:** [@kuishou68](https://github.com/kuishou68) **Created:** 4/19/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/issue-309-pack-ue8m0-assertion` --- ### 📝 Commits (1) - [`1436d10`](https://github.com/deepseek-ai/DeepGEMM/commit/1436d10523c13f3622f1f6ef8b598e85e4245f7a) fix: correct operator precedence in pack_ue8m0_to_int assertion (Closes #309) ### 📊 Changes **1 file changed** (+1 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `deep_gemm/utils/math.py` (+1 -1) </details> ### 📄 Description Closes #309 ## Problem In `deep_gemm/utils/math.py`, the `pack_ue8m0_to_int` function has an operator precedence bug in its assertion: ```python assert (x.view(torch.int) & ((1 << 23) - 1) == 0).all() ``` In Python, the `==` operator has **higher precedence** than `&`. So this is actually parsed as: ```python 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 `==`: ```python 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
deepseek-ai/DeepGEMM#356
No description provided.