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 2022/06/21 12:45:13 UTC

[GitHub] [incubator-mxnet] bgawrych commented on a diff in pull request #21046: [master] Node elimination graph pass

bgawrych commented on code in PR #21046:
URL: https://github.com/apache/incubator-mxnet/pull/21046#discussion_r902572550


##########
tests/python/dnnl/subgraphs/test_amp_subgraph.py:
##########
@@ -172,6 +173,7 @@ def test_amp_transformers():
 
 @mx.util.use_np
 def test_amp_concat():
+  os.environ["MXNET_NODE_ELIMINATION"] = "0"

Review Comment:
   personally I don't like this casting from nd to np - I would rather disable sharing parameters in FC and rewrite exected symbol:
   ```
   @mx.util.use_np
   def test_amp_concat():
     class TestNet(nn.HybridBlock):
       def __init__(self):
         super(TestNet, self).__init__()
         self.fc1 = nn.Dense(16)
         self.fc2 = nn.Dense(16)
   
       def forward(self, x):
         x1 = self.fc1(x)
         x2 = self.fc2(x)
         x = mx.np.concat((x1, x2), axis=1)
         return x
   
     net = TestNet()
     net.initialize()
   
     data_example = mx.np.random.uniform(-1, 1, (1, 16))
   
     exp_data = mx.symbol.Variable('data')
     exp_amp_data = mx.symbol.amp_cast(exp_data, dtype=AMP_DTYPE)
   
     exp_weight = [mx.symbol.Variable(f"fc{i}_weight") for i in range(2)]
     exp_bias = [mx.symbol.Variable(f"fc{i}_bias") for i in range(2)]
     exp_fc = [mx.symbol.FullyConnected(exp_amp_data, exp_weight[i], exp_bias[i], num_hidden=1)
               for i in range(2)]
     exp_sym = mx.symbol.Concat(*exp_fc)
     exp_sym = mx.symbol.amp_cast(exp_sym, dtype='float32')
     exp_sym = exp_sym.get_backend_symbol(SG_PASS_NAME)
     check_amp_fuse(net, [data_example], exp_sym)
   
     exp_fc[0] = mx.symbol.FullyConnected(exp_amp_data, exp_weight[0], exp_bias[0], num_hidden=1)
     exp_fc[1] = mx.symbol.FullyConnected(exp_data, exp_weight[1], exp_bias[1], num_hidden=1)
     exp_sym = mx.symbol.Concat(*exp_fc)
     exp_sym = exp_sym.get_backend_symbol(SG_PASS_NAME)
     check_amp_fuse(net, [data_example], exp_sym, ['sg_onednn_fully_connected_1'])
   ```



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@mxnet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org