larroy commented on a change in pull request #15969: Partitioning Gluon
HybridBlocks
URL: https://github.com/apache/incubator-mxnet/pull/15969#discussion_r373745860
##########
File path: tests/python/unittest/test_subgraph_op.py
##########
@@ -18,351 +18,448 @@
import os
import ctypes
import mxnet as mx
-from mxnet.base import SymbolHandle, check_call, _LIB, mx_uint, c_str_array,
c_str
+from mxnet.base import SymbolHandle, check_call, _LIB, mx_uint, c_str_array,
c_str, mx_real_t
from mxnet.symbol import Symbol
import numpy as np
from mxnet.test_utils import assert_almost_equal
-
-
-def _test_subgraph_exe(subgraph_backend):
- def _check_subgraph_exe1(sym, subgraph_backend, op_names):
- """Use the partitioned sym to simple_bind an executor and compare the
outputs
- with those of the original executor"""
- out = SymbolHandle()
- check_call(_LIB.MXBuildSubgraphByOpNames(sym.handle,
c_str(subgraph_backend), mx_uint(len(op_names)),
- c_str_array(op_names),
ctypes.byref(out)))
-
- partitioned_sym = Symbol(out)
- assert partitioned_sym.list_inputs() == sym.list_inputs()
- assert partitioned_sym.list_arguments() == sym.list_arguments()
- assert partitioned_sym.list_auxiliary_states() ==
sym.list_auxiliary_states()
+from mxnet import gluon
+from mxnet.gluon import nn
+from mxnet import nd
+
+def network_structure_1():
+ data1 = mx.sym.var('data1', shape=(2, 3, 10, 10))
+ data2 = mx.sym.var('data2')
+ conv1 = mx.sym.Convolution(data=data1, weight=data2, no_bias=True,
kernel=(2, 2), num_filter=1)
+ conv2 = mx.sym.Convolution(data=data2, no_bias=True, kernel=(1, 1),
num_filter=1)
+ out = mx.sym.Group([conv1, conv2])
+ return (out, ['data1'], [(2, 3, 10, 10)])
+
+def network_structure_2():
+ # this tests whether the partitioning algorithm can deal with cycles
+ data = mx.sym.var('data', shape=(2, 3, 10, 10))
+ ret = mx.sym.exp(data)
+ ret1 = mx.sym.cos(ret)
+ ret2 = mx.sym.sin(ret)
+ ret = ret1 + ret2
+ return (ret, ['data'], [(2, 3, 10, 10)])
+
+def network_structure_3():
+ # this tests whether the partitioned sym can distinguish in_args and
aux_states
+ data = mx.sym.var('data', shape=(2, 3, 10, 10))
+ ret = mx.sym.exp(data)
+ ret1 = mx.sym.cos(ret)
+ ret2 = mx.sym.sin(ret)
+ ret = ret1 + ret2
+ ret = mx.sym.BatchNorm(ret)
+ ret = mx.sym.BatchNorm(ret)
+ # Return the same and shape of 'data' and auxiliary states
+ return (ret, ['data', *ret.list_auxiliary_states()], [(2, 3, 10, 10),
(3,), (3,), (3,), (3,)])
+
+def network_structure_4():
+ # the last op has multiple duplicate outputs
Review comment:
I like the comments on these tests
----------------------------------------------------------------
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]
With regards,
Apache Git Services