pytorch/torch/csrc/autograd
2024-12-01 03:53:35 +00:00
..
functions C10_UNUSED to [[maybe_unused]] (#6357) (#138364) 2024-10-19 13:17:43 +00:00
utils [Reland] Fix tensor.data_ptr() representation overflow (#135567) 2024-11-28 02:01:52 +00:00
anomaly_mode.cpp [2/N] Fix clang-tidy warnings in torch/csrc/autograd (#133295) 2024-08-13 13:23:46 +00:00
anomaly_mode.h
autograd_meta.cpp [2/N] Fix clang-tidy warnings in torch/csrc/autograd (#133295) 2024-08-13 13:23:46 +00:00
autograd_not_implemented_fallback.cpp [sparse] add extra options to _cslt_spare_mm (#137427) 2024-11-27 05:32:45 +00:00
autograd_not_implemented_fallback.h
autograd.cpp [2/N] Fix clang-tidy warnings in torch/csrc/autograd (#133295) 2024-08-13 13:23:46 +00:00
autograd.h
cpp_hook.cpp [2/N] Fix clang-tidy warnings in torch/csrc/autograd (#133295) 2024-08-13 13:23:46 +00:00
cpp_hook.h
custom_function.cpp [2/N] Fix clang-tidy warnings in torch/csrc/autograd (#133295) 2024-08-13 13:23:46 +00:00
custom_function.h [compiled autograd][cpp node] point c++ custom autograd functions tracing error to google doc (#134514) 2024-08-28 17:54:31 +00:00
edge.h
engine.cpp [ca] expose option to collect sizes as dynamic (#141153) 2024-11-22 19:26:27 +00:00
engine.h [3/N] Fix clang-tidy warnings in torch/csrc/autograd (#133389) 2024-08-16 00:57:54 +00:00
forward_grad.cpp [Distributed] [13/N] Fix clang-tidy warnings in torch/csrc/distributed/ (#136713) 2024-09-27 10:11:53 +00:00
forward_grad.h
function_hook.h
function.cpp [2/N] Fix clang-tidy warnings in torch/csrc/autograd (#133295) 2024-08-13 13:23:46 +00:00
function.h Determine autograd engine ready queue based on InputMetadata instead of InputBuffer (#135633) 2024-10-04 23:59:46 +00:00
FunctionsManual.cpp [1/N] Avoid copy in std::get (#141812) 2024-12-01 03:53:35 +00:00
FunctionsManual.h [1/N] Avoid copy in std::get (#141812) 2024-12-01 03:53:35 +00:00
grad_mode.h
graph_task.h [2/N] Enable cppcoreguidelines-special-member-functions (#138670) 2024-10-24 04:35:18 +00:00
InferenceMode.h
init.cpp [9/N] Fix extra warnings brought by clang-tidy-17 (#139286) 2024-10-31 05:20:31 +00:00
input_buffer.cpp Determine autograd engine ready queue based on InputMetadata instead of InputBuffer (#135633) 2024-10-04 23:59:46 +00:00
input_buffer.h Fix Wextra-semi warnings (#139000) 2024-10-28 21:48:51 +00:00
input_metadata.cpp [2/N] Fix clang-tidy warnings in torch/csrc/autograd (#133295) 2024-08-13 13:23:46 +00:00
input_metadata.h
jit_decomp_interface.cpp [2/N] Fix clang-tidy warnings in torch/csrc/autograd (#133295) 2024-08-13 13:23:46 +00:00
jit_decomp_interface.h
profiler_kineto.cpp [pytorch/profiler] Profiler NCCL metadata can now contain collective Input and Ouput Tensor addrs (#140637) 2024-11-19 22:22:16 +00:00
profiler_kineto.h [Profiler] Add API for Dynamic Activity Toggling [2/n] (#133035) 2024-08-09 21:54:54 +00:00
profiler_legacy.cpp [2/N] Fix clang-tidy warnings in torch/csrc/autograd (#133295) 2024-08-13 13:23:46 +00:00
profiler_legacy.h [2/N] Fix clang-tidy warnings in torch/csrc/autograd (#133295) 2024-08-13 13:23:46 +00:00
profiler_python.cpp Use Wextra-semi (#140236) 2024-11-13 02:15:16 +00:00
profiler_python.h
profiler.h
python_anomaly_mode.cpp More nogil unsafe API fix (#137142) 2024-10-04 21:56:34 +00:00
python_anomaly_mode.h [8/N] Fix extra warnings brought by clang-tidy-17 (#139151) 2024-10-30 14:20:08 +00:00
python_autograd.h [11/N] Fix extra warnings brought by clang-tidy-17 (#139599) 2024-11-04 23:57:41 +00:00
python_cpp_function.cpp [BE][clang-format] make macro PyObject_HEAD_INIT(type) and PyVarObject_HEAD_INIT(type, size) have its own line (#136949) 2024-10-02 18:39:22 +00:00
python_cpp_function.h [BE][clang-format] make macro PyObject_HEAD have its own line (#136945) 2024-10-02 18:39:21 +00:00
python_engine.cpp [2/N] Turn inline static functions into static (#140068) 2024-11-09 03:31:24 +00:00
python_engine.h [3/N] Fix clang-tidy warnings in torch/csrc/autograd (#133389) 2024-08-16 00:57:54 +00:00
python_enum_tag.h
python_fft_functions.h [11/N] Fix extra warnings brought by clang-tidy-17 (#139599) 2024-11-04 23:57:41 +00:00
python_function.cpp Fix autograd.Function + NJT when an output grad is None (#136875) 2024-10-14 19:31:50 +00:00
python_function.h [2/N] Fix extra warnings brought by clang-tidy-17 (#137459) 2024-10-08 19:05:02 +00:00
python_hook.cpp More nogil unsafe API fix (#137142) 2024-10-04 21:56:34 +00:00
python_hook.h
python_legacy_variable.cpp [7/N] Fix extra warnings brought by clang-tidy-17 (#138972) 2024-10-26 19:09:47 +00:00
python_legacy_variable.h
python_linalg_functions.h [11/N] Fix extra warnings brought by clang-tidy-17 (#139599) 2024-11-04 23:57:41 +00:00
python_nested_functions_manual.cpp [2/N] Fix clang-tidy warnings in torch/csrc/autograd (#133295) 2024-08-13 13:23:46 +00:00
python_nested_functions.h [8/N] Fix extra warnings brought by clang-tidy-17 (#139151) 2024-10-30 14:20:08 +00:00
python_nn_functions.h Use clang-tidy 17 (#139678) 2024-11-05 16:00:25 +00:00
python_saved_variable_hooks.cpp Update SavedTensorHooks TLS stack to use SafePyObject (#131700) 2024-08-02 16:27:16 +00:00
python_saved_variable_hooks.h
python_sparse_functions.h [11/N] Fix extra warnings brought by clang-tidy-17 (#139599) 2024-11-04 23:57:41 +00:00
python_special_functions.h [11/N] Fix extra warnings brought by clang-tidy-17 (#139599) 2024-11-04 23:57:41 +00:00
python_torch_functions_manual.cpp Delete duplicate bindings in torch/csrc/autograd/python_torch_functions_manual.cpp (#136711) 2024-10-07 23:19:06 +00:00
python_torch_functions.h
python_variable_indexing.cpp Turn static inline into static function (#139843) 2024-11-07 23:58:18 +00:00
python_variable_indexing.h [2/N] Fix clang-tidy warnings in torch/csrc/autograd (#133295) 2024-08-13 13:23:46 +00:00
python_variable.cpp Remove unneeded std::make_optional (#141567) 2024-11-28 00:05:21 +00:00
python_variable.h Use Wextra-semi (#140236) 2024-11-13 02:15:16 +00:00
README.md
record_function_ops.cpp [6/N] Fix Wextra-semi warning (#139605) 2024-11-04 13:43:16 +00:00
record_function_ops.h
saved_variable_hooks.h
saved_variable.cpp
saved_variable.h [1/N] Enable cppcoreguidelines-special-member-functions (#137405) 2024-10-23 00:16:53 +00:00
symbolic.h
TraceTypeManual.cpp [3/N] Fix clang-tidy warnings in torch/csrc/autograd (#133389) 2024-08-16 00:57:54 +00:00
variable_info.cpp Fix autograd.Function + NJT when an output grad is None (#136875) 2024-10-14 19:31:50 +00:00
variable_info.h Fix autograd.Function + NJT when an output grad is None (#136875) 2024-10-14 19:31:50 +00:00
variable.cpp [8/N] Fix extra warnings brought by clang-tidy-17 (#139151) 2024-10-30 14:20:08 +00:00
variable.h [9/N] Fix extra warnings brought by clang-tidy-17 (#139286) 2024-10-31 05:20:31 +00:00
VariableTypeManual.cpp Remove deprecated alias macro(1/3) (#137556) 2024-10-21 17:32:32 +00:00
VariableTypeUtils.h [7/N] Fix extra warnings brought by clang-tidy-17 (#138972) 2024-10-26 19:09:47 +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).