Skip to content

Fix architecture-independent SDPA repro failures - #386

Merged
hwanseoc merged 9 commits into
NVIDIA:developfrom
hwanseoc:hwanseoc/restore-sdpa-repro-tensor-dumps
Jul 14, 2026
Merged

Fix architecture-independent SDPA repro failures#386
hwanseoc merged 9 commits into
NVIDIA:developfrom
hwanseoc:hwanseoc/restore-sdpa-repro-tensor-dumps

Conversation

@hwanseoc

@hwanseoc hwanseoc commented Jul 13, 2026

Copy link
Copy Markdown
Member

@coderabbitai ignore

Why

These are the repro fixes shared by the UID (#280) and hybrid TID+UID (#383) graph-JSON designs. They do not depend on either identity architecture.

Two independent failures remained:

  • the fast pointer-array execution path did not invoke tensor-dump logging, and Composite SDPA backward did not register sequence-length or ragged-offset tensors
  • FP8/MXFP8 --perf repros still built large references; large MXFP8 inputs also exceeded Transformer Engine's CUDA grid-y limit when quantized as one flattened tensor

Changes

Runtime tensor dumps

  • Adapt the fast path's UID/pointer arrays to the existing dump logger
  • Invoke it immediately before dispatch, after auxiliary workspace initialization
  • Register backward SEQ_LEN_Q, SEQ_LEN_KV, and Q/K/V/O/dO/Stats/dQ/dK/dV ragged-offset tensors
  • Deduplicate tensor-dump registrations by UID after collecting the complete graph subtree

FP8/MXFP8 repro testers

  • Skip forward/backward reference construction and comparison under --perf
  • Keep deterministic backward exact-equality checks enabled
  • Use GPU forward output and stats as backward inputs in MXFP8 perf mode
  • Avoid expanded FP32 MXFP8 scale references in perf mode
  • Quantize oversized MXFP8 inputs in aligned chunks, concatenate compact results, then apply the global TE GEMM scale swizzle
  • Add an MXFP8 perf integration test that fails if either reference function is called

Scope

This PR does not change graph JSON, graph identity, tensor identity, extraction schema, or log format. #280 and #383 both depend on it.

When tensor-dump logging is disabled, the fast-path adapter returns before allocating its UID map. With logging enabled, existing dump behavior includes device-to-host copies and stream synchronization.

Verification

NVIDIA B200, cuDNN backend 9.30:

  • Combined branch Python binding rebuild passed
  • Logged padded SDPA forward passed and emitted both sequence-length tensors
  • Logged deterministic SDPA backward passed; dQ/dK/dV matched bitwise and both sequence-length tensors were emitted on both executions
  • FP8 forward --perf passed
  • MXFP8 perf integration passed; forward and backward references were not called
  • MXFP8 deterministic backward dQ/dK/dV and all three amax outputs matched bitwise
  • MXFP8 non-perf reference comparison passed
  • Exact DSV3 sequence-16384 repro that previously exceeded TE's launch limit passed without CUDA OOM

MXFP8 verification used the supported PyTorch 26.05 container with PyTorch 2.12.0a0, CUDA 13.2, cuDNN 9.30, and Transformer Engine 2.15. During the original investigation, these tester fixes moved the supplied set from 2/60 to 60/60 passes and the deduplicated raw-log set from 385/445 to 445/445 passes.

Summary by CodeRabbit

  • New Features

    • Added tensor-dump support during graph execution, including relevant sequence-length and ragged-tensor metadata for attention workloads.
    • Added compact MXFP8 quantization for large tensors.
    • Added TransformerEngine version validation for MXFP8 workflows.
  • Performance

    • Improved performance-mode execution by skipping reference calculations and correctness comparisons when requested.
  • Tests

    • Added coverage confirming MXFP8 performance mode executes without reference computations.

@hwanseoc hwanseoc changed the title Restore SDPA repro tensor dumps Fix architecture-independent SDPA repro failures Jul 13, 2026
@hwanseoc

Copy link
Copy Markdown
Member Author

@CodeRabbit review

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The PR expands SDPA tensor dumping and adds performance-mode control to FP8 and MXFP8 tests, including optional reference computation, compact MXFP8 quantization, updated validation, and a dedicated performance test.

Changes

Tensor dump execution

Layer / File(s) Summary
Expanded SDPA dump collection
include/cudnn_frontend/node/scaled_dot_product_flash_attention.h
Backward dump collection deduplicates tensors and includes sequence-length tensors plus ragged offsets for inputs, statistics, and outputs.
Execution-time tensor logging
include/cudnn_frontend/graph_interface.h
Graph execution maps non-null tensor UIDs to prepared pointers and forwards them to the existing tensor-dump implementation.

FP8 performance paths

Layer / File(s) Summary
FP8 performance gating
test/python/sdpa/fp8.py
A centralized performance flag skips forward and backward reference calculations and correctness checks while preserving non-performance validation.
MXFP8 quantization contracts
test/python/sdpa/mxfp8.py
TransformerEngine version checks, compact row-chunk quantization, and optional reference scale computation are added.
MXFP8 execution and validation
test/python/sdpa/mxfp8.py, test/python/test_mhas_v2.py
MXFP8 execution uses centralized performance gating and updated stats wiring, with a test that verifies reference functions are not called in performance mode.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant exec_sdpa_mxfp8
  participant quantize_to_mxfp8
  participant cuDNN
  participant compute_ref
  exec_sdpa_mxfp8->>quantize_to_mxfp8: quantize with_ref=not perf
  quantize_to_mxfp8->>cuDNN: provide MXFP8 tensors and swizzled scales
  exec_sdpa_mxfp8->>cuDNN: execute forward and backward graphs
  alt perf disabled
    exec_sdpa_mxfp8->>compute_ref: compute reference outputs and gradients
    compute_ref-->>exec_sdpa_mxfp8: return references and amax values
  end
Loading

Suggested reviewers: anerudhan, egilliam-nv, yangxu1990uiuc, yanzhuo607, jhjpark

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main goal: fixing architecture-independent SDPA repro failures.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
test/python/sdpa/mxfp8.py (1)

35-57: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Chunked MXFP8 quantization relies on TE's private tensor attributes.

quantize_mxfp8_compact reaches into result._rowwise_data, result._rowwise_scale_inv, result._columnwise_data, result._columnwise_scale_inv — underscore-prefixed (private/internal) attributes of the TE-returned tensor — to manually reconstruct an MXFP8Tensor. The MXFP8_QUANTIZER_MAX_ROWS = 65535 * 64 constant does line up with CUDA's 65535 grid-y/z launch limit, and the reconstructed constructor kwargs (rowwise_data, rowwise_scale_inv, etc.) match TE's MXFP8TensorStorage/MXFP8Tensor public constructor signature, so the approach is plausible. However, depending on private instance attributes of a quantizer's return value is fragile against internal TE changes across versions (chunk-by-chunk quantization + concatenation of scale/data isn't part of TE's public API).

Consider filing/tracking this as a known coupling point, or checking if TE exposes any higher-level API for chunked quantization to reduce future breakage risk when TE internals change.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/python/sdpa/mxfp8.py` around lines 35 - 57, Review
quantize_mxfp8_compact for a supported Transformer Engine API for chunked MXFP8
quantization and concatenation, replacing direct access to the result private
attributes where possible. If no public API exists, document or track this
coupling explicitly while preserving the current MXFP8Tensor reconstruction
behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@include/cudnn_frontend/node/scaled_dot_product_flash_attention.h`:
- Around line 2188-2192: Update collect_tensors_to_dump_subtree() so tensor UIDs
are deduplicated across the entire subtree, not only within each node’s local
collection. Thread a shared std::unordered_set<Tensor_attributes::uid_t> through
recursive collection or deduplicate tensors_to_dump before final serialization,
preserving one dump entry per UID.

---

Nitpick comments:
In `@test/python/sdpa/mxfp8.py`:
- Around line 35-57: Review quantize_mxfp8_compact for a supported Transformer
Engine API for chunked MXFP8 quantization and concatenation, replacing direct
access to the result private attributes where possible. If no public API exists,
document or track this coupling explicitly while preserving the current
MXFP8Tensor reconstruction behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 3e8026dc-e1b0-41f9-8626-fc403159de80

📥 Commits

Reviewing files that changed from the base of the PR and between 526020e and f4e08f5.

📒 Files selected for processing (5)
  • include/cudnn_frontend/graph_interface.h
  • include/cudnn_frontend/node/scaled_dot_product_flash_attention.h
  • test/python/sdpa/fp8.py
  • test/python/sdpa/mxfp8.py
  • test/python/test_mhas_v2.py

Comment thread include/cudnn_frontend/node/scaled_dot_product_flash_attention.h Outdated
@hwanseoc

hwanseoc commented Jul 13, 2026

Copy link
Copy Markdown
Member Author

Evaluated the Transformer Engine coupling note. TE 2.12+ exposes get_metadata() but no MXFP8 concatenation operation. I tried the accessor refactor, then reverted it in 3e4266b because it replaced the direct storage access already required by this tester with repeated string-key dictionary lookups without changing behavior. The required reconstruction remains explicit here. MXFP8 perf integration still passes in TE 2.15, including chunked quantization above the monolithic launch limit.

@hwanseoc
hwanseoc requested review from Anerudhan and Copilot and removed request for Copilot July 13, 2026 19:21
@hwanseoc

Copy link
Copy Markdown
Member Author

@cudnn-ci-bot run

@cudnn-ci-bot

Copy link
Copy Markdown

🚀 Running mirror pipeline

Branch: cudnn-gh/pr-386-848ad26
Pipeline: 57854623

@NVIDIA NVIDIA deleted a comment from cudnn-ci-bot Jul 13, 2026
@NVIDIA NVIDIA deleted a comment from cudnn-ci-bot Jul 13, 2026
@NVIDIA NVIDIA deleted a comment from cudnn-ci-bot Jul 13, 2026
@NVIDIA NVIDIA deleted a comment from cudnn-ci-bot Jul 13, 2026

@Anerudhan Anerudhan 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

@hwanseoc
hwanseoc merged commit 693030e into NVIDIA:develop Jul 14, 2026
1 check passed
@Anerudhan Anerudhan mentioned this pull request Aug 6, 2026
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.

3 participants