You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2018/06/14 00:51:45 UTC
[GitHub] eric-haibin-lin commented on a change in pull request #11229:
[MXNET-379] L1 Normalization
eric-haibin-lin commented on a change in pull request #11229: [MXNET-379] L1 Normalization
URL: https://github.com/apache/incubator-mxnet/pull/11229#discussion_r195276671
##########
File path: tests/python/unittest/test_operator.py
##########
@@ -2879,6 +2879,32 @@ def npy_layer_norm(data, gamma, beta, axis=1, eps=1E-5):
grad_nodes={'data': req, 'gamma': req, 'beta': req},
numeric_eps=1e-2, rtol=1e-2, atol=1e-2)
+@with_seed()
+def test_l1_norm():
+ ctx = default_context()
+ data = mx.symbol.Variable('data')
+ in_data_dim = random_sample([4,5,6], 1)[0]
+ in_shape = rand_shape_nd(in_data_dim)
+ for dtype in [np.float16, np.float32, np.float64]:
+ in_data = np.random.uniform(-1, 1, in_shape).astype(dtype)
+ for i in range(in_data_dim):
+ for keep_dims in [True, False]:
+ norm_sym = mx.symbol.norm(data=data, ord=1, axis=i, keepdims=keep_dims)
+ npy_out = np.sum(abs(in_data), axis=i, keepdims=keep_dims)
+ check_symbolic_forward(norm_sym, [in_data], [npy_out],
+ rtol=1e-2 if dtype is np.float16 else 1e-5,
+ atol=1e-5, ctx=ctx)
+ # check gradient
+ #check_numeric_gradient(norm_sym, [in_data], numeric_eps=1e-3, rtol=1e-2, atol=1e-3)
+ if i < in_data_dim-1:
+ norm_sym = mx.symbol.norm(data=data, ord=1, axis=(i, i+1), keepdims=keep_dims)
+ npy_out = np.sum(abs(in_data), axis=(i, i+1), keepdims=keep_dims)
+ check_symbolic_forward(norm_sym, [in_data], [npy_out],
+ rtol=1e-2 if dtype is np.float16 else 1e-5,
+ atol=1e-5, ctx=ctx)
+ # check gradient
+ #check_numeric_gradient(norm_sym, [in_data], numeric_eps=1e-3, rtol=1e-2, atol=1e-3)
Review comment:
Also - check_symbolic_backward?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services