Commit Graph

240 Commits

Author SHA1 Message Date
c158848abe class_table_ to deps_table_ (#24281)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/24281

These are not just classes anymore, rename

Test Plan: Imported from OSS

Differential Revision: D16800564

Pulled By: suo

fbshipit-source-id: 8b8d508944c26a8916fc7642df43f22583dfcf82
2019-08-14 11:26:22 -07:00
f36c3e9e4a Revert D16684391: [jit] class_table_ to deps_table_
Differential Revision:
D16684391

Original commit changeset: af0024c0b7fb

fbshipit-source-id: c9b98ac60b460963dc50f4837100909ff8f6c3ea
2019-08-13 13:27:03 -07:00
94aae71ba9 Revert D16684390: [jit] clean up import_source
Differential Revision:
D16684390

Original commit changeset: fca81ca14d1a

fbshipit-source-id: eb229097560ab1ead43756175e552764c8a14703
2019-08-13 13:26:59 -07:00
c2549cb8d3 Remove DimensionedTensorType (#24077)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/24077

This replaces all uses of DimensionedTensorType with ProfiledTensorType.
For places where we propagate shape information, we still follow the
dimension-only propagation rules, meaning that even if full size information
is known on inputs the outputs will only have dimension information.

This fixes several bugs in existing implentations that this change uncovered:
* requires_grad was not propgated correctly across loops
* requires_grad on ProfiledTensorType returned false when requires_grad information
  is unknown but the conservative result is true
* some equality code on ProfiledTensorType contained bugs.

Test Plan: Imported from OSS

Reviewed By: suo

Differential Revision: D16729581

Pulled By: zdevito

fbshipit-source-id: bd9f823c1c6b1d06a236a1b5b2b2fcdf0245edce
2019-08-13 10:05:47 -07:00
bb4f4e4d03 clean up import_source (#23846)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/23846

This moves a test from Python to cpp, and in doing so lets us clean up a
bunch of otherwise unused code.

Test Plan: Imported from OSS

Differential Revision: D16684390

Pulled By: suo

fbshipit-source-id: fca81ca14d1ac9e4d6b47ae5eecaa42b38d69147
2019-08-12 20:30:06 -07:00
2dbd36b384 class_table_ to deps_table_ (#23845)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/23845

These are not just classes anymore, rename

Test Plan: Imported from OSS

Differential Revision: D16684391

Pulled By: suo

fbshipit-source-id: af0024c0b7fbcca68785ec3fc6dc288ec46a1b84
2019-08-12 20:30:01 -07:00
77c08aa46c serialize modules as classes
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/23098

Test Plan: Imported from OSS

Differential Revision: D16383328

Pulled By: suo

fbshipit-source-id: 36389b8e45c3febb7f224cd9c630fe643fa90bef
2019-08-11 15:50:29 -07:00
d3f6d5885d Replace Module::copy_into with Module::clone. (#24068)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/24068

The new method has a simpler interface (no arguments).

Resolves #23915.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/24068

Differential Revision: D16736379

Test Plan: Imported from OSS

Pulled By: ZolotukhinM

fbshipit-source-id: 1c1f397ce9cdaa5467fd7da3025cf44d1436ae6b
2019-08-09 18:25:38 -07:00
61d0624803 [jit[ make sure NameTuples have unique qualified names
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/23798

Test Plan: Imported from OSS

Differential Revision: D16652818

Pulled By: suo

fbshipit-source-id: c824f26427105ed5f0c553a67ab61c69a1f89655
2019-08-09 00:52:02 -07:00
7d207363bf Fix master - (#24003)
Summary:
I accidentally removed this in a merge, breaking a test. Fix for master
Pull Request resolved: https://github.com/pytorch/pytorch/pull/24003

Differential Revision: D16707108

Pulled By: eellison

fbshipit-source-id: 8b59f46e7932b88a7ae246a261c4daf17f23995f
2019-08-08 00:00:53 -07:00
451fc51d8d add support for overloading functions (#23886)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/23886

This is a series of PRs that will allow us to support adding [padding to conv](https://github.com/pytorch/pytorch/pull/22484) and also reduce the friction of adding method overloads that was brought up in  https://github.com/pytorch/pytorch/pull/23266.

Support for overloaded functions following the specification in [PEP 484](https://www.python.org/dev/peps/pep-0484/#function-method-overloading).

The usage is:
```
torch.jit.overload
def add(x: int, y: int) -> int: ...
torch.jit.overload
def add(x: float, y: float) -> float: ...

def add:
    return x + y
```

Follow up PRs:

- Add same API for methods
- A couple of cleanups for functions:
     - don't require default params specified on the overload as well
     - potentially error if invocation could be matched to multiple overloads. now it just chooses the first one, mypy does the same thing currently

Test Plan: Imported from OSS

Differential Revision: D16694863

Pulled By: eellison

fbshipit-source-id: f94f2933bc1c97fa58f31846acfe962b0630068c
2019-08-07 19:18:19 -07:00
9d1acd6dc2 Disable optimizer for __setstate__ (#23698)
Summary:
Before calling `__setstate__` when loading a module, we need to disable
the optimizer since the module's type does not match the values on the
stack (all the tensors will be `UndefinedTensor`)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/23698

Pulled By: driazati

Differential Revision: D16690935

fbshipit-source-id: 71e2238fd25cd16271af478ef21a3cf4e514a462
2019-08-07 12:37:24 -07:00
d413f2d335 format init.cpp (#23840)
Summary:
formatting in advance of pr that touches this file bc there is a lot of formatting noise :'(
Pull Request resolved: https://github.com/pytorch/pytorch/pull/23840

Differential Revision: D16659311

Pulled By: eellison

fbshipit-source-id: 7dedaccf9b9c455f97efdcce1c58515eb155d261
2019-08-06 10:38:30 -07:00
65a89472c4 Put all modules in the global Python CU
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/23154

Test Plan: Imported from OSS

Differential Revision: D16441913

Pulled By: suo

fbshipit-source-id: a79f2c3e06a33cbd79b2e3333f16c069f356f451
2019-07-29 16:38:20 -07:00
711be82951 Make optimize a thread_local flag
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/23170

Test Plan: Imported from OSS

Differential Revision: D16441912

Pulled By: suo

fbshipit-source-id: a33485178a329d54e41e364c4f14950f88481c55
2019-07-24 23:09:21 -07:00
d8220b0599 add simple inheritance support to AST
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/23109

Test Plan: Imported from OSS

Differential Revision: D16441914

Pulled By: suo

fbshipit-source-id: 18a57762d376759b98c18bc160eacbcc99f78ee9
2019-07-23 12:21:27 -07:00
017870a633 kill module_lookup
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/23097

Test Plan: Imported from OSS

Differential Revision: D16383329

Pulled By: suo

fbshipit-source-id: 282f8bac2245d584b66139daf4e5ea7b2b317295
2019-07-23 12:21:23 -07:00
3be0a2b4be Parse all stmts in class defs
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/23031

Test Plan: Imported from OSS

Differential Revision: D16383327

Pulled By: suo

fbshipit-source-id: 6485109a66e653b7f26d30b91a97af8d71594e22
2019-07-23 12:21:15 -07:00
5911cb8e5c Make load() create only one CU
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/22727

Differential Revision: D16197603

Test Plan: Imported from OSS

Pulled By: suo

fbshipit-source-id: 3eaefe6f229032b109d63a151fe0a20268b5cf56
2019-07-16 20:08:10 -07:00
7a370dbb41 Enable recursive script mode as the default (#22887)
Summary:
This fixes up the test suite (mostly just adding `ignore` decorations
to tests that need to call Python function) so that it all passes with
recursive script enabled.

The main user-facing result of this change is that Python functions are
compiled without any decorators, so non-TorchScriptable code must be
decorated with `torch.jit.ignore` (or
`torch.jit.ignore(drop_on_export=True` to maintain the functionality of
the current `ignore`)

Details can be found in #20939
](https://our.intern.facebook.com/intern/diff/16277608/)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/22887

Pulled By: driazati

Differential Revision: D16277608

fbshipit-source-id: 0abd0dc4291cf40651a1719bff813abb2b559640
2019-07-16 13:00:08 -07:00
eaee0c6cd9 Make classtypes hold a weak_ptr to their CU
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/22902

Test Plan: Imported from OSS

Differential Revision: D16278159

Pulled By: suo

fbshipit-source-id: 6aa682e347847e808b44218d38ff1dae66945a07
2019-07-16 12:04:20 -07:00
b6a88b3344 Make traced fns also go into the global python CU
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/22901

Test Plan: Imported from OSS

Differential Revision: D16278160

Pulled By: suo

fbshipit-source-id: f3e7d83b48d5f5b5cb1548ccc5b9bd382a3c411a
2019-07-16 12:04:16 -07:00
c5afdd0b55 Revert D16197605: [jit] Make traced fns also go into the global python CU
Differential Revision:
D16197605

Original commit changeset: d32c975486b0

fbshipit-source-id: a00f0490cc23824792f3e745d7b5a003b1a33d20
2019-07-15 22:31:33 -07:00
a326aad816 Revert D16197608: [jit] Make classtypes hold a weak_ptr to their CU
Differential Revision:
D16197608

Original commit changeset: 22250d6f0d24

fbshipit-source-id: 47a8cdeb62b1033252070ecb92906358014b551a
2019-07-15 19:49:41 -07:00
260b0e8476 Make classtypes hold a weak_ptr to their CU
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/22726

Differential Revision: D16197608

Test Plan: Imported from OSS

Pulled By: suo

fbshipit-source-id: 22250d6f0d249f61f269afb4fe8e7d1af0be1205
2019-07-15 13:13:16 -07:00
5fc1260e0a Make traced fns also go into the global python CU
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/22725

Differential Revision: D16197605

Test Plan: Imported from OSS

Pulled By: suo

fbshipit-source-id: d32c975486b0cb4808687f0aa89325571f2817c4
2019-07-15 13:13:12 -07:00
16aa235f43 _script_compile and _script_class_compile add to the python CU
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/22724

Differential Revision: D16197609

Test Plan: Imported from OSS

Pulled By: suo

fbshipit-source-id: e12b31f8c8ce14b0968f4ac9445e7d225126b210
2019-07-15 13:13:08 -07:00
de819be93e refactor self to be a class again
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/22722

Test Plan: Imported from OSS

Differential Revision: D16197607

Pulled By: suo

fbshipit-source-id: b4dd96b3f9cc46b48678aab0ff89afc3666e2185
2019-07-11 14:55:39 -07:00
22d70e0d4b Give functions qualified names
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/22721

Test Plan: Imported from OSS

Differential Revision: D16197606

Pulled By: suo

fbshipit-source-id: 94718fcdb0d3b651f16674af3cfd6249ed4533ae
2019-07-11 14:55:34 -07:00
1ecc945ab2 Revert D15998762: [jit] Give functions qualified names
Differential Revision:
D15998762

Original commit changeset: bc2b734f626a

fbshipit-source-id: a118cc4e9a34233279e8380529a8d8120a25839d
2019-07-10 16:10:28 -07:00
a1ca32409f Revert D15998758: [jit] refactor self to be a class again
Differential Revision:
D15998758

Original commit changeset: 14bad87bb6e4

fbshipit-source-id: f2c29974d4afc4d8f88a36e9c266e6d5a22a6191
2019-07-10 16:10:24 -07:00
ee9c8a75f4 refactor self to be a class again (#22207)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/22207
ghimport-source-id: 36ee8bd17411a2e220665ad2a27364653061070e

Test Plan: Imported from OSS

Differential Revision: D15998758

Pulled By: suo

fbshipit-source-id: 14bad87bb6e44bf1a43ae86339d8cc7b311c76dd
2019-07-10 15:19:07 -07:00
c0674cebf1 Give functions qualified names (#22206)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/22206
ghimport-source-id: d453219d907e048f24eb7f63c096b2c300307c83

Test Plan: Imported from OSS

Differential Revision: D15998762

Pulled By: suo

fbshipit-source-id: bc2b734f626ab07f97dc50ddf1b021e8b46de312
2019-07-10 15:19:03 -07:00
8a233b99cb Report errors through call stack (#22280)
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: https://github.com/pytorch/pytorch/pull/22280

Pulled By: driazati

Differential Revision: D16060781

fbshipit-source-id: c42968b53aaddb774ac69d5abbf7e60c23df8eed
2019-07-09 16:41:22 -07:00
b952011bae use save/load for emitFunctionHook
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/22314

Test Plan: Imported from OSS

Differential Revision: D16121781

Pulled By: suo

fbshipit-source-id: b376afb082726d78f082a0ff6902c4b501435d4b
2019-07-04 17:12:16 -07:00
f5919dba45 refactoring of module/object (#22203)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/22203
ghimport-source-id: 6b3807ac8aa53df2fdd770b43d8e54b8f0d69c20

Test Plan: Imported from OSS

Differential Revision: D15998760

Pulled By: suo

fbshipit-source-id: dd51edbcb66561189ae9d94a129434092bcad01b
2019-07-04 17:12:04 -07:00
3b2844eeea Make CompilationUnit own Functions (#22202)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/22202
ghimport-source-id: de6c963af1df76d2d6357155e64a5913ab879f76

Test Plan: Imported from OSS

Differential Revision: D15998761

Pulled By: suo

fbshipit-source-id: 5414a6424953738d823b265d20dc67dde6e5b2d8
2019-07-04 17:12:00 -07:00
2c2a913a4f Preserve SourceRanges across serialization (#22179)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/22179
ghimport-source-id: 9879551127da09d78ca348b9e436db5a09a92a38

Test Plan: Imported from OSS

Differential Revision: D15981423

Pulled By: jamesr66a

fbshipit-source-id: a2506f5a2f05916b6e8226841b0229110e758671
2019-07-01 21:14:35 -07:00
5b87049c66 remove uses of std::shared_ptr<Module> (#21934)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/21934
ghimport-source-id: e64ab9096f43749ead3ac5567675b815da295664

Test Plan: Imported from OSS

Differential Revision: D15892401

Pulled By: zdevito

fbshipit-source-id: 6424139206593ff944556c69d8a54723884eacaf
2019-06-25 13:24:38 -07:00
dd046bef8d NamedTuple serialization (#21839)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/21839
ghimport-source-id: b9d82018fbf26b22d58cad3a033cbfe4e879a8fe

Test Plan: Imported from OSS

Reviewed By: zdevito

Differential Revision: D15860002

Pulled By: jamesr66a

fbshipit-source-id: 0fc97c4adefa9ae4937f21179c7afa817f4099e5
2019-06-19 10:43:55 -07:00
5a37f8c63f Refactor TupleType to take a NamedTupleSpec (#21836)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/21836
ghimport-source-id: 91cab735765ff875046b42864188e86b8487b0ae

Test Plan: Imported from OSS

Reviewed By: zdevito

Differential Revision: D15860003

Pulled By: jamesr66a

fbshipit-source-id: 62a99a212ae6f9af83a90305e443f2dd05588292
2019-06-19 10:43:51 -07:00
c0be6e6290 Introduce SerializableType (#21835)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/21835
ghimport-source-id: e674048a56b9a573ba89e484f4b41818d3f08234

Test Plan: Imported from OSS

Reviewed By: zdevito

Differential Revision: D15860004

Pulled By: jamesr66a

fbshipit-source-id: 2d2905296939903ed4586932bea0a504b542bbdb
2019-06-19 10:43:47 -07:00
74104f383e Some small fixes for NamedTuple (#21813)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/21813
ghimport-source-id: a1edca8ad0384a9e493ef2f3b0aa5005a668a8f3

Test Plan: Imported from OSS

Reviewed By: zdevito

Differential Revision: D15860005

Pulled By: jamesr66a

fbshipit-source-id: 4a43432d2dacebde1a676a93ac57f675db857154
2019-06-19 10:43:43 -07:00
52e1cea057 Fix recusive method compilation (#21862)
Summary:
The code in `python_sugared_value.cpp` to recursively compile methods
was not being tested, so this adds a test for it and fixes some errors
in it

It was necessary to disable any hooks set since (at least in our tests) they would try to export
a half-finished graph since they were being called on recursively
compiled methods
Pull Request resolved: https://github.com/pytorch/pytorch/pull/21862

Differential Revision: D15860314

Pulled By: driazati

fbshipit-source-id: e8afe9d4c75c345b6e1471072d67c5e335b61337
2019-06-18 14:08:56 -07:00
eda08b0aae script::Module as a view. (#21814)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/21814
ghimport-source-id: 49cfea6101ad9ca438600c465762e23252e05ff3

Test Plan: Imported from OSS

Differential Revision: D15839583

Pulled By: zdevito

fbshipit-source-id: ab4ef31a523b3ac1477aa7e6d4d9513e7408c560
2019-06-18 13:58:49 -07:00
5237835a17 Make script::Method a value type (#21675)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/21675
ghimport-source-id: 90ee7ba00e58b0151ca4c17e91fd17303c9d5d08

Test Plan: Imported from OSS

Reviewed By: suo

Differential Revision: D15777725

Pulled By: zdevito

fbshipit-source-id: 8482cd2e1dcd7dd77a9cacbb76743bd190c7c4cf
2019-06-17 18:14:50 -07:00
972ec676b2 Remove lowered execution (#21674)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/21674
ghimport-source-id: b8e27f0ce9b8b362daf73556ee67457fb5355062

Reviewed By: eellison

Differential Revision: D15777726

Pulled By: zdevito

fbshipit-source-id: 718ac676c9a1bcf99b856862fd29631d825645da
2019-06-16 14:29:18 -07:00
4f75da3b41 change ClassType::compilation_unit to return owning ptr (#21787)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/21787
ghimport-source-id: eed7b98b0f02745066164b8ef3906291931e2ecb

Test Plan: Imported from OSS

Differential Revision: D15831353

Pulled By: suo

fbshipit-source-id: 50695c35dba8ffea710cbc9aca8aba6a75512fa0
2019-06-16 02:37:07 -07:00
4bcc72fe95 Support for NamedTuple (#21428)
Summary:
Resolves https://github.com/pytorch/lockdown/issues/18

This implements NamedTuple by taking advantage of the existing `names` field in `TupleType`.

TODO: This currently doesn't retain the NamedTuple-ness through serialization. Discussed with suo offline, we can probably make a way to define an anonymous NamedTuple in script (e.g. `NamedTuple('Foo', [('a', int), ('b', float), ('c', List[float])])` and serialize that
TODO: implement support for calling the constructor with kwargs
Pull Request resolved: https://github.com/pytorch/pytorch/pull/21428

Differential Revision: D15741564

Pulled By: jamesr66a

fbshipit-source-id: c077cbcea1880675ca6deb340a9ec78f824a136c
2019-06-14 16:45:56 -07:00
a3db2844e1 Support tuples in ScriptModule inputs/outputs (#20784)
Summary:
- [x] Add tests after https://github.com/pytorch/pytorch/pull/20256 is merged

- Support exporting ScriptModule with inputs/outputs of arbitrarily constructed tuples.

- Moved the assigning of output shapes to after graph conversion to ONNX is completed. By then all tuples in the IR has already been lowered by the pass ```_jit_pass_lower_all_tuples```. If assigning output shapes is required to happen before that, we'll need to hand parse the tuple structures in the graph, and repeat the same logic in ```_jit_pass_lower_all_tuples```. Handling inputs is easier because all tuple information is encoded within the input tensor type.

- Swap the order of ```_jit_pass_lower_all_tuples``` and ```_jit_pass_erase_number_types```. Ops like ```prim::TupleIndex``` relies on index being a scalar. ```_jit_pass_erase_number_types``` will convert these kind of scalars to tensors.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/20784

Reviewed By: zrphercule

Differential Revision: D15484171

Pulled By: houseroad

fbshipit-source-id: 4767a84038244c929f5662758047af6cb92228d3
2019-06-12 23:37:28 -07:00