Skip to content

Commit 677ba7f

Browse files
authored
Add CI to check with onnxruntime-traning and transformers (#1609)
Signed-off-by: Xavier Dupre <xadupre@microsoft.com>
1 parent d620466 commit 677ba7f

File tree

6 files changed

+63
-15
lines changed

6 files changed

+63
-15
lines changed

.github/workflows/main.yaml

+26
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,32 @@ jobs:
106106
name: IR profiling results
107107
path: tests/ir/serde_test_profiles
108108

109+
dort:
110+
strategy:
111+
fail-fast: false
112+
matrix:
113+
os: [ubuntu-latest]
114+
transformers: ["4.37.2", "4.41.2"]
115+
torch: ["release", "nightly"]
116+
python_version: ["3.11"]
117+
nox-tag: ["test-dort"]
118+
name:
119+
- dort
120+
runs-on: ${{ matrix.os }}
121+
steps:
122+
- uses: actions/checkout@v4
123+
- name: Setup Python ${{ matrix.python_version }}
124+
uses: actions/setup-python@v5
125+
with:
126+
python-version: ${{ matrix.python_version }}
127+
- name: Install nox
128+
run: python -m pip install nox
129+
- name: Pull Test Data
130+
run: git lfs pull
131+
- run: |
132+
nox -t ${{ matrix.nox-tag }} --forcecolor -- ${{ matrix.torch }} ${{ matrix.transformers }}
133+
name: Run tests
134+
109135
build_docs:
110136
strategy:
111137
fail-fast: false

noxfile.py

+29-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
'numpy==1.26.4; python_version>="3.9"',
2020
"packaging",
2121
"parameterized",
22-
"pyinstrument",
2322
"pytest-cov",
2423
"pytest-randomly",
2524
"pytest-subtests",
@@ -153,3 +152,32 @@ def test_experimental_torchlib_onnx_ir(session):
153152
*session.posargs,
154153
env={"TORCHLIB_EXPERIMENTAL_USE_IR": "1"},
155154
)
155+
156+
157+
@nox.session(tags=["test-dort"])
158+
def test_dort(session):
159+
"""Test the conversion of a couple of models from transformers."""
160+
session.install(
161+
*COMMON_TEST_DEPENDENCIES,
162+
)
163+
torch_version, transformers_version = session.posargs
164+
165+
if torch_version == "nighly":
166+
session.install(
167+
"--pre",
168+
"torch",
169+
"torchvision",
170+
"torchaudio",
171+
"--index-url",
172+
"https://download.pytorch.org/whl/nightly/cpu",
173+
)
174+
else:
175+
session.install("torch", "torchvision", "torchaudio")
176+
177+
session.install("torch", "torchvision", "torchaudio")
178+
session.install(f"transformers=={transformers_version}")
179+
session.install("onnxruntime-training==1.17.1")
180+
181+
session.run("pip", "list")
182+
session.run("pytest", "onnxscript")
183+
session.run("pytest", "tests")

onnxscript/tools/benchmark/export_model_test.py

+5
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ def test_export_model_llama_cpu_eager(self):
6262

6363
@unittest.skipIf(not has_transformers(), reason="transformers missing")
6464
@unittest.skipIf(not is_onnxruntime_training(), reason="onnxruntime-training is needed")
65+
@unittest.skipIf(
66+
torch_older_than("2.4"),
67+
reason="TypeError: _functionalize_sync(): "
68+
"argument 't' (position 1) must be Tensor, not NoneType",
69+
)
6570
def test_export_model_phi_cpu_dynamo(self):
6671
args = [
6772
"--verbose",

requirements-dev.txt

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ beartype!=0.16.0
2424
expecttest==0.1.6
2525
hypothesis
2626
parameterized
27-
pyinstrument
2827
pytest-cov
2928
pytest-randomly
3029
pytest-subtests

tests/common/testutils.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import numpy as np
1111
import onnx
1212
import onnxruntime
13+
import torch
1314

1415
from onnxscript import optimizer
1516
from onnxscript._legacy_ir import visitor
@@ -29,7 +30,7 @@ def skip_if_no_cuda(reason: str):
2930
def skip_dec(func):
3031
@functools.wraps(func)
3132
def wrapper(self, *args, **kwargs):
32-
if not onnxruntime.get_device() == "GPU":
33+
if not torch.cuda.is_available() or not onnxruntime.get_device() == "GPU":
3334
raise unittest.SkipTest(f"GPU is not available. {reason}")
3435
return func(self, *args, **kwargs)
3536

tests/ir/serde_roundtrip_test.py

+1-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright (c) Microsoft Corporation.
22
# Licensed under the MIT License.
3+
# pylint: disable=import-outside-toplevel
34
from __future__ import annotations
45

56
import pathlib
@@ -8,7 +9,6 @@
89
import onnx
910
import onnx.backend.test
1011
import parameterized
11-
import pyinstrument
1212

1313
import onnxscript.testing
1414
from onnxscript import ir
@@ -25,12 +25,6 @@
2525

2626

2727
class SerdeTest(unittest.TestCase):
28-
def setUp(self) -> None:
29-
self.profiler = pyinstrument.Profiler()
30-
31-
def tearDown(self) -> None:
32-
self.profiler.reset()
33-
3428
@parameterized.parameterized.expand(test_args)
3529
def test_serialization_deserialization_produces_same_model(
3630
self, _: str, model_path: pathlib.Path
@@ -41,13 +35,8 @@ def test_serialization_deserialization_produces_same_model(
4135
onnx.checker.check_model(model)
4236

4337
# Profile the serialization and deserialization process
44-
self.profiler.start()
4538
ir_model = ir.serde.deserialize_model(model)
4639
serialized = ir.serde.serialize_model(ir_model)
47-
self.profiler.stop()
48-
profile_path = pathlib.Path(__file__).parent / "serde_test_profiles"
49-
profile_path.mkdir(exist_ok=True)
50-
self.profiler.write_html(profile_path / f"{self.id().split('.')[-1]}.html")
5140

5241
onnxscript.testing.assert_onnx_proto_equal(serialized, model)
5342
onnx.checker.check_model(serialized)

0 commit comments

Comments
 (0)