pytorch/torch/csrc/autograd
Peter Bell fa09099ba3 Codegen: TraceType only includes operators being registered (#68691)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/68691

TraceType is a sharded file, so by only including specific operator
headers, we ensure that changing one (non-method) operator only needs
one shard to be re-compiled.

This also changes all the included autograd and jit headers from
including `ATen/ATen.h` to just including `ATen/core/Tensor.h`.

Test Plan: Imported from OSS

Reviewed By: gchanan

Differential Revision: D33336948

Pulled By: albanD

fbshipit-source-id: 4e40371592b9a5a7e7fcd1d8cecae11ffb873113
2022-01-02 13:09:19 -08:00
..
functions Codegen: TraceType only includes operators being registered (#68691) 2022-01-02 13:09:19 -08:00
utils
anomaly_mode.cpp
anomaly_mode.h Remove WindowsTorchApiMacro.h in favor of Export.h (#69585) 2021-12-09 17:30:09 -08:00
autograd.cpp
autograd.h Codegen: TraceType only includes operators being registered (#68691) 2022-01-02 13:09:19 -08:00
autograd_meta.cpp Codegen: TraceType only includes operators being registered (#68691) 2022-01-02 13:09:19 -08:00
autograd_not_implemented_fallback.cpp
autograd_not_implemented_fallback.h
cpp_hook.cpp
cpp_hook.h
custom_function.cpp
custom_function.h
edge.h
engine.cpp Remove THGeneral (#69041) 2021-12-13 16:14:28 -08:00
engine.h Remove WindowsTorchApiMacro.h in favor of Export.h (#69585) 2021-12-09 17:30:09 -08:00
forward_grad.cpp
forward_grad.h Codegen: TraceType only includes operators being registered (#68691) 2022-01-02 13:09:19 -08:00
function.cpp
function.h Codegen: TraceType only includes operators being registered (#68691) 2022-01-02 13:09:19 -08:00
function_hook.cpp
function_hook.h Remove WindowsTorchApiMacro.h in favor of Export.h (#69585) 2021-12-09 17:30:09 -08:00
FunctionsManual.cpp Fix some Composite Compliance problems with binary_cross_entropy backward (#70198) 2021-12-22 07:24:04 -08:00
FunctionsManual.h Remove backward ops for cuDNN transposed convolution (#69902) 2021-12-15 17:48:25 -08:00
grad_mode.h Remove WindowsTorchApiMacro.h in favor of Export.h (#69585) 2021-12-09 17:30:09 -08:00
InferenceMode.h Remove WindowsTorchApiMacro.h in favor of Export.h (#69585) 2021-12-09 17:30:09 -08:00
init.cpp [Profiler] Pull helper methods into dedicated file. (And start torch/csrc/profiler folder. (#69255) 2021-12-16 10:33:47 -08:00
input_buffer.cpp
input_buffer.h
input_metadata.h Codegen: TraceType only includes operators being registered (#68691) 2022-01-02 13:09:19 -08:00
profiler.h
profiler_kineto.cpp Codegen: TraceType only includes operators being registered (#68691) 2022-01-02 13:09:19 -08:00
profiler_kineto.h [Profiler] Factor common logic into torch/csrc/profiler/api.h (#69459) 2021-12-19 18:40:28 -08:00
profiler_legacy.cpp Codegen: TraceType only includes operators being registered (#68691) 2022-01-02 13:09:19 -08:00
profiler_legacy.h Codegen: TraceType only includes operators being registered (#68691) 2022-01-02 13:09:19 -08:00
profiler_python.cpp [Reland] Python tracer. (#68325) 2021-11-15 23:32:49 -08:00
profiler_python.h [Reland] Python tracer. (#68325) 2021-11-15 23:32:49 -08:00
profiler_utils.cpp [PyTorch][kineto] Remove heap-allocated vectors in saveExtraArgs (#69737) 2021-12-10 20:24:17 -08:00
python_anomaly_mode.cpp
python_anomaly_mode.h
python_autograd.h
python_cpp_function.cpp
python_cpp_function.h
python_engine.cpp
python_engine.h
python_fft_functions.h
python_function.cpp
python_function.h
python_hook.cpp
python_hook.h
python_legacy_variable.cpp
python_legacy_variable.h
python_linalg_functions.h
python_mode.cpp
python_mode.h
python_nn_functions.h
python_return_types.h expose return_types in Python (#66614) 2021-12-06 09:05:29 -08:00
python_saved_variable_hooks.cpp
python_saved_variable_hooks.h Rationalize API exports in torch_python (#68095) 2021-12-07 15:24:37 -08:00
python_sparse_functions.h [clone][sparse] Add torch._C._sparse namespace (#68672) 2021-11-19 19:47:38 -08:00
python_special_functions.h
python_torch_functions.h
python_torch_functions_manual.cpp functionalization: update is_aliased() logic (#68881) 2021-12-02 09:19:12 -08:00
python_variable.cpp
python_variable.h Rationalize API exports in torch_python (#68095) 2021-12-07 15:24:37 -08:00
python_variable_indexing.cpp Rationalize API exports in torch_python (#68095) 2021-12-07 15:24:37 -08:00
python_variable_indexing.h
README.md
record_function_ops.cpp
record_function_ops.h
saved_variable.cpp
saved_variable.h Codegen: TraceType only includes operators being registered (#68691) 2022-01-02 13:09:19 -08:00
saved_variable_hooks.h Codegen: TraceType only includes operators being registered (#68691) 2022-01-02 13:09:19 -08:00
symbolic.h
TraceTypeManual.cpp Codegen: TraceType only includes operators being registered (#68691) 2022-01-02 13:09:19 -08:00
variable.cpp
variable.h Codegen: TraceType only includes operators being registered (#68691) 2022-01-02 13:09:19 -08:00
VariableTypeManual.cpp Fix copy_ forward AD to handle broadcasting (#69592) 2021-12-12 00:11:08 -08:00
VariableTypeUtils.h Codegen: TraceType only includes operators being registered (#68691) 2022-01-02 13:09:19 -08: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).