szha commented on a change in pull request #18500:
URL: https://github.com/apache/incubator-mxnet/pull/18500#discussion_r436426078



##########
File path: tests/python/unittest/test_operator.py
##########
@@ -1944,20 +1960,27 @@ def _test_batchnorm_impl(op, shape, axis, cudnn_off, 
output_mean_var):
             ), running_var.asnumpy(), atol=atol, rtol=rtol)
 
             assert_almost_equal(data.grad.asnumpy(),
-                                dX.asnumpy(), atol=atol, rtol=rtol)
-            assert_almost_equal(
-                bn_gamma.grad.asnumpy(), dW.asnumpy(), atol=atol, rtol=rtol)
+                                adX.asnumpy(), atol=atol, rtol=rtol)
+            if not fix_gamma:
+                assert_almost_equal(
+                    bn_gamma.grad.asnumpy(), adW.asnumpy(),
+                    atol=atol, rtol=rtol)
+            else:
+                assert((bn_gamma.asnumpy() == 1).all())
             assert_almost_equal(
-                bn_beta.grad.asnumpy(), db.asnumpy(), atol=atol, rtol=rtol)
+                bn_beta.grad.asnumpy(), adb.asnumpy(), atol=atol, rtol=rtol)
 
     for op in [mx.nd.BatchNorm, mx.nd.contrib.SyncBatchNorm]:
-        for shape in [(24, 2), (24, 3, 4), (24, 4, 4, 4), (24, 8, 4, 4), (24, 
5, 6, 4, 4)]:
+        for shape in [(24, 2), (24, 3, 4), (24, 4, 4, 4),
+                (24, 8, 4, 4), (24, 5, 6, 4, 4)]:
             for axis in range(len(shape)):
-                for cudnn_off in [False, True]:
-                    for output_mean_var in [False, True]:
-                        _test_batchnorm_impl(op, shape, axis,
-                                             cudnn_off, output_mean_var)
-
+                for fix_gamma in [False, True]:
+                    for grad_req in ['write', 'add']:

Review comment:
       in gluon, the grad req can actually differ in gamma and beta. could you 
test the different combinations?




----------------------------------------------------------------
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:
[email protected]


Reply via email to