Skip to content

Commit

Permalink
5394 enable py311 tests (Project-MONAI#7182)
Browse files Browse the repository at this point in the history
Fixes Project-MONAI#5394


### Types of changes
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] Non-breaking change (fix or new feature that would not break
existing functionality).
- [ ] Breaking change (fix or new feature that would cause existing
functionality to change).
- [ ] New tests added to cover the changes.
- [ ] Integration tests passed locally by running `./runtests.sh -f -u
--net --coverage`.
- [ ] Quick tests passed locally by running `./runtests.sh --quick
--unittests --disttests`.
- [ ] In-line docstrings updated.
- [ ] Documentation updated, tested `make html` command in the `docs/`
folder.

---------

Signed-off-by: Wenqi Li <[email protected]>
  • Loading branch information
wyli authored Nov 1, 2023
1 parent 3239db8 commit cf886e7
Showing 1 changed file with 21 additions and 33 deletions.
54 changes: 21 additions & 33 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,22 +724,16 @@ def test_script_save(net, *inputs, device=None, rtol=1e-4, atol=0.0):
"""
# TODO: would be nice to use GPU if available, but it currently causes CI failures.
device = "cpu"
try:
with tempfile.TemporaryDirectory() as tempdir:
convert_to_torchscript(
model=net,
filename_or_obj=os.path.join(tempdir, "model.ts"),
verify=True,
inputs=inputs,
device=device,
rtol=rtol,
atol=atol,
)
except (RuntimeError, AttributeError):
if sys.version_info.major == 3 and sys.version_info.minor == 11:
warnings.warn("skipping py 3.11")
return
raise
with tempfile.TemporaryDirectory() as tempdir:
convert_to_torchscript(
model=net,
filename_or_obj=os.path.join(tempdir, "model.ts"),
verify=True,
inputs=inputs,
device=device,
rtol=rtol,
atol=atol,
)


def test_onnx_save(net, *inputs, device=None, rtol=1e-4, atol=0.0):
Expand All @@ -753,23 +747,17 @@ def test_onnx_save(net, *inputs, device=None, rtol=1e-4, atol=0.0):
# TODO: would be nice to use GPU if available, but it currently causes CI failures.
device = "cpu"
_, has_onnxruntime = optional_import("onnxruntime")
try:
with tempfile.TemporaryDirectory() as tempdir:
convert_to_onnx(
model=net,
filename=os.path.join(tempdir, "model.onnx"),
verify=True,
inputs=inputs,
device=device,
use_ort=has_onnxruntime,
rtol=rtol,
atol=atol,
)
except (RuntimeError, AttributeError):
if sys.version_info.major == 3 and sys.version_info.minor == 11:
warnings.warn("skipping py 3.11")
return
raise
with tempfile.TemporaryDirectory() as tempdir:
convert_to_onnx(
model=net,
filename=os.path.join(tempdir, "model.onnx"),
verify=True,
inputs=inputs,
device=device,
use_ort=has_onnxruntime,
rtol=rtol,
atol=atol,
)


def download_url_or_skip_test(*args, **kwargs):
Expand Down

0 comments on commit cf886e7

Please sign in to comment.