Skip to content

fix: cast fp32 block scales to UE8M0 before packing on SM100#3

Open
ipiszy wants to merge 2 commits into
mainfrom
fix/cast-fp32-to-ue8m0-on-pack
Open

fix: cast fp32 block scales to UE8M0 before packing on SM100#3
ipiszy wants to merge 2 commits into
mainfrom
fix/cast-fp32-to-ue8m0-on-pack

Conversation

@ipiszy

@ipiszy ipiszy commented Jun 27, 2026

Copy link
Copy Markdown

Summary

  • Replace UE8M0 packing device asserts with an explicit power-of-2 cast in smxx_layout.cuh.
  • Match the torch fallback path by rounding fp32 scales before exponent packing.

Why

DeepGEMM 2.6.1 asserts when masked MoE scale buffers contain non-UE8M0 fp32 values (including padded rows). The SM100 transform path with disable_ue8m0_cast=false should cast inputs to UE8M0, not require callers to pre-sanitize buffers.

Test plan

  • Text CUDA B200 TestDeepseek3.test_dsv2 on fireworks PR after bumping to this commit

Made with Cursor

Replace device asserts in the UE8M0 layout pack kernels with an explicit
power-of-2 cast so disable_ue8m0_cast=false can safely transform arbitrary
fp32 scale buffers (including padded masked-MoE rows) on Blackwell.

Co-authored-by: Cursor <cursoragent@cursor.com>
Comment thread deep_gemm/include/deep_gemm/impls/smxx_layout.cuh Outdated
Comment thread deep_gemm/include/deep_gemm/impls/smxx_layout.cuh Outdated

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale comment

Risk: medium. Cursor Bugbot completed with status skipping and no Bugbot review comment was found, so auto-approval is withheld. Requesting human review of the UE8M0 casting change in the SM100 pack kernels.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver

@cursor cursor Bot requested a review from vipulSharma18 June 27, 2026 06:31
@vipulSharma18

Copy link
Copy Markdown
Member

Please check fireworks code for parity. Deepgemm or flash MLA was breaking in the past and leading to quality issue due to quantization logic difference between fireworks triton kernels and their helpers. Clamp and saturation go a long way to end quality.

Drop the UE8M0 device asserts added in 353753e and the follow-up cast.
Pack fp32 block scales by shifting exponent bits into the int32 layout, matching
pre-353753e behavior while keeping PSUM layout support.

Co-authored-by: Cursor <cursoragent@cursor.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit b95c96e. Configure here.

const auto sf_k_idx = sf_k_pack_idx * 4 + j;
values[j] = valid_mn and sf_k_idx < SF_K ? ptx::ld_shared(sf_smem_buffer + mn_idx * SF_K + sf_k_idx) : 0;
// FP32 SFs must have a zero sign and mantissa (only the exponent is packed)
DG_DEVICE_ASSERT((values[j] & 0x807fffffu) == 0);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing UE8M0 cast before pack

High Severity

The UE8M0 packing asserts were removed, but fp32 block scales are still packed by shifting raw IEEE bits (>> 23) with no power-of-two rounding. Non-UE8M0 scales (nonzero mantissa) therefore encode a floored exponent instead of the rounded UE8M0 code used by ceil_to_ue8m0, tilelang get_sf_and_inv, and fast_log2_ceil/fast_pow2, which can skew SM100 GEMM dequantization and model quality.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit b95c96e. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Risk: medium. Not approving: Cursor Bugbot finished with status skipping and reported 1 unresolved finding (missing UE8M0 cast before exponent packing in smxx_layout.cuh). Human review is required; vipulSharma18 is already requested and zheanxu was added as a second reviewer.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver

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.

2 participants