pytorch/torch/csrc/autograd
Ivan Kobzarev 3112e23428 [py][vulkan][reland] Add is_vulkan to py api, add vulkan to device type parsing (#46655)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/46655

Test Plan: Imported from OSS

Pulled By: IvanKobzarev

Reviewed By: mrshenli

Differential Revision: D24448984

fbshipit-source-id: 5000846a06077f7a5a06dd51da422d2a42f70820
2020-10-22 09:35:50 -07:00
..
functions Allow consumer ops to sync on GraphRoot's gradient (#45787) 2020-10-07 08:53:53 -07:00
utils Add __torch_function__ for methods (#37091) 2020-08-05 20:44:13 -07:00
anomaly_mode.cpp
anomaly_mode.h Print all traceback for nested backwards in detect_anomaly (#43626) 2020-08-31 08:23:07 -07:00
autograd.cpp Add whitelist for complex backward (#45461) 2020-09-30 08:45:55 -07:00
autograd.h
cpp_hook.cpp
cpp_hook.h
custom_function.cpp Don't materialize output grads (#41821) 2020-08-11 04:27:07 -07:00
custom_function.h Fix implicit cast in custom_function (#46445) 2020-10-16 10:58:02 -07:00
edge.h Move torch/csrc/utils/hash.h to c10/util/hash.h. (#42503) 2020-08-29 17:47:00 -07:00
engine.cpp Remove lock from GraphTask::set_exception_without_signal. (#45867) 2020-10-05 20:02:29 -07:00
engine.h Preserve python backtrace in autograd engine errors. (#43684) 2020-09-01 01:28:47 -07:00
function_hook.cpp
function_hook.h
function.cpp Print all traceback for nested backwards in detect_anomaly (#43626) 2020-08-31 08:23:07 -07:00
function.h Source code level attribution in profiler (#43898) 2020-09-30 00:57:35 -07:00
FunctionsManual.cpp Avoid mat1 references in mm_mat1_backward (#45777) 2020-10-16 13:52:44 -07:00
FunctionsManual.h Avoid mat1 references in mm_mat1_backward (#45777) 2020-10-16 13:52:44 -07:00
grad_mode.h
init.cpp Remove PyCFunction casts as much as possible. (#46227) 2020-10-20 15:01:51 -07:00
input_buffer.cpp
input_buffer.h
input_metadata.h
profiler_cuda.cpp Destroy CUDA events after profiling (#39962) 2020-06-23 10:44:39 -07:00
profiler.cpp Source code level attribution in profiler (#43898) 2020-09-30 00:57:35 -07:00
profiler.h Source code level attribution in profiler (#43898) 2020-09-30 00:57:35 -07:00
python_anomaly_mode.cpp Print all traceback for nested backwards in detect_anomaly (#43626) 2020-08-31 08:23:07 -07:00
python_anomaly_mode.h Print all traceback for nested backwards in detect_anomaly (#43626) 2020-08-31 08:23:07 -07:00
python_autograd.h
python_cpp_function.cpp
python_cpp_function.h Remove PyCFunction casts as much as possible. (#46227) 2020-10-20 15:01:51 -07:00
python_engine.cpp Remove PyCFunction casts as much as possible. (#46227) 2020-10-20 15:01:51 -07:00
python_engine.h Use ivalue::Future in autograd engine and DistEngine. (#43676) 2020-08-29 02:15:26 -07:00
python_fft_functions.h Adds fft namespace (#41911) 2020-08-06 00:20:50 -07:00
python_function.cpp Remove PyCFunction casts as much as possible. (#46227) 2020-10-20 15:01:51 -07:00
python_function.h Don't materialize output grads (#41821) 2020-08-11 04:27:07 -07:00
python_hook.cpp
python_hook.h
python_legacy_variable.cpp Fix return value of PyErr_WarnEx ignored (SystemError) (#44371) 2020-09-10 10:15:21 -07:00
python_legacy_variable.h
python_linalg_functions.h Adds torch.linalg namespace (#42664) 2020-08-07 10:18:30 -07:00
python_nn_functions.h Adds fft namespace (#41911) 2020-08-06 00:20:50 -07:00
python_variable_indexing.cpp Add __torch_function__ for methods (#37091) 2020-08-05 20:44:13 -07:00
python_variable_indexing.h
python_variable.cpp [py][vulkan][reland] Add is_vulkan to py api, add vulkan to device type parsing (#46655) 2020-10-22 09:35:50 -07:00
python_variable.h
README.md
record_function_ops.cpp RecordFunction in Dispatcher (#37587) 2020-07-17 22:20:05 -07:00
record_function_ops.h [RFC] Profile rpc_async call from JIT (#40652) 2020-07-03 15:17:16 -07:00
saved_variable.cpp Change C++ frontend to take optional<Tensor> arguments (#41947) 2020-07-31 16:11:55 -07:00
saved_variable.h Change C++ frontend to take optional<Tensor> arguments (#41947) 2020-07-31 16:11:55 -07:00
symbolic.h
TraceTypeManual.cpp Allow Tensor& in the unboxing logic (#42712) 2020-08-12 17:33:23 -07:00
variable.cpp Add quick fix for view/inplace issue with DDP (#46406) 2020-10-15 15:13:11 -07:00
variable.h Reland split (#41567) 2020-07-21 08:06:27 -07:00
VariableTypeManual.cpp [WIP] Move catchAll to Math (#45939) 2020-10-16 16:17:16 -07:00
VariableTypeUtils.h detect inplace modifications of views earlier (fix #21875) (#46204) 2020-10-19 08:58:33 -07: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).