← Back to Pull requests

[JAX] Let XLA CSE identical MXFP8 quantizes and drop the per-quantize placeholders #3917

Open
unknown opened this pull request with 335 lines diff across 4 files
View on GitHub
unknown unknown commented on Nov 22, 2026 20:16 UTC
Author

Description

Two small changes to the JAX quantize primitive in transformer_engine/jax/cpp_extensions/quantization.py, so that XLA can CSE identical MXFP8 quantizes and stops inserting a copy before each one.

  • Amax alias. The quantize FFI is lowered with operand_output_aliases={2: 4}, donating the amax operand to updated_amax. The FFI only writes updated_amax for tensor scaling. For MXFP8, amax is a constant zero that is never written. The alias still made XLA insert a 4-byte D2D copy before every quantize, and it gave each quantize its own output buffer. That kept otherwise identical quantizes distinct.

  • Placeholders. The scale and rht_matrix placeholders in _quantize_dbias_impl were jnp.empty. That lowers to one AllocateBuffer custom call per quantize, so two quantizes of the same tensor never had identical operands and could not be CSE'd. This happens, for example, when one activation feeds several projections.
  • Measured on a DeepSeek-V4 MaxText training stack (GB300, MXFP8 recipe):

  • Outputs, dx and dW are bit-exact against the unpatched build.

  • Custom-made Quantize microbenchmark: 1.915 → 1.431 ms.

  • 8-layer, 4-GPU proxy: −4.85 ms/step. Quantize kernels per step drop from 440 to 344, and copy kernels from 602 to 164.

  • Full model, 8 nodes × 4 GB300: about −25 ms/step.
  • Fixes # (none)

    Type of change

  • Documentation change (change only to the documentation, either a fix or a new content)

  • Bug fix (non-breaking change which fixes an issue)

  • New feature (non-breaking change which adds functionality)

  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

  • Infra/Build change

  • Code refactoring
  • Changes

    Please list the changes introduced in this PR:

  • For MXFP8, lower the quantize FFI without the amax → updated_amax alias, and have impl() pass the input amax through as updated_amax. Tensor scaling and NVFP4 keep the alias.

  • Use jnp.zeros constants instead of jnp.empty for the scale and rht_matrix placeholders in _quantize_dbias_impl. When a real scale or RHT matrix is needed, it still replaces the placeholder as before.
  • Checklist:

  • I have read and followed the contributing guidelines

  • The functionality is complete

  • I have commented my code, particularly in hard-to-understand areas

  • I have made corresponding changes to the documentation

  • My changes generate no new warnings

  • I have added tests that prove my fix is effective or that my feature works

  • New and existing unit tests pass locally with my changes
  • Diff: 335 lines (+251 / -84) across 4 files Reviewer: greptile-apps[bot] Review duration: 10m
    All Vouch review confidence checks passed
    Residual risk 0.22 = Change Risk (0.42) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.42 · 335 lines diff across 4 files
    0.42
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    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.348
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #3917"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% 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: 42.2% (MEDIUM) · Higher = larger blast radius
    42.2%
    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: 46.7% · Lower = rushed or shallow review
    46.7%
    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: 22.5% · Safe to merge
    22.5%