Skip to content

Put TORCH_LIBRARY in torch/library.h; add custom class API#36742

Closed
ezyang wants to merge 13 commits intogh/ezyang/728/basefrom
gh/ezyang/728/head
Closed

Put TORCH_LIBRARY in torch/library.h; add custom class API#36742
ezyang wants to merge 13 commits intogh/ezyang/728/basefrom
gh/ezyang/728/head

Conversation

@ezyang
Copy link
Copy Markdown
Contributor

@ezyang ezyang commented Apr 16, 2020

Stack from ghstack:

Now, you can define a custom class inside a TORCH_LIBRARY block.
It looks very similar to what you did before. Instead of

static auto m = torch::class_<Class>("Namespace", "Class").def("foo", foo);

you write

TORCH_LIBRARY(Namespace, m) {
  m.class_<Class>("Class")
    .def("foo", foo);
}

All the old usages still work, but at some point we should start
updating the tutorials when we're ready to go 100% live with the
new pybind11 style API.

custom class API previously lived in torch/ folder and in torch
namespace, so for consistency, the new TORCH_LIBRARY also got
moved to torch/library.h The definition of Library::class_ is in the
bottom of that header because I need all of the class_ constructors
available, but there is a circular dependency between the two headers.

Signed-off-by: Edward Z. Yang ezyang@fb.com

Differential Revision: D21089648

Now, you can define a custom class inside a TORCH_LIBRARY block.
It looks very similar to what you did before.  Instead of

```
static auto m = torch::class_<Class>("Namespace", "Class").def("foo", foo);
```

you write

```
TORCH_LIBRARY(Namespace, m) {
  m.class_<Class>("Class")
    .def("foo", foo);
}
```

All the old usages still work, but at some point we should start
updating the tutorials when we're ready to go 100% live with the
new pybind11 style API.

custom_class_detail.h/custom_class.h were moved to ATen/core, there are
some modifications in custom_class.h: the definition of Library::class_
is in the bottom of that header because I need all of the class_
constructors available, but there is a circular dependency between the
two headers.

Signed-off-by: Edward Z. Yang <ezyang@fb.com>

[ghstack-poisoned]
@ezyang ezyang requested a review from apaszke as a code owner April 16, 2020 19:23
@facebook-github-bot facebook-github-bot added the oncall: jit Add this issue/PR to JIT oncall triage queue label Apr 16, 2020
@dr-ci
Copy link
Copy Markdown

dr-ci Bot commented Apr 16, 2020

💊 Build failures summary and remediations

As of commit 41a88fc (more details on the Dr. CI page):


  • 1/1 failures introduced in this PR

XLA failure

Job pytorch_xla_linux_bionic_py3_6_clang9_build is failing. Please create an issue with title prefixed by [PT_BREAK] in pytorch/xla and link to to this PR. If you have questions, please reach out to @ailzhang / @dlibenzi / @JackCaoG.


This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.

Please report bugs/suggestions on the GitHub issue tracker.

See how this bot performed.

This comment has been revised 48 times.

Comment thread torch/custom_class.h Outdated
} // namespace jit

} // namespace torch
#include <ATen/core/op_registration/custom_class.h>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need to move all this? custom_class.h was meant to be easily accessible and readable for libtorch users and I don't like the indirection this is introducing

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure. The operant question is whether or not I can include torch/ base directory from ATen/core. I can probably make it work if I push on the build system enough, but my default assumption is it will require a bit of finagling. (Maybe less finagling since custom_class.h already works on mobile, though?)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we ask if the same accessibility concerns apply to the new API as to custom_class.h? Maybe this is a symptom of the new stuff being too buried.

Now, you can define a custom class inside a TORCH_LIBRARY block.
It looks very similar to what you did before.  Instead of

```
static auto m = torch::class_<Class>("Namespace", "Class").def("foo", foo);
```

you write

```
TORCH_LIBRARY(Namespace, m) {
  m.class_<Class>("Class")
    .def("foo", foo);
}
```

