-
Notifications
You must be signed in to change notification settings - Fork 26.3k
[jit] Fix type hints for None constants #23029
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
Conversation
jamesr66a
left a comment
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.
Looks OK but I had some questions
jamesr66a
left a comment
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.
now we are on horse
| n->output()->setType(result_type); | ||
| } else { | ||
| // Implicitly wrap non-optionals | ||
| n->output()->setType(OptionalType::create(result_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.
How can this branch ever be reached ? inferred_type->isSubtypeOf(NoneType::get()) && !inferred_type->isSubtypeOf(result_type)) means that result_type has to be an Optional.
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.
This is in there to maintain compatibility for calls like torch.jit.annotate(Tensor, None) where the type hint is Tensor
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 think this should be handled in the compiler and not here. InsertConstant is a common API and this usage would be a bug at any of the other callsites
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.
It's not a bug though, it's something we support currently. Plus keeping it here lets us have all usages in 1 place so we can more easily delete it later if we go that route
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.
It is a bug. In any other case having a type of Tensor for a value of None is a bug
The type hint was being ignored when emitting
Noneconstants, this also de-dups some testing codeDifferential Revision: D16364572