Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import 'optim' only if PyTorch is installed #22072

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions orttraining/orttraining/python/training/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,30 @@
# Licensed under the MIT License.
# --------------------------------------------------------------------------
# isort: skip_file
import importlib.util

from onnxruntime.capi._pybind_state import (
PropagateCastOpsStrategy,
TrainingParameters,
is_ortmodule_available,
)

# Options need to be imported before `ORTTrainer`.
from . import amp, artifacts, optim
from . import amp, artifacts

__all__ = [
"PropagateCastOpsStrategy",
"TrainingParameters",
"is_ortmodule_available",
"amp",
"artifacts",
"optim",
]

if importlib.util.find_spec("torch") is not None:
from . import optim

__all__ += ["optim"]
xadupre marked this conversation as resolved.
Show resolved Hide resolved

try:
if is_ortmodule_available():
from .ortmodule import ORTModule
Expand Down
Loading