-
Notifications
You must be signed in to change notification settings - Fork 563
Update codegen to use xla::Shape #4111
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
5133503 to
c8074d5
Compare
3d4fcc4 to
b7f64f2
Compare
|
@alanwaketan, this should be ready for a review. Thanks! |
|
Let's also remove Lines 466 to 468 in 647a3d5
I added it a while back to use |
scripts/gen_lazy_tensor.py
Outdated
| /* num_outputs */ {len(schema.returns)}, | ||
| torch::lazy::MHash({scalar_hashes}))""" | ||
|
|
||
| def gen(self, schema: LazyIrSchema) -> List[str]: |
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.
Most of this function is same as upstream codegen. Some bits are updated to remove torch::lazy::Shape related logic.
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.
You did a good job on GenXlaLazyNativeFuncDefinition. We can repeat that.
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.
Thanks for the comment. It seems to be a bit harder to do make this overriding clean for the GenLazyIR class. The upstream GenLazyNativeFuncDefinition class has specific function named shape_inference() that we can override to remove the torch::lazy::Shape related logic. But for the upstream GenLazyIR class, the shape inference logic is part of a big gen() function so we are unable to override only the specific torch:lazy:Shape related codegen. I've added a comment to this function describing this, let me know if you think this is okay.
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.
Oops, accidentally deleted one of your original comments on this thread while I was trying to delete one of my older replies lol. Just for future reference, Jiewen's original comment was:
It looks like maybe we can make the parts we don't need as a method in the GenLazyIR class such that we can substitute them with things that output empty strings for instances.
ff8714a to
a2cb03e
Compare
|
Building cpp tests now succeeding locally, will let CI to verify the remaining tests. |
|
Some unit test failures, looking into it. |
|
The resulting shape was casted/promoted to Lines 466 to 468 in 647a3d5
Now since this logic and torch::lazy::Shape are both removed, codegen'ed bitwise ops casted/promoted the resulting shape to long. The last commit moves these ops to ir_codegen only, so we can explicitly call DoBinaryOpWithoutPromo in aten_xla_type.cpp. This does not introduce any new behavior or regression for these ops.
|
|
@alanwaketan this should be ready for another review, thanks! |
Just for my education, can you point me to where this promotion happens? |
Sure thing! In the current codegen'ed |
|
Thanks, @wonjoolee95. It looks like we don't want to promote scalar tensors. Because of decomposition, all the scalar variants of binary ops will be first converted to tensor version before reaching us (wrap the scalars into scalar tensors). Therefore, we need a way to detect scalar tensors and don't promote them. On the other hand, it looks like we do want to promote scalars? Or because scalars are annotated differently in xla so they don't get promoted by xla as well. Can you help me better understand the situation here? |
|
The problem here seems be the lack of xla/torch_xla/csrc/aten_xla_type.cpp Lines 903 to 910 in 1715ccd
So the old behavior looks like we don't want to promote scalars or tensors. And when we codegen'ed these ops at https://github.com/pytorch/xla/pull/3815/files, these DoBinaryOpWithoutPromo were omitted when we removed the bitwise ops from aten_xla_type.cpp.
|
|
Yea, if we dig into tensor variant of For the scalar variant, it does nothing special. That's why I'm confused. @JackCaoG Do you have any insights? |
This reverts commit 5133503.
f571565 to
982692d
Compare
|
Since the original upstream PyTorch PR pytorch/pytorch#87823 got merged, opened a new one to add the |
Just talked to Jack. It looks like the rule here is just to pass all the tests. |
alanwaketan
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.
LGTM. Thanks!
Add use_lazy_shape flag to GenLazyIr class to allow XLA to use its custom shape class. The default value is kept to use lazy shape, so this PR does not introduce any new behaviors. PyTorch/XLA companion PR: pytorch/xla#4111 Pull Request resolved: #88444 Approved by: https://github.com/alanwaketan, https://github.com/wconstab
|
Upstream PR is merged, will merge this PR without the torch_pin. |
Add use_lazy_shape flag to GenLazyIr class to allow XLA to use its custom shape class. The default value is kept to use lazy shape, so this PR does not introduce any new behaviors. PyTorch/XLA companion PR: pytorch/xla#4111 Pull Request resolved: pytorch#88444 Approved by: https://github.com/alanwaketan, https://github.com/wconstab
Add use_lazy_shape flag to GenLazyIr class to allow XLA to use its custom shape class. The default value is kept to use lazy shape, so this PR does not introduce any new behaviors. PyTorch/XLA companion PR: pytorch/xla#4111 Pull Request resolved: pytorch#88444 Approved by: https://github.com/alanwaketan, https://github.com/wconstab
Update codegen to use xla::Shape
This PR updates codegen to use
xla::Shapeinstead oftorch::lazy::Shapeby overriding the upstreamGenLazyNativeFuncDefinitionandGenLazyIrgenerators. It overridesGenLazyNativeFuncDefinition.shape_inference()andGenLazyNativeFuncDefinition.build_ir_node()functions to removetorch::lazy::Shaperelated shape inference and constructor codegen. It also overridesGenXlaLazyIR.gen()to removestd::vector<torch::lazy::Shape>inNodeconstructor`.This depends on an open upstream PyTorch PR pytorch/pytorch#87823 to make
GenLazyNativeFuncDefinitioncustomizable.New
LazyIr.hexample:Changes
std::vector<torch::lazy::Shape>argument to the constructorXlaNodeconstructor without thetorch::lazy::ShapeOld
LazyIr.hexample: #3930New
XlaNativeFunctions.cppexample:Changes:
torch::lazy::Shaperelated creation/assertion logicsymbolicShapeEnabledlogic (need to double check if this is okay)Old
XlaNativeFunctions.cppexample: #3930