Skip to content

Commit 4dc2a4d

Browse files
authored
chore(ci): test with tox (#332)
This PR introduces tox for managing test environments. It allows us to run the same tests locally and on CI on many different environment configurations. - fixes #329 - Fix a new error in `cat` from torch-nightly
1 parent 1a3df01 commit 4dc2a4d

File tree

10 files changed

+136
-109
lines changed

10 files changed

+136
-109
lines changed

.github/workflows/lint.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ jobs:
5050
python -m pip install --upgrade pip
5151
python -m pip install --upgrade setuptools
5252
python -m pip install -q -r requirements-dev.txt
53-
# Install ONNX
54-
python -m pip uninstall -y onnx-function-experiment
55-
python -m pip uninstall -y ort-function-experiment-nightly
56-
python -m pip install -r requirements-onnx.txt
5753
# Install packages
5854
python -m pip install -e .
5955
lintrunner init

.github/workflows/main.yaml

Lines changed: 23 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -10,80 +10,47 @@ on:
1010
# Allows you to run this workflow manually from the Actions tab
1111
workflow_dispatch:
1212

13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}-${{ github.event_name == 'workflow_dispatch' }}
15+
cancel-in-progress: true
16+
1317
jobs:
1418
test:
1519
strategy:
1620
fail-fast: false
1721
matrix:
1822
os: [ubuntu-latest, windows-latest, macos-latest]
1923
name:
20-
# - python311-onnx
21-
# TODO: Enable python311 when onnx is updated
22-
- python310-onnx
23-
- python39-onnx
24-
- python39-expe
25-
- python38-expe
24+
# names should match tox labels in tox.ini
25+
- python310
26+
- python39
27+
- python38
28+
- python310-experimental
29+
- python310-torch-nightly
2630
include:
27-
# - name: python311-onnx
28-
# python-version: "3.11"
29-
# onnx_standard: true
30-
# test_examples: true
31-
- name: python310-onnx
31+
- name: python310
3232
python-version: "3.10"
33-
onnx_standard: true
34-
test_examples: true
35-
- name: python39-onnx
36-
python-version: "3.9"
37-
onnx_standard: true
38-
test_examples: false
39-
- name: python39-expe
33+
- name: python39
4034
python-version: "3.9"
41-
onnx_standard: false
42-
test_examples: false
43-
- name: python38-expe
35+
- name: python38
4436
python-version: "3.8"
45-
onnx_standard: false
46-
test_examples: false
37+
- name: python310-experimental
38+
python-version: "3.10"
39+
- name: python310-torch-nightly
40+
python-version: "3.10"
4741
runs-on: ${{ matrix.os }}
4842
steps:
4943
- uses: actions/checkout@v3
5044
- name: Setup Python ${{ matrix.python-version }}
5145
uses: actions/setup-python@v4
5246
with:
5347
python-version: ${{ matrix.python-version }}
54-
cache: pip
55-
cache-dependency-path: "**/requirements-dev.txt"
56-
- name: Install dependencies
57-
run: |
58-
python -m pip install --upgrade pip setuptools wheel build
59-
python -m pip install -r requirements-dev.txt
60-
61-
- name: Install standard onnx
62-
if: ${{ matrix.onnx_standard }}
63-
run: |
64-
python -m pip uninstall -y onnx-function-experiment
65-
python -m pip uninstall -y ort-function-experiment-nightly
66-
python -m pip install -r requirements-onnx.txt
67-
68-
- name: Versions
69-
run: |
70-
pip list | grep numpy
71-
pip list | grep onnx
72-
pip list | grep torch
73-
74-
- name: pytest
75-
run: pytest -v onnxscript --cov=onnxscript --cov-report=xml -n=auto
76-
77-
- name: Install package
78-
run: pip install .
79-
80-
- name: Test examples
81-
if: ${{ matrix.test_examples }}
82-
run: pytest -v docs/test -n=auto
83-
84-
- name: Build package
85-
run: python -m build
86-
48+
- name: Install tox
49+
run: python -m pip install tox tox-gh
50+
- name: Setup test suite
51+
run: tox -m ${{ matrix.name }} --colored yes -vv --notest
52+
- name: Run test suite
53+
run: tox -m ${{ matrix.name }} --colored yes --skip-pkg-install -- -v --cov=onnxscript --cov-report=xml -n=auto
8754
- name: Upload coverage to Codecov
8855
uses: codecov/codecov-action@v3
8956

