Skip to content

fix: fix the inappropriate lowering pass of aten::to #1649

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
merged 1 commit into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions core/lowering/passes/reduce_to.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,6 @@ namespace lowering {
namespace passes {

void ReduceToOperation(std::shared_ptr<torch::jit::Graph>& graph) {
std::string to_dtype_layout_pattern = R"IR(
graph(%x, %dtype, %layout, %device, %pm, %nb, %copy, %format):
%out : Tensor = aten::to(%x, %dtype, %layout, %device, %pm, %nb, %copy, %format)
return (%out))IR";

std::string to_dtype_multi_input_pattern = R"IR(
graph(%x, %dtype, %layout, %device, %pm, %nb, %copy, %format):
%out : Tensor = aten::to(%x, %device, %dtype, %nb, %copy, %format)
return (%out))IR";

std::string to_type_as_pattern = R"IR(
graph(%input, %other):
%out : Tensor = aten::type_as(%input, %other)
Expand All @@ -30,11 +20,6 @@ void ReduceToOperation(std::shared_ptr<torch::jit::Graph>& graph) {
%out : Tensor = aten::to(%input, %other, %5, %5, %6)
return (%out))IR";

// replace aten::to.dtype_layout with aten::to.dtype
torch::jit::SubgraphRewriter map_aten_dtype_layout;
map_aten_dtype_layout.RegisterRewritePattern(to_dtype_layout_pattern, to_dtype_multi_input_pattern);
map_aten_dtype_layout.runOnGraph(graph);

// replace aten::type_as with aten::to.other
torch::jit::SubgraphRewriter map_aten_type_as_to_other;
map_aten_type_as_to_other.RegisterRewritePattern(to_type_as_pattern, to_other_pattern);
Expand Down
22 changes: 0 additions & 22 deletions tests/core/lowering/test_reduce_to_pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,6 @@
#include "torch/csrc/jit/ir/irparser.h"
#include "torch/csrc/jit/ir/subgraph_matcher.h"

TEST(LoweringPasses, ReduceToDtypeLayoutCorrectly) {
std::string source_graph = R"IR(
graph(%x, %dtype, %layout, %device, %pm, %nb, %copy, %format):
%out : Tensor = aten::to(%x, %dtype, %layout, %device, %pm, %nb, %copy, %format)
return (%out))IR";
std::string target_graph = R"IR(
graph(%x, %dtype, %layout, %device, %pm, %nb, %copy, %format):
%out : Tensor = aten::to(%x, %device, %dtype, %nb, %copy, %format)
return (%out))IR";

torch_tensorrt::core::util::logging::get_logger().set_reportable_log_level(
torch_tensorrt::core::util::logging::LogLevel::kGRAPH);
auto sg = std::make_shared<torch::jit::Graph>();
torch::jit::parseIR(source_graph, &*sg);
torch_tensorrt::core::lowering::passes::ReduceToOperation(sg);

auto tg = std::make_shared<torch::jit::Graph>();
torch::jit::parseIR(target_graph, &*tg);

ASSERT_TRUE(!torch::jit::findPatternMatches(*tg, *sg).empty());
}

TEST(LoweringPasses, ReduceAtenTypeAsCorrectly) {
std::string source_graph = R"IR(
graph(%input, %other):
Expand Down