test_external.py 1.5 KB
Newer Older
1 2 3
# -*- coding: utf-8 -*-
# MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
#
4
# Copyright (c) 2014-2021 Megvii Inc. All rights reserved.
5 6 7 8
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9
import io
10
import os
11
import platform
12 13 14 15 16

import numpy as np
import pytest

import megengine as mge
17
import megengine.utils.comp_graph_tools as cgtools
M
Megvii Engine Team 已提交
18
from megengine import Tensor
19 20
from megengine.distributed.helper import get_device_count_by_fork
from megengine.jit import trace
21
from megengine.module import Module
22
from megengine.module.external import TensorrtRuntimeSubgraph
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43


class MyModule(Module):
    def __init__(self, data):
        from megengine.module.external import CambriconSubgraph

        super().__init__()
        self.cambricon = CambriconSubgraph(data, "subnet0", True)

    def forward(self, inputs):
        out = self.cambricon(inputs)
        return out


@pytest.mark.skip(reason="cambricon unimplemented")
def test_cambricon_module():
    model = "CambriconRuntimeOprTest.MutableBatchSize.mlu"
    model = os.path.join(os.path.dirname(__file__), model)
    with open(model, "rb") as f:
        data = f.read()
        m = MyModule(data)
M
Megvii Engine Team 已提交
44 45 46
        inp = Tensor(
            np.random.normal((1, 64, 32, 32)).astype(np.float16), device="cambricon0"
        )
47 48 49 50 51

        def inference(inps):
            pred = m(inps)
            return pred

M
Megvii Engine Team 已提交
52
        pred = inference([inp])
53 54