Skip to content

Commit ed3f8bf

Browse files
authored
Fix build errors of GridSample and test failures in test_attention_fusion.py (#27642)
# Description This PR addresses a build error and subsequent test failures related to recent changes in GridSample and the transformer optimizer. Related PRs: #27201, #27556. ## Changes ### 1. Fix GridSample Build Error - Removed an unused local variable `mode_str` in `onnxruntime/core/providers/cuda/tensor/grid_sample.cc` that was causing a warning (treated as error) about shadowing a member variable. - Ref: [`grid_sample.cc`](https://github.com/microsoft/onnxruntime/blob/c979a2407f/onnxruntime/core/providers/cuda/tensor/grid_sample.cc#L54) ### 2. Update GridSample Tests - Updated `onnxruntime/test/providers/cpu/tensor/grid_sample_test_custom.inc` to use default execution providers in `RunTests` instead of a hardcoded opset version, ensuring compatibility across different environments. ### 3. Revert Transformer Fusion Fallback - Reverted a recent change in `onnxruntime/python/tools/transformers/fusion_skiplayernorm.py` that enabled a fallback for `SkipLayerNormalization` fusion when symbolic shape inference fails. - This revert was necessary to avoid regressions in GPT-2 tests where model definitions contain typos that intentionally (or coincidentally) break shape inference. - Ref: [`fusion_skiplayernorm.py`](https://github.com/microsoft/onnxruntime/blob/c979a2407f/onnxruntime/python/tools/transformers/fusion_skiplayernorm.py#L113) ### 4. Restore Transformer Test Parity - Updated `onnxruntime/test/python/transformers/test_attention_fusion.py` specifically `test_qwen3_normalization_fusion` to match the expected node counts after reverting the fusion fallback. - Ref: [`test_attention_fusion.py`](https://github.com/microsoft/onnxruntime/blob/c979a2407f/onnxruntime/test/python/transformers/test_attention_fusion.py#L398) ## Verification - `build_cuda.sh` completed successfully. - `onnxruntime/test/python/transformers/test_attention_fusion.py` passes with "OK". - `lintrunner -a` reports no issues.
1 parent e5f5a6a commit ed3f8bf

4 files changed

Lines changed: 10 additions & 13 deletions

File tree

onnxruntime/core/providers/cuda/tensor/grid_sample.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ template <typename T, bool IsNHWC>
5151
GridSample<T, IsNHWC>::GridSample(const OpKernelInfo& info) : CudaKernel(info) {
5252
opset_start_version_ = info.node().SinceVersion();
5353

54-
std::string mode_str = info.GetAttrOrDefault<std::string>("mode", "bilinear");
5554
std::string padding_mode_str = info.GetAttrOrDefault<std::string>("padding_mode", "zeros");
5655
align_corners_ = static_cast<bool>(info.GetAttrOrDefault<int64_t>("align_corners", 0));
5756

onnxruntime/python/tools/transformers/fusion_skiplayernorm.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,8 @@ def fuse(self, node, input_name_to_nodes, output_name_to_node):
110110
)
111111
return
112112
else:
113-
# Shape inference failed. Use default skip_index=1 (no broadcasting) since both
114-
# Add inputs have already been verified as non-initializer dynamic tensors above.
115-
logger.debug("symbolic shape inference failed, using default skip_index for SkipLayerNormalization")
113+
logger.debug("skip SkipLayerNormalization fusion since symbolic shape inference failed")
114+
return
116115

117116
gather_path = self.model.match_parent_path(add, ["Gather"], [None])
118117
if gather_path is not None and self.model.find_graph_input(gather_path[0].input[1]) is None:

onnxruntime/test/providers/cpu/tensor/grid_sample_test_custom.inc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ TYPED_TEST(GridSampleCustomTest, test_grid_sample_20_4D_linear_zeros_mixed_bound
3737
test.AddAttribute("padding_mode", padding_mode);
3838
test.AddAttribute("align_corners", align_corners);
3939
test.AddOutput<TypeParam>("Y", Y_shape, Y_data);
40-
RunTests(test, GetExecutionProviders(20));
40+
RunTests(test, GetExecutionProviders());
4141
}
4242

4343
TYPED_TEST(GridSampleCustomTest, test_grid_sample_20_4D_linear_zeros_mixed_bounds_left_top) {
@@ -69,6 +69,5 @@ TYPED_TEST(GridSampleCustomTest, test_grid_sample_20_4D_linear_zeros_mixed_bound
6969
test.AddAttribute("padding_mode", padding_mode);
7070
test.AddAttribute("align_corners", align_corners);
7171
test.AddOutput<TypeParam>("Y", Y_shape, Y_data);
72-
RunTests(test, GetExecutionProviders(20));
72+
RunTests(test, GetExecutionProviders());
7373
}
74-

onnxruntime/test/python/transformers/test_attention_fusion.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -395,17 +395,17 @@ def test_qwen3_normalization_fusion(self):
395395
ssln_count = sum(1 for n in nodes if n.op_type == "SkipSimplifiedLayerNormalization")
396396

397397
# 4 RMSNorm patterns: pre-attn, Q-norm, K-norm, post-attn.
398-
# Post-attn RMSNorm has an Add parent (residual) → fused as SkipSimplifiedLayerNormalization.
399-
# Remaining 3 stay as SimplifiedLayerNormalization.
398+
# Fallback for SkipLayerNormalization is disabled, so post-attn RMSNorm does not fuse.
399+
# All 4 stay as SimplifiedLayerNormalization.
400400
self.assertEqual(
401401
sln_count,
402-
3,
403-
f"Expected 3 SimplifiedLayerNormalization (pre-attn + Q-norm + K-norm), got {sln_count}",
402+
4,
403+
f"Expected 4 SimplifiedLayerNormalization (pre-attn + Q-norm + K-norm + post-attn), got {sln_count}",
404404
)
405405
self.assertEqual(
406406
ssln_count,
407-
1,
408-
f"Expected 1 SkipSimplifiedLayerNormalization (residual + post-attn RMSNorm), got {ssln_count}",
407+
0,
408+
f"Expected 0 SkipSimplifiedLayerNormalization (residual + post-attn RMSNorm failed to fuse), got {ssln_count}",
409409
)
410410

411411

0 commit comments

Comments
 (0)