Most of the core PyTorch functions on the torch
package and on torch.Tensor
are generated from Declarations.yaml (*) using gen_python_functions.cpp. The generated files look like:
python_torch_functions.cpp
python_variable_methods.cpp
We don’t use pybind11 here for a few reasons:
- We need to disambiguate multiple overloads in a PyTorch-specific way. Some of this behavior is due to historical Lua Torch function signatures. We try to avoid this ambiguity in new functions.
- pybind11 tends to slow down compile time a lot
(*) Declarations.yaml is generated from native_functions.yaml. There used to be other inputs that went into Declarations.yaml, but I’m not sure if that’s still the case. Anyways, Declarations.yaml is intended as the “public” machine-readable API specification for things like language bindings.