Skip to content

fix: Add schemas to convolution lowering pass #1728

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
Mar 24, 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
2 changes: 2 additions & 0 deletions core/lowering/lowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ void LowerGraph(std::shared_ptr<torch::jit::Graph>& g, std::vector<torch::jit::I
passes::Conv1DToConvolution(g);
passes::ConvTransposed1DToConvolution(g);
passes::Conv2DToConvolution(g);
passes::ConvTransposed2DToConvolution(g);
passes::Conv3DToConvolution(g);
passes::ConvTransposed3DToConvolution(g);
passes::FuseAddMMBranches(g);
passes::RemoveBNDimCheck(g);
// torch::jit::UnrollLoops(g);
Expand Down
28 changes: 28 additions & 0 deletions core/lowering/passes/convNd_to_convolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,20 @@ void Conv2DToConvolution(std::shared_ptr<torch::jit::Graph>& graph) {
LOG_GRAPH("Post map conv2d -> _convolution: " << *graph);
}

void ConvTransposed2DToConvolution(std::shared_ptr<torch::jit::Graph>& graph) {
const std::string conv_transpose2d_node_kind = "aten::conv_transpose2d";
const std::string convolution_pattern = R"IR(
graph(%x, %w, %b, %s, %p, %o, %g, %d):
%1 : bool = prim::Constant[value=1]()
%2 : bool = prim::Constant[value=1]()
%4 : Tensor = aten::_convolution(%x, %w, %b, %s, %p, %d, %1, %o, %g, %2, %2, %2, %2)
return (%4))IR";

// Schema is aten::conv_transpose2d(%x, %w, %b, %s, %p, %o, %g, %d) --> 8 inputs
replaceConv(graph->block(), conv_transpose2d_node_kind, convolution_pattern, 8);
LOG_GRAPH("Post map conv_transpose2d -> _convolution: " << *graph);
}

void Conv3DToConvolution(std::shared_ptr<torch::jit::Graph>& graph) {
const std::string conv3d_node_kind = "aten::conv3d";
const std::string convolution_pattern = R"IR(
Expand All @@ -96,6 +110,20 @@ void Conv3DToConvolution(std::shared_ptr<torch::jit::Graph>& graph) {
LOG_GRAPH("Post map conv3d -> _convolution: " << *graph);
}

void ConvTransposed3DToConvolution(std::shared_ptr<torch::jit::Graph>& graph) {
const std::string conv_transpose3d_node_kind = "aten::conv_transpose3d";
const std::string convolution_pattern = R"IR(
graph(%x, %w, %b, %s, %p, %o, %g, %d):
%1 : bool = prim::Constant[value=1]()
%2 : bool = prim::Constant[value=1]()
%4 : Tensor = aten::_convolution(%x, %w, %b, %s, %p, %d, %1, %o, %g, %2, %2, %2, %2)
return (%4))IR";

// Schema is aten::conv_transpose3d(%x, %w, %b, %s, %p, %o, %g, %d) --> 8 inputs
replaceConv(graph->block(), conv_transpose3d_node_kind, convolution_pattern, 8);
LOG_GRAPH("Post map conv_transpose3d -> _convolution: " << *graph);
}

} // namespace passes
} // namespace lowering
} // namespace core
Expand Down
2 changes: 2 additions & 0 deletions core/lowering/passes/passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ void NotateModuleForFallback(
void Conv1DToConvolution(std::shared_ptr<torch::jit::Graph>& graph);
void ConvTransposed1DToConvolution(std::shared_ptr<torch::jit::Graph>& graph);
void Conv2DToConvolution(std::shared_ptr<torch::jit::Graph>& graph);
void ConvTransposed2DToConvolution(std::shared_ptr<torch::jit::Graph>& graph);
void Conv3DToConvolution(std::shared_ptr<torch::jit::Graph>& graph);
void ConvTransposed3DToConvolution(std::shared_ptr<torch::jit::Graph>& graph);
void FuseAddMMBranches(std::shared_ptr<torch::jit::Graph> graph);
void LinearToAddMM(std::shared_ptr<torch::jit::Graph>& graph);
void EliminateExceptionOrPassPattern(std::shared_ptr<torch::jit::Graph> graph);
Expand Down
4 changes: 2 additions & 2 deletions tests/core/lowering/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ cc_test(
)

lowering_test(
name = "test_conv1d_pass",
name = "test_conv_pass",
)

lowering_test(
Expand Down Expand Up @@ -102,7 +102,7 @@ lowering_test(
test_suite(
name = "lowering_tests",
tests = [
":test_conv1d_pass",
":test_conv_pass",
":test_device_casting",
":test_exception_elimination_pass",
":test_linear_to_addmm",
Expand Down
202 changes: 0 additions & 202 deletions tests/core/lowering/test_conv1d_pass.cpp

This file was deleted.

Loading