Browse Source

add st for pynative mode part2

tags/v1.1.0
simson simson 5 years ago
parent
commit
be56104113
4 changed files with 53 additions and 0 deletions
  1. +4
    -0
      tests/st/pynative/loss_scale/test_loss_scale.py
  2. +4
    -0
      tests/st/pynative/test_function_staging.py
  3. +41
    -0
      tests/st/pynative/test_parser_operator.py
  4. +4
    -0
      tests/st/pynative/test_parser_tensor_assign.py

+ 4
- 0
tests/st/pynative/loss_scale/test_loss_scale.py View File

@@ -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 """



+ 4
- 0
tests/st/pynative/test_function_staging.py View File

@@ -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


+ 41
- 0
tests/st/pynative/test_parser_operator.py View File

@@ -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)

+ 4
- 0
tests/st/pynative/test_parser_tensor_assign.py View File

@@ -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


Loading…
Cancel
Save