-
Notifications
You must be signed in to change notification settings - Fork 59
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
Fix misleading annotation in the documentation #2046
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2046 +/- ##
=======================================
Coverage 71.76% 71.76%
=======================================
Files 225 225
Lines 29275 29276 +1
Branches 3455 3455
=======================================
+ Hits 21010 21011 +1
Misses 7133 7133
Partials 1132 1132 ☔ View full report in Codecov by Sentry. |
@@ -15,14 +15,14 @@ | |||
fold_constants_ir = constant_folding.fold_constants | |||
|
|||
|
|||
def optimize(model: ir.Model | onnx.ModelProto, *args, **kwargs): | |||
def optimize(model: ir.Model | onnx.ModelProto, *args, **kwargs) -> ir.Model | onnx.ModelProto: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should make this a TypeVar
define TModel as a typevar then
def optimize(model: ir.Model | onnx.ModelProto, *args, **kwargs) -> ir.Model | onnx.ModelProto: | |
def optimize(model: TModel, *args, **kwargs) -> TModel: |
etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just did it for the documentation because without it, I assumed the modifications were done inplace which is not always the case. For that only purpose, I feel like keeping both types gives better information than a TypeVar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using union confuses the type checker in user code because then it will not know which is the return type without an isinstance assertion. That's going to be an inconvenience to users. Right now since we don't annotate at all, the type checker is able to infer the return type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we need to clean this up. It stems from our transition from proto to IR, which also simultaneously switched from copy-and-optimize to optimize-in-place. One issue to resolve is how much backward-compatibility we need here. Ideally, we should migrate away from proto-based optimization (not sure if there is any usage of this remaining), and have just in-place IR modification.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A potential way to this this would be annotating with only IR and hide the usage of the proto input. At some point after some deprecation period we can remove the logic entirely.
The function does not seem to work inplace in all cases.