pytorch/torch/csrc/jit/python
Meghan Lele 73de98204d [JIT] Add static method support for TorchBind (#51177)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/51177

**Summary**
This commit adds support for static methods to TorchBind. Just like
pybind, the API for declaring a static method is `def_static(...)`. A
static method must be called on the class directly, and can be called
both in Python as well as TorchScript.

Support for static methods is implemented in a manner similar to that of
instance methods. Registered static functions are wrapped in a layer of
unboxing logic, their schemas are inferred using templates and
metaprogramming, and they are added to the `ClassType` object
corresponding to the TorchBind class on which they are registered.
ScriptClass has been extended to support a `__getattr__` function so
that static methods of TorchBind classes can be invoked in Python. The
implementation of `__getattr__` returns `ScriptClassFunctionPtr`, a
version of `StrongFunctionPtr` without a compilation unit (since the
functions of a TorchBind class live inside the TorchBind registry).
Within TorchScript, TorchBind static functions are desugared in
`PythonClassValue::attr` by looking them up on the class type of the
`PythonClassValue` instance.

**Test Plan**
This commit adds a unit test that tests a simple static method on a
TorchBind class.

Test Plan: Imported from OSS

Reviewed By: pbelevich

Differential Revision: D26356942

Pulled By: SplitInfinity

fbshipit-source-id: 1b6a9bc2e5f3e22071ad78e331a0201fbbf7ab30
2021-02-13 19:41:27 -08:00
..
init.cpp [package] make torch.package produce unified format (#51826) 2021-02-09 07:45:59 -08:00
init.h
module_python.h
pybind_utils.cpp Graceful invalidation of Python Node/Value/Block when C++ object is deleted (#50326) 2021-02-04 01:34:46 -08:00
pybind_utils.h [JIT/Futures] support set_exception api (#50983) 2021-02-04 20:22:19 -08:00
pybind.h Graceful invalidation of Python Node/Value/Block when C++ object is deleted (#50326) 2021-02-04 01:34:46 -08:00
python_arg_flatten.cpp [ONNX] ONNX dev branch merge 01-06-2021 (#50163) 2021-01-13 13:51:21 -08:00
python_arg_flatten.h Move torch/csrc/utils/hash.h to c10/util/hash.h. (#42503) 2020-08-29 17:47:00 -07:00
python_custom_class.cpp [JIT] Add static method support for TorchBind (#51177) 2021-02-13 19:41:27 -08:00
python_custom_class.h
python_interpreter.cpp Unify boxed function signature between jit and c10 (#37034) 2020-06-29 19:24:26 -07:00
python_ir.cpp Keep alive graph when creating iterators from it (#51951) 2021-02-10 11:09:51 -08:00
python_ir.h
python_ivalue.h Remove DataPtr extractor from CUDAFuture (#48840) 2020-12-19 11:03:45 -08:00
python_sugared_value.cpp [JIT] Add static method support for TorchBind (#51177) 2021-02-13 19:41:27 -08:00
python_sugared_value.h Fix clang-tidy warnings in python_sugared_value.{h,cpp} (#51703) 2021-02-04 21:29:40 -08:00
python_tracer.cpp [Usability] Capture argument names for traced functions and modules (#51775) 2021-02-10 18:28:08 -08:00
python_tracer.h [Usability] Capture argument names for traced functions and modules (#51775) 2021-02-10 18:28:08 -08:00
python_tree_views.cpp Add dict comprehension (#47774) 2020-12-17 15:25:30 -08:00
python_tree_views.h
script_init.cpp [Usability] Capture argument names for traced functions and modules (#51775) 2021-02-10 18:28:08 -08:00
script_init.h
update_graph_executor_opt.cpp
update_graph_executor_opt.h