|
|
|
@ -50,8 +50,9 @@ class TestScatterUpdateDynamicNet(nn.Cell):
|
|
|
|
|
self.updates = Parameter(updates, name="updates")
|
|
|
|
|
|
|
|
|
|
def construct(self):
|
|
|
|
|
out = self.test_dynamic(self.inputx)
|
|
|
|
|
out = self.scatter_update(out, self.indices, self.updates)
|
|
|
|
|
indices = self.test_dynamic(self.indices)
|
|
|
|
|
updates = self.test_dynamic(self.updates)
|
|
|
|
|
out = self.scatter_update(self.inputx, indices, updates)
|
|
|
|
|
return out
|
|
|
|
|
|
|
|
|
|
def scatter_update_d_net(inputx, indices, updates):
|
|
|
|
@ -60,22 +61,24 @@ def scatter_update_d_net(inputx, indices, updates):
|
|
|
|
|
return net()
|
|
|
|
|
|
|
|
|
|
class TestScatterUpdateDynamicNet2(nn.Cell):
|
|
|
|
|
def __init__(self):
|
|
|
|
|
def __init__(self, inputx):
|
|
|
|
|
super(TestScatterUpdateDynamicNet2, self).__init__()
|
|
|
|
|
self.scatter_update = P.ScatterUpdate()
|
|
|
|
|
self.test_dynamic = inner.GpuConvertToDynamicShape()
|
|
|
|
|
self.inputx = Parameter(inputx, name="inputx")
|
|
|
|
|
|
|
|
|
|
def construct(self, inputx, indices, updates):
|
|
|
|
|
out = self.test_dynamic(inputx)
|
|
|
|
|
out = self.scatter_update(out, indices, updates)
|
|
|
|
|
def construct(self, indices, updates):
|
|
|
|
|
indices = self.test_dynamic(indices)
|
|
|
|
|
updates = self.test_dynamic(updates)
|
|
|
|
|
out = self.scatter_update(self.inputx, indices, updates)
|
|
|
|
|
return out
|
|
|
|
|
|
|
|
|
|
def scatter_update_d2_net(inputx_1, indices_1, updates_1, inputx_2,
|
|
|
|
|
def scatter_update_d2_net(inputx, indices_1, updates_1,
|
|
|
|
|
indices_2, updates_2):
|
|
|
|
|
context.set_context(mode=context.GRAPH_MODE, device_target="GPU")
|
|
|
|
|
net = TestScatterUpdateDynamicNet2()
|
|
|
|
|
out1 = net(inputx_1, indices_1, updates_1)
|
|
|
|
|
out2 = net(inputx_2, indices_2, updates_2)
|
|
|
|
|
net = TestScatterUpdateDynamicNet2(inputx)
|
|
|
|
|
out1 = net(indices_1, updates_1)
|
|
|
|
|
out2 = net(indices_2, updates_2)
|
|
|
|
|
return (out1, out2)
|
|
|
|
|
|
|
|
|
|
@pytest.mark.level0
|
|
|
|
@ -90,6 +93,19 @@ def test_scatter_update_small_float32():
|
|
|
|
|
[3., 4., 5.]])
|
|
|
|
|
np.testing.assert_array_almost_equal(output.asnumpy(), expected)
|
|
|
|
|
|
|
|
|
|
@pytest.mark.level0
|
|
|
|
|
@pytest.mark.platform_x86_gpu_training
|
|
|
|
|
@pytest.mark.env_onecard
|
|
|
|
|
def test_scatter_update_input_updated():
|
|
|
|
|
inputx = Tensor(np.zeros((2, 3)).astype(np.float32))
|
|
|
|
|
indices = Tensor(np.array([0, 1]).astype(np.int32))
|
|
|
|
|
updates = Tensor(np.arange(6).reshape((2, 3)).astype(np.float32))
|
|
|
|
|
net = TestScatterUpdateNet(inputx, indices, updates)
|
|
|
|
|
net()
|
|
|
|
|
expected = np.array([[0., 1., 2.],
|
|
|
|
|
[3., 4., 5.]])
|
|
|
|
|
np.testing.assert_array_almost_equal(net.inputx.asnumpy(), expected)
|
|
|
|
|
|
|
|
|
|
@pytest.mark.level0
|
|
|
|
|
@pytest.mark.platform_x86_gpu_training
|
|
|
|
|
@pytest.mark.env_onecard
|
|
|
|
@ -328,20 +344,16 @@ def test_scatter_update_disordered_dynamic_int32():
|
|
|
|
|
@pytest.mark.platform_x86_gpu_training
|
|
|
|
|
@pytest.mark.env_onecard
|
|
|
|
|
def test_scatter_update_two_inputs():
|
|
|
|
|
inputx_1 = Tensor(np.zeros((2, 3)).astype(np.float32))
|
|
|
|
|
inputx = Tensor(np.zeros((2, 3)).astype(np.float32))
|
|
|
|
|
indices_1 = Tensor(np.array([0, 1]).astype(np.int32))
|
|
|
|
|
updates_1 = Tensor(np.arange(6).reshape((2, 3)).astype(np.float32))
|
|
|
|
|
inputx_2 = Tensor(np.array([[0.214141, 0.415151, 0.51516],
|
|
|
|
|
[0.876542, 0.451611, 0.55112],
|
|
|
|
|
[0.111244, 0.633333, 0.34444]]).astype(np.float32))
|
|
|
|
|
indices_2 = Tensor(np.array([1, 0, 2]).astype(np.int32))
|
|
|
|
|
updates_2 = Tensor(np.arange(34, 43).reshape((3, 3)).astype(np.float32))
|
|
|
|
|
output_1, output_2 = scatter_update_d2_net(inputx_1, indices_1, updates_1,
|
|
|
|
|
inputx_2, indices_2, updates_2)
|
|
|
|
|
indices_2 = Tensor(np.array([1]).astype(np.int32))
|
|
|
|
|
updates_2 = Tensor(np.arange(34, 37).reshape((1, 3)).astype(np.float32))
|
|
|
|
|
output_1, output_2 = scatter_update_d2_net(inputx, indices_1, updates_1,
|
|
|
|
|
indices_2, updates_2)
|
|
|
|
|
expected_1 = np.array([[0., 1., 2.],
|
|
|
|
|
[3., 4., 5.]])
|
|
|
|
|
expected_2 = np.array([[37., 38., 39.],
|
|
|
|
|
[34., 35., 36.],
|
|
|
|
|
[40., 41., 42.]], dtype=np.float32)
|
|
|
|
|
[3., 4., 5.]], dtype=np.float32)
|
|
|
|
|
expected_2 = np.array([[0., 1., 2.],
|
|
|
|
|
[34., 35., 36.]], dtype=np.float32)
|
|
|
|
|
np.testing.assert_array_almost_equal(output_1.asnumpy(), expected_1)
|
|
|
|
|
np.testing.assert_array_almost_equal(output_2.asnumpy(), expected_2)
|
|
|
|
|