Name Date Size #Lines LOC

..--

functions/H25-Apr-2025-1,528989

utils/H25-Apr-2025-380280

FunctionsManual.cppH A D25-Apr-2025246.9 KiB7,1894,957

FunctionsManual.hH A D25-Apr-202531.8 KiB1,1161,079

InferenceMode.hH A D25-Apr-2025156 116

README.mdH A D25-Apr-20251.8 KiB3428

TraceTypeManual.cppH A D25-Apr-202510.6 KiB299256

VariableTypeManual.cppH A D25-Apr-202517.5 KiB563459

VariableTypeUtils.hH A D25-Apr-202514.2 KiB441364

anomaly_mode.cppH A D25-Apr-20252.2 KiB7861

anomaly_mode.hH A D25-Apr-20251.7 KiB7238

autograd.cppH A D25-Apr-20256.4 KiB218193

autograd.hH A D25-Apr-20255.2 KiB10521

autograd_meta.cppH A D25-Apr-202511.5 KiB318171

autograd_not_implemented_fallback.cppH A D25-Apr-202525.1 KiB633481

autograd_not_implemented_fallback.hH A D25-Apr-20251.1 KiB3314

cpp_hook.cppH A D25-Apr-20251.9 KiB6857

cpp_hook.hH A D25-Apr-2025865 3022

custom_function.cppH A D25-Apr-202522.2 KiB586435

custom_function.hH A D25-Apr-202517.6 KiB486315

edge.hH A D25-Apr-20251.6 KiB5734

engine.cppH A D25-Apr-202561.6 KiB1,6741,047

engine.hH A D25-Apr-202510.5 KiB289167

forward_grad.cppH A D25-Apr-20252.5 KiB7960

forward_grad.hH A D25-Apr-20258.7 KiB21175

function.cppH A D25-Apr-20253.3 KiB11366

function.hH A D25-Apr-202529 KiB764385

function_hook.hH A D25-Apr-20252 KiB6549

grad_mode.hH A D25-Apr-2025210 127

graph_task.hH A D25-Apr-20259 KiB227105

init.cppH A D25-Apr-202547.5 KiB1,4161,257

input_buffer.cppH A D25-Apr-20258.9 KiB249165

input_buffer.hH A D25-Apr-20251.4 KiB4626

input_metadata.cppH A D25-Apr-20256.3 KiB205159

input_metadata.hH A D25-Apr-20252.9 KiB11479

jit_decomp_interface.cppH A D25-Apr-2025307 1812

jit_decomp_interface.hH A D25-Apr-20251.8 KiB5121

profiler.hH A D25-Apr-2025112 53

profiler_kineto.cppH A D25-Apr-202536.5 KiB1,084903

profiler_kineto.hH A D25-Apr-20257.8 KiB219128

profiler_legacy.cppH A D25-Apr-202522.9 KiB679510

profiler_legacy.hH A D25-Apr-202510.4 KiB402299

profiler_python.cppH A D25-Apr-202538.7 KiB1,145885

profiler_python.hH A D25-Apr-202584 84

python_anomaly_mode.cppH A D25-Apr-20253.8 KiB128104

python_anomaly_mode.hH A D25-Apr-20251.1 KiB4333

python_autograd.hH A D25-Apr-2025375 1811

python_cpp_function.cppH A D25-Apr-202511.8 KiB400336

python_cpp_function.hH A D25-Apr-20254.7 KiB10992

python_engine.cppH A D25-Apr-202517.6 KiB520439

python_engine.hH A D25-Apr-20251.2 KiB4535

python_enum_tag.hH A D25-Apr-2025120 85

python_fft_functions.hH A D25-Apr-202587 84

python_function.cppH A D25-Apr-202561.2 KiB1,8421,522

python_function.hH A D25-Apr-20255.4 KiB16184

python_hook.cppH A D25-Apr-202510.7 KiB353270

python_hook.hH A D25-Apr-20252 KiB5643

python_legacy_variable.cppH A D25-Apr-20254.9 KiB166137

python_legacy_variable.hH A D25-Apr-2025257 135

python_linalg_functions.hH A D25-Apr-202590 84

python_nested_functions.hH A D25-Apr-2025164 105

python_nested_functions_manual.cppH A D25-Apr-20251.3 KiB4334

python_nn_functions.hH A D25-Apr-202586 84

python_saved_variable_hooks.cppH A D25-Apr-20253 KiB9171

python_saved_variable_hooks.hH A D25-Apr-2025933 3426

python_sparse_functions.hH A D25-Apr-202590 84

python_special_functions.hH A D25-Apr-202591 84

python_torch_functions.hH A D25-Apr-2025650 2618

python_torch_functions_manual.cppH A D25-Apr-202530.3 KiB803704

python_variable.cppH A D25-Apr-202584.8 KiB2,3821,786

python_variable.hH A D25-Apr-20253.4 KiB11583

python_variable_indexing.cppH A D25-Apr-202518.5 KiB549453

python_variable_indexing.hH A D25-Apr-20252.7 KiB10083

record_function_ops.cppH A D25-Apr-20256.2 KiB167122

record_function_ops.hH A D25-Apr-2025935 2818

saved_variable.cppH A D25-Apr-202510.5 KiB288195

saved_variable.hH A D25-Apr-20254.5 KiB12157

saved_variable_hooks.hH A D25-Apr-2025296 149

symbolic.hH A D25-Apr-2025300 1711

variable.cppH A D25-Apr-202533.4 KiB910696

variable.hH A D25-Apr-202539.2 KiB949416

variable_info.cppH A D25-Apr-2025844 3325

variable_info.hH A D25-Apr-2025481 2215

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