-
Notifications
You must be signed in to change notification settings - Fork 514
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
Add hasDtype
checks everywhere dtypes are used in decompositions
#1750
Conversation
There are several decompositions that assume the operands of the op have dtypes available; however, the only time dtypes are guaranteed to be present is when the graph has reached the backend contract. In general, every pass that happens before reaching the backend contract should not assume dtypes are available and should use `hasDtype` to check first. This commit adds `hasDtype` checks to every decomposition that uses dtypes.
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
Hi @ramiro050, I have a doubt regarding this patch. In some places, you have directly used |
That's a good question. There are two scenarios that take place regarding the use of
For the first scenario, I used the The the second scenario, because it is important for Let me know if this makes sense to you and if the changes look good. |
Hi, I have a few more questions. Why can't we determine the dtype before the decomposition happens? If we can, is it a better way to handle this issue? (like finalizing the dtype in In the second scenario, will there be unexpected decomposition errors in some combination of ops, when we can determine the dtype but we didn't? Like |
Currently the torch-mlir/lib/Dialect/Torch/Transforms/Passes.cpp Lines 123 to 136 in f0998f9
Because your example does an However, these set of passes are meant to be run over and over again to avoid the catch-22 issue outlined above between the two dtype propagation passes (see: 57681f7). In your case, all that is needed is for the set of passes to be run one more time. What prevents this from happening is that
My patch fixes the example in your issue. I used your example to make sure things worked locally. |
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 try to cherry pick this patch for the nod-ai/SHARK-Studio#338. But it fails.
Here is the torchscipt ir.
Please run torchscript IR to torch the backend pipeline over that, and it will fail.
torch-mlir-opt -pass-pipeline='builtin.module(torchscript-module-to-torch-backend-pipeline{backend-legal-ops=torch.aten.flatten.using_ints})' /tmp/gpt2_torch_raw_elide.mlir --mlir-print-ir-after-all > gpt2_tosa_ramiro.mlir
You will get this after refine type
%884 = torch.aten.tanh %883 : !torch.vtensor<[1,5,3072],f32> -> !torch.vtensor<[1,5,3072],unk>
Please take a look at #1769, and let me know if that fixes it |
@AmosLewis, while #1769 might fix the issue you're having with Note: the commit message in #1769 explains why things still fail in GPT-2 when using this patch. |
The |
@vivekkhandelwal1, let me know if this PR and #1769 don't fix your issue. |
Hi @ramiro050, the issue with |
I think the best way forward is to finish the transition to using dtype functions written in Python. I have made an issue to track the progress: #1807 This should once and for all fix these issues. |
Thanks! |
There are several decompositions that assume the operands of the op have dtypes available; however, the only time dtypes are guaranteed to be present is when the graph has reached the backend contract. In general, every pass that happens before reaching the backend contract should not assume dtypes are available and should use
hasDtype
to check first.This commit adds
hasDtype
checks to every decomposition that uses dtypes.