-
Notifications
You must be signed in to change notification settings - Fork 199
/
noxfile.py
216 lines (187 loc) · 7.88 KB
/
noxfile.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# Copyright (C) 2023, Advanced Micro Devices, Inc. All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
import os
from platform import system
import sys
import nox
from packaging import version
from packaging.version import parse
sys.path.append(os.path.join(os.path.dirname(__file__), os.path.join('.', '.github', 'workflows')))
from gen_github_actions import EXAMPLES_LLM_PYTEST_PYTORCH_VERSIONS
from gen_github_actions import JIT_STATUSES
from gen_github_actions import PYTHON_VERSIONS
from gen_github_actions import PYTORCH_VERSIONS
IS_OSX = system() == 'Darwin'
PYTORCH_STABLE_WHEEL_SRC = 'https://download.pytorch.org/whl/cpu'
PYTORCH_STABLE_WHEEL_SRC_LEGACY = 'https://download.pytorch.org/whl/torch_stable.html'
PYTORCH_IDS = tuple([f'pytorch_{i}' for i in PYTORCH_VERSIONS])
EXAMPLES_LLM_PYTEST_PYTORCH_IDS = tuple([
f'pytorch_{i}' for i in EXAMPLES_LLM_PYTEST_PYTORCH_VERSIONS])
JIT_IDS = tuple([f'{i}'.lower() for i in JIT_STATUSES])
LSTM_EXPORT_MIN_PYTORCH = '1.10.1'
TORCHVISION_VERSION_DICT = {
'1.9.1': '0.10.1',
'1.10.1': '0.11.2',
'1.11.0': '0.12.0',
'1.12.1': '0.13.1',
'1.13.0': '0.14.0',
'2.0.1': '0.15.2',
'2.1.0': '0.16.0',
'2.2.2': '0.17.2',
'2.3.1': '0.18.1',
'2.4.0': '0.19.0'}
PARSED_TORCHVISION_VERSION_DICT = {version.parse(k): v for k, v in TORCHVISION_VERSION_DICT.items()}
def install_pytorch(pytorch, session):
if not IS_OSX:
if parse(pytorch) < parse('2.4.0'):
cmd = [f'torch=={pytorch}+cpu', '-f', PYTORCH_STABLE_WHEEL_SRC_LEGACY]
else:
cmd = [f'torch=={pytorch}', '--index-url', PYTORCH_STABLE_WHEEL_SRC]
else:
cmd = [f'torch=={pytorch}']
session.install(*cmd)
def install_torchvision(pytorch, session):
torchvision = PARSED_TORCHVISION_VERSION_DICT[version.parse(pytorch)]
if not IS_OSX:
if parse(pytorch) < parse('2.4.0'):
cmd = [
f'torch=={pytorch}+cpu', # make sure correct pytorch version is kept
f'torchvision=={torchvision}+cpu',
'-f',
PYTORCH_STABLE_WHEEL_SRC_LEGACY]
else:
cmd = [
f'torch=={pytorch}',
f'torchvision=={torchvision}',
'--index-url',
PYTORCH_STABLE_WHEEL_SRC]
else:
cmd = [f'torch=={pytorch}', f'torchvision=={torchvision}']
session.install(*cmd)
@nox.session(python=PYTHON_VERSIONS)
@nox.parametrize('pytorch', PYTORCH_VERSIONS, ids=PYTORCH_IDS)
@nox.parametrize('jit_status', JIT_STATUSES, ids=JIT_IDS)
def tests_brevitas_cpu(session, pytorch, jit_status):
session.env['BREVITAS_JIT'] = '{}'.format(int(jit_status == 'jit_enabled'))
install_pytorch(pytorch, session)
install_torchvision(pytorch, session)
session.install('--upgrade', '.[test, export]')
if jit_status == 'jit_enabled':
session.run('pytest', '-k', 'not _full', 'tests/brevitas/nn/test_nn_quantizers.py', '-v')
session.run(
'pytest',
'tests/brevitas',
'-n',
'logical',
'-v',
'--ignore',
'tests/brevitas/graph',
'--ignore',
'tests/brevitas/nn/test_nn_quantizers.py')
session.run('pytest', 'tests/brevitas/graph', '-n', 'logical', '-v')
else:
session.run(
'pytest',
'-n',
'logical',
'-k',
'_full or wbiol',
'tests/brevitas/nn/test_nn_quantizers.py',
'-v')
# run non graph tests
session.run(
'pytest',
'tests/brevitas',
'-n',
'logical',
'-v',
'--ignore',
'tests/brevitas/graph',
'--ignore',
'tests/brevitas/nn/test_nn_quantizers.py')
# run graph tests separately
session.run('pytest', 'tests/brevitas/graph', '-n', 'logical', '-v')
@nox.session(python=PYTHON_VERSIONS)
@nox.parametrize("pytorch", PYTORCH_VERSIONS, ids=PYTORCH_IDS)
@nox.parametrize("jit_status", JIT_STATUSES, ids=JIT_IDS)
def tests_brevitas_examples_cpu(session, pytorch, jit_status):
session.env['BREVITAS_JIT'] = '{}'.format(int(jit_status == 'jit_enabled'))
install_pytorch(pytorch, session)
install_torchvision(pytorch, session) # For CV eval scripts
session.install('--upgrade', '.[test, tts, stt, vision]')
session.run(
'pytest',
'-n',
'logical',
'--ignore-glob',
'tests/brevitas_examples/*llm*',
'tests/brevitas_examples')
@nox.session(python=PYTHON_VERSIONS)
@nox.parametrize(
"pytorch", EXAMPLES_LLM_PYTEST_PYTORCH_VERSIONS, ids=EXAMPLES_LLM_PYTEST_PYTORCH_IDS)
@nox.parametrize("jit_status", JIT_STATUSES, ids=JIT_IDS)
def tests_brevitas_examples_llm(session, pytorch, jit_status):
session.env['BREVITAS_JIT'] = '{}'.format(int(jit_status == 'jit_enabled'))
install_pytorch(pytorch, session)
install_torchvision(pytorch, session) # Optimum seems to require torchvision
session.install('-e', '.[test, llm, export]')
session.install(
'optimum-amd[brevitas] @ git+https://github.com/huggingface/optimum-amd.git@main')
session.run('pytest', '-n', 'logical', '-k', 'llm', 'tests/brevitas_examples/test_llm.py')
@nox.session(python=PYTHON_VERSIONS)
@nox.parametrize("pytorch", PYTORCH_VERSIONS, ids=PYTORCH_IDS)
def tests_brevitas_install_dev(session, pytorch):
install_pytorch(pytorch, session)
install_torchvision(pytorch, session)
session.install('--upgrade', '-e', '.[test]')
session.env['BREVITAS_VERBOSE'] = '1'
session.run('pytest', '-n', 'logical', '-v', 'tests/brevitas/test_brevitas_import.py')
@nox.session(python=PYTHON_VERSIONS)
@nox.parametrize("pytorch", PYTORCH_VERSIONS, ids=PYTORCH_IDS)
def tests_brevitas_examples_install_dev(session, pytorch):
install_pytorch(pytorch, session)
install_torchvision(pytorch, session)
session.install('--upgrade', '-e', '.[test, tts, stt]')
session.run('pytest', '-n', 'logical', '-v', 'tests/brevitas_examples/test_examples_import.py')
@nox.session(python=PYTHON_VERSIONS)
@nox.parametrize("pytorch", PYTORCH_VERSIONS, ids=PYTORCH_IDS)
def tests_brevitas_finn_integration(session, pytorch):
install_pytorch(pytorch, session)
install_torchvision(pytorch, session)
session.install('--upgrade', '-e', '.[test, stt, finn_integration]')
env = {'FINN_INST_NAME': 'finn'}
session.run('pytest', '-v', 'tests/brevitas_finn', env=env)
@nox.session(python=PYTHON_VERSIONS)
@nox.parametrize("pytorch", PYTORCH_VERSIONS, ids=PYTORCH_IDS)
def tests_brevitas_ort_integration(session, pytorch):
install_pytorch(pytorch, session)
install_torchvision(pytorch, session)
session.install('--upgrade', '-e', '.[test, ort_integration]')
session.run('pytest', '-n', 'logical', '-v', 'tests/brevitas_ort')
@nox.session(python=PYTHON_VERSIONS)
@nox.parametrize("pytorch", PYTORCH_VERSIONS, ids=PYTORCH_IDS)
def tests_brevitas_notebook(session, pytorch):
install_pytorch(pytorch, session)
install_torchvision(pytorch, session)
session.install('--upgrade', '-e', '.[test, ort_integration, notebook]')
if version.parse(pytorch) >= version.parse(LSTM_EXPORT_MIN_PYTORCH):
session.run(
'pytest', '-n', 'logical', '-v', '--nbmake', '--nbmake-kernel=python3', 'notebooks')
else:
session.run(
'pytest',
'-n',
'logical',
'-v',
'--nbmake',
'--nbmake-kernel=python3',
'notebooks',
'--ignore',
'notebooks/quantized_recurrent.ipynb')
@nox.session(python=PYTHON_VERSIONS)
@nox.parametrize("pytorch", PYTORCH_VERSIONS, ids=PYTORCH_IDS)
def tests_brevitas_end_to_end(session, pytorch):
install_pytorch(pytorch, session)
install_torchvision(pytorch, session)
session.install('--upgrade', '-e', '.[test, ort_integration]')
session.run('pytest', '-n', 'logical', '-v', 'tests/brevitas_end_to_end')