Skip to content

[hipDNN] Add SDPA backward operation descriptor and backend lowering/lifting#5674

Merged
SamuelReeder merged 10 commits intodevelopfrom
users/sareeder/almiopen-1589/add-sdpa-backward-descriptor
Mar 25, 2026
Merged

[hipDNN] Add SDPA backward operation descriptor and backend lowering/lifting#5674
SamuelReeder merged 10 commits intodevelopfrom
users/sareeder/almiopen-1589/add-sdpa-backward-descriptor

Conversation

@SamuelReeder
Copy link
Copy Markdown
Contributor

@SamuelReeder SamuelReeder commented Mar 20, 2026

Motivation

SDPA (Scaled Dot-Product Attention) forward already has a C-API descriptor and backend lowering. This PR adds the corresponding backwards (bprop) path, enabling frontend SdpaBpropNode to be lowered to a backend SDPA_BPROP_OPERATION descriptor via the C-API.

Technical Details

Generated and integrated via the hipDNN codegen tool. Adds SdpaBpropOperationDescriptor implementing setAttribute/getAttribute/buildNode/finalize for all SDPA backward tensor and data fields (Q, K, V, O, dO, dQ, dK, dV, stats, attn_scale, dropout probability/seed/offset, causal mask flag).

SdpaBpropPacker.hpp packs frontend node attributes into the backend descriptor, while SdpaBpropUnpacker.hpp reconstructs the frontend node from a backend descriptor. The existing SdpaBpropNode is wired with create_operation() and unpack_from_descriptor() overrides.

Infrastructure changes include a new attribute range in HipdnnBackendAttributeName.h, a HIPDNN_BACKEND_SDPA_BPROP_OPERATION_DESCRIPTOR type in HipdnnBackendDescriptorType.h, and dispatch cases in DescriptorFactory.cpp, NodeFactory.cpp, and OperationUnpacker.hpp. String utility coverage is added in BackendEnumStringUtils.hpp.

Test Plan

  • TestSdpaBpropOperationDescriptor.cpp — 23 unit tests covering all attributes (set/get, finalize validation)
  • TestGraphDescriptorSdpaBprop.cpp — graph-level round-trip tests (serialize → deserialize → verify)
  • IntegrationSdpaBpropDescriptorLowering.cpp — 2 E2E frontend-to-backend lowering tests (explicit UIDs + auto-assigned UIDs)
  • TestBackendEnumStringUtils.cpp — string coverage for new descriptor type and attributes
  • ninja unit-check — 5307 tests pass

Submission Checklist

…tests

Adds the SDPA backwards (bprop) operation descriptor to the C-API and
wires backend lowering from the frontend node to the backend descriptor
using the codegen tool.

Changes:
- New: SdpaBpropOperationDescriptor (.hpp/.cpp) — backend descriptor impl
- New: SdpaBpropPacker.hpp — frontend-to-backend attribute packing
- New: SdpaBpropUnpacker.hpp — backend-to-frontend attribute unpacking
- New: SdpaBpropNode.hpp updated with create_operation/unpack overrides
- New: SdpaBpropConstants.hpp — test SDK constants
- New: TestSdpaBpropOperationDescriptor.cpp — unit tests (23 cases)
- New: TestGraphDescriptorSdpaBprop.cpp — graph round-trip tests
- New: IntegrationSdpaBpropDescriptorLowering.cpp — E2E lowering tests
- Modified: HipdnnBackendAttributeName.h — SDPA bprop attribute range
- Modified: HipdnnBackendDescriptorType.h — SDPA_BPROP_OPERATION descriptor type
- Modified: BackendEnumStringUtils.hpp — string utils for new type/attrs
- Modified: DescriptorFactory.cpp — factory case for SdpaBprop descriptor
- Modified: NodeFactory.cpp/.hpp — node factory case for SdpaBprop
- Modified: OperationUnpacker.hpp — unpacker dispatch case
- Modified: CMakeLists.txt files — new sources and tests registered

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 20, 2026

Codecov Report

❌ Patch coverage is 91.92688% with 106 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...clude/hipdnn_frontend/detail/SdpaBpropUnpacker.hpp 81.70% 11 Missing and 32 partials ⚠️
...include/hipdnn_frontend/detail/SdpaBpropPacker.hpp 79.67% 4 Missing and 33 partials ⚠️
...hipdnn_frontend/detail/DescriptorUnpackHelpers.hpp 18.18% 14 Missing and 4 partials ⚠️
...d/src/descriptors/SdpaBpropOperationDescriptor.cpp 99.24% 0 Missing and 5 partials ⚠️
...ckend/src/descriptors/DescriptorAttributeUtils.hpp 91.67% 1 Missing and 1 partial ⚠️
...end/include/hipdnn_frontend/node/SdpaBpropNode.hpp 88.89% 0 Missing and 1 partial ⚠️

❌ Your project status has failed because the head coverage (77.21%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #5674      +/-   ##
===========================================
+ Coverage    67.02%   67.06%   +0.03%     
===========================================
  Files         1853     1857       +4     
  Lines       286550   287515     +965     
  Branches     40271    40392     +121     
===========================================
+ Hits        192053   192795     +742     
- Misses       78033    78226     +193     
- Partials     16464    16494      +30     
Flag Coverage Δ *Carryforward flag
hipBLAS 90.67% <ø> (ø) Carriedforward from 40caf30
hipBLASLt 43.49% <ø> (ø) Carriedforward from 40caf30
hipCUB 82.21% <ø> (ø) Carriedforward from 40caf30
hipDNN 86.18% <91.93%> (+0.28%) ⬆️
hipFFT 56.31% <ø> (ø) Carriedforward from 40caf30
hipRAND 76.12% <ø> (ø) Carriedforward from 40caf30
hipSOLVER 68.73% <ø> (ø) Carriedforward from 40caf30
hipSPARSE 84.70% <ø> (ø) Carriedforward from 40caf30
rocBLAS 47.97% <ø> (ø) Carriedforward from 40caf30
rocFFT 47.88% <ø> (-0.95%) ⬇️ Carriedforward from 40caf30
rocRAND 57.07% <ø> (ø) Carriedforward from 40caf30
rocSOLVER 77.21% <ø> (ø) Carriedforward from 40caf30
rocSPARSE 71.48% <ø> (ø) Carriedforward from 40caf30

*This pull request uses carry forward flags. Click here to find out more.

Files with missing lines Coverage Δ
...ects/hipdnn/backend/src/BackendEnumStringUtils.hpp 100.00% <100.00%> (ø)
...pdnn/backend/src/descriptors/DescriptorFactory.cpp 96.23% <100.00%> (+0.11%) ⬆️
...cts/hipdnn/backend/src/descriptors/NodeFactory.cpp 100.00% <100.00%> (ø)
...d/src/descriptors/SdpaBpropOperationDescriptor.hpp 100.00% <100.00%> (ø)
...d/src/descriptors/SdpaFpropOperationDescriptor.cpp 99.50% <100.00%> (+0.47%) ⬆️
...clude/hipdnn_frontend/detail/OperationUnpacker.hpp 100.00% <100.00%> (ø)
...end/include/hipdnn_frontend/node/SdpaBpropNode.hpp 91.48% <88.89%> (+8.37%) ⬆️
...ckend/src/descriptors/DescriptorAttributeUtils.hpp 93.70% <91.67%> (-0.47%) ⬇️
...d/src/descriptors/SdpaBpropOperationDescriptor.cpp 99.24% <99.24%> (ø)
...hipdnn_frontend/detail/DescriptorUnpackHelpers.hpp 88.10% <18.18%> (-5.55%) ⬇️
... and 2 more

... and 44 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

SamuelReeder and others added 2 commits March 20, 2026 20:40
Fix the SdpaBpropPacker to pack the operation name (was silently
dropped). Fix UID collisions in SdpaBpropConstants (50-69 -> 90-109
to avoid overlap with BlockScaleDequantize).

Comprehensive test coverage improvements:
- Integration tests: verify all tensor properties (UID, dims, strides,
  data type, name), all scalar/boolean/enum fields, optional tensor
  presence/absence. Add AutoAssignedUids and OperationNameRoundTrip tests.
- Backend descriptor tests: add fromNode() coverage (required-only, all
  fields, name preservation, missing required, absent optional in map),
  getAttribute() for all attributes (set/unset), setAttribute() negative
  cases (wrong type/count/null/unfinalized), graph serialization with
  exact tensor counts and full field verification.

Test count: 5307 -> 5378 (71 new tests), all passing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@SamuelReeder SamuelReeder marked this pull request as ready for review March 23, 2026 14:12
@SamuelReeder SamuelReeder requested a review from a team as a code owner March 23, 2026 14:12
@SamuelReeder SamuelReeder changed the title [hipDNN] Add SDPA backward operation descriptor and backend lowering [hipDNN] Add SDPA backward operation descriptor and backend lowering/lifting Mar 23, 2026
SamuelReeder and others added 3 commits March 23, 2026 17:29
- Add HIPDNN_ATTR_OPERATION_TYPE_EXT to SdpaBpropOperationDescriptor::getAttribute()
  so the lifting path can determine operation type during graph reconstruction
- Add IntegrationSdpaBpropLifting integration tests covering C-API round-trip,
  tensor sharing, serialization without finalization, attn scale, attn mask,
  and graph name preservation
- Add CreatesSdpaBpropNode test to TestOperationUnpacker
- Improve GetTensorDescriptors and GetTensorDescriptorsRequiredOnly to verify
  individual tensor dims and strides, not just UID presence
- Fix test constant UID collisions (shifted to 90-109 range)
- Improve integration tests: verify all optional tensors survive round-trip,
  use for loop in GetOptionalTensorUnsetReturnsCount0

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Comment thread projects/hipdnn/tests/frontend/IntegrationSdpaBpropDescriptorLowering.cpp Outdated
Comment thread projects/hipdnn/tests/frontend/IntegrationSdpaBpropLifting.cpp
Comment thread projects/hipdnn/backend/src/descriptors/NodeFactory.cpp
Comment thread projects/hipdnn/frontend/include/hipdnn_frontend/detail/SdpaBpropUnpacker.hpp Outdated
Comment thread projects/hipdnn/frontend/include/hipdnn_frontend/detail/SdpaBpropUnpacker.hpp Outdated
Comment thread projects/hipdnn/backend/src/descriptors/SdpaBpropOperationDescriptor.cpp Outdated
Comment thread projects/hipdnn/backend/src/descriptors/SdpaBpropOperationDescriptor.cpp Outdated
Comment thread projects/hipdnn/backend/src/descriptors/SdpaBpropOperationDescriptor.cpp Outdated
Copy link
Copy Markdown
Contributor

@BrianHarrisonAMD BrianHarrisonAMD left a comment

Choose a reason for hiding this comment

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

Approving, but we should fix comments before merging.

…iopen-1589/add-sdpa-backward-descriptor

# Conflicts:
#	projects/hipdnn/backend/tests/descriptors/TestNodeFactory.cpp
SamuelReeder and others added 2 commits March 24, 2026 17:50
Renumber SDPA bprop attribute range to 3100-3199 (CustomOp claims 3000-3099)
and descriptor type to 30 (CustomOp claims 29). Keep both in BackendEnumStringUtils
and DescriptorFactory.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@SamuelReeder SamuelReeder merged commit 4ab1ea6 into develop Mar 25, 2026
23 checks passed
@SamuelReeder SamuelReeder deleted the users/sareeder/almiopen-1589/add-sdpa-backward-descriptor branch March 25, 2026 02:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants