← Back to Pull requests

Zero the padding of MXFP4 scale tensors allocated in C++ #813

Closed
unknown closed this pull request without merging on Nov 24, 2026 16:38 UTC
View on GitHub
unknown unknown commented on Nov 23, 2026 04:00 UTC
Author

Problem

tests/pytorch/mxfp4/test_mxfp4_module_exact.py fails intermittently on MI355X with NaN output, e.g. test_mxfp4_linear_versus_reference[with_hadamard-single_step-torch.bfloat16-no_bias-128-256] in run 45064495409. Beyond the tests, any MXFP4 GEMM with K=128 can return wrong values or NaN, depending on what memory the allocator hands out.

Root cause

MXFP4Quantizer allocates its scale tensors in C++ with at::empty. They are padded: rows to a multiple of 256, scale columns to a multiple of 8. The cast kernel writes only the scales of real 32-element blocks, but the AITER a4w4 GEMM also reads the padding when K is not a multiple of 256, so leftover bytes end up in the result (0xFF is NaN in E8M0). The Python allocator, MXFP4Quantizer.make_empty, which the Triton cast path also uses, already zeroes these tensors.

Fix

create_tensor, create_grouped_tensor and convert_and_update_tensor allocate padded scale tensors with at::zeros. Unpadded ones keep at::empty, so aligned shapes pay nothing.

Testing (MI355X, ROCm 10.1)

  • New test_quantization_zeroes_scale_padding makes uninitialized memory read as 0xFF (torch.utils.deterministic.fill_uninitialized_memory) and checks that no scale byte is left unwritten. Without the fix 6 of its 8 cases fail; with it all pass.

  • With uninitialized memory poisoned the same way for the whole run, tests/pytorch/mxfp4/ fails 12 tests without the fix (every Linear and LayerNorm/RMSNorm-Linear case with a K=128 GEMM). With the fix it passes, 917 passed and 8 skipped, both poisoned and normally.
  • Diff: 208 lines (+156 / -52) across 2 files Reviewer: matthiasdiener Review duration: 2197m
    All Vouch review confidence checks passed
    Residual risk 0.16 = Change Risk (0.36) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.36 · 208 lines diff across 2 files
    0.36
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.320
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #813"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 36.4% (MEDIUM) · Higher = larger blast radius
    36.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 15.8% · Safe to merge
    15.8%