|
Name |
|
Date |
Size |
#Lines |
LOC |
| .. | | - | - |
| functions/ | H | 25-Apr-2025 | - | 1,528 | 989 |
| utils/ | H | 25-Apr-2025 | - | 380 | 280 |
| FunctionsManual.cpp | H A D | 25-Apr-2025 | 246.9 KiB | 7,189 | 4,957 |
| FunctionsManual.h | H A D | 25-Apr-2025 | 31.8 KiB | 1,116 | 1,079 |
| InferenceMode.h | H A D | 25-Apr-2025 | 156 | 11 | 6 |
| README.md | H A D | 25-Apr-2025 | 1.8 KiB | 34 | 28 |
| TraceTypeManual.cpp | H A D | 25-Apr-2025 | 10.6 KiB | 299 | 256 |
| VariableTypeManual.cpp | H A D | 25-Apr-2025 | 17.5 KiB | 563 | 459 |
| VariableTypeUtils.h | H A D | 25-Apr-2025 | 14.2 KiB | 441 | 364 |
| anomaly_mode.cpp | H A D | 25-Apr-2025 | 2.2 KiB | 78 | 61 |
| anomaly_mode.h | H A D | 25-Apr-2025 | 1.7 KiB | 72 | 38 |
| autograd.cpp | H A D | 25-Apr-2025 | 6.4 KiB | 218 | 193 |
| autograd.h | H A D | 25-Apr-2025 | 5.2 KiB | 105 | 21 |
| autograd_meta.cpp | H A D | 25-Apr-2025 | 11.5 KiB | 318 | 171 |
| autograd_not_implemented_fallback.cpp | H A D | 25-Apr-2025 | 25.1 KiB | 633 | 481 |
| autograd_not_implemented_fallback.h | H A D | 25-Apr-2025 | 1.1 KiB | 33 | 14 |
| cpp_hook.cpp | H A D | 25-Apr-2025 | 1.9 KiB | 68 | 57 |
| cpp_hook.h | H A D | 25-Apr-2025 | 865 | 30 | 22 |
| custom_function.cpp | H A D | 25-Apr-2025 | 22.2 KiB | 586 | 435 |
| custom_function.h | H A D | 25-Apr-2025 | 17.6 KiB | 486 | 315 |
| edge.h | H A D | 25-Apr-2025 | 1.6 KiB | 57 | 34 |
| engine.cpp | H A D | 25-Apr-2025 | 61.6 KiB | 1,674 | 1,047 |
| engine.h | H A D | 25-Apr-2025 | 10.5 KiB | 289 | 167 |
| forward_grad.cpp | H A D | 25-Apr-2025 | 2.5 KiB | 79 | 60 |
| forward_grad.h | H A D | 25-Apr-2025 | 8.7 KiB | 211 | 75 |
| function.cpp | H A D | 25-Apr-2025 | 3.3 KiB | 113 | 66 |
| function.h | H A D | 25-Apr-2025 | 29 KiB | 764 | 385 |
| function_hook.h | H A D | 25-Apr-2025 | 2 KiB | 65 | 49 |
| grad_mode.h | H A D | 25-Apr-2025 | 210 | 12 | 7 |
| graph_task.h | H A D | 25-Apr-2025 | 9 KiB | 227 | 105 |
| init.cpp | H A D | 25-Apr-2025 | 47.5 KiB | 1,416 | 1,257 |
| input_buffer.cpp | H A D | 25-Apr-2025 | 8.9 KiB | 249 | 165 |
| input_buffer.h | H A D | 25-Apr-2025 | 1.4 KiB | 46 | 26 |
| input_metadata.cpp | H A D | 25-Apr-2025 | 6.3 KiB | 205 | 159 |
| input_metadata.h | H A D | 25-Apr-2025 | 2.9 KiB | 114 | 79 |
| jit_decomp_interface.cpp | H A D | 25-Apr-2025 | 307 | 18 | 12 |
| jit_decomp_interface.h | H A D | 25-Apr-2025 | 1.8 KiB | 51 | 21 |
| profiler.h | H A D | 25-Apr-2025 | 112 | 5 | 3 |
| profiler_kineto.cpp | H A D | 25-Apr-2025 | 36.5 KiB | 1,084 | 903 |
| profiler_kineto.h | H A D | 25-Apr-2025 | 7.8 KiB | 219 | 128 |
| profiler_legacy.cpp | H A D | 25-Apr-2025 | 22.9 KiB | 679 | 510 |
| profiler_legacy.h | H A D | 25-Apr-2025 | 10.4 KiB | 402 | 299 |
| profiler_python.cpp | H A D | 25-Apr-2025 | 38.7 KiB | 1,145 | 885 |
| profiler_python.h | H A D | 25-Apr-2025 | 84 | 8 | 4 |
| python_anomaly_mode.cpp | H A D | 25-Apr-2025 | 3.8 KiB | 128 | 104 |
| python_anomaly_mode.h | H A D | 25-Apr-2025 | 1.1 KiB | 43 | 33 |
| python_autograd.h | H A D | 25-Apr-2025 | 375 | 18 | 11 |
| python_cpp_function.cpp | H A D | 25-Apr-2025 | 11.8 KiB | 400 | 336 |
| python_cpp_function.h | H A D | 25-Apr-2025 | 4.7 KiB | 109 | 92 |
| python_engine.cpp | H A D | 25-Apr-2025 | 17.6 KiB | 520 | 439 |
| python_engine.h | H A D | 25-Apr-2025 | 1.2 KiB | 45 | 35 |
| python_enum_tag.h | H A D | 25-Apr-2025 | 120 | 8 | 5 |
| python_fft_functions.h | H A D | 25-Apr-2025 | 87 | 8 | 4 |
| python_function.cpp | H A D | 25-Apr-2025 | 61.2 KiB | 1,842 | 1,522 |
| python_function.h | H A D | 25-Apr-2025 | 5.4 KiB | 161 | 84 |
| python_hook.cpp | H A D | 25-Apr-2025 | 10.7 KiB | 353 | 270 |
| python_hook.h | H A D | 25-Apr-2025 | 2 KiB | 56 | 43 |
| python_legacy_variable.cpp | H A D | 25-Apr-2025 | 4.9 KiB | 166 | 137 |
| python_legacy_variable.h | H A D | 25-Apr-2025 | 257 | 13 | 5 |
| python_linalg_functions.h | H A D | 25-Apr-2025 | 90 | 8 | 4 |
| python_nested_functions.h | H A D | 25-Apr-2025 | 164 | 10 | 5 |
| python_nested_functions_manual.cpp | H A D | 25-Apr-2025 | 1.3 KiB | 43 | 34 |
| python_nn_functions.h | H A D | 25-Apr-2025 | 86 | 8 | 4 |
| python_saved_variable_hooks.cpp | H A D | 25-Apr-2025 | 3 KiB | 91 | 71 |
| python_saved_variable_hooks.h | H A D | 25-Apr-2025 | 933 | 34 | 26 |
| python_sparse_functions.h | H A D | 25-Apr-2025 | 90 | 8 | 4 |
| python_special_functions.h | H A D | 25-Apr-2025 | 91 | 8 | 4 |
| python_torch_functions.h | H A D | 25-Apr-2025 | 650 | 26 | 18 |
| python_torch_functions_manual.cpp | H A D | 25-Apr-2025 | 30.3 KiB | 803 | 704 |
| python_variable.cpp | H A D | 25-Apr-2025 | 84.8 KiB | 2,382 | 1,786 |
| python_variable.h | H A D | 25-Apr-2025 | 3.4 KiB | 115 | 83 |
| python_variable_indexing.cpp | H A D | 25-Apr-2025 | 18.5 KiB | 549 | 453 |
| python_variable_indexing.h | H A D | 25-Apr-2025 | 2.7 KiB | 100 | 83 |
| record_function_ops.cpp | H A D | 25-Apr-2025 | 6.2 KiB | 167 | 122 |
| record_function_ops.h | H A D | 25-Apr-2025 | 935 | 28 | 18 |
| saved_variable.cpp | H A D | 25-Apr-2025 | 10.5 KiB | 288 | 195 |
| saved_variable.h | H A D | 25-Apr-2025 | 4.5 KiB | 121 | 57 |
| saved_variable_hooks.h | H A D | 25-Apr-2025 | 296 | 14 | 9 |
| symbolic.h | H A D | 25-Apr-2025 | 300 | 17 | 11 |
| variable.cpp | H A D | 25-Apr-2025 | 33.4 KiB | 910 | 696 |
| variable.h | H A D | 25-Apr-2025 | 39.2 KiB | 949 | 416 |
| variable_info.cpp | H A D | 25-Apr-2025 | 844 | 33 | 25 |
| variable_info.h | H A D | 25-Apr-2025 | 481 | 22 | 15 |
README.md
1## Autograd
2
3Autograd is a hotspot for PyTorch performance, so most of the heavy lifting is
4implemented in C++. This implies that we have to do some shuffling between
5Python and C++; and in general, we want data to be in a form that is convenient
6to manipulate from C++.
7
8Our general model is that for any key data type that autograd manipulates,
9there are two implementations: a C++ type and a Python object type. For
10example, consider variables in autograd: we have both `Variable` in `variable.h`
11(the C++ type) and `THPVariable` in `python_variable.h` (the Python type.)
12(By the way, THP stands for TorcH Python, not to be confused with THPP, TorcH
13C++). `Variable` contains the payload of a variable, while `THPVariable` just
14contains a `shared_ptr` reference to `Variable`, as well as references to other
15Python objects which the Python runtime needs to know about. A lot of
16data accessor implementations in `python_variable.cpp` simply reach through
17to the underlying `Variable` and return the appropriate value.
18
19The most complicated application of this principle is Function, which also
20supports users implementing custom behavior in Python. We have the following
21classes:
22
23* `Node` in `function.h`, the C++ type.
24* `THPFunction` in `python_function.h`, the Python object type. In
25 `python_function.cpp`, you can see the boilerplate that tells the Python
26 interpreter about this object.
27* `PyNode` in `python_function.h`, a subclass of `Node` which forwards
28 `apply` to a Python `THPFunction`. (NOT a Python object, despite its name!)
29
30Outside of `PyNode`, the C++ objects largely avoid referencing Python
31objects (there are a few exceptions, like `pyobj` in `Variable`, and
32`PyNode`, whose whole point is to let C++ call into Python). And `pyobj`
33in `Node` to ensure uniqueness of the associated python wrapper (if it exists).
34