Fix split_predict generating invalid ONNX models with missing elem_type#244
Draft
Fix split_predict generating invalid ONNX models with missing elem_type#244
Conversation
- Added inferElemType() helper function to infer missing elem_type from inputs - Modified split_predict to infer elem_type when creating new graph inputs/outputs - This fixes the bug where split_predict generates invalid ONNX models with missing elem_type Co-authored-by: justinchuby <11205048+justinchuby@users.noreply.github.com>
Co-authored-by: justinchuby <11205048+justinchuby@users.noreply.github.com>
Co-authored-by: justinchuby <11205048+justinchuby@users.noreply.github.com>
- Add null check for producer node - Improve documentation to explain limitations and supported operators - Clarify that this is a heuristic for common cases Co-authored-by: justinchuby <11205048+justinchuby@users.noreply.github.com>
- Clarify what happens when elem_type inference fails - Use TensorProto.UNDEFINED constant in Python test instead of magic number - Add comment explaining UNDEFINED value in C++ test Co-authored-by: justinchuby <11205048+justinchuby@users.noreply.github.com>
- Use named constant throughout split.h instead of magic number 0 - Update C++ test to use ONNX_NAMESPACE::TensorProto_DataType_UNDEFINED - Improves code readability and maintainability Co-authored-by: justinchuby <11205048+justinchuby@users.noreply.github.com>
- Add null pointer check for Value parameter to prevent segfaults - Clarify comment in Python test about TensorProto.UNDEFINED Co-authored-by: justinchuby <11205048+justinchuby@users.noreply.github.com>
|
Copilot
AI
changed the title
[WIP] Fix invalid optimized ONNX model generation by split_predict pass
Fix split_predict generating invalid ONNX models with missing elem_type
Dec 31, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



The
split_predictpass generates invalid ONNX models when intermediate values lack explicitvalue_info. Graph inputs end up with UNDEFINED elem_type (value 0), causing validation failures inonnx.checkerand ONNX Runtime load errors.Changes
Core fix in
onnxoptimizer/passes/split.h:inferElemType()helper that infers type from producing node's inputs when elem_type is UNDEFINEDcopyMetadata()Type inference heuristic:
Tests:
test_split_predict_preserves_elem_type()SplitPredictPreservesElemTypeBoth tests verify optimized models pass ONNX validation and have valid elem_type for all inputs.
Limitations
Type inference works for common operators where output type matches input type. Operators with different output types (Shape, Cast) require proper value_info in the original model.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.