← Back to Pull requests

[GPU] Allow bf16 input transposes to fuse into SDPA (TransposeSDPAMatcher) #38122

Merged
clee30 merged 6 files (171 lines) on Sep 21, 2026 10:47 UTC
View on GitHub
clee30 clee30 commented on Sep 14, 2026 10:13 UTC
Author

TransposeSDPAMatcher / TransposeVLSDPAMatcher fold q/k/v Transpose ops into the internal SDPA op's input transpose orders so the SDPA kernel reads the natural [B,S,H,D] layout. The pattern predicate (is_fp_type) only allowed f16/f32 tensors, so under the bf16 inference hint every pre-SDPA transpose stayed as a standalone permute kernel.

Tickets:


- CVS-192281

AI Assistance:


- AI assistance used: no / yes
- If yes, summarize how AI was used and what human validation was performed (build/tests/manual checks).

Diff: 171 lines (+111 / -60) across 6 files Reviewer: v-Golubev Review duration: 10113m
All Vouch review confidence checks passed
Residual risk 0.05 = Change Risk (0.41) × (1 − Review Confidence (0.87)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.41 · 171 lines diff across 6 files
0.41
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.83 · 5 substantive comment(s)
0.83
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
87%
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.308
Real PR Conversation Timeline
14 items
v-Golubev v-Golubev commented on code on Sep 14, 2026 10:55 UTC
Code Review
src/plugins/intel_gpu/src/plugin/transformations/transpose_fusion.cpp:1
@@ -91,6 +91,7 @@ TransposeFusion::TransposeFusion(bool supports_immad) {
 TransposeVLSDPAMatcher::TransposeVLSDPAMatcher() {
     auto is_fp_type = [](const ov::Output<ov::Node>& output) -> bool {

Could you please use pattern::type_matches_any instead of a custom predicate? The same in TransposeSDPAMatcher.

Also, it would be great to store sdpa_supported_precisions list in one place (as a static SDPA node function, for example) and reuse it everywhere: this would allow to avoid code modifications in several places when new precision is supported by the GPU node. What do you think?

v-Golubev v-Golubev commented on code on Sep 14, 2026 11:06 UTC
Code Review
src/plugins/intel_gpu/tests/unit/transformations/transpose_vlsdpa_fusion_test.cpp:1
@@ -29,10 +29,10 @@ namespace intel_gpu {
 namespace {
 const std::string mask_name = "cu_seq_lens";
 
-std::shared_ptr<ov::Model> build_model() {
-    auto q = std::make_shared<Parameter>(element::f32, PartialShape{-1,8,32});  /* L,H,S */
-    auto k = std::make_shared<Parameter>(element::f32, PartialShape{-1,8,32});
-    auto v = std::make_shared<Parameter>(element::f32, PartialShape{-1,8,32});
+std::shared_ptr<ov::Model> build_model(ov::element::Type et = ov::element::f32) {

Could you please also add f16 test case? It looks like we can easily parametrize the existing tests by input precision

v-Golubev v-Golubev commented on code on Sep 14, 2026 11:06 UTC
Code Review
src/plugins/intel_gpu/tests/unit/transformations/transpose_sdpa_fusion_test.cpp:1
@@ -202,6 +202,45 @@ TEST_F(TransformationTestsF, TranposeSDPAFusion5) {
     }
 }
 
+TEST_F(TransformationTestsF, TransposeSDPAFusionBF16AllInputs) {

Could you please also add f16 test case?

clee30 clee30 commented on code on Sep 15, 2026 02:06 UTC
Code Review
src/plugins/intel_gpu/src/plugin/transformations/transpose_fusion.cpp:1
@@ -91,6 +91,7 @@ TransposeFusion::TransposeFusion(bool supports_immad) {
 TransposeVLSDPAMatcher::TransposeVLSDPAMatcher() {
     auto is_fp_type = [](const ov::Output<ov::Node>& output) -> bool {

Good idea. Make the changes.

clee30 clee30 commented on code on Sep 15, 2026 02:06 UTC
Code Review
src/plugins/intel_gpu/tests/unit/transformations/transpose_vlsdpa_fusion_test.cpp:1
@@ -29,10 +29,10 @@ namespace intel_gpu {
 namespace {
 const std::string mask_name = "cu_seq_lens";
 
-std::shared_ptr<ov::Model> build_model() {
-    auto q = std::make_shared<Parameter>(element::f32, PartialShape{-1,8,32});  /* L,H,S */
-    auto k = std::make_shared<Parameter>(element::f32, PartialShape{-1,8,32});
-    auto v = std::make_shared<Parameter>(element::f32, PartialShape{-1,8,32});
+std::shared_ptr<ov::Model> build_model(ov::element::Type et = ov::element::f32) {

done

clee30 clee30 commented on code on Sep 15, 2026 02:06 UTC
Code Review
src/plugins/intel_gpu/tests/unit/transformations/transpose_sdpa_fusion_test.cpp:1
@@ -202,6 +202,45 @@ TEST_F(TransformationTestsF, TranposeSDPAFusion5) {
     }
 }
 
+TEST_F(TransformationTestsF, TransposeSDPAFusionBF16AllInputs) {

Done

v-Golubev v-Golubev commented on code on Sep 15, 2026 10:01 UTC
Code Review
src/plugins/intel_gpu/include/intel_gpu/op/sdpa.hpp:1
@@ -66,6 +66,15 @@ class SDPA : public ov::op::v13::ScaledDotProductAttention {
         return order;
     }
 
+    static const std::vector<ov::element::Type>& get_supported_precisions() {

Shouldn't we also verify precisions in SDPA::validate_and_infer_types?

clee30 clee30 commented on code on Sep 15, 2026 13:22 UTC
Code Review
src/plugins/intel_gpu/include/intel_gpu/op/sdpa.hpp:1
@@ -66,6 +66,15 @@ class SDPA : public ov::op::v13::ScaledDotProductAttention {
         return order;
     }
 
+    static const std::vector<ov::element::Type>& get_supported_precisions() {

I would rather leave this to kernel implementation like validate_impl. Currently, the rest of intel_gpu custom ops doesn't assert precision set in validate_and_infer_types().

v-Golubev v-Golubev commented on code on Sep 16, 2026 11:24 UTC
Code Review
src/plugins/intel_gpu/include/intel_gpu/op/sdpa.hpp:1
@@ -66,6 +66,15 @@ class SDPA : public ov::op::v13::ScaledDotProductAttention {
         return order;
     }
 
+    static const std::vector<ov::element::Type>& get_supported_precisions() {

Wouldn't this lead to a more difficult-to-debug situation when an operation is created with an unsupported precision? In that case, we would only get an exception at the kernel creation stage, instead of catching it earlier during model compilation

clee30 clee30 commented on code on Sep 17, 2026 01:56 UTC
Code Review
src/plugins/intel_gpu/include/intel_gpu/op/sdpa.hpp:1
@@ -66,6 +66,15 @@ class SDPA : public ov::op::v13::ScaledDotProductAttention {
         return order;
     }
 
+    static const std::vector<ov::element::Type>& get_supported_precisions() {

Yes, adding validate_and_infer_types can catch during graph construction for fail early detection. However, if a new precision type that add in kernel but not add here, it will fail in validate_and_infer_types check. As other intel_gpu custom ops doesn't add the check, that why not plan to add here.

v-Golubev v-Golubev commented on code on Sep 18, 2026 10:21 UTC
Code Review
src/plugins/intel_gpu/include/intel_gpu/op/sdpa.hpp:1
@@ -66,6 +66,15 @@ class SDPA : public ov::op::v13::ScaledDotProductAttention {
         return order;
     }
 
+    static const std::vector<ov::element::Type>& get_supported_precisions() {

From my perspective, the best solution here is to enable such checks for all gpu custom ops. But I agree that this is out of scope of the current PR, and this activity requires a broader discussion
@isanghao could you please share your thoughts on that?

v-Golubev v-Golubev approved these changes on Sep 18, 2026 10:21 UTC
Approved Reviewer

Approved these changes.

p-durandin p-durandin approved these changes on Sep 21, 2026 09:09 UTC
Approved Reviewer

Approved these changes.

Reviewers
Assignees
clee30 clee30
Labels
risk: low confidence: 87.1% 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: 41.1% (MEDIUM) · Higher = larger blast radius
41.1%
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: 87.1% · Lower = rushed or shallow review
87.1%
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: 5.3% · Safe to merge
5.3%