• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2023 Huawei Technologies Co., Ltd
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14# ============================================================================
15
16import pytest
17
18import mindspore as ms
19import mindspore.nn as nn
20from mindspore import Tensor, Parameter, ParameterTuple
21import numpy as np
22
23
24class Net(nn.Cell):
25    def __init__(self, pt):
26        super(Net, self).__init__()
27        self.a = ms.Tensor(2.)
28        self.b = pt
29
30
31@pytest.mark.level1
32@pytest.mark.platform_arm_ascend_training
33@pytest.mark.platform_x86_ascend_training
34@pytest.mark.platform_x86_gpu_training
35@pytest.mark.platform_x86_cpu
36@pytest.mark.platform_arm_cpu
37@pytest.mark.env_onecard
38@pytest.mark.parametrize('mode', [ms.GRAPH_MODE, ms.PYNATIVE_MODE])
39def test_Cell_del_tensor_paratuple_attr_case(mode):
40    """
41    Feature: Cell
42    Description: Verify the result of Cell deleting attribute which type is Tensor or ParameterTuple.
43    Expectation: success
44    """
45    ms.set_context(mode=mode)
46    x = Parameter(Tensor(np.array([[1, 2], [3, 4]], dtype=np.float32)), name="param")
47    y = Parameter(Tensor(np.array([[5, 6], [7, 8]], dtype=np.float32)), name="param1")
48    pt = ParameterTuple([x, y])
49    net = Net(pt)
50    del net.a
51    del net.b
52
53
54class AttrNet(nn.Cell):
55    def __init__(self):
56        super(AttrNet, self).__init__()
57        self.a = ms.Tensor(2.)
58
59
60@pytest.mark.level1
61@pytest.mark.platform_arm_ascend_training
62@pytest.mark.platform_x86_ascend_training
63@pytest.mark.platform_x86_gpu_training
64@pytest.mark.platform_x86_cpu
65@pytest.mark.platform_arm_cpu
66@pytest.mark.env_onecard
67@pytest.mark.parametrize('mode', [ms.GRAPH_MODE, ms.PYNATIVE_MODE])
68def test_Cell_set_cell_attr_case(mode):
69    """
70    Feature: Cell
71    Description: Verify the result of Cell setting attribute which type is Cell.
72    Expectation: success
73    """
74    ms.set_context(mode=mode)
75    p = Parameter(Tensor(np.array([[1, 2], [3, 4]], dtype=np.float32)), name="param")
76    net = Net(p)
77    attr_net = AttrNet()
78    net.__setattr__('initial-4-8-convt', attr_net)
79