pytorch/torch/csrc/autograd
2023-10-09 19:09:01 +00:00
..
functions [4/N] Enable clang-tidy in torch/csrc/autograd (#109455) 2023-09-17 17:11:50 +00:00
utils
anomaly_mode.cpp
anomaly_mode.h
autograd_meta.cpp [3/N] apply clang-tidy in torch/csrc/autograd (#109368) 2023-09-17 07:26:59 +00:00
autograd_not_implemented_fallback.cpp [4/N] Enable clang-tidy in torch/csrc/autograd (#109455) 2023-09-17 17:11:50 +00:00
autograd_not_implemented_fallback.h [reland] Deprecate registering autograd kernels at not an autograd key (#105078) 2023-07-14 15:03:07 +00:00
autograd.cpp
autograd.h
cpp_hook.cpp [2/N] apply clang-tidy in torch/csrc/autograd (#109277) 2023-09-15 00:39:12 +00:00
cpp_hook.h [2/N] apply clang-tidy in torch/csrc/autograd (#109277) 2023-09-15 00:39:12 +00:00
custom_function.cpp Revert "[reland] Update custom Function preserve torch function when inputs r… (#110679)" 2023-10-09 19:09:01 +00:00
custom_function.h Revert "[reland] Update custom Function preserve torch function when inputs r… (#110679)" 2023-10-09 19:09:01 +00:00
edge.h
engine.cpp retain_graph=True in compiled_autograd (#110367) 2023-10-06 08:22:10 +00:00
engine.h Compiled autograd (#103822) 2023-07-24 21:12:05 +00:00
forward_grad.cpp
forward_grad.h
function_hook.h Add tensor post accumulate grad hook API (#107063) 2023-08-24 00:19:35 +00:00
function.cpp [1/N] apply clang-tidy in torch/csrc/autograd (#109032) 2023-09-15 23:28:43 +00:00
function.h [1/N] Move c10::variant to std::variant (#103675) 2023-09-20 15:21:24 +00:00
FunctionsManual.cpp Implement split_with_sizes backward for NT (#110647) 2023-10-06 18:44:22 +00:00
FunctionsManual.h Implement split_with_sizes backward for NT (#110647) 2023-10-06 18:44:22 +00:00
grad_mode.h
graph_task.h [2/N] apply clang-tidy in torch/csrc/autograd (#109277) 2023-09-15 00:39:12 +00:00
InferenceMode.h
init.cpp [1/N] apply clang-tidy in torch/csrc/autograd (#109032) 2023-09-15 23:28:43 +00:00
input_buffer.cpp [3/N] apply clang-tidy in torch/csrc/autograd (#109368) 2023-09-17 07:26:59 +00:00
input_buffer.h Misc visibility changes for compiled autograd (#105298) 2023-07-18 01:10:04 +00:00
input_metadata.h [2/N] Move c10::variant to std::variant (#109723) 2023-09-24 02:47:43 +00:00
jit_decomp_interface.cpp
jit_decomp_interface.h
profiler_kineto.cpp [4/N] Move remaining c10::variant calls to std::variant (#110382) 2023-10-02 23:52:04 +00:00
profiler_kineto.h [1/N] apply clang-tidy in torch/csrc/autograd (#109032) 2023-09-15 23:28:43 +00:00
profiler_legacy.cpp
profiler_legacy.h
profiler_python.cpp [4/N] Move remaining c10::variant calls to std::variant (#110382) 2023-10-02 23:52:04 +00:00
profiler_python.h
profiler.h
python_anomaly_mode.cpp Remove auto_gil.h (#108492) 2023-09-05 08:26:13 +00:00
python_anomaly_mode.h Remove auto_gil.h (#108492) 2023-09-05 08:26:13 +00:00
python_autograd.h
python_cpp_function.cpp Enable misc clang-tidy checks (#110283) 2023-09-30 10:39:52 +00:00
python_cpp_function.h Add sequence_nr to aot_autograd to map forward ops to their corresponding backward ops (#103129) 2023-08-02 00:52:52 +00:00
python_engine.cpp Enable misc clang-tidy checks (#110283) 2023-09-30 10:39:52 +00:00
python_engine.h
python_enum_tag.h
python_fft_functions.h
python_function.cpp Revert "[reland] Update custom Function preserve torch function when inputs r… (#110679)" 2023-10-09 19:09:01 +00:00
python_function.h [Compiled Autograd] Remove TORCH_API from generated autograd nodes (#105286) 2023-07-27 02:33:14 +00:00
python_hook.cpp [4/N] Enable clang-tidy in torch/csrc/autograd (#109455) 2023-09-17 17:11:50 +00:00
python_hook.h [2/N] apply clang-tidy in torch/csrc/autograd (#109277) 2023-09-15 00:39:12 +00:00
python_legacy_variable.cpp Enable misc clang-tidy checks (#110283) 2023-09-30 10:39:52 +00:00
python_legacy_variable.h
python_linalg_functions.h
python_nested_functions_manual.cpp
python_nested_functions.h
python_nn_functions.h
python_saved_variable_hooks.cpp [4/N] Enable clang-tidy in torch/csrc/autograd (#109455) 2023-09-17 17:11:50 +00:00
python_saved_variable_hooks.h
python_sparse_functions.h
python_special_functions.h
python_torch_functions_manual.cpp [AOTInductor] Implement autograd eager backend for native triton kernels (#110403) 2023-10-04 17:56:56 +00:00
python_torch_functions.h
python_variable_indexing.cpp Add check to prevent NumPy ndarray from being treated as tuple when indexing (#108954) 2023-09-15 08:51:58 +00:00
python_variable_indexing.h
python_variable.cpp Enable misc clang-tidy checks (#110283) 2023-09-30 10:39:52 +00:00
python_variable.h Add tensor post accumulate grad hook API (#107063) 2023-08-24 00:19:35 +00:00
README.md
record_function_ops.cpp [4/N] Enable clang-tidy in torch/csrc/autograd (#109455) 2023-09-17 17:11:50 +00:00
record_function_ops.h
saved_variable_hooks.h
saved_variable.cpp
saved_variable.h Misc visibility changes for compiled autograd (#105298) 2023-07-18 01:10:04 +00:00
symbolic.h
TraceTypeManual.cpp [Reland] Move torch::make_unique to std::make_unique (#109780) 2023-09-21 18:30:21 +00:00
variable.cpp [2/N] apply clang-tidy in torch/csrc/autograd (#109277) 2023-09-15 00:39:12 +00:00
variable.h [4/N] Enable clang-tidy in torch/csrc/autograd (#109455) 2023-09-17 17:11:50 +00:00
VariableTypeManual.cpp [Reland] Move torch::make_unique to std::make_unique (#109780) 2023-09-21 18:30:21 +00:00
VariableTypeUtils.h [foreach] Set SavedVariable.is_output to true for grad_fn->result_ (#105504) 2023-07-26 14:29:32 +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).