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 2019/10/08 10:08:12 UTC

[GitHub] [incubator-mxnet] marcoabreu commented on a change in pull request #16184: Add large tensor nightly tests for MKL-DNN operators

marcoabreu commented on a change in pull request #16184: Add large tensor nightly tests for MKL-DNN operators
URL: https://github.com/apache/incubator-mxnet/pull/16184#discussion_r332433203
 
 

 ##########
 File path: tests/nightly/test_large_array.py
 ##########
 @@ -751,34 +767,55 @@ def test_activation():
 
     # Hyperbolic tangent (tanh)
     # y = (exp(x)-exp(-x))/(exp(x)+exp(-x))
-    a = mx.nd.Activation(a, act_type="tanh")
+    b = mx.nd.Activation(a, act_type="tanh")
     tanh_x = (np.exp(test_x)-np.exp(-test_x))/(np.exp(test_x)+np.exp(-test_x))
-    assert a[-1][-1] == tanh_x
+    assert b[-1][-1] == tanh_x
 
     # Recitified Linear Unit (relu)
     # y = max(x,0)
-    a = mx.nd.Activation(a, act_type="relu")
-    assert a[-1][-1] == 0
+    b = mx.nd.Activation(a, act_type="relu")
+    assert b[-1][-1] == 0.
 
     # Sigmoid
-    # y = x/(1+abs(x))
-    a = mx.nd.Activation(a, act_type="sigmoid")
-    sigmoid_x = 1/(1+math.exp(-test_x))
-    assert a[-1][-1] == sigmoid_x
+    # y = x/(1+exp(-x))
+    b = mx.nd.Activation(a, act_type="sigmoid")
+    sigmoid_x = 1 / (1 + math.exp(-test_x))
+    assert_almost_equal(b.asnumpy()[-1][-1], sigmoid_x)
 
     # Soft Sign
-    # y = 1/(1+exp(-x))
-    a = mx.nd.Activation(a, act_type="softsign")
-    softsign_x = test_x/(1+abs(test_x))
-    assert a[-1][-1] == softsign_x
+    # y = x/(1+abs(x))
+    b = mx.nd.Activation(a, act_type="softsign")
+    softsign_x = test_x / (1 + abs(test_x))
+    assert_almost_equal(b.asnumpy()[-1][-1], softsign_x)
 
 
 # TODO: correctness of batchnorm
 # in future, we could test if mean, var of output
 # matches target output's mean, var
 def test_batchnorm():
-    shape = (LARGE_X, SMALL_Y)
+    def get_ref_mean_var(data, running_mean, running_var, eps, use_global_status=True):
+        if not use_global_status:
+            # train mode, calculate the real mean and var
+            mean = nd.mean(data, axis=1, exclude=1)
+            mean_broad = nd.expand_dims(mean, axis=0)
+            mean_broad = nd.expand_dims(mean_broad, axis=2)
+            mean_broad = nd.expand_dims(mean_broad, axis=3)
+            mean_broad = nd.broadcast_like(mean_broad, data)
+            var = nd.multiply(data - mean_broad, data - mean_broad)
+            var = nd.mean(var, axis=1, exclude=1)
+        else:
+            # inference mode, use running_mean and running_var instead
+            mean = nd.full((data.shape[1],), running_mean)
+            var = nd.full((data.shape[1],), running_var)
+        
+        # calculate the inverse of standard variance
+        stdvar = 1. / nd.sqrt(var + eps)
+        nd.waitall()
+        return mean, stdvar
+
+    shape = (MEDIUM_X, MEDIUM_X, SMALL_Y, SMALL_Y)
 
 Review comment:
   You are changing the test by getting rid of LARGE_X, is that on purpose?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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