samskalicky commented on a change in pull request #17034: Dynamic subgraph 
property
URL: https://github.com/apache/incubator-mxnet/pull/17034#discussion_r363557990
 
 

 ##########
 File path: example/extensions/lib_subgraph/test_subgraph.py
 ##########
 @@ -39,22 +39,38 @@
 b = mx.sym.var('b')
 c = a + b
 d = mx.sym.exp(c)
-ret = mx.sym.log(d)
+sym = mx.sym.log(d)
 
-op_names = ['exp','log']
-out = SymbolHandle()
+#execute in MXNet
+print('-------------------------------')
+print('Testing regular MXNet execution')
+exe = sym.bind(ctx=mx.cpu(), args={'a':mx.nd.ones((3,2)), 
'b':mx.nd.ones((3,2))})
+out = exe.forward()
+print(out)
 
-check_call(_LIB.MXBuildSubgraphByOpNames(ret.handle,
-                                         c_str('default'),
-                                         mx_uint(len(op_names)),
-                                         c_str_array(op_names),
-                                         ctypes.byref(out)))
-partitioned_sym = mx.sym.Symbol(out)
-json_sym = partitioned_sym.tojson()
+# with propogating shapes/types
+print('-------------------------------')
+print('Testing partitioning with shapes/types')
+arg_array = [mx.nd.ones((3,2),dtype='float32'), 
mx.nd.ones((3,2),dtype='float32')]
+mysym2 = sym.optimize_for("myProp",arg_array)
+print(mysym2.tojson())
+exe2 = mysym2.bind(ctx=mx.cpu(), args={'a':mx.nd.ones((3,2)), 
'b':mx.nd.ones((3,2))})
+out2 = exe2.forward()
+print(out2)
 
-mystr = json_sym.replace("_CachedOp","_custom_subgraph_op")
-mysym = mx.sym.load_json(mystr)
+# with propogating shapes/types, rejecting subgraph
+print('-------------------------------')
+print('Testing partitioning with shapes/types - rejecting subgraph')
+arg_array = [mx.nd.ones((3,2),dtype='float32'), 
mx.nd.ones((3,2),dtype='float32')]
+mysym2 = sym.optimize_for("myProp", arg_array, reject=True)
+exe2 = mysym2.bind(ctx=mx.cpu(), args={'a':mx.nd.ones((3,2)), 
'b':mx.nd.ones((3,2))})
+out2 = exe2.forward()
+print(out2)
 
-exe = mysym.bind(ctx=mx.cpu(), args={'a':mx.nd.ones((3,2)), 
'b':mx.nd.ones((3,2))})
-out = exe.forward()
-print(out)
+# without propogating shapes/types
+print('-------------------------------')
+print('Testing partitioning without shapes/types')
+mysym3 = sym.optimize_for("myProp", myOpt='yello')
+exe3 = mysym3.bind(ctx=mx.cpu(), args={'a':mx.nd.ones((3,2)), 
'b':mx.nd.ones((3,2))})
+out3 = exe3.forward()
+print(out3)
 
 Review comment:
   No, we didnt add this for SymbolBlock in the PR which added the 
`optimize_for` API #15886
   
   Thats something that can be done in the future though. ill make note of that

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to