Commit Graph

162 Commits

Author SHA1 Message Date
da6c3c90d9 Relax constraints on return statements in the script (#6070)
Script functions can now have no return statements, empty
return statements, or return one or more values.

Additionally fix the lexer to always emit TK_NEWLINE before
TK_DEDENT, which simplifies the parser.
2018-03-31 18:35:33 +02:00
1807bacd65 Fix printing of unknown binop operator in torchscript (#6069)
Before, using an unknown binary operator like `@`:
```
import torch
@torch.jit.script
def mm(x, y):
    return x @ y

x = torch.randn(4, 3)
y = torch.randn(3, 2)
mm(x, y)
```
resulted in [this not-so-readable trace](https://gist.github.com/zou3519/052b8998108c4bc0fe0e7c85c6f5758e).

Now, it tells the user that the problem is an unknown binary operator:
```
NotSupportedError: unsupported binary operator: MatMult
@torch.jit.script
def mm(x, y):
    return x @ y
            ~~~ <--- HERE
```
2018-03-28 19:41:45 +02:00
213fa61706 Implement range for loop in script (#5827)
* Implement range for loop in script

* Fix handling of boolean constants

* Use WithInsertPoint

* Allow dynamic max trip count

* fix symbols

* Fix argument order

* fix test

* Add insert{Input,Output} APIs and use them

* Factor out condition stuff

* clang-format

* Address remaining comments

* Fix tests

* Implement script in AST frontend
2018-03-23 11:55:32 -04:00
418aad2c54 Add support for subscripts in Python frontend (#5890) 2018-03-22 01:11:25 -04:00
e6ac93b817 Add support for number and list literals in Python frontend (#5843) 2018-03-17 10:22:23 -04:00
694bee1f7e Fix the rule for Assign in JIT's Python frontend (#5793) 2018-03-15 09:14:03 +01:00
41285edbb6 [jit] add a compiled script module (#5630)
Add script::Module C++ class to represent script modules
switch AST -> IR conversion to work on Modules/Methods rather than raw graphs
function-only AST -> IR conversion is just a simplified case where there is
only one module with a single method and no parameters.
introduce SugaredValue in compiler.h to represent values in scope in a script
function that are not first-class and that get desugared. This is used to
represent the module's self parameter, as well as python function calls,
and method calls on tensor
provide a Python ScriptModule that provides a nice API on top of script::Module
allowing for the definition of script modules with methods, parameters,
and submodules
Not in this PR but intended for the future:

ScriptModule actually subclasses nn.Module, with most methods implemented
Unification of tracedmodule and script module functionality into one container class.

Detailed changelog:

* Switch compiler over to using Module, but don't
use them yet.

* Remove intermediate attribute encoding in compiler

* Create SugaredValue object to handle resolution
of compiled module.

* switch to_ir to modules, implement Select

* hacky python wrappers

* Private ScriptModule

* Add `define` to script module

* Attributes use TK_LIST_LITERAL

this anticipates adding a real list literal expression to the language.

* Add a metaclass to make sure script stubs are registered

* Add a test

* Doc createResolutionCallback

* Docs and minor editing

* Address PR comments

* Document

* Fix unicode issue
2018-03-12 09:52:40 -04:00
e4c303f373 Defer shape analysis failures until runtime (#5574) 2018-03-09 18:43:03 +01:00
5597aba868 Add return statement to the JIT AST (#5578) 2018-03-06 13:14:53 +01:00
a0118533ef Add a print() function to the JIT script (#5274)
Additionally:
- add support for calling functions that are not methods in the Python frontend
- add an end-to-end test for the Python frontend
- add a capture_stdout helper for checking that `print` actually works
2018-02-24 11:15:55 +01:00
c2a3d85a07 Traverse sub-blocks in JIT passes (#5329)
* Traverse sub-blocks in JIT passes

* Add an extra check to prevent cross-block fusion
2018-02-22 17:32:31 -08:00
cb2fd39fdd Add Python frontend to the JIT (#5190) 2018-02-15 22:53:19 +01:00