Skip to content

Remove function value error in version converter#2791

Merged
titaiwangms merged 6 commits intomicrosoft:mainfrom
titaiwangms:titaiwang/fix_c
Feb 9, 2026
Merged

Remove function value error in version converter#2791
titaiwangms merged 6 commits intomicrosoft:mainfrom
titaiwangms:titaiwang/fix_c

Conversation

@titaiwangms
Copy link
Contributor

Fix #2790

This pull request makes a targeted change to the version converter in onnxscript. The main update removes the restriction that prevented models containing functions from being processed by the version conversion pass.

Version conversion support update:

  • Removed the check that raised an error when the input model contained functions, allowing the version conversion pass to process such models without requiring prior inlining. (onnxscript/version_converter/__init__.py)

@codecov
Copy link

codecov bot commented Feb 4, 2026

Codecov Report

❌ Patch coverage is 98.14815% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 70.50%. Comparing base (0206a98) to head (e251868).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
onnxscript/version_converter/_version_converter.py 87.50% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2791      +/-   ##
==========================================
+ Coverage   70.45%   70.50%   +0.05%     
==========================================
  Files         228      228              
  Lines       27177    27211      +34     
  Branches     2734     2737       +3     
==========================================
+ Hits        19148    19186      +38     
+ Misses       7092     7090       -2     
+ Partials      937      935       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@titaiwangms
Copy link
Contributor Author

TODO: support function within version converter

Copy link
Contributor

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 pull request enables version conversion support for ONNX models containing functions, addressing issue #2790 where models with functions caused the version converter to fail after upstream changes in onnx-ir.

Changes:

  • Removed the automatic inlining of functions before version conversion
  • Added support for converting nodes inside function definitions directly
  • Removed the error that prevented processing models with functions

Reviewed changes

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

File Description
onnxscript/version_converter/init.py Removed InlinePass from the conversion pipeline and the ValueError check for models with functions
onnxscript/version_converter/_version_converter.py Added visit_function method to handle version conversion of nodes inside functions and integrated it into the model visitor
onnxscript/version_converter/_version_converter_test.py Added test case verifying that nodes inside model functions are correctly version-converted

@github-project-automation github-project-automation bot moved this from Todo to Done in ONNX Script Review Board Feb 7, 2026
@titaiwangms titaiwangms merged commit 74a5f34 into microsoft:main Feb 9, 2026
32 checks passed
@gramalingam
Copy link
Collaborator

Unfortunately, there is a problem with generalizing the version-converter to work for functions. The issues is that for nodes inside a Function, there may be attributes that are attribute-references ... and if the version-converter logic needs the values of these attributes, then they may not be able to handle nodes where there are attribute-references instead of actual attribute-values.

At the least, we need logic in the version-converter (for any op, where we check an attribute-value) to catch the case where it is an attribute-reference and raise an NotImplemented error. For example, see the logic here ... here we should not use the default value of zero if it is an attribute-reference; instead we should copy the attribute-reference. Some adjustment to the logic is required, along with test-cases.

@titaiwangms
Copy link
Contributor Author

Unfortunately, there is a problem with generalizing the version-converter to work for functions. The issues is that for nodes inside a Function, there may be attributes that are attribute-references ... and if the version-converter logic needs the values of these attributes, then they may not be able to handle nodes where there are attribute-references instead of actual attribute-values.

At the least, we need logic in the version-converter (for any op, where we check an attribute-value) to catch the case where it is an attribute-reference and raise an NotImplemented error. For example, see the logic here ... here we should not use the default value of zero if it is an attribute-reference; instead we should copy the attribute-reference. Some adjustment to the logic is required, along with test-cases.

#2806

titaiwangms added a commit that referenced this pull request Feb 13, 2026
Regarding the concern from
#2791 (comment),
this PR specifically raises when function has RefAttr.

---
This pull request adds a new validation to the version converter to
ensure nodes with reference attributes (`RefAttr`) are not supported,
and introduces a corresponding unit test to verify that the version
converter raises an error in such cases.

Validation for unsupported reference attributes:

* Added a check in `visit_graph_or_function` in
`onnxscript/version_converter/_version_converter.py` to raise a
`VersionConverterError` if any node has a reference attribute
(`RefAttr`), as these are not currently supported by the version
converter.

Testing and error handling:

* Added a new unit test
`test_version_convert_raises_on_function_node_with_ref_attribute` in
`onnxscript/version_converter/_version_converter_test.py` to ensure that
converting a model containing a function node with a reference attribute
raises the appropriate error and includes a clear message.

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Justin Chu <justinchuby@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Development

Successfully merging this pull request may close these issues.

Version conversion failing due to functions in the model

3 participants