pytorch/torch/csrc/autograd
2024-04-23 00:33:25 +00:00
..
functions Remove unnecessary const_casts (#121225) 2024-03-05 17:34:24 +00:00
utils [DeviceIndex][3/N] Use DeviceIndex in more places (#119635) 2024-02-12 21:31:27 +00:00
anomaly_mode.cpp
anomaly_mode.h [12/N] Apply clang-tidy and fix warnings in headers of torch/csrc (#116486) 2024-01-10 08:48:14 +00:00
autograd_meta.cpp Update jvp to support symbolic execution. (#120338) 2024-03-25 20:50:12 +00:00
autograd_not_implemented_fallback.cpp Skip use_count() debug assert for _nested_get_offsets() (#122917) 2024-03-28 23:19:17 +00:00
autograd_not_implemented_fallback.h [12/N] Apply clang-tidy and fix warnings in headers of torch/csrc (#116486) 2024-01-10 08:48:14 +00:00
autograd.cpp Fix error message of autograd (#123154) 2024-04-03 19:07:21 +00:00
autograd.h [12/N] Apply clang-tidy and fix warnings in headers of torch/csrc (#116486) 2024-01-10 08:48:14 +00:00
cpp_hook.cpp
cpp_hook.h [12/N] Apply clang-tidy and fix warnings in headers of torch/csrc (#116486) 2024-01-10 08:48:14 +00:00
custom_function.cpp Move VariableInfo into its own file to avoid circular dependency (#120732) 2024-03-01 08:48:13 +00:00
custom_function.h [compiled autograd] support custom ops backed by c++ autograd::Function (#120681) 2024-03-13 21:13:21 +00:00
edge.h [12/N] Apply clang-tidy and fix warnings in headers of torch/csrc (#116486) 2024-01-10 08:48:14 +00:00
engine.cpp [codemod][lowrisk] Remove unused exception parameter from caffe2/caffe2/image/image_input_op.h (#123056) 2024-04-04 17:24:43 +00:00
engine.h [Clang-tidy header][16/N] Enable clang-tidy on headers in torch/csrc/autograd (#117821) 2024-01-22 00:52:56 +00:00
forward_grad.cpp
forward_grad.h [12/N] Apply clang-tidy and fix warnings in headers of torch/csrc (#116486) 2024-01-10 08:48:14 +00:00
function_hook.h [12/N] Apply clang-tidy and fix warnings in headers of torch/csrc (#116486) 2024-01-10 08:48:14 +00:00
function.cpp Remove unused header inclusion (#119667) 2024-02-12 05:36:25 +00:00
function.h Add Accelerator device and shell hooks (#119329) 2024-02-13 23:15:24 +00:00
FunctionsManual.cpp compile: ban mutations on non-compositional uses of as_strided (#122502) 2024-04-12 01:12:23 +00:00
FunctionsManual.h [12/N] Apply clang-tidy and fix warnings in headers of torch/csrc (#116486) 2024-01-10 08:48:14 +00:00
grad_mode.h [12/N] Apply clang-tidy and fix warnings in headers of torch/csrc (#116486) 2024-01-10 08:48:14 +00:00
graph_task.h Add Accelerator device and shell hooks (#119329) 2024-02-13 23:15:24 +00:00
InferenceMode.h [12/N] Apply clang-tidy and fix warnings in headers of torch/csrc (#116486) 2024-01-10 08:48:14 +00:00
init.cpp rename ort to maia (#123265) 2024-04-23 00:33:25 +00:00
input_buffer.cpp enable privateuseone to perform streaming backward (#117111) 2024-01-30 15:13:31 +00:00
input_buffer.h [Clang-tidy header][16/N] Enable clang-tidy on headers in torch/csrc/autograd (#117821) 2024-01-22 00:52:56 +00:00
input_metadata.cpp Rewrite maybe_reduce more carefully for unbacked SymInt (#119562) 2024-02-13 21:40:06 +00:00
input_metadata.h Refactor out shape test into InputMetadata::maybe_reduce (#119559) 2024-02-12 19:27:48 +00:00
jit_decomp_interface.cpp
jit_decomp_interface.h [12/N] Apply clang-tidy and fix warnings in headers of torch/csrc (#116486) 2024-01-10 08:48:14 +00:00
profiler_kineto.cpp Revert "[Profiler][PrivateUse1] Profiler support PrivateUse1 key (#120556)" 2024-04-17 15:38:14 +00:00
profiler_kineto.h [Profiler] Make Kineto traces export ns granularity for finer timestamps (#122425) (#123650) 2024-04-11 04:29:20 +00:00
profiler_legacy.cpp [Clang-tidy header][19/N] Enable clang-tidy on torch/csrc/autograd/profiler_legacy.* (#120552) 2024-02-25 03:29:40 +00:00
profiler_legacy.h [Clang-tidy header][19/N] Enable clang-tidy on torch/csrc/autograd/profiler_legacy.* (#120552) 2024-02-25 03:29:40 +00:00
profiler_python.cpp [PyTorch] Redirect c10::optional to std::optional (#101995) 2023-11-30 02:46:41 +00:00
profiler_python.h [12/N] Apply clang-tidy and fix warnings in headers of torch/csrc (#116486) 2024-01-10 08:48:14 +00:00
profiler.h
python_anomaly_mode.cpp Remove unused header inclusion (#119667) 2024-02-12 05:36:25 +00:00
python_anomaly_mode.h [Clang-tidy header][16/N] Enable clang-tidy on headers in torch/csrc/autograd (#117821) 2024-01-22 00:52:56 +00:00
python_autograd.h [12/N] Apply clang-tidy and fix warnings in headers of torch/csrc (#116486) 2024-01-10 08:48:14 +00:00
python_cpp_function.cpp Enable set sequence nr (#114120) 2023-11-21 19:47:28 +00:00
python_cpp_function.h [12/N] Apply clang-tidy and fix warnings in headers of torch/csrc (#116486) 2024-01-10 08:48:14 +00:00
python_engine.cpp Remove unused header inclusion (#119667) 2024-02-12 05:36:25 +00:00
python_engine.h [12/N] Apply clang-tidy and fix warnings in headers of torch/csrc (#116486) 2024-01-10 08:48:14 +00:00
python_enum_tag.h [12/N] Apply clang-tidy and fix warnings in headers of torch/csrc (#116486) 2024-01-10 08:48:14 +00:00
python_fft_functions.h [12/N] Apply clang-tidy and fix warnings in headers of torch/csrc (#116486) 2024-01-10 08:48:14 +00:00
python_function.cpp [compiled autograd] support custom ops backed by c++ autograd::Function (#120681) 2024-03-13 21:13:21 +00:00
python_function.h [Compiled Autograd] Introduce BackwardState capture (#120382) 2024-02-28 20:36:47 +00:00
python_hook.cpp
python_hook.h [12/N] Apply clang-tidy and fix warnings in headers of torch/csrc (#116486) 2024-01-10 08:48:14 +00:00
python_legacy_variable.cpp Revert "[Exception] [6/N] Remove use of torch::TypeError (#117964)" 2024-01-27 08:44:34 +00:00
python_legacy_variable.h [12/N] Apply clang-tidy and fix warnings in headers of torch/csrc (#116486) 2024-01-10 08:48:14 +00:00
python_linalg_functions.h [12/N] Apply clang-tidy and fix warnings in headers of torch/csrc (#116486) 2024-01-10 08:48:14 +00:00
python_nested_functions_manual.cpp
python_nested_functions.h [12/N] Apply clang-tidy and fix warnings in headers of torch/csrc (#116486) 2024-01-10 08:48:14 +00:00
python_nn_functions.h [12/N] Apply clang-tidy and fix warnings in headers of torch/csrc (#116486) 2024-01-10 08:48:14 +00:00
python_saved_variable_hooks.cpp
python_saved_variable_hooks.h [12/N] Apply clang-tidy and fix warnings in headers of torch/csrc (#116486) 2024-01-10 08:48:14 +00:00
python_sparse_functions.h [12/N] Apply clang-tidy and fix warnings in headers of torch/csrc (#116486) 2024-01-10 08:48:14 +00:00
python_special_functions.h [12/N] Apply clang-tidy and fix warnings in headers of torch/csrc (#116486) 2024-01-10 08:48:14 +00:00
python_torch_functions_manual.cpp [AOTAutograd] Replay views on output using FunctionalTensor metas. (#121007) 2024-04-12 16:54:13 +00:00
python_torch_functions.h [Clang-tidy header][16/N] Enable clang-tidy on headers in torch/csrc/autograd (#117821) 2024-01-22 00:52:56 +00:00
python_variable_indexing.cpp Remove unused header inclusion (#119667) 2024-02-12 05:36:25 +00:00
python_variable_indexing.h [12/N] Apply clang-tidy and fix warnings in headers of torch/csrc (#116486) 2024-01-10 08:48:14 +00:00
python_variable.cpp rename ort to maia (#123265) 2024-04-23 00:33:25 +00:00
python_variable.h Refactor gpu trace to be device-agnostic (#121794) 2024-03-30 13:04:38 +00:00
README.md
record_function_ops.cpp
record_function_ops.h [12/N] Apply clang-tidy and fix warnings in headers of torch/csrc (#116486) 2024-01-10 08:48:14 +00:00
saved_variable_hooks.h [12/N] Apply clang-tidy and fix warnings in headers of torch/csrc (#116486) 2024-01-10 08:48:14 +00:00
saved_variable.cpp Remove unused header inclusion (#119667) 2024-02-12 05:36:25 +00:00
saved_variable.h [12/N] Apply clang-tidy and fix warnings in headers of torch/csrc (#116486) 2024-01-10 08:48:14 +00:00
symbolic.h [Clang-tidy header][16/N] Enable clang-tidy on headers in torch/csrc/autograd (#117821) 2024-01-22 00:52:56 +00:00
TraceTypeManual.cpp
variable_info.cpp Move VariableInfo into its own file to avoid circular dependency (#120732) 2024-03-01 08:48:13 +00:00
variable_info.h Move VariableInfo into its own file to avoid circular dependency (#120732) 2024-03-01 08:48:13 +00:00
variable.cpp Reify view_func() closures as ViewFuncs (#118404) 2024-02-14 22:00:43 +00:00
variable.h fix typo in 4 files (#123529) 2024-04-09 23:37:35 +00:00
VariableTypeManual.cpp Reify view_func() closures as ViewFuncs (#118404) 2024-02-14 22:00:43 +00:00
VariableTypeUtils.h Simplify forward AD missing support error (#122639) 2024-03-29 02:11:46 +00:00

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).