Skip to content
Closed
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
7 changes: 7 additions & 0 deletions benchmarks/static_runtime/test_static_runtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,12 @@ TEST(StaticRuntime, LayerNorm) {
return torch.layer_norm(input, normalized_shape, None, None, 1e-05, False).clone()
)JIT";

const std::string layer_norm_with_noncontiguous_input = R"JIT(
def forward(self, input: Tensor, normalized_shape: List[int], weight: Tensor, bias: Tensor):
input = torch.transpose(input, 1, 2)
return torch.layer_norm(input, normalized_shape, weight, bias, 1e-05, False).clone()
)JIT";

const auto a = torch::rand({1, 2, 2, 2});
const auto b = torch::rand({3, 2, 2, 2});
for (int normalized_size : {2, 3}) {
Expand All @@ -684,6 +690,7 @@ TEST(StaticRuntime, LayerNorm) {
std::vector<IValue> args1{b, normalized_shape, weight, bias};
testStaticRuntime(layer_norm_with_weights, args);
testStaticRuntime(layer_norm_with_weights, args, args1);
testStaticRuntime(layer_norm_with_noncontiguous_input, args);

args = {a, normalized_shape};
testStaticRuntime(layer_norm_without_weights, args);
Expand Down
2 changes: 1 addition & 1 deletion torch/csrc/jit/runtime/static/ops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2122,7 +2122,7 @@ REGISTER_OPERATOR_FUNCTOR(aten::layer_norm, aten_layer_norm, [](Node* n) -> SROp
p_node->Output(0).toTensor(), X->sizes(), c10::nullopt);
}
at::Tensor& output = p_node->Output(0).toTensor();
at::native::layer_norm_cpu_out(output, input, *gamma, *beta, eps, M, N);
at::native::layer_norm_cpu_out(output, *X, *gamma, *beta, eps, M, N);
};
});

Expand Down