-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(aten::batch_norm): A new batch norm implementation that hopefully
doesnt have the same performace cost Signed-off-by: Naren Dasan <naren@narendasan.com> Signed-off-by: Naren Dasan <narens@nvidia.com>
- Loading branch information
1 parent
2d677cd
commit 6461872
Showing
5 changed files
with
99 additions
and
87 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,36 @@ | ||
#include <string> | ||
#include "gtest/gtest.h" | ||
#include "torch/csrc/jit/ir/irparser.h" | ||
#include "tests/util/util.h" | ||
#include "core/compiler.h" | ||
|
||
TEST(Converters, ATenBatchNormConvertsCorrectly) { | ||
const auto graph = R"IR( | ||
graph(%0 : Tensor, | ||
%1: Float(5), | ||
%2: Float(5), | ||
%3: Float(5), | ||
%4: Float(5)): | ||
%5 : bool = prim::Constant[value=0]() | ||
%6 : float = prim::Constant[value=1.0000000000000001e-05]() | ||
%7 : float = prim::Constant[value=0.10000000000000001]() | ||
%8 : Tensor = aten::batch_norm(%0, %1, %2, %3, %4, %5, %6, %7, %5) | ||
return (%8))IR"; | ||
|
||
auto g = std::make_shared<torch::jit::Graph>(); | ||
torch::jit::parseIR(graph, &*g); | ||
|
||
auto in = at::randint(1, 10, {1, 5, 5, 5}, {at::kCUDA}); | ||
auto gamma = at::randint(1, 10, {5}, {at::kCUDA}); | ||
auto beta = at::randint(1, 10, {5}, {at::kCUDA}); | ||
auto mean = at::randint(1, 10, {5}, {at::kCUDA}); | ||
auto var = at::randint(1, 10, {5}, {at::kCUDA}); | ||
|
||
auto params = trtorch::core::conversion::get_named_params(g->inputs(), {gamma, beta, mean, var}); | ||
auto jit_results = trtorch::tests::util::RunGraph(g, params, {in}); | ||
|
||
params = trtorch::core::conversion::get_named_params(g->inputs(), {gamma, beta, mean, var}); | ||
auto trt_results = trtorch::tests::util::RunGraphEngine(g, params, {in}); | ||
|
||
ASSERT_TRUE(trtorch::tests::util::almostEqual(jit_results[0], trt_results[0].reshape_as(jit_results[0]), 2e-6)); | ||
} |