Skip to content

Commit

Permalink
Add save/load json in testcases for foreach (apache#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
Junru Shao authored and zheng-da committed Jun 28, 2018
1 parent 535b9c7 commit 298ee88
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/python/unittest/test_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5901,6 +5901,10 @@ def verify_foreach(step, in_syms, state_syms, free_syms,
out[i] = out[i] * 2
out.extend(states)
out = mx.sym.Group(out)
js_1 = out.tojson()
out = mx.sym.load_json(js_1)
js_2 = out.tojson()
assert js_1 == js_2
arr_grads = []
arg_dict = {}
arg_grad_dict = {}
Expand Down Expand Up @@ -6048,6 +6052,10 @@ def step(in1, states):
out1[i] = out1[i]
out1.extend(out[1])
out = mx.sym.Group(out1)
js_1 = out.tojson()
out = mx.sym.load_json(js_1)
js_2 = out.tojson()
assert js_1 == js_2

data = mx.nd.arange(4).reshape((1, 2, 2))
state = mx.nd.arange(2)
Expand Down Expand Up @@ -6121,6 +6129,11 @@ def sym_group(out):
h2h_barr_grad1 = mx.nd.empty(h2h_barr.shape)
out = mx.sym.contrib.foreach(step, data, [init_h, init_c])
out = sym_group(out)
js_1 = out.tojson()
out = mx.sym.load_json(js_1)
js_2 = out.tojson()
assert js_1 == js_2

e1 = out.bind(ctx=default_context(),
args={'data': data_arr, 'h': h_arr, 'c': c_arr,
'i2h_weight': i2h_warr, 'h2h_weight': h2h_warr,
Expand Down Expand Up @@ -6152,6 +6165,11 @@ def sym_group(out):
unroll_outs.append(mx.sym.expand_dims(h, axis=0))
unroll_outs = mx.sym.concat(*unroll_outs, dim=0)
out = mx.sym.Group([unroll_outs, h, c])
js_1 = out.tojson()
out = mx.sym.load_json(js_1)
js_2 = out.tojson()
assert js_1 == js_2

e2 = out.bind(ctx=default_context(),
args={'data': data_arr, 'h': h_arr, 'c': c_arr,
'mylstm_i2h_weight': i2h_warr, 'mylstm_h2h_weight': h2h_warr,
Expand Down

0 comments on commit 298ee88

Please sign in to comment.