mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
This PR is part of the work to deprecate torch::deploy in OSS. Effectively it does 3 things to get started. 1. Remove test_deploy_interaction as we no longer need to worry about this 2. Remove all torch._running_with_deploy checks and use the False path always (surfaced 1) 3. Remove `USE_DEPLOY` and switch to the default path always Note: MyPy does fail on a bunch of things here as a bunch of older files are touched. It may be better to fix these things on a separate PR Pull Request resolved: https://github.com/pytorch/pytorch/pull/158288 Approved by: https://github.com/albanD
39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
import functools
|
|
import importlib.util
|
|
from types import ModuleType
|
|
from typing import Optional
|
|
|
|
|
|
def _check_module_exists(name: str) -> bool:
|
|
r"""Returns if a top-level module with :attr:`name` exists *without**
|
|
importing it. This is generally safer than try-catch block around a
|
|
`import X`. It avoids third party libraries breaking assumptions of some of
|
|
our tests, e.g., setting multiprocessing start method when imported
|
|
(see librosa/#747, torchvision/#544).
|
|
"""
|
|
try:
|
|
spec = importlib.util.find_spec(name)
|
|
return spec is not None
|
|
except ImportError:
|
|
return False
|
|
|
|
|
|
@functools.lru_cache
|
|
def dill_available() -> bool:
|
|
return _check_module_exists("dill")
|
|
|
|
|
|
@functools.lru_cache
|
|
def import_dill() -> Optional[ModuleType]:
|
|
if not dill_available():
|
|
return None
|
|
|
|
import dill
|
|
|
|
# XXX: By default, dill writes the Pickler dispatch table to inject its
|
|
# own logic there. This globally affects the behavior of the standard library
|
|
# pickler for any user who transitively depends on this module!
|
|
# Undo this extension to avoid altering the behavior of the pickler globally.
|
|
dill.extend(use_dill=False)
|
|
return dill
|