-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy pathtest_fp16.py
58 lines (42 loc) · 1.84 KB
/
test_fp16.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
# Copyright (C) 2018-2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
import numpy as np
import pytest
import torch
from pytorch_layer_test_class import PytorchLayerTest
class TestBF16(PytorchLayerTest):
def _prepare_input(self):
return (np.random.randn(10).astype(np.float32),)
def create_model(self):
class aten_add(torch.nn.Module):
def __init__(self):
super(aten_add, self).__init__()
self.y = torch.randn(10, dtype=torch.bfloat16)
def forward(self, x):
return x + self.y.to(torch.float32)
return aten_add(), None, "aten::add"
@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.precommit_torch_export
@pytest.mark.parametrize("to_trace", [True, False])
def test_bf16(self, ie_device, precision, ir_version, to_trace):
self._test(*self.create_model(), ie_device, precision,
ir_version, trace_model=to_trace, freeze_model=False, use_convert_model=True)
class TestFP16(PytorchLayerTest):
def _prepare_input(self):
return (np.random.randn(10).astype(np.float32),)
def create_model(self):
class aten_add(torch.nn.Module):
def __init__(self):
super(aten_add, self).__init__()
self.y = torch.randn(10, dtype=torch.float16)
def forward(self, x):
return x + self.y.to(torch.float32)
return aten_add(), None, "aten::add"
@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.precommit_torch_export
@pytest.mark.parametrize("to_trace", [True, False])
def test_fp16(self, ie_device, precision, ir_version, to_trace):
self._test(*self.create_model(), ie_device, precision,
ir_version, trace_model=to_trace, freeze_model=False, use_convert_model=True)