From 3f397503c014aac03fe501cd953ffc4ebc24bee4 Mon Sep 17 00:00:00 2001 From: TFBunny Date: Tue, 9 Mar 2021 13:47:51 -0500 Subject: [PATCH] add dynamic shape testcases for Sub --- tests/st/ops/gpu/test_sub_op.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/tests/st/ops/gpu/test_sub_op.py b/tests/st/ops/gpu/test_sub_op.py index 1947d8e668..62cb2725fc 100644 --- a/tests/st/ops/gpu/test_sub_op.py +++ b/tests/st/ops/gpu/test_sub_op.py @@ -20,7 +20,7 @@ import mindspore.context as context import mindspore.nn as nn from mindspore import Tensor from mindspore.ops import operations as P - +from mindspore.ops.operations import _inner_ops as inner class Net(nn.Cell): def __init__(self): @@ -30,6 +30,18 @@ class Net(nn.Cell): def construct(self, x, y): return self.sub(x, y) +class NetDynamic(nn.Cell): + def __init__(self): + super(NetDynamic, self).__init__() + self.d = inner.GpuConvertToDynamicShape() + self.sub = P.Sub() + + def construct(self, x, y): + x = self.d(x) + y = self.d(y) + out = self.sub(x, y) + return out + def sub(nptype): np_x0 = np.random.uniform(-2, 2, (2, 3, 4, 4)).astype(nptype) @@ -110,6 +122,19 @@ def sub(nptype): assert np.all(diff4 < error4) assert output4.shape == expect4.shape + #dynamic shape + context.set_context(mode=context.GRAPH_MODE, device_target="GPU") + d_sub_net = NetDynamic() + output3 = d_sub_net(x3, y3) + output0 = d_sub_net(x0, y0) + diff3 = output3.asnumpy() - expect3 + assert np.all(diff3 < error3) + assert output3.shape == expect3.shape + diff0 = output0.asnumpy() - expect0 + assert np.all(diff0 < error0) + assert output0.shape == expect0.shape + + @pytest.mark.level0 @pytest.mark.platform_x86_gpu_training @pytest.mark.env_onecard