-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathsym_size.py
More file actions
80 lines (62 loc) · 2.21 KB
/
Copy pathsym_size.py
File metadata and controls
80 lines (62 loc) · 2.21 KB
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
69
70
71
72
73
74
75
76
77
78
79
# Copyright (c) 2025 Samsung Electronics Co., Ltd. All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import torch
from torch.export import Dim
from test.modules.base import TestModuleBase
from test.utils import tag
@tag.use_onert
class SymSizeSimple(TestModuleBase):
"""
Simplest test case for sym_size.int generation.
Just returns the batch size (first dimension).
"""
def forward(self, x):
# Accessing x.shape[0] on a dynamic dimension creates sym_size.int
return x.shape[0]
def get_example_inputs(self):
return (torch.randn(2, 4, 4),), {}
def get_dynamic_shapes(self):
batch = Dim("batch", min=1, max=128)
return {"x": {0: batch}}
@tag.use_onert
@tag.skip(reason="Not yet supported")
class SymSizeInReshape(TestModuleBase):
"""
Test case using sym_size.int in a reshape operation.
This is a common pattern in dynamic batch size models.
"""
def forward(self, x):
batch_size = x.shape[0]
# Use the dynamic batch size in reshape
return x.reshape(batch_size, -1)
def get_example_inputs(self):
return (torch.randn(2, 4, 4),), {}
def get_dynamic_shapes(self):
batch = Dim("batch", min=1, max=128)
return {"x": {0: batch}}
@tag.use_onert
class SymSizeMultipleDims(TestModuleBase):
"""
Test case using multiple dynamic dimensions.
"""
def forward(self, x):
h = x.shape[1]
w = x.shape[2]
# Reshape using multiple dynamic dimensions
return x.reshape(-1, h * w)
def get_example_inputs(self):
return (torch.randn(2, 4, 4),), {}
def get_dynamic_shapes(self):
batch = Dim("batch", min=1, max=128)
return {"x": {0: batch}}