eric-haibin-lin commented on a change in pull request #8539: expose group2ctx to module URL: https://github.com/apache/incubator-mxnet/pull/8539#discussion_r149873831
########## File path: tests/python/unittest/test_module.py ########## @@ -70,6 +70,63 @@ def test_module_input_grads(): assert np.all(c_grad == 3), c_grad +def test_module_ctx_group(): + with mx.AttrScope(ctx_group='dev1'): + a = mx.symbol.Variable('a') + a = a * 2 + with mx.AttrScope(ctx_group='dev2'): + b = mx.symbol.Variable('b') + c = a + b + shape = (2, 5) + mod1 = mx.mod.Module(c, context=[mx.cpu(0)], data_names=['a', 'b'], label_names=None, + group2ctxs=[{'dev1':mx.cpu(1),'dev2':mx.cpu(2)}]) + mod1.bind(data_shapes=[['a', shape], ['b', shape]], inputs_need_grad=True) + mod1.init_params() + mod1.forward(data_batch=mx.io.DataBatch(data=[mx.nd.ones(shape), mx.nd.ones(shape)]), is_train=True) + mod1.backward([mx.nd.ones(shape)]) + mod1_input_grads = mod1.get_input_grads() + + mod2 = mx.mod.Module(c, data_names=['a', 'b'], label_names=None) + mod2.bind(data_shapes=[['a', shape], ['b', shape]], inputs_need_grad=True) + mod2.init_params() + mod2.forward(data_batch=mx.io.DataBatch(data=[mx.nd.ones(shape), mx.nd.ones(shape)]), is_train=True) + mod2.backward([mx.nd.ones(shape)]) + mod2_input_grads = mod2.get_input_grads() + + assert np.all(mod1_input_grads[0].asnumpy() == mod2_input_grads[0].asnumpy()) + assert np.all(mod1_input_grads[1].asnumpy() == mod2_input_grads[1].asnumpy()) + + +def test_bucket_module_ctx_group(): Review comment: Yeah just add `assert mod.binded ` ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services