Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- miniconda3/envs/ladir/lib/python3.10/site-packages/tokenizers-0.22.2.dist-info/WHEEL +5 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C.cpython-310-x86_64-linux-gnu.so +0 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_VariableFunctions.pyi +0 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/__init__.pyi +0 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_acc/__init__.pyi +15 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_aoti.pyi +164 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_autograd.pyi +144 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_cpu.pyi +13 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_cudnn.pyi +14 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_cusparselt.pyi +1 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_distributed.pyi +21 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_distributed_autograd.pyi +26 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_distributed_c10d.pyi +889 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_distributed_rpc.pyi +188 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_distributed_rpc_testing.pyi +32 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_dynamo/__init__.pyi +4 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_dynamo/compiled_autograd.pyi +13 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_dynamo/eval_frame.pyi +84 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_dynamo/guards.pyi +452 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_export/__init__.pyi +9 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_export/pt2_archive_constants.pyi +25 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_functionalization.pyi +16 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_functions.pyi +19 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_functorch.pyi +89 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_instruction_counter.pyi +4 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_itt.pyi +5 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_jit_tree_views.pyi +202 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_lazy.pyi +26 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_lazy_ts_backend.pyi +12 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_monitor.pyi +58 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_nn.pyi +341 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_nvtx.pyi +9 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_onnx.pyi +39 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_profiler.pyi +247 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_verbose.pyi +3 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C_flatbuffer/__init__.pyi +11 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_VF.py +31 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_VF.pyi +0 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/torch/__config__.py +22 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/torch/__future__.py +75 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/torch/__init__.py +0 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_appdirs.py +666 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_awaits/__init__.py +53 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_classes.py +56 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_compile.py +60 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_custom_op/__init__.py +0 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_custom_op/autograd.py +307 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_custom_op/impl.py +716 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_custom_ops.py +326 -0
- miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_decomp/__init__.py +549 -0
miniconda3/envs/ladir/lib/python3.10/site-packages/tokenizers-0.22.2.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: maturin (1.10.2)
|
| 3 |
+
Root-Is-Purelib: false
|
| 4 |
+
Tag: cp39-abi3-manylinux_2_17_x86_64
|
| 5 |
+
Tag: cp39-abi3-manylinux2014_x86_64
|
miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C.cpython-310-x86_64-linux-gnu.so
ADDED
|
Binary file (25.5 kB). View file
|
|
|
miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_VariableFunctions.pyi
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/__init__.pyi
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_acc/__init__.pyi
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from torch import Tensor
|
| 2 |
+
from torch.types import _dtype, _int, Device
|
| 3 |
+
|
| 4 |
+
# Defined in torch/csrc/acc/Module.cpp
|
| 5 |
+
class PrivateUse1Hooks:
|
| 6 |
+
def has_primary_context(self, device_index: _int) -> bool: ...
|
| 7 |
+
def is_built(self) -> bool: ...
|
| 8 |
+
def is_avaible(self) -> bool: ...
|
| 9 |
+
|
| 10 |
+
class DeviceGuard:
|
| 11 |
+
def type_(self) -> Device: ...
|
| 12 |
+
|
| 13 |
+
def register_python_privateuseone_device_guard(guard: DeviceGuard) -> bool: ...
|
| 14 |
+
def register_python_privateuseone_hook(hook: PrivateUse1Hooks) -> bool: ...
|
| 15 |
+
def create_empty_tensor(shape: tuple[_int, ...], dtype: _dtype) -> Tensor: ...
|
miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_aoti.pyi
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from ctypes import c_void_p
|
| 2 |
+
from typing import overload, Protocol
|
| 3 |
+
|
| 4 |
+
from torch import Tensor
|
| 5 |
+
|
| 6 |
+
# Defined in torch/csrc/inductor/aoti_runner/pybind.cpp
|
| 7 |
+
|
| 8 |
+
# Tensor to AtenTensorHandle
|
| 9 |
+
def unsafe_alloc_void_ptrs_from_tensors(tensors: list[Tensor]) -> list[c_void_p]: ...
|
| 10 |
+
def unsafe_alloc_void_ptr_from_tensor(tensor: Tensor) -> c_void_p: ...
|
| 11 |
+
|
| 12 |
+
# AtenTensorHandle to Tensor
|
| 13 |
+
def alloc_tensors_by_stealing_from_void_ptrs(
|
| 14 |
+
handles: list[c_void_p],
|
| 15 |
+
) -> list[Tensor]: ...
|
| 16 |
+
def alloc_tensor_by_stealing_from_void_ptr(
|
| 17 |
+
handle: c_void_p,
|
| 18 |
+
) -> Tensor: ...
|
| 19 |
+
|
| 20 |
+
class AOTIModelContainerRunner(Protocol):
|
| 21 |
+
def run(
|
| 22 |
+
self, inputs: list[Tensor], stream_handle: c_void_p = ...
|
| 23 |
+
) -> list[Tensor]: ...
|
| 24 |
+
def get_call_spec(self) -> list[str]: ...
|
| 25 |
+
def get_constant_names_to_original_fqns(self) -> dict[str, str]: ...
|
| 26 |
+
def get_constant_names_to_dtypes(self) -> dict[str, int]: ...
|
| 27 |
+
def extract_constants_map(self, use_inactive: bool) -> dict[str, Tensor]: ...
|
| 28 |
+
def update_constant_buffer(
|
| 29 |
+
self,
|
| 30 |
+
tensor_map: dict[str, Tensor],
|
| 31 |
+
use_inactive: bool,
|
| 32 |
+
validate_full_updates: bool,
|
| 33 |
+
user_managed: bool = ...,
|
| 34 |
+
) -> None: ...
|
| 35 |
+
def swap_constant_buffer(self) -> None: ...
|
| 36 |
+
def free_inactive_constant_buffer(self) -> None: ...
|
| 37 |
+
|
| 38 |
+
class AOTIModelContainerRunnerCpu:
|
| 39 |
+
def __init__(self, model_so_path: str, num_models: int) -> None: ...
|
| 40 |
+
def run(
|
| 41 |
+
self, inputs: list[Tensor], stream_handle: c_void_p = ...
|
| 42 |
+
) -> list[Tensor]: ...
|
| 43 |
+
def get_call_spec(self) -> list[str]: ...
|
| 44 |
+
def get_constant_names_to_original_fqns(self) -> dict[str, str]: ...
|
| 45 |
+
def get_constant_names_to_dtypes(self) -> dict[str, int]: ...
|
| 46 |
+
def extract_constants_map(self, use_inactive: bool) -> dict[str, Tensor]: ...
|
| 47 |
+
def update_constant_buffer(
|
| 48 |
+
self,
|
| 49 |
+
tensor_map: dict[str, Tensor],
|
| 50 |
+
use_inactive: bool,
|
| 51 |
+
validate_full_updates: bool,
|
| 52 |
+
user_managed: bool = ...,
|
| 53 |
+
) -> None: ...
|
| 54 |
+
def swap_constant_buffer(self) -> None: ...
|
| 55 |
+
def free_inactive_constant_buffer(self) -> None: ...
|
| 56 |
+
|
| 57 |
+
class AOTIModelContainerRunnerCuda:
|
| 58 |
+
@overload
|
| 59 |
+
def __init__(self, model_so_path: str, num_models: int) -> None: ...
|
| 60 |
+
@overload
|
| 61 |
+
def __init__(
|
| 62 |
+
self, model_so_path: str, num_models: int, device_str: str
|
| 63 |
+
) -> None: ...
|
| 64 |
+
@overload
|
| 65 |
+
def __init__(
|
| 66 |
+
self, model_so_path: str, num_models: int, device_str: str, cubin_dir: str
|
| 67 |
+
) -> None: ...
|
| 68 |
+
def run(
|
| 69 |
+
self, inputs: list[Tensor], stream_handle: c_void_p = ...
|
| 70 |
+
) -> list[Tensor]: ...
|
| 71 |
+
def get_call_spec(self) -> list[str]: ...
|
| 72 |
+
def get_constant_names_to_original_fqns(self) -> dict[str, str]: ...
|
| 73 |
+
def get_constant_names_to_dtypes(self) -> dict[str, int]: ...
|
| 74 |
+
def extract_constants_map(self, use_inactive: bool) -> dict[str, Tensor]: ...
|
| 75 |
+
def update_constant_buffer(
|
| 76 |
+
self,
|
| 77 |
+
tensor_map: dict[str, Tensor],
|
| 78 |
+
use_inactive: bool,
|
| 79 |
+
validate_full_updates: bool,
|
| 80 |
+
user_managed: bool = ...,
|
| 81 |
+
) -> None: ...
|
| 82 |
+
def swap_constant_buffer(self) -> None: ...
|
| 83 |
+
def free_inactive_constant_buffer(self) -> None: ...
|
| 84 |
+
|
| 85 |
+
class AOTIModelContainerRunnerXpu:
|
| 86 |
+
@overload
|
| 87 |
+
def __init__(self, model_so_path: str, num_models: int) -> None: ...
|
| 88 |
+
@overload
|
| 89 |
+
def __init__(
|
| 90 |
+
self, model_so_path: str, num_models: int, device_str: str
|
| 91 |
+
) -> None: ...
|
| 92 |
+
@overload
|
| 93 |
+
def __init__(
|
| 94 |
+
self, model_so_path: str, num_models: int, device_str: str, kernel_bin_dir: str
|
| 95 |
+
) -> None: ...
|
| 96 |
+
def run(
|
| 97 |
+
self, inputs: list[Tensor], stream_handle: c_void_p = ...
|
| 98 |
+
) -> list[Tensor]: ...
|
| 99 |
+
def get_call_spec(self) -> list[str]: ...
|
| 100 |
+
def get_constant_names_to_original_fqns(self) -> dict[str, str]: ...
|
| 101 |
+
def get_constant_names_to_dtypes(self) -> dict[str, int]: ...
|
| 102 |
+
def extract_constants_map(self, use_inactive: bool) -> dict[str, Tensor]: ...
|
| 103 |
+
def update_constant_buffer(
|
| 104 |
+
self,
|
| 105 |
+
tensor_map: dict[str, Tensor],
|
| 106 |
+
use_inactive: bool,
|
| 107 |
+
validate_full_updates: bool,
|
| 108 |
+
user_managed: bool = ...,
|
| 109 |
+
) -> None: ...
|
| 110 |
+
def swap_constant_buffer(self) -> None: ...
|
| 111 |
+
def free_inactive_constant_buffer(self) -> None: ...
|
| 112 |
+
|
| 113 |
+
class AOTIModelContainerRunnerMps:
|
| 114 |
+
def __init__(self, model_so_path: str, num_models: int) -> None: ...
|
| 115 |
+
def run(
|
| 116 |
+
self, inputs: list[Tensor], stream_handle: c_void_p = ...
|
| 117 |
+
) -> list[Tensor]: ...
|
| 118 |
+
def get_call_spec(self) -> list[str]: ...
|
| 119 |
+
def get_constant_names_to_original_fqns(self) -> dict[str, str]: ...
|
| 120 |
+
def get_constant_names_to_dtypes(self) -> dict[str, int]: ...
|
| 121 |
+
def extract_constants_map(self, use_inactive: bool) -> dict[str, Tensor]: ...
|
| 122 |
+
def update_constant_buffer(
|
| 123 |
+
self,
|
| 124 |
+
tensor_map: dict[str, Tensor],
|
| 125 |
+
use_inactive: bool,
|
| 126 |
+
validate_full_updates: bool,
|
| 127 |
+
user_managed: bool = ...,
|
| 128 |
+
) -> None: ...
|
| 129 |
+
def swap_constant_buffer(self) -> None: ...
|
| 130 |
+
def free_inactive_constant_buffer(self) -> None: ...
|
| 131 |
+
|
| 132 |
+
# Defined in torch/csrc/inductor/aoti_package/pybind.cpp
|
| 133 |
+
class AOTIModelPackageLoader:
|
| 134 |
+
def __init__(
|
| 135 |
+
self,
|
| 136 |
+
model_package_path: str,
|
| 137 |
+
model_name: str,
|
| 138 |
+
run_single_threaded: bool,
|
| 139 |
+
num_runners: int,
|
| 140 |
+
device_index: int,
|
| 141 |
+
) -> None: ...
|
| 142 |
+
def get_metadata(self) -> dict[str, str]: ...
|
| 143 |
+
def run(
|
| 144 |
+
self, inputs: list[Tensor], stream_handle: c_void_p = ...
|
| 145 |
+
) -> list[Tensor]: ...
|
| 146 |
+
def boxed_run(
|
| 147 |
+
self, inputs: list[Tensor], stream_handle: c_void_p = ...
|
| 148 |
+
) -> list[Tensor]: ...
|
| 149 |
+
def get_call_spec(self) -> list[str]: ...
|
| 150 |
+
def get_constant_fqns(self) -> list[str]: ...
|
| 151 |
+
def load_constants(
|
| 152 |
+
self,
|
| 153 |
+
constants_map: dict[str, Tensor],
|
| 154 |
+
use_inactive: bool,
|
| 155 |
+
check_full_update: bool,
|
| 156 |
+
user_managed: bool = ...,
|
| 157 |
+
) -> None: ...
|
| 158 |
+
def update_constant_buffer(
|
| 159 |
+
self,
|
| 160 |
+
tensor_map: dict[str, Tensor],
|
| 161 |
+
use_inactive: bool,
|
| 162 |
+
validate_full_updates: bool,
|
| 163 |
+
user_managed: bool = ...,
|
| 164 |
+
) -> None: ...
|
miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_autograd.pyi
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# mypy: allow-untyped-defs
|
| 2 |
+
from collections.abc import Callable
|
| 3 |
+
from enum import Enum
|
| 4 |
+
from typing import Any
|
| 5 |
+
|
| 6 |
+
import torch
|
| 7 |
+
from torch._C._profiler import (
|
| 8 |
+
_ProfilerEvent,
|
| 9 |
+
ActiveProfilerType,
|
| 10 |
+
ProfilerActivity,
|
| 11 |
+
ProfilerConfig,
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
# Defined in torch/csrc/autograd/init.cpp
|
| 15 |
+
|
| 16 |
+
class DeviceType(Enum):
|
| 17 |
+
CPU = ...
|
| 18 |
+
CUDA = ...
|
| 19 |
+
XPU = ...
|
| 20 |
+
MKLDNN = ...
|
| 21 |
+
OPENGL = ...
|
| 22 |
+
OPENCL = ...
|
| 23 |
+
IDEEP = ...
|
| 24 |
+
HIP = ...
|
| 25 |
+
FPGA = ...
|
| 26 |
+
MAIA = ...
|
| 27 |
+
XLA = ...
|
| 28 |
+
MTIA = ...
|
| 29 |
+
MPS = ...
|
| 30 |
+
HPU = ...
|
| 31 |
+
Meta = ...
|
| 32 |
+
Vulkan = ...
|
| 33 |
+
Metal = ...
|
| 34 |
+
PrivateUse1 = ...
|
| 35 |
+
|
| 36 |
+
class ProfilerEvent:
|
| 37 |
+
def cpu_elapsed_us(self, other: ProfilerEvent) -> float: ...
|
| 38 |
+
def cpu_memory_usage(self) -> int: ...
|
| 39 |
+
def cuda_elapsed_us(self, other: ProfilerEvent) -> float: ...
|
| 40 |
+
def privateuse1_elapsed_us(self, other: ProfilerEvent) -> float: ...
|
| 41 |
+
def cuda_memory_usage(self) -> int: ...
|
| 42 |
+
def device(self) -> int: ...
|
| 43 |
+
def handle(self) -> int: ...
|
| 44 |
+
def has_cuda(self) -> bool: ...
|
| 45 |
+
def is_remote(self) -> bool: ...
|
| 46 |
+
def kind(self) -> int: ...
|
| 47 |
+
def name(self) -> str: ...
|
| 48 |
+
def node_id(self) -> int: ...
|
| 49 |
+
def sequence_nr(self) -> int: ...
|
| 50 |
+
def shapes(self) -> list[list[int]]: ...
|
| 51 |
+
def thread_id(self) -> int: ...
|
| 52 |
+
def flops(self) -> float: ...
|
| 53 |
+
def is_async(self) -> bool: ...
|
| 54 |
+
|
| 55 |
+
class _KinetoEvent:
|
| 56 |
+
def name(self) -> str: ...
|
| 57 |
+
def overload_name(self) -> str: ...
|
| 58 |
+
def device_index(self) -> int: ...
|
| 59 |
+
def device_resource_id(self) -> int: ...
|
| 60 |
+
def start_ns(self) -> int: ...
|
| 61 |
+
def end_ns(self) -> int: ...
|
| 62 |
+
def duration_ns(self) -> int: ...
|
| 63 |
+
def is_async(self) -> bool: ...
|
| 64 |
+
def linked_correlation_id(self) -> int: ...
|
| 65 |
+
def shapes(self) -> list[list[int]]: ...
|
| 66 |
+
def dtypes(self) -> list[str]: ...
|
| 67 |
+
def concrete_inputs(self) -> list[Any]: ...
|
| 68 |
+
def kwinputs(self) -> dict[str, Any]: ...
|
| 69 |
+
def device_type(self) -> DeviceType: ...
|
| 70 |
+
def start_thread_id(self) -> int: ...
|
| 71 |
+
def end_thread_id(self) -> int: ...
|
| 72 |
+
def correlation_id(self) -> int: ...
|
| 73 |
+
def fwd_thread_id(self) -> int: ...
|
| 74 |
+
def stack(self) -> list[str]: ...
|
| 75 |
+
def scope(self) -> int: ...
|
| 76 |
+
def sequence_nr(self) -> int: ...
|
| 77 |
+
def flops(self) -> int: ...
|
| 78 |
+
def cuda_elapsed_us(self) -> int: ...
|
| 79 |
+
def privateuse1_elapsed_us(self) -> int: ...
|
| 80 |
+
def is_user_annotation(self) -> bool: ...
|
| 81 |
+
def is_hidden_event(self) -> bool: ...
|
| 82 |
+
def metadata_json(self) -> str: ...
|
| 83 |
+
|
| 84 |
+
class _ProfilerResult:
|
| 85 |
+
def events(self) -> list[_KinetoEvent]: ...
|
| 86 |
+
def legacy_events(self) -> list[list[ProfilerEvent]]: ...
|
| 87 |
+
def save(self, path: str) -> None: ...
|
| 88 |
+
def experimental_event_tree(self) -> list[_ProfilerEvent]: ...
|
| 89 |
+
def trace_start_ns(self) -> int: ...
|
| 90 |
+
|
| 91 |
+
class SavedTensor: ...
|
| 92 |
+
|
| 93 |
+
def _enable_profiler(
|
| 94 |
+
config: ProfilerConfig,
|
| 95 |
+
activities: set[ProfilerActivity],
|
| 96 |
+
) -> None: ...
|
| 97 |
+
def _prepare_profiler(
|
| 98 |
+
config: ProfilerConfig,
|
| 99 |
+
activities: set[ProfilerActivity],
|
| 100 |
+
) -> None: ...
|
| 101 |
+
def _toggle_collection_dynamic(
|
| 102 |
+
enable: bool,
|
| 103 |
+
activities: set[ProfilerActivity],
|
| 104 |
+
) -> None: ...
|
| 105 |
+
def _disable_profiler() -> _ProfilerResult: ...
|
| 106 |
+
def _profiler_enabled() -> bool: ...
|
| 107 |
+
def _add_metadata_json(key: str, value: str) -> None: ...
|
| 108 |
+
def _kineto_step() -> None: ...
|
| 109 |
+
def _get_current_graph_task_keep_graph() -> bool: ...
|
| 110 |
+
def _get_sequence_nr() -> int: ...
|
| 111 |
+
def kineto_available() -> bool: ...
|
| 112 |
+
def _record_function_with_args_enter(name: str, *args) -> torch.Tensor: ...
|
| 113 |
+
def _record_function_with_args_exit(handle: torch.Tensor) -> None: ...
|
| 114 |
+
def _supported_activities() -> set[ProfilerActivity]: ...
|
| 115 |
+
def _enable_record_function(enable: bool) -> None: ...
|
| 116 |
+
def _set_empty_test_observer(is_global: bool, sampling_prob: float) -> None: ...
|
| 117 |
+
def _push_saved_tensors_default_hooks(
|
| 118 |
+
pack_hook: Callable[[torch.Tensor], Any],
|
| 119 |
+
unpack_hook: Callable[[Any], torch.Tensor],
|
| 120 |
+
) -> None: ...
|
| 121 |
+
def _pop_saved_tensors_default_hooks() -> None: ...
|
| 122 |
+
def _top_saved_tensors_default_hooks(
|
| 123 |
+
ignore_is_tracing: bool,
|
| 124 |
+
) -> tuple[Callable[[torch.Tensor], Any], Callable[[Any], torch.Tensor]]: ...
|
| 125 |
+
def _unsafe_set_version_counter(
|
| 126 |
+
t: tuple[torch.Tensor, ...], prev_version: tuple[int, ...]
|
| 127 |
+
) -> None: ...
|
| 128 |
+
def _enable_profiler_legacy(config: ProfilerConfig) -> None: ...
|
| 129 |
+
def _disable_profiler_legacy() -> list[list[ProfilerEvent]]: ...
|
| 130 |
+
def _profiler_type() -> ActiveProfilerType: ...
|
| 131 |
+
def _saved_tensors_hooks_enable() -> None: ...
|
| 132 |
+
def _saved_tensors_hooks_disable(message: str, fail_if_non_empty=True) -> None: ...
|
| 133 |
+
def _saved_tensors_hooks_get_disabled_error_message() -> str | None: ...
|
| 134 |
+
def _saved_tensors_hooks_set_tracing(is_tracing: bool) -> bool: ...
|
| 135 |
+
|
| 136 |
+
class CreationMeta(Enum):
|
| 137 |
+
DEFAULT = ...
|
| 138 |
+
IN_CUSTOM_FUNCTION = ...
|
| 139 |
+
MULTI_OUTPUT_NODE = ...
|
| 140 |
+
NO_GRAD_MODE = ...
|
| 141 |
+
INFERENCE_MODE = ...
|
| 142 |
+
|
| 143 |
+
def _set_creation_meta(t: torch.Tensor, creation_meta: CreationMeta) -> None: ...
|
| 144 |
+
def _get_creation_meta(t: torch.Tensor) -> CreationMeta: ...
|
miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_cpu.pyi
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from torch.types import _bool, _int
|
| 2 |
+
|
| 3 |
+
# Defined in torch/csrc/cpu/Module.cpp
|
| 4 |
+
|
| 5 |
+
def _is_avx2_supported() -> _bool: ...
|
| 6 |
+
def _is_avx512_supported() -> _bool: ...
|
| 7 |
+
def _is_avx512_vnni_supported() -> _bool: ...
|
| 8 |
+
def _is_avx512_bf16_supported() -> _bool: ...
|
| 9 |
+
def _is_amx_tile_supported() -> _bool: ...
|
| 10 |
+
def _is_amx_fp16_supported() -> _bool: ...
|
| 11 |
+
def _init_amx() -> _bool: ...
|
| 12 |
+
def _L1d_cache_size() -> _int: ...
|
| 13 |
+
def _L2_cache_size() -> _int: ...
|
miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_cudnn.pyi
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from enum import IntEnum
|
| 2 |
+
|
| 3 |
+
# Defined in torch/csrc/cuda/shared/cudnn.cpp
|
| 4 |
+
is_cuda: bool
|
| 5 |
+
|
| 6 |
+
def getRuntimeVersion() -> tuple[int, int, int]: ...
|
| 7 |
+
def getCompileVersion() -> tuple[int, int, int]: ...
|
| 8 |
+
def getVersionInt() -> int: ...
|
| 9 |
+
|
| 10 |
+
class RNNMode(IntEnum):
|
| 11 |
+
rnn_relu = ...
|
| 12 |
+
rnn_tanh = ...
|
| 13 |
+
lstm = ...
|
| 14 |
+
gru = ...
|
miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_cusparselt.pyi
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
def getVersionInt() -> int: ...
|
miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_distributed.pyi
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This module is defined in torch/csrc/distributed/python_placement.cpp
|
| 2 |
+
|
| 3 |
+
class Placement:
|
| 4 |
+
def is_partial(self, reduce_op: str | None = None) -> bool: ...
|
| 5 |
+
def is_replicate(self) -> bool: ...
|
| 6 |
+
def is_shard(self, dim: int | None = None) -> bool: ...
|
| 7 |
+
|
| 8 |
+
class Shard(Placement):
|
| 9 |
+
dim: int
|
| 10 |
+
def __init__(self, dim: int): ...
|
| 11 |
+
|
| 12 |
+
class StridedShard(Placement):
|
| 13 |
+
dim: int
|
| 14 |
+
split_factor: int
|
| 15 |
+
def __init__(self, dim: int, *, split_factor: int): ...
|
| 16 |
+
|
| 17 |
+
class Replicate(Placement): ...
|
| 18 |
+
|
| 19 |
+
class Partial(Placement):
|
| 20 |
+
reduce_op: str
|
| 21 |
+
def __init__(self, reduce_op: str | None = None): ...
|
miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_distributed_autograd.pyi
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Any
|
| 2 |
+
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
# This module is defined in torch/csrc/distributed/autograd/init.cpp
|
| 6 |
+
|
| 7 |
+
class DistAutogradContext:
|
| 8 |
+
def _context_id(self) -> int: ...
|
| 9 |
+
def _recv_functions(self) -> dict[int, Any]: ...
|
| 10 |
+
def _send_functions(self) -> dict[int, Any]: ...
|
| 11 |
+
def _known_worker_ids(self) -> set[int]: ...
|
| 12 |
+
|
| 13 |
+
def _new_context() -> DistAutogradContext: ...
|
| 14 |
+
def _release_context(context_id: int) -> None: ...
|
| 15 |
+
def _get_max_id() -> int: ...
|
| 16 |
+
def _is_valid_context(worker_id: int) -> bool: ...
|
| 17 |
+
def _retrieve_context(context_id: int) -> DistAutogradContext: ...
|
| 18 |
+
def _current_context() -> DistAutogradContext: ...
|
| 19 |
+
def _init(worker_id: int) -> None: ...
|
| 20 |
+
def _get_debug_info() -> dict[str, str]: ...
|
| 21 |
+
def backward(
|
| 22 |
+
context_id: int,
|
| 23 |
+
roots: list[torch.Tensor],
|
| 24 |
+
retain_graph: bool = False,
|
| 25 |
+
) -> None: ...
|
| 26 |
+
def get_gradients(context_id: int) -> dict[torch.Tensor, torch.Tensor]: ...
|
miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_distributed_c10d.pyi
ADDED
|
@@ -0,0 +1,889 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# mypy: allow-untyped-defs
|
| 2 |
+
# mypy: disable-error-code="type-arg"
|
| 3 |
+
from collections.abc import Callable
|
| 4 |
+
from datetime import timedelta
|
| 5 |
+
from enum import Enum
|
| 6 |
+
from typing import Any, Optional, overload, Union
|
| 7 |
+
|
| 8 |
+
import torch
|
| 9 |
+
from torch import Tensor
|
| 10 |
+
from torch._C import ScriptObject
|
| 11 |
+
from torch._C._autograd import DeviceType
|
| 12 |
+
from torch.distributed.distributed_c10d import GroupName
|
| 13 |
+
from torch.futures import Future
|
| 14 |
+
|
| 15 |
+
# This module is defined in torch/csrc/distributed/c10d/init.cpp
|
| 16 |
+
|
| 17 |
+
_DEFAULT_FIRST_BUCKET_BYTES: int
|
| 18 |
+
_DEFAULT_NO_TIMEOUT: timedelta
|
| 19 |
+
_DEFAULT_PG_TIMEOUT: timedelta
|
| 20 |
+
_DEFAULT_PG_NCCL_TIMEOUT: timedelta
|
| 21 |
+
|
| 22 |
+
class BuiltinCommHookType(Enum):
|
| 23 |
+
ALLREDUCE = ...
|
| 24 |
+
FP16_COMPRESS = ...
|
| 25 |
+
|
| 26 |
+
def _register_comm_hook(reducer: Reducer, state: Any, comm_hook: Any): ...
|
| 27 |
+
def _register_builtin_comm_hook(
|
| 28 |
+
reducer: Reducer,
|
| 29 |
+
comm_hook_type: BuiltinCommHookType,
|
| 30 |
+
): ...
|
| 31 |
+
def _set_global_rank(rank: int) -> None: ...
|
| 32 |
+
def _hash_tensors(tensors: list[Tensor]) -> int: ...
|
| 33 |
+
|
| 34 |
+
class GradBucket:
|
| 35 |
+
def index(self) -> int: ...
|
| 36 |
+
def buffer(self) -> Tensor: ...
|
| 37 |
+
def gradients(self) -> list[Tensor]: ...
|
| 38 |
+
def is_last(self) -> bool: ...
|
| 39 |
+
def set_buffer(self, tensor: Tensor) -> None: ...
|
| 40 |
+
def parameters(self) -> list[Tensor]: ...
|
| 41 |
+
|
| 42 |
+
class Reducer:
|
| 43 |
+
def __init__(
|
| 44 |
+
self,
|
| 45 |
+
params: list[Tensor],
|
| 46 |
+
bucket_indices: list[list[int]],
|
| 47 |
+
per_bucket_size_limits: list[int],
|
| 48 |
+
process_group: ProcessGroup,
|
| 49 |
+
expect_sparse_gradients: list[bool] = ...,
|
| 50 |
+
bucket_bytes_cap: int = ..., # kDefaultBucketBytesCap in reducer.hpp
|
| 51 |
+
find_unused_parameters: bool = ...,
|
| 52 |
+
gradient_as_bucket_view: bool = ...,
|
| 53 |
+
param_to_name_mapping: dict[int, str] = ...,
|
| 54 |
+
first_bucket_types_cap: int = ..., # kDefaultFirstBucketBytes in reducer.hpp
|
| 55 |
+
skip_all_reduce_unused_params: bool = ...,
|
| 56 |
+
use_python_reducer: bool = ...,
|
| 57 |
+
) -> None: ...
|
| 58 |
+
def prepare_for_forward(self) -> None: ...
|
| 59 |
+
def prepare_for_backward(self, output: list[Tensor]) -> None: ...
|
| 60 |
+
def get_backward_stats(self) -> list[int]: ...
|
| 61 |
+
def _install_post_backward_futures(self, futures: list[Future]) -> None: ...
|
| 62 |
+
def _rebuild_buckets(self) -> bool: ...
|
| 63 |
+
def _get_zeros_like_grad_buckets(self) -> list[GradBucket]: ...
|
| 64 |
+
def _push_all_rebuilt_params(self) -> None: ...
|
| 65 |
+
def _set_forward_pass_work_handle(
|
| 66 |
+
self,
|
| 67 |
+
work: Work,
|
| 68 |
+
use_static_world_size: bool,
|
| 69 |
+
): ...
|
| 70 |
+
def _get_local_used_map(self) -> Tensor: ...
|
| 71 |
+
def _set_ddp_runtime_logging_sample_rate(self, sample_rate: int) -> None: ...
|
| 72 |
+
def _set_static_graph(self) -> None: ...
|
| 73 |
+
def _run_comm_hook(self, bucket: GradBucket) -> Future: ...
|
| 74 |
+
def set_logger(self, logger: Logger) -> None: ...
|
| 75 |
+
def _remove_autograd_hooks(self) -> None: ...
|
| 76 |
+
def _check_reducer_finalized(self) -> None: ...
|
| 77 |
+
def _set_sparse_metadata(self, global_unique_ids: dict[str, Tensor]) -> None: ...
|
| 78 |
+
def _reset_state(self) -> None: ...
|
| 79 |
+
def _update_process_group(self, new_process_group: ProcessGroup) -> None: ...
|
| 80 |
+
|
| 81 |
+
class DDPLoggingData:
|
| 82 |
+
strs_map: dict[str, str]
|
| 83 |
+
ints_map: dict[str, int]
|
| 84 |
+
|
| 85 |
+
class Logger:
|
| 86 |
+
def __init__(self, reducer: Reducer) -> None: ...
|
| 87 |
+
def set_construction_data_and_log(
|
| 88 |
+
self,
|
| 89 |
+
module_name: str,
|
| 90 |
+
device_ids: list[int],
|
| 91 |
+
output_device: int,
|
| 92 |
+
broadcast_buffers: bool,
|
| 93 |
+
has_sync_bn: bool,
|
| 94 |
+
static_graph: bool,
|
| 95 |
+
): ...
|
| 96 |
+
def set_runtime_stats_and_log(self) -> None: ...
|
| 97 |
+
def set_error_and_log(self, error: str) -> None: ...
|
| 98 |
+
def _get_ddp_logging_data(self) -> DDPLoggingData: ...
|
| 99 |
+
def _set_comm_hook_name(self, comm_hook: str) -> None: ...
|
| 100 |
+
def _set_uneven_input_join(self) -> None: ...
|
| 101 |
+
def _set_static_graph(self) -> None: ...
|
| 102 |
+
|
| 103 |
+
class _WorkerServer:
|
| 104 |
+
port: int
|
| 105 |
+
|
| 106 |
+
def __init__(self, host_or_file: str, port: int = ...) -> None: ...
|
| 107 |
+
def shutdown(self) -> None: ...
|
| 108 |
+
|
| 109 |
+
def get_debug_level(): ...
|
| 110 |
+
def set_debug_level(): ...
|
| 111 |
+
def set_debug_level_from_env(): ...
|
| 112 |
+
|
| 113 |
+
class DebugLevel(Enum):
|
| 114 |
+
OFF = ...
|
| 115 |
+
INFO = ...
|
| 116 |
+
DETAIL = ...
|
| 117 |
+
|
| 118 |
+
class ReduceOp:
|
| 119 |
+
# pyrefly: ignore # unknown-name
|
| 120 |
+
def __init__(self, op: RedOpType) -> None: ...
|
| 121 |
+
|
| 122 |
+
# pyrefly: ignore # unknown-name
|
| 123 |
+
SUM: RedOpType = ...
|
| 124 |
+
# pyrefly: ignore # unknown-name
|
| 125 |
+
AVG: RedOpType = ...
|
| 126 |
+
# pyrefly: ignore # unknown-name
|
| 127 |
+
PRODUCT: RedOpType = ...
|
| 128 |
+
# pyrefly: ignore # unknown-name
|
| 129 |
+
MIN: RedOpType = ...
|
| 130 |
+
# pyrefly: ignore # unknown-name
|
| 131 |
+
MAX: RedOpType = ...
|
| 132 |
+
# pyrefly: ignore # unknown-name
|
| 133 |
+
BAND: RedOpType = ...
|
| 134 |
+
# pyrefly: ignore # unknown-name
|
| 135 |
+
BOR: RedOpType = ...
|
| 136 |
+
# pyrefly: ignore # unknown-name
|
| 137 |
+
BXOR: RedOpType = ...
|
| 138 |
+
# pyrefly: ignore # unknown-name
|
| 139 |
+
PREMUL_SUM: RedOpType = ...
|
| 140 |
+
# pyrefly: ignore # unknown-name
|
| 141 |
+
UNUSED: RedOpType = ...
|
| 142 |
+
|
| 143 |
+
# mypy error being ignored:
|
| 144 |
+
# Detected enum "torch._C._distributed_c10d.ReduceOp.RedOpType" in a type
|
| 145 |
+
# stub with zero members. There is a chance this is due to a recent change
|
| 146 |
+
# in the semantics of enum membership. If so, use `member = value` to mark
|
| 147 |
+
# an enum member, instead of `member: type`
|
| 148 |
+
class RedOpType(Enum): ... # type: ignore[misc]
|
| 149 |
+
|
| 150 |
+
class BroadcastOptions:
|
| 151 |
+
rootRank: int
|
| 152 |
+
rootTensor: int
|
| 153 |
+
timeout: timedelta
|
| 154 |
+
asyncOp: bool
|
| 155 |
+
|
| 156 |
+
class AllreduceOptions:
|
| 157 |
+
reduceOp: ReduceOp
|
| 158 |
+
timeout: timedelta
|
| 159 |
+
asyncOp: bool
|
| 160 |
+
sparseIndices: Optional[Tensor]
|
| 161 |
+
|
| 162 |
+
class AllreduceCoalescedOptions(AllreduceOptions): ...
|
| 163 |
+
|
| 164 |
+
class ReduceOptions:
|
| 165 |
+
reduceOp: ReduceOp
|
| 166 |
+
rootRank: int
|
| 167 |
+
rootTensor: int
|
| 168 |
+
timeout: timedelta
|
| 169 |
+
asyncOp: bool
|
| 170 |
+
|
| 171 |
+
class AllgatherOptions:
|
| 172 |
+
timeout: timedelta
|
| 173 |
+
asyncOp: bool
|
| 174 |
+
|
| 175 |
+
class GatherOptions:
|
| 176 |
+
rootRank: int
|
| 177 |
+
timeout: timedelta
|
| 178 |
+
asyncOp: bool
|
| 179 |
+
|
| 180 |
+
class ScatterOptions:
|
| 181 |
+
rootRank: int
|
| 182 |
+
timeout: timedelta
|
| 183 |
+
asyncOp: bool
|
| 184 |
+
|
| 185 |
+
class ReduceScatterOptions:
|
| 186 |
+
reduceOp: ReduceOp
|
| 187 |
+
timeout: timedelta
|
| 188 |
+
asyncOp: bool
|
| 189 |
+
|
| 190 |
+
class BarrierOptions:
|
| 191 |
+
device_ids: list[int]
|
| 192 |
+
device: torch.device
|
| 193 |
+
timeout: timedelta
|
| 194 |
+
asyncOp: bool
|
| 195 |
+
|
| 196 |
+
class AllToAllOptions:
|
| 197 |
+
timeout: timedelta
|
| 198 |
+
asyncOp: bool
|
| 199 |
+
|
| 200 |
+
class Store:
|
| 201 |
+
def set(self, key: str, value: str): ...
|
| 202 |
+
def get(self, key: str) -> bytes: ...
|
| 203 |
+
def add(self, key: str, value: int) -> int: ...
|
| 204 |
+
def check(self, keys: list[str]) -> bool: ...
|
| 205 |
+
def compare_set(
|
| 206 |
+
self,
|
| 207 |
+
key: str,
|
| 208 |
+
expected_value: str,
|
| 209 |
+
desired_value: str,
|
| 210 |
+
) -> bytes: ...
|
| 211 |
+
def delete_key(self, key: str) -> bool: ...
|
| 212 |
+
def multi_get(self, keys: list[str]) -> list[bytes]: ...
|
| 213 |
+
def num_keys(self) -> int: ...
|
| 214 |
+
def set_timeout(self, timeout: timedelta): ...
|
| 215 |
+
@overload
|
| 216 |
+
def wait(self, keys: list[str]): ...
|
| 217 |
+
@overload
|
| 218 |
+
def wait(self, keys: list[str], timeout: timedelta): ...
|
| 219 |
+
def queue_pop(self, key: str, block: bool = True) -> bytes: ...
|
| 220 |
+
def queue_push(self, key: str, value: Union[bytes, str]) -> None: ...
|
| 221 |
+
def queue_len(self, key: str) -> int: ...
|
| 222 |
+
def list_keys(self) -> list[str]: ...
|
| 223 |
+
|
| 224 |
+
class FileStore(Store):
|
| 225 |
+
def __init__(self, path: str, numWorkers: int = ...) -> None: ...
|
| 226 |
+
|
| 227 |
+
class HashStore(Store):
|
| 228 |
+
def __init__(self) -> None: ...
|
| 229 |
+
|
| 230 |
+
class TCPStore(Store):
|
| 231 |
+
def __init__(
|
| 232 |
+
self,
|
| 233 |
+
host_name: str,
|
| 234 |
+
port: int,
|
| 235 |
+
world_size: int | None = ...,
|
| 236 |
+
is_master: bool = ...,
|
| 237 |
+
timeout: timedelta = ...,
|
| 238 |
+
wait_for_workers: bool = ...,
|
| 239 |
+
multi_tenant: bool = ...,
|
| 240 |
+
master_listen_fd: int | None = ...,
|
| 241 |
+
use_libuv: bool | None = ...,
|
| 242 |
+
) -> None: ...
|
| 243 |
+
@property
|
| 244 |
+
def host(self) -> str: ...
|
| 245 |
+
@property
|
| 246 |
+
def port(self) -> int: ...
|
| 247 |
+
|
| 248 |
+
class PrefixStore(Store):
|
| 249 |
+
def __init__(self, prefix: str, store: Store) -> None: ...
|
| 250 |
+
@property
|
| 251 |
+
def underlying_store(self) -> Store: ...
|
| 252 |
+
|
| 253 |
+
class _ControlCollectives:
|
| 254 |
+
def barrier(self, key: str, timeout: timedelta, blocking: bool) -> None: ...
|
| 255 |
+
def broadcast_send(self, key: str, data: str, timeout: timedelta) -> None: ...
|
| 256 |
+
def broadcast_recv(self, key: str, timeout: timedelta) -> str: ...
|
| 257 |
+
def gather_send(self, key: str, data: str, timeout: timedelta) -> None: ...
|
| 258 |
+
def gather_recv(self, key: str, timeout: timedelta) -> str: ...
|
| 259 |
+
def scatter_send(self, key: str, data: str, timeout: timedelta) -> None: ...
|
| 260 |
+
def scatter_recv(self, key: str, timeout: timedelta) -> str: ...
|
| 261 |
+
def all_gather(self, key: str, data: str, timeout: timedelta) -> str: ...
|
| 262 |
+
def all_sum(self, key: str, data: int, timeout: timedelta) -> int: ...
|
| 263 |
+
|
| 264 |
+
class _StoreCollectives(_ControlCollectives):
|
| 265 |
+
def __init__(self, store: Store, rank: int, world_size: int) -> None: ...
|
| 266 |
+
|
| 267 |
+
class _DistributedBackendOptions:
|
| 268 |
+
def __init__(self) -> None: ...
|
| 269 |
+
@property
|
| 270 |
+
def store(self) -> Store: ...
|
| 271 |
+
@store.setter
|
| 272 |
+
def store(self, store: Store) -> None: ...
|
| 273 |
+
@property
|
| 274 |
+
def group_rank(self) -> int: ...
|
| 275 |
+
@group_rank.setter
|
| 276 |
+
def group_rank(self, rank: int) -> None: ...
|
| 277 |
+
@property
|
| 278 |
+
def group_size(self) -> int: ...
|
| 279 |
+
@group_size.setter
|
| 280 |
+
def group_size(self, size: int) -> None: ...
|
| 281 |
+
@property
|
| 282 |
+
def timeout(self) -> timedelta: ...
|
| 283 |
+
@timeout.setter
|
| 284 |
+
def timeout(self, timeout: timedelta) -> None: ...
|
| 285 |
+
@property
|
| 286 |
+
def group_id(self) -> str: ...
|
| 287 |
+
@group_id.setter
|
| 288 |
+
def group_id(self, group_id: str) -> None: ...
|
| 289 |
+
@property
|
| 290 |
+
def global_ranks_in_group(self) -> list[int]: ...
|
| 291 |
+
@global_ranks_in_group.setter
|
| 292 |
+
def global_ranks_in_group(self, ranks: list[int]) -> None: ...
|
| 293 |
+
|
| 294 |
+
class Work:
|
| 295 |
+
def is_completed(self) -> bool: ...
|
| 296 |
+
def is_success(self) -> bool: ...
|
| 297 |
+
def exception(self) -> Any: ...
|
| 298 |
+
def wait(self, timeout: timedelta = ...) -> bool: ...
|
| 299 |
+
def block_current_stream(self) -> None: ...
|
| 300 |
+
def get_future(self) -> Future: ...
|
| 301 |
+
def source_rank(self) -> int: ...
|
| 302 |
+
def _source_rank(self) -> int: ...
|
| 303 |
+
def result(self) -> list[Tensor]: ...
|
| 304 |
+
def synchronize(self) -> None: ...
|
| 305 |
+
def boxed(self) -> ScriptObject: ...
|
| 306 |
+
@staticmethod
|
| 307 |
+
def unbox(obj: ScriptObject) -> Work: ...
|
| 308 |
+
|
| 309 |
+
class Backend:
|
| 310 |
+
class Options:
|
| 311 |
+
def __init__(self, backend: str, timeout: timedelta = ...) -> None: ...
|
| 312 |
+
@property
|
| 313 |
+
def backend(self) -> str: ...
|
| 314 |
+
@property
|
| 315 |
+
def _timeout(self) -> timedelta: ...
|
| 316 |
+
@_timeout.setter
|
| 317 |
+
def _timeout(self, val: timedelta) -> None: ...
|
| 318 |
+
global_ranks_in_group: list[int]
|
| 319 |
+
group_name: GroupName
|
| 320 |
+
|
| 321 |
+
def __init__(
|
| 322 |
+
self,
|
| 323 |
+
rank: int,
|
| 324 |
+
size: int,
|
| 325 |
+
) -> None: ...
|
| 326 |
+
@property
|
| 327 |
+
def supports_splitting(self) -> bool: ...
|
| 328 |
+
@property
|
| 329 |
+
def supports_coalescing(self) -> bool: ...
|
| 330 |
+
@property
|
| 331 |
+
def supports_time_estimate(self) -> bool: ...
|
| 332 |
+
def set_timeout(self, timeout: timedelta) -> None: ...
|
| 333 |
+
@property
|
| 334 |
+
def options(self) -> Options: ...
|
| 335 |
+
def rank(self) -> int: ...
|
| 336 |
+
def size(self) -> int: ...
|
| 337 |
+
def name(self) -> str: ...
|
| 338 |
+
def abort(self) -> None: ...
|
| 339 |
+
def shutdown(self) -> None: ...
|
| 340 |
+
def eager_connect_single_device(self, device: torch.device | None) -> None: ...
|
| 341 |
+
def _set_sequence_number_for_group(self) -> None: ...
|
| 342 |
+
def _set_default_timeout(self, timeout: timedelta) -> None: ...
|
| 343 |
+
def get_error(self) -> ErrorType: ...
|
| 344 |
+
def supports_tensor_alloc(self, device: torch.device) -> bool: ...
|
| 345 |
+
def allocate_tensor(
|
| 346 |
+
self,
|
| 347 |
+
size: int,
|
| 348 |
+
*,
|
| 349 |
+
dtype: torch.dtype,
|
| 350 |
+
device: torch.device,
|
| 351 |
+
) -> Tensor: ...
|
| 352 |
+
@property
|
| 353 |
+
def mem_allocator(self) -> Any: ...
|
| 354 |
+
|
| 355 |
+
class ProcessGroup:
|
| 356 |
+
class BackendType(Enum):
|
| 357 |
+
UNDEFINED = ...
|
| 358 |
+
GLOO = ...
|
| 359 |
+
NCCL = ...
|
| 360 |
+
UCC = ...
|
| 361 |
+
MPI = ...
|
| 362 |
+
XCCL = ...
|
| 363 |
+
CUSTOM = ...
|
| 364 |
+
|
| 365 |
+
def __init__(
|
| 366 |
+
self,
|
| 367 |
+
store: Store,
|
| 368 |
+
rank: int,
|
| 369 |
+
size: int,
|
| 370 |
+
) -> None: ...
|
| 371 |
+
def rank(self) -> int: ...
|
| 372 |
+
def size(self) -> int: ...
|
| 373 |
+
def get_group_store(self) -> Store: ...
|
| 374 |
+
def split_group(
|
| 375 |
+
self,
|
| 376 |
+
new_ranks: list[int],
|
| 377 |
+
timeout: Optional[timedelta] = None,
|
| 378 |
+
opts: Optional[Backend.Options] = None,
|
| 379 |
+
group_name: GroupName | None = None,
|
| 380 |
+
group_desc: Optional[str] = None,
|
| 381 |
+
) -> Optional[ProcessGroup]: ...
|
| 382 |
+
def merge_remote_group(
|
| 383 |
+
self,
|
| 384 |
+
store: Store,
|
| 385 |
+
size: int,
|
| 386 |
+
timeout: timedelta,
|
| 387 |
+
group_name: GroupName | None = None,
|
| 388 |
+
group_desc: Optional[str] = None,
|
| 389 |
+
) -> ProcessGroup: ...
|
| 390 |
+
def abort(self) -> None: ...
|
| 391 |
+
def set_timeout(self, timeout: timedelta) -> None: ...
|
| 392 |
+
def shutdown(self) -> None: ...
|
| 393 |
+
@overload
|
| 394 |
+
def broadcast(
|
| 395 |
+
self,
|
| 396 |
+
tensors: list[Tensor],
|
| 397 |
+
opts=...,
|
| 398 |
+
) -> Work: ...
|
| 399 |
+
@overload
|
| 400 |
+
def broadcast(
|
| 401 |
+
self,
|
| 402 |
+
tensor: Tensor,
|
| 403 |
+
root: int,
|
| 404 |
+
timeout: timedelta | None = None,
|
| 405 |
+
) -> Work: ...
|
| 406 |
+
@overload
|
| 407 |
+
def allreduce(
|
| 408 |
+
self,
|
| 409 |
+
tensors: list[Tensor],
|
| 410 |
+
opts: AllreduceOptions = ...,
|
| 411 |
+
) -> Work: ...
|
| 412 |
+
@overload
|
| 413 |
+
def allreduce(
|
| 414 |
+
self,
|
| 415 |
+
tensors: list[Tensor],
|
| 416 |
+
op=...,
|
| 417 |
+
timeout: timedelta | None = None,
|
| 418 |
+
) -> Work: ...
|
| 419 |
+
@overload
|
| 420 |
+
def allreduce(
|
| 421 |
+
self,
|
| 422 |
+
tensor: Tensor,
|
| 423 |
+
op=...,
|
| 424 |
+
timeout: timedelta | None = None,
|
| 425 |
+
) -> Work: ...
|
| 426 |
+
def allreduce_coalesced(
|
| 427 |
+
self,
|
| 428 |
+
tensors: list[Tensor],
|
| 429 |
+
opts=...,
|
| 430 |
+
) -> Work: ...
|
| 431 |
+
def reduce_scatter_tensor_coalesced(
|
| 432 |
+
self,
|
| 433 |
+
outputTensors: list[Tensor],
|
| 434 |
+
inputTensors: list[Tensor],
|
| 435 |
+
opts: ReduceScatterOptions | None = None,
|
| 436 |
+
) -> Work: ...
|
| 437 |
+
@overload
|
| 438 |
+
def reduce(
|
| 439 |
+
self,
|
| 440 |
+
tensors: list[Tensor],
|
| 441 |
+
opts=...,
|
| 442 |
+
) -> Work: ...
|
| 443 |
+
@overload
|
| 444 |
+
def reduce(
|
| 445 |
+
self,
|
| 446 |
+
tensor: Tensor,
|
| 447 |
+
root: int,
|
| 448 |
+
op=...,
|
| 449 |
+
timeout: timedelta | None = None,
|
| 450 |
+
) -> Work: ...
|
| 451 |
+
@overload
|
| 452 |
+
def allgather(
|
| 453 |
+
self,
|
| 454 |
+
output_tensors: list[list[Tensor]],
|
| 455 |
+
input_tensors: list[Tensor],
|
| 456 |
+
opts=...,
|
| 457 |
+
) -> Work: ...
|
| 458 |
+
@overload
|
| 459 |
+
def allgather(
|
| 460 |
+
self,
|
| 461 |
+
output_tensors: list[Tensor],
|
| 462 |
+
input_tensor: Tensor,
|
| 463 |
+
timeout: timedelta | None = None,
|
| 464 |
+
) -> Work: ...
|
| 465 |
+
def _allgather_base(
|
| 466 |
+
self,
|
| 467 |
+
output: Tensor,
|
| 468 |
+
input: Tensor,
|
| 469 |
+
opts=...,
|
| 470 |
+
) -> Work: ...
|
| 471 |
+
def allgather_coalesced(
|
| 472 |
+
self,
|
| 473 |
+
output_lists: list[list[Tensor]],
|
| 474 |
+
input_list: list[Tensor],
|
| 475 |
+
opts=...,
|
| 476 |
+
) -> Work: ...
|
| 477 |
+
def allgather_into_tensor_coalesced(
|
| 478 |
+
self,
|
| 479 |
+
output_lists: list[Tensor],
|
| 480 |
+
input_list: list[Tensor],
|
| 481 |
+
opts=...,
|
| 482 |
+
) -> Work: ...
|
| 483 |
+
@overload
|
| 484 |
+
def gather(
|
| 485 |
+
self,
|
| 486 |
+
output_tensors: list[list[Tensor]],
|
| 487 |
+
input_tensors: list[Tensor],
|
| 488 |
+
opts=...,
|
| 489 |
+
) -> Work: ...
|
| 490 |
+
@overload
|
| 491 |
+
def gather(
|
| 492 |
+
self,
|
| 493 |
+
output_tensors: list[Tensor],
|
| 494 |
+
input_tensor: Tensor,
|
| 495 |
+
root: int,
|
| 496 |
+
timeout: timedelta | None = None,
|
| 497 |
+
) -> Work: ...
|
| 498 |
+
@overload
|
| 499 |
+
def scatter(
|
| 500 |
+
self,
|
| 501 |
+
output_tensors: list[Tensor],
|
| 502 |
+
input_tensors: list[list[Tensor]],
|
| 503 |
+
opts=...,
|
| 504 |
+
) -> Work: ...
|
| 505 |
+
@overload
|
| 506 |
+
def scatter(
|
| 507 |
+
self,
|
| 508 |
+
output_tensor: Tensor,
|
| 509 |
+
input_tensors: list[Tensor],
|
| 510 |
+
root: int,
|
| 511 |
+
timeout: timedelta | None = None,
|
| 512 |
+
) -> Work: ...
|
| 513 |
+
@overload
|
| 514 |
+
def reduce_scatter(
|
| 515 |
+
self,
|
| 516 |
+
output_tensors: list[Tensor],
|
| 517 |
+
input_tensors: list[list[Tensor]],
|
| 518 |
+
opts=...,
|
| 519 |
+
) -> Work: ...
|
| 520 |
+
@overload
|
| 521 |
+
def reduce_scatter(
|
| 522 |
+
self,
|
| 523 |
+
output_tensors: Tensor,
|
| 524 |
+
input_tensor: list[Tensor],
|
| 525 |
+
op=...,
|
| 526 |
+
timeout: timedelta | None = None,
|
| 527 |
+
) -> Work: ...
|
| 528 |
+
def _reduce_scatter_base(
|
| 529 |
+
self,
|
| 530 |
+
outputTensor: Tensor,
|
| 531 |
+
inputTensor: Tensor,
|
| 532 |
+
opts: ReduceScatterOptions | None,
|
| 533 |
+
) -> Work: ...
|
| 534 |
+
@overload
|
| 535 |
+
def alltoall_base(
|
| 536 |
+
self,
|
| 537 |
+
output_tensor: Tensor,
|
| 538 |
+
input_tensor: Tensor,
|
| 539 |
+
output_split_sizes: list[int],
|
| 540 |
+
input_split_sizes: list[int],
|
| 541 |
+
opts=...,
|
| 542 |
+
) -> Work: ...
|
| 543 |
+
@overload
|
| 544 |
+
def alltoall_base(
|
| 545 |
+
self,
|
| 546 |
+
output: Tensor,
|
| 547 |
+
input: Tensor,
|
| 548 |
+
output_split_sizes: list[int],
|
| 549 |
+
input_split_sizes: list[int],
|
| 550 |
+
timeout: timedelta | None = None,
|
| 551 |
+
) -> Work: ...
|
| 552 |
+
@overload
|
| 553 |
+
def alltoall(
|
| 554 |
+
self,
|
| 555 |
+
output_tensor: list[Tensor],
|
| 556 |
+
input_tensor: list[Tensor],
|
| 557 |
+
opts=...,
|
| 558 |
+
) -> Work: ...
|
| 559 |
+
@overload
|
| 560 |
+
def alltoall(
|
| 561 |
+
self,
|
| 562 |
+
output: list[Tensor],
|
| 563 |
+
input: list[Tensor],
|
| 564 |
+
timeout: timedelta | None = None,
|
| 565 |
+
) -> Work: ...
|
| 566 |
+
def send(
|
| 567 |
+
self,
|
| 568 |
+
tensors: list[Tensor],
|
| 569 |
+
dstRank: int,
|
| 570 |
+
tag: int,
|
| 571 |
+
) -> Work: ...
|
| 572 |
+
def recv(
|
| 573 |
+
self,
|
| 574 |
+
tensors: list[Tensor],
|
| 575 |
+
srcRank: int,
|
| 576 |
+
tag: int,
|
| 577 |
+
) -> Work: ...
|
| 578 |
+
def recv_anysource(self, tensors: list[Tensor], tag: int) -> Work: ...
|
| 579 |
+
@overload
|
| 580 |
+
def barrier(self, opts=...) -> Work: ...
|
| 581 |
+
@overload
|
| 582 |
+
def barrier(self, timeout: timedelta | None = None) -> Work: ...
|
| 583 |
+
def boxed(self) -> ScriptObject: ...
|
| 584 |
+
@staticmethod
|
| 585 |
+
def unbox(obj: ScriptObject) -> ProcessGroup: ...
|
| 586 |
+
def _start_coalescing(self, device: torch.device) -> None: ...
|
| 587 |
+
def _end_coalescing(self, device: torch.device) -> Work: ...
|
| 588 |
+
def _get_backend_name(self) -> str: ...
|
| 589 |
+
def _backend_id(self, backend_type: BackendType) -> int: ...
|
| 590 |
+
@property
|
| 591 |
+
def _device_types(self) -> list[torch.device]: ...
|
| 592 |
+
def _get_backend(self, device: torch.device) -> Backend: ...
|
| 593 |
+
def _set_default_backend(self, backend_type: BackendType) -> None: ...
|
| 594 |
+
def _register_backend(
|
| 595 |
+
self,
|
| 596 |
+
device: torch.device,
|
| 597 |
+
backend_type: BackendType,
|
| 598 |
+
backend: Backend | None,
|
| 599 |
+
) -> None: ...
|
| 600 |
+
def _set_group_name(self, name: GroupName) -> None: ...
|
| 601 |
+
def _set_group_desc(self, desc: str) -> None: ...
|
| 602 |
+
def name(self) -> str: ...
|
| 603 |
+
def _has_hooks(self) -> bool: ...
|
| 604 |
+
def _wait_for_pending_works(self) -> None: ...
|
| 605 |
+
def _set_sequence_number_for_group(self) -> None: ...
|
| 606 |
+
@property
|
| 607 |
+
def bound_device_id(self) -> torch.device | None: ...
|
| 608 |
+
@bound_device_id.setter
|
| 609 |
+
def bound_device_id(self, device: torch.device | None) -> None: ...
|
| 610 |
+
@property
|
| 611 |
+
def group_name(self) -> GroupName: ...
|
| 612 |
+
@property
|
| 613 |
+
def group_desc(self) -> str: ...
|
| 614 |
+
|
| 615 |
+
class FakeProcessGroup(Backend):
|
| 616 |
+
@staticmethod
|
| 617 |
+
def _create_internal(rank: int, world_size: int) -> FakeProcessGroup: ...
|
| 618 |
+
|
| 619 |
+
class FakeWork(Work):
|
| 620 |
+
seq_id: int
|
| 621 |
+
def __init__(self) -> None: ...
|
| 622 |
+
def wait(self, timeout: timedelta = ...) -> bool: ...
|
| 623 |
+
def getFuture(self) -> Future: ...
|
| 624 |
+
|
| 625 |
+
class PythonCallbackWork(Work):
|
| 626 |
+
def __init__(self, callback: Callable[[timedelta], bool]) -> None: ...
|
| 627 |
+
def wait(self, timeout: timedelta = ...) -> bool: ...
|
| 628 |
+
def get_future(self) -> Future: ...
|
| 629 |
+
|
| 630 |
+
class ProcessGroupGloo(Backend):
|
| 631 |
+
class Device: ...
|
| 632 |
+
|
| 633 |
+
class Options(Backend.Options):
|
| 634 |
+
devices: list[ProcessGroupGloo.Device]
|
| 635 |
+
threads: int
|
| 636 |
+
|
| 637 |
+
def __init__(self): ...
|
| 638 |
+
|
| 639 |
+
def __init__(
|
| 640 |
+
self,
|
| 641 |
+
store: Store,
|
| 642 |
+
rank: int,
|
| 643 |
+
size: int,
|
| 644 |
+
timeout: timedelta,
|
| 645 |
+
) -> None: ...
|
| 646 |
+
@staticmethod
|
| 647 |
+
def create_device(hostname="", interface="", lazy_init=None) -> Device: ...
|
| 648 |
+
@staticmethod
|
| 649 |
+
def create_default_device(lazy_init=None) -> Device: ...
|
| 650 |
+
def _set_default_timeout(self, timeout) -> None: ...
|
| 651 |
+
@property
|
| 652 |
+
def options(self) -> Options: ... # type: ignore[override]
|
| 653 |
+
|
| 654 |
+
class _ProcessGroupWrapper(Backend):
|
| 655 |
+
def __init__(self, pg: Backend, gloo_pg: ProcessGroupGloo) -> None: ...
|
| 656 |
+
wrapped_pg: Backend
|
| 657 |
+
|
| 658 |
+
class ErrorType(Enum):
|
| 659 |
+
SUCCESS = ...
|
| 660 |
+
TIMEOUT = ...
|
| 661 |
+
COMM_ERROR = ...
|
| 662 |
+
REMOTE_ERROR = ...
|
| 663 |
+
|
| 664 |
+
class ProcessGroupNCCL(Backend):
|
| 665 |
+
class NCCLConfig:
|
| 666 |
+
blocking: int
|
| 667 |
+
cga_cluster_size: int
|
| 668 |
+
min_ctas: int
|
| 669 |
+
max_ctas: int
|
| 670 |
+
def unsafe_get_ptr(self) -> int: ...
|
| 671 |
+
|
| 672 |
+
class Options(Backend.Options):
|
| 673 |
+
config: ProcessGroupNCCL.NCCLConfig
|
| 674 |
+
is_high_priority_stream: bool
|
| 675 |
+
split_from: ProcessGroupNCCL
|
| 676 |
+
split_color: int
|
| 677 |
+
|
| 678 |
+
def __init__(self, is_high_priority_stream: bool = False): ...
|
| 679 |
+
|
| 680 |
+
def __init__(
|
| 681 |
+
self,
|
| 682 |
+
store: Store,
|
| 683 |
+
rank: int,
|
| 684 |
+
size: int,
|
| 685 |
+
options: Options,
|
| 686 |
+
) -> None: ...
|
| 687 |
+
def _group_start(self) -> None: ...
|
| 688 |
+
def _group_end(self) -> None: ...
|
| 689 |
+
def _start_time_estimate(self) -> None: ...
|
| 690 |
+
def _end_time_estimate(self) -> float: ...
|
| 691 |
+
def _set_default_timeout(self, timeout) -> None: ...
|
| 692 |
+
def perform_nocolor_split(self, device: torch.device) -> None: ...
|
| 693 |
+
def register_mem_pool(self, pool: torch.cuda.MemPool) -> None: ...
|
| 694 |
+
def deregister_mem_pool(self, pool: torch.cuda.MemPool) -> None: ...
|
| 695 |
+
def comm_split_count(self) -> int: ...
|
| 696 |
+
def _add_ephemeral_timeout(self, timeout: timedelta) -> None: ...
|
| 697 |
+
def abort(self) -> None: ...
|
| 698 |
+
def _is_initialized(self) -> bool: ...
|
| 699 |
+
@property
|
| 700 |
+
def uid(self) -> int: ...
|
| 701 |
+
@property
|
| 702 |
+
def options(self) -> Options: ... # type: ignore[override]
|
| 703 |
+
@staticmethod
|
| 704 |
+
def get_build_nccl_version(self) -> tuple[int, int, int]: ...
|
| 705 |
+
@staticmethod
|
| 706 |
+
def get_runtime_nccl_version(self) -> tuple[int, int, int]: ...
|
| 707 |
+
|
| 708 |
+
class ProcessGroupUCC(Backend):
|
| 709 |
+
def __init__(
|
| 710 |
+
self,
|
| 711 |
+
store: Store,
|
| 712 |
+
rank: int,
|
| 713 |
+
size: int,
|
| 714 |
+
timeout: timedelta,
|
| 715 |
+
) -> None: ...
|
| 716 |
+
|
| 717 |
+
class ProcessGroupMPI(Backend):
|
| 718 |
+
def __init__(
|
| 719 |
+
self,
|
| 720 |
+
rank: int,
|
| 721 |
+
size: int,
|
| 722 |
+
pgComm: int,
|
| 723 |
+
) -> None: ...
|
| 724 |
+
@staticmethod
|
| 725 |
+
def create(ranks: list[int]) -> ProcessGroupMPI: ...
|
| 726 |
+
|
| 727 |
+
def _compute_bucket_assignment_by_size(
|
| 728 |
+
tensors: list[Tensor],
|
| 729 |
+
bucket_size_limits: list[int],
|
| 730 |
+
expect_sparse_gradient: list[bool] = ...,
|
| 731 |
+
tensor_indices: list[int] = ...,
|
| 732 |
+
) -> tuple[list[list[int]], list[int]]: ...
|
| 733 |
+
def _broadcast_coalesced(
|
| 734 |
+
process_group: ProcessGroup,
|
| 735 |
+
tensors: list[Tensor],
|
| 736 |
+
buffer_size: int,
|
| 737 |
+
src: int,
|
| 738 |
+
): ...
|
| 739 |
+
def _test_python_store(store: Store): ...
|
| 740 |
+
def _verify_params_across_processes(
|
| 741 |
+
process_group: ProcessGroup,
|
| 742 |
+
params: list[Tensor],
|
| 743 |
+
logger: Logger | None,
|
| 744 |
+
): ...
|
| 745 |
+
def _make_nccl_premul_sum(factor: float | list[Tensor]) -> ReduceOp: ...
|
| 746 |
+
def _register_process_group(
|
| 747 |
+
group_name: GroupName,
|
| 748 |
+
process_group: ProcessGroup,
|
| 749 |
+
) -> None: ...
|
| 750 |
+
def _resolve_process_group(group_name: GroupName) -> ProcessGroup: ...
|
| 751 |
+
def _register_work(tensor: torch.Tensor, work: Work) -> ProcessGroup: ...
|
| 752 |
+
def _get_work_registry_size() -> int: ...
|
| 753 |
+
def _set_allow_inflight_collective_as_graph_input(
|
| 754 |
+
value: bool,
|
| 755 |
+
) -> None: ...
|
| 756 |
+
def _allow_inflight_collective_as_graph_input() -> bool: ...
|
| 757 |
+
def _unregister_all_process_groups() -> None: ...
|
| 758 |
+
def _unregister_process_group(group_name: GroupName) -> None: ...
|
| 759 |
+
|
| 760 |
+
# Initializes the device state in CUmodule so that it's able to perform NVSHMEM
|
| 761 |
+
# operations. CUmodule is a pointer to a CUDA module, carried by a int64 in
|
| 762 |
+
# Python. At C++ interface, it is converted to a uintptr_t.
|
| 763 |
+
def _nvshmemx_cumodule_init(module: int) -> None: ...
|
| 764 |
+
|
| 765 |
+
# Check if NVSHMEM is available on current system.
|
| 766 |
+
def _is_nvshmem_available() -> bool: ...
|
| 767 |
+
|
| 768 |
+
class _SymmetricMemory:
|
| 769 |
+
@staticmethod
|
| 770 |
+
def set_group_info(
|
| 771 |
+
group_name: str,
|
| 772 |
+
rank: int,
|
| 773 |
+
world_size: int,
|
| 774 |
+
store: Store,
|
| 775 |
+
) -> None: ...
|
| 776 |
+
@staticmethod
|
| 777 |
+
def empty_strided_p2p(
|
| 778 |
+
size: torch.types._size,
|
| 779 |
+
stride: torch.types._size,
|
| 780 |
+
dtype: torch.dtype,
|
| 781 |
+
device: torch.device,
|
| 782 |
+
group_name: str | None = None,
|
| 783 |
+
alloc_id: int | None = None,
|
| 784 |
+
) -> torch.Tensor: ...
|
| 785 |
+
@staticmethod
|
| 786 |
+
def has_multicast_support(
|
| 787 |
+
device_type: DeviceType,
|
| 788 |
+
device_idx: int,
|
| 789 |
+
) -> bool: ...
|
| 790 |
+
# Set Symmetric Memory allocation backend.
|
| 791 |
+
@staticmethod
|
| 792 |
+
def set_backend(name: str) -> None: ...
|
| 793 |
+
@staticmethod
|
| 794 |
+
def get_backend(device: torch.device) -> Optional[str]: ...
|
| 795 |
+
@staticmethod
|
| 796 |
+
def get_mempool_allocator(device: torch.device) -> Any: ...
|
| 797 |
+
signal_pad_size: int
|
| 798 |
+
@property
|
| 799 |
+
def rank(self) -> int: ...
|
| 800 |
+
@property
|
| 801 |
+
def world_size(self) -> int: ...
|
| 802 |
+
@staticmethod
|
| 803 |
+
def rendezvous(
|
| 804 |
+
tensor: torch.Tensor, group_name: str | None = None
|
| 805 |
+
) -> _SymmetricMemory: ...
|
| 806 |
+
def get_buffer(
|
| 807 |
+
self,
|
| 808 |
+
rank: int,
|
| 809 |
+
sizes: torch.types._size,
|
| 810 |
+
dtype: torch.dtype,
|
| 811 |
+
storage_offset: int | None = 0,
|
| 812 |
+
) -> torch.Tensor: ...
|
| 813 |
+
def get_signal_pad(
|
| 814 |
+
self,
|
| 815 |
+
rank: int,
|
| 816 |
+
sizes: torch.types._size = [],
|
| 817 |
+
dtype: torch.dtype | None = None,
|
| 818 |
+
storage_offset: int | None = 0,
|
| 819 |
+
) -> torch.Tensor: ...
|
| 820 |
+
def barrier(self, channel: int = 0, timeout_ms: int = 0) -> None: ...
|
| 821 |
+
def put_signal(
|
| 822 |
+
self,
|
| 823 |
+
dst_rank: int,
|
| 824 |
+
channel: int = 0,
|
| 825 |
+
timeout_ms: int = 0,
|
| 826 |
+
) -> None: ...
|
| 827 |
+
def wait_signal(
|
| 828 |
+
self,
|
| 829 |
+
src_rank: int,
|
| 830 |
+
channel: int = 0,
|
| 831 |
+
timeout_ms: int = 0,
|
| 832 |
+
) -> None: ...
|
| 833 |
+
def get_remote_tensor(
|
| 834 |
+
self,
|
| 835 |
+
peer: int,
|
| 836 |
+
sizes: torch.types._size,
|
| 837 |
+
dtype: torch.dtype,
|
| 838 |
+
) -> torch.Tensor: ...
|
| 839 |
+
@staticmethod
|
| 840 |
+
def memset32(
|
| 841 |
+
tensor: torch.Tensor, offset: int, val: int, count: int = 1
|
| 842 |
+
) -> torch.Tensor: ...
|
| 843 |
+
@staticmethod
|
| 844 |
+
def stream_write_value32(
|
| 845 |
+
tensor: torch.Tensor, offset: int, val: int
|
| 846 |
+
) -> torch.Tensor: ...
|
| 847 |
+
@property
|
| 848 |
+
def buffer_ptrs(self) -> list[int]: ...
|
| 849 |
+
@property
|
| 850 |
+
def buffer_ptrs_dev(self) -> int: ...
|
| 851 |
+
@property
|
| 852 |
+
def signal_pad_ptrs(self) -> list[int]: ...
|
| 853 |
+
@property
|
| 854 |
+
def signal_pad_ptrs_dev(self) -> int: ...
|
| 855 |
+
@property
|
| 856 |
+
def multicast_ptr(self) -> int: ...
|
| 857 |
+
@property
|
| 858 |
+
def buffer_size(self) -> int: ...
|
| 859 |
+
|
| 860 |
+
class ProcessGroupXCCL(Backend):
|
| 861 |
+
class Options(Backend.Options):
|
| 862 |
+
is_high_priority_stream: bool
|
| 863 |
+
|
| 864 |
+
def __init__(self, is_high_priority_stream: bool = False): ...
|
| 865 |
+
|
| 866 |
+
def __init__(
|
| 867 |
+
self,
|
| 868 |
+
store: Store,
|
| 869 |
+
rank: int,
|
| 870 |
+
size: int,
|
| 871 |
+
options: Options,
|
| 872 |
+
) -> None: ...
|
| 873 |
+
@property
|
| 874 |
+
def options(self) -> Options: ... # type: ignore[override]
|
| 875 |
+
|
| 876 |
+
def _set_process_group(pg: ProcessGroup) -> None: ...
|
| 877 |
+
def _current_process_group() -> ProcessGroup: ...
|
| 878 |
+
|
| 879 |
+
class _Request:
|
| 880 |
+
def body(self) -> bytes: ...
|
| 881 |
+
def get_param(self, str) -> str: ...
|
| 882 |
+
|
| 883 |
+
class _Response:
|
| 884 |
+
def set_content(self, content: str | bytes, content_type: str) -> None: ...
|
| 885 |
+
def set_status(self, status: int) -> None: ...
|
| 886 |
+
|
| 887 |
+
def _register_handler(
|
| 888 |
+
name: str, handler: Callable[[_Request, _Response], None]
|
| 889 |
+
) -> None: ...
|
miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_distributed_rpc.pyi
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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ic, overload, TypeVar
|
| 5 |
+
|
| 6 |
+
import torch
|
| 7 |
+
from torch._C import Future
|
| 8 |
+
from torch._C._autograd import ProfilerEvent
|
| 9 |
+
from torch._C._distributed_c10d import Store
|
| 10 |
+
from torch._C._profiler import ProfilerConfig
|
| 11 |
+
|
| 12 |
+
# This module is defined in torch/csrc/distributed/rpc/init.cpp
|
| 13 |
+
|
| 14 |
+
_DEFAULT_INIT_METHOD: str
|
| 15 |
+
_DEFAULT_NUM_WORKER_THREADS: int
|
| 16 |
+
_UNSET_RPC_TIMEOUT: float
|
| 17 |
+
_DEFAULT_RPC_TIMEOUT_SEC: float
|
| 18 |
+
|
| 19 |
+
_T = TypeVar("_T")
|
| 20 |
+
|
| 21 |
+
class RpcBackendOptions:
|
| 22 |
+
rpc_timeout: float
|
| 23 |
+
init_method: str
|
| 24 |
+
def __init__(
|
| 25 |
+
self,
|
| 26 |
+
rpc_timeout: float = ...,
|
| 27 |
+
init_method: str = ...,
|
| 28 |
+
) -> None: ...
|
| 29 |
+
|
| 30 |
+
class WorkerInfo:
|
| 31 |
+
def __init__(self, name: str, worker_id: int) -> None: ...
|
| 32 |
+
@property
|
| 33 |
+
def name(self) -> str: ...
|
| 34 |
+
@property
|
| 35 |
+
def id(self) -> int: ...
|
| 36 |
+
def __eq__(self, other: object) -> bool: ...
|
| 37 |
+
|
| 38 |
+
class RpcAgent:
|
| 39 |
+
def join(self, shutdown: bool = False, timeout: float = 0): ...
|
| 40 |
+
def sync(self): ...
|
| 41 |
+
def shutdown(self): ...
|
| 42 |
+
@overload
|
| 43 |
+
def get_worker_info(self) -> WorkerInfo: ...
|
| 44 |
+
@overload
|
| 45 |
+
def get_worker_info(self, workerName: str) -> WorkerInfo: ...
|
| 46 |
+
def get_worker_infos(self) -> list[WorkerInfo]: ...
|
| 47 |
+
def _get_device_map(self, dst: WorkerInfo) -> dict[torch.device, torch.device]: ...
|
| 48 |
+
def get_debug_info(self) -> dict[str, str]: ...
|
| 49 |
+
def get_metrics(self) -> dict[str, str]: ...
|
| 50 |
+
|
| 51 |
+
class PyRRef(Generic[_T]):
|
| 52 |
+
def __init__(self, value: _T, type_hint: Any = None) -> None: ...
|
| 53 |
+
def is_owner(self) -> bool: ...
|
| 54 |
+
def confirmed_by_owner(self) -> bool: ...
|
| 55 |
+
def owner(self) -> WorkerInfo: ...
|
| 56 |
+
def owner_name(self) -> str: ...
|
| 57 |
+
def to_here(self, timeout: float = ...) -> _T: ...
|
| 58 |
+
def local_value(self) -> Any: ...
|
| 59 |
+
def rpc_sync(self, timeout: float = ...) -> Any: ...
|
| 60 |
+
def rpc_async(self, timeout: float = ...) -> Any: ...
|
| 61 |
+
def remote(self, timeout: float = ...) -> Any: ...
|
| 62 |
+
def _serialize(self) -> tuple: ...
|
| 63 |
+
@staticmethod
|
| 64 |
+
def _deserialize(tp: tuple) -> PyRRef: ...
|
| 65 |
+
def _get_type(self) -> type[_T]: ...
|
| 66 |
+
def _get_future(self) -> Future[_T]: ...
|
| 67 |
+
def _get_profiling_future(self) -> Future[_T]: ...
|
| 68 |
+
def _set_profiling_future(self, profilingFuture: Future[_T]): ...
|
| 69 |
+
|
| 70 |
+
class _TensorPipeRpcBackendOptionsBase(RpcBackendOptions):
|
| 71 |
+
num_worker_threads: int
|
| 72 |
+
device_maps: dict[str, dict[torch.device, torch.device]]
|
| 73 |
+
devices: list[torch.device]
|
| 74 |
+
def __init__(
|
| 75 |
+
self,
|
| 76 |
+
num_worker_threads: int,
|
| 77 |
+
_transports: list | None,
|
| 78 |
+
_channels: list | None,
|
| 79 |
+
rpc_timeout: float = ...,
|
| 80 |
+
init_method: str = ...,
|
| 81 |
+
device_maps: dict[str, dict[torch.device, torch.device]] = {}, # noqa: B006
|
| 82 |
+
devices: list[torch.device] = [], # noqa: B006
|
| 83 |
+
) -> None: ...
|
| 84 |
+
def _set_device_map(
|
| 85 |
+
self,
|
| 86 |
+
to: str,
|
| 87 |
+
device_map: dict[torch.device, torch.device],
|
| 88 |
+
): ...
|
| 89 |
+
|
| 90 |
+
class TensorPipeAgent(RpcAgent):
|
| 91 |
+
def __init__(
|
| 92 |
+
self,
|
| 93 |
+
store: Store,
|
| 94 |
+
name: str,
|
| 95 |
+
worker_id: int,
|
| 96 |
+
world_size: int | None,
|
| 97 |
+
opts: _TensorPipeRpcBackendOptionsBase,
|
| 98 |
+
reverse_device_maps: dict[str, dict[torch.device, torch.device]],
|
| 99 |
+
devices: list[torch.device],
|
| 100 |
+
) -> None: ...
|
| 101 |
+
def join(self, shutdown: bool = False, timeout: float = 0): ...
|
| 102 |
+
def shutdown(self): ...
|
| 103 |
+
@overload
|
| 104 |
+
def get_worker_info(self) -> WorkerInfo: ...
|
| 105 |
+
@overload
|
| 106 |
+
def get_worker_info(self, workerName: str) -> WorkerInfo: ...
|
| 107 |
+
@overload
|
| 108 |
+
def get_worker_info(self, id: int) -> WorkerInfo: ...
|
| 109 |
+
def get_worker_infos(self) -> list[WorkerInfo]: ...
|
| 110 |
+
def _get_device_map(self, dst: WorkerInfo) -> dict[torch.device, torch.device]: ...
|
| 111 |
+
def _update_group_membership(
|
| 112 |
+
self,
|
| 113 |
+
worker_info: WorkerInfo,
|
| 114 |
+
my_devices: list[torch.device],
|
| 115 |
+
reverse_device_map: dict[str, dict[torch.device, torch.device]],
|
| 116 |
+
is_join: bool,
|
| 117 |
+
): ...
|
| 118 |
+
def _get_backend_options(self) -> _TensorPipeRpcBackendOptionsBase: ...
|
| 119 |
+
@property
|
| 120 |
+
def is_static_group(self) -> bool: ...
|
| 121 |
+
@property
|
| 122 |
+
def store(self) -> Store: ...
|
| 123 |
+
|
| 124 |
+
def _is_current_rpc_agent_set() -> bool: ...
|
| 125 |
+
def _get_current_rpc_agent() -> RpcAgent: ...
|
| 126 |
+
def _set_and_start_rpc_agent(agent: RpcAgent): ...
|
| 127 |
+
def _reset_current_rpc_agent(): ...
|
| 128 |
+
def _delete_all_user_and_unforked_owner_rrefs(timeout: timedelta = ...): ...
|
| 129 |
+
def _destroy_rref_context(ignoreRRefLeak: bool): ...
|
| 130 |
+
def _rref_context_get_debug_info() -> dict[str, str]: ...
|
| 131 |
+
def _cleanup_python_rpc_handler(): ...
|
| 132 |
+
def _invoke_rpc_builtin(
|
| 133 |
+
dst: WorkerInfo,
|
| 134 |
+
opName: str,
|
| 135 |
+
rpcTimeoutSeconds: float,
|
| 136 |
+
*args: Any,
|
| 137 |
+
**kwargs: Any,
|
| 138 |
+
): ...
|
| 139 |
+
def _invoke_rpc_python_udf(
|
| 140 |
+
dst: WorkerInfo,
|
| 141 |
+
pickledPythonUDF: str,
|
| 142 |
+
tensors: list[torch.Tensor],
|
| 143 |
+
rpcTimeoutSeconds: float,
|
| 144 |
+
isAsyncExecution: bool,
|
| 145 |
+
): ...
|
| 146 |
+
def _invoke_rpc_torchscript(
|
| 147 |
+
dstWorkerName: str,
|
| 148 |
+
qualifiedNameStr: str,
|
| 149 |
+
argsTuple: tuple,
|
| 150 |
+
kwargsDict: dict,
|
| 151 |
+
rpcTimeoutSeconds: float,
|
| 152 |
+
isAsyncExecution: bool,
|
| 153 |
+
): ...
|
| 154 |
+
def _invoke_remote_builtin(
|
| 155 |
+
dst: WorkerInfo,
|
| 156 |
+
opName: str,
|
| 157 |
+
rpcTimeoutSeconds: float,
|
| 158 |
+
*args: Any,
|
| 159 |
+
**kwargs: Any,
|
| 160 |
+
): ...
|
| 161 |
+
def _invoke_remote_python_udf(
|
| 162 |
+
dst: WorkerInfo,
|
| 163 |
+
pickledPythonUDF: str,
|
| 164 |
+
tensors: list[torch.Tensor],
|
| 165 |
+
rpcTimeoutSeconds: float,
|
| 166 |
+
isAsyncExecution: bool,
|
| 167 |
+
): ...
|
| 168 |
+
def _invoke_remote_torchscript(
|
| 169 |
+
dstWorkerName: WorkerInfo,
|
| 170 |
+
qualifiedNameStr: str,
|
| 171 |
+
rpcTimeoutSeconds: float,
|
| 172 |
+
isAsyncExecution: bool,
|
| 173 |
+
*args: Any,
|
| 174 |
+
**kwargs: Any,
|
| 175 |
+
): ...
|
| 176 |
+
def get_rpc_timeout() -> float: ...
|
| 177 |
+
def enable_gil_profiling(flag: bool): ...
|
| 178 |
+
def _set_rpc_timeout(rpcTimeoutSeconds: float): ...
|
| 179 |
+
|
| 180 |
+
class RemoteProfilerManager:
|
| 181 |
+
@staticmethod
|
| 182 |
+
def set_current_profiling_key(key: str): ...
|
| 183 |
+
|
| 184 |
+
def _enable_server_process_global_profiler(new_config: ProfilerConfig): ...
|
| 185 |
+
def _disable_server_process_global_profiler() -> list[list[list[ProfilerEvent]]]: ...
|
| 186 |
+
def _set_profiler_node_id(default_node_id: int): ...
|
| 187 |
+
def _enable_jit_rref_pickle(): ...
|
| 188 |
+
def _disable_jit_rref_pickle(): ...
|
miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_distributed_rpc_testing.pyi
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from torch._C._distributed_c10d import Store
|
| 3 |
+
from torch._C._distributed_rpc import _TensorPipeRpcBackendOptionsBase, TensorPipeAgent
|
| 4 |
+
|
| 5 |
+
# This module is defined in torch/csrc/distributed/rpc/testing/init.cpp
|
| 6 |
+
|
| 7 |
+
class FaultyTensorPipeRpcBackendOptions(_TensorPipeRpcBackendOptionsBase):
|
| 8 |
+
def __init__(
|
| 9 |
+
self,
|
| 10 |
+
num_worker_threads: int,
|
| 11 |
+
rpc_timeout: float,
|
| 12 |
+
init_method: str,
|
| 13 |
+
messages_to_fail: list[str],
|
| 14 |
+
messages_to_delay: dict[str, float],
|
| 15 |
+
num_fail_sends: int,
|
| 16 |
+
) -> None: ...
|
| 17 |
+
num_send_recv_threads: int
|
| 18 |
+
messages_to_fail: list[str]
|
| 19 |
+
messages_to_delay: dict[str, float]
|
| 20 |
+
num_fail_sends: int
|
| 21 |
+
|
| 22 |
+
class FaultyTensorPipeAgent(TensorPipeAgent):
|
| 23 |
+
def __init__(
|
| 24 |
+
self,
|
| 25 |
+
store: Store,
|
| 26 |
+
name: str,
|
| 27 |
+
rank: int,
|
| 28 |
+
world_size: int,
|
| 29 |
+
options: FaultyTensorPipeRpcBackendOptions,
|
| 30 |
+
reverse_device_maps: dict[str, dict[torch.device, torch.device]],
|
| 31 |
+
devices: list[torch.device],
|
| 32 |
+
) -> None: ...
|
miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_dynamo/__init__.pyi
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from . import compiled_autograd, eval_frame, guards # noqa: F401
|
| 2 |
+
|
| 3 |
+
def strip_function_call(name: str) -> str: ...
|
| 4 |
+
def is_valid_var_name(name: str) -> bool | int: ...
|
miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_dynamo/compiled_autograd.pyi
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from collections.abc import Callable
|
| 2 |
+
|
| 3 |
+
from torch import Tensor
|
| 4 |
+
from torch._dynamo.compiled_autograd import AutogradCompilerInstance
|
| 5 |
+
|
| 6 |
+
def set_autograd_compiler(
|
| 7 |
+
autograd_compiler: Callable[[], AutogradCompilerInstance] | None,
|
| 8 |
+
dynamic: bool,
|
| 9 |
+
) -> tuple[Callable[[], AutogradCompilerInstance] | None, bool]: ...
|
| 10 |
+
def clear_cache() -> None: ...
|
| 11 |
+
def is_cache_empty() -> bool: ...
|
| 12 |
+
def set_verbose_logger(fn: Callable[[str], None] | None) -> bool: ...
|
| 13 |
+
def call_cpp_tensor_pre_hooks(idx: int, grad: Tensor) -> Tensor: ...
|
miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_dynamo/eval_frame.pyi
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import enum
|
| 2 |
+
import types
|
| 3 |
+
from collections.abc import Callable
|
| 4 |
+
from typing import Optional, overload
|
| 5 |
+
|
| 6 |
+
from torch._dynamo.guards import GuardManagerWrapper
|
| 7 |
+
from torch._dynamo.types import DynamoCallback, DynamoGuardCompleteHook, DynamoGuardHook
|
| 8 |
+
from torch._guards import CompileId
|
| 9 |
+
|
| 10 |
+
def set_eval_frame(callback: DynamoCallback) -> DynamoCallback: ...
|
| 11 |
+
def set_skip_guard_eval_unsafe(value: bool) -> bool: ...
|
| 12 |
+
def get_eval_frame_callback() -> DynamoCallback: ...
|
| 13 |
+
def reset_code(code: types.CodeType) -> None: ...
|
| 14 |
+
def unsupported(obj1: object, obj2: object) -> object: ...
|
| 15 |
+
def set_code_exec_strategy(
|
| 16 |
+
code: types.CodeType, strategy: _FrameExecStrategy
|
| 17 |
+
) -> None: ...
|
| 18 |
+
def set_guard_error_hook(hook: DynamoGuardHook) -> None: ...
|
| 19 |
+
def set_guard_complete_hook(
|
| 20 |
+
hook: Optional[DynamoGuardCompleteHook],
|
| 21 |
+
) -> Optional[DynamoGuardCompleteHook]: ...
|
| 22 |
+
def raise_sigtrap() -> None: ...
|
| 23 |
+
def set_c_recursion_limit(limit: int) -> None: ...
|
| 24 |
+
def get_c_recursion_limit() -> int: ...
|
| 25 |
+
|
| 26 |
+
class _CacheEntry:
|
| 27 |
+
def check_fn(self, *args: object, **kwargs: object) -> bool: ...
|
| 28 |
+
def update_diff_guard_root_manager(self) -> None: ...
|
| 29 |
+
code: types.CodeType
|
| 30 |
+
compile_id: CompileId
|
| 31 |
+
# If we run into circular issues, just use object
|
| 32 |
+
guard_manager: GuardManagerWrapper
|
| 33 |
+
backend: Callable
|
| 34 |
+
next: _CacheEntry | None
|
| 35 |
+
|
| 36 |
+
class _PrecompileEntry:
|
| 37 |
+
guard_manager: GuardManagerWrapper
|
| 38 |
+
|
| 39 |
+
class _ExtraState:
|
| 40 |
+
def invalidate(
|
| 41 |
+
self, cache_entry: _CacheEntry, guard_manager: GuardManagerWrapper
|
| 42 |
+
) -> None: ...
|
| 43 |
+
|
| 44 |
+
class _FrameAction(enum.IntEnum):
|
| 45 |
+
DEFAULT = 0
|
| 46 |
+
SKIP = 1
|
| 47 |
+
RUN_ONLY = 2
|
| 48 |
+
|
| 49 |
+
class _FrameExecStrategy:
|
| 50 |
+
cur_action: _FrameAction
|
| 51 |
+
recursive_action: _FrameAction
|
| 52 |
+
|
| 53 |
+
@overload
|
| 54 |
+
def __init__(self) -> None: ...
|
| 55 |
+
@overload
|
| 56 |
+
def __init__(
|
| 57 |
+
self, cur_action: _FrameAction, recursive_action: _FrameAction
|
| 58 |
+
) -> None: ...
|
| 59 |
+
|
| 60 |
+
# This is an object that encapsulates the Python FrameType, and exposes
|
| 61 |
+
# properties Dynamo cares about for a frame.
|
| 62 |
+
class _PyInterpreterFrame:
|
| 63 |
+
f_code: types.CodeType
|
| 64 |
+
f_locals: dict[str, object]
|
| 65 |
+
f_globals: dict[str, object]
|
| 66 |
+
f_builtins: dict[str, object]
|
| 67 |
+
f_lasti: int
|
| 68 |
+
f_lineno: int
|
| 69 |
+
f_back: types.FrameType
|
| 70 |
+
# A tuple containing cell objects captured by this frame.
|
| 71 |
+
closure: tuple[types.CellType]
|
| 72 |
+
|
| 73 |
+
def _debug_get_cache_entry_list(code: types.CodeType) -> list[_CacheEntry]: ...
|
| 74 |
+
|
| 75 |
+
py_opcode_caches: list[int]
|
| 76 |
+
|
| 77 |
+
def code_framelocals_names(code: types.CodeType) -> tuple[str, ...]: ...
|
| 78 |
+
def _load_precompile_entry(
|
| 79 |
+
code: types.CodeType,
|
| 80 |
+
guard_manager: GuardManagerWrapper,
|
| 81 |
+
dynamo_code: types.CodeType,
|
| 82 |
+
) -> None: ...
|
| 83 |
+
def _reset_precompile_entries(code: types.CodeType) -> None: ...
|
| 84 |
+
def _debug_get_precompile_entries(code: types.CodeType) -> list[_PrecompileEntry]: ...
|
miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_dynamo/guards.pyi
ADDED
|
@@ -0,0 +1,452 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import enum
|
| 2 |
+
from collections.abc import Callable
|
| 3 |
+
from typing import Any, Optional, TypeAlias
|
| 4 |
+
|
| 5 |
+
import torch
|
| 6 |
+
|
| 7 |
+
# TODO: We should move the `GuardManagerType`
|
| 8 |
+
# defined in `guards.py` here and update other
|
| 9 |
+
# imports
|
| 10 |
+
GuardManagerType: TypeAlias = enum.Enum
|
| 11 |
+
|
| 12 |
+
class GlobalStateGuard:
|
| 13 |
+
def check(self) -> bool: ...
|
| 14 |
+
def reason(self) -> str: ...
|
| 15 |
+
|
| 16 |
+
class LeafGuard:
|
| 17 |
+
def verbose_code_parts(self) -> list[str]: ...
|
| 18 |
+
|
| 19 |
+
class RelationalGuard: ...
|
| 20 |
+
|
| 21 |
+
class GuardDebugInfo:
|
| 22 |
+
verbose_code_parts: list[str]
|
| 23 |
+
result: bool
|
| 24 |
+
num_guards_executed: int
|
| 25 |
+
|
| 26 |
+
class GuardManager:
|
| 27 |
+
def check(self, value: Any) -> bool: ...
|
| 28 |
+
def check_verbose(self, value: Any) -> GuardDebugInfo: ...
|
| 29 |
+
|
| 30 |
+
# Accessors
|
| 31 |
+
def globals_dict_manager(
|
| 32 |
+
self,
|
| 33 |
+
f_globals: dict[str, Any],
|
| 34 |
+
source: str,
|
| 35 |
+
example_value: Any,
|
| 36 |
+
guard_manager_enum: GuardManagerType,
|
| 37 |
+
) -> GuardManager: ...
|
| 38 |
+
def framelocals_manager(
|
| 39 |
+
self,
|
| 40 |
+
key: tuple[str, int],
|
| 41 |
+
source: str,
|
| 42 |
+
example_value: Any,
|
| 43 |
+
guard_manager_enum: GuardManagerType,
|
| 44 |
+
) -> GuardManager: ...
|
| 45 |
+
def dict_getitem_manager(
|
| 46 |
+
self,
|
| 47 |
+
key: Any,
|
| 48 |
+
source: str,
|
| 49 |
+
example_value: Any,
|
| 50 |
+
guard_manager_enum: GuardManagerType,
|
| 51 |
+
) -> GuardManager: ...
|
| 52 |
+
def grad_manager(
|
| 53 |
+
self,
|
| 54 |
+
source: str,
|
| 55 |
+
example_value: Any,
|
| 56 |
+
guard_manager_enum: GuardManagerType,
|
| 57 |
+
) -> GuardManager: ...
|
| 58 |
+
def generic_getattr_manager(
|
| 59 |
+
self,
|
| 60 |
+
attr: str,
|
| 61 |
+
source: str,
|
| 62 |
+
example_value: Any,
|
| 63 |
+
guard_manager_enum: GuardManagerType,
|
| 64 |
+
) -> GuardManager: ...
|
| 65 |
+
def getitem_manager(
|
| 66 |
+
self,
|
| 67 |
+
key: Any,
|
| 68 |
+
source: str,
|
| 69 |
+
example_value: Any,
|
| 70 |
+
guard_manager_enum: GuardManagerType,
|
| 71 |
+
) -> GuardManager: ...
|
| 72 |
+
def get_generic_dict_manager(
|
| 73 |
+
self,
|
| 74 |
+
source: str,
|
| 75 |
+
example_value: Any,
|
| 76 |
+
guard_manager_enum: GuardManagerType,
|
| 77 |
+
) -> GuardManager: ...
|
| 78 |
+
def list_getitem_manager(
|
| 79 |
+
self,
|
| 80 |
+
key: Any,
|
| 81 |
+
source: str,
|
| 82 |
+
example_value: Any,
|
| 83 |
+
guard_manager_enum: GuardManagerType,
|
| 84 |
+
) -> GuardManager: ...
|
| 85 |
+
def tuple_getitem_manager(
|
| 86 |
+
self,
|
| 87 |
+
key: Any,
|
| 88 |
+
source: str,
|
| 89 |
+
example_value: Any,
|
| 90 |
+
guard_manager_enum: GuardManagerType,
|
| 91 |
+
) -> GuardManager: ...
|
| 92 |
+
def set_getitem_manager(
|
| 93 |
+
self,
|
| 94 |
+
index: Any,
|
| 95 |
+
source: str,
|
| 96 |
+
example_value: Any,
|
| 97 |
+
guard_manager_enum: GuardManagerType,
|
| 98 |
+
) -> GuardManager: ...
|
| 99 |
+
def func_defaults_manager(
|
| 100 |
+
self,
|
| 101 |
+
source: str,
|
| 102 |
+
example_value: Any,
|
| 103 |
+
guard_manager_enum: GuardManagerType,
|
| 104 |
+
) -> GuardManager: ...
|
| 105 |
+
def func_kwdefaults_manager(
|
| 106 |
+
self,
|
| 107 |
+
source: str,
|
| 108 |
+
example_value: Any,
|
| 109 |
+
guard_manager_enum: GuardManagerType,
|
| 110 |
+
) -> GuardManager: ...
|
| 111 |
+
def tuple_iterator_getitem_manager(
|
| 112 |
+
self,
|
| 113 |
+
index: Any,
|
| 114 |
+
source: str,
|
| 115 |
+
example_value: Any,
|
| 116 |
+
guard_manager_enum: GuardManagerType,
|
| 117 |
+
) -> GuardManager: ...
|
| 118 |
+
def weakref_call_manager(
|
| 119 |
+
self,
|
| 120 |
+
source: str,
|
| 121 |
+
example_value: Any,
|
| 122 |
+
guard_manager_enum: GuardManagerType,
|
| 123 |
+
) -> GuardManager: ...
|
| 124 |
+
def call_function_no_args_manager(
|
| 125 |
+
self,
|
| 126 |
+
source: str,
|
| 127 |
+
example_value: Any,
|
| 128 |
+
guard_manager_enum: GuardManagerType,
|
| 129 |
+
) -> GuardManager: ...
|
| 130 |
+
def global_weakref_manager(
|
| 131 |
+
self,
|
| 132 |
+
global_name: str,
|
| 133 |
+
source: str,
|
| 134 |
+
example_value: Any,
|
| 135 |
+
guard_manager_enum: GuardManagerType,
|
| 136 |
+
) -> GuardManager: ...
|
| 137 |
+
def type_manager(
|
| 138 |
+
self,
|
| 139 |
+
source: str,
|
| 140 |
+
example_value: Any,
|
| 141 |
+
guard_manager_enum: GuardManagerType,
|
| 142 |
+
) -> GuardManager: ...
|
| 143 |
+
def getattr_manager(
|
| 144 |
+
self,
|
| 145 |
+
attr: str,
|
| 146 |
+
source: str,
|
| 147 |
+
example_value: Any,
|
| 148 |
+
guard_manager_enum: GuardManagerType,
|
| 149 |
+
) -> GuardManager: ...
|
| 150 |
+
def tensor_property_size_manager(
|
| 151 |
+
self,
|
| 152 |
+
idx: int,
|
| 153 |
+
source: str,
|
| 154 |
+
example_value: Any,
|
| 155 |
+
guard_manager_enum: GuardManagerType,
|
| 156 |
+
) -> GuardManager: ...
|
| 157 |
+
def tensor_property_shape_manager(
|
| 158 |
+
self,
|
| 159 |
+
idx: int,
|
| 160 |
+
source: str,
|
| 161 |
+
example_value: Any,
|
| 162 |
+
guard_manager_enum: GuardManagerType,
|
| 163 |
+
) -> GuardManager: ...
|
| 164 |
+
def tensor_property_storage_offset_manager(
|
| 165 |
+
self,
|
| 166 |
+
idx: int,
|
| 167 |
+
source: str,
|
| 168 |
+
example_value: Any,
|
| 169 |
+
guard_manager_enum: GuardManagerType,
|
| 170 |
+
) -> GuardManager: ...
|
| 171 |
+
def indexed_manager(
|
| 172 |
+
self,
|
| 173 |
+
idx: int,
|
| 174 |
+
source: str,
|
| 175 |
+
example_value: Any,
|
| 176 |
+
guard_manager_enum: GuardManagerType,
|
| 177 |
+
) -> GuardManager: ...
|
| 178 |
+
def lambda_manager(
|
| 179 |
+
self,
|
| 180 |
+
python_lambda: Callable[..., Any],
|
| 181 |
+
source: str,
|
| 182 |
+
example_value: Any,
|
| 183 |
+
guard_manager_enum: GuardManagerType,
|
| 184 |
+
) -> GuardManager: ...
|
| 185 |
+
def get_root(self) -> RootGuardManager: ...
|
| 186 |
+
def get_source(self) -> str: ...
|
| 187 |
+
def fail_count(self) -> int: ...
|
| 188 |
+
def get_child_managers(self) -> list[GuardManager]: ...
|
| 189 |
+
def repr(self) -> str: ...
|
| 190 |
+
def type_of_guarded_value(self) -> str: ...
|
| 191 |
+
def get_leaf_guards(self) -> list[LeafGuard]: ...
|
| 192 |
+
def get_accessors(self) -> list[GuardManager]: ...
|
| 193 |
+
def is_guarded_value_immutable(self) -> bool: ...
|
| 194 |
+
def is_tag_safe(self) -> bool: ...
|
| 195 |
+
def is_tag_safe_root(self) -> bool: ...
|
| 196 |
+
def has_no_accessors(self) -> bool: ...
|
| 197 |
+
def has_object_aliasing_guard(self) -> bool: ...
|
| 198 |
+
def get_type_of_guarded_value(self) -> type: ...
|
| 199 |
+
def type_dict_manager(
|
| 200 |
+
self,
|
| 201 |
+
source: str,
|
| 202 |
+
example_value: Any,
|
| 203 |
+
guard_manager_enum: GuardManagerType,
|
| 204 |
+
) -> GuardManager: ...
|
| 205 |
+
def type_mro_manager(
|
| 206 |
+
self,
|
| 207 |
+
source: str,
|
| 208 |
+
example_value: Any,
|
| 209 |
+
guard_manager_enum: GuardManagerType,
|
| 210 |
+
) -> GuardManager: ...
|
| 211 |
+
def code_manager(
|
| 212 |
+
self,
|
| 213 |
+
source: str,
|
| 214 |
+
example_value: Any,
|
| 215 |
+
guard_manager_enum: GuardManagerType,
|
| 216 |
+
) -> GuardManager: ...
|
| 217 |
+
def closure_manager(
|
| 218 |
+
self,
|
| 219 |
+
source: str,
|
| 220 |
+
example_value: Any,
|
| 221 |
+
guard_manager_enum: GuardManagerType,
|
| 222 |
+
) -> GuardManager: ...
|
| 223 |
+
# Leaf guards
|
| 224 |
+
def add_lambda_guard(
|
| 225 |
+
self, user_lambda: Callable[..., Any], verbose_code_parts: list[str]
|
| 226 |
+
) -> None: ...
|
| 227 |
+
def add_id_match_guard(
|
| 228 |
+
self, id_val: int, verbose_code_parts: list[str]
|
| 229 |
+
) -> None: ...
|
| 230 |
+
def add_equals_match_guard(
|
| 231 |
+
self,
|
| 232 |
+
equals_val: Any,
|
| 233 |
+
verbose_code_parts: list[str],
|
| 234 |
+
) -> None: ...
|
| 235 |
+
def add_global_state_guard(
|
| 236 |
+
self, initial_state: Any, verbose_code_parts: list[str]
|
| 237 |
+
) -> None: ...
|
| 238 |
+
def add_torch_function_mode_stack_guard(
|
| 239 |
+
self, initial_stack: list[Any], verbose_code_parts: list[str]
|
| 240 |
+
) -> None: ...
|
| 241 |
+
def add_mapping_keys_guard(
|
| 242 |
+
self, value: Any, verbose_code_parts: list[str]
|
| 243 |
+
) -> None: ...
|
| 244 |
+
def add_dict_length_check_guard(
|
| 245 |
+
self, value: int, verbose_code_parts: list[str]
|
| 246 |
+
) -> None: ...
|
| 247 |
+
def add_length_check_guard(
|
| 248 |
+
self, value: int, verbose_code_parts: list[str]
|
| 249 |
+
) -> None: ...
|
| 250 |
+
def add_true_match_guard(
|
| 251 |
+
self,
|
| 252 |
+
verbose_code_parts: list[str],
|
| 253 |
+
) -> None: ...
|
| 254 |
+
def add_false_match_guard(
|
| 255 |
+
self,
|
| 256 |
+
verbose_code_parts: list[str],
|
| 257 |
+
) -> None: ...
|
| 258 |
+
def add_none_match_guard(
|
| 259 |
+
self,
|
| 260 |
+
verbose_code_parts: list[str],
|
| 261 |
+
) -> None: ...
|
| 262 |
+
def add_not_none_guard(
|
| 263 |
+
self,
|
| 264 |
+
verbose_code_parts: list[str],
|
| 265 |
+
) -> None: ...
|
| 266 |
+
def add_dispatch_key_set_guard(
|
| 267 |
+
self,
|
| 268 |
+
dispatch_key: Any,
|
| 269 |
+
verbose_code_parts: list[str],
|
| 270 |
+
) -> None: ...
|
| 271 |
+
def add_tensor_match_guard(
|
| 272 |
+
self,
|
| 273 |
+
value: Any,
|
| 274 |
+
sizes: list[int],
|
| 275 |
+
strides: list[int],
|
| 276 |
+
tensor_name: str,
|
| 277 |
+
verbose_code_parts: list[str],
|
| 278 |
+
ptype: Any,
|
| 279 |
+
dispatch_keys: Any,
|
| 280 |
+
) -> None: ...
|
| 281 |
+
def add_dynamic_indices_guard(
|
| 282 |
+
self,
|
| 283 |
+
value: set[Any],
|
| 284 |
+
verbose_code_parts: list[str],
|
| 285 |
+
) -> None: ...
|
| 286 |
+
def add_no_hasattr_guard(
|
| 287 |
+
self,
|
| 288 |
+
attr_name: str,
|
| 289 |
+
verbose_code_parts: list[str],
|
| 290 |
+
) -> None: ...
|
| 291 |
+
def add_dict_contains_guard(
|
| 292 |
+
self,
|
| 293 |
+
contains: bool,
|
| 294 |
+
key: Any,
|
| 295 |
+
verbose_code_parts: list[str],
|
| 296 |
+
) -> None: ...
|
| 297 |
+
def add_type_match_guard(
|
| 298 |
+
self,
|
| 299 |
+
value: int,
|
| 300 |
+
verbose_code_parts: list[str],
|
| 301 |
+
) -> None: ...
|
| 302 |
+
def add_dict_version_guard(
|
| 303 |
+
self,
|
| 304 |
+
value: Any,
|
| 305 |
+
verbose_code_parts: list[str],
|
| 306 |
+
) -> None: ...
|
| 307 |
+
def add_set_contains_guard(
|
| 308 |
+
self,
|
| 309 |
+
contains: bool,
|
| 310 |
+
item: Any,
|
| 311 |
+
verbose_code_parts: list[str],
|
| 312 |
+
) -> None: ...
|
| 313 |
+
def add_dual_level_match_guard(
|
| 314 |
+
self,
|
| 315 |
+
level: int,
|
| 316 |
+
verbose_code_parts: list[str],
|
| 317 |
+
) -> None: ...
|
| 318 |
+
def add_float_is_nan_guard(
|
| 319 |
+
self,
|
| 320 |
+
verbose_code_parts: list[str],
|
| 321 |
+
) -> None: ...
|
| 322 |
+
def add_complex_is_nan_guard(
|
| 323 |
+
self,
|
| 324 |
+
verbose_code_parts: list[str],
|
| 325 |
+
) -> None: ...
|
| 326 |
+
def add_tuple_iterator_length_guard(
|
| 327 |
+
self,
|
| 328 |
+
length: int,
|
| 329 |
+
type_id: int,
|
| 330 |
+
verbose_code_parts: list[str],
|
| 331 |
+
) -> None: ...
|
| 332 |
+
def add_range_iterator_match_guard(
|
| 333 |
+
self,
|
| 334 |
+
start: int,
|
| 335 |
+
stop: int,
|
| 336 |
+
step: int,
|
| 337 |
+
type_id: int,
|
| 338 |
+
verbose_code_parts: list[str],
|
| 339 |
+
) -> None: ...
|
| 340 |
+
def add_default_device_guard(
|
| 341 |
+
self,
|
| 342 |
+
verbose_code_parts: list[str],
|
| 343 |
+
) -> None: ...
|
| 344 |
+
def mark_tag_safe(self) -> None: ...
|
| 345 |
+
def mark_tag_safe_root(self) -> None: ...
|
| 346 |
+
|
| 347 |
+
class RootGuardManager(GuardManager):
|
| 348 |
+
def get_epilogue_lambda_guards(self) -> list[LeafGuard]: ...
|
| 349 |
+
def add_epilogue_lambda_guard(
|
| 350 |
+
self,
|
| 351 |
+
guard: LeafGuard,
|
| 352 |
+
verbose_code_parts: list[str],
|
| 353 |
+
) -> None: ...
|
| 354 |
+
def clone_manager(
|
| 355 |
+
self, clone_filter_fn: Callable[[GuardManager], bool]
|
| 356 |
+
) -> RootGuardManager: ...
|
| 357 |
+
def attach_compile_id(self, compile_id: str) -> None: ...
|
| 358 |
+
|
| 359 |
+
class DictGuardManager(GuardManager):
|
| 360 |
+
def get_key_manager(
|
| 361 |
+
self,
|
| 362 |
+
index: int,
|
| 363 |
+
source: str,
|
| 364 |
+
example_value: Any,
|
| 365 |
+
guard_manager_enum: GuardManagerType,
|
| 366 |
+
) -> GuardManager: ...
|
| 367 |
+
def get_value_manager(
|
| 368 |
+
self,
|
| 369 |
+
index: int,
|
| 370 |
+
source: str,
|
| 371 |
+
example_value: Any,
|
| 372 |
+
guard_manager_enum: GuardManagerType,
|
| 373 |
+
) -> GuardManager: ...
|
| 374 |
+
def get_key_value_managers(
|
| 375 |
+
self,
|
| 376 |
+
) -> dict[int, tuple[GuardManager, GuardManager]]: ...
|
| 377 |
+
|
| 378 |
+
# Guard accessor stubs
|
| 379 |
+
class GuardAccessor: ...
|
| 380 |
+
class DictGetItemGuardAccessor(GuardAccessor): ...
|
| 381 |
+
class GetGenericDictGuardAccessor(GuardAccessor): ...
|
| 382 |
+
class TypeDictGuardAccessor(GuardAccessor): ...
|
| 383 |
+
class TypeMROGuardAccessor(GuardAccessor): ...
|
| 384 |
+
class ClosureGuardAccessor(GuardAccessor): ...
|
| 385 |
+
class TupleGetItemGuardAccessor(GuardAccessor): ...
|
| 386 |
+
class TypeGuardAccessor(GuardAccessor): ...
|
| 387 |
+
class CodeGuardAccessor(GuardAccessor): ...
|
| 388 |
+
class FuncDefaultsGuardAccessor(GuardAccessor): ...
|
| 389 |
+
class FuncKwDefaultsGuardAccessor(GuardAccessor): ...
|
| 390 |
+
|
| 391 |
+
class GetAttrGuardAccessor(GuardAccessor):
|
| 392 |
+
def get_attr_name(self) -> str: ...
|
| 393 |
+
|
| 394 |
+
def install_object_aliasing_guard(
|
| 395 |
+
x: GuardManager,
|
| 396 |
+
y: GuardManager,
|
| 397 |
+
verbose_code_parts: list[str],
|
| 398 |
+
) -> None: ...
|
| 399 |
+
def install_no_tensor_aliasing_guard(
|
| 400 |
+
guard_managers: list[GuardManager],
|
| 401 |
+
tensor_names: list[str],
|
| 402 |
+
verbose_code_parts: list[str],
|
| 403 |
+
) -> None: ...
|
| 404 |
+
def install_storage_overlapping_guard(
|
| 405 |
+
overlapping_guard_managers: list[GuardManager],
|
| 406 |
+
non_overlapping_guard_managers: list[GuardManager],
|
| 407 |
+
verbose_code_parts: list[str],
|
| 408 |
+
) -> None: ...
|
| 409 |
+
def install_symbolic_shape_guard(
|
| 410 |
+
guard_managers: list[GuardManager],
|
| 411 |
+
nargs_int: int,
|
| 412 |
+
nargs_float: int,
|
| 413 |
+
py_addr: int,
|
| 414 |
+
py_addr_keep_alive: Any,
|
| 415 |
+
verbose_code_parts: list[str],
|
| 416 |
+
) -> None: ...
|
| 417 |
+
def profile_guard_manager(
|
| 418 |
+
guard_manager: GuardManager,
|
| 419 |
+
f_locals: dict[str, Any],
|
| 420 |
+
n_iters: int,
|
| 421 |
+
) -> float: ...
|
| 422 |
+
|
| 423 |
+
class TensorGuards:
|
| 424 |
+
def __init__(
|
| 425 |
+
self,
|
| 426 |
+
*,
|
| 427 |
+
dynamic_dims_sizes: list[torch.SymInt | None] | None = None,
|
| 428 |
+
dynamic_dims_strides: list[torch.SymInt | None] | None = None,
|
| 429 |
+
) -> None: ...
|
| 430 |
+
def check(self, *args: Any) -> bool: ...
|
| 431 |
+
def check_verbose(
|
| 432 |
+
self, *args: Any, tensor_check_names: Optional[list[str]] = None
|
| 433 |
+
) -> bool | str: ...
|
| 434 |
+
|
| 435 |
+
def assert_size_stride(
|
| 436 |
+
item: torch.Tensor,
|
| 437 |
+
size: torch.types._size,
|
| 438 |
+
stride: torch.types._size,
|
| 439 |
+
op_name: str | None = None,
|
| 440 |
+
) -> None: ...
|
| 441 |
+
def assert_alignment(
|
| 442 |
+
item: torch.Tensor,
|
| 443 |
+
alignment: int,
|
| 444 |
+
op_name: str | None = None,
|
| 445 |
+
) -> None: ...
|
| 446 |
+
def check_obj_id(obj: object, expected: int) -> bool: ...
|
| 447 |
+
def check_type_id(obj: object, expected: int) -> bool: ...
|
| 448 |
+
def dict_version(d: dict[Any, Any]) -> int: ...
|
| 449 |
+
def compute_overlapping_tensors(
|
| 450 |
+
tensors: list[torch.Tensor], symbolic: bool = True
|
| 451 |
+
) -> set[int]: ...
|
| 452 |
+
def set_is_in_mode_without_ignore_compile_internals(value: bool) -> None: ...
|
miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_export/__init__.pyi
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Defined in torch/csrc/export/pybind.cpp
|
| 2 |
+
class CppExportedProgram: ...
|
| 3 |
+
|
| 4 |
+
def deserialize_exported_program(
|
| 5 |
+
serialized_program: str,
|
| 6 |
+
) -> CppExportedProgram: ...
|
| 7 |
+
def serialize_exported_program(
|
| 8 |
+
cpp_exported_program: CppExportedProgram,
|
| 9 |
+
) -> str: ...
|
miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_export/pt2_archive_constants.pyi
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Defined in torch/csrc/export/pt2_archive_constants.h
|
| 2 |
+
|
| 3 |
+
ARCHIVE_ROOT_NAME: str = ...
|
| 4 |
+
ARCHIVE_FORMAT_PATH: str = ...
|
| 5 |
+
ARCHIVE_FORMAT_VALUE: str = ...
|
| 6 |
+
ARCHIVE_VERSION_PATH: str = ...
|
| 7 |
+
ARCHIVE_VERSION_VALUE: str = ...
|
| 8 |
+
MODELS_DIR: str = ...
|
| 9 |
+
MODELS_FILENAME_FORMAT: str = ...
|
| 10 |
+
AOTINDUCTOR_DIR: str = ...
|
| 11 |
+
MTIA_DIR: str = ...
|
| 12 |
+
WEIGHTS_DIR: str = ...
|
| 13 |
+
WEIGHTS_CONFIG_FILENAME_FORMAT: str = ...
|
| 14 |
+
WEIGHT_FILENAME_PREFIX: str = ...
|
| 15 |
+
CONSTANTS_DIR: str = ...
|
| 16 |
+
CONSTANTS_CONFIG_FILENAME_FORMAT: str = ...
|
| 17 |
+
TENSOR_CONSTANT_FILENAME_PREFIX: str = ...
|
| 18 |
+
CUSTOM_OBJ_FILENAME_PREFIX: str = ...
|
| 19 |
+
SAMPLE_INPUTS_DIR: str = ...
|
| 20 |
+
SAMPLE_INPUTS_FILENAME_FORMAT: str = ...
|
| 21 |
+
EXECUTORCH_DIR: str = ...
|
| 22 |
+
EXTRA_DIR: str = ...
|
| 23 |
+
MODULE_INFO_PATH: str = ...
|
| 24 |
+
XL_MODEL_WEIGHTS_DIR: str = ...
|
| 25 |
+
XL_MODEL_WEIGHTS_PARAM_CONFIG_PATH: str = ...
|
miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_functionalization.pyi
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from torch import Tensor
|
| 2 |
+
from torch.types import _bool
|
| 3 |
+
|
| 4 |
+
# Defined in torch/csrc/functionalization/Module.cpp
|
| 5 |
+
|
| 6 |
+
class ViewMeta:
|
| 7 |
+
has_symbolic_inputs: _bool
|
| 8 |
+
|
| 9 |
+
# Returns the list of ViewMeta instances of the given functional tensor.
|
| 10 |
+
#
|
| 11 |
+
# Although we do have python bindings for their types, we won't
|
| 12 |
+
# expose them here, since they should not be used by users.
|
| 13 |
+
def get_view_meta_sequence(tensor: Tensor) -> list[ViewMeta]: ...
|
| 14 |
+
|
| 15 |
+
# Applies the ViewMeta sequence on top of the given base.
|
| 16 |
+
def apply_view_meta_sequence(base: Tensor, sequence: list[ViewMeta]) -> Tensor: ...
|
miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_functions.pyi
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import AnyStr, overload
|
| 2 |
+
|
| 3 |
+
from torch import Tensor
|
| 4 |
+
|
| 5 |
+
class UndefinedGrad:
|
| 6 |
+
def __init__(self) -> None: ...
|
| 7 |
+
def __call__(self, *inputs: Tensor) -> list[Tensor]: ...
|
| 8 |
+
|
| 9 |
+
class DelayedError:
|
| 10 |
+
def __init__(self, msg: AnyStr, num_inputs: int) -> None: ...
|
| 11 |
+
|
| 12 |
+
# __call__ should really be a higher-kinded type:
|
| 13 |
+
# def __call__(self, arg: Tensor) -> Tensor: ...
|
| 14 |
+
# def __call__(self, *args: Tensor * num_inputs) -> Tuple[Tensor * num_inputs]: ...
|
| 15 |
+
|
| 16 |
+
@overload
|
| 17 |
+
def __call__(self, i0: Tensor) -> Tensor: ...
|
| 18 |
+
@overload
|
| 19 |
+
def __call__(self, *args: Tensor) -> tuple[Tensor, ...]: ...
|
miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_functorch.pyi
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# mypy: allow-untyped-defs
|
| 2 |
+
from enum import Enum
|
| 3 |
+
|
| 4 |
+
from torch import Tensor
|
| 5 |
+
|
| 6 |
+
# Defined in torch/csrc/functorch/init.cpp
|
| 7 |
+
|
| 8 |
+
def set_inplace_requires_grad_allowed(allowed: bool) -> None: ...
|
| 9 |
+
def get_inplace_requires_grad_allowed() -> bool: ...
|
| 10 |
+
def _set_dynamic_layer_keys_included(included: bool) -> None: ...
|
| 11 |
+
def get_unwrapped(tensor: Tensor) -> Tensor: ...
|
| 12 |
+
def is_batchedtensor(tensor: Tensor) -> bool: ...
|
| 13 |
+
def is_functionaltensor(tensor: Tensor) -> bool: ...
|
| 14 |
+
def is_functorch_wrapped_tensor(tensor: Tensor) -> bool: ...
|
| 15 |
+
def is_gradtrackingtensor(tensor: Tensor) -> bool: ...
|
| 16 |
+
def is_legacy_batchedtensor(tensor: Tensor) -> bool: ...
|
| 17 |
+
def maybe_get_bdim(tensor: Tensor) -> int: ...
|
| 18 |
+
def maybe_get_level(tensor: Tensor) -> int: ...
|
| 19 |
+
def maybe_current_level() -> int | None: ...
|
| 20 |
+
def unwrap_if_dead(tensor: Tensor) -> Tensor: ...
|
| 21 |
+
def _unwrap_for_grad(tensor: Tensor, level: int) -> Tensor: ...
|
| 22 |
+
def _wrap_for_grad(tensor: Tensor, level: int) -> Tensor: ...
|
| 23 |
+
def _unwrap_batched(tensor: Tensor, level: int) -> tuple[Tensor, int | None]: ...
|
| 24 |
+
def current_level() -> int: ...
|
| 25 |
+
def count_jvp_interpreters() -> int: ...
|
| 26 |
+
def _add_batch_dim(tensor: Tensor, bdim: int, level: int) -> Tensor: ...
|
| 27 |
+
def _maybe_unsafe_set_level(tensor: Tensor, level: int) -> None: ...
|
| 28 |
+
def set_single_level_autograd_function_allowed(allowed: bool) -> None: ...
|
| 29 |
+
def get_single_level_autograd_function_allowed() -> bool: ...
|
| 30 |
+
def _unwrap_functional_tensor(tensor: Tensor, reapply_views: bool) -> Tensor: ...
|
| 31 |
+
def _wrap_functional_tensor(tensor: Tensor, level: int) -> Tensor: ...
|
| 32 |
+
def _vmap_increment_nesting(batch_size: int, randomness: str) -> int: ...
|
| 33 |
+
def _vmap_decrement_nesting() -> int: ...
|
| 34 |
+
def _grad_increment_nesting() -> int: ...
|
| 35 |
+
def _grad_decrement_nesting() -> int: ...
|
| 36 |
+
def _jvp_increment_nesting() -> int: ...
|
| 37 |
+
def _jvp_decrement_nesting() -> int: ...
|
| 38 |
+
|
| 39 |
+
# Defined in aten/src/ATen/functorch/Interpreter.h
|
| 40 |
+
class TransformType(Enum):
|
| 41 |
+
Torch = ...
|
| 42 |
+
Vmap = ...
|
| 43 |
+
Grad = ...
|
| 44 |
+
Jvp = ...
|
| 45 |
+
Functionalize = ...
|
| 46 |
+
|
| 47 |
+
class RandomnessType(Enum):
|
| 48 |
+
Error = ...
|
| 49 |
+
Same = ...
|
| 50 |
+
Different = ...
|
| 51 |
+
|
| 52 |
+
class CInterpreter:
|
| 53 |
+
def key(self) -> TransformType: ...
|
| 54 |
+
def level(self) -> int: ...
|
| 55 |
+
def serialize(self) -> bytes: ...
|
| 56 |
+
@staticmethod
|
| 57 |
+
def deserialize(bytes) -> CInterpreter: ...
|
| 58 |
+
|
| 59 |
+
class CGradInterpreterPtr:
|
| 60 |
+
def __init__(self, interpreter: CInterpreter) -> None: ...
|
| 61 |
+
def lift(self, Tensor) -> Tensor: ...
|
| 62 |
+
def prevGradMode(self) -> bool: ...
|
| 63 |
+
|
| 64 |
+
class CJvpInterpreterPtr:
|
| 65 |
+
def __init__(self, interpreter: CInterpreter) -> None: ...
|
| 66 |
+
def lift(self, Tensor) -> Tensor: ...
|
| 67 |
+
def prevFwdGradMode(self) -> bool: ...
|
| 68 |
+
|
| 69 |
+
class CFunctionalizeInterpreterPtr:
|
| 70 |
+
def __init__(self, interpreter: CInterpreter) -> None: ...
|
| 71 |
+
def key(self) -> TransformType: ...
|
| 72 |
+
def level(self) -> int: ...
|
| 73 |
+
def functionalizeAddBackViews(self) -> bool: ...
|
| 74 |
+
|
| 75 |
+
class CVmapInterpreterPtr:
|
| 76 |
+
def __init__(self, interpreter: CInterpreter) -> None: ...
|
| 77 |
+
def key(self) -> TransformType: ...
|
| 78 |
+
def level(self) -> int: ...
|
| 79 |
+
def batchSize(self) -> int: ...
|
| 80 |
+
def randomness(self) -> RandomnessType: ...
|
| 81 |
+
|
| 82 |
+
class DynamicLayer: ...
|
| 83 |
+
|
| 84 |
+
def get_dynamic_layer_stack_depth() -> int: ...
|
| 85 |
+
def get_interpreter_stack() -> list[CInterpreter]: ...
|
| 86 |
+
def peek_interpreter_stack() -> CInterpreter: ...
|
| 87 |
+
def pop_dynamic_layer_stack() -> DynamicLayer: ...
|
| 88 |
+
def pop_dynamic_layer_stack_and_undo_to_depth(int) -> None: ...
|
| 89 |
+
def push_dynamic_layer_stack(dl: DynamicLayer) -> int: ...
|
miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_instruction_counter.pyi
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Defined in torch/csrc/instruction_counter/Module.cpp
|
| 2 |
+
|
| 3 |
+
def start() -> int: ...
|
| 4 |
+
def end(id: int) -> int: ...
|
miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_itt.pyi
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Defined in torch/csrc/itt.cpp
|
| 2 |
+
def is_available() -> None: ...
|
| 3 |
+
def rangePush(message: str) -> None: ...
|
| 4 |
+
def rangePop() -> None: ...
|
| 5 |
+
def mark(message: str) -> None: ...
|
miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_jit_tree_views.pyi
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Any, Optional
|
| 2 |
+
|
| 3 |
+
# Defined in torch/csrc/jit/python/python_tree_views.cpp
|
| 4 |
+
|
| 5 |
+
class SourceRange:
|
| 6 |
+
def highlight(self) -> str: ...
|
| 7 |
+
@property
|
| 8 |
+
def start(self) -> int: ...
|
| 9 |
+
@property
|
| 10 |
+
def end(self) -> int: ...
|
| 11 |
+
|
| 12 |
+
class SourceRangeFactory:
|
| 13 |
+
def __init__(
|
| 14 |
+
self,
|
| 15 |
+
text: str,
|
| 16 |
+
filename: Any,
|
| 17 |
+
file_lineno: int,
|
| 18 |
+
leading_whitespace_chars: int,
|
| 19 |
+
) -> None: ...
|
| 20 |
+
def make_range(self, line: int, start_col: int, end_col: int) -> SourceRange: ...
|
| 21 |
+
def make_raw_range(self, start: int, end: int) -> SourceRange: ...
|
| 22 |
+
@property
|
| 23 |
+
def source(self) -> str: ...
|
| 24 |
+
|
| 25 |
+
class TreeView:
|
| 26 |
+
def range(self) -> SourceRange: ...
|
| 27 |
+
def dump(self) -> None: ...
|
| 28 |
+
|
| 29 |
+
class Ident(TreeView):
|
| 30 |
+
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
|
| 31 |
+
@property
|
| 32 |
+
def name(self) -> str: ...
|
| 33 |
+
|
| 34 |
+
class Param(TreeView):
|
| 35 |
+
def __init__(self, type: Optional[Any], name: Ident, kwarg_only: bool) -> None: ...
|
| 36 |
+
|
| 37 |
+
class Attribute(TreeView):
|
| 38 |
+
def __init__(self, name: Ident, value: Any) -> None: ...
|
| 39 |
+
|
| 40 |
+
# Literals
|
| 41 |
+
def TrueLiteral(range: SourceRange) -> Any: ...
|
| 42 |
+
def FalseLiteral(range: SourceRange) -> Any: ...
|
| 43 |
+
def NoneLiteral(range: SourceRange) -> Any: ...
|
| 44 |
+
|
| 45 |
+
# Tree nodes
|
| 46 |
+
class Stmt(TreeView):
|
| 47 |
+
def __init__(self, thing: TreeView) -> None: ...
|
| 48 |
+
|
| 49 |
+
class Expr(TreeView): ...
|
| 50 |
+
|
| 51 |
+
class Def(TreeView):
|
| 52 |
+
def __init__(self, name: Ident, decl: Any, body: list[Stmt]) -> None: ...
|
| 53 |
+
def decl(self) -> Any: ...
|
| 54 |
+
def name(self) -> Ident: ...
|
| 55 |
+
|
| 56 |
+
class Property(TreeView):
|
| 57 |
+
def __init__(
|
| 58 |
+
self, r: SourceRange, name: Ident, getter: Def, setter: Optional[Def]
|
| 59 |
+
) -> None: ...
|
| 60 |
+
def name(self) -> Ident: ...
|
| 61 |
+
def getter_name(self) -> str: ...
|
| 62 |
+
def setter_name(self) -> Optional[Ident]: ...
|
| 63 |
+
|
| 64 |
+
class ClassDef(TreeView):
|
| 65 |
+
def __init__(
|
| 66 |
+
self, name: Ident, body: list[Stmt], props: list[Property], assigns: list[Any]
|
| 67 |
+
) -> None: ...
|
| 68 |
+
|
| 69 |
+
class Decl(TreeView):
|
| 70 |
+
def __init__(
|
| 71 |
+
self, r: SourceRange, params: list[Param], return_type: Optional[Expr]
|
| 72 |
+
) -> None: ...
|
| 73 |
+
|
| 74 |
+
class Delete(Stmt):
|
| 75 |
+
def __init__(self, range: SourceRange, targets: list[Expr]) -> None: ...
|
| 76 |
+
|
| 77 |
+
class WithItem(Expr):
|
| 78 |
+
def __init__(
|
| 79 |
+
self, range: SourceRange, target: Expr, var: Optional[Any]
|
| 80 |
+
) -> None: ...
|
| 81 |
+
|
| 82 |
+
class Assign(Stmt):
|
| 83 |
+
def __init__(
|
| 84 |
+
self, lhs: list[Expr], rhs: Expr, type: Optional[Expr] = None
|
| 85 |
+
) -> None: ...
|
| 86 |
+
|
| 87 |
+
class AugAssign(Stmt):
|
| 88 |
+
def __init__(self, lhs: Expr, kind_str: str, rhs: Expr) -> None: ...
|
| 89 |
+
|
| 90 |
+
class Return(Stmt):
|
| 91 |
+
def __init__(self, range: SourceRange, value: Optional[Expr]) -> None: ...
|
| 92 |
+
|
| 93 |
+
class Raise(Stmt):
|
| 94 |
+
def __init__(self, range: SourceRange, expr: Expr) -> None: ...
|
| 95 |
+
|
| 96 |
+
class Assert(Stmt):
|
| 97 |
+
def __init__(self, range: SourceRange, test: Expr, msg: Optional[Expr]) -> None: ...
|
| 98 |
+
|
| 99 |
+
class Pass(Stmt):
|
| 100 |
+
def __init__(self, range: SourceRange) -> None: ...
|
| 101 |
+
|
| 102 |
+
class Break(Stmt): ...
|
| 103 |
+
class Continue(Stmt): ...
|
| 104 |
+
|
| 105 |
+
class Dots(Expr, TreeView):
|
| 106 |
+
def __init__(self, range: SourceRange) -> None: ...
|
| 107 |
+
|
| 108 |
+
class If(Stmt):
|
| 109 |
+
def __init__(
|
| 110 |
+
self,
|
| 111 |
+
range: SourceRange,
|
| 112 |
+
cond: Expr,
|
| 113 |
+
true_branch: list[Stmt],
|
| 114 |
+
false_branch: list[Stmt],
|
| 115 |
+
) -> None: ...
|
| 116 |
+
|
| 117 |
+
class While(Stmt):
|
| 118 |
+
def __init__(self, range: SourceRange, cond: Expr, body: list[Stmt]) -> None: ...
|
| 119 |
+
|
| 120 |
+
class With(Stmt):
|
| 121 |
+
def __init__(
|
| 122 |
+
self, range: SourceRange, targets: list[WithItem], body: list[Stmt]
|
| 123 |
+
) -> None: ...
|
| 124 |
+
|
| 125 |
+
class For(Stmt):
|
| 126 |
+
def __init__(
|
| 127 |
+
self,
|
| 128 |
+
range: SourceRange,
|
| 129 |
+
targets: list[Expr],
|
| 130 |
+
itrs: list[Expr],
|
| 131 |
+
body: list[Stmt],
|
| 132 |
+
) -> None: ...
|
| 133 |
+
|
| 134 |
+
class ExprStmt(Stmt):
|
| 135 |
+
def __init__(self, expr: Expr) -> None: ...
|
| 136 |
+
|
| 137 |
+
class Var(Expr):
|
| 138 |
+
def __init__(self, name: Ident) -> None: ...
|
| 139 |
+
@property
|
| 140 |
+
def name(self) -> str: ...
|
| 141 |
+
|
| 142 |
+
class BinOp(Expr):
|
| 143 |
+
def __init__(self, kind: str, lhs: Expr, rhs: Expr) -> None: ...
|
| 144 |
+
|
| 145 |
+
class UnaryOp(Expr):
|
| 146 |
+
def __init__(self, range: SourceRange, kind: str, expr: Expr) -> None: ...
|
| 147 |
+
|
| 148 |
+
class Const(Expr):
|
| 149 |
+
def __init__(self, range: SourceRange, value: str) -> None: ...
|
| 150 |
+
|
| 151 |
+
class StringLiteral(Expr):
|
| 152 |
+
def __init__(self, range: SourceRange, value: str) -> None: ...
|
| 153 |
+
|
| 154 |
+
class Apply(Expr):
|
| 155 |
+
def __init__(
|
| 156 |
+
self, expr: Expr, args: list[Expr], kwargs: list[Attribute]
|
| 157 |
+
) -> None: ...
|
| 158 |
+
|
| 159 |
+
class Select(Expr):
|
| 160 |
+
def __init__(self, expr: Expr, field: Ident) -> None: ...
|
| 161 |
+
|
| 162 |
+
class TernaryIf(Expr):
|
| 163 |
+
def __init__(self, cond: Expr, true_expr: Expr, false_expr: Expr) -> None: ...
|
| 164 |
+
|
| 165 |
+
class ListComp(Expr):
|
| 166 |
+
def __init__(
|
| 167 |
+
self, range: SourceRange, elt: Expr, target: Expr, iter: Expr
|
| 168 |
+
) -> None: ...
|
| 169 |
+
|
| 170 |
+
class DictComp(Expr):
|
| 171 |
+
def __init__(
|
| 172 |
+
self, range: SourceRange, key: Expr, value: Expr, target: Expr, iter: Expr
|
| 173 |
+
) -> None: ...
|
| 174 |
+
|
| 175 |
+
class ListLiteral(Expr):
|
| 176 |
+
def __init__(self, range: SourceRange, args: list[Expr]) -> None: ...
|
| 177 |
+
|
| 178 |
+
class TupleLiteral(Expr):
|
| 179 |
+
def __init__(self, range: SourceRange, args: list[Expr]) -> None: ...
|
| 180 |
+
|
| 181 |
+
class DictLiteral(Expr):
|
| 182 |
+
def __init__(
|
| 183 |
+
self, range: SourceRange, keys: list[Expr], values: list[Expr]
|
| 184 |
+
) -> None: ...
|
| 185 |
+
|
| 186 |
+
class Subscript(Expr):
|
| 187 |
+
def __init__(self, base: Expr, subscript_exprs: list[Expr]) -> None: ...
|
| 188 |
+
|
| 189 |
+
class SliceExpr(Expr):
|
| 190 |
+
def __init__(
|
| 191 |
+
self,
|
| 192 |
+
range: SourceRange,
|
| 193 |
+
lower: Optional[Expr],
|
| 194 |
+
upper: Optional[Expr],
|
| 195 |
+
step: Optional[Expr],
|
| 196 |
+
) -> None: ...
|
| 197 |
+
|
| 198 |
+
class Starred(Expr):
|
| 199 |
+
def __init__(self, range: SourceRange, expr: Expr) -> None: ...
|
| 200 |
+
|
| 201 |
+
class EmptyTypeAnnotation(TreeView):
|
| 202 |
+
def __init__(self, range: SourceRange) -> None: ...
|
miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_lazy.pyi
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from torch import Tensor
|
| 2 |
+
|
| 3 |
+
# defined in torch/csrc/lazy/python/init.cpp
|
| 4 |
+
def _mark_step(device: str, devices: list[str], wait: bool) -> None: ...
|
| 5 |
+
def _wait_device_ops(devices: list[str]) -> None: ...
|
| 6 |
+
def _reset_metrics() -> None: ...
|
| 7 |
+
def _counter_names() -> list[str]: ...
|
| 8 |
+
def _counter_value(name: str) -> int: ...
|
| 9 |
+
def _metrics_report() -> str: ...
|
| 10 |
+
def _get_graph_hash(tensors: list[Tensor]) -> str: ...
|
| 11 |
+
def _sync_multi(
|
| 12 |
+
tensors: list[Tensor],
|
| 13 |
+
devices: list[str],
|
| 14 |
+
wait: bool = True,
|
| 15 |
+
sync_ltc_data: bool = True,
|
| 16 |
+
) -> None: ...
|
| 17 |
+
def _get_tensor_id(tensor: Tensor) -> int: ...
|
| 18 |
+
def _get_tensors_text(tensors: list[Tensor]) -> str: ...
|
| 19 |
+
def _get_tensors_dot(tensors: list[Tensor]) -> str: ...
|
| 20 |
+
def _get_tensors_backend(tensors: list[Tensor]) -> str: ...
|
| 21 |
+
def _get_force_fallback() -> str: ...
|
| 22 |
+
def _set_force_fallback(newval: str) -> None: ...
|
| 23 |
+
def _clear_ir_cache() -> None: ...
|
| 24 |
+
def _dump_ir_cache(filename: str) -> None: ...
|
| 25 |
+
def _set_reuse_ir(val: bool) -> None: ...
|
| 26 |
+
def _get_default_device_type() -> str: ...
|
miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_lazy_ts_backend.pyi
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# mypy: allow-untyped-defs
|
| 2 |
+
# defined in torch/csrc/lazy/python/init.cpp
|
| 3 |
+
|
| 4 |
+
from typing import Any
|
| 5 |
+
|
| 6 |
+
from torch import Tensor
|
| 7 |
+
|
| 8 |
+
def _init(): ...
|
| 9 |
+
def _get_tensors_ts_device_data_node(
|
| 10 |
+
tensors: list[Tensor],
|
| 11 |
+
) -> tuple[list[int], list[Any]]: ...
|
| 12 |
+
def _run_cached_graph(hash_str: str, graph_inputs: list[Any]) -> list[Tensor]: ...
|
miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_monitor.pyi
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Defined in torch/csrc/monitor/python_init.cpp
|
| 2 |
+
|
| 3 |
+
import datetime
|
| 4 |
+
from collections.abc import Callable
|
| 5 |
+
from enum import Enum
|
| 6 |
+
from types import TracebackType
|
| 7 |
+
|
| 8 |
+
class Aggregation(Enum):
|
| 9 |
+
VALUE = ...
|
| 10 |
+
MEAN = ...
|
| 11 |
+
COUNT = ...
|
| 12 |
+
SUM = ...
|
| 13 |
+
MAX = ...
|
| 14 |
+
MIN = ...
|
| 15 |
+
|
| 16 |
+
class Stat:
|
| 17 |
+
name: str
|
| 18 |
+
count: int
|
| 19 |
+
def __init__(
|
| 20 |
+
self,
|
| 21 |
+
name: str,
|
| 22 |
+
aggregations: list[Aggregation],
|
| 23 |
+
window_size: int,
|
| 24 |
+
max_samples: int = -1,
|
| 25 |
+
) -> None: ...
|
| 26 |
+
def add(self, v: float) -> None: ...
|
| 27 |
+
def get(self) -> dict[Aggregation, float]: ...
|
| 28 |
+
|
| 29 |
+
class Event:
|
| 30 |
+
name: str
|
| 31 |
+
timestamp: datetime.datetime
|
| 32 |
+
data: dict[str, int | float | bool | str]
|
| 33 |
+
def __init__(
|
| 34 |
+
self,
|
| 35 |
+
name: str,
|
| 36 |
+
timestamp: datetime.datetime,
|
| 37 |
+
data: dict[str, int | float | bool | str],
|
| 38 |
+
) -> None: ...
|
| 39 |
+
|
| 40 |
+
def log_event(e: Event) -> None: ...
|
| 41 |
+
|
| 42 |
+
class EventHandlerHandle: ...
|
| 43 |
+
|
| 44 |
+
def register_event_handler(handler: Callable[[Event], None]) -> EventHandlerHandle: ...
|
| 45 |
+
def unregister_event_handler(handle: EventHandlerHandle) -> None: ...
|
| 46 |
+
|
| 47 |
+
class _WaitCounterTracker:
|
| 48 |
+
def __enter__(self) -> None: ...
|
| 49 |
+
def __exit__(
|
| 50 |
+
self,
|
| 51 |
+
exc_type: type[BaseException] | None = None,
|
| 52 |
+
exc_value: BaseException | None = None,
|
| 53 |
+
traceback: TracebackType | None = None,
|
| 54 |
+
) -> None: ...
|
| 55 |
+
|
| 56 |
+
class _WaitCounter:
|
| 57 |
+
def __init__(self, key: str) -> None: ...
|
| 58 |
+
def guard(self) -> _WaitCounterTracker: ...
|
miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_nn.pyi
ADDED
|
@@ -0,0 +1,341 @@
|
|
|
|
|
|
|
|
|
|
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ools/pyi/gen_pyi.py from torch/_C/_nn.pyi.in
|
| 2 |
+
# mypy: disable-error-code="type-arg"
|
| 3 |
+
|
| 4 |
+
from collections.abc import Sequence
|
| 5 |
+
from typing import Literal, overload
|
| 6 |
+
|
| 7 |
+
from torch import memory_format, Tensor
|
| 8 |
+
from torch.types import _bool, _device, _dtype, _int, _size
|
| 9 |
+
|
| 10 |
+
# Defined in tools/autograd/templates/python_nn_functions.cpp
|
| 11 |
+
|
| 12 |
+
def adaptive_avg_pool2d(input: Tensor, output_size: _int | _size) -> Tensor: ...
|
| 13 |
+
def adaptive_avg_pool3d(input: Tensor, output_size: _int | _size) -> Tensor: ...
|
| 14 |
+
def adaptive_max_pool2d(
|
| 15 |
+
input: Tensor,
|
| 16 |
+
output_size: _int | _size,
|
| 17 |
+
) -> tuple[Tensor, Tensor]: ...
|
| 18 |
+
def adaptive_max_pool3d(
|
| 19 |
+
input: Tensor,
|
| 20 |
+
output_size: _int | _size,
|
| 21 |
+
) -> tuple[Tensor, Tensor]: ...
|
| 22 |
+
def avg_pool2d(
|
| 23 |
+
input: Tensor,
|
| 24 |
+
kernel_size: _int | _size,
|
| 25 |
+
stride: _int | _size | None = None,
|
| 26 |
+
padding: _int | _size = 0,
|
| 27 |
+
ceil_mode: bool = False,
|
| 28 |
+
count_include_pad: bool = True,
|
| 29 |
+
divisor_override: int | None = None,
|
| 30 |
+
) -> Tensor: ...
|
| 31 |
+
def avg_pool3d(
|
| 32 |
+
input: Tensor,
|
| 33 |
+
kernel_size: _int | _size,
|
| 34 |
+
stride: _int | _size | None = None,
|
| 35 |
+
padding: _int | _size = 0,
|
| 36 |
+
ceil_mode: bool = False,
|
| 37 |
+
count_include_pad: bool = True,
|
| 38 |
+
divisor_override: int | None = None,
|
| 39 |
+
) -> Tensor: ...
|
| 40 |
+
def binary_cross_entropy(
|
| 41 |
+
input: Tensor,
|
| 42 |
+
target: Tensor,
|
| 43 |
+
weight: Tensor | None = None,
|
| 44 |
+
reduction: str = ...,
|
| 45 |
+
) -> Tensor: ...
|
| 46 |
+
def col2im(
|
| 47 |
+
input: Tensor,
|
| 48 |
+
output_size: _int | _size,
|
| 49 |
+
kernel_size: _int | _size,
|
| 50 |
+
dilation: _int | _size,
|
| 51 |
+
stride: _int | _size | None = None,
|
| 52 |
+
padding: _int | _size = 0,
|
| 53 |
+
) -> Tensor: ...
|
| 54 |
+
def cross_entropy_loss(
|
| 55 |
+
input: Tensor,
|
| 56 |
+
target: Tensor,
|
| 57 |
+
weight: Tensor | None = None,
|
| 58 |
+
reduction: str = ...,
|
| 59 |
+
ignore_index: int = -100,
|
| 60 |
+
label_smoothing: float = 0.0,
|
| 61 |
+
) -> Tensor: ...
|
| 62 |
+
def elu(
|
| 63 |
+
input: Tensor,
|
| 64 |
+
alpha: float = 1.0,
|
| 65 |
+
scale: float = 1.0,
|
| 66 |
+
input_scale: float = 1.0,
|
| 67 |
+
) -> Tensor: ...
|
| 68 |
+
def elu_(input: Tensor, alpha: float = ...) -> Tensor: ...
|
| 69 |
+
def fractional_max_pool2d(
|
| 70 |
+
input: Tensor,
|
| 71 |
+
kernel_size: _int | _size,
|
| 72 |
+
output_size: _int | _size,
|
| 73 |
+
_random_samples: Tensor,
|
| 74 |
+
) -> tuple[Tensor, Tensor]: ...
|
| 75 |
+
def fractional_max_pool3d(
|
| 76 |
+
input: Tensor,
|
| 77 |
+
kernel_size: _int | _size,
|
| 78 |
+
output_size: _int | _size,
|
| 79 |
+
_random_samples: Tensor,
|
| 80 |
+
) -> tuple[Tensor, Tensor]: ...
|
| 81 |
+
def gelu(input: Tensor, approximate: str = ...) -> Tensor: ...
|
| 82 |
+
def glu(input: Tensor, dim: int = -1) -> Tensor: ...
|
| 83 |
+
def hardsigmoid(input: Tensor, *, out: Tensor | None = None) -> Tensor: ...
|
| 84 |
+
def hardsigmoid_(input: Tensor) -> Tensor: ...
|
| 85 |
+
def hardswish(input: Tensor) -> Tensor: ...
|
| 86 |
+
def hardswish_(input: Tensor) -> Tensor: ...
|
| 87 |
+
def hardtanh(
|
| 88 |
+
input: Tensor,
|
| 89 |
+
min_val: float = ...,
|
| 90 |
+
max_val: float = ...,
|
| 91 |
+
*,
|
| 92 |
+
out: Tensor | None = None,
|
| 93 |
+
) -> Tensor: ...
|
| 94 |
+
def hardtanh_(
|
| 95 |
+
input: Tensor,
|
| 96 |
+
min_val: float = ...,
|
| 97 |
+
max_val: float = ...,
|
| 98 |
+
) -> Tensor: ...
|
| 99 |
+
def huber_loss(
|
| 100 |
+
input: Tensor,
|
| 101 |
+
target: Tensor,
|
| 102 |
+
reduction: str = ...,
|
| 103 |
+
delta: float = 1.0,
|
| 104 |
+
) -> Tensor: ...
|
| 105 |
+
def im2col(
|
| 106 |
+
input: Tensor,
|
| 107 |
+
kernel_size: _int | _size,
|
| 108 |
+
dilation: _int | _size,
|
| 109 |
+
padding: _int | _size,
|
| 110 |
+
stride: _int | _size,
|
| 111 |
+
) -> Tensor: ...
|
| 112 |
+
def l1_loss(input: Tensor, target: Tensor, reduction: str = ...) -> Tensor: ...
|
| 113 |
+
def leaky_relu(
|
| 114 |
+
input: Tensor,
|
| 115 |
+
negative_slope: float = ...,
|
| 116 |
+
*,
|
| 117 |
+
out: Tensor | None = None,
|
| 118 |
+
) -> Tensor: ...
|
| 119 |
+
def leaky_relu_(input: Tensor, negative_slope: float = ...) -> Tensor: ...
|
| 120 |
+
def linear(
|
| 121 |
+
input: Tensor,
|
| 122 |
+
weight: Tensor,
|
| 123 |
+
bias: Tensor | None = None,
|
| 124 |
+
) -> Tensor: ...
|
| 125 |
+
def log_sigmoid(input: Tensor) -> Tensor: ...
|
| 126 |
+
def max_pool2d_with_indices(
|
| 127 |
+
input: Tensor,
|
| 128 |
+
kernel_size: _int | _size,
|
| 129 |
+
stride: _int | _size | None = None,
|
| 130 |
+
padding: _int | _size = 0,
|
| 131 |
+
dilation: _int | _size = 1,
|
| 132 |
+
ceil_mode: bool = False,
|
| 133 |
+
) -> tuple[Tensor, Tensor]: ...
|
| 134 |
+
def max_pool3d_with_indices(
|
| 135 |
+
input: Tensor,
|
| 136 |
+
kernel_size: _int | _size,
|
| 137 |
+
stride: _int | _size | None = None,
|
| 138 |
+
padding: _int | _size = 0,
|
| 139 |
+
dilation: _int | _size = 1,
|
| 140 |
+
ceil_mode: bool = False,
|
| 141 |
+
) -> tuple[Tensor, Tensor]: ...
|
| 142 |
+
def max_unpool2d(
|
| 143 |
+
input: Tensor,
|
| 144 |
+
indices: Tensor,
|
| 145 |
+
output_size: Sequence[int] | None,
|
| 146 |
+
) -> Tensor: ...
|
| 147 |
+
def max_unpool3d(
|
| 148 |
+
input: Tensor,
|
| 149 |
+
indices: Tensor,
|
| 150 |
+
output_size: Sequence[int] | None,
|
| 151 |
+
stride: _int | _size,
|
| 152 |
+
padding: _int | _size,
|
| 153 |
+
) -> Tensor: ...
|
| 154 |
+
def mish(input: Tensor) -> Tensor: ...
|
| 155 |
+
def mish_(input: Tensor) -> Tensor: ...
|
| 156 |
+
def mse_loss(input: Tensor, target: Tensor, reduction: str = ...) -> Tensor: ...
|
| 157 |
+
def multi_margin_loss(
|
| 158 |
+
input: Tensor,
|
| 159 |
+
target: Tensor,
|
| 160 |
+
p: float = 1.0,
|
| 161 |
+
margin: float = 1.0,
|
| 162 |
+
weight: Tensor | None = None,
|
| 163 |
+
reduction: str = ...,
|
| 164 |
+
) -> Tensor: ...
|
| 165 |
+
def multilabel_margin_loss(
|
| 166 |
+
input: Tensor,
|
| 167 |
+
target: Tensor,
|
| 168 |
+
reduction: str = ...,
|
| 169 |
+
) -> Tensor: ...
|
| 170 |
+
def nll_loss_nd(
|
| 171 |
+
input: Tensor,
|
| 172 |
+
target: Tensor,
|
| 173 |
+
weight: Tensor | None = None,
|
| 174 |
+
reduction: str = ...,
|
| 175 |
+
ignore_index: int = -100,
|
| 176 |
+
) -> Tensor: ...
|
| 177 |
+
def one_hot(tensor: Tensor, num_classes: int = ...) -> Tensor: ...
|
| 178 |
+
def pad(
|
| 179 |
+
input: Tensor,
|
| 180 |
+
pad: Sequence[int],
|
| 181 |
+
mode: str = ...,
|
| 182 |
+
value: float | None = None,
|
| 183 |
+
) -> Tensor: ...
|
| 184 |
+
def relu6(input: Tensor) -> Tensor: ...
|
| 185 |
+
def relu6_(input: Tensor) -> Tensor: ...
|
| 186 |
+
def scaled_dot_product_attention(
|
| 187 |
+
query: Tensor,
|
| 188 |
+
key: Tensor,
|
| 189 |
+
value: Tensor,
|
| 190 |
+
attn_mask: Tensor | None = None,
|
| 191 |
+
dropout_p: float = 0.0,
|
| 192 |
+
is_causal: bool = False,
|
| 193 |
+
scale: float | None = None,
|
| 194 |
+
enable_gqa: bool = False,
|
| 195 |
+
) -> Tensor: ...
|
| 196 |
+
def silu(input: Tensor) -> Tensor: ...
|
| 197 |
+
def silu_(input: Tensor) -> Tensor: ...
|
| 198 |
+
def smooth_l1_loss(
|
| 199 |
+
input: Tensor,
|
| 200 |
+
target: Tensor,
|
| 201 |
+
reduction: str = ...,
|
| 202 |
+
beta: float = 1.0,
|
| 203 |
+
) -> Tensor: ...
|
| 204 |
+
def soft_margin_loss(
|
| 205 |
+
input: Tensor,
|
| 206 |
+
target: Tensor,
|
| 207 |
+
reduction: str = ...,
|
| 208 |
+
) -> Tensor: ...
|
| 209 |
+
def softplus(
|
| 210 |
+
input: Tensor,
|
| 211 |
+
beta: float = ...,
|
| 212 |
+
threshold: float = ...,
|
| 213 |
+
) -> Tensor: ...
|
| 214 |
+
def softshrink(input: Tensor, lambd: float = ...) -> Tensor: ...
|
| 215 |
+
|
| 216 |
+
# Defined in aten/src/ATen/native/mkldnn/Linear.cpp
|
| 217 |
+
def mkldnn_linear(input: Tensor, weight: Tensor, bias: Tensor | None) -> Tensor: ...
|
| 218 |
+
|
| 219 |
+
# Defined at aten/src/ATen/native/mkldnn/MKLDNNConversions.cpp
|
| 220 |
+
def mkldnn_reorder_conv2d_weight(
|
| 221 |
+
self: Tensor,
|
| 222 |
+
padding: list,
|
| 223 |
+
stride: list,
|
| 224 |
+
dilatation: list,
|
| 225 |
+
groups: int,
|
| 226 |
+
) -> Tensor: ...
|
| 227 |
+
def mkldnn_reorder_conv3d_weight(
|
| 228 |
+
self: Tensor,
|
| 229 |
+
padding: list,
|
| 230 |
+
stride: list,
|
| 231 |
+
dilatation: list,
|
| 232 |
+
groups: int,
|
| 233 |
+
) -> Tensor: ...
|
| 234 |
+
|
| 235 |
+
# Defined in aten/src/ATen/native/mkldnn/Prelu.cpp
|
| 236 |
+
def mkldnn_prelu(input: Tensor, weight: Tensor) -> Tensor: ...
|
| 237 |
+
|
| 238 |
+
# Defined at tools/autograd/templates/python_nn_functions.cpp
|
| 239 |
+
@overload
|
| 240 |
+
def _parse_to(
|
| 241 |
+
device: _device,
|
| 242 |
+
dtype: _dtype,
|
| 243 |
+
non_blocking: _bool,
|
| 244 |
+
copy: _bool,
|
| 245 |
+
*,
|
| 246 |
+
memory_format: memory_format,
|
| 247 |
+
) -> tuple[_device, _dtype, _bool, memory_format]: ...
|
| 248 |
+
@overload
|
| 249 |
+
def _parse_to(
|
| 250 |
+
dtype: _dtype,
|
| 251 |
+
non_blocking: _bool,
|
| 252 |
+
copy: _bool,
|
| 253 |
+
*,
|
| 254 |
+
memory_format: memory_format,
|
| 255 |
+
) -> tuple[_device, _dtype, _bool, memory_format]: ...
|
| 256 |
+
@overload
|
| 257 |
+
def _parse_to(
|
| 258 |
+
tensor: Tensor,
|
| 259 |
+
non_blocking: _bool,
|
| 260 |
+
copy: _bool,
|
| 261 |
+
*,
|
| 262 |
+
memory_format: memory_format,
|
| 263 |
+
) -> tuple[_device, _dtype, _bool, memory_format]: ...
|
| 264 |
+
|
| 265 |
+
# Defined in aten/src/ATen/native/PackedSequence.cpp
|
| 266 |
+
def pad_sequence(
|
| 267 |
+
sequences: list[Tensor] | tuple[Tensor, ...],
|
| 268 |
+
batch_first: bool = False,
|
| 269 |
+
padding_value: float = 0.0,
|
| 270 |
+
padding_side: Literal["left", "right"] = "right",
|
| 271 |
+
) -> Tensor: ...
|
| 272 |
+
|
| 273 |
+
# Upsample functions used by torch.nn.functional.interpolate
|
| 274 |
+
def upsample_nearest1d(
|
| 275 |
+
input: Tensor,
|
| 276 |
+
output_size: Sequence[int] | None,
|
| 277 |
+
scale_factors: Sequence[float] | None,
|
| 278 |
+
) -> Tensor: ...
|
| 279 |
+
def upsample_nearest2d(
|
| 280 |
+
input: Tensor,
|
| 281 |
+
output_size: Sequence[int] | None,
|
| 282 |
+
scale_factors: Sequence[float] | None,
|
| 283 |
+
) -> Tensor: ...
|
| 284 |
+
def upsample_nearest3d(
|
| 285 |
+
input: Tensor,
|
| 286 |
+
output_size: Sequence[int] | None,
|
| 287 |
+
scale_factors: Sequence[float] | None,
|
| 288 |
+
) -> Tensor: ...
|
| 289 |
+
def _upsample_nearest_exact1d(
|
| 290 |
+
input: Tensor,
|
| 291 |
+
output_size: Sequence[int] | None,
|
| 292 |
+
scale_factors: Sequence[float] | None,
|
| 293 |
+
) -> Tensor: ...
|
| 294 |
+
def _upsample_nearest_exact2d(
|
| 295 |
+
input: Tensor,
|
| 296 |
+
output_size: Sequence[int] | None,
|
| 297 |
+
scale_factors: Sequence[float] | None,
|
| 298 |
+
) -> Tensor: ...
|
| 299 |
+
def _upsample_nearest_exact3d(
|
| 300 |
+
input: Tensor,
|
| 301 |
+
output_size: Sequence[int] | None,
|
| 302 |
+
scale_factors: Sequence[float] | None,
|
| 303 |
+
) -> Tensor: ...
|
| 304 |
+
def upsample_linear1d(
|
| 305 |
+
input: Tensor,
|
| 306 |
+
output_size: Sequence[int] | None,
|
| 307 |
+
align_corners: bool,
|
| 308 |
+
scale_factors: Sequence[float] | None,
|
| 309 |
+
) -> Tensor: ...
|
| 310 |
+
def _upsample_bilinear2d_aa(
|
| 311 |
+
input: Tensor,
|
| 312 |
+
output_size: Sequence[int] | None,
|
| 313 |
+
align_corners: bool,
|
| 314 |
+
scale_factors: Sequence[float] | None,
|
| 315 |
+
) -> Tensor: ...
|
| 316 |
+
def upsample_bilinear2d(
|
| 317 |
+
input: Tensor,
|
| 318 |
+
output_size: Sequence[int] | None,
|
| 319 |
+
align_corners: bool,
|
| 320 |
+
scale_factors: Sequence[float] | None,
|
| 321 |
+
) -> Tensor: ...
|
| 322 |
+
def upsample_trilinear3d(
|
| 323 |
+
input: Tensor,
|
| 324 |
+
output_size: Sequence[int] | None,
|
| 325 |
+
align_corners: bool,
|
| 326 |
+
scale_factors: Sequence[float] | None,
|
| 327 |
+
) -> Tensor: ...
|
| 328 |
+
def _upsample_bicubic2d_aa(
|
| 329 |
+
input: Tensor,
|
| 330 |
+
output_size: Sequence[int] | None,
|
| 331 |
+
align_corners: bool,
|
| 332 |
+
scale_factors: Sequence[float] | None,
|
| 333 |
+
) -> Tensor: ...
|
| 334 |
+
def upsample_bicubic2d(
|
| 335 |
+
input: Tensor,
|
| 336 |
+
output_size: Sequence[int] | None,
|
| 337 |
+
align_corners: bool,
|
| 338 |
+
scale_factors: Sequence[float] | None,
|
| 339 |
+
) -> Tensor: ...
|
| 340 |
+
def flatten_dense_tensors(tensors: list[Tensor]) -> Tensor: ...
|
| 341 |
+
def unflatten_dense_tensors(flat: Tensor, tensors: list[Tensor]) -> list[Tensor]: ...
|
miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_nvtx.pyi
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# mypy: allow-untyped-defs
|
| 2 |
+
# Defined in torch/csrc/cuda/shared/nvtx.cpp
|
| 3 |
+
def rangePushA(message: str) -> int: ...
|
| 4 |
+
def rangePop() -> int: ...
|
| 5 |
+
def rangeStartA(message: str) -> int: ...
|
| 6 |
+
def rangeEnd(int) -> None: ...
|
| 7 |
+
def markA(message: str) -> None: ...
|
| 8 |
+
def deviceRangeStart(message: str, stream: int) -> object: ...
|
| 9 |
+
def deviceRangeEnd(range_handle: object, stream: int) -> None: ...
|
miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_onnx.pyi
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Defined in torch/csrc/onnx/init.cpp
|
| 2 |
+
|
| 3 |
+
from enum import Enum
|
| 4 |
+
|
| 5 |
+
PRODUCER_VERSION: str
|
| 6 |
+
|
| 7 |
+
class TensorProtoDataType(Enum):
|
| 8 |
+
UNDEFINED = ...
|
| 9 |
+
FLOAT = ...
|
| 10 |
+
UINT8 = ...
|
| 11 |
+
INT8 = ...
|
| 12 |
+
UINT16 = ...
|
| 13 |
+
INT16 = ...
|
| 14 |
+
INT32 = ...
|
| 15 |
+
INT64 = ...
|
| 16 |
+
STRING = ...
|
| 17 |
+
BOOL = ...
|
| 18 |
+
FLOAT16 = ...
|
| 19 |
+
DOUBLE = ...
|
| 20 |
+
UINT32 = ...
|
| 21 |
+
UINT64 = ...
|
| 22 |
+
COMPLEX64 = ...
|
| 23 |
+
COMPLEX128 = ...
|
| 24 |
+
BFLOAT16 = ...
|
| 25 |
+
FLOAT8E5M2 = ...
|
| 26 |
+
FLOAT8E4M3FN = ...
|
| 27 |
+
FLOAT8E5M2FNUZ = ...
|
| 28 |
+
FLOAT8E4M3FNUZ = ...
|
| 29 |
+
|
| 30 |
+
class OperatorExportTypes(Enum):
|
| 31 |
+
ONNX = ...
|
| 32 |
+
ONNX_ATEN = ...
|
| 33 |
+
ONNX_ATEN_FALLBACK = ...
|
| 34 |
+
ONNX_FALLTHROUGH = ...
|
| 35 |
+
|
| 36 |
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from enum import Enum
|
| 2 |
+
from typing import Literal, TypeAlias
|
| 3 |
+
|
| 4 |
+
from torch._C import device, dtype, layout
|
| 5 |
+
|
| 6 |
+
# defined in torch/csrc/profiler/python/init.cpp
|
| 7 |
+
|
| 8 |
+
class RecordScope(Enum):
|
| 9 |
+
FUNCTION = ...
|
| 10 |
+
BACKWARD_FUNCTION = ...
|
| 11 |
+
TORCHSCRIPT_FUNCTION = ...
|
| 12 |
+
KERNEL_FUNCTION_DTYPE = ...
|
| 13 |
+
CUSTOM_CLASS = ...
|
| 14 |
+
BUILD_FEATURE = ...
|
| 15 |
+
LITE_INTERPRETER = ...
|
| 16 |
+
USER_SCOPE = ...
|
| 17 |
+
STATIC_RUNTIME_OP = ...
|
| 18 |
+
STATIC_RUNTIME_MODEL = ...
|
| 19 |
+
|
| 20 |
+
class ProfilerState(Enum):
|
| 21 |
+
Disabled = ...
|
| 22 |
+
CPU = ...
|
| 23 |
+
CUDA = ...
|
| 24 |
+
NVTX = ...
|
| 25 |
+
ITT = ...
|
| 26 |
+
PRIVATEUSE1 = ...
|
| 27 |
+
KINETO = ...
|
| 28 |
+
KINETO_GPU_FALLBACK = ...
|
| 29 |
+
KINETO_PRIVATEUSE1_FALLBACK = ...
|
| 30 |
+
|
| 31 |
+
class ActiveProfilerType(Enum):
|
| 32 |
+
NONE = ...
|
| 33 |
+
LEGACY = ...
|
| 34 |
+
KINETO = ...
|
| 35 |
+
NVTX = ...
|
| 36 |
+
ITT = ...
|
| 37 |
+
PRIVATEUSE1 = ...
|
| 38 |
+
|
| 39 |
+
class ProfilerActivity(Enum):
|
| 40 |
+
CPU = ...
|
| 41 |
+
CUDA = ...
|
| 42 |
+
XPU = ...
|
| 43 |
+
MTIA = ...
|
| 44 |
+
HPU = ...
|
| 45 |
+
PrivateUse1 = ...
|
| 46 |
+
|
| 47 |
+
class _EventType(Enum):
|
| 48 |
+
TorchOp = ...
|
| 49 |
+
Backend = ...
|
| 50 |
+
Allocation = ...
|
| 51 |
+
OutOfMemory = ...
|
| 52 |
+
PyCall = ...
|
| 53 |
+
PyCCall = ...
|
| 54 |
+
Kineto = ...
|
| 55 |
+
|
| 56 |
+
class _ExperimentalConfig:
|
| 57 |
+
def __init__(
|
| 58 |
+
self,
|
| 59 |
+
profiler_metrics: list[str] = ...,
|
| 60 |
+
profiler_measure_per_kernel: bool = ...,
|
| 61 |
+
verbose: bool = ...,
|
| 62 |
+
performance_events: list[str] = ...,
|
| 63 |
+
enable_cuda_sync_events: bool = ...,
|
| 64 |
+
profile_all_threads: bool = ...,
|
| 65 |
+
) -> None: ...
|
| 66 |
+
|
| 67 |
+
class ProfilerConfig:
|
| 68 |
+
def __init__(
|
| 69 |
+
self,
|
| 70 |
+
state: ProfilerState,
|
| 71 |
+
report_input_shapes: bool,
|
| 72 |
+
profile_memory: bool,
|
| 73 |
+
with_stack: bool,
|
| 74 |
+
with_flops: bool,
|
| 75 |
+
with_modules: bool,
|
| 76 |
+
experimental_config: _ExperimentalConfig,
|
| 77 |
+
trace_id: str | None = None,
|
| 78 |
+
) -> None: ...
|
| 79 |
+
|
| 80 |
+
class _ProfilerEvent:
|
| 81 |
+
start_tid: int
|
| 82 |
+
start_time_ns: int
|
| 83 |
+
children: list[_ProfilerEvent]
|
| 84 |
+
|
| 85 |
+
# TODO(robieta): remove in favor of `self.typed`
|
| 86 |
+
extra_fields: (
|
| 87 |
+
_ExtraFields_TorchOp
|
| 88 |
+
| _ExtraFields_Backend
|
| 89 |
+
| _ExtraFields_Allocation
|
| 90 |
+
| _ExtraFields_OutOfMemory
|
| 91 |
+
| _ExtraFields_PyCall
|
| 92 |
+
| _ExtraFields_PyCCall
|
| 93 |
+
| _ExtraFields_Kineto
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
@property
|
| 97 |
+
def typed(
|
| 98 |
+
self,
|
| 99 |
+
) -> (
|
| 100 |
+
tuple[Literal[_EventType.TorchOp], _ExtraFields_TorchOp]
|
| 101 |
+
| tuple[Literal[_EventType.Backend], _ExtraFields_Backend]
|
| 102 |
+
| tuple[Literal[_EventType.Allocation], _ExtraFields_Allocation]
|
| 103 |
+
| tuple[Literal[_EventType.OutOfMemory], _ExtraFields_OutOfMemory]
|
| 104 |
+
| tuple[Literal[_EventType.PyCall], _ExtraFields_PyCall]
|
| 105 |
+
| tuple[Literal[_EventType.PyCCall], _ExtraFields_PyCCall]
|
| 106 |
+
| tuple[Literal[_EventType.Kineto], _ExtraFields_Kineto]
|
| 107 |
+
): ...
|
| 108 |
+
@property
|
| 109 |
+
def name(self) -> str: ...
|
| 110 |
+
@property
|
| 111 |
+
def tag(self) -> _EventType: ...
|
| 112 |
+
@property
|
| 113 |
+
def id(self) -> int: ...
|
| 114 |
+
@property
|
| 115 |
+
def parent(self) -> _ProfilerEvent | None: ...
|
| 116 |
+
@property
|
| 117 |
+
def correlation_id(self) -> int: ...
|
| 118 |
+
@property
|
| 119 |
+
def end_time_ns(self) -> int: ...
|
| 120 |
+
@property
|
| 121 |
+
def duration_time_ns(self) -> int: ...
|
| 122 |
+
|
| 123 |
+
class _TensorMetadata:
|
| 124 |
+
impl_ptr: int | None
|
| 125 |
+
storage_data_ptr: int | None
|
| 126 |
+
id: int | None
|
| 127 |
+
|
| 128 |
+
@property
|
| 129 |
+
def allocation_id(self) -> int | None: ...
|
| 130 |
+
@property
|
| 131 |
+
def layout(self) -> layout: ...
|
| 132 |
+
@property
|
| 133 |
+
def device(self) -> device: ...
|
| 134 |
+
@property
|
| 135 |
+
def dtype(self) -> dtype: ...
|
| 136 |
+
@property
|
| 137 |
+
def sizes(self) -> list[int]: ...
|
| 138 |
+
@property
|
| 139 |
+
def strides(self) -> list[int]: ...
|
| 140 |
+
|
| 141 |
+
Scalar: TypeAlias = int | float | bool | complex
|
| 142 |
+
Input: TypeAlias = _TensorMetadata | list[_TensorMetadata] | Scalar | None
|
| 143 |
+
|
| 144 |
+
class _ExtraFields_TorchOp:
|
| 145 |
+
name: str
|
| 146 |
+
sequence_number: int
|
| 147 |
+
allow_tf32_cublas: bool
|
| 148 |
+
|
| 149 |
+
@property
|
| 150 |
+
def inputs(self) -> list[Input]: ...
|
| 151 |
+
@property
|
| 152 |
+
def scope(self) -> RecordScope: ...
|
| 153 |
+
|
| 154 |
+
class _ExtraFields_Backend: ...
|
| 155 |
+
|
| 156 |
+
class _ExtraFields_Allocation:
|
| 157 |
+
ptr: int
|
| 158 |
+
id: int | None
|
| 159 |
+
alloc_size: int
|
| 160 |
+
total_allocated: int
|
| 161 |
+
total_reserved: int
|
| 162 |
+
|
| 163 |
+
@property
|
| 164 |
+
def allocation_id(self) -> int | None: ...
|
| 165 |
+
@property
|
| 166 |
+
def device(self) -> device: ...
|
| 167 |
+
|
| 168 |
+
class _ExtraFields_OutOfMemory: ...
|
| 169 |
+
|
| 170 |
+
class _PyFrameState:
|
| 171 |
+
line_number: int
|
| 172 |
+
function_name: str
|
| 173 |
+
|
| 174 |
+
@property
|
| 175 |
+
def file_name(self) -> str: ...
|
| 176 |
+
|
| 177 |
+
class _NNModuleInfo:
|
| 178 |
+
@property
|
| 179 |
+
def self_ptr(self) -> int: ...
|
| 180 |
+
@property
|
| 181 |
+
def cls_ptr(self) -> int: ...
|
| 182 |
+
@property
|
| 183 |
+
def cls_name(self) -> str: ...
|
| 184 |
+
@property
|
| 185 |
+
def parameters(
|
| 186 |
+
self,
|
| 187 |
+
) -> list[tuple[str, _TensorMetadata, _TensorMetadata | None]]: ...
|
| 188 |
+
|
| 189 |
+
class _OptimizerInfo:
|
| 190 |
+
@property
|
| 191 |
+
def parameters(
|
| 192 |
+
self,
|
| 193 |
+
) -> list[
|
| 194 |
+
tuple[
|
| 195 |
+
# Parameter
|
| 196 |
+
_TensorMetadata,
|
| 197 |
+
#
|
| 198 |
+
# Gradient (if present during optimizer.step())
|
| 199 |
+
_TensorMetadata | None,
|
| 200 |
+
#
|
| 201 |
+
# Optimizer state for Parameter as (name, tensor) pairs
|
| 202 |
+
list[tuple[str, _TensorMetadata]],
|
| 203 |
+
]
|
| 204 |
+
]: ...
|
| 205 |
+
|
| 206 |
+
class _ExtraFields_PyCCall:
|
| 207 |
+
@property
|
| 208 |
+
def caller(self) -> _PyFrameState: ...
|
| 209 |
+
|
| 210 |
+
class _ExtraFields_PyCall:
|
| 211 |
+
@property
|
| 212 |
+
def callsite(self) -> _PyFrameState: ...
|
| 213 |
+
@property
|
| 214 |
+
def caller(self) -> _PyFrameState: ...
|
| 215 |
+
@property
|
| 216 |
+
def module(self) -> _NNModuleInfo | None: ...
|
| 217 |
+
@property
|
| 218 |
+
def optimizer(self) -> _OptimizerInfo | None: ...
|
| 219 |
+
|
| 220 |
+
class _ExtraFields_Kineto: ...
|
| 221 |
+
|
| 222 |
+
def _add_execution_trace_observer(output_file_path: str) -> bool: ...
|
| 223 |
+
def _remove_execution_trace_observer() -> None: ...
|
| 224 |
+
def _enable_execution_trace_observer() -> None: ...
|
| 225 |
+
def _disable_execution_trace_observer() -> None: ...
|
| 226 |
+
def _set_record_concrete_inputs_enabled_val(val: bool) -> None: ...
|
| 227 |
+
def _set_fwd_bwd_enabled_val(val: bool) -> None: ...
|
| 228 |
+
def _set_cuda_sync_enabled_val(val: bool) -> None: ...
|
| 229 |
+
|
| 230 |
+
class CapturedTraceback: ...
|
| 231 |
+
|
| 232 |
+
def gather_traceback(python: bool, script: bool, cpp: bool) -> CapturedTraceback: ...
|
| 233 |
+
|
| 234 |
+
# The Dict has name, filename, line
|
| 235 |
+
def symbolize_tracebacks(
|
| 236 |
+
to_symbolize: list[CapturedTraceback],
|
| 237 |
+
) -> list[list[dict[str, str]]]: ...
|
| 238 |
+
|
| 239 |
+
class _RecordFunctionFast:
|
| 240 |
+
def __init__(
|
| 241 |
+
self,
|
| 242 |
+
name: str,
|
| 243 |
+
input_values: list | tuple | None = None,
|
| 244 |
+
keyword_values: dict | None = None,
|
| 245 |
+
) -> None: ...
|
| 246 |
+
def __enter__(self) -> None: ...
|
| 247 |
+
def __exit__(self, *exc_info: object) -> None: ...
|
miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C/_verbose.pyi
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Defined in torch/csrc/utils/verbose.cpp
|
| 2 |
+
def mkl_set_verbose(enable: int) -> int: ...
|
| 3 |
+
def mkldnn_set_verbose(level: int) -> int: ...
|
miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_C_flatbuffer/__init__.pyi
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# mypy: allow-untyped-defs
|
| 2 |
+
from torch._C import LiteScriptModule, ScriptModule
|
| 3 |
+
|
| 4 |
+
def _load_mobile_module_from_file(filename: str): ...
|
| 5 |
+
def _load_mobile_module_from_bytes(bytes_: bytes): ...
|
| 6 |
+
def _load_jit_module_from_file(filename: str): ...
|
| 7 |
+
def _load_jit_module_from_bytes(bytes_: bytes): ...
|
| 8 |
+
def _save_mobile_module(m: LiteScriptModule, filename: str): ...
|
| 9 |
+
def _save_jit_module(m: ScriptModule, filename: str): ...
|
| 10 |
+
def _save_mobile_module_to_bytes(m: LiteScriptModule) -> bytes: ...
|
| 11 |
+
def _save_jit_module_to_bytes(m: ScriptModule) -> bytes: ...
|
miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_VF.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
This makes the functions in torch._C._VariableFunctions available as
|
| 3 |
+
torch._VF.<funcname>
|
| 4 |
+
without mypy being able to find them.
|
| 5 |
+
|
| 6 |
+
A subset of those functions are mapped to ATen functions in
|
| 7 |
+
torch/jit/_builtins.py
|
| 8 |
+
|
| 9 |
+
See https://github.com/pytorch/pytorch/issues/21478 for the reason for
|
| 10 |
+
introducing torch._VF
|
| 11 |
+
|
| 12 |
+
"""
|
| 13 |
+
|
| 14 |
+
import sys
|
| 15 |
+
import types
|
| 16 |
+
|
| 17 |
+
import torch
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
class VFModule(types.ModuleType):
|
| 21 |
+
vf: types.ModuleType
|
| 22 |
+
|
| 23 |
+
def __init__(self, name: str):
|
| 24 |
+
super().__init__(name)
|
| 25 |
+
self.vf = torch._C._VariableFunctions
|
| 26 |
+
|
| 27 |
+
def __getattr__(self, name: str) -> object:
|
| 28 |
+
return getattr(self.vf, name)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
sys.modules[__name__] = VFModule(__name__)
|
miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_VF.pyi
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
miniconda3/envs/ladir/lib/python3.10/site-packages/torch/__config__.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
def show() -> str:
|
| 5 |
+
"""
|
| 6 |
+
Return a human-readable string with descriptions of the
|
| 7 |
+
configuration of PyTorch.
|
| 8 |
+
"""
|
| 9 |
+
return torch._C._show_config()
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
# TODO: In principle, we could provide more structured version/config
|
| 13 |
+
# information here. For now only CXX_FLAGS is exposed, as Timer
|
| 14 |
+
# uses them.
|
| 15 |
+
def _cxx_flags() -> str:
|
| 16 |
+
"""Returns the CXX_FLAGS used when building PyTorch."""
|
| 17 |
+
return torch._C._cxx_flags()
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def parallel_info() -> str:
|
| 21 |
+
r"""Returns detailed string with parallelization settings"""
|
| 22 |
+
return torch._C._parallel_info()
|
miniconda3/envs/ladir/lib/python3.10/site-packages/torch/__future__.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
_overwrite_module_params_on_conversion: bool = False
|
| 2 |
+
_swap_module_params_on_conversion: bool = False
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def set_overwrite_module_params_on_conversion(value: bool) -> None:
|
| 6 |
+
"""
|
| 7 |
+
Sets whether to assign new tensors to the parameters instead of changing the
|
| 8 |
+
existing parameters in-place when converting an ``nn.Module``.
|
| 9 |
+
|
| 10 |
+
When enabled, the following methods will assign new parameters to the module:
|
| 11 |
+
|
| 12 |
+
#. ``module.{device}()`` (e.g. :meth:`nn.Module.cuda()`) for moving a module between devices
|
| 13 |
+
#. ``module.{dtype}()`` (e.g. :meth:`nn.Module.float()`) for converting a module to a different dtype
|
| 14 |
+
#. :meth:`nn.Module.to`
|
| 15 |
+
#. :meth:`nn.Module.to_empty`
|
| 16 |
+
|
| 17 |
+
Args:
|
| 18 |
+
value (bool): Whether to assign new tensors or not.
|
| 19 |
+
|
| 20 |
+
"""
|
| 21 |
+
global _overwrite_module_params_on_conversion
|
| 22 |
+
_overwrite_module_params_on_conversion = value
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def get_overwrite_module_params_on_conversion() -> bool:
|
| 26 |
+
"""
|
| 27 |
+
Returns whether to assign new tensors to the parameters instead of changing the
|
| 28 |
+
existing parameters in-place when converting an :class:`torch.nn.Module`. Defaults to ``False``.
|
| 29 |
+
|
| 30 |
+
See :func:`~torch.__future__.set_overwrite_module_params_on_conversion` for more information.
|
| 31 |
+
"""
|
| 32 |
+
return _overwrite_module_params_on_conversion
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def set_swap_module_params_on_conversion(value: bool) -> None:
|
| 36 |
+
"""
|
| 37 |
+
Sets whether to use :func:`~torch.utils.swap_tensors` instead of setting ``.data`` to
|
| 38 |
+
change the existing parameters in-place when converting an ``nn.Module`` and instead
|
| 39 |
+
of ``param.copy_(state_dict[key])`` when loading a state dict into an ``nn.Module``.
|
| 40 |
+
|
| 41 |
+
.. note::
|
| 42 |
+
This function takes precedence over :func:`~torch.__future__.get_overwrite_module_params_on_conversion`
|
| 43 |
+
|
| 44 |
+
When enabled, the following methods will swap the existing parameters in-place:
|
| 45 |
+
|
| 46 |
+
#. ``module.{device}()`` (e.g. :meth:`nn.Module.cuda()`) for moving a module between devices
|
| 47 |
+
#. ``module.{dtype}()`` (e.g. :meth:`nn.Module.float()`) for converting a module to a different dtype
|
| 48 |
+
#. :meth:`nn.Module.to`
|
| 49 |
+
#. :meth:`nn.Module.to_empty`
|
| 50 |
+
#. :meth:`nn.Module.load_state_dict`
|
| 51 |
+
|
| 52 |
+
The semantics for :meth:`~nn.Module.load_state_dict` when this is set are as follows:
|
| 53 |
+
|
| 54 |
+
#. For each parameter/buffer, its corresponding ``state_dict['key']`` is transformed via
|
| 55 |
+
:meth:`~torch.Tensor.module_load` (i.e. ``res = param.module_load(state_dict['key'])``)
|
| 56 |
+
#. If necessary, ``res`` will be wrapped in an :class:`~nn.Parameter`
|
| 57 |
+
#. The parameter/buffer in the module will be swapped via :func:`~torch.utils.swap_tensors`
|
| 58 |
+
with ``res``
|
| 59 |
+
|
| 60 |
+
Args:
|
| 61 |
+
value (bool): Whether to use :func:`~torch.utils.swap_tensors` or not.
|
| 62 |
+
|
| 63 |
+
"""
|
| 64 |
+
global _swap_module_params_on_conversion
|
| 65 |
+
_swap_module_params_on_conversion = value
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def get_swap_module_params_on_conversion() -> bool:
|
| 69 |
+
"""
|
| 70 |
+
Returns whether to use :func:`~torch.utils.swap_tensors` instead of setting .data to
|
| 71 |
+
change the existing parameters in-place when converting an ``nn.Module``. Defaults to ``False``.
|
| 72 |
+
|
| 73 |
+
See :func:`~torch.__future__.set_swap_module_params_on_conversion` for more information.
|
| 74 |
+
"""
|
| 75 |
+
return _swap_module_params_on_conversion
|
miniconda3/envs/ladir/lib/python3.10/site-packages/torch/__init__.py
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_appdirs.py
ADDED
|
@@ -0,0 +1,666 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
# Copyright (c) 2005-2010 ActiveState Software Inc.
|
| 4 |
+
# Copyright (c) 2013 Eddy Petrișor
|
| 5 |
+
|
| 6 |
+
# flake8: noqa
|
| 7 |
+
|
| 8 |
+
"""
|
| 9 |
+
This file is directly from
|
| 10 |
+
https://github.com/ActiveState/appdirs/blob/3fe6a83776843a46f20c2e5587afcffe05e03b39/appdirs.py
|
| 11 |
+
|
| 12 |
+
The license of https://github.com/ActiveState/appdirs copied below:
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
# This is the MIT license
|
| 16 |
+
|
| 17 |
+
Copyright (c) 2010 ActiveState Software Inc.
|
| 18 |
+
|
| 19 |
+
Permission is hereby granted, free of charge, to any person obtaining a
|
| 20 |
+
copy of this software and associated documentation files (the
|
| 21 |
+
"Software"), to deal in the Software without restriction, including
|
| 22 |
+
without limitation the rights to use, copy, modify, merge, publish,
|
| 23 |
+
distribute, sublicense, and/or sell copies of the Software, and to
|
| 24 |
+
permit persons to whom the Software is furnished to do so, subject to
|
| 25 |
+
the following conditions:
|
| 26 |
+
|
| 27 |
+
The above copyright notice and this permission notice shall be included
|
| 28 |
+
in all copies or substantial portions of the Software.
|
| 29 |
+
|
| 30 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
| 31 |
+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
| 32 |
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
| 33 |
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
| 34 |
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
| 35 |
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
| 36 |
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
| 37 |
+
"""
|
| 38 |
+
|
| 39 |
+
"""Utilities for determining application-specific dirs.
|
| 40 |
+
|
| 41 |
+
See <https://github.com/ActiveState/appdirs> for details and usage.
|
| 42 |
+
"""
|
| 43 |
+
# Dev Notes:
|
| 44 |
+
# - Windows "Known Folders": https://learn.microsoft.com/en-us/windows/win32/shell/csidl
|
| 45 |
+
# - macOS File System Programming Guide: https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/Introduction/Introduction.html
|
| 46 |
+
# - XDG spec for Un*x: https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
|
| 47 |
+
|
| 48 |
+
__version__ = "1.4.4"
|
| 49 |
+
__version_info__ = tuple(int(segment) for segment in __version__.split("."))
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
import os
|
| 53 |
+
import sys
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
unicode = str
|
| 57 |
+
|
| 58 |
+
if sys.platform.startswith("java"):
|
| 59 |
+
import platform
|
| 60 |
+
|
| 61 |
+
os_name = platform.java_ver()[3][0]
|
| 62 |
+
if os_name.startswith("Windows"): # "Windows XP", "Windows 7", etc.
|
| 63 |
+
system = "win32"
|
| 64 |
+
elif os_name.startswith("Mac"): # "Mac OS X", etc.
|
| 65 |
+
system = "darwin"
|
| 66 |
+
else: # "Linux", "SunOS", "FreeBSD", etc.
|
| 67 |
+
# Setting this to "linux2" is not ideal, but only Windows or Mac
|
| 68 |
+
# are actually checked for and the rest of the module expects
|
| 69 |
+
# *sys.platform* style strings.
|
| 70 |
+
system = "linux2"
|
| 71 |
+
else:
|
| 72 |
+
system = sys.platform
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
def user_data_dir(appname=None, appauthor=None, version=None, roaming=False):
|
| 76 |
+
r"""Return full path to the user-specific data dir for this application.
|
| 77 |
+
|
| 78 |
+
"appname" is the name of application.
|
| 79 |
+
If None, just the system directory is returned.
|
| 80 |
+
"appauthor" (only used on Windows) is the name of the
|
| 81 |
+
appauthor or distributing body for this application. Typically
|
| 82 |
+
it is the owning company name. This falls back to appname. You may
|
| 83 |
+
pass False to disable it.
|
| 84 |
+
"version" is an optional version path element to append to the
|
| 85 |
+
path. You might want to use this if you want multiple versions
|
| 86 |
+
of your app to be able to run independently. If used, this
|
| 87 |
+
would typically be "<major>.<minor>".
|
| 88 |
+
Only applied when appname is present.
|
| 89 |
+
"roaming" (boolean, default False) can be set True to use the Windows
|
| 90 |
+
roaming appdata directory. That means that for users on a Windows
|
| 91 |
+
network setup for roaming profiles, this user data will be
|
| 92 |
+
sync'd on login. See
|
| 93 |
+
<http://technet.microsoft.com/en-us/library/cc766489(WS.10).aspx>
|
| 94 |
+
for a discussion of issues.
|
| 95 |
+
|
| 96 |
+
Typical user data directories are:
|
| 97 |
+
Mac OS X: ~/Library/Application Support/<AppName>
|
| 98 |
+
Unix: ~/.local/share/<AppName> # or in $XDG_DATA_HOME, if defined
|
| 99 |
+
Win XP (not roaming): C:\Documents and Settings\<username>\Application Data\<AppAuthor>\<AppName>
|
| 100 |
+
Win XP (roaming): C:\Documents and Settings\<username>\Local Settings\Application Data\<AppAuthor>\<AppName>
|
| 101 |
+
Win 7 (not roaming): C:\Users\<username>\AppData\Local\<AppAuthor>\<AppName>
|
| 102 |
+
Win 7 (roaming): C:\Users\<username>\AppData\Roaming\<AppAuthor>\<AppName>
|
| 103 |
+
|
| 104 |
+
For Unix, we follow the XDG spec and support $XDG_DATA_HOME.
|
| 105 |
+
That means, by default "~/.local/share/<AppName>".
|
| 106 |
+
"""
|
| 107 |
+
if system == "win32":
|
| 108 |
+
if appauthor is None:
|
| 109 |
+
appauthor = appname
|
| 110 |
+
const = roaming and "CSIDL_APPDATA" or "CSIDL_LOCAL_APPDATA"
|
| 111 |
+
path = os.path.normpath(_get_win_folder(const))
|
| 112 |
+
if appname:
|
| 113 |
+
if appauthor is not False:
|
| 114 |
+
path = os.path.join(path, appauthor, appname)
|
| 115 |
+
else:
|
| 116 |
+
path = os.path.join(path, appname)
|
| 117 |
+
elif system == "darwin":
|
| 118 |
+
path = os.path.expanduser("~/Library/Application Support/")
|
| 119 |
+
if appname:
|
| 120 |
+
path = os.path.join(path, appname)
|
| 121 |
+
else:
|
| 122 |
+
path = os.getenv("XDG_DATA_HOME", os.path.expanduser("~/.local/share"))
|
| 123 |
+
if appname:
|
| 124 |
+
path = os.path.join(path, appname)
|
| 125 |
+
if appname and version:
|
| 126 |
+
path = os.path.join(path, version)
|
| 127 |
+
return path
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
def site_data_dir(appname=None, appauthor=None, version=None, multipath=False):
|
| 131 |
+
r"""Return full path to the user-shared data dir for this application.
|
| 132 |
+
|
| 133 |
+
"appname" is the name of application.
|
| 134 |
+
If None, just the system directory is returned.
|
| 135 |
+
"appauthor" (only used on Windows) is the name of the
|
| 136 |
+
appauthor or distributing body for this application. Typically
|
| 137 |
+
it is the owning company name. This falls back to appname. You may
|
| 138 |
+
pass False to disable it.
|
| 139 |
+
"version" is an optional version path element to append to the
|
| 140 |
+
path. You might want to use this if you want multiple versions
|
| 141 |
+
of your app to be able to run independently. If used, this
|
| 142 |
+
would typically be "<major>.<minor>".
|
| 143 |
+
Only applied when appname is present.
|
| 144 |
+
"multipath" is an optional parameter only applicable to *nix
|
| 145 |
+
which indicates that the entire list of data dirs should be
|
| 146 |
+
returned. By default, the first item from XDG_DATA_DIRS is
|
| 147 |
+
returned, or '/usr/local/share/<AppName>',
|
| 148 |
+
if XDG_DATA_DIRS is not set
|
| 149 |
+
|
| 150 |
+
Typical site data directories are:
|
| 151 |
+
Mac OS X: /Library/Application Support/<AppName>
|
| 152 |
+
Unix: /usr/local/share/<AppName> or /usr/share/<AppName>
|
| 153 |
+
Win XP: C:\Documents and Settings\All Users\Application Data\<AppAuthor>\<AppName>
|
| 154 |
+
Vista: (Fail! "C:\ProgramData" is a hidden *system* directory on Vista.)
|
| 155 |
+
Win 7: C:\ProgramData\<AppAuthor>\<AppName> # Hidden, but writeable on Win 7.
|
| 156 |
+
|
| 157 |
+
For Unix, this is using the $XDG_DATA_DIRS[0] default.
|
| 158 |
+
|
| 159 |
+
WARNING: Do not use this on Windows. See the Vista-Fail note above for why.
|
| 160 |
+
"""
|
| 161 |
+
if system == "win32":
|
| 162 |
+
if appauthor is None:
|
| 163 |
+
appauthor = appname
|
| 164 |
+
path = os.path.normpath(_get_win_folder("CSIDL_COMMON_APPDATA"))
|
| 165 |
+
if appname:
|
| 166 |
+
if appauthor is not False:
|
| 167 |
+
path = os.path.join(path, appauthor, appname)
|
| 168 |
+
else:
|
| 169 |
+
path = os.path.join(path, appname)
|
| 170 |
+
elif system == "darwin":
|
| 171 |
+
path = os.path.expanduser("/Library/Application Support")
|
| 172 |
+
if appname:
|
| 173 |
+
path = os.path.join(path, appname)
|
| 174 |
+
else:
|
| 175 |
+
# XDG default for $XDG_DATA_DIRS
|
| 176 |
+
# only first, if multipath is False
|
| 177 |
+
path = os.getenv(
|
| 178 |
+
"XDG_DATA_DIRS", os.pathsep.join(["/usr/local/share", "/usr/share"])
|
| 179 |
+
)
|
| 180 |
+
pathlist = [
|
| 181 |
+
os.path.expanduser(x.rstrip(os.sep)) for x in path.split(os.pathsep)
|
| 182 |
+
]
|
| 183 |
+
if appname:
|
| 184 |
+
if version:
|
| 185 |
+
appname = os.path.join(appname, version)
|
| 186 |
+
pathlist = [os.sep.join([x, appname]) for x in pathlist]
|
| 187 |
+
|
| 188 |
+
if multipath:
|
| 189 |
+
path = os.pathsep.join(pathlist)
|
| 190 |
+
else:
|
| 191 |
+
path = pathlist[0]
|
| 192 |
+
return path
|
| 193 |
+
|
| 194 |
+
if appname and version:
|
| 195 |
+
path = os.path.join(path, version)
|
| 196 |
+
return path
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
def user_config_dir(appname=None, appauthor=None, version=None, roaming=False):
|
| 200 |
+
r"""Return full path to the user-specific config dir for this application.
|
| 201 |
+
|
| 202 |
+
"appname" is the name of application.
|
| 203 |
+
If None, just the system directory is returned.
|
| 204 |
+
"appauthor" (only used on Windows) is the name of the
|
| 205 |
+
appauthor or distributing body for this application. Typically
|
| 206 |
+
it is the owning company name. This falls back to appname. You may
|
| 207 |
+
pass False to disable it.
|
| 208 |
+
"version" is an optional version path element to append to the
|
| 209 |
+
path. You might want to use this if you want multiple versions
|
| 210 |
+
of your app to be able to run independently. If used, this
|
| 211 |
+
would typically be "<major>.<minor>".
|
| 212 |
+
Only applied when appname is present.
|
| 213 |
+
"roaming" (boolean, default False) can be set True to use the Windows
|
| 214 |
+
roaming appdata directory. That means that for users on a Windows
|
| 215 |
+
network setup for roaming profiles, this user data will be
|
| 216 |
+
sync'd on login. See
|
| 217 |
+
<http://technet.microsoft.com/en-us/library/cc766489(WS.10).aspx>
|
| 218 |
+
for a discussion of issues.
|
| 219 |
+
|
| 220 |
+
Typical user config directories are:
|
| 221 |
+
Mac OS X: ~/Library/Preferences/<AppName>
|
| 222 |
+
Unix: ~/.config/<AppName> # or in $XDG_CONFIG_HOME, if defined
|
| 223 |
+
Win *: same as user_data_dir
|
| 224 |
+
|
| 225 |
+
For Unix, we follow the XDG spec and support $XDG_CONFIG_HOME.
|
| 226 |
+
That means, by default "~/.config/<AppName>".
|
| 227 |
+
"""
|
| 228 |
+
if system == "win32":
|
| 229 |
+
path = user_data_dir(appname, appauthor, None, roaming)
|
| 230 |
+
elif system == "darwin":
|
| 231 |
+
path = os.path.expanduser("~/Library/Preferences/")
|
| 232 |
+
if appname:
|
| 233 |
+
path = os.path.join(path, appname)
|
| 234 |
+
else:
|
| 235 |
+
path = os.getenv("XDG_CONFIG_HOME", os.path.expanduser("~/.config"))
|
| 236 |
+
if appname:
|
| 237 |
+
path = os.path.join(path, appname)
|
| 238 |
+
if appname and version:
|
| 239 |
+
path = os.path.join(path, version)
|
| 240 |
+
return path
|
| 241 |
+
|
| 242 |
+
|
| 243 |
+
def site_config_dir(appname=None, appauthor=None, version=None, multipath=False):
|
| 244 |
+
r"""Return full path to the user-shared data dir for this application.
|
| 245 |
+
|
| 246 |
+
"appname" is the name of application.
|
| 247 |
+
If None, just the system directory is returned.
|
| 248 |
+
"appauthor" (only used on Windows) is the name of the
|
| 249 |
+
appauthor or distributing body for this application. Typically
|
| 250 |
+
it is the owning company name. This falls back to appname. You may
|
| 251 |
+
pass False to disable it.
|
| 252 |
+
"version" is an optional version path element to append to the
|
| 253 |
+
path. You might want to use this if you want multiple versions
|
| 254 |
+
of your app to be able to run independently. If used, this
|
| 255 |
+
would typically be "<major>.<minor>".
|
| 256 |
+
Only applied when appname is present.
|
| 257 |
+
"multipath" is an optional parameter only applicable to *nix
|
| 258 |
+
which indicates that the entire list of config dirs should be
|
| 259 |
+
returned. By default, the first item from XDG_CONFIG_DIRS is
|
| 260 |
+
returned, or '/etc/xdg/<AppName>', if XDG_CONFIG_DIRS is not set
|
| 261 |
+
|
| 262 |
+
Typical site config directories are:
|
| 263 |
+
Mac OS X: same as site_data_dir
|
| 264 |
+
Unix: /etc/xdg/<AppName> or $XDG_CONFIG_DIRS[i]/<AppName> for each value in
|
| 265 |
+
$XDG_CONFIG_DIRS
|
| 266 |
+
Win *: same as site_data_dir
|
| 267 |
+
Vista: (Fail! "C:\ProgramData" is a hidden *system* directory on Vista.)
|
| 268 |
+
|
| 269 |
+
For Unix, this is using the $XDG_CONFIG_DIRS[0] default, if multipath=False
|
| 270 |
+
|
| 271 |
+
WARNING: Do not use this on Windows. See the Vista-Fail note above for why.
|
| 272 |
+
"""
|
| 273 |
+
if system == "win32":
|
| 274 |
+
path = site_data_dir(appname, appauthor)
|
| 275 |
+
if appname and version:
|
| 276 |
+
path = os.path.join(path, version)
|
| 277 |
+
elif system == "darwin":
|
| 278 |
+
path = os.path.expanduser("/Library/Preferences")
|
| 279 |
+
if appname:
|
| 280 |
+
path = os.path.join(path, appname)
|
| 281 |
+
else:
|
| 282 |
+
# XDG default for $XDG_CONFIG_DIRS
|
| 283 |
+
# only first, if multipath is False
|
| 284 |
+
path = os.getenv("XDG_CONFIG_DIRS", "/etc/xdg")
|
| 285 |
+
pathlist = [
|
| 286 |
+
os.path.expanduser(x.rstrip(os.sep)) for x in path.split(os.pathsep)
|
| 287 |
+
]
|
| 288 |
+
if appname:
|
| 289 |
+
if version:
|
| 290 |
+
appname = os.path.join(appname, version)
|
| 291 |
+
pathlist = [os.sep.join([x, appname]) for x in pathlist]
|
| 292 |
+
|
| 293 |
+
if multipath:
|
| 294 |
+
path = os.pathsep.join(pathlist)
|
| 295 |
+
else:
|
| 296 |
+
path = pathlist[0]
|
| 297 |
+
return path
|
| 298 |
+
|
| 299 |
+
|
| 300 |
+
def user_cache_dir(appname=None, appauthor=None, version=None, opinion=True):
|
| 301 |
+
r"""Return full path to the user-specific cache dir for this application.
|
| 302 |
+
|
| 303 |
+
"appname" is the name of application.
|
| 304 |
+
If None, just the system directory is returned.
|
| 305 |
+
"appauthor" (only used on Windows) is the name of the
|
| 306 |
+
appauthor or distributing body for this application. Typically
|
| 307 |
+
it is the owning company name. This falls back to appname. You may
|
| 308 |
+
pass False to disable it.
|
| 309 |
+
"version" is an optional version path element to append to the
|
| 310 |
+
path. You might want to use this if you want multiple versions
|
| 311 |
+
of your app to be able to run independently. If used, this
|
| 312 |
+
would typically be "<major>.<minor>".
|
| 313 |
+
Only applied when appname is present.
|
| 314 |
+
"opinion" (boolean) can be False to disable the appending of
|
| 315 |
+
"Cache" to the base app data dir for Windows. See
|
| 316 |
+
discussion below.
|
| 317 |
+
|
| 318 |
+
Typical user cache directories are:
|
| 319 |
+
Mac OS X: ~/Library/Caches/<AppName>
|
| 320 |
+
Unix: ~/.cache/<AppName> (XDG default)
|
| 321 |
+
Win XP: C:\Documents and Settings\<username>\Local Settings\Application Data\<AppAuthor>\<AppName>\Cache
|
| 322 |
+
Vista: C:\Users\<username>\AppData\Local\<AppAuthor>\<AppName>\Cache
|
| 323 |
+
|
| 324 |
+
On Windows the only suggestion in the MSDN docs is that local settings go in
|
| 325 |
+
the `CSIDL_LOCAL_APPDATA` directory. This is identical to the non-roaming
|
| 326 |
+
app data dir (the default returned by `user_data_dir` above). Apps typically
|
| 327 |
+
put cache data somewhere *under* the given dir here. Some examples:
|
| 328 |
+
...\Mozilla\Firefox\Profiles\<ProfileName>\Cache
|
| 329 |
+
...\Acme\SuperApp\Cache\1.0
|
| 330 |
+
OPINION: This function appends "Cache" to the `CSIDL_LOCAL_APPDATA` value.
|
| 331 |
+
This can be disabled with the `opinion=False` option.
|
| 332 |
+
"""
|
| 333 |
+
if system == "win32":
|
| 334 |
+
if appauthor is None:
|
| 335 |
+
appauthor = appname
|
| 336 |
+
path = os.path.normpath(_get_win_folder("CSIDL_LOCAL_APPDATA"))
|
| 337 |
+
if appname:
|
| 338 |
+
if appauthor is not False:
|
| 339 |
+
path = os.path.join(path, appauthor, appname)
|
| 340 |
+
else:
|
| 341 |
+
path = os.path.join(path, appname)
|
| 342 |
+
if opinion:
|
| 343 |
+
path = os.path.join(path, "Cache")
|
| 344 |
+
elif system == "darwin":
|
| 345 |
+
path = os.path.expanduser("~/Library/Caches")
|
| 346 |
+
if appname:
|
| 347 |
+
path = os.path.join(path, appname)
|
| 348 |
+
else:
|
| 349 |
+
path = os.getenv("XDG_CACHE_HOME", os.path.expanduser("~/.cache"))
|
| 350 |
+
if appname:
|
| 351 |
+
path = os.path.join(path, appname)
|
| 352 |
+
if appname and version:
|
| 353 |
+
path = os.path.join(path, version)
|
| 354 |
+
return path
|
| 355 |
+
|
| 356 |
+
|
| 357 |
+
def user_state_dir(appname=None, appauthor=None, version=None, roaming=False):
|
| 358 |
+
r"""Return full path to the user-specific state dir for this application.
|
| 359 |
+
|
| 360 |
+
"appname" is the name of application.
|
| 361 |
+
If None, just the system directory is returned.
|
| 362 |
+
"appauthor" (only used on Windows) is the name of the
|
| 363 |
+
appauthor or distributing body for this application. Typically
|
| 364 |
+
it is the owning company name. This falls back to appname. You may
|
| 365 |
+
pass False to disable it.
|
| 366 |
+
"version" is an optional version path element to append to the
|
| 367 |
+
path. You might want to use this if you want multiple versions
|
| 368 |
+
of your app to be able to run independently. If used, this
|
| 369 |
+
would typically be "<major>.<minor>".
|
| 370 |
+
Only applied when appname is present.
|
| 371 |
+
"roaming" (boolean, default False) can be set True to use the Windows
|
| 372 |
+
roaming appdata directory. That means that for users on a Windows
|
| 373 |
+
network setup for roaming profiles, this user data will be
|
| 374 |
+
sync'd on login. See
|
| 375 |
+
<http://technet.microsoft.com/en-us/library/cc766489(WS.10).aspx>
|
| 376 |
+
for a discussion of issues.
|
| 377 |
+
|
| 378 |
+
Typical user state directories are:
|
| 379 |
+
Mac OS X: same as user_data_dir
|
| 380 |
+
Unix: ~/.local/state/<AppName> # or in $XDG_STATE_HOME, if defined
|
| 381 |
+
Win *: same as user_data_dir
|
| 382 |
+
|
| 383 |
+
For Unix, we follow this Debian proposal <https://wiki.debian.org/XDGBaseDirectorySpecification#state>
|
| 384 |
+
to extend the XDG spec and support $XDG_STATE_HOME.
|
| 385 |
+
|
| 386 |
+
That means, by default "~/.local/state/<AppName>".
|
| 387 |
+
"""
|
| 388 |
+
if system in ["win32", "darwin"]:
|
| 389 |
+
path = user_data_dir(appname, appauthor, None, roaming)
|
| 390 |
+
else:
|
| 391 |
+
path = os.getenv("XDG_STATE_HOME", os.path.expanduser("~/.local/state"))
|
| 392 |
+
if appname:
|
| 393 |
+
path = os.path.join(path, appname)
|
| 394 |
+
if appname and version:
|
| 395 |
+
path = os.path.join(path, version)
|
| 396 |
+
return path
|
| 397 |
+
|
| 398 |
+
|
| 399 |
+
def user_log_dir(appname=None, appauthor=None, version=None, opinion=True):
|
| 400 |
+
r"""Return full path to the user-specific log dir for this application.
|
| 401 |
+
|
| 402 |
+
"appname" is the name of application.
|
| 403 |
+
If None, just the system directory is returned.
|
| 404 |
+
"appauthor" (only used on Windows) is the name of the
|
| 405 |
+
appauthor or distributing body for this application. Typically
|
| 406 |
+
it is the owning company name. This falls back to appname. You may
|
| 407 |
+
pass False to disable it.
|
| 408 |
+
"version" is an optional version path element to append to the
|
| 409 |
+
path. You might want to use this if you want multiple versions
|
| 410 |
+
of your app to be able to run independently. If used, this
|
| 411 |
+
would typically be "<major>.<minor>".
|
| 412 |
+
Only applied when appname is present.
|
| 413 |
+
"opinion" (boolean) can be False to disable the appending of
|
| 414 |
+
"Logs" to the base app data dir for Windows, and "log" to the
|
| 415 |
+
base cache dir for Unix. See discussion below.
|
| 416 |
+
|
| 417 |
+
Typical user log directories are:
|
| 418 |
+
Mac OS X: ~/Library/Logs/<AppName>
|
| 419 |
+
Unix: ~/.cache/<AppName>/log # or under $XDG_CACHE_HOME if defined
|
| 420 |
+
Win XP: C:\Documents and Settings\<username>\Local Settings\Application Data\<AppAuthor>\<AppName>\Logs
|
| 421 |
+
Vista: C:\Users\<username>\AppData\Local\<AppAuthor>\<AppName>\Logs
|
| 422 |
+
|
| 423 |
+
On Windows the only suggestion in the MSDN docs is that local settings
|
| 424 |
+
go in the `CSIDL_LOCAL_APPDATA` directory. (Note: I'm interested in
|
| 425 |
+
examples of what some windows apps use for a logs dir.)
|
| 426 |
+
|
| 427 |
+
OPINION: This function appends "Logs" to the `CSIDL_LOCAL_APPDATA`
|
| 428 |
+
value for Windows and appends "log" to the user cache dir for Unix.
|
| 429 |
+
This can be disabled with the `opinion=False` option.
|
| 430 |
+
"""
|
| 431 |
+
if system == "darwin":
|
| 432 |
+
path = os.path.join(os.path.expanduser("~/Library/Logs"), appname)
|
| 433 |
+
elif system == "win32":
|
| 434 |
+
path = user_data_dir(appname, appauthor, version)
|
| 435 |
+
version = False
|
| 436 |
+
if opinion:
|
| 437 |
+
path = os.path.join(path, "Logs")
|
| 438 |
+
else:
|
| 439 |
+
path = user_cache_dir(appname, appauthor, version)
|
| 440 |
+
version = False
|
| 441 |
+
if opinion:
|
| 442 |
+
path = os.path.join(path, "log")
|
| 443 |
+
if appname and version:
|
| 444 |
+
path = os.path.join(path, version)
|
| 445 |
+
return path
|
| 446 |
+
|
| 447 |
+
|
| 448 |
+
class AppDirs:
|
| 449 |
+
"""Convenience wrapper for getting application dirs."""
|
| 450 |
+
|
| 451 |
+
def __init__(
|
| 452 |
+
self, appname=None, appauthor=None, version=None, roaming=False, multipath=False
|
| 453 |
+
):
|
| 454 |
+
self.appname = appname
|
| 455 |
+
self.appauthor = appauthor
|
| 456 |
+
self.version = version
|
| 457 |
+
self.roaming = roaming
|
| 458 |
+
self.multipath = multipath
|
| 459 |
+
|
| 460 |
+
@property
|
| 461 |
+
def user_data_dir(self):
|
| 462 |
+
return user_data_dir(
|
| 463 |
+
self.appname, self.appauthor, version=self.version, roaming=self.roaming
|
| 464 |
+
)
|
| 465 |
+
|
| 466 |
+
@property
|
| 467 |
+
def site_data_dir(self):
|
| 468 |
+
return site_data_dir(
|
| 469 |
+
self.appname, self.appauthor, version=self.version, multipath=self.multipath
|
| 470 |
+
)
|
| 471 |
+
|
| 472 |
+
@property
|
| 473 |
+
def user_config_dir(self):
|
| 474 |
+
return user_config_dir(
|
| 475 |
+
self.appname, self.appauthor, version=self.version, roaming=self.roaming
|
| 476 |
+
)
|
| 477 |
+
|
| 478 |
+
@property
|
| 479 |
+
def site_config_dir(self):
|
| 480 |
+
return site_config_dir(
|
| 481 |
+
self.appname, self.appauthor, version=self.version, multipath=self.multipath
|
| 482 |
+
)
|
| 483 |
+
|
| 484 |
+
@property
|
| 485 |
+
def user_cache_dir(self):
|
| 486 |
+
return user_cache_dir(self.appname, self.appauthor, version=self.version)
|
| 487 |
+
|
| 488 |
+
@property
|
| 489 |
+
def user_state_dir(self):
|
| 490 |
+
return user_state_dir(self.appname, self.appauthor, version=self.version)
|
| 491 |
+
|
| 492 |
+
@property
|
| 493 |
+
def user_log_dir(self):
|
| 494 |
+
return user_log_dir(self.appname, self.appauthor, version=self.version)
|
| 495 |
+
|
| 496 |
+
|
| 497 |
+
# ---- internal support stuff
|
| 498 |
+
|
| 499 |
+
|
| 500 |
+
def _get_win_folder_from_registry(csidl_name):
|
| 501 |
+
"""This is a fallback technique at best. I'm not sure if using the
|
| 502 |
+
registry for this guarantees us the correct answer for all CSIDL_*
|
| 503 |
+
names.
|
| 504 |
+
"""
|
| 505 |
+
import winreg as _winreg
|
| 506 |
+
|
| 507 |
+
shell_folder_name = {
|
| 508 |
+
"CSIDL_APPDATA": "AppData",
|
| 509 |
+
"CSIDL_COMMON_APPDATA": "Common AppData",
|
| 510 |
+
"CSIDL_LOCAL_APPDATA": "Local AppData",
|
| 511 |
+
}[csidl_name]
|
| 512 |
+
|
| 513 |
+
key = _winreg.OpenKey(
|
| 514 |
+
_winreg.HKEY_CURRENT_USER,
|
| 515 |
+
r"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders",
|
| 516 |
+
)
|
| 517 |
+
dir, _type = _winreg.QueryValueEx(key, shell_folder_name)
|
| 518 |
+
return dir
|
| 519 |
+
|
| 520 |
+
|
| 521 |
+
def _get_win_folder_with_pywin32(csidl_name):
|
| 522 |
+
from win32com.shell import shell, shellcon
|
| 523 |
+
|
| 524 |
+
dir = shell.SHGetFolderPath(0, getattr(shellcon, csidl_name), 0, 0)
|
| 525 |
+
# Try to make this a unicode path because SHGetFolderPath does
|
| 526 |
+
# not return unicode strings when there is unicode data in the
|
| 527 |
+
# path.
|
| 528 |
+
try:
|
| 529 |
+
dir = unicode(dir)
|
| 530 |
+
|
| 531 |
+
# Downgrade to short path name if have highbit chars. See
|
| 532 |
+
# <http://bugs.activestate.com/show_bug.cgi?id=85099>.
|
| 533 |
+
has_high_char = False
|
| 534 |
+
for c in dir:
|
| 535 |
+
if ord(c) > 255:
|
| 536 |
+
has_high_char = True
|
| 537 |
+
break
|
| 538 |
+
if has_high_char:
|
| 539 |
+
try:
|
| 540 |
+
import win32api
|
| 541 |
+
|
| 542 |
+
dir = win32api.GetShortPathName(dir)
|
| 543 |
+
except ImportError:
|
| 544 |
+
pass
|
| 545 |
+
except UnicodeError:
|
| 546 |
+
pass
|
| 547 |
+
return dir
|
| 548 |
+
|
| 549 |
+
|
| 550 |
+
def _get_win_folder_with_ctypes(csidl_name):
|
| 551 |
+
import ctypes
|
| 552 |
+
|
| 553 |
+
csidl_const = {
|
| 554 |
+
"CSIDL_APPDATA": 26,
|
| 555 |
+
"CSIDL_COMMON_APPDATA": 35,
|
| 556 |
+
"CSIDL_LOCAL_APPDATA": 28,
|
| 557 |
+
}[csidl_name]
|
| 558 |
+
|
| 559 |
+
buf = ctypes.create_unicode_buffer(1024)
|
| 560 |
+
ctypes.windll.shell32.SHGetFolderPathW(None, csidl_const, None, 0, buf)
|
| 561 |
+
|
| 562 |
+
# Downgrade to short path name if have highbit chars. See
|
| 563 |
+
# <http://bugs.activestate.com/show_bug.cgi?id=85099>.
|
| 564 |
+
has_high_char = False
|
| 565 |
+
for c in buf:
|
| 566 |
+
if ord(c) > 255:
|
| 567 |
+
has_high_char = True
|
| 568 |
+
break
|
| 569 |
+
if has_high_char:
|
| 570 |
+
buf2 = ctypes.create_unicode_buffer(1024)
|
| 571 |
+
if ctypes.windll.kernel32.GetShortPathNameW(buf.value, buf2, 1024):
|
| 572 |
+
buf = buf2
|
| 573 |
+
|
| 574 |
+
return buf.value
|
| 575 |
+
|
| 576 |
+
|
| 577 |
+
def _get_win_folder_with_jna(csidl_name):
|
| 578 |
+
import array
|
| 579 |
+
|
| 580 |
+
from com.sun import jna
|
| 581 |
+
from com.sun.jna.platform import win32
|
| 582 |
+
|
| 583 |
+
buf_size = win32.WinDef.MAX_PATH * 2
|
| 584 |
+
buf = array.zeros("c", buf_size)
|
| 585 |
+
shell = win32.Shell32.INSTANCE
|
| 586 |
+
shell.SHGetFolderPath(
|
| 587 |
+
None,
|
| 588 |
+
getattr(win32.ShlObj, csidl_name),
|
| 589 |
+
None,
|
| 590 |
+
win32.ShlObj.SHGFP_TYPE_CURRENT,
|
| 591 |
+
buf,
|
| 592 |
+
)
|
| 593 |
+
dir = jna.Native.toString(buf.tostring()).rstrip("\0")
|
| 594 |
+
|
| 595 |
+
# Downgrade to short path name if have highbit chars. See
|
| 596 |
+
# <http://bugs.activestate.com/show_bug.cgi?id=85099>.
|
| 597 |
+
has_high_char = False
|
| 598 |
+
for c in dir:
|
| 599 |
+
if ord(c) > 255:
|
| 600 |
+
has_high_char = True
|
| 601 |
+
break
|
| 602 |
+
if has_high_char:
|
| 603 |
+
buf = array.zeros("c", buf_size)
|
| 604 |
+
kernel = win32.Kernel32.INSTANCE
|
| 605 |
+
if kernel.GetShortPathName(dir, buf, buf_size):
|
| 606 |
+
dir = jna.Native.toString(buf.tostring()).rstrip("\0")
|
| 607 |
+
|
| 608 |
+
return dir
|
| 609 |
+
|
| 610 |
+
|
| 611 |
+
if system == "win32":
|
| 612 |
+
try:
|
| 613 |
+
import win32com.shell
|
| 614 |
+
|
| 615 |
+
_get_win_folder = _get_win_folder_with_pywin32
|
| 616 |
+
except ImportError:
|
| 617 |
+
try:
|
| 618 |
+
from ctypes import windll
|
| 619 |
+
|
| 620 |
+
_get_win_folder = _get_win_folder_with_ctypes
|
| 621 |
+
except ImportError:
|
| 622 |
+
try:
|
| 623 |
+
import com.sun.jna
|
| 624 |
+
|
| 625 |
+
_get_win_folder = _get_win_folder_with_jna
|
| 626 |
+
except ImportError:
|
| 627 |
+
_get_win_folder = _get_win_folder_from_registry
|
| 628 |
+
|
| 629 |
+
|
| 630 |
+
# ---- self test code
|
| 631 |
+
|
| 632 |
+
if __name__ == "__main__":
|
| 633 |
+
appname = "MyApp"
|
| 634 |
+
appauthor = "MyCompany"
|
| 635 |
+
|
| 636 |
+
props = (
|
| 637 |
+
"user_data_dir",
|
| 638 |
+
"user_config_dir",
|
| 639 |
+
"user_cache_dir",
|
| 640 |
+
"user_state_dir",
|
| 641 |
+
"user_log_dir",
|
| 642 |
+
"site_data_dir",
|
| 643 |
+
"site_config_dir",
|
| 644 |
+
)
|
| 645 |
+
|
| 646 |
+
print(f"-- app dirs {__version__} --")
|
| 647 |
+
|
| 648 |
+
print("-- app dirs (with optional 'version')")
|
| 649 |
+
dirs = AppDirs(appname, appauthor, version="1.0")
|
| 650 |
+
for prop in props:
|
| 651 |
+
print(f"{prop}: {getattr(dirs, prop)}")
|
| 652 |
+
|
| 653 |
+
print("\n-- app dirs (without optional 'version')")
|
| 654 |
+
dirs = AppDirs(appname, appauthor)
|
| 655 |
+
for prop in props:
|
| 656 |
+
print(f"{prop}: {getattr(dirs, prop)}")
|
| 657 |
+
|
| 658 |
+
print("\n-- app dirs (without optional 'appauthor')")
|
| 659 |
+
dirs = AppDirs(appname)
|
| 660 |
+
for prop in props:
|
| 661 |
+
print(f"{prop}: {getattr(dirs, prop)}")
|
| 662 |
+
|
| 663 |
+
print("\n-- app dirs (with disabled 'appauthor')")
|
| 664 |
+
dirs = AppDirs(appname, appauthor=False)
|
| 665 |
+
for prop in props:
|
| 666 |
+
print(f"{prop}: {getattr(dirs, prop)}")
|
miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_awaits/__init__.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from typing import Generic, TypeVar
|
| 4 |
+
|
| 5 |
+
import torch
|
| 6 |
+
|
| 7 |
+
__all__ = ['Await']
|
| 8 |
+
|
| 9 |
+
W = TypeVar("W")
|
| 10 |
+
|
| 11 |
+
class _PyAwaitMeta(type(torch._C._Await), type(Generic)): # type: ignore[misc, no-redef]
|
| 12 |
+
pass
|
| 13 |
+
|
| 14 |
+
class _Await(torch._C._Await, Generic[W], metaclass=_PyAwaitMeta):
|
| 15 |
+
r"""
|
| 16 |
+
Wrapper around a ``torch._C.Await`` which encapsulates delayed execution
|
| 17 |
+
of a callable. All manipulations happen with functions ``torch.jit._awaitable``,
|
| 18 |
+
``torch.jit._awaitable_wait``, ``torch.jit._awaitable_nowait``.
|
| 19 |
+
|
| 20 |
+
Torch scriptable manipulations:
|
| 21 |
+
``torch.jit._awaitable(func, *args)``
|
| 22 |
+
Creates ``Await[W]`` object, where W is return type of func.
|
| 23 |
+
|
| 24 |
+
Returns:
|
| 25 |
+
``torch.jit._awaitable_wait(Await[W])``
|
| 26 |
+
Returns the result of the function, specified at ``_awaitable``, with specified arguments.
|
| 27 |
+
|
| 28 |
+
Returns:
|
| 29 |
+
The result of type ``W`` of the function call. The result is owned by ``Await[W]``
|
| 30 |
+
and returned on all following ``_awaitable_wait`` calls.
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
``torch.jit._awaitable_nowait(W)``
|
| 34 |
+
Returns:
|
| 35 |
+
Trivial ``Await[W]`` with specified result.
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
Only in eager mode:
|
| 39 |
+
``fn() -> Callable[Tuple[Any], W]``
|
| 40 |
+
Returns:
|
| 41 |
+
Specified at ``_awaitable`` python function ``func``.
|
| 42 |
+
|
| 43 |
+
``args() -> Tuple[Any]``
|
| 44 |
+
Returns:
|
| 45 |
+
Specified at ``_awaitable`` python args.
|
| 46 |
+
|
| 47 |
+
``is_nowait() -> _bool``
|
| 48 |
+
Returns:
|
| 49 |
+
``True`` if this object was created via ``_awaitable_nowait`` call (trivial `Await[W]`).
|
| 50 |
+
|
| 51 |
+
In eager mode ``Await[W]`` can be used as ``W`` i.e. attributes of W can be called on ``Await[W]``,
|
| 52 |
+
``_awaitable_wait()`` call will be transparently added.
|
| 53 |
+
"""
|
miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_classes.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import types
|
| 2 |
+
from typing import Any
|
| 3 |
+
|
| 4 |
+
import torch._C
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class _ClassNamespace(types.ModuleType):
|
| 8 |
+
def __init__(self, name: str) -> None:
|
| 9 |
+
super().__init__("torch.classes" + name)
|
| 10 |
+
self.name = name
|
| 11 |
+
|
| 12 |
+
def __getattr__(self, attr: str) -> Any:
|
| 13 |
+
proxy = torch._C._get_custom_class_python_wrapper(self.name, attr)
|
| 14 |
+
if proxy is None:
|
| 15 |
+
raise RuntimeError(f"Class {self.name}.{attr} not registered!")
|
| 16 |
+
return proxy
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class _Classes(types.ModuleType):
|
| 20 |
+
__file__ = "_classes.py"
|
| 21 |
+
|
| 22 |
+
def __init__(self) -> None:
|
| 23 |
+
super().__init__("torch.classes")
|
| 24 |
+
|
| 25 |
+
def __getattr__(self, name: str) -> _ClassNamespace:
|
| 26 |
+
namespace = _ClassNamespace(name)
|
| 27 |
+
setattr(self, name, namespace)
|
| 28 |
+
return namespace
|
| 29 |
+
|
| 30 |
+
@property
|
| 31 |
+
def loaded_libraries(self) -> Any:
|
| 32 |
+
return torch.ops.loaded_libraries
|
| 33 |
+
|
| 34 |
+
def load_library(self, path: str) -> None:
|
| 35 |
+
"""
|
| 36 |
+
Loads a shared library from the given path into the current process.
|
| 37 |
+
|
| 38 |
+
The library being loaded may run global initialization code to register
|
| 39 |
+
custom classes with the PyTorch JIT runtime. This allows dynamically
|
| 40 |
+
loading custom classes. For this, you should compile your class
|
| 41 |
+
and the static registration code into a shared library object, and then
|
| 42 |
+
call ``torch.classes.load_library('path/to/libcustom.so')`` to load the
|
| 43 |
+
shared object.
|
| 44 |
+
|
| 45 |
+
After the library is loaded, it is added to the
|
| 46 |
+
``torch.classes.loaded_libraries`` attribute, a set that may be inspected
|
| 47 |
+
for the paths of all libraries loaded using this function.
|
| 48 |
+
|
| 49 |
+
Args:
|
| 50 |
+
path (str): A path to a shared library to load.
|
| 51 |
+
"""
|
| 52 |
+
torch.ops.load_library(path)
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
# The classes "namespace"
|
| 56 |
+
classes = _Classes()
|
miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_compile.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
APIs related to torch.compile which lazily import torch._dynamo to avoid
|
| 3 |
+
circular dependencies.
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import functools
|
| 7 |
+
from collections.abc import Callable
|
| 8 |
+
from typing import overload, TypeVar
|
| 9 |
+
from typing_extensions import ParamSpec
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
_T = TypeVar("_T")
|
| 13 |
+
_P = ParamSpec("_P")
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
@overload
|
| 17 |
+
def _disable_dynamo(
|
| 18 |
+
fn: Callable[_P, _T], recursive: bool = True
|
| 19 |
+
) -> Callable[_P, _T]: ...
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
@overload
|
| 23 |
+
def _disable_dynamo(
|
| 24 |
+
fn: None = None, recursive: bool = True
|
| 25 |
+
) -> Callable[[Callable[_P, _T]], Callable[_P, _T]]: ...
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def _disable_dynamo(
|
| 29 |
+
fn: Callable[_P, _T] | None = None, recursive: bool = True
|
| 30 |
+
) -> Callable[_P, _T] | Callable[[Callable[_P, _T]], Callable[_P, _T]]:
|
| 31 |
+
"""
|
| 32 |
+
This API should be only used inside torch, external users should still use
|
| 33 |
+
torch._dynamo.disable. The main goal of this API is to avoid circular
|
| 34 |
+
imports issues that is common while using _dynamo.disable inside torch
|
| 35 |
+
itself.
|
| 36 |
+
|
| 37 |
+
This API avoids it by lazily importing torch._dynamo from the import time to
|
| 38 |
+
the invocation of the decorated function.
|
| 39 |
+
"""
|
| 40 |
+
if fn is not None:
|
| 41 |
+
|
| 42 |
+
@functools.wraps(fn)
|
| 43 |
+
def inner(*args: _P.args, **kwargs: _P.kwargs) -> _T:
|
| 44 |
+
# cache this on the first invocation to avoid adding too much overhead.
|
| 45 |
+
disable_fn = getattr(fn, "__dynamo_disable", None)
|
| 46 |
+
if disable_fn is None:
|
| 47 |
+
import torch._dynamo
|
| 48 |
+
|
| 49 |
+
# We can safely turn off functools.wraps here because the inner
|
| 50 |
+
# already wraps fn in the outer scope.
|
| 51 |
+
disable_fn = torch._dynamo.disable(fn, recursive, wrapping=False)
|
| 52 |
+
fn.__dynamo_disable = disable_fn # type: ignore[attr-defined]
|
| 53 |
+
|
| 54 |
+
return disable_fn(*args, **kwargs)
|
| 55 |
+
|
| 56 |
+
return inner
|
| 57 |
+
else:
|
| 58 |
+
# decorator usage like @_disable_dynamo(recursive=False). The resulting
|
| 59 |
+
# object expects the original decorated function as the arg.
|
| 60 |
+
return functools.partial(_disable_dynamo, recursive=recursive)
|
miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_custom_op/__init__.py
ADDED
|
File without changes
|
miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_custom_op/autograd.py
ADDED
|
@@ -0,0 +1,307 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# mypy: allow-untyped-defs
|
| 2 |
+
import functools
|
| 3 |
+
from collections import namedtuple
|
| 4 |
+
|
| 5 |
+
import torch
|
| 6 |
+
import torch.utils._pytree as pytree
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
# NOTE [CustomOp autograd kernel indirection]
|
| 10 |
+
# We register `inner` as the autograd kernel for this custom_op.
|
| 11 |
+
# `inner` either calls the autograd formula registered by the user,
|
| 12 |
+
# or goes into an `autograd_not_implemented` kernel.
|
| 13 |
+
#
|
| 14 |
+
# The reason why this indirection exists is
|
| 15 |
+
# so that we can swap out the autograd kernel (the PyTorch dispatcher
|
| 16 |
+
# doesn't actually allow us to do this). By default, we want
|
| 17 |
+
# the `autograd_not_implemented` behavior, but then the user may come
|
| 18 |
+
# and register something that is actually a backward formula
|
| 19 |
+
def autograd_kernel_indirection(custom_op):
|
| 20 |
+
autograd_fallback = autograd_not_implemented(custom_op)
|
| 21 |
+
|
| 22 |
+
def inner(*args, **kwargs):
|
| 23 |
+
if custom_op._has_impl("autograd"):
|
| 24 |
+
kernel = custom_op._get_impl("autograd").func
|
| 25 |
+
return kernel(*args, **kwargs)
|
| 26 |
+
# As explained in NOTE ["backward", "save_for_backward", and "autograd"],
|
| 27 |
+
# after the user gives us "backward" and "save_for_backward", we generate
|
| 28 |
+
# the "autograd" impl. If the user only provided one, then we tell
|
| 29 |
+
# the user they've done something wrong.
|
| 30 |
+
if custom_op._has_impl("save_for_backward") or custom_op._has_impl("backward"):
|
| 31 |
+
missing = (
|
| 32 |
+
"save_for_backward" if custom_op._has_impl("backward") else "backward"
|
| 33 |
+
)
|
| 34 |
+
found = "save_for_backward" if missing == "backward" else "backward"
|
| 35 |
+
loc = custom_op._get_impl(found).location
|
| 36 |
+
raise RuntimeError(
|
| 37 |
+
f"We found a '{found}' registration for {custom_op} at "
|
| 38 |
+
f"{loc} but were unable to find a '{missing}' registration. "
|
| 39 |
+
f"To use the CustomOp API to register a backward formula, "
|
| 40 |
+
f"please provide us both a backward function and a "
|
| 41 |
+
f"'save for backward' function via `impl_backward` and "
|
| 42 |
+
f"`impl_save_for_backward` respectively."
|
| 43 |
+
)
|
| 44 |
+
return autograd_fallback(*args, **kwargs)
|
| 45 |
+
|
| 46 |
+
return inner
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
# TODO(#101191): Use the actual C++ autograd not implemented fallback,
|
| 50 |
+
# or change the default autograd fallback to the autograd not implemented fallback.
|
| 51 |
+
def autograd_not_implemented(custom_op):
|
| 52 |
+
def kernel(*args, **kwargs):
|
| 53 |
+
if torch.is_grad_enabled() and pytree.tree_any(
|
| 54 |
+
lambda x: isinstance(x, torch.Tensor) and x.requires_grad, (args, kwargs)
|
| 55 |
+
):
|
| 56 |
+
raise RuntimeError("Autograd has not been implemented for operator")
|
| 57 |
+
with torch._C._AutoDispatchBelowAutograd():
|
| 58 |
+
return custom_op(*args, **kwargs)
|
| 59 |
+
|
| 60 |
+
return kernel
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def mark_non_differentiable(ctx, output, output_differentiability):
|
| 64 |
+
# Output types are restricted to be:
|
| 65 |
+
# - Tensor
|
| 66 |
+
# - Tensor[]
|
| 67 |
+
# - int, bool, Scalar, float
|
| 68 |
+
# See _check_can_register_backward
|
| 69 |
+
if output_differentiability is not None:
|
| 70 |
+
if not isinstance(output, tuple):
|
| 71 |
+
tuple_output = (output,)
|
| 72 |
+
else:
|
| 73 |
+
tuple_output = output # type: ignore[assignment]
|
| 74 |
+
assert len(output_differentiability) == len(tuple_output)
|
| 75 |
+
non_differentiable_tensors = []
|
| 76 |
+
for idx, (differentiable, out) in enumerate(
|
| 77 |
+
zip(output_differentiability, tuple_output)
|
| 78 |
+
):
|
| 79 |
+
if isinstance(out, torch.Tensor):
|
| 80 |
+
if not differentiable:
|
| 81 |
+
non_differentiable_tensors.append(out)
|
| 82 |
+
continue
|
| 83 |
+
if isinstance(out, list):
|
| 84 |
+
if not differentiable:
|
| 85 |
+
non_differentiable_tensors.extend(out)
|
| 86 |
+
continue
|
| 87 |
+
if differentiable:
|
| 88 |
+
raise RuntimeError(
|
| 89 |
+
f"With output_differentiability={output_differentiability}. "
|
| 90 |
+
f"At idx {idx}, we received an object of type {type(out)} that "
|
| 91 |
+
f"is not a Tensor, so it cannot have be marked as differentiable in "
|
| 92 |
+
f"output_differentiability."
|
| 93 |
+
)
|
| 94 |
+
if non_differentiable_tensors:
|
| 95 |
+
ctx.mark_non_differentiable(*non_differentiable_tensors)
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
def construct_autograd_kernel(
|
| 99 |
+
schema,
|
| 100 |
+
output_differentiability,
|
| 101 |
+
custom_op,
|
| 102 |
+
op_overload,
|
| 103 |
+
save_for_backward_fn,
|
| 104 |
+
backward_fn,
|
| 105 |
+
):
|
| 106 |
+
def apply(*args):
|
| 107 |
+
flat_args, spec = pytree.tree_flatten(args)
|
| 108 |
+
out_spec = None
|
| 109 |
+
|
| 110 |
+
def forward(ctx, *flat_args):
|
| 111 |
+
ctx.set_materialize_grads(True)
|
| 112 |
+
args = pytree.tree_unflatten(list(flat_args), spec)
|
| 113 |
+
with torch._C._AutoDispatchBelowAutograd():
|
| 114 |
+
output = op_overload(*args)
|
| 115 |
+
|
| 116 |
+
# We use the info about args to give better error messages in backward
|
| 117 |
+
args_info = namedtuple_args(schema, pytree.tree_map(type, args))
|
| 118 |
+
|
| 119 |
+
save_for_backward_fn_inputs = namedtuple_args(schema, args)
|
| 120 |
+
to_save = save_for_backward_fn(save_for_backward_fn_inputs, output)
|
| 121 |
+
|
| 122 |
+
save_pytree_for_backward(ctx, (to_save, args_info))
|
| 123 |
+
mark_non_differentiable(ctx, output, output_differentiability)
|
| 124 |
+
|
| 125 |
+
nonlocal out_spec
|
| 126 |
+
flat_output, out_spec = pytree.tree_flatten(output)
|
| 127 |
+
return tuple(flat_output)
|
| 128 |
+
|
| 129 |
+
def backward(ctx, *flat_grad_output):
|
| 130 |
+
assert out_spec is not None
|
| 131 |
+
grads = pytree.tree_unflatten(list(flat_grad_output), out_spec)
|
| 132 |
+
saved, args_info = unpack_saved(ctx)
|
| 133 |
+
# There is nothing on the ctx object for now, it is just there so
|
| 134 |
+
# that we can add additional things in the future.
|
| 135 |
+
inner_ctx = object()
|
| 136 |
+
if not isinstance(grads, tuple):
|
| 137 |
+
grads = (grads,)
|
| 138 |
+
grad_inputs_dict = backward_fn(inner_ctx, saved, *grads)
|
| 139 |
+
|
| 140 |
+
# Massage the grad_inputs_dict to a form acceptable by
|
| 141 |
+
# autograd.Function.
|
| 142 |
+
validate_grad_inputs_dict(grad_inputs_dict, custom_op, args_info)
|
| 143 |
+
return grad_inputs_dict_to_flat_tuple(grad_inputs_dict, args_info)
|
| 144 |
+
|
| 145 |
+
generated_cls = gen_autograd_function(
|
| 146 |
+
custom_op._opname + "_customop", forward, backward
|
| 147 |
+
)
|
| 148 |
+
|
| 149 |
+
flat_output = generated_cls.apply(*flat_args)
|
| 150 |
+
assert out_spec is not None
|
| 151 |
+
return pytree.tree_unflatten(list(flat_output), out_spec)
|
| 152 |
+
|
| 153 |
+
return apply
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
def gen_autograd_function(name, forward, backward):
|
| 157 |
+
generated_cls = type(
|
| 158 |
+
name,
|
| 159 |
+
(torch.autograd.Function,),
|
| 160 |
+
{
|
| 161 |
+
"forward": staticmethod(forward),
|
| 162 |
+
"backward": staticmethod(backward),
|
| 163 |
+
},
|
| 164 |
+
)
|
| 165 |
+
return generated_cls
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
@functools.lru_cache
|
| 169 |
+
def namedtuple_args_cls(schema):
|
| 170 |
+
attribs = [arg.name for arg in schema.arguments.flat_all]
|
| 171 |
+
name = str(schema.name) + "_args"
|
| 172 |
+
# mypy doesn't support dynamic namedtuple name
|
| 173 |
+
tuple_cls = namedtuple(name, attribs) # type: ignore[misc]
|
| 174 |
+
return tuple_cls
|
| 175 |
+
|
| 176 |
+
|
| 177 |
+
def namedtuple_args(schema, args):
|
| 178 |
+
assert isinstance(args, tuple)
|
| 179 |
+
tuple_cls = namedtuple_args_cls(schema)
|
| 180 |
+
return tuple_cls(*args)
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
def validate_grad_inputs_dict(grad_inputs_dict, forward_op, args_info):
|
| 184 |
+
def error(what):
|
| 185 |
+
backward = forward_op._get_impl("backward")
|
| 186 |
+
raise RuntimeError(
|
| 187 |
+
f"In the backward function defined for {forward_op} at "
|
| 188 |
+
f"{backward.location} using the CustomOp API, {what}"
|
| 189 |
+
)
|
| 190 |
+
|
| 191 |
+
if not isinstance(grad_inputs_dict, dict):
|
| 192 |
+
error(
|
| 193 |
+
f"expected the output of the backward function to be a dict but "
|
| 194 |
+
f"got {type(grad_inputs_dict)}"
|
| 195 |
+
)
|
| 196 |
+
|
| 197 |
+
expected_keys = {
|
| 198 |
+
arg.name
|
| 199 |
+
for arg in forward_op._schema.arguments.flat_all
|
| 200 |
+
if arg.type.is_tensor_like()
|
| 201 |
+
}
|
| 202 |
+
actual_keys = grad_inputs_dict.keys()
|
| 203 |
+
if expected_keys != actual_keys:
|
| 204 |
+
error(
|
| 205 |
+
f"expected the returned grad_input dict to have keys "
|
| 206 |
+
f"{expected_keys} but got {actual_keys}. The backward "
|
| 207 |
+
f"function must return a gradient (can be None) for each arg "
|
| 208 |
+
f"to the CustomOp that may be a Tensor or Sequence[Tensor]. "
|
| 209 |
+
f"Args declared to be non-Tensor-like types should not appear "
|
| 210 |
+
f"in the grad_input dict"
|
| 211 |
+
)
|
| 212 |
+
|
| 213 |
+
for name, grad in grad_inputs_dict.items():
|
| 214 |
+
arg_info = getattr(args_info, name)
|
| 215 |
+
|
| 216 |
+
if isinstance(arg_info, list):
|
| 217 |
+
if not isinstance(grad, (tuple, list)):
|
| 218 |
+
error(
|
| 219 |
+
f"for input '{name}' expected the grad_input dict to "
|
| 220 |
+
f"hold a list of gradients but got object of type "
|
| 221 |
+
f"{type(grad)}."
|
| 222 |
+
)
|
| 223 |
+
if len(grad) != len(arg_info):
|
| 224 |
+
error(
|
| 225 |
+
f"for input '{name}' expected the grad_input dict to "
|
| 226 |
+
f"hold a list of {len(arg_info)} gradients but got "
|
| 227 |
+
f"{len(grad)}"
|
| 228 |
+
)
|
| 229 |
+
for idx, (g, info) in enumerate(zip(grad, arg_info)):
|
| 230 |
+
if g is None:
|
| 231 |
+
continue
|
| 232 |
+
if not isinstance(g, torch.Tensor):
|
| 233 |
+
error(
|
| 234 |
+
f"for input '{name}' expected the grad_input dict to "
|
| 235 |
+
f"hold a list of None or Tensor gradients but got "
|
| 236 |
+
f"object of {type(g)} at index {idx}"
|
| 237 |
+
)
|
| 238 |
+
if not issubclass(info, torch.Tensor):
|
| 239 |
+
error(
|
| 240 |
+
f"for input '{name}', got a Tensor as the gradient "
|
| 241 |
+
f"for the {idx}-th value but expected None because "
|
| 242 |
+
f"the {idx}-th value was not a Tensor (it was "
|
| 243 |
+
f"type {arg_info}"
|
| 244 |
+
)
|
| 245 |
+
continue
|
| 246 |
+
|
| 247 |
+
if grad is None:
|
| 248 |
+
continue
|
| 249 |
+
if not isinstance(grad, torch.Tensor):
|
| 250 |
+
error(
|
| 251 |
+
f"got object of type {type(grad)} as the gradient for input "
|
| 252 |
+
f"'{name}', "
|
| 253 |
+
f"but expected the gradient to be either None or a Tensor"
|
| 254 |
+
)
|
| 255 |
+
if not issubclass(arg_info, torch.Tensor):
|
| 256 |
+
error(
|
| 257 |
+
f"got a Tensor as the gradient for input '{name}' but "
|
| 258 |
+
f"expected None as the gradient because input '{name}' "
|
| 259 |
+
f"was not a Tensor (it was type {arg_info})."
|
| 260 |
+
)
|
| 261 |
+
|
| 262 |
+
|
| 263 |
+
def grad_inputs_dict_to_flat_tuple(grad_inputs_dict, args_info):
|
| 264 |
+
result = []
|
| 265 |
+
for name, arg_info in args_info._asdict().items():
|
| 266 |
+
if name not in grad_inputs_dict:
|
| 267 |
+
result.append(pytree.tree_map(lambda x: None, arg_info))
|
| 268 |
+
continue
|
| 269 |
+
result.append(grad_inputs_dict[name])
|
| 270 |
+
return tuple(pytree.tree_leaves(result))
|
| 271 |
+
|
| 272 |
+
|
| 273 |
+
# Saves "stuff" (a pytree) onto the ctx object. Use unpack_saved to unpack it.
|
| 274 |
+
# autograd.Function prefers that users use ctx.save_for_backward to
|
| 275 |
+
# save Tensors (to avoid reference cycles) and for non-Tensors to go onto the
|
| 276 |
+
# ctx object.
|
| 277 |
+
def save_pytree_for_backward(ctx, stuff):
|
| 278 |
+
flat_stuff, spec = pytree.tree_flatten(stuff)
|
| 279 |
+
num_elts = len(flat_stuff)
|
| 280 |
+
tensor_idxs = [
|
| 281 |
+
idx for idx, thing in enumerate(flat_stuff) if isinstance(thing, torch.Tensor)
|
| 282 |
+
]
|
| 283 |
+
non_tensor_idxs = [
|
| 284 |
+
idx
|
| 285 |
+
for idx, thing in enumerate(flat_stuff)
|
| 286 |
+
if not isinstance(thing, torch.Tensor)
|
| 287 |
+
]
|
| 288 |
+
tensors = [thing for thing in flat_stuff if isinstance(thing, torch.Tensor)]
|
| 289 |
+
non_tensors = [thing for thing in flat_stuff if not isinstance(thing, torch.Tensor)]
|
| 290 |
+
|
| 291 |
+
ctx.spec = spec
|
| 292 |
+
ctx.num_elts = num_elts
|
| 293 |
+
ctx.save_for_backward(*tensors)
|
| 294 |
+
ctx.tensor_idxs = tensor_idxs
|
| 295 |
+
ctx.saved_non_tensors = non_tensors
|
| 296 |
+
ctx.non_tensor_idxs = non_tensor_idxs
|
| 297 |
+
|
| 298 |
+
|
| 299 |
+
# Inverse operation to save_pytree_for_backward
|
| 300 |
+
def unpack_saved(ctx):
|
| 301 |
+
flat_stuff = [None] * ctx.num_elts
|
| 302 |
+
for tensor, idx in zip(ctx.saved_tensors, ctx.tensor_idxs):
|
| 303 |
+
flat_stuff[idx] = tensor
|
| 304 |
+
for non_tensor, idx in zip(ctx.saved_non_tensors, ctx.non_tensor_idxs):
|
| 305 |
+
flat_stuff[idx] = non_tensor
|
| 306 |
+
stuff = pytree.tree_unflatten(flat_stuff, ctx.spec)
|
| 307 |
+
return stuff
|
miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_custom_op/impl.py
ADDED
|
@@ -0,0 +1,716 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# mypy: allow-untyped-defs
|
| 2 |
+
import dataclasses
|
| 3 |
+
import functools
|
| 4 |
+
import inspect
|
| 5 |
+
import sys
|
| 6 |
+
import typing
|
| 7 |
+
import warnings
|
| 8 |
+
import weakref
|
| 9 |
+
|
| 10 |
+
import torch
|
| 11 |
+
import torch._C as _C
|
| 12 |
+
import torch._library.infer_schema
|
| 13 |
+
import torch.library as library
|
| 14 |
+
from torch._library.infer_schema import infer_schema
|
| 15 |
+
from torch.library import get_ctx
|
| 16 |
+
from torchgen.model import (
|
| 17 |
+
BaseTy,
|
| 18 |
+
BaseType,
|
| 19 |
+
FunctionSchema,
|
| 20 |
+
ListType,
|
| 21 |
+
OperatorName,
|
| 22 |
+
SchemaKind,
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
from .autograd import autograd_kernel_indirection, construct_autograd_kernel
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
"""
|
| 29 |
+
torch._custom_op is deprecated. We shipped a production-ready version of it into torch.library.
|
| 30 |
+
Please use those APIs instead.
|
| 31 |
+
"""
|
| 32 |
+
|
| 33 |
+
__all__ = ["custom_op", "CustomOp", "get_ctx"]
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
SUPPORTED_DEVICE_TYPE_TO_KEY = {
|
| 37 |
+
"cpu": "CPU",
|
| 38 |
+
"cuda": "CUDA",
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
# We will not let users register CustomOps with anything that could look like
|
| 42 |
+
# PyTorch internals to avoid confusion.
|
| 43 |
+
RESERVED_NS = {
|
| 44 |
+
"prim",
|
| 45 |
+
"prims",
|
| 46 |
+
"aten",
|
| 47 |
+
"at",
|
| 48 |
+
"torch",
|
| 49 |
+
"pytorch",
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def warn_deprecated():
|
| 54 |
+
warnings.warn(
|
| 55 |
+
"torch._custom_op is deprecated and will be removed in PyTorch 2.6, please "
|
| 56 |
+
"use the equivalent torch.library API instead.",
|
| 57 |
+
DeprecationWarning,
|
| 58 |
+
stacklevel=2,
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def custom_op(
|
| 63 |
+
qualname: str, manual_schema: typing.Optional[str] = None
|
| 64 |
+
) -> typing.Callable:
|
| 65 |
+
r"""
|
| 66 |
+
This API is deprecated, please use torch.library.custom_op instead
|
| 67 |
+
"""
|
| 68 |
+
warn_deprecated()
|
| 69 |
+
|
| 70 |
+
def inner(func):
|
| 71 |
+
if not inspect.isfunction(func):
|
| 72 |
+
raise ValueError(
|
| 73 |
+
f"custom_op(...)(func): Expected `func` to be a Python "
|
| 74 |
+
f"function, got: {type(func)}"
|
| 75 |
+
)
|
| 76 |
+
|
| 77 |
+
ns, name = parse_qualname(qualname)
|
| 78 |
+
validate_namespace(ns)
|
| 79 |
+
if func.__name__ != name:
|
| 80 |
+
raise ValueError(
|
| 81 |
+
f"custom_op(qualname='{qualname}', ...)(func): expected `func` "
|
| 82 |
+
f"to have name '{name}' but got '{func.__name__}'. "
|
| 83 |
+
f"Please either change the name of `func` or the qualname that "
|
| 84 |
+
f"is passed to `custom_op`"
|
| 85 |
+
)
|
| 86 |
+
|
| 87 |
+
schema = (
|
| 88 |
+
infer_schema(func, mutates_args=())
|
| 89 |
+
if manual_schema is None
|
| 90 |
+
else manual_schema
|
| 91 |
+
)
|
| 92 |
+
schema_str = f"{name}{schema}"
|
| 93 |
+
function_schema = FunctionSchema.parse(schema_str)
|
| 94 |
+
validate_schema(function_schema)
|
| 95 |
+
if manual_schema is not None:
|
| 96 |
+
validate_function_matches_schema(function_schema, func)
|
| 97 |
+
|
| 98 |
+
lib = library.Library(ns, "FRAGMENT")
|
| 99 |
+
lib.define(schema_str)
|
| 100 |
+
ophandle = find_ophandle_or_throw(ns, function_schema.name)
|
| 101 |
+
result = CustomOp(
|
| 102 |
+
lib, ns, function_schema, name, ophandle, _private_access=True
|
| 103 |
+
)
|
| 104 |
+
|
| 105 |
+
result.__name__ = func.__name__ # pyrefly: ignore [bad-assignment]
|
| 106 |
+
result.__module__ = func.__module__
|
| 107 |
+
result.__doc__ = func.__doc__
|
| 108 |
+
|
| 109 |
+
library.impl(lib, result._opname, "Autograd")(
|
| 110 |
+
autograd_kernel_indirection(weakref.proxy(result))
|
| 111 |
+
)
|
| 112 |
+
|
| 113 |
+
torch._C._dispatch_set_report_error_callback(
|
| 114 |
+
ophandle, functools.partial(report_error_callback, weakref.proxy(result))
|
| 115 |
+
)
|
| 116 |
+
|
| 117 |
+
return result
|
| 118 |
+
|
| 119 |
+
return inner
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
# Global dictionary holding references to all CustomOp objects
|
| 123 |
+
# Yes, it keeps all CustomOps alive (see NOTE [CustomOp lifetime])
|
| 124 |
+
# Used to query the CustomOp associated with a specific C++ dispatcher operator.
|
| 125 |
+
# An example usage is FakeTensor: FakeTensor checks if a specific operator
|
| 126 |
+
# has an implementation registered via the CustomOp API.
|
| 127 |
+
# Indexed by qualname (e.g. aten::foo)
|
| 128 |
+
global_registry: dict[str, "CustomOp"] = {}
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
class CustomOp:
|
| 132 |
+
r"""
|
| 133 |
+
This API is deprecated, please use torch.library.custom_op instead
|
| 134 |
+
"""
|
| 135 |
+
|
| 136 |
+
def __init__(
|
| 137 |
+
self, lib, cpp_ns, schema, operator_name, ophandle, *, _private_access=False
|
| 138 |
+
):
|
| 139 |
+
super().__init__()
|
| 140 |
+
warn_deprecated()
|
| 141 |
+
if not _private_access:
|
| 142 |
+
raise RuntimeError(
|
| 143 |
+
"The CustomOp constructor is private and we do not guarantee "
|
| 144 |
+
"BC for it. Please use custom_op(...) to create a CustomOp object"
|
| 145 |
+
)
|
| 146 |
+
name = f"{cpp_ns}::{operator_name}"
|
| 147 |
+
self._schema = schema
|
| 148 |
+
self._cpp_ns = cpp_ns
|
| 149 |
+
self._lib: library.Library = lib
|
| 150 |
+
self._ophandle: _C._DispatchOperatorHandle = ophandle
|
| 151 |
+
# Has the name of the op, e.g. "foo". We cache here for convenience.
|
| 152 |
+
self._opname: str = operator_name
|
| 153 |
+
# this is _opname but with namespace. e.g. "custom::foo"
|
| 154 |
+
self._qualname: str = name
|
| 155 |
+
self.__name__ = None # mypy requires this
|
| 156 |
+
# NB: Some of these impls are registered as kernels to DispatchKeys.
|
| 157 |
+
# Modifying the _impls dict directly won't do anything in that case.
|
| 158 |
+
self._impls: dict[str, typing.Optional[FuncAndLocation]] = {}
|
| 159 |
+
# See NOTE [CustomOp autograd kernel indirection]
|
| 160 |
+
self._registered_autograd_kernel_indirection = False
|
| 161 |
+
|
| 162 |
+
global_registry[self._qualname] = self
|
| 163 |
+
|
| 164 |
+
def _register_autograd_kernel_indirection(self):
|
| 165 |
+
assert not self._registered_autograd_kernel_indirection
|
| 166 |
+
self._lib.impl(
|
| 167 |
+
self._opname, autograd_kernel_indirection(weakref.proxy(self)), "Autograd"
|
| 168 |
+
)
|
| 169 |
+
self._registered_autograd_kernel_indirection = True
|
| 170 |
+
|
| 171 |
+
# Records the impl and the source location in self._impls
|
| 172 |
+
# Note that this doesn't cause torch.library to use the impl, that
|
| 173 |
+
# needs to be done in a separate self._lib.impl call.
|
| 174 |
+
def _register_impl(self, kind, func, stacklevel=2):
|
| 175 |
+
if self._has_impl(kind):
|
| 176 |
+
func_and_location = self._impls[kind]
|
| 177 |
+
assert func_and_location is not None # Pacify mypy
|
| 178 |
+
location = func_and_location.location
|
| 179 |
+
raise RuntimeError(
|
| 180 |
+
f"Attempting to register a {kind} impl for operator {self._qualname} "
|
| 181 |
+
f"that already has a {kind} impl registered from Python at "
|
| 182 |
+
f"{location}. This is not supported."
|
| 183 |
+
)
|
| 184 |
+
frame = inspect.getframeinfo(sys._getframe(stacklevel))
|
| 185 |
+
location = f"{frame.filename}:{frame.lineno}"
|
| 186 |
+
self._impls[kind] = FuncAndLocation(func, location)
|
| 187 |
+
|
| 188 |
+
def _get_impl(self, kind):
|
| 189 |
+
return self._impls[kind]
|
| 190 |
+
|
| 191 |
+
def _has_impl(self, kind):
|
| 192 |
+
return kind in self._impls
|
| 193 |
+
|
| 194 |
+
def _destroy(self):
|
| 195 |
+
# NOTE: [CustomOp lifetime]
|
| 196 |
+
# A CustomOp, once created, lives forever. The mechanism is that the
|
| 197 |
+
# global registry holds a reference to it. However, to make testing
|
| 198 |
+
# easier, we want to be able to destroy CustomOp objects.
|
| 199 |
+
# CustomOp._destroy does the job, though it leaves the CustomOp
|
| 200 |
+
# in a garbage state.
|
| 201 |
+
del self._lib
|
| 202 |
+
|
| 203 |
+
opnamespace = getattr(torch.ops, self._cpp_ns)
|
| 204 |
+
if hasattr(opnamespace, self._opname):
|
| 205 |
+
delattr(opnamespace, self._opname)
|
| 206 |
+
|
| 207 |
+
del global_registry[self._qualname]
|
| 208 |
+
|
| 209 |
+
def __repr__(self):
|
| 210 |
+
return f'<CustomOp(op="{self._qualname}")>'
|
| 211 |
+
|
| 212 |
+
def __call__(self, *args, **kwargs):
|
| 213 |
+
# Bypass torch.ops.* and directly do OperatorHandle::callBoxed.
|
| 214 |
+
# Using torch.ops.* is a bit of a pain (it can be slow and it has lifetime
|
| 215 |
+
# issues from caching operators that make testing CustomOp difficult).
|
| 216 |
+
result = _C._dispatch_call_boxed(self._ophandle, *args, **kwargs)
|
| 217 |
+
return result
|
| 218 |
+
|
| 219 |
+
def impl(
|
| 220 |
+
self,
|
| 221 |
+
device_types: typing.Union[str, typing.Iterable[str]],
|
| 222 |
+
_stacklevel=2,
|
| 223 |
+
) -> typing.Callable:
|
| 224 |
+
r"""
|
| 225 |
+
This API is deprecated, please use torch.library.custom_op instead
|
| 226 |
+
"""
|
| 227 |
+
if isinstance(device_types, str):
|
| 228 |
+
device_types = [device_types]
|
| 229 |
+
for device_type in device_types:
|
| 230 |
+
validate_device_type(device_type)
|
| 231 |
+
|
| 232 |
+
def inner(f):
|
| 233 |
+
for device_type in set(device_types):
|
| 234 |
+
self._check_doesnt_have_library_impl(device_type)
|
| 235 |
+
self._register_impl(device_type, f, stacklevel=_stacklevel)
|
| 236 |
+
dispatch_key = SUPPORTED_DEVICE_TYPE_TO_KEY[device_type]
|
| 237 |
+
library.impl(self._lib, self._opname, dispatch_key)(f)
|
| 238 |
+
return f
|
| 239 |
+
|
| 240 |
+
return inner
|
| 241 |
+
|
| 242 |
+
def _check_doesnt_have_library_impl(self, device_type):
|
| 243 |
+
if self._has_impl(device_type):
|
| 244 |
+
return
|
| 245 |
+
key = SUPPORTED_DEVICE_TYPE_TO_KEY[device_type]
|
| 246 |
+
if _C._dispatch_has_computed_kernel_for_dispatch_key(self._qualname, key):
|
| 247 |
+
raise RuntimeError(
|
| 248 |
+
f"impl(..., device_types={device_type}): the operator {self._qualname} "
|
| 249 |
+
f"already has an implementation for this device type via a "
|
| 250 |
+
f"pre-existing torch.library or TORCH_LIBRARY registration."
|
| 251 |
+
)
|
| 252 |
+
|
| 253 |
+
def impl_factory(self) -> typing.Callable:
|
| 254 |
+
r"""Register an implementation for a factory function."""
|
| 255 |
+
|
| 256 |
+
def inner(f):
|
| 257 |
+
self._register_impl("factory", f)
|
| 258 |
+
library.impl(self._lib, self._opname, "BackendSelect")(f)
|
| 259 |
+
return f
|
| 260 |
+
|
| 261 |
+
return inner
|
| 262 |
+
|
| 263 |
+
def impl_abstract(self, _stacklevel=2) -> typing.Callable:
|
| 264 |
+
r"""
|
| 265 |
+
This API is deprecated, please use torch.library.custom_op instead
|
| 266 |
+
"""
|
| 267 |
+
|
| 268 |
+
def inner(f):
|
| 269 |
+
self._check_doesnt_have_library_meta_impl()
|
| 270 |
+
self._register_impl("abstract", f, stacklevel=_stacklevel)
|
| 271 |
+
location = self._get_impl("abstract").location
|
| 272 |
+
|
| 273 |
+
qualname = self._qualname
|
| 274 |
+
|
| 275 |
+
# Handle DispatchKey.Meta registration
|
| 276 |
+
@functools.wraps(f)
|
| 277 |
+
def f_with_ctx(*args, **kwargs):
|
| 278 |
+
def error_on_ctx():
|
| 279 |
+
raise RuntimeError(
|
| 280 |
+
f"Attempted to call get_ctx() for the meta implementation "
|
| 281 |
+
f"for {qualname}."
|
| 282 |
+
f"You have presumably called get_ctx() because the operator "
|
| 283 |
+
f"has a data-dependent output shape; if so, there is no "
|
| 284 |
+
f"such meta implementation and this error is the correct "
|
| 285 |
+
f"behavior. Otherwise, please remove the call to get_ctx() "
|
| 286 |
+
f"in the implementation registered with impl_abstract "
|
| 287 |
+
f"at {location}"
|
| 288 |
+
)
|
| 289 |
+
|
| 290 |
+
with torch._library.fake_impl.set_ctx_getter(error_on_ctx):
|
| 291 |
+
return f(*args, **kwargs)
|
| 292 |
+
|
| 293 |
+
self._lib.impl(self._opname, f_with_ctx, "Meta")
|
| 294 |
+
return f
|
| 295 |
+
|
| 296 |
+
return inner
|
| 297 |
+
|
| 298 |
+
def _check_can_register_backward(self):
|
| 299 |
+
def error(detail):
|
| 300 |
+
raise RuntimeError(
|
| 301 |
+
f"Cannot use torch._custom_ops APIs to register backward "
|
| 302 |
+
f"formula for {detail}. Got operator "
|
| 303 |
+
f"{self._qualname} with schema: {schema}"
|
| 304 |
+
)
|
| 305 |
+
|
| 306 |
+
schema = self._schema
|
| 307 |
+
if schema.kind() != SchemaKind.functional:
|
| 308 |
+
error("non-functional operator")
|
| 309 |
+
|
| 310 |
+
rets = schema.returns
|
| 311 |
+
if not schema.returns:
|
| 312 |
+
error("operator with no returns")
|
| 313 |
+
|
| 314 |
+
assert len(rets) > 0
|
| 315 |
+
is_non_mutating_view = any(
|
| 316 |
+
r.annotation is not None and not r.annotation.is_write for r in rets
|
| 317 |
+
)
|
| 318 |
+
if is_non_mutating_view:
|
| 319 |
+
error("operator that returns views")
|
| 320 |
+
|
| 321 |
+
# We make assumptions about the schema's return types.
|
| 322 |
+
allowed_return_types = {
|
| 323 |
+
BaseType(BaseTy.int): "int",
|
| 324 |
+
BaseType(BaseTy.SymInt): "SymInt",
|
| 325 |
+
BaseType(BaseTy.bool): "bool",
|
| 326 |
+
BaseType(BaseTy.float): "float",
|
| 327 |
+
BaseType(BaseTy.Tensor): "Tensor",
|
| 328 |
+
ListType(BaseType(BaseTy.Tensor), None): "List[Tensor]",
|
| 329 |
+
}
|
| 330 |
+
for ret in schema.returns:
|
| 331 |
+
if ret.type in allowed_return_types:
|
| 332 |
+
continue
|
| 333 |
+
error(
|
| 334 |
+
f"operator with return not in {list(allowed_return_types.values())} (got {ret.type})"
|
| 335 |
+
)
|
| 336 |
+
|
| 337 |
+
def _check_doesnt_have_library_autograd_impl(self):
|
| 338 |
+
if self._registered_autograd_kernel_indirection:
|
| 339 |
+
return
|
| 340 |
+
|
| 341 |
+
if _C._dispatch_has_kernel_for_dispatch_key(
|
| 342 |
+
self._qualname, "CompositeImplicitAutograd"
|
| 343 |
+
):
|
| 344 |
+
raise RuntimeError(
|
| 345 |
+
f"impl_backward/impl_save_for_backward: the operator {self._qualname} "
|
| 346 |
+
f"already has an implementation for this device type via a "
|
| 347 |
+
f"pre-existing registration to DispatchKey::CompositeImplicitAutograd."
|
| 348 |
+
f"CompositeImplicitAutograd operators do not need an autograd formula; "
|
| 349 |
+
f"instead, the operator will decompose into its constituents and those "
|
| 350 |
+
f"can have autograd formulas defined on them."
|
| 351 |
+
)
|
| 352 |
+
|
| 353 |
+
# We can improve this by adding "all Autograd<BACKEND> keys", but
|
| 354 |
+
# realistically people will just be using this API for CPU/CUDA for now.
|
| 355 |
+
for key in ["Autograd", "AutogradCPU", "AutogradCUDA"]:
|
| 356 |
+
if _C._dispatch_has_kernel_for_dispatch_key(self._qualname, key):
|
| 357 |
+
raise RuntimeError(
|
| 358 |
+
f"impl_backward/impl_save_for_backward: "
|
| 359 |
+
f"the operator {self._qualname} already has an Autograd kernel "
|
| 360 |
+
f"registered to DispatchKey::{key} vi a pre-existing "
|
| 361 |
+
f"torch.library or TORCH_LIBRARY registration. Please either "
|
| 362 |
+
f"remove those registrations or don't use the torch._custom_ops APIs"
|
| 363 |
+
)
|
| 364 |
+
|
| 365 |
+
def _check_doesnt_have_library_meta_impl(self):
|
| 366 |
+
if self._has_impl("abstract"):
|
| 367 |
+
return
|
| 368 |
+
|
| 369 |
+
# If the user's operator is CompositeExplicitAutograd,
|
| 370 |
+
# allow them to impl_abstract. This is being pragmatic
|
| 371 |
+
# (existing custom ops may have CompositeExplicitAutograd
|
| 372 |
+
# registration that don't work with Meta kernels, so this
|
| 373 |
+
# gives them an escape hatch).
|
| 374 |
+
if _C._dispatch_has_kernel_for_dispatch_key(
|
| 375 |
+
self._qualname, "CompositeExplicitAutograd"
|
| 376 |
+
) and not _C._dispatch_has_kernel_for_dispatch_key(self._qualname, "Meta"):
|
| 377 |
+
return
|
| 378 |
+
|
| 379 |
+
# Otherwise, if the user's already has a Meta kernel or their
|
| 380 |
+
# op is CompositeImplicitAutograd or some other alias dispatch key,
|
| 381 |
+
# raise.
|
| 382 |
+
|
| 383 |
+
# Special case for CompositeImplicitAutograd
|
| 384 |
+
if _C._dispatch_has_kernel_for_dispatch_key(
|
| 385 |
+
self._qualname, "CompositeImplicitAutograd"
|
| 386 |
+
):
|
| 387 |
+
raise RuntimeError(
|
| 388 |
+
f"impl_abstract(...): the operator {self._qualname} "
|
| 389 |
+
f"already has an implementation for this device type via a "
|
| 390 |
+
f"pre-existing registration to DispatchKey::CompositeImplicitAutograd."
|
| 391 |
+
f"CompositeImplicitAutograd operators do not need an abstract impl; "
|
| 392 |
+
f"instead, the operator will decompose into its constituents and those "
|
| 393 |
+
f"can have abstract impls defined on them."
|
| 394 |
+
)
|
| 395 |
+
|
| 396 |
+
if _C._dispatch_has_kernel_for_dispatch_key(self._qualname, "Meta"):
|
| 397 |
+
raise RuntimeError(
|
| 398 |
+
f"impl_abstract(...): the operator {self._qualname} "
|
| 399 |
+
f"already has an DispatchKey::Meta implementation via a "
|
| 400 |
+
f"pre-existing torch.library or TORCH_LIBRARY registration. "
|
| 401 |
+
f"Please either remove that registration or don't call impl_abstract."
|
| 402 |
+
)
|
| 403 |
+
|
| 404 |
+
# NOTE ["backward", "save_for_backward", and "autograd"]
|
| 405 |
+
# As a part of the explicit autograd API, a user must provide us
|
| 406 |
+
# a "save_for_backward" function and a "backward" function.
|
| 407 |
+
# When both of these have been provided, then we automatically
|
| 408 |
+
# construct the "autograd" kernel.
|
| 409 |
+
def _register_autograd_kernel(self):
|
| 410 |
+
assert self._has_impl("backward")
|
| 411 |
+
assert self._has_impl("save_for_backward")
|
| 412 |
+
kernel = construct_autograd_kernel(
|
| 413 |
+
self._schema,
|
| 414 |
+
self._output_differentiability,
|
| 415 |
+
self,
|
| 416 |
+
get_op(self._qualname),
|
| 417 |
+
self._get_impl("save_for_backward").func,
|
| 418 |
+
self._get_impl("backward").func,
|
| 419 |
+
)
|
| 420 |
+
self._register_impl("autograd", kernel)
|
| 421 |
+
|
| 422 |
+
def impl_save_for_backward(self, _stacklevel=2):
|
| 423 |
+
r"""Register a function that tells us what to save for backward.
|
| 424 |
+
|
| 425 |
+
Please see impl_backward for more details.
|
| 426 |
+
"""
|
| 427 |
+
|
| 428 |
+
def inner(f):
|
| 429 |
+
self._check_can_register_backward()
|
| 430 |
+
self._check_doesnt_have_library_autograd_impl()
|
| 431 |
+
if not self._registered_autograd_kernel_indirection:
|
| 432 |
+
self._register_autograd_kernel_indirection()
|
| 433 |
+
self._register_impl("save_for_backward", f, stacklevel=_stacklevel)
|
| 434 |
+
if self._has_impl("backward"):
|
| 435 |
+
self._register_autograd_kernel()
|
| 436 |
+
|
| 437 |
+
return inner
|
| 438 |
+
|
| 439 |
+
def impl_backward(self, output_differentiability=None, _stacklevel=2):
|
| 440 |
+
r"""
|
| 441 |
+
This API is deprecated, please use torch.library.custom_op instead
|
| 442 |
+
"""
|
| 443 |
+
if output_differentiability is not None:
|
| 444 |
+
|
| 445 |
+
def yell():
|
| 446 |
+
raise RuntimeError(
|
| 447 |
+
f"impl_backward(output_differentiability): expected "
|
| 448 |
+
f"output_differentiability to be a list of bools with "
|
| 449 |
+
f"length equal to the number of outputs of this CustomOp "
|
| 450 |
+
f"got: {output_differentiability}"
|
| 451 |
+
)
|
| 452 |
+
|
| 453 |
+
if not isinstance(output_differentiability, list):
|
| 454 |
+
yell()
|
| 455 |
+
for diff in output_differentiability:
|
| 456 |
+
if not isinstance(diff, bool):
|
| 457 |
+
yell()
|
| 458 |
+
if len(self._schema.returns) != len(output_differentiability):
|
| 459 |
+
yell()
|
| 460 |
+
|
| 461 |
+
def inner(f):
|
| 462 |
+
self._check_can_register_backward()
|
| 463 |
+
self._check_doesnt_have_library_autograd_impl()
|
| 464 |
+
if not self._registered_autograd_kernel_indirection:
|
| 465 |
+
self._register_autograd_kernel_indirection()
|
| 466 |
+
self._register_impl("backward", f, stacklevel=_stacklevel)
|
| 467 |
+
self._output_differentiability = output_differentiability
|
| 468 |
+
if self._has_impl("save_for_backward"):
|
| 469 |
+
self._register_autograd_kernel()
|
| 470 |
+
|
| 471 |
+
return inner
|
| 472 |
+
|
| 473 |
+
|
| 474 |
+
@dataclasses.dataclass
|
| 475 |
+
class FuncAndLocation:
|
| 476 |
+
func: typing.Callable
|
| 477 |
+
location: str
|
| 478 |
+
|
| 479 |
+
|
| 480 |
+
def find_ophandle_or_throw(cpp_ns: str, operator_name: OperatorName):
|
| 481 |
+
overload_name = (
|
| 482 |
+
"" if operator_name.overload_name is None else operator_name.overload_name
|
| 483 |
+
)
|
| 484 |
+
return _C._dispatch_find_schema_or_throw(
|
| 485 |
+
f"{cpp_ns}::{str(operator_name.name)}", overload_name
|
| 486 |
+
)
|
| 487 |
+
|
| 488 |
+
|
| 489 |
+
def validate_namespace(ns: str) -> None:
|
| 490 |
+
if "." in ns:
|
| 491 |
+
raise ValueError(
|
| 492 |
+
f'custom_op(..., ns="{ns}"): expected ns to not contain any . (and be a '
|
| 493 |
+
f"valid variable name)"
|
| 494 |
+
)
|
| 495 |
+
if ns in RESERVED_NS:
|
| 496 |
+
raise ValueError(
|
| 497 |
+
f"custom_op(..., ns='{ns}'): '{ns}' is a reserved namespace, "
|
| 498 |
+
f"please choose something else. "
|
| 499 |
+
)
|
| 500 |
+
|
| 501 |
+
|
| 502 |
+
def validate_schema(schema: FunctionSchema) -> None:
|
| 503 |
+
if not torch._library.utils.is_functional_schema(schema):
|
| 504 |
+
raise ValueError(
|
| 505 |
+
f"custom_op only supports functional operators "
|
| 506 |
+
f"(ops that do not mutate any inputs, do not return "
|
| 507 |
+
f"views of the inputs, and has at least one return). "
|
| 508 |
+
f"Got the following non-functional schema: {schema}"
|
| 509 |
+
)
|
| 510 |
+
|
| 511 |
+
# For simplicity: don't allow self arguments
|
| 512 |
+
if schema.arguments.self_arg is not None:
|
| 513 |
+
raise ValueError(
|
| 514 |
+
f"custom_op does not support arguments named 'self'. Please "
|
| 515 |
+
f"rename your argument. Got: {schema}"
|
| 516 |
+
)
|
| 517 |
+
|
| 518 |
+
|
| 519 |
+
def parse_qualname(qualname: str) -> tuple[str, str]:
|
| 520 |
+
names = qualname.split("::", 1)
|
| 521 |
+
if len(names) != 2:
|
| 522 |
+
raise ValueError(
|
| 523 |
+
f"Expected there to be a namespace in {qualname}, i.e. The "
|
| 524 |
+
f"operator name should look something like ns::foo"
|
| 525 |
+
)
|
| 526 |
+
if "." in names[1]:
|
| 527 |
+
raise ValueError(
|
| 528 |
+
f"The torch.custom_ops APIs do not handle overloads, "
|
| 529 |
+
f"i.e. operator names with '.' in them. "
|
| 530 |
+
f"Please name your operator something like ns::foo. "
|
| 531 |
+
f"Got: {qualname}"
|
| 532 |
+
)
|
| 533 |
+
return names[0], names[1]
|
| 534 |
+
|
| 535 |
+
|
| 536 |
+
def validate_device_type(device_type: str) -> None:
|
| 537 |
+
if device_type not in SUPPORTED_DEVICE_TYPE_TO_KEY:
|
| 538 |
+
raise ValueError(
|
| 539 |
+
f"CustomOp.impl(device_types=[{device_type}, ...]): we only support device_type "
|
| 540 |
+
f"in {SUPPORTED_DEVICE_TYPE_TO_KEY.keys()}."
|
| 541 |
+
)
|
| 542 |
+
|
| 543 |
+
|
| 544 |
+
def supported_param(param: inspect.Parameter) -> bool:
|
| 545 |
+
return param.kind in (
|
| 546 |
+
inspect.Parameter.POSITIONAL_OR_KEYWORD,
|
| 547 |
+
inspect.Parameter.KEYWORD_ONLY,
|
| 548 |
+
)
|
| 549 |
+
|
| 550 |
+
|
| 551 |
+
def validate_function_matches_schema(
|
| 552 |
+
schema: FunctionSchema, func: typing.Callable
|
| 553 |
+
) -> None:
|
| 554 |
+
sig = inspect.signature(func)
|
| 555 |
+
|
| 556 |
+
if not all(supported_param(p) for _, p in sig.parameters.items()):
|
| 557 |
+
raise ValueError(
|
| 558 |
+
f"custom_op(..., manual_schema)(func): positional-only args, "
|
| 559 |
+
f"varargs, and kwargs are not supported. Please rewrite `func` "
|
| 560 |
+
f"to not have them. Got `func` with signature: {sig}"
|
| 561 |
+
)
|
| 562 |
+
|
| 563 |
+
if (
|
| 564 |
+
any(
|
| 565 |
+
p.annotation is not inspect.Parameter.empty
|
| 566 |
+
for _, p in sig.parameters.items()
|
| 567 |
+
)
|
| 568 |
+
or sig.return_annotation is not inspect.Signature.empty
|
| 569 |
+
):
|
| 570 |
+
raise ValueError(
|
| 571 |
+
f"custom_op(..., manual_schema)(func): When passing in a manual "
|
| 572 |
+
f"schema, we expect `func` to have no type annotations to avoid "
|
| 573 |
+
f"ambiguity. Got `func` with signature: {sig}"
|
| 574 |
+
)
|
| 575 |
+
|
| 576 |
+
positional = [
|
| 577 |
+
(name, param)
|
| 578 |
+
for name, param in sig.parameters.items()
|
| 579 |
+
if param.kind == inspect.Parameter.POSITIONAL_OR_KEYWORD
|
| 580 |
+
]
|
| 581 |
+
kwargonly = [
|
| 582 |
+
(name, param)
|
| 583 |
+
for name, param in sig.parameters.items()
|
| 584 |
+
if param.kind == inspect.Parameter.KEYWORD_ONLY
|
| 585 |
+
]
|
| 586 |
+
|
| 587 |
+
def error():
|
| 588 |
+
raise ValueError(
|
| 589 |
+
f"custom_op(..., manual_schema)(func): When passing in a manual "
|
| 590 |
+
f"schema, we expect `func`'s signature to match `manual_schema` "
|
| 591 |
+
f"(aside from type annotations). "
|
| 592 |
+
f"func's signature: {sig}, manual_schema: {schema}"
|
| 593 |
+
)
|
| 594 |
+
|
| 595 |
+
def error_default_args():
|
| 596 |
+
raise ValueError(
|
| 597 |
+
f"custom_op(..., manual_schema)(func): "
|
| 598 |
+
f"neither func nor manual_schema should have default "
|
| 599 |
+
f"arguments. Got "
|
| 600 |
+
f"func's signature: {sig}, manual_schema: {schema}"
|
| 601 |
+
)
|
| 602 |
+
|
| 603 |
+
def compare(sig_args, schema_args):
|
| 604 |
+
if len(sig_args) != len(schema_args):
|
| 605 |
+
error()
|
| 606 |
+
for (name, param), arg in zip(sig_args, schema_args):
|
| 607 |
+
if name != arg.name:
|
| 608 |
+
error()
|
| 609 |
+
if param.default is not inspect.Parameter.empty or arg.default is not None:
|
| 610 |
+
error_default_args()
|
| 611 |
+
|
| 612 |
+
compare(positional, schema.arguments.flat_positional)
|
| 613 |
+
compare(kwargonly, schema.arguments.flat_kwarg_only)
|
| 614 |
+
|
| 615 |
+
|
| 616 |
+
def report_error_callback(custom_op: typing.Any, key: str) -> None:
|
| 617 |
+
if key == "Undefined":
|
| 618 |
+
raise NotImplementedError(
|
| 619 |
+
f"{custom_op}: There were no Tensor inputs to this operator "
|
| 620 |
+
f"(e.g. you passed an empty list of Tensors). If your operator is a "
|
| 621 |
+
f"factory function (that is, it takes no Tensors and constructs "
|
| 622 |
+
f"a new one), then please use CustomOp.impl_factory to register "
|
| 623 |
+
f"an implementation for it"
|
| 624 |
+
)
|
| 625 |
+
if key == "Meta":
|
| 626 |
+
raise NotImplementedError(
|
| 627 |
+
f"{custom_op}: when running with device='Meta' tensors: there is no "
|
| 628 |
+
f"abstract impl registered for this CustomOp. Please register one via "
|
| 629 |
+
f"CustomOp.impl_abstract to get this CustomOp to work with Meta tensors"
|
| 630 |
+
)
|
| 631 |
+
if key in ("CPU", "CUDA"):
|
| 632 |
+
device = key.lower()
|
| 633 |
+
raise NotImplementedError(
|
| 634 |
+
f"{custom_op}: when running with device='{device}' tensors: there is no "
|
| 635 |
+
f"{device} impl registered for this CustomOp. Please register one via "
|
| 636 |
+
f"CustomOp.impl(device_type='{device}')"
|
| 637 |
+
)
|
| 638 |
+
raise NotImplementedError(
|
| 639 |
+
f"{custom_op}: No implementation for dispatch key {key}. It is likely "
|
| 640 |
+
f"that we have not added this functionality yet, please either open an "
|
| 641 |
+
f"issue or if you're feeling adventurous, use the low-level "
|
| 642 |
+
f"torch.library API"
|
| 643 |
+
)
|
| 644 |
+
|
| 645 |
+
|
| 646 |
+
def custom_op_from_existing(op):
|
| 647 |
+
ns = op.namespace
|
| 648 |
+
lib = torch.library.Library(ns, "FRAGMENT")
|
| 649 |
+
name = op.name().split("::")[-1]
|
| 650 |
+
schema_str = str(op._schema)
|
| 651 |
+
# CustomOp expects the schema string without the namespace
|
| 652 |
+
schema_str = schema_str.rsplit("::", maxsplit=1)[-1]
|
| 653 |
+
schema = FunctionSchema.parse(schema_str)
|
| 654 |
+
return CustomOp(lib, ns, schema, name, op, _private_access=True)
|
| 655 |
+
|
| 656 |
+
|
| 657 |
+
def get_op(qualname):
|
| 658 |
+
def error_not_found():
|
| 659 |
+
raise ValueError(
|
| 660 |
+
f"Could not find the operator {qualname}. Please make sure you have "
|
| 661 |
+
f"already registered the operator and (if registered from C++) "
|
| 662 |
+
f"loaded it via torch.ops.load_library."
|
| 663 |
+
)
|
| 664 |
+
|
| 665 |
+
ns, name = parse_qualname(qualname)
|
| 666 |
+
if not hasattr(torch.ops, ns):
|
| 667 |
+
error_not_found()
|
| 668 |
+
opnamespace = getattr(torch.ops, ns)
|
| 669 |
+
if not hasattr(opnamespace, name):
|
| 670 |
+
error_not_found()
|
| 671 |
+
packet = getattr(opnamespace, name)
|
| 672 |
+
if not hasattr(packet, "default"):
|
| 673 |
+
error_not_found()
|
| 674 |
+
return packet.default
|
| 675 |
+
|
| 676 |
+
|
| 677 |
+
def _find_custom_op(qualname, also_check_torch_library=False):
|
| 678 |
+
if qualname in global_registry:
|
| 679 |
+
return global_registry[qualname]
|
| 680 |
+
if not also_check_torch_library:
|
| 681 |
+
raise RuntimeError(
|
| 682 |
+
f'Could not find custom op "{qualname}". Did you register it via '
|
| 683 |
+
f"the torch._custom_ops API?"
|
| 684 |
+
)
|
| 685 |
+
overload = get_op(qualname)
|
| 686 |
+
result = custom_op_from_existing(overload)
|
| 687 |
+
return result
|
| 688 |
+
|
| 689 |
+
|
| 690 |
+
def get_abstract_impl(qualname):
|
| 691 |
+
if qualname not in torch._custom_op.impl.global_registry:
|
| 692 |
+
return None
|
| 693 |
+
custom_op = torch._custom_op.impl.global_registry[qualname]
|
| 694 |
+
if custom_op is None:
|
| 695 |
+
return None
|
| 696 |
+
if not custom_op._has_impl("abstract"):
|
| 697 |
+
return None
|
| 698 |
+
return custom_op._get_impl("abstract").func
|
| 699 |
+
|
| 700 |
+
|
| 701 |
+
def _custom_op_with_schema(qualname, schema, needs_fixed_stride_order=True):
|
| 702 |
+
ns, name = qualname.split("::")
|
| 703 |
+
schema_str = f"{name}{schema}"
|
| 704 |
+
function_schema = FunctionSchema.parse(schema_str)
|
| 705 |
+
validate_schema(function_schema)
|
| 706 |
+
tags = [torch._C.Tag.needs_fixed_stride_order] if needs_fixed_stride_order else []
|
| 707 |
+
lib = library.Library(ns, "FRAGMENT")
|
| 708 |
+
lib.define(schema_str, tags=tags)
|
| 709 |
+
ophandle = find_ophandle_or_throw(ns, function_schema.name)
|
| 710 |
+
result = CustomOp(lib, ns, function_schema, name, ophandle, _private_access=True)
|
| 711 |
+
result._register_autograd_kernel_indirection()
|
| 712 |
+
|
| 713 |
+
torch._C._dispatch_set_report_error_callback(
|
| 714 |
+
ophandle, functools.partial(report_error_callback, weakref.proxy(result))
|
| 715 |
+
)
|
| 716 |
+
return get_op(qualname)
|
miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_custom_ops.py
ADDED
|
@@ -0,0 +1,326 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# mypy: allow-untyped-defs
|
| 2 |
+
import inspect
|
| 3 |
+
|
| 4 |
+
from torch._custom_op.impl import (
|
| 5 |
+
_custom_op_with_schema,
|
| 6 |
+
_find_custom_op,
|
| 7 |
+
infer_schema,
|
| 8 |
+
parse_qualname,
|
| 9 |
+
validate_namespace,
|
| 10 |
+
)
|
| 11 |
+
from torch.library import get_ctx
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
__all__ = [
|
| 15 |
+
"custom_op",
|
| 16 |
+
"impl",
|
| 17 |
+
"impl_abstract",
|
| 18 |
+
"get_ctx",
|
| 19 |
+
"impl_save_for_backward",
|
| 20 |
+
"impl_backward",
|
| 21 |
+
]
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def custom_op(qualname, func_or_schema=None):
|
| 25 |
+
r"""Register a new custom operator
|
| 26 |
+
|
| 27 |
+
In PyTorch, defining an op (short for "operator") is a two step-process:
|
| 28 |
+
- we need to define the op (by providing an operator name and schema)
|
| 29 |
+
- we need to implement behavior for how the operator interacts with
|
| 30 |
+
various PyTorch subsystems, like CPU/CUDA Tensors, Autograd, etc.
|
| 31 |
+
|
| 32 |
+
This entrypoint defines the custom operator (the first step)
|
| 33 |
+
you must then perform the second step by calling various
|
| 34 |
+
``impl_*`` APIs.
|
| 35 |
+
|
| 36 |
+
This API may be used as a decorator (see examples).
|
| 37 |
+
|
| 38 |
+
For a detailed guide on custom ops, please see
|
| 39 |
+
https://docs.google.com/document/d/1aGWtgxV3HppuxQAdddyPrs74_aEntpkYt9MalnCKnhk
|
| 40 |
+
|
| 41 |
+
Arguments:
|
| 42 |
+
qualname (str): Should be a string that looks like
|
| 43 |
+
"namespace::operator_name". Operators in PyTorch need a namespace to
|
| 44 |
+
avoid name collisions; a given operator may only be created once.
|
| 45 |
+
If you are writing a Python library, we recommend the namespace to
|
| 46 |
+
be the name of your top-level module.
|
| 47 |
+
func_or_schema (Union[Callable, str]): Each PyTorch operator needs a
|
| 48 |
+
schema that tells PyTorch the types of the inputs/outputs.
|
| 49 |
+
If this is a Callable, we will automatically infer the schema from
|
| 50 |
+
the type annotations on the function (see examples). Otherwise,
|
| 51 |
+
if you don't want to use type annotations, you may provide us the
|
| 52 |
+
schema string.
|
| 53 |
+
|
| 54 |
+
Example::
|
| 55 |
+
|
| 56 |
+
>>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA)
|
| 57 |
+
>>> import torch
|
| 58 |
+
>>> import numpy as np
|
| 59 |
+
>>> from torch import Tensor
|
| 60 |
+
>>>
|
| 61 |
+
>>> # Step 1: define the custom op.
|
| 62 |
+
>>> # We need to provide the API a "prototype function"
|
| 63 |
+
>>> # (a function that returns NotImplementedError), from which
|
| 64 |
+
>>> # we will infer the types of the inputs and outputs.
|
| 65 |
+
>>> @torch._custom_ops.custom_op("mylibrary::numpy_sin")
|
| 66 |
+
>>> def numpy_sin(x: Tensor) -> Tensor:
|
| 67 |
+
>>> raise NotImplementedError
|
| 68 |
+
>>>
|
| 69 |
+
>>> # The custom op is now accessible via the torch.ops module:
|
| 70 |
+
>>> torch.ops.mylibrary.numpy_sin
|
| 71 |
+
>>>
|
| 72 |
+
>>> # Step 2: Register an implementation for various PyTorch subsystems
|
| 73 |
+
>>>
|
| 74 |
+
>>> # Register an implementation for CPU tensors
|
| 75 |
+
>>> @torch._custom_ops.impl("mylibrary::numpy_sin", device_types="cpu")
|
| 76 |
+
>>> def numpy_sin_impl_cpu(x):
|
| 77 |
+
>>> return torch.from_numpy(np.sin(x.numpy()))
|
| 78 |
+
>>>
|
| 79 |
+
>>> # Register an implementation for CUDA tensors
|
| 80 |
+
>>> @torch._custom_ops.impl("mylibrary::numpy_sin", device_types="cuda")
|
| 81 |
+
>>> def numpy_sin_impl_cuda(x):
|
| 82 |
+
>>> return torch.from_numpy(np.sin(x.cpu().numpy())).to(x.device)
|
| 83 |
+
>>>
|
| 84 |
+
>>> x = torch.randn(3)
|
| 85 |
+
>>> torch.ops.mylibrary.numpy_sin(x) # calls numpy_sin_impl_cpu
|
| 86 |
+
>>>
|
| 87 |
+
>>> x_cuda = x.cuda()
|
| 88 |
+
>>> torch.ops.mylibrary.numpy_sin(x) # calls numpy_sin_impl_cuda
|
| 89 |
+
|
| 90 |
+
"""
|
| 91 |
+
ns, name = parse_qualname(qualname)
|
| 92 |
+
validate_namespace(ns)
|
| 93 |
+
|
| 94 |
+
def inner(func):
|
| 95 |
+
if not inspect.isfunction(func):
|
| 96 |
+
raise ValueError(
|
| 97 |
+
f"custom_op(...)(func): Expected `func` to be a Python "
|
| 98 |
+
f"function, got: {type(func)}"
|
| 99 |
+
)
|
| 100 |
+
|
| 101 |
+
if func.__name__ != name:
|
| 102 |
+
raise ValueError(
|
| 103 |
+
f"custom_op(qualname='{qualname}', ...)(func): expected `func` "
|
| 104 |
+
f"to have name '{name}' but got '{func.__name__}'. "
|
| 105 |
+
f"Please either change the name of `func` or the qualname that "
|
| 106 |
+
f"is passed to `custom_op`"
|
| 107 |
+
)
|
| 108 |
+
|
| 109 |
+
schema = infer_schema(func, mutates_args=())
|
| 110 |
+
_custom_op_with_schema(qualname, schema)
|
| 111 |
+
return func
|
| 112 |
+
|
| 113 |
+
if func_or_schema is None:
|
| 114 |
+
return inner
|
| 115 |
+
if isinstance(func_or_schema, str):
|
| 116 |
+
_custom_op_with_schema(qualname, func_or_schema)
|
| 117 |
+
else:
|
| 118 |
+
return inner(func_or_schema)
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
def impl(qualname, *, device_types=("cpu", "cuda"), func=None):
|
| 122 |
+
r"""Register an implementation for a device type for this custom op.
|
| 123 |
+
|
| 124 |
+
If the op is passed multiple Tensor inputs with different device
|
| 125 |
+
types, it will dispatch to the registered implementation for the highest
|
| 126 |
+
priority device type among those present.
|
| 127 |
+
The supported device types, in order of priority, are {'cuda', 'cpu'}.
|
| 128 |
+
|
| 129 |
+
This API may be used as a decorator (see examples).
|
| 130 |
+
|
| 131 |
+
For a detailed guide on custom ops, please see
|
| 132 |
+
https://docs.google.com/document/d/1aGWtgxV3HppuxQAdddyPrs74_aEntpkYt9MalnCKnhk
|
| 133 |
+
|
| 134 |
+
Arguments:
|
| 135 |
+
device_types (str or Iterable[str]): the device type(s) to register the function for.
|
| 136 |
+
|
| 137 |
+
Example::
|
| 138 |
+
|
| 139 |
+
>>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CUDA)
|
| 140 |
+
>>> import torch
|
| 141 |
+
>>> import numpy as np
|
| 142 |
+
>>> from torch import Tensor
|
| 143 |
+
>>>
|
| 144 |
+
>>> # Step 1: define the custom op.
|
| 145 |
+
>>> # We need to provide the API a "prototype function"
|
| 146 |
+
>>> # (a function that returns NotImplementedError), from which
|
| 147 |
+
>>> # we will infer the types of the inputs and outputs.
|
| 148 |
+
>>> @torch._custom_ops.custom_op("mylibrary::numpy_cos")
|
| 149 |
+
>>> def numpy_cos(x: Tensor) -> Tensor:
|
| 150 |
+
>>> raise NotImplementedError
|
| 151 |
+
>>>
|
| 152 |
+
>>> # The custom op is now accessible via the torch.ops module:
|
| 153 |
+
>>> torch.ops.mylibrary.numpy_cos
|
| 154 |
+
>>>
|
| 155 |
+
>>> # Step 2: Register an implementation for various PyTorch subsystems
|
| 156 |
+
>>>
|
| 157 |
+
>>> # Register an implementation for CPU tensors
|
| 158 |
+
>>> @torch._custom_ops.impl("mylibrary::numpy_cos", device_types="cpu")
|
| 159 |
+
>>> def numpy_cos_impl_cpu(x):
|
| 160 |
+
>>> return torch.from_numpy(np.cos(x.numpy()))
|
| 161 |
+
>>>
|
| 162 |
+
>>> # Register an implementation for CUDA tensors
|
| 163 |
+
>>> @torch._custom_ops.impl("mylibrary::numpy_cos", device_types="cuda")
|
| 164 |
+
>>> def numpy_cos_impl_cuda(x):
|
| 165 |
+
>>> return torch.from_numpy(np.cos(x.cpu().numpy())).to(x.device)
|
| 166 |
+
>>>
|
| 167 |
+
>>> x = torch.randn(3)
|
| 168 |
+
>>> torch.ops.mylibrary.numpy_cos(x) # calls numpy_cos_impl_cpu
|
| 169 |
+
>>>
|
| 170 |
+
>>> x_cuda = x.cuda()
|
| 171 |
+
>>> torch.ops.mylibrary.numpy_cos(x) # calls numpy_cos_impl_cuda
|
| 172 |
+
|
| 173 |
+
"""
|
| 174 |
+
|
| 175 |
+
def inner(func):
|
| 176 |
+
custom_op = _find_custom_op(qualname, also_check_torch_library=True)
|
| 177 |
+
custom_op.impl(device_types, _stacklevel=3)(func)
|
| 178 |
+
return func
|
| 179 |
+
|
| 180 |
+
if func is None:
|
| 181 |
+
return inner
|
| 182 |
+
return inner(func)
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
def impl_abstract(qualname, *, func=None):
|
| 186 |
+
r"""Register an abstract implementation for this operator.
|
| 187 |
+
|
| 188 |
+
An "abstract implementation" specifies the behavior of this operator on
|
| 189 |
+
Tensors that carry no data. Given some input Tensors with certain properties
|
| 190 |
+
(sizes/strides/storage_offset/device), it specifies what the properties of
|
| 191 |
+
the output Tensors are.
|
| 192 |
+
|
| 193 |
+
The abstract implementation has the same signature as the operator.
|
| 194 |
+
It is run for both FakeTensors and meta tensors. To write an abstract
|
| 195 |
+
implementation, assume that all Tensor inputs to the operator are
|
| 196 |
+
regular CPU/CUDA/Meta tensors, but they do not have storage, and
|
| 197 |
+
you are trying to return regular CPU/CUDA/Meta tensor(s) as output.
|
| 198 |
+
The abstract implementation must consist of only PyTorch operations
|
| 199 |
+
(and may not directly access the storage or data of any input or
|
| 200 |
+
intermediate Tensors).
|
| 201 |
+
|
| 202 |
+
This API may be used as a decorator (see examples).
|
| 203 |
+
|
| 204 |
+
For a detailed guide on custom ops, please see
|
| 205 |
+
https://docs.google.com/document/d/1aGWtgxV3HppuxQAdddyPrs74_aEntpkYt9MalnCKnhk
|
| 206 |
+
|
| 207 |
+
Examples::
|
| 208 |
+
>>> import numpy as np
|
| 209 |
+
>>> from torch import Tensor
|
| 210 |
+
>>>
|
| 211 |
+
>>> # Example 1: an operator without data-dependent output shape
|
| 212 |
+
>>> @torch._custom_ops.custom_op("mylibrary::custom_linear")
|
| 213 |
+
>>> def custom_linear(x: Tensor, weight: Tensor, bias: Tensor) -> Tensor:
|
| 214 |
+
>>> raise NotImplementedError
|
| 215 |
+
>>>
|
| 216 |
+
>>> @torch._custom_ops.impl_abstract("mylibrary::custom_linear")
|
| 217 |
+
>>> def custom_linear_abstract(x, weight):
|
| 218 |
+
>>> assert x.dim() == 2
|
| 219 |
+
>>> assert weight.dim() == 2
|
| 220 |
+
>>> assert bias.dim() == 1
|
| 221 |
+
>>> assert x.shape[1] == weight.shape[1]
|
| 222 |
+
>>> assert weight.shape[0] == bias.shape[0]
|
| 223 |
+
>>> assert x.device == weight.device
|
| 224 |
+
>>>
|
| 225 |
+
>>> return (x @ weight.t()) + bias
|
| 226 |
+
>>>
|
| 227 |
+
>>> # Example 2: an operator with data-dependent output shape
|
| 228 |
+
>>> @torch._custom_ops.custom_op('mylibrary::custom_nonzero')
|
| 229 |
+
>>> def custom_nonzero(x: Tensor) -> Tensor:
|
| 230 |
+
>>> ...
|
| 231 |
+
>>>
|
| 232 |
+
>>> @torch._custom_ops.impl_abstract("mylibrary::custom_nonzero")
|
| 233 |
+
>>> def custom_nonzero_abstract(x):
|
| 234 |
+
>>> # Number of nonzero-elements is data-dependent.
|
| 235 |
+
>>> # Since we cannot peek at the data in an abstract impl,
|
| 236 |
+
>>> # we use the ctx object to construct a new symint that
|
| 237 |
+
>>> # represents the data-dependent size.
|
| 238 |
+
>>> ctx = torch._custom_ops.get_ctx()
|
| 239 |
+
>>> nnz = ctx.create_unbacked_symint()
|
| 240 |
+
>>> shape = [x.dim(), nnz]
|
| 241 |
+
>>> result = x.new_empty(shape, dtype=torch.long)
|
| 242 |
+
>>> return result
|
| 243 |
+
>>>
|
| 244 |
+
>>> @torch._custom_ops.impl("mylibrary::custom_nonzero")
|
| 245 |
+
>>> def custom_nonzero_impl(x):
|
| 246 |
+
>>> x_np = to_numpy(x)
|
| 247 |
+
>>> res = np.stack(np.nonzero(x_np), axis=1)
|
| 248 |
+
>>> # unbacked symbolic ints in PyTorch must be >= 2, so we
|
| 249 |
+
>>> # constrain the range to at least 2
|
| 250 |
+
>>> if res.shape[0] <= 1:
|
| 251 |
+
>>> raise RuntimeError("not supported")
|
| 252 |
+
>>> return torch.tensor(res, device=x.device)
|
| 253 |
+
|
| 254 |
+
"""
|
| 255 |
+
import torch.library
|
| 256 |
+
|
| 257 |
+
return torch.library.register_fake(qualname, func, _stacklevel=2)
|
| 258 |
+
|
| 259 |
+
|
| 260 |
+
def impl_save_for_backward(qualname, *, func=None):
|
| 261 |
+
r"""Register a function that tells us what to save for backward.
|
| 262 |
+
|
| 263 |
+
Please see :func:`impl_backward` for more details.
|
| 264 |
+
"""
|
| 265 |
+
|
| 266 |
+
def inner(func):
|
| 267 |
+
custom_op = _find_custom_op(qualname, also_check_torch_library=True)
|
| 268 |
+
custom_op.impl_save_for_backward(_stacklevel=3)(func)
|
| 269 |
+
return func
|
| 270 |
+
|
| 271 |
+
if func is None:
|
| 272 |
+
return inner
|
| 273 |
+
return inner(func)
|
| 274 |
+
|
| 275 |
+
|
| 276 |
+
def impl_backward(qualname, output_differentiability=None, *, func=None):
|
| 277 |
+
r"""Registers a backward formula for an operator.
|
| 278 |
+
|
| 279 |
+
In order for an operator to work with autograd, you need to register
|
| 280 |
+
a backward formula. There are two pieces to this:
|
| 281 |
+
1. You must give us a function to specify what to save for backward.
|
| 282 |
+
Call this the "save for backward" function.
|
| 283 |
+
2. You must give us a function that computes gradients. Call this the
|
| 284 |
+
"backward" function.
|
| 285 |
+
|
| 286 |
+
Use `impl_save_for_backward` to define a "save for backward" function
|
| 287 |
+
that specifies what gets saved for backward. The function should accept
|
| 288 |
+
two arguments ``(inputs, output)`` and return the quantities to be saved
|
| 289 |
+
for backward.
|
| 290 |
+
|
| 291 |
+
During runtime, when you call the operator in a forwards pass, PyTorch
|
| 292 |
+
will invoke the "save for backward" function with the inputs and output
|
| 293 |
+
of the operator.
|
| 294 |
+
|
| 295 |
+
Use `impl_backward` to define the "backward" function. The backward
|
| 296 |
+
function must accept ``(ctx, saved, *grads)``:
|
| 297 |
+
- ``ctx`` is a context object where we may provide information
|
| 298 |
+
- ``saved`` is exactly what gets returned from the "save for backward"
|
| 299 |
+
function
|
| 300 |
+
- ``grads`` is one or more gradients. The number of gradients matches
|
| 301 |
+
the number of outputs of the operator.
|
| 302 |
+
|
| 303 |
+
The backward function must return a dict that maps the name of
|
| 304 |
+
an input to the operator to its corresponding gradient. All inputs that
|
| 305 |
+
were declared to be Tensors in the operator definition must be accounted
|
| 306 |
+
for in the dict. The gradient may be a Tensor or None.
|
| 307 |
+
|
| 308 |
+
For a detailed guide on custom ops, please see
|
| 309 |
+
https://docs.google.com/document/d/1aGWtgxV3HppuxQAdddyPrs74_aEntpkYt9MalnCKnhk
|
| 310 |
+
|
| 311 |
+
"""
|
| 312 |
+
|
| 313 |
+
def inner(func):
|
| 314 |
+
custom_op = _find_custom_op(qualname, also_check_torch_library=True)
|
| 315 |
+
custom_op.impl_backward(output_differentiability, _stacklevel=3)(func)
|
| 316 |
+
return func
|
| 317 |
+
|
| 318 |
+
if func is None:
|
| 319 |
+
return inner
|
| 320 |
+
return inner(func)
|
| 321 |
+
|
| 322 |
+
|
| 323 |
+
def _destroy(qualname):
|
| 324 |
+
"""De-registers a custom op. For testing purposes only"""
|
| 325 |
+
custom_op = _find_custom_op(qualname)
|
| 326 |
+
custom_op._destroy()
|
miniconda3/envs/ladir/lib/python3.10/site-packages/torch/_decomp/__init__.py
ADDED
|
@@ -0,0 +1,549 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# mypy: allow-untyped-defs
|
| 2 |
+
import inspect
|
| 3 |
+
from collections import defaultdict
|
| 4 |
+
from collections.abc import Callable, Sequence
|
| 5 |
+
from functools import lru_cache, partial, wraps
|
| 6 |
+
from itertools import chain
|
| 7 |
+
from typing import Optional, TYPE_CHECKING, TypeVar, Union
|
| 8 |
+
from typing_extensions import ParamSpec
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
if TYPE_CHECKING:
|
| 12 |
+
from torch.export.decomp_utils import CustomDecompTable
|
| 13 |
+
|
| 14 |
+
import torch
|
| 15 |
+
import torch.library
|
| 16 |
+
from torch._ops import HigherOrderOperator, OperatorBase, OpOverload, OpOverloadPacket
|
| 17 |
+
from torch._prims_common import CustomOutParamAnnotation
|
| 18 |
+
from torch._subclasses.functional_tensor import FunctionalTensor
|
| 19 |
+
from torch.utils import _pytree as pytree
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
__all__ = [
|
| 23 |
+
"decomposition_table",
|
| 24 |
+
"pre_autograd_decomposition_table",
|
| 25 |
+
"meta_table",
|
| 26 |
+
"register_decomposition",
|
| 27 |
+
"get_decompositions",
|
| 28 |
+
"core_aten_decompositions",
|
| 29 |
+
"_should_decompose_because_unsafe_op",
|
| 30 |
+
]
|
| 31 |
+
|
| 32 |
+
_T = TypeVar("_T")
|
| 33 |
+
_P = ParamSpec("_P")
|
| 34 |
+
|
| 35 |
+
# TODO: relax key type here; torch registrations should be possible to; but
|
| 36 |
+
# right now this type is accurate
|
| 37 |
+
global_decomposition_table: dict[str, dict[torch._ops.OperatorBase, Callable]] = (
|
| 38 |
+
defaultdict(dict)
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
decomposition_table = global_decomposition_table["post_autograd"]
|
| 42 |
+
pre_autograd_decomposition_table = global_decomposition_table["pre_autograd"]
|
| 43 |
+
meta_table = global_decomposition_table["meta"]
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def _should_decompose_because_unsafe_op(op: torch._ops.OperatorBase) -> bool:
|
| 47 |
+
"""
|
| 48 |
+
Returns True if the op must always decompose in export/compile tracing system
|
| 49 |
+
|
| 50 |
+
In export, we always decompose certain CIA ops that are tagged with
|
| 51 |
+
maybe_aliasing_or_mutating because we statically need to know if the op is
|
| 52 |
+
mutating or not. But these CIA ops could have different behaviour in runtime.
|
| 53 |
+
|
| 54 |
+
native_batch_norm is a prim op which has a wrong schema and it needs to be replaced
|
| 55 |
+
with correct schema. But until then, we will force decompose it via this tag.
|
| 56 |
+
"""
|
| 57 |
+
if not isinstance(op, torch._ops.OpOverload):
|
| 58 |
+
return False
|
| 59 |
+
if torch.Tag.maybe_aliasing_or_mutating in op.tags:
|
| 60 |
+
return True
|
| 61 |
+
return op is torch.ops.aten.native_batch_norm.default
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def _add_op_to_registry(registry, op, fn):
|
| 65 |
+
"""
|
| 66 |
+
This is an internal API for adding an op to the decomposition table.
|
| 67 |
+
|
| 68 |
+
If op is OpOverload, it will be added to the registry directly.
|
| 69 |
+
If op is OpOverloadPacket, all the valid op_overloads in the packet will be added to the registry.
|
| 70 |
+
"""
|
| 71 |
+
overloads: list[Union[torch._ops.OperatorBase]] = []
|
| 72 |
+
if isinstance(op, HigherOrderOperator):
|
| 73 |
+
# There's no concept of overloads for HigherOrderOperator
|
| 74 |
+
registry[op] = fn
|
| 75 |
+
return
|
| 76 |
+
elif isinstance(op, OpOverload):
|
| 77 |
+
overloads.append(op)
|
| 78 |
+
else:
|
| 79 |
+
assert isinstance(op, OpOverloadPacket)
|
| 80 |
+
for ol in op.overloads():
|
| 81 |
+
overloads.append(getattr(op, ol))
|
| 82 |
+
|
| 83 |
+
for op_overload in overloads:
|
| 84 |
+
if op_overload in registry:
|
| 85 |
+
raise RuntimeError(f"duplicate registrations for {op_overload}")
|
| 86 |
+
# TorchScript dumps a bunch of extra nonsense overloads
|
| 87 |
+
# which don't have corresponding dispatcher entries, we need
|
| 88 |
+
# to filter those out, e.g aten.add.float_int
|
| 89 |
+
if torch._C._dispatch_has_kernel(op_overload.name()):
|
| 90 |
+
registry[op_overload] = fn
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
def _convert_out_params(f):
|
| 94 |
+
out_annotation = f.__annotations__.get("out")
|
| 95 |
+
|
| 96 |
+
# If there are no out params, do not wrap the function.
|
| 97 |
+
if not out_annotation:
|
| 98 |
+
return f
|
| 99 |
+
|
| 100 |
+
# Hack to detect when out is a Tuple. There seems to be no pretty way of doing this
|
| 101 |
+
if getattr(out_annotation, "__origin__", None) is tuple:
|
| 102 |
+
sig = inspect.signature(f)
|
| 103 |
+
out_names = sig.return_annotation._fields
|
| 104 |
+
# If out is a tuple, we need to register a function that unpacks all the out
|
| 105 |
+
# elements as this is what native_functions.yaml expects
|
| 106 |
+
|
| 107 |
+
@wraps(f)
|
| 108 |
+
def _fn(*args, **kwargs):
|
| 109 |
+
out_kwargs = tuple(kwargs.pop(o, None) for o in out_names)
|
| 110 |
+
# Either all of the out kwargs are set or none of them
|
| 111 |
+
is_none = out_kwargs[0] is None
|
| 112 |
+
assert all((o is None) == is_none for o in out_kwargs)
|
| 113 |
+
return f(*args, **kwargs, out=None if is_none else out_kwargs)
|
| 114 |
+
|
| 115 |
+
out_params = [
|
| 116 |
+
inspect.Parameter(
|
| 117 |
+
o,
|
| 118 |
+
kind=inspect.Parameter.KEYWORD_ONLY,
|
| 119 |
+
default=None,
|
| 120 |
+
annotation=t,
|
| 121 |
+
)
|
| 122 |
+
for o, t in zip(out_names, out_annotation.__args__)
|
| 123 |
+
]
|
| 124 |
+
# Drop the out parameter and concatenate the new kwargs in the signature
|
| 125 |
+
params = chain((v for k, v in sig.parameters.items() if k != "out"), out_params)
|
| 126 |
+
_fn.__signature__ = inspect.Signature( # type: ignore[attr-defined]
|
| 127 |
+
parameters=params, # type: ignore[arg-type]
|
| 128 |
+
return_annotation=sig.return_annotation,
|
| 129 |
+
)
|
| 130 |
+
# Drop the out parameter and concatenate the new kwargs in the annotations
|
| 131 |
+
_fn.__annotations__ = {k: v for k, v in f.__annotations__.items() if k != "out"}
|
| 132 |
+
for o in out_params:
|
| 133 |
+
_fn.__annotations__[o.name] = o.annotation
|
| 134 |
+
|
| 135 |
+
# Propagate that this function is wrapped by `out_wrapper`
|
| 136 |
+
_fn._torch_decompositions_out_wrapper = f._torch_decompositions_out_wrapper # type: ignore[attr-defined]
|
| 137 |
+
|
| 138 |
+
return _fn
|
| 139 |
+
|
| 140 |
+
# Alternatively, there may be a single tensor out parameter with a name
|
| 141 |
+
# other than "out". This will need special treatment and is indicated by an
|
| 142 |
+
# annotation, which we will remove here so it is not exposed after wrapping.
|
| 143 |
+
custom_out_param_name = f.__annotations__.pop(CustomOutParamAnnotation, None)
|
| 144 |
+
if custom_out_param_name:
|
| 145 |
+
|
| 146 |
+
@wraps(f)
|
| 147 |
+
def _fn(*args, **kwargs):
|
| 148 |
+
out_kwarg = kwargs.pop(custom_out_param_name, None)
|
| 149 |
+
return f(*args, **kwargs, out=out_kwarg)
|
| 150 |
+
|
| 151 |
+
out_param = inspect.Parameter(
|
| 152 |
+
custom_out_param_name,
|
| 153 |
+
kind=inspect.Parameter.KEYWORD_ONLY,
|
| 154 |
+
default=None,
|
| 155 |
+
annotation=out_annotation,
|
| 156 |
+
)
|
| 157 |
+
|
| 158 |
+
# Drop the out parameter and concatenate the new kwarg in the signature
|
| 159 |
+
sig = inspect.signature(f)
|
| 160 |
+
params = chain(
|
| 161 |
+
(v for k, v in sig.parameters.items() if k != "out"), (out_param,)
|
| 162 |
+
)
|
| 163 |
+
_fn.__signature__ = inspect.Signature( # type: ignore[attr-defined]
|
| 164 |
+
parameters=params, # type: ignore[arg-type]
|
| 165 |
+
return_annotation=sig.return_annotation,
|
| 166 |
+
)
|
| 167 |
+
|
| 168 |
+
# Drop the out parameter and concatenate the new kwargs in the annotations
|
| 169 |
+
_fn.__annotations__ = {k: v for k, v in f.__annotations__.items() if k != "out"}
|
| 170 |
+
_fn.__annotations__[out_param.name] = out_param.annotation
|
| 171 |
+
|
| 172 |
+
return _fn
|
| 173 |
+
|
| 174 |
+
return f
|
| 175 |
+
|
| 176 |
+
|
| 177 |
+
def register_decomposition(
|
| 178 |
+
aten_op, registry=None, *, type="post_autograd", unsafe=False
|
| 179 |
+
) -> Callable[[Callable[_P, _T]], Callable[_P, _T]]:
|
| 180 |
+
"""
|
| 181 |
+
A decorator to register a function as a decomposition to the Python
|
| 182 |
+
decomposition table. Use it like this::
|
| 183 |
+
|
| 184 |
+
@register_decomposition(torch.ops.aten.clamp_min)
|
| 185 |
+
def clamp_min(x):
|
| 186 |
+
return torch.clamp(self, min=min)
|
| 187 |
+
|
| 188 |
+
If you are writing a new decomposition, consider contributing it
|
| 189 |
+
directly to PyTorch in torch._decomp.decompositions.
|
| 190 |
+
|
| 191 |
+
This API is experimental; we are almost certainly going to extend
|
| 192 |
+
the API when we make decompositions eligible for use in transforms (e.g.,
|
| 193 |
+
autograd) and not just backend tracing, where we then need to know if a
|
| 194 |
+
decomposition can be used to simulate a transform.
|
| 195 |
+
|
| 196 |
+
By default, we also will register it to the Meta key of dispatcher,
|
| 197 |
+
and replace the c++ Meta implementation if there is already one.
|
| 198 |
+
|
| 199 |
+
unsafe kwarg is for reuse of this function for registering non-function
|
| 200 |
+
things
|
| 201 |
+
"""
|
| 202 |
+
|
| 203 |
+
assert type in {"post_autograd", "pre_autograd", "meta"}
|
| 204 |
+
|
| 205 |
+
def decomposition_decorator(fn: Callable[_P, _T]) -> Callable[_P, _T]:
|
| 206 |
+
orig_fn = fn
|
| 207 |
+
if not unsafe:
|
| 208 |
+
fn = _convert_out_params(fn)
|
| 209 |
+
|
| 210 |
+
nonlocal registry
|
| 211 |
+
if registry is None:
|
| 212 |
+
registry = global_decomposition_table[type]
|
| 213 |
+
|
| 214 |
+
def register(op):
|
| 215 |
+
_add_op_to_registry(registry, op, fn)
|
| 216 |
+
|
| 217 |
+
# To handle allowing multiple aten_ops at once
|
| 218 |
+
pytree.tree_map_(register, aten_op)
|
| 219 |
+
return orig_fn
|
| 220 |
+
|
| 221 |
+
return decomposition_decorator
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
def get_decompositions(
|
| 225 |
+
aten_ops: Sequence[Union[torch._ops.OperatorBase, OpOverloadPacket]],
|
| 226 |
+
type: str = "post_autograd",
|
| 227 |
+
) -> dict[torch._ops.OperatorBase, Callable]:
|
| 228 |
+
"""
|
| 229 |
+
Retrieve a dictionary of decompositions corresponding to the list of
|
| 230 |
+
operator overloads and overload packets passed as input. Overload
|
| 231 |
+
packets will include all decomposed overloads in the packet. If there is
|
| 232 |
+
no decomposition for a requested operator, it is silently ignored.
|
| 233 |
+
|
| 234 |
+
This API is experimental; we are almost certainly going to give an alternate,
|
| 235 |
+
more recommended formulation, where a user provides the set of operators
|
| 236 |
+
they know how to implement, and we provide decompositions for everything
|
| 237 |
+
not in this set.
|
| 238 |
+
"""
|
| 239 |
+
assert type in {"post_autograd", "pre_autograd", "meta"}
|
| 240 |
+
|
| 241 |
+
registry = global_decomposition_table[type]
|
| 242 |
+
packets_to_overloads = defaultdict(list)
|
| 243 |
+
|
| 244 |
+
for opo in registry:
|
| 245 |
+
if isinstance(opo, (OpOverload, OpOverloadPacket)):
|
| 246 |
+
packets_to_overloads[opo.overloadpacket].append(opo)
|
| 247 |
+
decompositions: dict[torch._ops.OperatorBase, Callable] = {}
|
| 248 |
+
for op in aten_ops:
|
| 249 |
+
if isinstance(op, OpOverloadPacket) and op in packets_to_overloads:
|
| 250 |
+
for op_overload in packets_to_overloads[op]:
|
| 251 |
+
decompositions[op_overload] = registry[op_overload]
|
| 252 |
+
elif isinstance(op, (torch._ops.OperatorBase)) and op in registry:
|
| 253 |
+
decompositions[op] = registry[op]
|
| 254 |
+
return decompositions
|
| 255 |
+
|
| 256 |
+
|
| 257 |
+
def remove_decompositions(
|
| 258 |
+
decompositions: dict[torch._ops.OperatorBase, Callable],
|
| 259 |
+
aten_ops: Sequence[Union[OpOverload, OpOverloadPacket]],
|
| 260 |
+
) -> None:
|
| 261 |
+
"""
|
| 262 |
+
Given a dictionary of decompositions obtained from get_decompositions(), removes
|
| 263 |
+
operators associated with a list of operator overloads and overload packets passed
|
| 264 |
+
as input. If the decomposition dictionary does not contain a decomposition that is
|
| 265 |
+
specified to be removed, it is silently ignored.
|
| 266 |
+
"""
|
| 267 |
+
for op in aten_ops:
|
| 268 |
+
if isinstance(op, OpOverloadPacket):
|
| 269 |
+
for overload_name in op.overloads():
|
| 270 |
+
opo = getattr(op, overload_name)
|
| 271 |
+
decompositions.pop(opo, None)
|
| 272 |
+
elif isinstance(op, OpOverload):
|
| 273 |
+
decompositions.pop(op, None)
|
| 274 |
+
|
| 275 |
+
|
| 276 |
+
# populate the table
|
| 277 |
+
import torch._decomp.decompositions
|
| 278 |
+
import torch._refs
|
| 279 |
+
|
| 280 |
+
|
| 281 |
+
def core_aten_decompositions() -> "CustomDecompTable":
|
| 282 |
+
from torch.export.exported_program import default_decompositions
|
| 283 |
+
|
| 284 |
+
return default_decompositions()
|
| 285 |
+
|
| 286 |
+
|
| 287 |
+
# See NOTE [Core ATen Ops]
|
| 288 |
+
#
|
| 289 |
+
# list was copied from torch/_inductor/decomposition.py
|
| 290 |
+
# excluding decompositions that results in prim ops
|
| 291 |
+
# Resulting opset of decomposition is core aten ops
|
| 292 |
+
def _core_aten_decompositions_post_autograd() -> dict[
|
| 293 |
+
torch._ops.OperatorBase, Callable
|
| 294 |
+
]:
|
| 295 |
+
aten = torch.ops.aten
|
| 296 |
+
return get_decompositions(
|
| 297 |
+
[
|
| 298 |
+
aten.addcdiv,
|
| 299 |
+
aten.addcdiv_,
|
| 300 |
+
aten.addcmul,
|
| 301 |
+
aten.addcmul_,
|
| 302 |
+
aten.addr,
|
| 303 |
+
aten.affine_grid_generator,
|
| 304 |
+
aten.alias_copy,
|
| 305 |
+
aten.all,
|
| 306 |
+
aten.aminmax,
|
| 307 |
+
aten.arange.default,
|
| 308 |
+
aten.arange.start,
|
| 309 |
+
aten.avg_pool2d_backward,
|
| 310 |
+
aten.baddbmm,
|
| 311 |
+
aten.binary_cross_entropy,
|
| 312 |
+
aten.binary_cross_entropy_backward,
|
| 313 |
+
aten.binary_cross_entropy_with_logits,
|
| 314 |
+
aten.block_diag,
|
| 315 |
+
aten.bernoulli.p,
|
| 316 |
+
aten.bernoulli.default,
|
| 317 |
+
aten.celu,
|
| 318 |
+
aten.celu_,
|
| 319 |
+
aten.channel_shuffle,
|
| 320 |
+
aten.clamp_max,
|
| 321 |
+
aten.clamp_min,
|
| 322 |
+
aten.col2im,
|
| 323 |
+
aten.count_nonzero,
|
| 324 |
+
aten.linalg_cross,
|
| 325 |
+
aten.cudnn_batch_norm,
|
| 326 |
+
aten.cudnn_batch_norm_backward,
|
| 327 |
+
aten.miopen_batch_norm_backward,
|
| 328 |
+
aten.deg2rad,
|
| 329 |
+
aten.deg2rad_,
|
| 330 |
+
aten.detach,
|
| 331 |
+
aten.diag_embed,
|
| 332 |
+
aten.diagonal_backward,
|
| 333 |
+
aten.diagonal_copy,
|
| 334 |
+
aten.dot,
|
| 335 |
+
aten.vdot,
|
| 336 |
+
aten.elu_,
|
| 337 |
+
aten.elu_backward,
|
| 338 |
+
aten._embedding_bag,
|
| 339 |
+
aten.embedding_dense_backward,
|
| 340 |
+
aten.empty_like,
|
| 341 |
+
aten._euclidean_dist.default,
|
| 342 |
+
aten.expand_as,
|
| 343 |
+
aten.expand_copy,
|
| 344 |
+
aten.eye,
|
| 345 |
+
aten.fill,
|
| 346 |
+
aten.fill_,
|
| 347 |
+
aten.floor_divide,
|
| 348 |
+
aten.frac,
|
| 349 |
+
aten.frac_,
|
| 350 |
+
aten._fused_moving_avg_obs_fq_helper,
|
| 351 |
+
aten.gelu_,
|
| 352 |
+
aten.gelu_backward,
|
| 353 |
+
aten.glu,
|
| 354 |
+
aten.glu_backward,
|
| 355 |
+
aten.hardshrink,
|
| 356 |
+
aten.hardsigmoid,
|
| 357 |
+
aten.hardsigmoid_,
|
| 358 |
+
aten.hardsigmoid_backward,
|
| 359 |
+
aten.hardswish,
|
| 360 |
+
aten.hardswish_,
|
| 361 |
+
aten.hardswish_backward,
|
| 362 |
+
aten.hardtanh_,
|
| 363 |
+
aten.hardtanh_backward,
|
| 364 |
+
aten.heaviside,
|
| 365 |
+
aten.heaviside_,
|
| 366 |
+
aten.huber_loss,
|
| 367 |
+
aten.huber_loss_backward,
|
| 368 |
+
aten.im2col,
|
| 369 |
+
aten.index_add.out,
|
| 370 |
+
aten.index_add.default,
|
| 371 |
+
aten.index_add_,
|
| 372 |
+
aten.index_copy.out,
|
| 373 |
+
aten.index_copy.default,
|
| 374 |
+
aten.index_copy_,
|
| 375 |
+
aten.index_fill.int_Scalar,
|
| 376 |
+
aten.index_fill.int_Tensor,
|
| 377 |
+
aten.index_fill.int_Scalar_out,
|
| 378 |
+
aten.index_fill.int_Tensor_out,
|
| 379 |
+
aten.index_fill_,
|
| 380 |
+
aten.isin,
|
| 381 |
+
aten.isneginf,
|
| 382 |
+
aten.isposinf,
|
| 383 |
+
aten.l1_loss,
|
| 384 |
+
aten._lazy_clone,
|
| 385 |
+
aten._test_parallel_materialize,
|
| 386 |
+
aten.leaky_relu_,
|
| 387 |
+
aten.leaky_relu_backward,
|
| 388 |
+
aten.lerp,
|
| 389 |
+
aten.lerp_,
|
| 390 |
+
aten.linspace,
|
| 391 |
+
aten.logaddexp,
|
| 392 |
+
aten.logaddexp2,
|
| 393 |
+
aten.logit,
|
| 394 |
+
aten.logit_,
|
| 395 |
+
aten.logit_backward,
|
| 396 |
+
aten.log_sigmoid_backward,
|
| 397 |
+
aten.log_sigmoid_forward,
|
| 398 |
+
aten._log_softmax_backward_data,
|
| 399 |
+
aten.logspace,
|
| 400 |
+
aten.logsumexp.default,
|
| 401 |
+
aten.masked_fill,
|
| 402 |
+
aten.masked_fill_,
|
| 403 |
+
aten.max_unpool2d,
|
| 404 |
+
aten.max_unpool3d,
|
| 405 |
+
aten.mish,
|
| 406 |
+
aten.mish_,
|
| 407 |
+
aten.mish_backward,
|
| 408 |
+
aten.mse_loss,
|
| 409 |
+
aten.mse_loss_backward,
|
| 410 |
+
aten.multi_margin_loss,
|
| 411 |
+
aten.multilabel_margin_loss_forward,
|
| 412 |
+
aten.mv,
|
| 413 |
+
aten.mvlgamma,
|
| 414 |
+
aten.mvlgamma_,
|
| 415 |
+
aten.nansum,
|
| 416 |
+
aten.nan_to_num,
|
| 417 |
+
aten.nan_to_num_,
|
| 418 |
+
aten.narrow,
|
| 419 |
+
aten.native_batch_norm_backward,
|
| 420 |
+
aten.native_dropout_backward,
|
| 421 |
+
aten.native_group_norm_backward,
|
| 422 |
+
aten.native_layer_norm_backward,
|
| 423 |
+
aten._fused_rms_norm,
|
| 424 |
+
aten._fused_rms_norm_backward,
|
| 425 |
+
aten.new_empty,
|
| 426 |
+
aten.new_full,
|
| 427 |
+
aten.new_ones,
|
| 428 |
+
aten.new_zeros,
|
| 429 |
+
aten.nll_loss2d_forward,
|
| 430 |
+
aten.nll_loss2d_backward,
|
| 431 |
+
aten.nll_loss_backward,
|
| 432 |
+
aten.nll_loss_forward,
|
| 433 |
+
aten.norm.ScalarOpt_dtype,
|
| 434 |
+
aten.norm.Scalar,
|
| 435 |
+
aten.norm.ScalarOpt_dim_dtype,
|
| 436 |
+
aten.norm.ScalarOpt_dim,
|
| 437 |
+
aten.norm.dtype_out,
|
| 438 |
+
aten.norm.out,
|
| 439 |
+
aten.norm.names_dtype_out,
|
| 440 |
+
aten.norm.names_out,
|
| 441 |
+
aten.norm.ScalarOpt_dtype_out,
|
| 442 |
+
aten.norm.Scalar_out,
|
| 443 |
+
aten.ones,
|
| 444 |
+
aten.ones_like,
|
| 445 |
+
aten.pixel_shuffle,
|
| 446 |
+
aten.pixel_unshuffle,
|
| 447 |
+
aten._prelu_kernel,
|
| 448 |
+
aten._prelu_kernel_backward,
|
| 449 |
+
aten._reshape_alias,
|
| 450 |
+
aten.rad2deg,
|
| 451 |
+
aten.rad2deg_,
|
| 452 |
+
aten.reflection_pad1d,
|
| 453 |
+
aten.reflection_pad1d_backward,
|
| 454 |
+
aten.reflection_pad2d,
|
| 455 |
+
aten.reflection_pad2d_backward,
|
| 456 |
+
aten.reflection_pad3d,
|
| 457 |
+
aten.reflection_pad3d_backward,
|
| 458 |
+
aten.replication_pad1d,
|
| 459 |
+
aten.replication_pad2d,
|
| 460 |
+
aten.replication_pad3d,
|
| 461 |
+
aten.renorm,
|
| 462 |
+
aten.renorm_,
|
| 463 |
+
aten.replication_pad2d,
|
| 464 |
+
aten.resize_as,
|
| 465 |
+
aten.roll,
|
| 466 |
+
aten.rot90,
|
| 467 |
+
aten.rrelu_with_noise,
|
| 468 |
+
aten.rrelu_with_noise_,
|
| 469 |
+
aten.rsub,
|
| 470 |
+
aten._safe_softmax,
|
| 471 |
+
aten._scaled_dot_product_flash_attention_for_cpu.default,
|
| 472 |
+
aten.select_backward,
|
| 473 |
+
aten.select_scatter,
|
| 474 |
+
aten.sgn,
|
| 475 |
+
aten.sgn_,
|
| 476 |
+
aten.sigmoid_backward,
|
| 477 |
+
aten.silu,
|
| 478 |
+
aten.silu_,
|
| 479 |
+
aten.silu_backward.grad_input,
|
| 480 |
+
aten.silu_backward,
|
| 481 |
+
aten.sinc,
|
| 482 |
+
aten.sinc_,
|
| 483 |
+
aten.slice_backward,
|
| 484 |
+
aten.smooth_l1_loss,
|
| 485 |
+
aten.smooth_l1_loss_backward,
|
| 486 |
+
aten.soft_margin_loss,
|
| 487 |
+
aten.soft_margin_loss_backward,
|
| 488 |
+
aten._softmax_backward_data,
|
| 489 |
+
aten.softplus,
|
| 490 |
+
aten.softplus_backward,
|
| 491 |
+
aten.softshrink,
|
| 492 |
+
aten.special_entr,
|
| 493 |
+
aten.special_log_ndtr,
|
| 494 |
+
aten.special_xlog1py,
|
| 495 |
+
aten.split.Tensor,
|
| 496 |
+
aten.split_with_sizes_copy,
|
| 497 |
+
aten.squeeze_copy,
|
| 498 |
+
aten.squeeze.default,
|
| 499 |
+
aten.squeeze.dim,
|
| 500 |
+
aten.std.correction,
|
| 501 |
+
aten.std.out,
|
| 502 |
+
aten.std.correction_out,
|
| 503 |
+
aten.std.names_out,
|
| 504 |
+
aten.std.correction_names_out,
|
| 505 |
+
aten.std_mean.correction,
|
| 506 |
+
aten.std_mean.correction_out,
|
| 507 |
+
aten.stack,
|
| 508 |
+
aten.sum.default,
|
| 509 |
+
aten.sum.out,
|
| 510 |
+
aten.t,
|
| 511 |
+
aten.t_copy,
|
| 512 |
+
aten.take,
|
| 513 |
+
aten.tanh_backward,
|
| 514 |
+
aten.threshold,
|
| 515 |
+
aten.threshold_,
|
| 516 |
+
aten.threshold_backward,
|
| 517 |
+
aten.trace,
|
| 518 |
+
aten.transpose.int,
|
| 519 |
+
aten.transpose_copy,
|
| 520 |
+
aten.tril,
|
| 521 |
+
aten.tril_,
|
| 522 |
+
aten.triu,
|
| 523 |
+
aten.triu_,
|
| 524 |
+
aten.unbind,
|
| 525 |
+
aten.unfold_backward,
|
| 526 |
+
aten.unfold_copy,
|
| 527 |
+
aten._unsafe_index,
|
| 528 |
+
aten._unsafe_index_put,
|
| 529 |
+
aten._unsafe_masked_index,
|
| 530 |
+
aten._unsafe_masked_index_put_accumulate,
|
| 531 |
+
aten.unsafe_split.Tensor,
|
| 532 |
+
aten.unsafe_split_with_sizes,
|
| 533 |
+
aten.unsqueeze_copy,
|
| 534 |
+
aten._unsafe_view,
|
| 535 |
+
aten.upsample_linear1d,
|
| 536 |
+
aten.upsample_bilinear2d.out,
|
| 537 |
+
aten.upsample_trilinear3d.out,
|
| 538 |
+
aten.upsample_nearest2d_backward,
|
| 539 |
+
aten.view_as_complex,
|
| 540 |
+
aten.xlogy,
|
| 541 |
+
aten.xlogy_,
|
| 542 |
+
aten.zero,
|
| 543 |
+
aten.zero_,
|
| 544 |
+
aten.zeros,
|
| 545 |
+
aten.zeros_like,
|
| 546 |
+
aten._chunk_cat,
|
| 547 |
+
aten._weight_norm_interface,
|
| 548 |
+
]
|
| 549 |
+
)
|