-
Notifications
You must be signed in to change notification settings - Fork 539
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
[RFC] Selective Op decomposition: Propagate down backend-legal Ops as Custom Ops #1519
Comments
This sounds like a reasonably useful tool to me. This seems generic enough to me to work across multiple backends, assuming that they have some way to wrap the op similar to what tosa.custom allows. So for TOSA I'd say yes, although I'd like to get indications from other backends that this would work for them, so that we can have a consistent experience. As a side note, I'm working on a change for tosa.custom to accept two additional strings, one for a 'config', which is like a namespace for the identifier, and another one to pass attributes of the wrapped operation if needed. I should be posting that in the TOSA dialect soon. |
@Svoch, thanks for presenting on this during the community meeting! I'll mention here the feedback given during the meeting. The approach mentioned here seems good to me. We definitely want to have a way to specify One thing we need to figure out is how to deal with the type conversions for certain torch dialect types that are expected to vanish once we finish the Off the top of my head, the types that we need to worry about are: |
I wasn't present at the discussion, but my general thoughts on this are that there isn't much to do here. TorchLoweringPipelineOptions already has a way to set backend legal ops. So as Ramiro points out, we just need a pass We don't want to have a |
@silvasean, I noticed you commented here https://reviews.llvm.org/D137133 regarding the design of |
Sometimes ints/floats are optional so for that we won't be able to represent them as operands due to the "None" case. And I think that makes sense since for the other backends we often pattern-match them as constants anyway during lowering. The important thing here semantically is to consider what is truly a dynamically computed value and what is not, as far as TOSA is concerned. Since TOSA does not lower e.g. AtenAddIntOp/AtenAddFloatOp, it is fair to say that we do not expect For cross-project, stable IR contracts, it is preferable to start with a constrained contract that is loosened over time to meet real demands, and putting all non-Tensor's in attributes (which for now probably means JSONifying) is the most consistent with that philosophy at the moment. TBD how to handle I would recommend that as part of the development of this feature, that we run at least once the e2e test suite in a dummy mode that turns all ops into tosa custom ops and see what ops don't work. We should have a pretty clear explanation for each kind of op that we don't systematically convert in the v1 of this feature. |
Thanks for your comments folks,
@eric-k256 regarding your comment on considering the new Please let me know how does this approach sound, and thanks for the reviews again! |
BTW, here is an example of performing selective decomposition the module defined below with marking
|
Hi folks, I'd like to get your feedback on my proposed design of selective decomposition of operations in Torch-MLIR.
I am building mainly on the notion of "backend-legal Ops" (merged in this PR) and the ideas proposed in the design for the custom Ops support (mentioned in this RFC).
When an operation is marked as legal in the backend, then it will not be decomposed in the "DecomposeComplexOpsPass", and is propagated down to the backend. Next there would be two possibilities:
AtenLayerNormOp
and compiling will yield an IR that cannot be lowered into the backend dialects.To handle the second case, we can mark such operations during (or before) the decomposition pass and have the backend conversion passes lower them into custom Ops. For example, consider Torch module below:
When compiling this to a backend, say TOSA, using the commands below
The compilation fails due to not being able to legalize unhandled Ops like the
aten.layer_norm.int
and its attributes present asconstant.int
in the Torch IR:But we can mark the
AtenLayerNormOp
as "backend-legal" during or before the decomposition pass, and introduce a conversion pass to lower the marked Ops to custom Ops in the backend dialect. For example, this could be the a valid TOSA IR for a full selective decomposition compilation:Please note that
torch.aten.layer_norm
was marked with a UnaryAttribute namedbackend_legal
and converted into atosa.custom
operation, and the rest of the operations used by it converted totosa.const
Ops via the existing lowering patterns in Torch to TOSA conversion pass. Since there is no way for the conversion to distinguish between the attributes and constant input arguments, all of the Ops used by the custom Op will be treated as inputs. It will be up to the downstream dialects ingesting this IR to deduce the arguments and attributes based on their custom Op lowering methods.On a final note, the concept of "backend-legal" can be extended to distinguish between the two cases mentioned above: Ops that should be handled by the lowering targets in Torch-MLIR, and Ops that should be tunneled down to the downstream dialects as custom Ops which can be marked as "backend-custom" Ops maybe.
cc @silvasean @powderluv
The text was updated successfully, but these errors were encountered: