-
Notifications
You must be signed in to change notification settings - Fork 436
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
Throw better error message when not returning a tensor or tuple of tensors #1491
Comments
Re: the case we talked about today, of returning a single-item tuple. The following error is thrown: Traceback (most recent call last):
File "/usr/local/google/home/danielellis/torch-mlir/repro.py", line 40, in <module>
main()
File "/usr/local/google/home/danielellis/torch-mlir/repro.py", line 32, in main
linalg_on_tensors_mlir = torch_mlir.compile(
File "/usr/local/google/home/danielellis/torch-mlir/build/tools/torch-mlir/python_packages/torch_mlir/torch_mlir/__init__.py", line 274, in compile
run_pipeline_with_repro_report(
File "/usr/local/google/home/danielellis/torch-mlir/build/tools/torch-mlir/python_packages/torch_mlir/torch_mlir/compiler_utils.py", line 73, in run_pipeline_with_repro_report
raise TorchMlirCompilerError(trimmed_message) from None
torch_mlir.compiler_utils.TorchMlirCompilerError: Lowering TorchScript IR -> Torch Backend IR failed with the following diagnostics:
error: failed to legalize unresolved materialization from '!torch.tuple<tensor>' to '!torch.tensor' that remained live after conversion
note: see current operation: %2 = "builtin.unrealized_conversion_cast"(%1) : (!torch.tuple<tensor>) -> !torch.tensor
note: see existing live user here: "func.return"(%2) : (!torch.tensor) -> () We talked about putting another check just before the success here. We never actually reach this line, however. We end up failing in the check before, in the call to |
I think the issue is this type conversion: torch-mlir/lib/Dialect/Torch/Transforms/AdjustCallingConventions.cpp Lines 196 to 201 in 0af5578
It should not succeed if the tuple only has one element in it. Another point that might be important to look at is: torch-mlir/lib/Dialect/Torch/Transforms/AdjustCallingConventions.cpp Lines 78 to 81 in 0af5578
That conversion should also result in an error if the tuple has one element in it. |
Actually, I think the conversions should simply return the tuple type when the tuple has one element, rather than throwing an error, since there are valid cases where we should have a function returning a single element tuple. For example: def foo(x):
return (x,)
def forward(x):
return foo(x)[0] |
Strictly speaking, we need to distinguish between externally-callable functions and private functions. AdjustCallingConventions is only about externally-callable functions, and for those, a single-element tuple is not a valid return type (it will not satisfy the backend contract). (it makes sense to catch that as soon as possible) |
Right, that's a good point. I was thinking about the example I mentioned above because of this lit test replacing torch-mlir/test/Dialect/Torch/adjust-calling-conventions.mlir Lines 95 to 99 in c97df38
Is this something that is already being done? The |
I suspect what we are doing now "happens to be sound", but yeah, AdjustCallingConventions probably should be explicitly checking public/private in theory. |
See #1471 for background
The text was updated successfully, but these errors were encountered: