pytorch/torch/csrc/autograd
Jeff Moe b8fc24e092 Upstream v2.1.0 2023-11-08 09:13:36 -07:00
..
functions Upstream v2.1.0 2023-11-08 09:13:36 -07:00
utils Upstream v2.1.0 2023-11-08 09:13:36 -07:00
FunctionsManual.cpp Upstream v2.1.0 2023-11-08 09:13:36 -07:00
FunctionsManual.h Upstream v2.1.0 2023-11-08 09:13:36 -07:00
InferenceMode.h Forklet of Pytorch 2023-11-08 09:01:59 -07:00
README.md Forklet of Pytorch 2023-11-08 09:01:59 -07:00
TraceTypeManual.cpp Upstream v2.1.0 2023-11-08 09:13:36 -07:00
VariableTypeManual.cpp Upstream v2.1.0 2023-11-08 09:13:36 -07:00
VariableTypeUtils.h Upstream v2.1.0 2023-11-08 09:13:36 -07:00
anomaly_mode.cpp Forklet of Pytorch 2023-11-08 09:01:59 -07:00
anomaly_mode.h Forklet of Pytorch 2023-11-08 09:01:59 -07:00
autograd.cpp Upstream v2.1.0 2023-11-08 09:13:36 -07:00
autograd.h Forklet of Pytorch 2023-11-08 09:01:59 -07:00
autograd_meta.cpp Upstream v2.1.0 2023-11-08 09:13:36 -07:00
autograd_not_implemented_fallback.cpp Upstream v2.1.0 2023-11-08 09:13:36 -07:00
autograd_not_implemented_fallback.h Upstream v2.1.0 2023-11-08 09:13:36 -07:00
cpp_hook.cpp Upstream v2.1.0 2023-11-08 09:13:36 -07:00
cpp_hook.h Upstream v2.1.0 2023-11-08 09:13:36 -07:00
custom_function.cpp Upstream v2.1.0 2023-11-08 09:13:36 -07:00
custom_function.h Upstream v2.1.0 2023-11-08 09:13:36 -07:00
edge.h Forklet of Pytorch 2023-11-08 09:01:59 -07:00
engine.cpp Upstream v2.1.0 2023-11-08 09:13:36 -07:00
engine.h Upstream v2.1.0 2023-11-08 09:13:36 -07:00
forward_grad.cpp Forklet of Pytorch 2023-11-08 09:01:59 -07:00
forward_grad.h Upstream v2.1.0 2023-11-08 09:13:36 -07:00
function.cpp Forklet of Pytorch 2023-11-08 09:01:59 -07:00
function.h Upstream v2.1.0 2023-11-08 09:13:36 -07:00
function_hook.h Upstream v2.1.0 2023-11-08 09:13:36 -07:00
grad_mode.h Forklet of Pytorch 2023-11-08 09:01:59 -07:00
graph_task.h Upstream v2.1.0 2023-11-08 09:13:36 -07:00
init.cpp Upstream v2.1.0 2023-11-08 09:13:36 -07:00
input_buffer.cpp Upstream v2.1.0 2023-11-08 09:13:36 -07:00
input_buffer.h Upstream v2.1.0 2023-11-08 09:13:36 -07:00
input_metadata.h Upstream v2.1.0 2023-11-08 09:13:36 -07:00
jit_decomp_interface.cpp Forklet of Pytorch 2023-11-08 09:01:59 -07:00
jit_decomp_interface.h Forklet of Pytorch 2023-11-08 09:01:59 -07:00
profiler.h Forklet of Pytorch 2023-11-08 09:01:59 -07:00
profiler_kineto.cpp Upstream v2.1.0 2023-11-08 09:13:36 -07:00
profiler_kineto.h Upstream v2.1.0 2023-11-08 09:13:36 -07:00
profiler_legacy.cpp Upstream v2.1.0 2023-11-08 09:13:36 -07:00
profiler_legacy.h Upstream v2.1.0 2023-11-08 09:13:36 -07:00
profiler_python.cpp Upstream v2.1.0 2023-11-08 09:13:36 -07:00
profiler_python.h Forklet of Pytorch 2023-11-08 09:01:59 -07:00
python_anomaly_mode.cpp Forklet of Pytorch 2023-11-08 09:01:59 -07:00
python_anomaly_mode.h Forklet of Pytorch 2023-11-08 09:01:59 -07:00
python_autograd.h Forklet of Pytorch 2023-11-08 09:01:59 -07:00
python_cpp_function.cpp Upstream v2.1.0 2023-11-08 09:13:36 -07:00
python_cpp_function.h Upstream v2.1.0 2023-11-08 09:13:36 -07:00
python_engine.cpp Upstream v2.1.0 2023-11-08 09:13:36 -07:00
python_engine.h Forklet of Pytorch 2023-11-08 09:01:59 -07:00
python_enum_tag.h Forklet of Pytorch 2023-11-08 09:01:59 -07:00
python_fft_functions.h Forklet of Pytorch 2023-11-08 09:01:59 -07:00
python_function.cpp Upstream v2.1.0 2023-11-08 09:13:36 -07:00
python_function.h Upstream v2.1.0 2023-11-08 09:13:36 -07:00
python_hook.cpp Upstream v2.1.0 2023-11-08 09:13:36 -07:00
python_hook.h Upstream v2.1.0 2023-11-08 09:13:36 -07:00
python_legacy_variable.cpp Upstream v2.1.0 2023-11-08 09:13:36 -07:00
python_legacy_variable.h Forklet of Pytorch 2023-11-08 09:01:59 -07:00
python_linalg_functions.h Forklet of Pytorch 2023-11-08 09:01:59 -07:00
python_nested_functions.h Forklet of Pytorch 2023-11-08 09:01:59 -07:00
python_nested_functions_manual.cpp Forklet of Pytorch 2023-11-08 09:01:59 -07:00
python_nn_functions.h Forklet of Pytorch 2023-11-08 09:01:59 -07:00
python_return_types.h Forklet of Pytorch 2023-11-08 09:01:59 -07:00
python_saved_variable_hooks.cpp Forklet of Pytorch 2023-11-08 09:01:59 -07:00
python_saved_variable_hooks.h Forklet of Pytorch 2023-11-08 09:01:59 -07:00
python_sparse_functions.h Forklet of Pytorch 2023-11-08 09:01:59 -07:00
python_special_functions.h Forklet of Pytorch 2023-11-08 09:01:59 -07:00
python_torch_functions.h Forklet of Pytorch 2023-11-08 09:01:59 -07:00
python_torch_functions_manual.cpp Upstream v2.1.0 2023-11-08 09:13:36 -07:00
python_variable.cpp Upstream v2.1.0 2023-11-08 09:13:36 -07:00
python_variable.h Upstream v2.1.0 2023-11-08 09:13:36 -07:00
python_variable_indexing.cpp Upstream v2.1.0 2023-11-08 09:13:36 -07:00
python_variable_indexing.h Forklet of Pytorch 2023-11-08 09:01:59 -07:00
record_function_ops.cpp Upstream v2.1.0 2023-11-08 09:13:36 -07:00
record_function_ops.h Forklet of Pytorch 2023-11-08 09:01:59 -07:00
saved_variable.cpp Upstream v2.1.0 2023-11-08 09:13:36 -07:00
saved_variable.h Upstream v2.1.0 2023-11-08 09:13:36 -07:00
saved_variable_hooks.h Forklet of Pytorch 2023-11-08 09:01:59 -07:00
symbolic.h Forklet of Pytorch 2023-11-08 09:01:59 -07:00
variable.cpp Upstream v2.1.0 2023-11-08 09:13:36 -07:00
variable.h Upstream v2.1.0 2023-11-08 09:13:36 -07:00