All the old usages still work, but at some point we should start
updating the tutorials when we're ready to go 100% live with the
new pybind11 style API.

custom_class_detail.h/custom_class.h were moved to ATen/core, there are
some modifications in custom_class.h: the definition of Library::class_
is in the bottom of that header because I need all of the class_
constructors available, but there is a circular dependency between the
two headers.

Signed-off-by: Edward Z. Yang <ezyang@fb.com>

[ghstack-poisoned]
Now, you can define a custom class inside a TORCH_LIBRARY block.
It looks very similar to what you did before.  Instead of

```
static auto m = torch::class_<Class>("Namespace", "Class").def("foo", foo);
```

you write

```
TORCH_LIBRARY(Namespace, m) {
  m.class_<Class>("Class")
    .def("foo", foo);
}
```

All the old usages still work, but at some point we should start
updating the tutorials when we're ready to go 100% live with the
new pybind11 style API.

custom_class_detail.h/custom_class.h were moved to ATen/core, there are
some modifications in custom_class.h: the definition of Library::class_
is in the bottom of that header because I need all of the class_
constructors available, but there is a circular dependency between the
two headers.

Signed-off-by: Edward Z. Yang <ezyang@fb.com>

[ghstack-poisoned]
ezyang added a commit that referenced this pull request Apr 16, 2020
Now, you can define a custom class inside a TORCH_LIBRARY block.
It looks very similar to what you did before.  Instead of

```
static auto m = torch::class_<Class>("Namespace", "Class").def("foo", foo);
```

you write

```
TORCH_LIBRARY(Namespace, m) {
  m.class_<Class>("Class")
    .def("foo", foo);
}
```

All the old usages still work, but at some point we should start
updating the tutorials when we're ready to go 100% live with the
new pybind11 style API.

custom_class_detail.h/custom_class.h were moved to ATen/core, there are
some modifications in custom_class.h: the definition of Library::class_
is in the bottom of that header because I need all of the class_
constructors available, but there is a circular dependency between the
two headers.

Signed-off-by: Edward Z. Yang <ezyang@fb.com>

ghstack-source-id: 3236e79
Pull Request resolved: #36742
Now, you can define a custom class inside a TORCH_LIBRARY block.
It looks very similar to what you did before.  Instead of

```
static auto m = torch::class_<Class>("Namespace", "Class").def("foo", foo);
```

you write

```
TORCH_LIBRARY(Namespace, m) {
  m.class_<Class>("Class")
    .def("foo", foo);
}
```

All the old usages still work, but at some point we should start
updating the tutorials when we're ready to go 100% live with the
new pybind11 style API.

custom_class_detail.h/custom_class.h were moved to ATen/core, there are
some modifications in custom_class.h: the definition of Library::class_
is in the bottom of that header because I need all of the class_
constructors available, but there is a circular dependency between the
two headers.

Signed-off-by: Edward Z. Yang <ezyang@fb.com>

[ghstack-poisoned]
ezyang added 2 commits April 17, 2020 07:19
Now, you can define a custom class inside a TORCH_LIBRARY block.
It looks very similar to what you did before.  Instead of

```
static auto m = torch::class_<Class>("Namespace", "Class").def("foo", foo);
```

you write

```
TORCH_LIBRARY(Namespace, m) {
  m.class_<Class>("Class")
    .def("foo", foo);
}
```

All the old usages still work, but at some point we should start
updating the tutorials when we're ready to go 100% live with the
new pybind11 style API.

custom_class_detail.h/custom_class.h were moved to ATen/core, there are
some modifications in custom_class.h: the definition of Library::class_
is in the bottom of that header because I need all of the class_
constructors available, but there is a circular dependency between the
two headers.

Signed-off-by: Edward Z. Yang <ezyang@fb.com>

[ghstack-poisoned]
Now, you can define a custom class inside a TORCH_LIBRARY block.
It looks very similar to what you did before.  Instead of

```
static auto m = torch::class_<Class>("Namespace", "Class").def("foo", foo);
```

you write

```
TORCH_LIBRARY(Namespace, m) {
  m.class_<Class>("Class")
    .def("foo", foo);
}
```

All the old usages still work, but at some point we should start
updating the tutorials when we're ready to go 100% live with the
new pybind11 style API.

custom_class_detail.h/custom_class.h were moved to ATen/core, there are
some modifications in custom_class.h: the definition of Library::class_
is in the bottom of that header because I need all of the class_
constructors available, but there is a circular dependency between the
two headers.

Signed-off-by: Edward Z. Yang <ezyang@fb.com>

Differential Revision: [D21089648](https://our.internmc.facebook.com/intern/diff/D21089648)

[ghstack-poisoned]
@ezyang ezyang changed the title Add custom class API to TORCH_LIBRARY API. Put TORCH_LIBRARY in torch/library.h; add custom class API Apr 20, 2020
Now, you can define a custom class inside a TORCH_LIBRARY block.
It looks very similar to what you did before.  Instead of

```
static auto m = torch::class_<Class>("Namespace", "Class").def("foo", foo);
```

you write

```
TORCH_LIBRARY(Namespace, m) {
  m.class_<Class>("Class")
    .def("foo", foo);
}
```

All the old usages still work, but at some point we should start
updating the tutorials when we're ready to go 100% live with the
new pybind11 style API.

custom class API previously lived in torch/ folder and in torch
namespace, so for consistency, the new TORCH_LIBRARY also got
moved to torch/library.h The definition of Library::class_ is in the
bottom of that header because I need all of the class_ constructors
available, but there is a circular dependency between the two headers.

Signed-off-by: Edward Z. Yang <ezyang@fb.com>

Differential Revision: [D21089648](https://our.internmc.facebook.com/intern/diff/D21089648)

[ghstack-poisoned]
Now, you can define a custom class inside a TORCH_LIBRARY block.
It looks very similar to what you did before.  Instead of

```
static auto m = torch::class_<Class>("Namespace", "Class").def("foo", foo);
```

you write

```
TORCH_LIBRARY(Namespace, m) {
  m.class_<Class>("Class")
    .def("foo", foo);
}
```

All the old usages still work, but at some point we should start
updating the tutorials when we're ready to go 100% live with the
new pybind11 style API.

custom class API previously lived in torch/ folder and in torch
namespace, so for consistency, the new TORCH_LIBRARY also got
moved to torch/library.h The definition of Library::class_ is in the
bottom of that header because I need all of the class_ constructors
available, but there is a circular dependency between the two headers.

Signed-off-by: Edward Z. Yang <ezyang@fb.com>

Differential Revision: [D21089648](https://our.internmc.facebook.com/intern/diff/D21089648)

[ghstack-poisoned]
Now, you can define a custom class inside a TORCH_LIBRARY block.
It looks very similar to what you did before.  Instead of

```
static auto m = torch::class_<Class>("Namespace", "Class").def("foo", foo);
```

you write

```
TORCH_LIBRARY(Namespace, m) {
  m.class_<Class>("Class")
    .def("foo", foo);
}
```

All the old usages still work, but at some point we should start
updating the tutorials when we're ready to go 100% live with the
new pybind11 style API.

custom class API previously lived in torch/ folder and in torch
namespace, so for consistency, the new TORCH_LIBRARY also got
moved to torch/library.h The definition of Library::class_ is in the
bottom of that header because I need all of the class_ constructors
available, but there is a circular dependency between the two headers.

Signed-off-by: Edward Z. Yang <ezyang@fb.com>

Differential Revision: [D21089648](https://our.internmc.facebook.com/intern/diff/D21089648)

[ghstack-poisoned]
Now, you can define a custom class inside a TORCH_LIBRARY block.
It looks very similar to what you did before.  Instead of

```
static auto m = torch::class_<Class>("Namespace", "Class").def("foo", foo);
```

you write

```
TORCH_LIBRARY(Namespace, m) {
  m.class_<Class>("Class")
    .def("foo", foo);
}
```

All the old usages still work, but at some point we should start
updating the tutorials when we're ready to go 100% live with the
new pybind11 style API.

custom class API previously lived in torch/ folder and in torch
namespace, so for consistency, the new TORCH_LIBRARY also got
moved to torch/library.h The definition of Library::class_ is in the
bottom of that header because I need all of the class_ constructors
available, but there is a circular dependency between the two headers.

Signed-off-by: Edward Z. Yang <ezyang@fb.com>

Differential Revision: [D21089648](https://our.internmc.facebook.com/intern/diff/D21089648)

[ghstack-poisoned]
ezyang added a commit that referenced this pull request Apr 20, 2020
Now, you can define a custom class inside a TORCH_LIBRARY block.
It looks very similar to what you did before.  Instead of

```
static auto m = torch::class_<Class>("Namespace", "Class").def("foo", foo);
```

you write

```
TORCH_LIBRARY(Namespace, m) {
  m.class_<Class>("Class")
    .def("foo", foo);
}
```

All the old usages still work, but at some point we should start
updating the tutorials when we're ready to go 100% live with the
new pybind11 style API.

custom class API previously lived in torch/ folder and in torch
namespace, so for consistency, the new TORCH_LIBRARY also got
moved to torch/library.h The definition of Library::class_ is in the
bottom of that header because I need all of the class_ constructors
available, but there is a circular dependency between the two headers.

Signed-off-by: Edward Z. Yang <ezyang@fb.com>

ghstack-source-id: 0cfaae8
Pull Request resolved: #36742
@ezyang
Copy link
Copy Markdown
Contributor Author

ezyang commented Apr 20, 2020

@jamesr66a OK, PR is updated so that TORCH_LIBRARY is now next to custom_class.h in torch folder

Now, you can define a custom class inside a TORCH_LIBRARY block.
It looks very similar to what you did before.  Instead of

```
static auto m = torch::class_<Class>("Namespace", "Class").def("foo", foo);
```

you write

```
TORCH_LIBRARY(Namespace, m) {
  m.class_<Class>("Class")
    .def("foo", foo);
}
```

All the old usages still work, but at some point we should start
updating the tutorials when we're ready to go 100% live with the
new pybind11 style API.

custom class API previously lived in torch/ folder and in torch
namespace, so for consistency, the new TORCH_LIBRARY also got
moved to torch/library.h The definition of Library::class_ is in the
bottom of that header because I need all of the class_ constructors
available, but there is a circular dependency between the two headers.

Signed-off-by: Edward Z. Yang <ezyang@fb.com>

Differential Revision: [D21089648](https://our.internmc.facebook.com/intern/diff/D21089648)

[ghstack-poisoned]
Now, you can define a custom class inside a TORCH_LIBRARY block.
It looks very similar to what you did before.  Instead of

```
static auto m = torch::class_<Class>("Namespace", "Class").def("foo", foo);
```

you write

```
TORCH_LIBRARY(Namespace, m) {
  m.class_<Class>("Class")
    .def("foo", foo);
}
```

All the old usages still work, but at some point we should start
updating the tutorials when we're ready to go 100% live with the
new pybind11 style API.

custom class API previously lived in torch/ folder and in torch
namespace, so for consistency, the new TORCH_LIBRARY also got
moved to torch/library.h The definition of Library::class_ is in the
bottom of that header because I need all of the class_ constructors
available, but there is a circular dependency between the two headers.

Signed-off-by: Edward Z. Yang <ezyang@fb.com>

Differential Revision: [D21089648](https://our.internmc.facebook.com/intern/diff/D21089648)

[ghstack-poisoned]
ezyang added a commit to pytorch/xla that referenced this pull request Apr 20, 2020
Companion to pytorch/pytorch#36742

Signed-off-by: Edward Z. Yang <ezyang@fb.com>
Now, you can define a custom class inside a TORCH_LIBRARY block.
It looks very similar to what you did before.  Instead of

```
static auto m = torch::class_<Class>("Namespace", "Class").def("foo", foo);
```

you write

```
TORCH_LIBRARY(Namespace, m) {
  m.class_<Class>("Class")
    .def("foo", foo);
}
```

All the old usages still work, but at some point we should start
updating the tutorials when we're ready to go 100% live with the
new pybind11 style API.

custom class API previously lived in torch/ folder and in torch
namespace, so for consistency, the new TORCH_LIBRARY also got
moved to torch/library.h The definition of Library::class_ is in the
bottom of that header because I need all of the class_ constructors
available, but there is a circular dependency between the two headers.

Signed-off-by: Edward Z. Yang <ezyang@fb.com>

Differential Revision: [D21089648](https://our.internmc.facebook.com/intern/diff/D21089648)

[ghstack-poisoned]
ailzhang pushed a commit to pytorch/xla that referenced this pull request Apr 21, 2020
* Update include path to torch/library.h

Companion to pytorch/pytorch#36742

Signed-off-by: Edward Z. Yang <ezyang@fb.com>

* Delete .torch_pin
@facebook-github-bot
Copy link
Copy Markdown
Contributor

@ezyang merged this pull request in 01100cb.

@jamesr66a
Copy link
Copy Markdown
Collaborator

Reverting due to master-only breakage of pytorch_linux_xenial_py3_clang5_mobile_code_analysis (see https://app.circleci.com/jobs/github/pytorch/pytorch/5207707)

To Run:

Construct your PR as usual. Then, on a diff stacked on top of your PR, make the following modifications:

* Edit .circleci/cimodel/data/pytorch_build_data.py: Find the relevant build definition in CONFIG_TREE_DATA and replace the function call to X with XImportant
* Edit .circleci/scripts/should_run_job.sh: Add “exit 0” to the top of this file
* Run .circleci/regenerate.sh

Push this PR. Your requested job will now run on the PR.

ezyang added a commit that referenced this pull request Apr 21, 2020
…ustom class API"

This reverts commit 2ccdc39.

Original PR: #36742
facebook-github-bot pushed a commit that referenced this pull request Apr 21, 2020
…ustom class API" (#37019)

Summary:
This reverts commit 2ccdc39.

Original PR: #36742
Pull Request resolved: #37019

Differential Revision: D21161361

Pulled By: ezyang

fbshipit-source-id: dca4192d3f7be25a34bbe3d57ddce3afc1c2558c
@facebook-github-bot facebook-github-bot deleted the gh/ezyang/728/head branch April 25, 2020 14:16
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
…6742)

Summary:
Pull Request resolved: pytorch#36742

Now, you can define a custom class inside a TORCH_LIBRARY block.
It looks very similar to what you did before.  Instead of

```
static auto m = torch::class_<Class>("Namespace", "Class").def("foo", foo);
```

you write

```
TORCH_LIBRARY(Namespace, m) {
  m.class_<Class>("Class")
    .def("foo", foo);
}
```

All the old usages still work, but at some point we should start
updating the tutorials when we're ready to go 100% live with the
new pybind11 style API.

custom class API previously lived in torch/ folder and in torch
namespace, so for consistency, the new TORCH_LIBRARY also got
moved to torch/library.h The definition of Library::class_ is in the
bottom of that header because I need all of the class_ constructors
available, but there is a circular dependency between the two headers.

Signed-off-by: Edward Z. Yang <ezyang@fb.com>

Differential Revision: D21089648

Test Plan: Imported from OSS

Pulled By: ezyang

fbshipit-source-id: 8d54329c125242605336c22fa1642aae6940b507
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
…ustom class API" (pytorch#37019)

Summary:
This reverts commit c062dd8.

Original PR: pytorch#36742
Pull Request resolved: pytorch#37019

Differential Revision: D21161361

Pulled By: ezyang

fbshipit-source-id: dca4192d3f7be25a34bbe3d57ddce3afc1c2558c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merged oncall: jit Add this issue/PR to JIT oncall triage queue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants