Skip to content

[QNN EP] Add remove_initializer_from_input in qnn.preprocess #25102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

quic-hungjuiw
Copy link
Contributor

Description

  • Add argument "--exclude_initializer_from_input" to remove initializer from input if model.ir_version >= 4
  • Add function argument on remove_initializer_from_input
  • Modify the onnxruntime_python.cmake to include remove_initializer_from_input.py

Motivation and Context

  • To solve the issue Initializer <name> appears in graph inputs and will not be treated as constant value/weight., we require the remove_initializer_from_input to be included in qnn.preprocess

- Add argument "--exclude_initializer_from_input" to remove initializer
  from input if model.ir_version >= 4
- Add function argument on remove_initializer_from_input
- Modify the onnxruntime_python.cmake to include
  remove_initializer_from_input.py
@HectorSVC HectorSVC added the ep:QNN issues related to QNN exeution provider label Jun 19, 2025
@HectorSVC
Copy link
Contributor

/azp run Linux QNN CI Pipeline,Win_TRT_Minimal_CUDA_Test_CI,Windows ARM64 QNN CI Pipeline,Windows GPU Doc Gen CI Pipeline,Windows x64 QNN CI Pipeline

Copy link

Azure Pipelines successfully started running 5 pipeline(s).

@HectorSVC HectorSVC requested a review from Copilot June 19, 2025 03:40
Copy link
Contributor

@Copilot Copilot AI left a comment

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 introduces a new option to exclude initializers from model inputs for ONNX models with ir_version >=4, addressing an issue related to initializers appearing as graph inputs.

  • Adds a new argument "--exclude_initializer_from_input" across relevant scripts and the CMake build file.
  • Refactors the remove_initializer_from_input function to accept a model argument and return a boolean indicating whether modifications were made.

Reviewed Changes

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

File Description
tools/python/remove_initializer_from_input.py Refactored function to remove initializers from input and now returns a boolean flag; updated main block accordingly.
onnxruntime/python/tools/quantization/execution_providers/qnn/preprocess.py Integrated the exclude_initializer_from_input option into the QNN preprocessing logic.
onnxruntime/python/tools/qnn/preprocess.py Added new argument and documentation updates for excluding initializers from inputs.
cmake/onnxruntime_python.cmake Updated to include the new remove_initializer_from_input.py script in the build process.

args = get_args()

model = onnx.load(args.input)
def remove_initializer_from_input(model: onnx.ModelProto) -> bool:
if model.ir_version < 4:
print("Model with ir_version below 4 requires to include initilizer in graph input")
Copy link
Preview

Copilot AI Jun 19, 2025

Choose a reason for hiding this comment

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

There is a spelling error in the printed message: 'initilizer' should be corrected to 'initializer'.

Suggested change
print("Model with ir_version below 4 requires to include initilizer in graph input")
print("Model with ir_version below 4 requires to include initializer in graph input")

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ep:QNN issues related to QNN exeution provider
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants