70 Commits

Author SHA1 Message Date
09a7788a2f [torchbind] Improve IValue custom class API and remove most Capsule stuff (#34848)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/34848

Test Plan: Imported from OSS

Differential Revision: D20480514

Pulled By: jamesr66a

fbshipit-source-id: 1c595faf34e00aab0a6202a8902426bd310551c3
2020-03-17 20:39:34 -07:00
fb20621b3b Move torchbind out of jit namespace (#34745)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/34745

Test Plan: Imported from OSS

Differential Revision: D20450239

Pulled By: jamesr66a

fbshipit-source-id: 3f5597626f21d7b5e329b57da358c76b531bf806
2020-03-13 23:03:14 -07:00
ab76a8206f [JIT][mobile] Support built-in Function call in lite interpreter (#34676)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/34676

Test Plan: Imported from OSS

Differential Revision: D20427938

Pulled By: jamesr66a

fbshipit-source-id: 79eebfa858776f26da55ffd49d3f78fa7ae0df9b
2020-03-13 18:24:18 -07:00
c235be42dd [jit] kill script namespace (#34515)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/34515

Once upon a time we thought this was necessary. In reality it is not, so
removing it.

For backcompat, our public interface (defined in `api/`) still has
typedefs to the old `script::` names.

There was only one collision: `Pass` as a `Stmt` and `Pass` as a graph
transform. I renamed one of them.

Test Plan: Imported from OSS

Differential Revision: D20353503

Pulled By: suo

fbshipit-source-id: 48bb911ce75120a8c9e0c6fb65262ef775dfba93
2020-03-11 23:32:48 -07:00
45a504dd2d [JIT] Introduce BuiltinOpFunction and integrate into torchbind (#34098)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/34098

* #33900 [JIT] Move stuff out of class_type.cpp

Test Plan: Imported from OSS

Differential Revision: D20229166

Pulled By: jamesr66a

fbshipit-source-id: d658a63a5d6e372e675f35b8456adc8de82b49f3
2020-03-07 10:03:56 -08:00
2fa51dde28 Remove unnecessary tensor copies (#33732)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/33732

move and forward instead of copy

Benchmarks:
A microbenchmark calling the add operation on two tensors in a tight loop shows a 5% improvement in performance.
No visible change for a model like resnet that does more work in its kernels.
ghstack-source-id: 99161486

Test Plan: benchmarks

Differential Revision: D20082642

fbshipit-source-id: eeac59686f8621dd5eaa85d61e6d219bba48c847
2020-02-28 14:47:04 -08:00
dbe850af5b [jit] do the code reorg (#33851)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/33851

Rationale and context described in #33828.

Script to reproduce the move:
https://gist.github.com/suo/16cbefaaeb67ca5a7c6caffd49b7f6e9
ghstack-source-id: 99079645

Test Plan: Make sure CI passes

Reviewed By: jamesr66a

Differential Revision: D20133869

fbshipit-source-id: 390e9241a9c85366d9005c492ac31f10aa96488e
2020-02-27 13:02:51 -08:00
0ea65d63cf [JIT] Fix stateful lambda stuff and simplify code in custom C++ binding API
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/32658

Test Plan: Imported from OSS

Differential Revision: D19584701

Pulled By: jamesr66a

fbshipit-source-id: d556c7db2f32900eb1122348402789b59516a7d7
2020-01-28 11:03:04 -08:00
465ebd58ba [JIT] pickle serialization for custom bound classes
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/32604

Test Plan: Imported from OSS

Differential Revision: D19566633

fbshipit-source-id: 9387d3ff45cbd6ccde49ce190a52859481cc301c
2020-01-28 11:02:59 -08:00
1719da13f9 [JIT] Support for registering C++ lambdas as methods on custom C++ class
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/32553

Test Plan: Imported from OSS

Differential Revision: D19543269

Pulled By: jamesr66a

fbshipit-source-id: 7e566650295e9d1c4f2f716470e061308a6210a0
2020-01-28 11:01:07 -08:00
6745bfc31c Revert "Remove __torch__ from custom class qualname" (#32514)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/32514

This reverts commit c7fdf5b251c6fecd5d78b4f33d30bd77ca3f841c.

Test Plan: Imported from OSS

Differential Revision: D19525532

Pulled By: jamesr66a

fbshipit-source-id: 126f4e87250a2ac739bd7aa161a0f7b39f143d38
2020-01-23 14:56:25 -08:00
69f9bf8893 [JIT] Support returning tuple from custom bound C++ method
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/32477

Test Plan: Imported from OSS

Differential Revision: D19509927

Pulled By: jamesr66a

fbshipit-source-id: 7d407150402cc19344c3ec3b4a27b3d7c464e8ac
2020-01-23 14:56:15 -08:00
ae42e232ce [JIT] Fix custom class method binding for const methods
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/32471

Test Plan: Imported from OSS

Differential Revision: D19508249

Pulled By: jamesr66a

fbshipit-source-id: 3a0bce6845072bb03567049a73b9982b54d8daf9
2020-01-23 14:56:11 -08:00
c7fdf5b251 Remove __torch__ from custom class qualname
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/32301

Test Plan: Imported from OSS

Differential Revision: D19431645

Pulled By: jamesr66a

fbshipit-source-id: 198522a1641cb9f90fa4c614da4ca4162fadf456
2020-01-17 23:09:29 -08:00
7d630278da Separate torchbind from Python (#30242)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/30242

Pull Request resolved: https://github.com/pytorch/pytorch/pull/29501

Currently blocked on schema serialization issue

Test Plan: Imported from OSS

Differential Revision: D18463063

Pulled By: jamesr66a

fbshipit-source-id: c12a1b644eb9bf04e68ff93cccf91d6cb3e75359
2019-12-21 22:52:40 -08:00
643ca5def2 Replace c10::guts::stuff with std::stuff (#30915)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/30915

Since we now have C++14, we don't need these c10::guts helpers anymore
ghstack-source-id: 95777609

Test Plan: waitforsandcastle

Differential Revision: D18869639

fbshipit-source-id: 97716f932297c64c6e814410ac47b444c33d4e2e
2019-12-16 13:57:19 -08:00
949678bd9e Small fixes for torchbind (#28800)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/28800

Fix up namespaces and make friendly error message when registered class doesn't inherit from the right base

Test Plan: Imported from OSS

Differential Revision: D18175067

Pulled By: jamesr66a

fbshipit-source-id: 5c7cf3a49fb45db502d84eb3f9a69be126ee59fb
2019-10-28 16:45:24 -07:00
6cae07a668 search class type for methods (#23689)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/23689

We store methods, no reason to try to lock the CU to find a method on a
class type

Test Plan: Imported from OSS

Differential Revision: D16610045

Pulled By: suo

fbshipit-source-id: d84ad81faa42c4e2da20b666fa3645e22f11dac3
2019-08-12 20:29:45 -07:00
61d0624803 [jit[ make sure NameTuples have unique qualified names
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/23798

Test Plan: Imported from OSS

Differential Revision: D16652818

Pulled By: suo

fbshipit-source-id: c824f26427105ed5f0c553a67ab61c69a1f89655
2019-08-09 00:52:02 -07:00
f81db8afb8 Initial torchbind prototype (#21098)
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
2019-08-02 18:45:15 -07:00