-
Notifications
You must be signed in to change notification settings - Fork 522
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
[TorchToTosa] Refactoring to separate construction of legal/illegal ops and conversion patterns. #3759
Conversation
Hi @sjarus, tagging you as you recently reviewed a PR for changes in the |
a76c138
to
49199da
Compare
I'll take a look within a day. |
Hi @sjarus , a gentle reminder to review this PR when you get a chance. Thanks! |
e62285c
to
a197fdf
Compare
a197fdf
to
14e3cea
Compare
Hi @sjarus any thoughts on this PR? |
14e3cea
to
6760b46
Compare
Terribly sorry - I completely missed this PR! Please ping me on discord if you don't get a timely response from me. Reviewing this now. |
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.
.
0f92856
to
7e120d4
Compare
7e120d4
to
ffa472f
Compare
ffa472f
to
f60b53f
Compare
f60b53f
to
39aaae8
Compare
This PR refactors TorchToTosa to separate the construction of legal/illegal ops and conversion patterns in their own functions:
Currently the (il)legality of the ops that are (il)legal after the conversion pass runs is embedded within the conversion pattern. Our end goal is to write a new pass pipeline that converts
torch
ops to a mix oftosa
,linalg
,tensor
, etc dialect ops. The reason we want to also emittosa
ops (instead of using the existingTorchToLinalg
to emitlinalg
+tensor
+...) is because some operations likeconv2d
encodes the padding behavior in the op intosa
unlike thelinalg
version -- this helps in lowering thetosa.conv2d
to a custom implementation that does padding on the fly.To implement this new pipeline we need to be able to separate out the illegal
tosa
ops from the conversion pattern itself. Otherwise we will hit an issue for ops likeAtenMaxDimOp
which can be lowered to bothtosa
andlinalg + others
dialects. Not allAtenMaxDimOp
can be lowered successfully totosa
as the implementation usestosa.reshape
which cannot handle multiple dynamic dimensions but theTorchToLinalg
lowering can handle it. In the current behavior the pipeline will stop as soon as the existingTorchToTosa
conversion runs asAtenMaxDimOp
will be marked as an illegal op.Essentially we want to be able to control what the legality of the ops should be independent of the conversion pattern. This is also inline with the conversion patterns in the llvm-mlir repo such as https://github.com/llvm/llvm-project/blob/000e790be35b77a01872851646d54432a203542c/mlir/lib/Conversion/SCFToControlFlow/SCFToControlFlow.cpp#L718
"THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY."