-
Notifications
You must be signed in to change notification settings - Fork 361
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(aten::Int): Adding a new pass to remove single use
0D Tensors Now we remove select more complex aten::Int cases found in models such as BERT, like the following: ``` graph(%0: int): %1: Tensor = prim::Constant[value={8}]() %2: int = prim::Constant[value=1]() %3: Tensor = prim::NumToTensor(%0) %4: Tensor = aten::add(%1, %3, %2) %5: int = aten::Int(%4) %6: int = aten::add(%5, %5) return (%6)"; graph(%0: int): %1: int = prim::Constant[value=8]() %4: int = aten::add(%1, %0) %6: int = aten::add(%4, %4) return (%6)"; ``` Signed-off-by: Naren Dasan <[email protected]> Signed-off-by: Naren Dasan <[email protected]>
- Loading branch information
1 parent
908340f
commit 46ac757
Showing
5 changed files
with
232 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include <stack> | ||
#include <unordered_set> | ||
|
||
#include "torch/csrc/jit/passes/subgraph_rewrite.h" | ||
|
||
#include "core/lowering/passes/passes.h" | ||
#include "core/util/prelude.h" | ||
|
||
namespace torch_tensorrt { | ||
namespace core { | ||
namespace lowering { | ||
namespace passes { | ||
|
||
void RemoveSetAttrs(const torch::jit::Module& mod, std::string method_name) { | ||
auto g = mod.get_method(method_name).graph(); | ||
|
||
std::string set_attr_pattern = R"IR( | ||
graph(%self, %0): | ||
None = prim::SetAttr[name="_has_warned"](%self, %0) | ||
return ())IR"; | ||
std::string no_set_attr_pattern = R"IR( | ||
graph(%self, %0): | ||
return ())IR"; | ||
|
||
// remove contiguous | ||
torch::jit::SubgraphRewriter remove_set_attr; | ||
remove_set_attr.RegisterRewritePattern(set_attr_pattern, no_set_attr_pattern); | ||
remove_set_attr.runOnGraph(g); | ||
LOG_GRAPH("Post remove contiguous: " << *g); | ||
} | ||
|
||
} // 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