Skip to content

Conversation

@driazati
Copy link
Contributor

@driazati driazati commented Jun 26, 2019

The error for test_error_stack_module:

Traceback (most recent call last):
  File "../test.py", line 35, in <module>
    scripted = torch.jit.script(M())
  File "/home/davidriazati/other/pytorch/torch/jit/__init__.py", line 1119, in script
    return _convert_to_script_module(obj)
  File "/home/davidriazati/other/pytorch/torch/jit/__init__.py", line 1825, in _convert_to_script_module
    raise e
RuntimeError: 

d(int x) -> int:
Expected a value of type 'int' for argument 'x' but instead found type 'str'.
:
at ../test.py:11:12
def c(x):
    return d("hello") + d(x)
           ~ <--- HERE

'c' is being compiled since it was called from 'b'
at ../test.py:14:12
def b(x):
    return c(x)
           ~~~ <--- HERE

'b' is being compiled since it was called from 'forward'
at ../test.py:22:16
    def forward(self, x):
        return b(x)
               ~~~ <--- HERE

'forward' is being compiled since it was called from 'forward'
at ../test.py:31:20
    def forward(self, x):
        return x + self.submodule(x)
                   ~~~~~~~~~~~~~~~~ <--- HERE

This also unifies our error reporting in the front end with ErrorReport

TODO

Differential Revision: D16060781

@pytorchbot pytorchbot added caffe2 oncall: jit Add this issue/PR to JIT oncall triage queue module: build Build system issues module: internals Related to internal abstractions in c10 and ATen labels Jun 26, 2019
@driazati driazati changed the title [wip][jit] Report errors through call stack [jit] Report errors through call stack Jun 27, 2019
@driazati driazati requested a review from zdevito July 1, 2019 20:03
@pytorchbot pytorchbot added the module: pybind Related to our Python bindings / interactions with other Python libraries label Jul 2, 2019
Copy link
Contributor

@zdevito zdevito left a comment

Choose a reason for hiding this comment

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

Looks pretty good. There is one change in compiler that should be make otherwise I think a lot of potential errors are missed, but that change is pretty easy to make.

return sv->attr(select.range(), method, select.selector().name());
}
case TK_APPLY: {
// Push the source range of a call in case compiling this function
Copy link
Contributor

Choose a reason for hiding this comment

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

TK_APPLY is not the only call that can trigger recursive compilation. There are a ton of them: magic method invocations, method invocations (they won't go through TK_APPLY), various sugared value things that invoke toIValue type things. It is probably not sustainable to be able to find all these places. Can we instead do something like record the current source Range of the Node being emitted for every call to emitStmt and emitSugaredExpr, and then if we end up in a recursive compilation scenario (i.e. there is a call to push_function that occurs later), we can add this source range to the stack.

Copy link
Contributor

Choose a reason for hiding this comment

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

The way it is setup this would be something like set_source_for_current_function, with push_function and pop_function being the only things that adjust the depth of the stack.

test/test_jit.py Outdated
def forward(self, x):
return b(x)


Copy link
Contributor

Choose a reason for hiding this comment

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

We probably want one test for something that gets compiled because of a magic method.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@driazati is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@pytorchbot pytorchbot added the module: cpp Related to C++ API label Jul 8, 2019
zdevito pushed a commit to zdevito/ATen that referenced this pull request Jul 10, 2019
Summary:
The error for `test_error_stack_module`:

```
Traceback (most recent call last):
  File "../test.py", line 35, in <module>
    scripted = torch.jit.script(M())
  File "/home/davidriazati/other/pytorch/torch/jit/__init__.py", line 1119, in script
    return _convert_to_script_module(obj)
  File "/home/davidriazati/other/pytorch/torch/jit/__init__.py", line 1825, in _convert_to_script_module
    raise e
RuntimeError:

d(int x) -> int:
Expected a value of type 'int' for argument 'x' but instead found type 'str'.
:
at ../test.py:11:12
def c(x):
    return d("hello") + d(x)
           ~ <--- HERE

'c' is being compiled since it was called from 'b'
at ../test.py:14:12
def b(x):
    return c(x)
           ~~~ <--- HERE

'b' is being compiled since it was called from 'forward'
at ../test.py:22:16
    def forward(self, x):
        return b(x)
               ~~~ <--- HERE

'forward' is being compiled since it was called from 'forward'
at ../test.py:31:20
    def forward(self, x):
        return x + self.submodule(x)
                   ~~~~~~~~~~~~~~~~ <--- HERE
```

This also unifies our error reporting in the front end with `ErrorReport`

TODO
* Include module names in message, #22207 should make this easy

](https://our.intern.facebook.com/intern/diff/16060781/)
Pull Request resolved: pytorch/pytorch#22280

Pulled By: driazati

Differential Revision: D16060781

fbshipit-source-id: c42968b53aaddb774ac69d5abbf7e60c23df8eed
@facebook-github-bot
Copy link
Contributor

@driazati merged this pull request in 8a233b9.

driazati pushed a commit that referenced this pull request Jul 16, 2019
Following on to #22280, this adds module names so they're included in
the call stacks of an error message (e.g. so it appears as `M.forward`
instead of `forward`)
facebook-github-bot pushed a commit that referenced this pull request Jul 19, 2019
Summary:
Following on to #22280, this adds module names so they're included in
the call stacks of an error message (e.g. so it appears as `M.forward`
instead of `forward`)
](https://our.intern.facebook.com/intern/diff/16287925/)
Pull Request resolved: #22921

Pulled By: driazati

Differential Revision: D16287925

fbshipit-source-id: 6f31d72caa87ba2dc527805d36f7d62eb94c0808
@facebook-github-bot facebook-github-bot deleted the driazati/errorstack branch July 13, 2020 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

caffe2 Merged module: build Build system issues module: cpp Related to C++ API module: internals Related to internal abstractions in c10 and ATen module: pybind Related to our Python bindings / interactions with other Python libraries 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