azure-pipelines.yml

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# Python package
2-
# Create and test a Python package on multiple Python versions.
3-
# Add steps that analyze code, save the dist with the build record, publish to a PyPI-compatible index, and more:
4-
# https://docs.microsoft.com/azure/devops/pipelines/languages/python
2+
# Clone the repository for mandatory injected checks
53

64
trigger:
75
- main
@@ -12,43 +10,8 @@ strategy:
1210
matrix:
1311
Python310-onnx:
1412
python.version: '3.10'
15-
onnx.standard: '1'
16-
test.examples: '1'
1713
steps:
1814
- task: UsePythonVersion@0
1915
inputs:
2016
versionSpec: '$(python.version)'
2117
displayName: 'Use Python $(python.version)'
22-
23-
- script: |
24-
python -m pip install --upgrade pip setuptools wheel
25-
python -m pip install -r requirements-dev.txt
26-
displayName: 'Install dependencies'
27-
28-
- script: |
29-
if [ '$(onnx.standard)' == '1' ]
30-
then
31-
python -m pip uninstall -y onnx-function-experiment
32-
python -m pip uninstall -y ort-function-experiment-nightly
33-
python -m pip install -r requirements-onnx.txt
34-
fi
35-
displayName: 'Install onnx'
36-
37-
- script: |
38-
python setup.py sdist
39-
displayName: 'make package'
40-
41-
- script: |
42-
pytest -v onnxscript --cov=onnxscript --cov-report term-missing
43-
displayName: 'pytest'
44-
45-
- script: |
46-
python setup.py install
47-
displayName: 'install package'
48-
49-
- script: |
50-
if [ '$(test.examples)' == '1' ]
51-
then
52-
pytest -v docs/test
53-
fi
54-
displayName: 'Test examples'

onnxscript/backend/onnx_export.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,9 +427,6 @@ def export_template(
427427
Returns:
428428
python code
429429
"""
430-
# delayed import to avoid raising an exception if not installed.
431-
import autopep8 # pylint: disable=import-outside-toplevel
432-
433430
# unique_function_domain_version
434431
unique_function_domain_version = set()
435432
if hasattr(model_onnx, "functions"):
@@ -521,6 +518,9 @@ def rename_variable(name):
521518
if "\nreturn" in final:
522519
raise SyntaxError(f"The produced code is wrong.\n{final}")
523520
if clean_code:
521+
# delayed import to avoid raising an exception if not installed.
522+
import autopep8 # pylint: disable=import-outside-toplevel
523+
524524
cleaned_code = autopep8.fix_code(final, options=autopep_options)
525525
if "\nreturn" in cleaned_code:
526526
raise SyntaxError(f"The cleaned code is wrong.\n{final}\n------{cleaned_code}")

onnxscript/function_libs/torch_aten/ops/core.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,9 @@ def aten_cat(tensors: Sequence[TTensor], dim: int = 0) -> TTensor:
735735
num_of_input = len(tensors) # len() function not support yet
736736
a = op.SequenceEmpty()
737737
for i in range(num_of_input):
738+
if op.Size(tensors[i]) == 0 and dim != 0:
739+
# Skip empty tensors when concatenating along non-zero dimension
740+
continue
738741
a = op.SequenceInsert(a, tensors[i])
739742
return op.ConcatFromSequence(a, axis=dim)
740743

onnxscript/test/function_libs/torch_aten/ops_correctness_test.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import numpy as np
1111
import onnx
12+
import packaging.version
1213
import torch
1314
from torch.testing._internal import common_device_type, common_methods_invocations
1415
from torch.testing._internal.opinfo import core as opinfo_core
@@ -148,9 +149,15 @@ def wrapped(fn):
148149
def duplicate_opinfo(opinfos: list[opinfo_core.OpInfo], name: str, new_names: tuple[str, ...]):
149150
"""Duplicate an opinfo in the opinfo database and give it a new name."""
150151
duplicated = []
152+
all_info_names = {opinfo.name for opinfo in opinfos}
151153
for opinfo in opinfos:
152154
if opinfo.name == name:
153155
for new_name in new_names:
156+
if new_name in all_info_names:
157+
# NOTE: Avoid duplicating an opinfo that already exists in the database.
158+
# New opinfos are expected to be added in torch-nightly.
159+
warnings.warn(f"OpInfo {new_name} already exists in the database.")
160+
continue
154161
new_opinfo = copy.deepcopy(opinfo)
155162
new_opinfo.name = new_name
156163
duplicated.append(new_opinfo)
@@ -187,7 +194,8 @@ def _full_input_wrangler(
187194
args: list[Any], kwargs: dict[str, Any]
188195
) -> tuple[list[Any], dict[str, Any]]:
189196
# Remove the self argument
190-
args.pop(0)
197+
if packaging.version.parse(torch.__version__) <= packaging.version.parse("1.13.1"):
198+
args.pop(0)
191199
return args, kwargs
192200

193201

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ classifiers = [
2626
"Programming Language :: Python :: 3.11",
2727
"License :: OSI Approved :: Apache Software License",
2828
]
29-
dependencies = ["numpy", "protobuf<4", "onnx"]
29+
dependencies = ["numpy", "protobuf<4", "onnx", "typing_extensions"]
3030

3131
[tool.setuptools.dynamic]
3232
version = {attr = "onnxscript.__version__"}

requirements-dev.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
autopep8
21
click
32
numpy==1.23.5
43
matplotlib

requirements-onnx.txt

Lines changed: 0 additions & 5 deletions
This file was deleted.

tox.ini

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
[tox]
2+
requires =
3+
tox>=4
4+
env_list =
5+
py{37,38,39,310}
6+
test-onnx-preview
7+
examples
8+
build
9+
labels =
10+
python310 = py310, build
11+
python39 = py39, build
12+
python38 = py38, build
13+
python37 = py37, build
14+
python310-experimental = test-onnx-preview
15+
python310-torch-nightly = test-torch-nightly
16+
17+
[base]
18+
deps =
19+
autopep8
20+
click
21+
jinja2
22+
numpy==1.23.5
23+
protobuf<4
24+
typing_extensions
25+
26+
; ATen lib
27+
beartype
28+
types-PyYAML
29+
30+
; Testing
31+
expecttest
32+
packaging
33+
parameterized
34+
pytest-cov
35+
pytest-subtests
36+
pytest-xdist
37+
pytest!=7.1.0
38+
pyyaml
39+
commands =
40+
pip list
41+
pytest onnxscript {posargs}
42+
43+
[testenv]
44+
description = run unit tests
45+
deps =
46+
{[base]deps}
47+
onnx==1.13
48+
onnxruntime
49+
torch==1.13
50+
commands =
51+
{[base]commands}
52+
pytest docs/test
53+
54+
[testenv:test-onnx-preview]
55+
description = test with onnx experimental builds
56+
deps=
57+
{[base]deps}
58+
ort-function-experiment-nightly
59+
torch==1.13
60+
pip_pre = true
61+
install_command = python -I -m pip install -f https://onnxruntimepackages.z14.web.core.windows.net/onnxruntime-function-experiment.html {opts} {packages}
62+
commands =
63+
; Uninstall onnx here, because the released onnx is required and installed when onnxscript is installed
64+
python -I -m pip uninstall -y onnx
65+
python -I -m pip install -f https://onnxruntimepackages.z14.web.core.windows.net/onnx-function-experiment.html --pre onnx-function-experiment
66+
pip list
67+
pytest onnxscript {posargs}
68+
pytest docs/test
69+
70+
[testenv:test-torch-nightly]
71+
description = test with pytorch nightly
72+
deps=
73+
{[base]deps}
74+
onnx==1.13
75+
onnxruntime
76+
torch
77+
pip_pre = true
78+
set_env =
79+
PIP_EXTRA_INDEX_URL = {env:PIP_EXTRA_INDEX_URL:https://download.pytorch.org/whl/nightly/cpu}
80+
commands =
81+
{[base]commands}
82+
83+
[testenv:build]
84+
description = build package
85+
skip_install = true
86+
deps =
87+
build
88+
wheel
89+
commands =
90+
python -m build
91+
92+
[gh]
93+
python =
94+
3.8: py38, build
95+
3.9: py39, build
96+
3.10: py310, build, test-onnx-preview, test-torch-nightly

0 commit comments

Comments
 (0)