From: Sebastian Messmer Date: Tue, 15 Jan 2019 19:24:00 +0000 (-0800) Subject: Test cases for calling caffe2 LayerNorm from PyTorch and JIT X-Git-Tag: accepted/tizen/6.5/unified/20211028.231830~1841 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=57b5e7572bfdebf399818eda58362d10654053c4;p=platform%2Fupstream%2Fpytorch.git Test cases for calling caffe2 LayerNorm from PyTorch and JIT Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/15895 Reviewed By: dzhulgakov Differential Revision: D13615336 fbshipit-source-id: de28fef8ce025d6d37a4c80c029ec97b7195cfd9 --- diff --git a/caffe2/python/operator_test/layer_norm_op_test.py b/caffe2/python/operator_test/layer_norm_op_test.py index ed618ed..892b9cc 100644 --- a/caffe2/python/operator_test/layer_norm_op_test.py +++ b/caffe2/python/operator_test/layer_norm_op_test.py @@ -118,6 +118,21 @@ class TestLayerNormOp(serial.SerializedTestCase): ) @given(X=hu.tensors(n=1), **hu.gcs) + def test_layer_norm_op_pytorch(self, X, gc, dc): + X = X[0] + if len(X.shape) == 1: + X = np.expand_dims(X, axis=0) + axis = np.random.randint(0, len(X.shape)) + epsilon = 1e-4 + + expected_norm, expected_mean, expected_stdev = _layer_norm_ref(axis, epsilon, X) + actual_norm, actual_mean, actual_stdev = torch.ops.caffe2.layer_norm_dont_use_this_op_yet(torch.tensor(X), axis, epsilon) + + torch.testing.assert_allclose(expected_norm, actual_norm) + torch.testing.assert_allclose(expected_mean, actual_mean) + torch.testing.assert_allclose(expected_stdev, actual_stdev) + + @given(X=hu.tensors(n=1), **hu.gcs) def test_layer_norm_brew_wrapper(self, X, gc, dc): X = X[0] if len(X.shape) == 1: