Skip to content

mxfp8: add swizzled-scale fast path for cast-only quantization - #3338

Open
WanZzzzzz wants to merge 2 commits into
NVIDIA:mainfrom
WanZzzzzz:mxfp8-cast-swizzle-main
Open

mxfp8: add swizzled-scale fast path for cast-only quantization#3338
WanZzzzzz wants to merge 2 commits into
NVIDIA:mainfrom
WanZzzzzz:mxfp8-cast-swizzle-main

Conversation

@WanZzzzzz

Copy link
Copy Markdown
Contributor

Produce GEMM-ready scales directly in the specialized cast-only kernels to avoid separate scale-swizzle launches while preserving generic fallbacks for unsupported shapes.

Description

Please include a brief summary of the changes, relevant motivation and context.

Fixes # (issue)

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:

  • Change A
  • Change B

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

Produce GEMM-ready scales directly in the specialized cast-only kernels to avoid separate scale-swizzle launches while preserving generic fallbacks for unsupported shapes.

Signed-off-by: qiyuw <qiyuw@nvidia.com>
@github-actions github-actions Bot added the community-contribution PRs from external contributor outside the core maintainers, representing community-driven work. label Aug 10, 2026
@greptile-apps

greptile-apps Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR adds a Blackwell MXFP8 cast-only fast path that writes GEMM-swizzled rowwise and columnwise scales directly, avoiding a separate swizzle launch while retaining generic fallback behavior.

  • Extends specialized cast traits and scale-export logic for swizzled layouts.
  • Tightens specialized dispatch eligibility and preserves noop-aware cached outputs.
  • Clears padded scale regions before direct swizzled writes.
  • Adds C++ equivalence coverage and a PyTorch padding test.

Confidence Score: 5/5

The PR appears safe to merge; no concrete changed-code failure remains after checking specialized dispatch, scale indexing, padding, and noop behavior.

Reachable specialized shapes keep rowwise shared-memory accesses within their per-CTA scale storage, while padding initialization and noop-aware fallback preserve the existing output contract.

Important Files Changed

Filename Overview
transformer_engine/common/cast/mxfp8/quantize_mxfp8.cuh Adds noop-aware padding initialization and dispatches eligible swizzled cast-only operations to specialized traits while preserving generic fallbacks.
transformer_engine/common/cast/mxfp8/specialized/quantize_mxfp8.cuh Implements direct GEMM-swizzled rowwise and cached columnwise scale export with bounded tail handling and updated trait metadata.
tests/cpp/operator/test_cast_mxfp8.cu Adds byte-exact comparisons between direct-swizzled specialized output and linear-cast-plus-swizzle references across representative shapes and dtypes.
tests/pytorch/mxfp8/test_mxfp8_quantize_swizzle_fusion.py Verifies that direct bidirectional swizzled quantization leaves padded row-scale bytes zero.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[MXFP8 quantize request] --> B{Cast-only specialization supported?}
  B -->|No| G[Generic quantization kernel]
  B -->|Yes| C{Shape chunks and grid supported?}
  C -->|No| G
  C -->|Yes| D{Device noop pointer absent?}
  D -->|No| G
  D -->|Yes| E{GEMM-swizzled scales requested?}
  E -->|No| F[Specialized compact-scale cast]
  E -->|Yes| H[Specialized direct-swizzled cast]
  H --> I[GEMM-ready FP8 data and scales]
  F --> I
  G --> I
Loading

Reviews (1): Last reviewed commit: "[pre-commit.ci] auto fixes from pre-comm..." | Re-trigger Greptile

@Oleg-Goncharov

Copy link
Copy Markdown
Collaborator

/te-ci

@Oleg-Goncharov Oleg-Goncharov left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@ptrendx ptrendx added the 2.19 label Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.19 community-contribution PRs from external contributor outside the core maintainers, representing community-driven work.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants