diff --git a/tests/st/pynative/loss_scale/test_loss_scale.py b/tests/st/pynative/loss_scale/test_loss_scale.py index c80bc4367f..b17f6fbdc1 100644 --- a/tests/st/pynative/loss_scale/test_loss_scale.py +++ b/tests/st/pynative/loss_scale/test_loss_scale.py @@ -16,6 +16,7 @@ import numpy as np import pytest import mindspore.nn as nn +from mindspore import context from mindspore import Tensor, Parameter from mindspore.nn.wrap.cell_wrapper import WithLossCell from mindspore.nn.wrap.loss_scale import TrainOneStepWithLossScaleCell @@ -27,6 +28,9 @@ from mindspore.train import Model from mindspore.nn.optim import Lamb from mindspore.train.loss_scale_manager import DynamicLossScaleManager +def setup_module(): + context.set_context(mode=context.PYNATIVE_MODE, device_target="Ascend") + class MindData: """ Stub for MindData """ diff --git a/tests/st/pynative/test_function_staging.py b/tests/st/pynative/test_function_staging.py index 018548e220..a1bdbca2b9 100644 --- a/tests/st/pynative/test_function_staging.py +++ b/tests/st/pynative/test_function_staging.py @@ -15,11 +15,15 @@ import pytest import numpy as np +from mindspore import context from mindspore.nn import ReLU from mindspore.nn import Cell from mindspore.common.tensor import Tensor from mindspore.common.api import ms_function +def setup_module(): + context.set_context(mode=context.PYNATIVE_MODE, device_target="Ascend") + @pytest.mark.level0 @pytest.mark.platform_arm_ascend_training @pytest.mark.platform_x86_ascend_training diff --git a/tests/st/pynative/test_parser_operator.py b/tests/st/pynative/test_parser_operator.py new file mode 100644 index 0000000000..7dea734b5b --- /dev/null +++ b/tests/st/pynative/test_parser_operator.py @@ -0,0 +1,41 @@ +# Copyright 2020 Huawei Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ + +from mindspore import context +from mindspore.nn import ReLU +from mindspore.nn import Cell +from mindspore.common.tensor import Tensor +import numpy as np + +def setup_module(): + context.set_context(mode=context.PYNATIVE_MODE, device_target="Ascend") + +def test_parser_operator_floor_div(): + class Net(Cell): + def __init__(self): + super(Net, self).__init__() + self.relu = ReLU() + + def construct(self, x): + x = self.relu(x) + x = 3 // x + return x + + input_np_x = np.array(2).astype(np.float32) + input_me_x = Tensor(input_np_x) + net = Net() + out_me = net(input_me_x) + + assert np.allclose(out_me.asnumpy(), 3 // input_np_x, 0.001, 0.001) diff --git a/tests/st/pynative/test_parser_tensor_assign.py b/tests/st/pynative/test_parser_tensor_assign.py index b59db8134a..7b4bc672cd 100644 --- a/tests/st/pynative/test_parser_tensor_assign.py +++ b/tests/st/pynative/test_parser_tensor_assign.py @@ -16,11 +16,15 @@ import pytest import numpy as np import mindspore as ms +from mindspore import context from mindspore.nn import ReLU from mindspore.nn import Cell from mindspore.common.tensor import Tensor from mindspore.ops import operations as P +def setup_module(): + context.set_context(mode=context.PYNATIVE_MODE, device_target="Ascend") + @pytest.mark.level0 @pytest.mark.platform_arm_ascend_training @pytest.mark.platform_x86_ascend_training