README.md

Autograd

Autograd is a hotspot for PyTorch performance, so most of the heavy lifting is implemented in C++. This implies that we have to do some shuffling between Python and C++; and in general, we want data to be in a form that is convenient to manipulate from C++.

Our general model is that for any key data type that autograd manipulates, there are two implementations: a C++ type and a Python object type. For example, consider variables in autograd: we have both Variable in variable.h (the C++ type) and THPVariable in python_variable.h (the Python type.) (By the way, THP stands for TorcH Python, not to be confused with THPP, TorcH C++). Variable contains the payload of a variable, while THPVariable just contains a shared_ptr reference to Variable, as well as references to other Python objects which the Python runtime needs to know about. A lot of data accessor implementations in python_variable.cpp simply reach through to the underlying Variable and return the appropriate value.

The most complicated application of this principle is Function, which also supports users implementing custom behavior in Python. We have the following classes:

  • Node in function.h, the C++ type.
  • THPFunction in python_function.h, the Python object type. In python_function.cpp, you can see the boilerplate that tells the Python interpreter about this object.
  • PyNode in python_function.h, a subclass of Node which forwards apply to a Python THPFunction. (NOT a Python object, despite its name!)

Outside of PyNode, the C++ objects largely avoid referencing Python objects (there are a few exceptions, like pyobj in Variable, and PyNode, whose whole point is to let C++ call into Python). And pyobj in Node to ensure uniqueness of the associated python wrapper (if it exists).