Skip to content

Commit

Permalink
5394 adds py311 min tests (#5481)
Browse files Browse the repository at this point in the history
Signed-off-by: Wenqi Li <wenqil@nvidia.com>

part of #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.


cc @rijobro

Signed-off-by: Wenqi Li <wenqil@nvidia.com>
Signed-off-by: monai-bot <monai.miccai2019@gmail.com>
Co-authored-by: monai-bot <monai.miccai2019@gmail.com>
  • Loading branch information
wyli and monai-bot authored Nov 8, 2022
1 parent 468f490 commit e7bfac6
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 26 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pythonapp-min.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10']
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
timeout-minutes: 40
steps:
- uses: actions/checkout@v3
Expand All @@ -102,7 +102,7 @@ jobs:
- name: Install the dependencies
run: |
# min. requirements
python -m pip install torch==1.13
python -m pip install torch --extra-index-url https://download.pytorch.org/whl/cpu
python -m pip install -r requirements-min.txt
python -m pip list
BUILD_MONAI=0 python setup.py develop # no compile of extensions
Expand Down
8 changes: 6 additions & 2 deletions monai/engines/multi_gpu_supervised_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@
from ignite.engine import Engine
from ignite.metrics import Metric
else:
Engine, _ = optional_import("ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Engine")
Metric, _ = optional_import("ignite.metrics", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Metric")
Engine, _ = optional_import(
"ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Engine", as_type="decorator"
)
Metric, _ = optional_import(
"ignite.metrics", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Metric", as_type="decorator"
)

__all__ = ["create_multigpu_supervised_trainer", "create_multigpu_supervised_evaluator"]

Expand Down
12 changes: 9 additions & 3 deletions monai/engines/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,15 @@
from ignite.engine import Engine, EventEnum
from ignite.metrics import Metric
else:
Engine, _ = optional_import("ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Engine")
Metric, _ = optional_import("ignite.metrics", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Metric")
EventEnum, _ = optional_import("ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "EventEnum")
Engine, _ = optional_import(
"ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Engine", as_type="decorator"
)
Metric, _ = optional_import(
"ignite.metrics", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Metric", as_type="decorator"
)
EventEnum, _ = optional_import(
"ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "EventEnum", as_type="decorator"
)


class Workflow(IgniteEngine): # type: ignore[valid-type, misc] # due to optional_import
Expand Down
4 changes: 3 additions & 1 deletion monai/handlers/earlystop_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
if TYPE_CHECKING:
from ignite.engine import Engine
else:
Engine, _ = optional_import("ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Engine")
Engine, _ = optional_import(
"ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Engine", as_type="decorator"
)


class EarlyStopHandler:
Expand Down
4 changes: 3 additions & 1 deletion monai/handlers/lr_schedule_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
if TYPE_CHECKING:
from ignite.engine import Engine
else:
Engine, _ = optional_import("ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Engine")
Engine, _ = optional_import(
"ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Engine", as_type="decorator"
)


class LrScheduleHandler:
Expand Down
4 changes: 3 additions & 1 deletion monai/handlers/metric_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
if TYPE_CHECKING:
from ignite.engine import Engine
else:
Engine, _ = optional_import("ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Engine")
Engine, _ = optional_import(
"ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Engine", as_type="decorator"
)


def _get_loss_from_output(output, loss_key: str = CommonKeys.LOSS):
Expand Down
4 changes: 3 additions & 1 deletion monai/handlers/mlflow_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
if TYPE_CHECKING:
from ignite.engine import Engine
else:
Engine, _ = optional_import("ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Engine")
Engine, _ = optional_import(
"ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Engine", as_type="decorator"
)

DEFAULT_TAG = "Loss"

Expand Down
8 changes: 6 additions & 2 deletions monai/handlers/nvtx_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@
if TYPE_CHECKING:
from ignite.engine import Engine, Events
else:
Engine, _ = optional_import("ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Engine")
Events, _ = optional_import("ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Events")
Engine, _ = optional_import(
"ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Engine", as_type="decorator"
)
Events, _ = optional_import(
"ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Events", as_type="decorator"
)

__all__ = ["RangeHandler", "RangePushHandler", "RangePopHandler", "MarkHandler"]

Expand Down
4 changes: 3 additions & 1 deletion monai/handlers/stats_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
if TYPE_CHECKING:
from ignite.engine import Engine
else:
Engine, _ = optional_import("ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Engine")
Engine, _ = optional_import(
"ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Engine", as_type="decorator"
)

DEFAULT_KEY_VAL_FORMAT = "{}: {:.4f} "
DEFAULT_TAG = "Loss"
Expand Down
4 changes: 3 additions & 1 deletion monai/handlers/tensorboard_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
if TYPE_CHECKING:
from ignite.engine import Engine
else:
Engine, _ = optional_import("ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Engine")
Engine, _ = optional_import(
"ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Engine", as_type="decorator"
)

DEFAULT_TAG = "Loss"

Expand Down
2 changes: 1 addition & 1 deletion tests/min_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def run_testsuit():
from monai.utils.module import load_submodules

_, err_mod = load_submodules(sys.modules["monai"], True)
assert not err_mod
assert not err_mod, f"err_mod={err_mod} not empty"

# testing all modules
test_runner = unittest.TextTestRunner(stream=sys.stdout, verbosity=2)
Expand Down
25 changes: 15 additions & 10 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,16 +698,21 @@ 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"
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,
)
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


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

0 comments on commit e7bfac6

Please sign in to comment.