Skip to content

Conversation

@galagam
Copy link
Contributor

@galagam galagam commented Dec 22, 2025

What does this PR do?

Type of change: New feature

Overview:
AutoCast runs full type inference to get the new types after adding casts. ONNX doesn't have a separate function for type inference, and it is done as part of shape inference. Shape inference is a much more complex task than type inference, especially when dynamic shapes are involved. We're seeing some shape inference related bugs in AutoCast. Typically we can WAR, but it's cumbersome. A local implementation might allow users to WAR shape inference related issues. This is opt-in and marked as experimental.

Usage

python -m modelopt.onnx.autocast --onnx_path /path/to/input.onnx [options] --use_standalone_type_inference

Testing

Added use_standalone_type_inference=True to all existing PrecisionConverter tests.

Before your PR is "Ready for review"

  • Make sure you read and follow Contributor guidelines and your commits are signed.
  • Is this change backward compatible?: Yes
  • Did you write any new necessary tests?: Yes
  • Did you add or update any necessary documentation?: Yes
  • Did you update Changelog?: Yes

Additional Information

A more permanent fix would be to decouple type and shape inference in ONNX, we should invest in that when we have the resources - see onnx/onnx#7100
. This is a quick fix, which is also why it is opt-in and not the default mode.

Signed-off-by: Gal Hubara Agam <96368689+galagam@users.noreply.github.com>
@copy-pr-bot
Copy link

copy-pr-bot bot commented Dec 22, 2025

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@codecov
Copy link

codecov bot commented Dec 22, 2025

Codecov Report

❌ Patch coverage is 69.45607% with 73 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.62%. Comparing base (03dc386) to head (28365ea).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
modelopt/onnx/utils.py 67.94% 67 Missing ⚠️
modelopt/onnx/autocast/precisionconverter.py 82.60% 4 Missing ⚠️
modelopt/onnx/autocast/convert.py 66.66% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #719      +/-   ##
==========================================
- Coverage   74.69%   74.62%   -0.08%     
==========================================
  Files         192      192              
  Lines       18946    19169     +223     
==========================================
+ Hits        14152    14305     +153     
- Misses       4794     4864      +70     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

created by cursor and committed by mistake

Signed-off-by: Gal Hubara Agam <96368689+galagam@users.noreply.github.com>
Signed-off-by: Gal Hubara Agam <96368689+galagam@users.noreply.github.com>
Signed-off-by: Gal Hubara Agam <96368689+galagam@users.noreply.github.com>
Signed-off-by: Gal Hubara Agam <96368689+galagam@users.noreply.github.com>
@galagam galagam marked this pull request as ready for review December 25, 2025 07:39
@galagam galagam requested review from a team as code owners December 25, 2025 07:39
@galagam galagam requested review from ajrasane and gcunhase December 25, 2025 07:39
@galagam galagam changed the title Draft: AutoCast local implementation for type inference [5750013][5591945][5360813]: AutoCast local implementation for type inference Dec 25, 2025
…add to changelog

Signed-off-by: Gal Hubara Agam <96368689+galagam@users.noreply.github.com>
@galagam galagam force-pushed the feat/local-type-infer branch from a659cad to 7caedc7 Compare December 25, 2025 07:51
@galagam galagam changed the title [5750013][5591945][5360813]: AutoCast local implementation for type inference [5750013][5591945][5360813]: AutoCast standalone implementation for type inference Dec 25, 2025
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.

1 participant