Browse Source

!6969 Add st for pynative mode part3

Merge pull request !6969 from Simson/push-to-opensource
tags/v1.1.0
mindspore-ci-bot Gitee 5 years ago
parent
commit
db14ab7fb2
4 changed files with 79 additions and 4 deletions
  1. +1
    -1
      tests/st/pynative/loss_scale/test_loss_scale.py
  2. +70
    -0
      tests/st/pynative/parser/test_parser_construct.py
  3. +7
    -2
      tests/st/pynative/parser/test_parser_operator.py
  4. +1
    -1
      tests/st/pynative/parser/test_parser_tensor_assign.py

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

@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
""" test_loss_scale """
import numpy as np
import pytest
import mindspore.nn as nn


+ 70
- 0
tests/st/pynative/parser/test_parser_construct.py View File

@@ -0,0 +1,70 @@
# 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.
# ============================================================================
""" test_parser_construct """
import pytest
import numpy as np
from mindspore import context
from mindspore.nn import Cell
from mindspore.common.tensor import Tensor
from mindspore.ops import operations as P
from mindspore.ops.composite import GradOperation

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
@pytest.mark.env_onecard
def test_parser_construct():
class ParentNet(Cell):
def __init__(self):
super().__init__()
self.relu = P.ReLU()

def construct(self, x):
return self.relu(x)

class UncleNet(Cell):
def __init__(self):
super(UncleNet, self).__init__()
self.sigmoid = P.Sigmoid()

def construct(self, x):
return self.sigmoid(x)

class Net(UncleNet, ParentNet):
def __init__(self):
super().__init__()
super(UncleNet, self).__init__()

def construct(self, x):
return super(UncleNet, self).construct(x)

input_np_x = np.ones([2, 3, 4, 5]).astype(np.float32)
out_np = np.ones([2, 3, 4, 5]).astype(np.float32)

input_me = Tensor(input_np_x)
output_grad_me = Tensor(out_np)
net = Net()
out_me = net(input_me)

net1 = Net()
grad = GradOperation(sens_param=True)
grad_op = grad(net1)
grad_me = grad_op(input_me, output_grad_me)

assert np.allclose(input_np_x, out_me.asnumpy(), 0.001, 0.001)
assert np.allclose(input_np_x, grad_me.asnumpy(), 0.001, 0.001)

tests/st/pynative/test_parser_operator.py → tests/st/pynative/parser/test_parser_operator.py View File

@@ -12,16 +12,21 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================

""" test_parser_operator """
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
import numpy as np

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
@pytest.mark.env_onecard
def test_parser_operator_floor_div():
class Net(Cell):
def __init__(self):

tests/st/pynative/test_parser_tensor_assign.py → tests/st/pynative/parser/test_parser_tensor_assign.py View File

@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
""" test_parser_tensor_assign """
import pytest
import numpy as np
import mindspore as ms

Loading…
Cancel
Save