• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2019 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
15import numpy as np
16
17import mindspore.nn as nn
18from mindspore import Tensor
19from mindspore.common.api import _cell_graph_executor
20from mindspore.ops import operations as P
21from mindspore.ops.operations.comm_ops import _VirtualDataset
22
23
24class VirtualDatasetNet(nn.Cell):
25    def __init__(self):
26        super(VirtualDatasetNet, self).__init__()
27        self.virtual_dataset = _VirtualDataset()
28        self.matmul1 = P.MatMul()
29        self.matmul2 = P.MatMul()
30        self.gelu = P.GeLU()
31
32    def construct(self, x, y, z):
33        x, y, z = self.virtual_dataset(x, y, z)
34        out = self.gelu(self.matmul1(x, y))
35        out = self.matmul2(out, z)
36        return out
37
38
39def test_virtual_dataset():
40    x = Tensor(np.ones([128, 32], dtype=np.float32))
41    y = Tensor(np.ones([32, 64], dtype=np.float32))
42    z = Tensor(np.ones([64, 64], dtype=np.float32))
43    network = VirtualDatasetNet()
44    _cell_graph_executor.compile(network, x, y, z)
45