Skip to content

Commit

Permalink
Update transformers test requirements (#22911)
Browse files Browse the repository at this point in the history
### Description

* Install PyTorch for transformers tests. The installation is before
python tests so that it can use torch if needed.
* Update protobuf and numpy versions used in transformers test.

### Motivation and Context

Currently, transformers tests are enabled in the following CI pipelines:
* Linux CPU CI Pipeline (torch for cpu-only)
* Linux GPU CI Pipeline (torch for cuda 12)
* Windows GPU CUDA CI Pipeline (torch for cpu-only right now, note that
we might change it to torch for cuda 12 in the future).

For ROCm CI Pipeline, transformer tests are enabled but skipped since
onnx package is not installed in CI.

Previously, torch was not installed before python tests, so some tests
depending on torch were skipped like
[test_bind_onnx_types_not_supported_by_numpy](https://github.com/microsoft/onnxruntime/blob/f6e1d4482941d43737d40723df16a6bf0da43ee5/onnxruntime/test/python/onnxruntime_test_python_iobinding.py#L199)
or [test
user_compute_stream](https://github.com/microsoft/onnxruntime/blob/main/onnxruntime/test/python/onnxruntime_test_python.py#L465-L476).

In this PR, we changed build.py to install torch before running python
tests.
  • Loading branch information
tianleiwu authored Nov 22, 2024
1 parent b1ccbe2 commit c97dd6e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
12 changes: 12 additions & 0 deletions tools/ci_build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2074,6 +2074,17 @@ def run_onnxruntime_tests(args, source_dir, ctest_path, build_dir, configs):
if is_windows():
cwd = os.path.join(cwd, config)

if args.enable_transformers_tool_test and not args.disable_contrib_ops and not args.use_rocm:
# PyTorch is required for transformers tests, and optional for some python tests.
# Install cpu only version of torch when cuda is not enabled in Linux.
extra = [] if args.use_cuda and is_linux() else ["--index-url", "https://download.pytorch.org/whl/cpu"]
run_subprocess(
[sys.executable, "-m", "pip", "install", "torch", *extra],
cwd=cwd,
dll_path=dll_path,
python_path=python_path,
)

run_subprocess(
[sys.executable, "onnxruntime_test_python.py"], cwd=cwd, dll_path=dll_path, python_path=python_path
)
Expand Down Expand Up @@ -2128,6 +2139,7 @@ def run_onnxruntime_tests(args, source_dir, ctest_path, build_dir, configs):
dll_path=dll_path,
python_path=python_path,
)

if not args.disable_contrib_ops:
run_subprocess(
[sys.executable, "-m", "unittest", "discover", "-s", "quantization"], cwd=cwd, dll_path=dll_path
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# packages used by transformers python unittest (only enabled in Linux CPU CI Pipeline)
# packages used by transformers python unittest
packaging
protobuf==3.20.2
numpy==1.24.0 ; python_version < '3.12'
numpy==1.26.0 ; python_version >= '3.12'
# protobuf and numpy is same as tools/ci_build/github/linux/docker/scripts/manylinux/requirements.txt
protobuf==4.21.12
numpy==1.21.6 ; python_version < '3.9'
numpy==2.0.0 ; python_version >= '3.9'
torch
coloredlogs==15.0
transformers==4.46.3
Expand Down

0 comments on commit c97dd6e

Please sign in to comment.