[TensorExpr Fuser] Handle fusing values with un-profiled uses (#48689)
Summary:
Copying myself from the code comments:
A value can be profiled with differently typed uses.
This can occur from:
- having a use which is not executed, so the type will be
TensorType::get()
- control-flow that depends on tensor type:
if x.size() == 2 op(x) else op(x)
- mutation of the value on a field represented in the tensor type
op(x); x.resize_([...]); op(x)
The most common case today with num_profiles = 1 is from the first case. Here we can just ignore non-profiled uses, and choose any of the profiled uses. Because we guard all tensor types in the runtime, even if we set a Value to have a profiled type from one use and then execute a use with a different profiled type, we will still be correct. In the future we could consider unifying the types of uses, or adding a type refinement node so uses can have the correct corresponding type.
Fix for https://github.com/pytorch/pytorch/issues/48043 I think there's probably too much context required for that to be a good bootcamp task...
There was an observed missed fusion opportunity in detectron2 because of this issue.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/48689
Reviewed By: ngimel
Differential Revision: D25278791
Pulled By: eellison
fbshipit-source-id: 443e5e1254446a31cc895a275b5f1ac3798c327f