-
Notifications
You must be signed in to change notification settings - Fork 360
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2105 from andi4191/anurag.dixit/aten_tile
feat: Added support for aten::tile converter
- Loading branch information
Showing
9 changed files
with
193 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,25 @@ | ||
#include "core/util/prelude.h" | ||
#include "torch/csrc/jit/passes/subgraph_rewrite.h" | ||
|
||
namespace torch_tensorrt { | ||
namespace core { | ||
namespace lowering { | ||
namespace passes { | ||
void ReplaceTileWithRepeat(std::shared_ptr<torch::jit::Graph>& graph) { | ||
std::string tile_pattern = R"IR( | ||
graph(%input, %1): | ||
%2 = aten::tile(%input, %1) | ||
return (%2))IR"; | ||
std::string repeat_pattern = R"IR( | ||
graph(%input, %1): | ||
%2 = aten::repeat(%input, %1) | ||
return (%2))IR"; | ||
torch::jit::SubgraphRewriter tile_to_repeat; | ||
tile_to_repeat.RegisterRewritePattern(tile_pattern, repeat_pattern); | ||
tile_to_repeat.runOnGraph(graph); | ||
LOG_GRAPH("Mapping tile -> repeat: " << *graph); | ||
} | ||
} // namespace passes | ||
} // namespace lowering | ||
} // namespace core | ||
} // namespace torch_tensorrt |
This file contains 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 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 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 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,26 @@ | ||
#include <string> | ||
#include "core/compiler.h" | ||
#include "core/lowering/passes/passes.h" | ||
#include "gtest/gtest.h" | ||
#include "tests/util/util.h" | ||
#include "torch/csrc/jit/ir/irparser.h" | ||
#include "torch/csrc/jit/ir/subgraph_matcher.h" | ||
|
||
TEST(LoweringPasses, TileToRepeatCorrectly) { | ||
std::string source_graph = R"IR( | ||
graph(%input, %dim): | ||
%o : Tensor = aten::tile(%input, %dim) | ||
return (%o))IR"; | ||
std::string target_graph = R"IR( | ||
graph(%input, %dim): | ||
%o : Tensor = aten::repeat(%input, %dim) | ||
return (%o))IR"; | ||
auto sg = std::make_shared<torch::jit::Graph>(); | ||
torch::jit::parseIR(source_graph, sg.get()); | ||
torch_tensorrt::core::lowering::passes::ReplaceTileWithRepeat(sg); | ||
|
||
auto tg = std::make_shared<torch::jit::Graph>(); | ||
torch::jit::parseIR(target_graph, tg.get()); | ||
|
||
ASSERT_TRUE(!torch::jit::findPatternMatches(*tg, *sg).empty()); | ||
} |