Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ONNX] handle aten::_set_item on Dict in convertInplaceOpsAndTrackAlias #58317

Merged
merged 1 commit into from
May 19, 2021

Conversation

garymm
Copy link
Collaborator

@garymm garymm commented May 14, 2021

It seems the JIT produces an output for aten::_set_item on lists but
not on dicts. Previously the code would crash because it assumed it
was operating on a list.

The different behavior can be seen with the following test:

class DictModule(torch.nn.Module):
    def forward(self, x_in: torch.Tensor) -> typing.Dict[str, torch.Tensor]:
        x_out = {}
        x_out["test_key_out"] = x_in
        return x_out
    
x_in = torch.tensor(1)
dms = torch.jit.script(DictModule())
torch.onnx.export(dms, (x_in,), "/dev/null", example_outputs=(dms(x_in),))

Before this change:
RuntimeError: outputs_.size() == 1INTERNAL ASSERT FAILED at "../torch/csrc/jit/ir/ir.h":452, please report a bug to PyTorch.

After this change:
RuntimeError: Exporting the operator prim_DictConstruct to ONNX opset version 9 is not supported. Please feel free to request support or submit a pull request on PyTorch GitHub.

This is a more useful error message.

@facebook-github-bot
Copy link
Contributor

facebook-github-bot commented May 14, 2021

💊 CI failures summary and remediations

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


  • 1/1 failures introduced in this PR

🕵️ 1 new failure recognized by patterns

The following CI failures do not appear to be due to upstream breakages:

See CircleCI build pytorch_xla_linux_bionic_py3_6_clang9_build (1/1)

Step: "Build" (full log | diagnosis details | 🔁 rerun)

May 18 21:47:06 AssertionError: Found an invalid operator name: _copy_from_and_resize
May 18 21:47:06   File "/opt/conda/lib/python3.6/runpy.py", line 193, in _run_module_as_main
May 18 21:47:06     "__main__", mod_spec)
May 18 21:47:06   File "/opt/conda/lib/python3.6/runpy.py", line 85, in _run_code
May 18 21:47:06     exec(code, run_globals)
May 18 21:47:06   File "/var/lib/jenkins/workspace/tools/codegen/gen_backend_stubs.py", line 126, in <module>
May 18 21:47:06     main()
May 18 21:47:06   File "/var/lib/jenkins/workspace/tools/codegen/gen_backend_stubs.py", line 87, in main
May 18 21:47:06     cpp_namespace, external_backend_functions = parse_backend_yaml(options.source_yaml, grouped_native_functions)
May 18 21:47:06   File "/var/lib/jenkins/workspace/tools/codegen/gen_backend_stubs.py", line 61, in parse_backend_yaml
May 18 21:47:06     raise AssertionError(f"Found an invalid operator name: {op_name}")
May 18 21:47:06 AssertionError: Found an invalid operator name: _copy_from_and_resize
May 18 21:47:06 ~/workspace/xla
May 18 21:47:06 + OPTS=()
May 18 21:47:06 + getopts O: OPTION
May 18 21:47:06 + case $OPTION in
May 18 21:47:06 + for i in ${OPTARG}
May 18 21:47:06 + OPTS+=("--cxxopt=${i}")
May 18 21:47:06 + getopts O: OPTION
May 18 21:47:06 + shift 2
May 18 21:47:06 + CMD=install
May 18 21:47:06 ++ dirname /var/lib/jenkins/workspace/xla/build_torch_xla_libs.sh

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

Click here to manually regenerate this comment.

@facebook-github-bot facebook-github-bot added the oncall: jit Add this issue/PR to JIT oncall triage queue label May 14, 2021
@BowenBao
Copy link
Collaborator

Thanks for the fix! PR looks good, could you include the test case in the description in unit test as well, with assertRaises?

@garymm
Copy link
Collaborator Author

garymm commented May 18, 2021

Thanks for the fix! PR looks good, could you include the test case in the description in unit test as well, with assertRaises?

Good idea. Done!
BTW, Is there a way that we can more easily differentiate between assertion failures in the JIT and unsupported operations? Perhaps with a different exception type?

@BowenBao
Copy link
Collaborator

@garymm That would be a great idea, i think currently we don't have a specialized exception type for onnx export. It'd be interesting to see how to use a same exception type across C++ and Python code, maybe need to touch torch/csrc/Exceptions.h and make sure it works with pybind.
Another point I see in this example is that there are cases of assertion errors that were actually caused by unsupported operations, yet it failed early at assertions before reaching the place to print a more meaningful error. I guess we need to be more careful about what we assume when writing passes.

@garymm
Copy link
Collaborator Author

garymm commented May 18, 2021

Filed https://msdata.visualstudio.com/Vienna/_workitems/edit/1185416/.

Please take another look at this PR and approve and merge if ready.

Thanks!

It seems the JIT produces an output for aten::_set_item on lists but
not on dicts. Previously the code would crash because it assumed it
was operating on a list.

