Skip to content
This repository was archived by the owner on Aug 21, 2025. It is now read-only.

add functionalize index tests#820

Merged
zou3519 merged 2 commits intomainfrom
index_test2
Jul 14, 2022
Merged

add functionalize index tests#820
zou3519 merged 2 commits intomainfrom
index_test2

Conversation

@bdhirsh
Copy link
Contributor

@bdhirsh bdhirsh commented May 19, 2022

There was a bug with JIT container types that caused a problem with List[Optional[Tensor]] arguments, that only actually surfaces in functorch (basically libtorch.so and functorch.so will each get their own static singleton instance of that type). Adding tests for it here.

companion core patch: pytorch/pytorch#77846

@bdhirsh bdhirsh requested a review from zou3519 May 19, 2022 14:31
bdhirsh added a commit to pytorch/pytorch that referenced this pull request May 19, 2022
…ton bug"

This should fix the remaining dynamo <> functionalization integration issue.


I had a fix earlier for JIT containers not correctly having singleton instances [here](#76085), which fixed a bug in this code for functionalization:
```
def f(a, b):
    return a[b]

functionalize(foo)(torch.arange(3), torch.ones(2, dtype=torch.long))
```

But apparently the following code is still broken:
```
def f(a, b):
    return torch.ops.aten.index(a, b)

functionalize(foo)(torch.arange(3), torch.ones(2, dtype=torch.long))
```

Why? we have separate schema parsing logic for the ops in `torch.ops.aten`, and that logic circumvented my fix, creating its own singleton instance for Optional[Tensor].


We can't test this in core for the same reason as the last fix, so companion functorch tests here: pytorch/functorch#820




[ghstack-poisoned]
bdhirsh added a commit to pytorch/pytorch that referenced this pull request May 19, 2022
This should fix the remaining dynamo <> functionalization integration issue.


I had a fix earlier for JIT containers not correctly having singleton instances [here](#76085), which fixed a bug in this code for functionalization:
```
def f(a, b):
    return a[b]

functionalize(foo)(torch.arange(3), torch.ones(2, dtype=torch.long))
```

But apparently the following code is still broken:
```
def f(a, b):
    return torch.ops.aten.index(a, b)

functionalize(foo)(torch.arange(3), torch.ones(2, dtype=torch.long))
```

Why? we have separate schema parsing logic for the ops in `torch.ops.aten`, and that logic circumvented my fix, creating its own singleton instance for Optional[Tensor].


We can't test this in core for the same reason as the last fix, so companion functorch tests here: pytorch/functorch#820




[ghstack-poisoned]
Copy link
Contributor

@zou3519 zou3519 left a comment

Choose a reason for hiding this comment

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

LGTM

@zou3519
Copy link
Contributor

zou3519 commented May 20, 2022

(should give this a rebase before merge to check the test passes when the change makes it into pytorch/pytorch. Yay co-development)

@zou3519
Copy link
Contributor

zou3519 commented Jul 14, 2022

Rebased; will merge on green

@zou3519 zou3519 merged commit 1ae03b3 into main Jul 14, 2022
@zou3519 zou3519 deleted the index_test2 branch July 14, 2022 18:36
zou3519 added a commit to zou3519/pytorch that referenced this pull request Jul 20, 2022
* add functionalize index tests

* Update expecttest

Co-authored-by: Richard Zou <zou3519@gmail.com>
bigfootjon pushed a commit to pytorch/pytorch that referenced this pull request Jul 21, 2022
* add functionalize index tests

* Update expecttest

Co-authored-by: Richard Zou <zou3519@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants