-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy pathtest_dict.py
68 lines (50 loc) · 2.45 KB
/
test_dict.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Copyright (C) 2018-2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
import numpy as np
import platform
import pytest
import torch
from typing import Dict
from pytorch_layer_test_class import PytorchLayerTest
class TestDict(PytorchLayerTest):
def _prepare_input(self):
return (np.random.randn(2, 5, 3, 4).astype(np.float32),)
def create_model(self):
class aten_dict(torch.nn.Module):
def forward(self, x):
return {"b": x, "a": x + x, "c": 2 * x}, x / 2
return aten_dict(), None, "prim::DictConstruct"
@pytest.mark.nightly
@pytest.mark.precommit
def test_dict(self, ie_device, precision, ir_version):
self._test(*self.create_model(), ie_device, precision,
ir_version, use_convert_model=True)
class aten_dict_with_types(torch.nn.Module):
def forward(self, x_dict: Dict[str, torch.Tensor]):
return x_dict["x1"].to(torch.float32) + x_dict["x2"].to(torch.float32)
class aten_dict_no_types(torch.nn.Module):
def forward(self, x_dict: Dict[str, torch.Tensor]):
return x_dict["x1"] + x_dict["x2"]
class TestDictParam(PytorchLayerTest):
def _prepare_input(self):
return ({"x1": np.random.randn(2, 5, 3, 4).astype(np.float32),
"x2": np.random.randn(2, 5, 3, 4).astype(np.float32)},)
@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.skipif(platform.system() == 'Darwin' and platform.machine() in ('x86_64', 'AMD64'),
reason='Ticket - 142190')
def test_dict_param(self, ie_device, precision, ir_version):
self._test(aten_dict_with_types(), None, "aten::__getitem__", ie_device, precision,
ir_version, trace_model=True)
@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.skipif(platform.system() == 'Darwin', reason='Ticket - 142190')
def test_dict_param_convert_model(self, ie_device, precision, ir_version):
self._test(aten_dict_with_types(), None, "aten::__getitem__", ie_device, precision,
ir_version, trace_model=True, use_convert_model=True)
@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.skipif(platform.system() == 'Darwin', reason='Ticket - 142190')
def test_dict_param_no_types(self, ie_device, precision, ir_version):
self._test(aten_dict_no_types(), None, "aten::__getitem__", ie_device, precision,
ir_version, trace_model=True, freeze_model=False)