The different behavior can be seen with the following test:

class DictModule(torch.nn.Module):
    def forward(self, x_in: torch.Tensor) -> typing.Dict[str, torch.Tensor]:
        x_out = {}
        x_out["test_key_out"] = x_in
        return x_out

x_in = torch.tensor(1)
dms = torch.jit.script(DictModule())
torch.onnx.export(dms, (x_in,), "/dev/null", example_outputs=(dms(x_in),))

Before this change:
RuntimeError: outputs_.size() == 1INTERNAL ASSERT FAILED at "../torch/csrc/jit/ir/ir.h":452, please report a bug to PyTorch.

After this change:
RuntimeError: Exporting the operator prim_DictConstruct to ONNX opset version 9 is not supported. Please feel free to request support or submit a pull request on PyTorch GitHub.

This is a more useful error message.
@BowenBao BowenBao merged commit d2f2a03 into pytorch:onnx_ms_1 May 19, 2021
@garymm garymm deleted the set-item branch May 19, 2021 16:40
BowenBao pushed a commit that referenced this pull request May 19, 2021
…as (#58317)

It seems the JIT produces an output for aten::_set_item on lists but
not on dicts. Previously the code would crash because it assumed it
was operating on a list.

The different behavior can be seen with the following test:

```python
class DictModule(torch.nn.Module):
    def forward(self, x_in: torch.Tensor) -> typing.Dict[str, torch.Tensor]:
        x_out = {}
        x_out["test_key_out"] = x_in
        return x_out

x_in = torch.tensor(1)
dms = torch.jit.script(DictModule())
torch.onnx.export(dms, (x_in,), "/dev/null", example_outputs=(dms(x_in),))
```

Before this change:
`RuntimeError: outputs_.size() == 1INTERNAL ASSERT FAILED at "../torch/csrc/jit/ir/ir.h":452, please report a bug to PyTorch.`

After this change:
`RuntimeError: Exporting the operator prim_DictConstruct to ONNX opset version 9 is not supported. Please feel free to request support or submit a pull request on PyTorch GitHub.`

This is a more useful error message.

Co-authored-by: Gary Miguel <garymiguel@microsoft.com>

[ghstack-poisoned]
BowenBao pushed a commit that referenced this pull request May 19, 2021
…as (#58317)

It seems the JIT produces an output for aten::_set_item on lists but
not on dicts. Previously the code would crash because it assumed it
was operating on a list.
    
The different behavior can be seen with the following test:

```python
class DictModule(torch.nn.Module):
    def forward(self, x_in: torch.Tensor) -> typing.Dict[str, torch.Tensor]:
        x_out = {}
        x_out["test_key_out"] = x_in
        return x_out
    
x_in = torch.tensor(1)
dms = torch.jit.script(DictModule())
torch.onnx.export(dms, (x_in,), "/dev/null", example_outputs=(dms(x_in),))
```

Before this change:
`RuntimeError: outputs_.size() == 1INTERNAL ASSERT FAILED at "../torch/csrc/jit/ir/ir.h":452, please report a bug to PyTorch.`
    
After this change:
`RuntimeError: Exporting the operator prim_DictConstruct to ONNX opset version 9 is not supported. Please feel free to request support or submit a pull request on PyTorch GitHub.`
    
This is a more useful error message.

Co-authored-by: Gary Miguel <garymiguel@microsoft.com>
BowenBao pushed a commit that referenced this pull request May 20, 2021
…as (#58317)

It seems the JIT produces an output for aten::_set_item on lists but
not on dicts. Previously the code would crash because it assumed it
was operating on a list.

The different behavior can be seen with the following test:

```python
class DictModule(torch.nn.Module):
    def forward(self, x_in: torch.Tensor) -> typing.Dict[str, torch.Tensor]:
        x_out = {}
        x_out["test_key_out"] = x_in
        return x_out

x_in = torch.tensor(1)
dms = torch.jit.script(DictModule())
torch.onnx.export(dms, (x_in,), "/dev/null", example_outputs=(dms(x_in),))
```

Before this change:
`RuntimeError: outputs_.size() == 1INTERNAL ASSERT FAILED at "../torch/csrc/jit/ir/ir.h":452, please report a bug to PyTorch.`

After this change:
`RuntimeError: Exporting the operator prim_DictConstruct to ONNX opset version 9 is not supported. Please feel free to request support or submit a pull request on PyTorch GitHub.`

This is a more useful error message.

Co-authored-by: Gary Miguel <garymiguel@microsoft.com>

[ghstack-poisoned]
BowenBao added a commit that referenced this pull request May 20, 2021
…AndTrackAlias (#58317)"

It seems the JIT produces an output for aten::_set_item on lists but
not on dicts. Previously the code would crash because it assumed it
was operating on a list.

The different behavior can be seen with the following test:

```python
class DictModule(torch.nn.Module):
    def forward(self, x_in: torch.Tensor) -> typing.Dict[str, torch.Tensor]:
        x_out = {}
        x_out["test_key_out"] = x_in
        return x_out

x_in = torch.tensor(1)
dms = torch.jit.script(DictModule())
torch.onnx.export(dms, (x_in,), "/dev/null", example_outputs=(dms(x_in),))
```

Before this change:
`RuntimeError: outputs_.size() == 1INTERNAL ASSERT FAILED at "../torch/csrc/jit/ir/ir.h":452, please report a bug to PyTorch.`

After this change:
`RuntimeError: Exporting the operator prim_DictConstruct to ONNX opset version 9 is not supported. Please feel free to request support or submit a pull request on PyTorch GitHub.`

This is a more useful error message.

Co-authored-by: Gary Miguel <garymiguel@microsoft.com>

[ghstack-poisoned]
BowenBao added a commit that referenced this pull request May 26, 2021
…AndTrackAlias (#58317)"


It seems the JIT produces an output for aten::_set_item on lists but
not on dicts. Previously the code would crash because it assumed it
was operating on a list.

The different behavior can be seen with the following test:

```python
class DictModule(torch.nn.Module):
    def forward(self, x_in: torch.Tensor) -> typing.Dict[str, torch.Tensor]:
        x_out = {}
        x_out["test_key_out"] = x_in
        return x_out

x_in = torch.tensor(1)
dms = torch.jit.script(DictModule())
torch.onnx.export(dms, (x_in,), "/dev/null", example_outputs=(dms(x_in),))
```

Before this change:
`RuntimeError: outputs_.size() == 1INTERNAL ASSERT FAILED at "../torch/csrc/jit/ir/ir.h":452, please report a bug to PyTorch.`

After this change:
`RuntimeError: Exporting the operator prim_DictConstruct to ONNX opset version 9 is not supported. Please feel free to request support or submit a pull request on PyTorch GitHub.`

This is a more useful error message.

Co-authored-by: Gary Miguel <garymiguel@microsoft.com>

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

[ghstack-poisoned]
facebook-github-bot pushed a commit that referenced this pull request May 27, 2021
…as (#58317) (#58696)

Summary:
Pull Request resolved: #58696

It seems the JIT produces an output for aten::_set_item on lists but
not on dicts. Previously the code would crash because it assumed it
was operating on a list.

The different behavior can be seen with the following test:

```python
class DictModule(torch.nn.Module):
    def forward(self, x_in: torch.Tensor) -> typing.Dict[str, torch.Tensor]:
        x_out = {}
        x_out["test_key_out"] = x_in
        return x_out

x_in = torch.tensor(1)
dms = torch.jit.script(DictModule())
torch.onnx.export(dms, (x_in,), "/dev/null", example_outputs=(dms(x_in),))
```

Before this change:
`RuntimeError: outputs_.size() == 1INTERNAL ASSERT FAILED at "../torch/csrc/jit/ir/ir.h":452, please report a bug to PyTorch.`

After this change:
`RuntimeError: Exporting the operator prim_DictConstruct to ONNX opset version 9 is not supported. Please feel free to request support or submit a pull request on PyTorch GitHub.`

This is a more useful error message.

Test Plan: Imported from OSS

Reviewed By: driazati

Differential Revision: D28714804

Pulled By: SplitInfinity

fbshipit-source-id: 1e5dc5fb44d1e3f971a22a79b5cf009d7590bf84

Co-authored-by: Gary Miguel <garymiguel@microsoft.com>
deniskokarev pushed a commit to deniskokarev/pytorch that referenced this pull request Jun 9, 2021
…as (pytorch#58317) (pytorch#58696)

Summary:
Pull Request resolved: pytorch#58696

It seems the JIT produces an output for aten::_set_item on lists but
not on dicts. Previously the code would crash because it assumed it
was operating on a list.

The different behavior can be seen with the following test:

```python
class DictModule(torch.nn.Module):
    def forward(self, x_in: torch.Tensor) -> typing.Dict[str, torch.Tensor]:
        x_out = {}
        x_out["test_key_out"] = x_in
        return x_out

x_in = torch.tensor(1)
dms = torch.jit.script(DictModule())
torch.onnx.export(dms, (x_in,), "/dev/null", example_outputs=(dms(x_in),))
```

Before this change:
`RuntimeError: outputs_.size() == 1INTERNAL ASSERT FAILED at "../torch/csrc/jit/ir/ir.h":452, please report a bug to PyTorch.`

After this change:
`RuntimeError: Exporting the operator prim_DictConstruct to ONNX opset version 9 is not supported. Please feel free to request support or submit a pull request on PyTorch GitHub.`

This is a more useful error message.

Test Plan: Imported from OSS

Reviewed By: driazati

Differential Revision: D28714804

Pulled By: SplitInfinity

fbshipit-source-id: 1e5dc5fb44d1e3f971a22a79b5cf009d7590bf84

Co-authored-by: Gary Miguel <garymiguel@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla signed oncall: jit Add this issue/PR to JIT oncall triage queue open source
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants