Skip to content

vmap: temporarily disable support for (most) random functions - #42324

Closed
zou3519 wants to merge 4 commits into
gh/zou3519/276/basefrom
gh/zou3519/276/head
Closed

zou3519 wants to merge 4 commits into
gh/zou3519/276/basefrom
gh/zou3519/276/head

Conversation

@zou3519

@zou3519 zou3519 commented Jul 30, 2020 •

Copy link
Copy Markdown
Contributor

Stack from ghstack:

While we figure out the random plan, I want to initially disable
support for random operations. This is because there is an ambiguity in
what randomness means. For example,

tensor = torch.zeros(B0, 1)
vmap(lambda t: t.normal_())(tensor)

in the above example, should tensor[0] and tensor[1] be equal (i.e.,
use the same random seed), or should they be different?

The mechanism for disabling random support is as follows:

  • we register a batching rule that throws an error
  • for any future (out-of-place) random operations, the fallback path
    will probably catch them and throw an error.

I want to disable random factory functions as well, but I haven't
figured out how to do that yet. (e.g., torch.rand, torch.randn). That
will come next.

Test Plan:

  • pytest test/test_vmap.py -v -k "Operators"

Differential Revision: D22846274

While we figure out the random plan, I want to initially disable
support for random operations. This is because there is an ambiguity in
what randomness means. For example,
```
tensor = torch.zeros(B0, 1)
vmap(lambda t: t.normal_())(tensor)
```
in the above example, should `tensor[0]` and `tensor[1]` be equal (i.e.,
use the same random seed), or should they be different?

The mechanism for disabling random support is as follows:
- we register a batching rule that throws an error
- for any future (out-of-place) random operations, the fallback path
will probably catch them and throw an error.

I want to disable random factory functions as well, but I haven't
figured out how to do that yet. (e.g., torch.rand, torch.randn). That
will come next.

Test Plan:
- `pytest test/test_vmap.py -v -k "Operators"`

[ghstack-poisoned]
zou3519 added a commit that referenced this pull request Jul 30, 2020
While we figure out the random plan, I want to initially disable
support for random operations. This is because there is an ambiguity in
what randomness means. For example,
```
tensor = torch.zeros(B0, 1)
vmap(lambda t: t.normal_())(tensor)
```
in the above example, should `tensor[0]` and `tensor[1]` be equal (i.e.,
use the same random seed), or should they be different?

The mechanism for disabling random support is as follows:
- we register a batching rule that throws an error
- for any future (out-of-place) random operations, the fallback path
will probably catch them and throw an error.

I want to disable random factory functions as well, but I haven't
figured out how to do that yet. (e.g., torch.rand, torch.randn). That
will come next.

Test Plan:
- `pytest test/test_vmap.py -v -k "Operators"`

ghstack-source-id: 5867be5
Pull Request resolved: #42324
@zou3519
zou3519 requested review from cpuhrsch and ezyang July 30, 2020 18:38
schema.arguments().begin(),
schema.arguments().end(),
[] (const Argument& arg) {
// Check for Generator or Optional<Generator>.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If someone ever adds list of generators I will eat my shoe.

template <typename... Args> Tensor& unsupportedRandomOp_(Args... args) {
TORCH_CHECK(false, "vmap: We do not yet support random operations. Please ",
"perform random operations outside of vmap as a workaround");
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You could do this with marginally less boilerplate by making another magical unsupported boxed kernel, similar to the named tensor not supported kernel. Then it wouldn't be necessary to get the correct type instantiations below. Up to you.

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'll add that as a follow-up item to investigate. Getting the correct type instantiations is annoying (and potentially fragile if someone updates the schema) so the magical unsupported kernel sounds nice.

Comment thread test/test_vmap.py
B0 = 2
random_ops = [
# out-of-place
(torch.bernoulli, (torch.rand(B0, 1),)),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@mruberry Op DB!!!

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.

an op database would indeed solve a lot of my testing problems

…ons"

While we figure out the random plan, I want to initially disable
support for random operations. This is because there is an ambiguity in
what randomness means. For example,
```
tensor = torch.zeros(B0, 1)
vmap(lambda t: t.normal_())(tensor)
```
in the above example, should `tensor[0]` and `tensor[1]` be equal (i.e.,
use the same random seed), or should they be different?

The mechanism for disabling random support is as follows:
- we register a batching rule that throws an error
- for any future (out-of-place) random operations, the fallback path
will probably catch them and throw an error.

I want to disable random factory functions as well, but I haven't
figured out how to do that yet. (e.g., torch.rand, torch.randn). That
will come next.

Test Plan:
- `pytest test/test_vmap.py -v -k "Operators"`

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

[ghstack-poisoned]
zou3519 added a commit that referenced this pull request Jul 31, 2020
While we figure out the random plan, I want to initially disable
support for random operations. This is because there is an ambiguity in
what randomness means. For example,
```
tensor = torch.zeros(B0, 1)
vmap(lambda t: t.normal_())(tensor)
```
in the above example, should `tensor[0]` and `tensor[1]` be equal (i.e.,
use the same random seed), or should they be different?

The mechanism for disabling random support is as follows:
- we register a batching rule that throws an error
- for any future (out-of-place) random operations, the fallback path
will probably catch them and throw an error.

I want to disable random factory functions as well, but I haven't
figured out how to do that yet. (e.g., torch.rand, torch.randn). That
will come next.

Test Plan:
- `pytest test/test_vmap.py -v -k "Operators"`

ghstack-source-id: 3bf24d9
Pull Request resolved: #42324
…ons"

While we figure out the random plan, I want to initially disable
support for random operations. This is because there is an ambiguity in
what randomness means. For example,
```
tensor = torch.zeros(B0, 1)
vmap(lambda t: t.normal_())(tensor)
```
in the above example, should `tensor[0]` and `tensor[1]` be equal (i.e.,
use the same random seed), or should they be different?

The mechanism for disabling random support is as follows:
- we register a batching rule that throws an error
- for any future (out-of-place) random operations, the fallback path
will probably catch them and throw an error.

I want to disable random factory functions as well, but I haven't
figured out how to do that yet. (e.g., torch.rand, torch.randn). That
will come next.

Test Plan:
- `pytest test/test_vmap.py -v -k "Operators"`

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

[ghstack-poisoned]
…ons"

While we figure out the random plan, I want to initially disable
support for random operations. This is because there is an ambiguity in
what randomness means. For example,
```
tensor = torch.zeros(B0, 1)
vmap(lambda t: t.normal_())(tensor)
```
in the above example, should `tensor[0]` and `tensor[1]` be equal (i.e.,
use the same random seed), or should they be different?

The mechanism for disabling random support is as follows:
- we register a batching rule that throws an error
- for any future (out-of-place) random operations, the fallback path
will probably catch them and throw an error.

I want to disable random factory functions as well, but I haven't
figured out how to do that yet. (e.g., torch.rand, torch.randn). That
will come next.

Test Plan:
- `pytest test/test_vmap.py -v -k "Operators"`

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

[ghstack-poisoned]
zou3519 added a commit that referenced this pull request Jul 31, 2020
While we figure out the random plan, I want to initially disable
support for random operations. This is because there is an ambiguity in
what randomness means. For example,
```
tensor = torch.zeros(B0, 1)
vmap(lambda t: t.normal_())(tensor)
```
in the above example, should `tensor[0]` and `tensor[1]` be equal (i.e.,
use the same random seed), or should they be different?

The mechanism for disabling random support is as follows:
- we register a batching rule that throws an error
- for any future (out-of-place) random operations, the fallback path
will probably catch them and throw an error.

I want to disable random factory functions as well, but I haven't
figured out how to do that yet. (e.g., torch.rand, torch.randn). That
will come next.

Test Plan:
- `pytest test/test_vmap.py -v -k "Operators"`

ghstack-source-id: 1f3bebd
Pull Request resolved: #42324
@zou3519

zou3519 commented Aug 3, 2020

Copy link
Copy Markdown
Contributor Author

I'm going to hold off on landing this until I figure out #42324 (comment). There's a case where this PR doesn't cover and a dispatcher-approach would (we also want to ban random operations for regular tensors (non-BatchedTensors) inside vmap!)

@zou3519

zou3519 commented Aug 5, 2020

Copy link
Copy Markdown
Contributor Author

#42617 supercedes this.

@zou3519 zou3519 closed this Aug 5, 2020
@facebook-github-bot
facebook-github-bot deleted the gh/zou3519/276/head branch September 5, 2020 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants