Skip to content
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
17 changes: 12 additions & 5 deletions core/lowering/passes/unpack_var.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,18 @@ void UnpackVar(std::shared_ptr<torch::jit::Graph>& graph) {
%var: Tensor = aten::sub(%sqrdmean, %meansqrd, %1)
%varout : Tensor = prim::If(%unbiased)
block0():
%shape: int[] = aten::size(%input)
%shapet: Tensor = aten::tensor(%shape, %f32_dtype, %none, %false)
%dim: int = prim::ListUnpack(%dims)
%reduceddims: Tensor = aten::select(%shapet, %0, %dim)
%numel: Tensor = aten::prod(%reduceddims, %dim, %keepdim, %none)
# Compute number of elements in original input tensor
%originalshape: int[] = aten::size(%input)
%originalshapet: Tensor = aten::tensor(%originalshape, %f32_dtype, %none, %false)
%originalnumel: Tensor = aten::prod(%originalshapet, %0, %false, %none)
# Compute number of elements in resulting output tensor
%resultingshape: int[] = aten::size(%var)
%resultingshapet: Tensor = aten::tensor(%resultingshape, %f32_dtype, %none, %false)
%resultingnumel: Tensor = aten::prod(%resultingshapet, %0, %false, %none)
# Quotient of original number of elements and resulting number of elements
# is equal to the number of elements used per variance calculation
%numel: Tensor = aten::div(%originalnumel, %resultingnumel)
# Perform Bessel's correction on computed variance
%mul: Tensor = aten::mul(%var, %numel)
%sub: Tensor = aten::sub(%numel, %1, %1)
%v: Tensor = aten::div(%mul, %sub)
Expand Down
3 changes: 2 additions & 1 deletion tests/core/conversion/converters/test_reduce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,8 @@ TEST(Converters, UnpackStdUnbiasedKeepDimsLowersCorrectly) {
%5 : bool = prim::Constant[value=0]() # test_zeros.py:10:65
%4 : bool = prim::Constant[value=1]() # test_zeros.py:10:50
%3 : int = prim::Constant[value=0]() # test_zeros.py:10:39
%6 : int[] = prim::ListConstruct(%3)
%one : int = prim::Constant[value=1]()
%6 : int[] = prim::ListConstruct(%3, %one)
%7 : Tensor = aten::std(%x.1, %6, %4, %5) # test_zeros.py:10:26
return (%7))IR";

Expand Down
6 changes: 4 additions & 2 deletions tests/core/lowering/test_unpack_reduce_ops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ TEST(LoweringPasses, UnpackStdKeepDimsLowersCorrectly) {
%5 : bool = prim::Constant[value=0]() # test_zeros.py:10:65
%4 : bool = prim::Constant[value=1]() # test_zeros.py:10:50
%3 : int = prim::Constant[value=0]() # test_zeros.py:10:39
%6 : int[] = prim::ListConstruct(%3)
%one : int = prim::Constant[value=1]()
%6 : int[] = prim::ListConstruct(%3, %one)
%7 : Tensor = aten::std(%x.1, %6, %5, %5) # test_zeros.py:10:26
return (%7))IR";

Expand Down Expand Up @@ -184,7 +185,8 @@ TEST(LoweringPasses, UnpackStdUnbiasedKeepDimsLowersCorrectly) {
%5 : bool = prim::Constant[value=0]() # test_zeros.py:10:65
%4 : bool = prim::Constant[value=1]() # test_zeros.py:10:50
%3 : int = prim::Constant[value=0]() # test_zeros.py:10:39
%6 : int[] = prim::ListConstruct(%3)
%one : int = prim::Constant[value=1]()
%6 : int[] = prim::ListConstruct(%3, %one)
%7 : Tensor = aten::std(%x.1, %6, %4, %5) # test_zeros.py:10:26
return (%7))IR";

Expand Down