Skip to content

Conversation

zou3519
Copy link
Contributor

@zou3519 zou3519 commented Aug 5, 2020

Stack from ghstack:

This PR extends the BatchedTensor fallback to support operators with
multiple Tensor returns. If an operator has multiple returns, we stack
shards of each return to create the full outputs.

For example, let's consider

tensor = torch.randn(B0, 10)
vmap(torch.var_mean)(torch.randn(B0, 10))

torch.var_mean returns two Tensors. The fallback path essentially does
the following:

  • for each batch i, let ai, bi = torch.var_mean(tensor[i])
  • return torch.stack([a0, a1, ..., a{B0}]), torch.stack([b0, b1, ..., b{B0}])

Test Plan:

  • pytest test/test_vmap.py -v. Added a new test for an operator with
    multiple returns (torch.var_mean).

Differential Revision: D22957095

…returns

This PR extends the BatchedTensor fallback to support operators with
multiple Tensor returns. If an operator has multiple returns, we stack
shards of each return to create the full outputs.

Test Plan:
- `pytest test/test_vmap.py -v`. Added a new test for an operator with
multiple returns (torch.var_mean).

[ghstack-poisoned]
…ple Tensor returns"

This PR extends the BatchedTensor fallback to support operators with
multiple Tensor returns. If an operator has multiple returns, we stack
shards of each return to create the full outputs.

For example, let's consider
```
tensor = torch.randn(B0, 10)
vmap(torch.var_mean)(torch.randn(B0, 10))
```
`torch.var_mean` returns two Tensors. The fallback path essentially does
the following:
- for each batch i, let ai, bi = torch.var_mean(tensor[i])
- return torch.stack([a0, a1, ..., a{B0}]), torch.stack([b0, b1, ..., b{B0}])

Test Plan:
- `pytest test/test_vmap.py -v`. Added a new test for an operator with
multiple returns (torch.var_mean).

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

[ghstack-poisoned]
zou3519 added a commit that referenced this pull request Aug 5, 2020
…returns

This PR extends the BatchedTensor fallback to support operators with
multiple Tensor returns. If an operator has multiple returns, we stack
shards of each return to create the full outputs.

For example, let's consider
```
tensor = torch.randn(B0, 10)
vmap(torch.var_mean)(torch.randn(B0, 10))
```
`torch.var_mean` returns two Tensors. The fallback path essentially does
the following:
- for each batch i, let ai, bi = torch.var_mean(tensor[i])
- return torch.stack([a0, a1, ..., a{B0}]), torch.stack([b0, b1, ..., b{B0}])

Test Plan:
- `pytest test/test_vmap.py -v`. Added a new test for an operator with
multiple returns (torch.var_mean).

ghstack-source-id: 729597c
Pull Request resolved: #42628
@dr-ci
Copy link

dr-ci bot commented Aug 5, 2020

💊 CI failures summary and remediations

As of commit 9529b4e (more details on the Dr. CI page):


  • 1/1 failures possibly* introduced in this PR
    • 1/1 non-CircleCI failure(s)

ci.pytorch.org: 1 failed


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 or post in the (internal) Dr. CI Users group.

See how this bot performed.

This comment has been revised 11 times.

TORCH_CHECK(num_returns >= 1,
"Batching rule not implemented for ", schema, ". ",
"We do not yet support operations with multiple returns.");
"We do not support operations with no returns.");
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't this be easy to support lol

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this isn't hard to support. However it implies the operation does nothing (since it would have to have no returns and no alias annotations). I'll clarify that this means that the fallback doesn't support that

// [ a0, a1, a2, a3, b0, b1, b2, b3, c0, c1, c2, c3]
// This is so that we can call at::stack([a0...a3]), at::stack([b0...b3])
// more easily in the next step.
std::vector<Tensor> output_shards(num_batches * num_returns);
Copy link
Contributor

Choose a reason for hiding this comment

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

MatrixRef may be of interest here!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed the indexing code to use MatrixRef! It's a nice way to abstract that behavior, thanks for pointing it out

…ple Tensor returns"

This PR extends the BatchedTensor fallback to support operators with
multiple Tensor returns. If an operator has multiple returns, we stack
shards of each return to create the full outputs.

For example, let's consider
```
tensor = torch.randn(B0, 10)
vmap(torch.var_mean)(torch.randn(B0, 10))
```
`torch.var_mean` returns two Tensors. The fallback path essentially does
the following:
- for each batch i, let ai, bi = torch.var_mean(tensor[i])
- return torch.stack([a0, a1, ..., a{B0}]), torch.stack([b0, b1, ..., b{B0}])

Test Plan:
- `pytest test/test_vmap.py -v`. Added a new test for an operator with
multiple returns (torch.var_mean).

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

[ghstack-poisoned]
…ple Tensor returns"

This PR extends the BatchedTensor fallback to support operators with
multiple Tensor returns. If an operator has multiple returns, we stack
shards of each return to create the full outputs.

For example, let's consider
```
tensor = torch.randn(B0, 10)
vmap(torch.var_mean)(torch.randn(B0, 10))
```
`torch.var_mean` returns two Tensors. The fallback path essentially does
the following:
- for each batch i, let ai, bi = torch.var_mean(tensor[i])
- return torch.stack([a0, a1, ..., a{B0}]), torch.stack([b0, b1, ..., b{B0}])

Test Plan:
- `pytest test/test_vmap.py -v`. Added a new test for an operator with
multiple returns (torch.var_mean).

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

[ghstack-poisoned]
…ple Tensor returns"

This PR extends the BatchedTensor fallback to support operators with
multiple Tensor returns. If an operator has multiple returns, we stack
shards of each return to create the full outputs.

For example, let's consider
```
tensor = torch.randn(B0, 10)
vmap(torch.var_mean)(torch.randn(B0, 10))
```
`torch.var_mean` returns two Tensors. The fallback path essentially does
the following:
- for each batch i, let ai, bi = torch.var_mean(tensor[i])
- return torch.stack([a0, a1, ..., a{B0}]), torch.stack([b0, b1, ..., b{B0}])

Test Plan:
- `pytest test/test_vmap.py -v`. Added a new test for an operator with
multiple returns (torch.var_mean).

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

[ghstack-poisoned]
@facebook-github-bot
Copy link
Contributor

@zou3519 merged this pull request in 8f67c7a.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants