Skip to content

Commit

Permalink
tentative changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Giuseppe5 committed Mar 22, 2023
1 parent 6537fb7 commit ee9c6c2
Show file tree
Hide file tree
Showing 173 changed files with 6,329 additions and 4,194 deletions.
274 changes: 172 additions & 102 deletions .github/workflows/gen_github_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

# Data shared betwen Nox sessions and Github Actions, formatted as tuples
PYTHON_VERSIONS = ('3.7', '3.8')
PYTORCH_VERSIONS = ('1.5.1', '1.6.0', '1.7.1', '1.8.1', '1.9.1', '1.10.1', '1.11.0', '1.12.1',
'1.13.0')
PYTORCH_VERSIONS = (
'1.5.1', '1.6.0', '1.7.1', '1.8.1', '1.9.1', '1.10.1', '1.11.0', '1.12.1', '1.13.0')
PYTORCH_LIST_REDUCED = ["1.5.1", "1.10.1", "1.13.0"]
JIT_STATUSES = ('jit_disabled',)

Expand All @@ -33,157 +33,227 @@
EXCLUDE_LIST = []

NOTEBOOK_EXCLUDE_LIST = [
od([('pytorch_version', ['1.5.1', '1.6.0', '1.7.1'])]),
od([('platform', [
od([('pytorch_version', ['1.5.1', '1.6.0', '1.7.1'])]), od([('platform', [
'macos-latest',])])]

END_TO_END_EXCLUDE_LIST = [od([('platform', [
'windows-latest',])])]

MATRIX = od([('python_version', list(PYTHON_VERSIONS)), ('pytorch_version', list(PYTORCH_VERSIONS)),
('platform', PLATFORM_LIST)])
MATRIX = od(
[
('python_version', list(PYTHON_VERSIONS)), ('pytorch_version', list(PYTORCH_VERSIONS)),
('platform', PLATFORM_LIST)])

FINN_MATRIX = od([('python_version', list(PYTHON_VERSIONS)),
('pytorch_version', list(PYTORCH_VERSIONS)), ('platform', FINN_PLATFORM_LIST)])
FINN_MATRIX = od(
[
('python_version', list(PYTHON_VERSIONS)), ('pytorch_version', list(PYTORCH_VERSIONS)),
('platform', FINN_PLATFORM_LIST)])

PYTEST_MATRIX_EXTRA = od([('jit_status', list(JIT_STATUSES))])

PYTEST_STEP_LIST = [
od([('name', 'Run Nox session for brevitas pytest'),
('if',
CONDITION.replace('%PYTORCH_LIST_REDUCED',
', '.join(f'"{version}"' for version in PYTORCH_LIST_REDUCED))),
('shell', 'bash'),
('run',
'nox -v -s tests_brevitas_cpu-${{ matrix.python_version }}\(${{ matrix.jit_status }}\,\ pytorch_${{ matrix.pytorch_version }}\)'
)]),]
od(
[
('name', 'Run Nox session for brevitas pytest'),
(
'if',
CONDITION.replace(
'%PYTORCH_LIST_REDUCED',
', '.join(f'"{version}"' for version in PYTORCH_LIST_REDUCED))),
('shell', 'bash'),
(
'run',
'nox -v -s tests_brevitas_cpu-${{ matrix.python_version }}\(${{ matrix.jit_status }}\,\ pytorch_${{ matrix.pytorch_version }}\)'
)]),]

EXAMPLES_PYTEST_STEP_LIST = [
od([('name', 'Run Nox session for brevitas_examples pytest'),
('if',
CONDITION.replace('%PYTORCH_LIST_REDUCED',
', '.join(f'"{version}"' for version in PYTORCH_LIST_REDUCED))),
('shell', 'bash'),
('run',
'nox -v -s tests_brevitas_examples_cpu-${{ matrix.python_version }}\(${{ matrix.jit_status }}\,\ pytorch_${{ matrix.pytorch_version }}\)'
)]),]
od(
[
('name', 'Run Nox session for brevitas_examples pytest'),
(
'if',
CONDITION.replace(
'%PYTORCH_LIST_REDUCED',
', '.join(f'"{version}"' for version in PYTORCH_LIST_REDUCED))),
('shell', 'bash'),
(
'run',
'nox -v -s tests_brevitas_examples_cpu-${{ matrix.python_version }}\(${{ matrix.jit_status }}\,\ pytorch_${{ matrix.pytorch_version }}\)'
)]),]

FINN_INTEGRATION_STEP_LIST = [
od([('name', 'Install protobuf on Ubuntu'),
('if',
CONDITION.replace('%PYTORCH_LIST_REDUCED',
', '.join(f'"{version}"' for version in PYTORCH_LIST_REDUCED))),
('shell', 'bash'), ('run', 'sudo apt-get install protobuf-compiler libprotoc-dev'),
('if', "startsWith(runner.os, 'Linux') == true")]),
od([('name', 'Run Nox session for Brevitas-FINN integration'),
('if',
CONDITION.replace('%PYTORCH_LIST_REDUCED',
', '.join(f'"{version}"' for version in PYTORCH_LIST_REDUCED))),
('shell', 'bash'),
('run',
'nox -v -s tests_brevitas_finn_integration-${{ matrix.python_version }}\(\pytorch_${{ matrix.pytorch_version }}\)'
)])]
od(
[
('name', 'Install protobuf on Ubuntu'),
(
'if',
CONDITION.replace(
'%PYTORCH_LIST_REDUCED',
', '.join(f'"{version}"' for version in PYTORCH_LIST_REDUCED))),
('shell', 'bash'), ('run', 'sudo apt-get install protobuf-compiler libprotoc-dev'),
('if', "startsWith(runner.os, 'Linux') == true")]),
od(
[
('name', 'Run Nox session for Brevitas-FINN integration'),
(
'if',
CONDITION.replace(
'%PYTORCH_LIST_REDUCED',
', '.join(f'"{version}"' for version in PYTORCH_LIST_REDUCED))),
('shell', 'bash'),
(
'run',
'nox -v -s tests_brevitas_finn_integration-${{ matrix.python_version }}\(\pytorch_${{ matrix.pytorch_version }}\)'
)])]

PYXIR_INTEGRATION_STEP_LIST = [
od([('name', 'Run Nox session for Brevitas-PyXIR integration'),
('if',
CONDITION.replace('%PYTORCH_LIST_REDUCED',
', '.join(f'"{version}"' for version in PYTORCH_LIST_REDUCED))),
('shell', 'bash'),
('run',
'nox -v -s tests_brevitas_pyxir_integration-${{ matrix.python_version }}\(\pytorch_${{ matrix.pytorch_version }}\)'
)])]
od(
[
('name', 'Run Nox session for Brevitas-PyXIR integration'),
(
'if',
CONDITION.replace(
'%PYTORCH_LIST_REDUCED',
', '.join(f'"{version}"' for version in PYTORCH_LIST_REDUCED))),
('shell', 'bash'),
(
'run',
'nox -v -s tests_brevitas_pyxir_integration-${{ matrix.python_version }}\(\pytorch_${{ matrix.pytorch_version }}\)'
)])]

ORT_INTEGRATION_STEP_LIST = [
od([('name', 'Run Nox session for Brevitas-ORT integration'),
('if',
CONDITION.replace('%PYTORCH_LIST_REDUCED',
', '.join(f'"{version}"' for version in PYTORCH_LIST_REDUCED))),
('shell', 'bash'),
('run',
'nox -v -s tests_brevitas_ort_integration-${{ matrix.python_version }}\(\pytorch_${{ matrix.pytorch_version }}\)'
)])]
od(
[
('name', 'Run Nox session for Brevitas-ORT integration'),
(
'if',
CONDITION.replace(
'%PYTORCH_LIST_REDUCED',
', '.join(f'"{version}"' for version in PYTORCH_LIST_REDUCED))),
('shell', 'bash'),
(
'run',
'nox -v -s tests_brevitas_ort_integration-${{ matrix.python_version }}\(\pytorch_${{ matrix.pytorch_version }}\)'
)])]

TEST_INSTALL_DEV_STEP_LIST = [
od([('name', 'Run Nox session for testing brevitas develop install and imports'),
('if',
CONDITION.replace('%PYTORCH_LIST_REDUCED',
', '.join(f'"{version}"' for version in PYTORCH_LIST_REDUCED))),
('shell', 'bash'),
('run',
'nox -v -s tests_brevitas_install_dev-${{ matrix.python_version }}\(\pytorch_${{ matrix.pytorch_version }}\)'
)]),
od([('name', 'Run Nox session for testing brevitas_examples develop install and imports'),
('if',
CONDITION.replace('%PYTORCH_LIST_REDUCED',
', '.join(f'"{version}"' for version in PYTORCH_LIST_REDUCED))),
('shell', 'bash'),
('run',
'nox -v -s tests_brevitas_examples_install_dev-${{ matrix.python_version }}\(\pytorch_${{ matrix.pytorch_version }}\)'
)])]
od(
[
('name', 'Run Nox session for testing brevitas develop install and imports'),
(
'if',
CONDITION.replace(
'%PYTORCH_LIST_REDUCED',
', '.join(f'"{version}"' for version in PYTORCH_LIST_REDUCED))),
('shell', 'bash'),
(
'run',
'nox -v -s tests_brevitas_install_dev-${{ matrix.python_version }}\(\pytorch_${{ matrix.pytorch_version }}\)'
)]),
od(
[
('name', 'Run Nox session for testing brevitas_examples develop install and imports'),
(
'if',
CONDITION.replace(
'%PYTORCH_LIST_REDUCED',
', '.join(f'"{version}"' for version in PYTORCH_LIST_REDUCED))),
('shell', 'bash'),
(
'run',
'nox -v -s tests_brevitas_examples_install_dev-${{ matrix.python_version }}\(\pytorch_${{ matrix.pytorch_version }}\)'
)])]

NOTEBOOK_STEP_LIST = [
od([('name', 'Run Nox session for Notebook execution'),
('if',
CONDITION.replace('%PYTORCH_LIST_REDUCED',
', '.join(f'"{version}"' for version in PYTORCH_LIST_REDUCED))),
('shell', 'bash'),
('run',
'nox -v -s tests_brevitas_notebook-${{ matrix.python_version }}\(\pytorch_${{ matrix.pytorch_version }}\)'
)])]
od(
[
('name', 'Run Nox session for Notebook execution'),
(
'if',
CONDITION.replace(
'%PYTORCH_LIST_REDUCED',
', '.join(f'"{version}"' for version in PYTORCH_LIST_REDUCED))),
('shell', 'bash'),
(
'run',
'nox -v -s tests_brevitas_notebook-${{ matrix.python_version }}\(\pytorch_${{ matrix.pytorch_version }}\)'
)])]

ENDTOEND_STEP_LIST = [
od([('name', 'Run Nox session for end-to-end flows'),
('if',
CONDITION.replace('%PYTORCH_LIST_REDUCED',
', '.join(f'"{version}"' for version in PYTORCH_LIST_REDUCED))),
('shell', 'bash'),
('run',
'nox -v -s tests_brevitas_end_to_end-${{ matrix.python_version }}\(\pytorch_${{ matrix.pytorch_version }}\)'
)])]
od(
[
('name', 'Run Nox session for end-to-end flows'),
(
'if',
CONDITION.replace(
'%PYTORCH_LIST_REDUCED',
', '.join(f'"{version}"' for version in PYTORCH_LIST_REDUCED))),
('shell', 'bash'),
(
'run',
'nox -v -s tests_brevitas_end_to_end-${{ matrix.python_version }}\(\pytorch_${{ matrix.pytorch_version }}\)'
)])]


def gen_pytest_yml():
pytest = Action('Pytest', EXCLUDE_LIST, combine_od_list([MATRIX, PYTEST_MATRIX_EXTRA]),
PYTEST_STEP_LIST, STRATEGY)
pytest = Action(
'Pytest',
EXCLUDE_LIST,
combine_od_list([MATRIX, PYTEST_MATRIX_EXTRA]),
PYTEST_STEP_LIST,
STRATEGY)
pytest.gen_yaml(BASE_YML_TEMPLATE, PYTEST_YML)


def gen_examples_pytest_yml():
pytest = Action('Examples Pytest', EXCLUDE_LIST, combine_od_list([MATRIX, PYTEST_MATRIX_EXTRA]),
EXAMPLES_PYTEST_STEP_LIST, STRATEGY)
pytest = Action(
'Examples Pytest',
EXCLUDE_LIST,
combine_od_list([MATRIX, PYTEST_MATRIX_EXTRA]),
EXAMPLES_PYTEST_STEP_LIST,
STRATEGY)
pytest.gen_yaml(BASE_YML_TEMPLATE, EXAMPLES_PYTEST_YML)


def gen_test_develop_install_yml():
test_develop_install = Action('Test develop install', EXCLUDE_LIST, MATRIX,
TEST_INSTALL_DEV_STEP_LIST, STRATEGY)
test_develop_install = Action(
'Test develop install', EXCLUDE_LIST, MATRIX, TEST_INSTALL_DEV_STEP_LIST, STRATEGY)
test_develop_install.gen_yaml(BASE_YML_TEMPLATE, DEVELOP_INSTALL_YML)


def gen_test_brevitas_finn_integration():
test_finn_integration = Action('Test Brevitas-FINN integration', EXCLUDE_LIST, FINN_MATRIX,
FINN_INTEGRATION_STEP_LIST, STRATEGY)
test_finn_integration = Action(
'Test Brevitas-FINN integration',
EXCLUDE_LIST,
FINN_MATRIX,
FINN_INTEGRATION_STEP_LIST,
STRATEGY)
test_finn_integration.gen_yaml(BASE_YML_TEMPLATE, FINN_INTEGRATION_YML)


def gen_test_brevitas_ort_integration():
test_ort_integration = Action('Test Brevitas-ORT integration', EXCLUDE_LIST, MATRIX,
ORT_INTEGRATION_STEP_LIST, STRATEGY)
test_ort_integration = Action(
'Test Brevitas-ORT integration', EXCLUDE_LIST, MATRIX, ORT_INTEGRATION_STEP_LIST, STRATEGY)
test_ort_integration.gen_yaml(BASE_YML_TEMPLATE, ORT_INTEGRATION_YML)


def gen_test_brevitas_notebook():
tests_brevitas_notebooks = Action('Test Notebook execution',
EXCLUDE_LIST + NOTEBOOK_EXCLUDE_LIST, MATRIX,
NOTEBOOK_STEP_LIST, STRATEGY)
tests_brevitas_notebooks = Action(
'Test Notebook execution',
EXCLUDE_LIST + NOTEBOOK_EXCLUDE_LIST,
MATRIX,
NOTEBOOK_STEP_LIST,
STRATEGY)
tests_brevitas_notebooks.gen_yaml(BASE_YML_TEMPLATE, NOTEBOOK_YML)


def gen_test_brevitas_end_to_end():
tests_brevitas_end_to_end = Action('Test End-to-end flows',
EXCLUDE_LIST + END_TO_END_EXCLUDE_LIST, MATRIX,
ENDTOEND_STEP_LIST, STRATEGY_ENDTOEND)
tests_brevitas_end_to_end = Action(
'Test End-to-end flows',
EXCLUDE_LIST + END_TO_END_EXCLUDE_LIST,
MATRIX,
ENDTOEND_STEP_LIST,
STRATEGY_ENDTOEND)
tests_brevitas_end_to_end.gen_yaml(BASE_YML_TEMPLATE, ENDTOEND_YML)


Expand Down
9 changes: 4 additions & 5 deletions .github/workflows/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,17 @@ def dict_str(d, quote_val, indent_first, newline_val=False):
else:
repr += f"{name}: {val}" + NIX_NEWLINE
if indent_first:
repr = indent(repr,
RELATIVE_INDENT * ' ',
predicate=lambda line: not first_line_prefix in line)
repr = indent(
repr, RELATIVE_INDENT * ' ', predicate=lambda line: not first_line_prefix in line)
repr += NIX_NEWLINE
return repr

def gen_yaml(self, base_template_path, output_path):
d = {}
d['name'] = self.name
d['matrix'] = indent(Action.dict_str(self.matrix, False, False), MATRIX_INDENT * ' ')
d['steps'] = indent(Action.list_of_dicts_str(self.step_list, False, True),
STEP_INDENT * ' ')
d['steps'] = indent(
Action.list_of_dicts_str(self.step_list, False, True), STEP_INDENT * ' ')
if self.exclude_list:
d['exclude'] = indent('exclude:\n', MATRIX_INDENT * ' ') + indent(
Action.list_of_dicts_str(self.exclude_list, False, True, True),
Expand Down
8 changes: 0 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@ repos:
- id: isort
name: isort (python)

# - repo: https://github.com/charliermarsh/ruff-pre-commit
# # Ruff version.
# rev: 'v0.0.218'
# hooks:
# - id: ruff
# # Respect `exclude` and `extend-exclude` settings.
# args: ["--force-exclude",
# "--fix"]

- repo: https://github.com/pre-commit/mirrors-yapf
rev: v0.32.0 # Use the sha / tag you want to point at
Expand Down
10 changes: 8 additions & 2 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,14 @@ def tests_brevitas_notebook(session, pytorch):
if version.parse(pytorch) >= version.parse(LSTM_EXPORT_MIN_PYTORCH):
session.run('pytest', '-v', '--nbmake', '--nbmake-kernel=python3', 'notebooks')
else:
session.run('pytest', '-v', '--nbmake', '--nbmake-kernel=python3', 'notebooks', '--ignore',
'notebooks/quantized_recurrent.ipynb')
session.run(
'pytest',
'-v',
'--nbmake',
'--nbmake-kernel=python3',
'notebooks',
'--ignore',
'notebooks/quantized_recurrent.ipynb')


@nox.session(python=PYTHON_VERSIONS)
Expand Down
Loading

0 comments on commit ee9c6c2

Please sign in to comment.