mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-07 12:21:27 +01:00
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 |
||
|---|---|---|
| .. | ||
| init.cpp | ||
| init.h | ||
| module_python.h | ||
| pybind_utils.cpp | ||
| pybind_utils.h | ||
| pybind.h | ||
| python_arg_flatten.cpp | ||
| python_arg_flatten.h | ||
| python_custom_class.cpp | ||
| python_custom_class.h | ||
| python_interpreter.cpp | ||
| python_ir.cpp | ||
| python_ir.h | ||
| python_ivalue.h | ||
| python_sugared_value.cpp | ||
| python_sugared_value.h | ||
| python_tracer.cpp | ||
| python_tracer.h | ||
| python_tree_views.cpp | ||
| python_tree_views.h | ||
| script_init.cpp | ||
| script_init.h | ||
| update_graph_executor_opt.cpp | ||
| update_graph_executor_opt.h | ||