-
Notifications
You must be signed in to change notification settings - Fork 364
Adding the new device API, fixing the a nested dict issue in the existing compile phase, adding new lowering pass for bn #288
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
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6eeba1c
feat(//py): [to_backend] adding device specification support for
narendasan 3d14cda
feat(//core/lowering): Adding a new pass to handle new dim checks for
narendasan 0618b6b
refactor!: Update bazel and trt versions
narendasan 57c6d46
docs: Update the docs to include new device API for to_backend
narendasan 0815680
refactor: Lint code
narendasan 5031324
refactor: Addressing PR comments
narendasan 6b942e5
fix(//py): Fix bounds for enum macros
narendasan 86bb5b7
fix(//core/lowering): fix debug message for bn dim check removal pass
narendasan 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
3.7.0 | ||
4.0.0 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#include "torch/csrc/jit/ir/alias_analysis.h" | ||
#include "torch/csrc/jit/jit_log.h" | ||
#include "torch/csrc/jit/passes/constant_propagation.h" | ||
#include "torch/csrc/jit/passes/dead_code_elimination.h" | ||
#include "torch/csrc/jit/passes/guard_elimination.h" | ||
#include "torch/csrc/jit/passes/peephole.h" | ||
#include "torch/csrc/jit/runtime/graph_executor.h" | ||
|
||
#include "core/util/prelude.h" | ||
|
||
#include <vector> | ||
|
||
namespace trtorch { | ||
namespace core { | ||
namespace lowering { | ||
namespace passes { | ||
namespace { | ||
using namespace torch::jit; | ||
struct BNDimCheckRemoval { | ||
BNDimCheckRemoval(std::shared_ptr<Graph> graph) : graph_(std::move(graph)) {} | ||
|
||
void run() { | ||
findBNDimCheckNodes(graph_->block()); | ||
torch::jit::EliminateDeadCode(graph_); | ||
LOG_GRAPH("Post batch norm dim check removal: " << *graph_); | ||
} | ||
|
||
private: | ||
bool isBNDimCheckNodes(Node* n) { | ||
/// Check if this Node hosts a pattern like so: | ||
/// %290 : bool = aten::ne(%289, %9) | ||
/// = prim::If(%290) | ||
/// block0(): | ||
/// %291 : str = aten::format(%10, %289) | ||
/// = prim::RaiseException(%291) | ||
/// -> () | ||
/// block1(): | ||
/// -> () | ||
|
||
if (n->blocks().size() != 2) { | ||
return false; | ||
} | ||
auto arm1 = n->blocks()[0]; | ||
auto arm2 = n->blocks()[1]; | ||
if (arm1->outputs().size() != 0 || arm2->outputs().size() != 0) { | ||
// Make sure that the node doesn't actually produce any Value that are | ||
// used by other nodes | ||
return false; | ||
} | ||
|
||
auto arm1_start = arm1->nodes().begin(); | ||
|
||
if ((*arm1_start)->kind() != c10::Symbol::fromQualString("aten::format") && | ||
(*(++arm1_start))->kind() != prim::RaiseException && (*(++arm1_start))->kind() != prim::Return) { | ||
// Make sure that block0 is solely just the exception and the return | ||
return false; | ||
} | ||
|
||
if ((*(arm2->nodes().begin()))->kind() != prim::Return) { | ||
// Make sure that block1 is solely the return | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
void findBNDimCheckNodes(Block* b) { | ||
for (auto it = b->nodes().begin(); it != b->nodes().end(); it++) { | ||
auto n = *it; | ||
if (n->kind() == prim::If && isBNDimCheckNodes(n)) { | ||
LOG_GRAPH("Found that node " << *n << " is an batch norm dim check node (EliminateChecks)" << std::endl); | ||
it.destroyCurrent(); | ||
} | ||
} | ||
} | ||
|
||
std::shared_ptr<Graph> graph_; | ||
}; | ||
} // namespace | ||
|
||
void RemoveBNDimCheck(std::shared_ptr<Graph> graph) { | ||
BNDimCheckRemoval bndcr(std::move(graph)); | ||
bndcr.run(); | ||
} | ||
|
||
} // namespace passes | ||
} // namespace lowering | ||
} // namespace core | ||
} // namespace trtorch |
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
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 |
---|---|---|
|
@@ -19,8 +19,12 @@ def setUp(self): | |
"refit": False, | ||
"debug": False, | ||
"strict_types": False, | ||
"allow_gpu_fallback": True, | ||
"device_type": "gpu", | ||
"device": { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @andi4191 This struct looks correct to you right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you are missing dla_core. |
||
"device_type": trtorch.DeviceType.GPU, | ||
"gpu_id": 0, | ||
"dla_core": 0, | ||
"allow_gpu_fallback": True | ||
}, | ||
"capability": trtorch.EngineCapability.default, | ||
"num_min_timing_iters": 2, | ||
"num_avg_timing_iters": 1, | ||
|
@@ -29,14 +33,14 @@ def setUp(self): | |
} | ||
|
||
def test_to_backend_lowering(self): | ||
trt_mod = torch._C._jit_to_tensorrt(self.scripted_model._c, {"forward": self.spec}) | ||
trt_mod = torch._C._jit_to_backend("tensorrt", self.scripted_model, self.spec) | ||
same = (trt_mod.forward(self.input) - self.scripted_model(self.input)).abs().max() | ||
self.assertTrue(same < 2e-3) | ||
|
||
|
||
def test_suite(): | ||
suite = unittest.TestSuite() | ||
suite.addTest(TestToBackendLowering.parametrize(TestToBackendLowering, model=models.mobilenet_v2(pretrained=True))) | ||
suite.addTest(TestToBackendLowering.parametrize(TestToBackendLowering, model=models.resnet18(pretrained=True))) | ||
|
||
return suite | ||
|
||
|
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.