mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-06 12:20:52 +01:00
Summary:
I have some test code in there as well, along with a script "test_libtorch" to run it. You'll need to modify `test_libtorch` to point to where you have `pytorch` built. I currently require that `pybind11` is included as a subdirectory of the test, but added it to the `.gitignore` to make this reviewable.
Currently, something like this works:
```cpp
struct Foo {
int x, y;
Foo(): x(2), y(5){}
Foo(int x_, int y_) : x(x_), y(y_) {}
void display() {
cout<<"x: "<<x<<' '<<"y: "<<y<<endl;
}
int64_t add(int64_t z) {
return (x+y)*z;
}
};
static auto test = torch::jit::class_<Foo>("Foo")
.def(torch::jit::init<int64_t, int64_t>())
.def("display", &Foo::display)
.def("add", &Foo::add)
.def("combine", &Foo::combine);
```
with
```py
torch.jit.script
def f(x):
val = torch._C.Foo(5, 3)
val.display()
print(val.add(3))
```
results in
```
x: 5 y: 3
24
```
Current issues:
- [x] The python class created by torchscript doesn't interactly properly with the surrounding code.
```
torch.jit.script
def f(x):
val = torch._C.Foo(5, 3)
return val
```
- [x] Doesn't properly take in non-pointer classes. Can't define this function signature in cpp (We don't want to support this I believe).
```cpp
void combine(Foo x) {
```
- [x] Has some issues with memory for blobs when constructing multiple objects (fix constant propagation pass to not treat capsules as the same object).
```py
torch.jit.script
def f(x):
val = torch._C.Foo(5, 3)
val2 = torch._C.Foo(100, 0)
val.display()
print(val.add(3))
```
- [ ] Can't define multiple constructors (need to define overload string. Currently not possible since we don't support overloaded methods).
- [x] `init` is a little bit different syntax than `pybind`. `.init<...>()` instead of `.def(py::init<>())`
- [x] I couldn't figure out how to add some files into the build so they'd be copied to the `include/` directories, so I symlinked them manually.
- [ ] Currently, the conversion from Python into Torchscript doesn't work.
- [ ] Torchbind also currently requires Python/Pybind dependency. Fixing this would probably involve some kind of macro to bind into Python when possible.
- [ ] We pass back into Python by value, currently. There's no way of passing by reference.
- [x] Currently can only register one method with the same type signature. This is because we create a `static auto opRegistry`, and the function is templated on the type signature.
Somewhat blocked on https://github.com/pytorch/pytorch/pull/21177. We currently use some structures that will be refactored by his PR (namely `return_type_to_ivalue` and `ivalue_to_arg_type`.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/21098
Differential Revision: D16634872
Pulled By: Chillee
fbshipit-source-id: 1408bb89ea649c27d560df59e2cf9920467fe1de
|
||
|---|---|---|
| .. | ||
| backends | ||
| docs | ||
| fuser | ||
| passes | ||
| script | ||
| testing | ||
| alias_info.h | ||
| argument_spec.cpp | ||
| argument_spec.h | ||
| attributes.cpp | ||
| attributes.h | ||
| autodiff.cpp | ||
| autodiff.h | ||
| catch_utils.hpp | ||
| code_template.h | ||
| constants.cpp | ||
| constants.h | ||
| custom_operator.h | ||
| dynamic_dag.h | ||
| exception_message.h | ||
| export.cpp | ||
| export.h | ||
| function.cpp | ||
| function.h | ||
| graph_executor_impl.h | ||
| graph_executor.cpp | ||
| graph_executor.h | ||
| graph_node_list.h | ||
| hooks_for_testing.cpp | ||
| hooks_for_testing.h | ||
| import_export_helpers.cpp | ||
| import_export_helpers.h | ||
| import_source.cpp | ||
| import_source.h | ||
| import.cpp | ||
| import.h | ||
| init.cpp | ||
| init.h | ||
| interned_strings_class.h | ||
| interpreter.cpp | ||
| interpreter.h | ||
| ir_views.h | ||
| ir.cpp | ||
| ir.h | ||
| irparser.cpp | ||
| irparser.h | ||
| jit_log.cpp | ||
| jit_log.h | ||
| named_value.h | ||
| netdef_converter.cpp | ||
| netdef_converter.h | ||
| node_hashing.cpp | ||
| node_hashing.h | ||
| operator_options.cpp | ||
| operator_options.h | ||
| operator.cpp | ||
| operator.h | ||
| pass_manager.cpp | ||
| pass_manager.h | ||
| pickler.cpp | ||
| pickler.h | ||
| print_handler.cpp | ||
| print_handler.h | ||
| profiling_graph_executor_impl.cpp | ||
| profiling_graph_executor_impl.h | ||
| profiling_record.cpp | ||
| profiling_record.h | ||
| pybind_utils.h | ||
| pybind.h | ||
| python_arg_flatten.cpp | ||
| python_arg_flatten.h | ||
| python_interpreter.cpp | ||
| python_ir.cpp | ||
| python_ir.h | ||
| python_tracer.cpp | ||
| python_tracer.h | ||
| register_c10_ops.cpp | ||
| register_prim_ops.cpp | ||
| register_special_ops.cpp | ||
| register_string_ops.cpp | ||
| resource_guard.h | ||
| scope.cpp | ||
| scope.h | ||
| source_range_serialization_impl.h | ||
| source_range_serialization.cpp | ||
| source_range_serialization.h | ||
| source_range.cpp | ||
| source_range.h | ||
| subgraph_matcher.cpp | ||
| subgraph_matcher.h | ||
| symbolic_script.cpp | ||
| symbolic_script.h | ||
| symbolic_variable.h | ||
| tracer.cpp | ||
| tracer.h | ||
| variable_tensor_list.h | ||