Skip to content

Fix transpose of empty initializers called from constant folding#25922

Merged
xadupre merged 2 commits into
mainfrom
xadupre/zeroshape
Sep 4, 2025
Merged

Fix transpose of empty initializers called from constant folding#25922
xadupre merged 2 commits into
mainfrom
xadupre/zeroshape

Conversation

@xadupre

@xadupre xadupre commented Sep 2, 2025

Copy link
Copy Markdown
Member

Description

ConstantFolding crashes when a constant empty initializer is transposed.

Motivation and Context

This rare case happened when converting a LLM into onnx with static shape.

@xadupre xadupre marked this pull request as ready for review September 2, 2025 15:41
@justinchuby justinchuby requested a review from Copilot September 2, 2025 17:04

Copilot AI 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.

Pull Request Overview

This PR fixes a crash in ConstantFolding when attempting to transpose constant empty initializers by adding a guard condition to skip the transpose operation for empty tensors.

  • Added guard condition to skip transpose operation when tensor size is 0
  • Added test case to verify the fix works correctly for empty initializer transpose scenarios

Reviewed Changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.

File Description
onnxruntime/test/optimizer/graph_transform_test.cc Adds test case to verify constant folding doesn't crash on empty initializer transpose
onnxruntime/core/optimizer/transpose_optimization/ort_optimizer_api_impl.cc Adds size check guard to prevent transpose operation on empty tensors

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread onnxruntime/test/optimizer/graph_transform_test.cc
@xadupre xadupre changed the title Fix transpose of empty initiliazers called from constant folding Fix transpose of empty initializers called from constant folding Sep 4, 2025
@xadupre xadupre merged commit 5bd1ff0 into main Sep 4, 2025
90 of 92 checks passed
@xadupre xadupre deleted the xadupre/zeroshape branch September 4, 2025 13:24
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