• 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 numpy as np
17import pytest
18
19import mindspore as ms
20import mindspore.nn as nn
21from mindspore import Tensor
22
23
24class Net(nn.Cell):
25    def __init__(self):
26        super(Net, self).__init__()
27        self.embeddinglookup = nn.EmbeddingLookup(4, 2, dtype=ms.float32)
28
29    def construct(self, x):
30        out = self.embeddinglookup(x)
31        return out
32
33
34@pytest.mark.level1
35@pytest.mark.platform_x86_cpu
36@pytest.mark.platform_arm_cpu
37@pytest.mark.platform_x86_gpu_training
38@pytest.mark.platform_arm_ascend_training
39@pytest.mark.platform_x86_ascend_training
40@pytest.mark.env_onecard
41@pytest.mark.parametrize('mode', [ms.GRAPH_MODE, ms.PYNATIVE_MODE])
42def test_embeddinglookup_para_customed_dtype(mode):
43    """
44    Feature: EmbeddingLookup
45    Description: Verify the result of EmbeddingLookup specifying customed para dtype.
46    Expectation: success
47    """
48    ms.set_context(mode=mode)
49    net = Net()
50    x = Tensor(np.array([[1, 0], [3, 2]]), ms.int32)
51    output = net(x)
52    expect_output_shape = (2, 2, 2)
53    assert np.allclose(expect_output_shape, output.shape)
54