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

handle ImportError and OSError in extras.pytorch #1141

Merged
merged 2 commits into from
Aug 25, 2022
Merged
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
13 changes: 12 additions & 1 deletion flytekit/extras/pytorch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,21 @@
"""
from flytekit.loggers import logger

# TODO: abstract this out so that there's an established pattern for registering plugins
# that have soft dependencies
try:
# isolate the exception to the torch import
import torch

_torch_installed = True
except (ImportError, OSError):
_torch_installed = False


if _torch_installed:
from .checkpoint import PyTorchCheckpoint, PyTorchCheckpointTransformer
from .native import PyTorchModuleTransformer, PyTorchTensorTransformer
except ImportError:
else:
logger.info(
"We won't register PyTorchCheckpointTransformer, PyTorchTensorTransformer, and PyTorchModuleTransformer because torch is not installed."
)