!6969 Add st for pynative mode part3

Merge pull request !6969 from Simson/push-to-opensource
pull/6969/MERGE
mindspore-ci-bot 4 years ago committed by Gitee
commit db14ab7fb2

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

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

@ -12,16 +12,21 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# ============================================================================ # ============================================================================
""" test_parser_operator """
import pytest
import numpy as np
from mindspore import context from mindspore import context
from mindspore.nn import ReLU from mindspore.nn import ReLU
from mindspore.nn import Cell from mindspore.nn import Cell
from mindspore.common.tensor import Tensor from mindspore.common.tensor import Tensor
import numpy as np
def setup_module(): def setup_module():
context.set_context(mode=context.PYNATIVE_MODE, device_target="Ascend") 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(): def test_parser_operator_floor_div():
class Net(Cell): class Net(Cell):
def __init__(self): def __init__(self):

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