-
Notifications
You must be signed in to change notification settings - Fork 621
Enable VerifyBackendContract in LTC backend #1798
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
Merged
GlebKazantaev
merged 5 commits into
llvm:main
from
GlebKazantaev:gleb/verify_backend_contract
Jan 25, 2023
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e528c43
Enable VerifyBackendContract in LTC backend
GlebKazantaev dea5b8a
Update VerifyBackendContract pass
GlebKazantaev d7ce401
Move convert_scalar_implicit to jit_utils
GlebKazantaev bdddd7f
Rename VerifyBackendContract to VerifyBackendContractNoDecompositions
GlebKazantaev 8248863
Update verify-backend-contract-error.mlir test
GlebKazantaev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
python/torch_mlir/csrc/base_lazy_backend/utils/jit_utils.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| #include "jit_utils.h" | ||
|
|
||
| #include <torch/csrc/jit/runtime/graph_iterator.h> | ||
|
|
||
| #include <ATen/core/type_factory.h> | ||
|
|
||
| namespace torch { | ||
| namespace jit { | ||
|
|
||
| void ConvertScalarImplicit(std::shared_ptr<Graph>& graph) { | ||
| DepthFirstGraphNodeIterator it(graph); | ||
| for (auto* node = it.next(); node != nullptr; node = it.next()) { | ||
| if (node->kind() != c10::aten::ScalarImplicit) { | ||
| continue; | ||
| } | ||
|
|
||
| auto input = node->input(0); | ||
| auto scalar_type = input->type()->cast<c10::TensorType>()->scalarType(); | ||
| TORCH_CHECK(scalar_type, "scalar type is not defined for input value"); | ||
|
|
||
| NodeKind node_type; | ||
| TypePtr output_type; | ||
| if (c10::isIntegralType(*scalar_type, false)) { | ||
| node_type = c10::aten::IntImplicit; | ||
| output_type = IntType::get(); | ||
| } else if (c10::isFloatingType(*scalar_type)) { | ||
| node_type = c10::aten::FloatImplicit; | ||
| output_type = FloatType::get(); | ||
| } else { | ||
| throw std::runtime_error( | ||
| "Expected isIntegralType or isFloatingType"); | ||
| } | ||
|
|
||
| Value * output = graph | ||
GlebKazantaev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ->create(node_type, {input}) | ||
| ->insertBefore(node) | ||
| ->output() | ||
| ->setType(output_type); | ||
| node->output()->replaceAllUsesWith(output); | ||
| node->destroy(); | ||
| } | ||
| } | ||
|
|
||
| } // namespace jit | ||
| } // namespace torch | ||
10 changes: 10 additions & 0 deletions
10
python/torch_mlir/csrc/base_lazy_backend/utils/jit_utils.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| #include <torch/csrc/jit/ir/ir.h> | ||
|
|
||
| namespace torch { | ||
| namespace jit { | ||
|
|
||
| // Convert ScalarImplicit to IntImplicit or FloatImplicit. | ||
| TORCH_API void ConvertScalarImplicit(std::shared_ptr<Graph>& graph); | ||
|
|
||
| } // namespace jit | ||
| } // namespace torch |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| // RUN: torch-mlir-opt -torch-verify-backend-contract -split-input-file -verify-diagnostics %s | ||
| func.func @f(%arg0: !torch.vtensor<[?,?],f32>) -> !torch.vtensor<[?,?],f32> { | ||
| // expected-error @+2 {{found an op that was marked as backend illegal}} | ||
| // expected-note @+1 {{this is likely due to}} | ||
| %t = torch.aten.t %arg0 : !torch.vtensor<[?,?],f32> -> !torch.vtensor<[?,?],f32> | ||
| return %t : !torch.vtensor<[?,?],f32> | ||
| // RUN: torch-mlir-opt -torch-verify-backend-contract-no-decompositions -split-input-file -verify-diagnostics %s | ||
| func.func @f(%arg0: !torch.vtensor<[?,?],f32>) -> !torch.vtensor { | ||
| // expected-error @below {{unsupported by backend contract: tensor with unknown rank}} | ||
| // expected-note @below {{this is likely due to a missing transfer function}} | ||
| %t = torch.aten.t %arg0 : !torch.vtensor<[?,?],f32> -> !torch.vtensor | ||
| return %t : !torch.vtensor | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.