/usr/local/lib64/python3.6/site-packages/torch/utils
NameSizeModeActions
backcompat/-0755rm
benchmark/-0755rm
bottleneck/-0755rm
data/-0755rm
ffi/-0755rm
hipify/-0755rm
model_dump/-0755rm
tensorboard/-0755rm
__pycache__/-0755rm
bundled_inputs.py222820644editdlrm
checkpoint.py121650644editdlrm
collect_env.py167230644editdlrm
cpp_extension.py877390644editdlrm
dlpack.py20450644editdlrm
file_baton.py13960644editdlrm
hooks.py73730644editdlrm
mkldnn.py72190644editdlrm
mobile_optimizer.py62640644editdlrm
model_zoo.py1170644editdlrm
show_pickle.py51690644editdlrm
throughput_benchmark.py63870644editdlrm
_cpp_extension_versioner.py19910644editdlrm
_crash_handler.py6730644editdlrm
_python_dispatch.py16360644editdlrm
_pytree.py81740644editdlrm
__init__.py6350644editdlrm
Edit: /usr/local/lib64/python3.6/site-packages/torch/utils/_python_dispatch.py (1636B)
import torch import contextlib from typing import Iterator # Context manager that causes all pytorch operators to dispatch to the passed-in # type's __torch_dispatch__ function. # operation that accepts no tensors but returns a tensor. # # enable_python_mode is affected by torch._C._DisableTorchDispatch. # # NB: Calling an operator inside __torch_dispatch__ does go through # __torch_dispatch__ again. Please use _DisableTorchDispatch inside # __torch_dispatch__ to prevent infinite recursion. # # TODO: Limitations and things about enable_python_mode we should fix before exposing it: # - it currently cannot be nested. This should be simple to implement; we need a # stack of TorchDispatchTypeObjects and the next bullet point. # - We need a better user-facing api for torch._C._DisableTorchDispatch that # is able to selectively disable __torch_dispatch__ of a particular class. # - It doesn't work with the tensor constructors (torch.tensor, torch.Tensor) # - Better name (see https://github.com/pytorch/pytorch/pull/63496#discussion_r694091694) @contextlib.contextmanager def enable_python_mode(cls) -> Iterator[None]: if not hasattr(cls, '__torch_dispatch__'): raise ValueError('The class passed to enable_python_mode ' 'must have a __torch_dispatch__ classmethod') if not isinstance(cls, type) or not issubclass(cls, (torch.Tensor,)): raise ValueError('The argument passed to enable_python_mode ' 'must be the type of a Tensor subclass') torch._C._enter_python_mode(cls) try: yield finally: torch._C._exit_python_mode()