Skip to content

Relax CompileModel validation to accept zero-input OrtModel graphs - #28771

Merged
adrastogi merged 1 commit into
mainfrom
adrastogi/empty-model-inputs
Jun 24, 2026
Merged

Relax CompileModel validation to accept zero-input OrtModel graphs#28771
adrastogi merged 1 commit into
mainfrom
adrastogi/empty-model-inputs

Conversation

@adrastogi

Copy link
Copy Markdown
Contributor

Description

Relax the input-validation in OrtApi::CompileModel to accept OrtModel instances with zero graph inputs. Previously, ModelCompilationOptions::Check() rejected such models with "OrtModel graph must have at least one input and one output defined." The check now requires only at least one graph output; the zero-input case is legal.

Tests in test_model_builder_api.cc are restructured:

  • The old CompileFromModelWithEmptyInputsOutputs_Fails is renamed to CompileFromModelWithEmptyOutputs_Fails and reshaped to provide 1 input + 0 outputs, isolating the output-only check.
  • A new regression test CompileFromModelWithEmptyInputs_Succeeds builds a 0-input model with a RandomNormal node and verifies compilation succeeds.

Motivation and Context

Fixes #28135
The original check was too restrictive and impacts callers (e.g., WebNN/Chromium needs to call CompileModel on such models in a separate compiler process (and then load the compiled artifact via CreateSessionFromArray in the GPU process)).

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 relaxes OrtApi::CompileModel validation for OrtModel inputs so that models with zero graph inputs are accepted, aligning CompileModel behavior with CreateSessionFromModel for input-less generator graphs (e.g., RandomNormal).

Changes:

  • Update ModelCompilationOptions::Check() to require at least one graph output, no longer requiring at least one input.
  • Restructure shared-lib tests to isolate the “no outputs” failure case.
  • Add a regression test that compiles a 0-input, 1-output model built via the Model Editor API and asserts compilation produces a non-empty artifact.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
onnxruntime/test/shared_lib/test_model_builder_api.cc Updates validation tests and adds a regression test covering successful compilation of a 0-input OrtModel.
onnxruntime/core/session/model_compilation_options.cc Relaxes OrtModel compile-time validation to allow zero graph inputs while still requiring at least one output.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@adrastogi
adrastogi merged commit b77b312 into main Jun 24, 2026
92 of 93 checks passed
@adrastogi
adrastogi deleted the adrastogi/empty-model-inputs branch June 24, 2026 21:47
@fdwr

Copy link
Copy Markdown
Contributor

Nice, thanks adrastogi.

adrastogi pushed a commit that referenced this pull request Jul 23, 2026
### Description
<!-- Describe your changes. -->
Set `min_arity` of inputs to zero in EPContext node registration.


### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->
PR #28771 relaxed
CompileModel validation to accept zero-input OrtModel graphs, so
EpContext node should also accept zero-input.
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.

[ORT CPU][WebNN][Feature Request] Support OrtModel graph with empty inputs in the CompileModel method

4 participants