-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy pathtest_tensor_split.py
67 lines (57 loc) · 2.19 KB
/
test_tensor_split.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
# Copyright (C) 2018-2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
from collections.abc import Collection
from numbers import Number
import numpy as np
import pytest
import torch
from pytorch_layer_test_class import PytorchLayerTest
class TestTensorSplit(PytorchLayerTest):
def _prepare_input(self):
return (np.random.rand(*self.input_shape),)
def create_model(self, splits, axis):
class aten_tensor_split(torch.nn.Module):
def __init__(self, splits, dim) -> None:
super().__init__()
self.splits = splits
self.dim = dim
num_outs = None
if isinstance(splits, Number):
num_outs = splits
elif isinstance(splits, Collection):
num_outs = len(splits) + 1
self.forward = getattr(self, f"forward_{num_outs}")
def forward_2(self, input_tensor):
a, b = torch.tensor_split(input_tensor, self.splits, dim=self.dim)
return a, b
def forward_3(self, input_tensor):
a, b, c = torch.tensor_split(input_tensor, self.splits, dim=self.dim)
return a, b, c
def forward_4(self, input_tensor):
a, b, c, d = torch.tensor_split(input_tensor, self.splits, dim=self.dim)
return a, b, c, d
return aten_tensor_split(splits, axis), None, "aten::tensor_split"
@pytest.mark.parametrize("input_shape", [(2, 1, 8), (3, 5, 7, 11)])
@pytest.mark.parametrize(
"splits",
[
# 1, Does not work for 1 - no list_unpack present in the graph
2,
3,
4,
[2],
[5],
[-1],
[-5],
[1, 3],
[1, 3, 5],
[5, -1, 7],
],
)
@pytest.mark.parametrize("axis", [0, 1, -1])
@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.precommit_torch_export
def test_tensor_split(self, input_shape, splits, axis, ie_device, precision, ir_version):
self.input_shape = input_shape
self._test(*self.create_model(splits, axis), ie_device, precision, ir_version)