Commit Graph

24397 Commits

Author SHA1 Message Date
Edward Z. Yang
3c6549ca0b Update on "Add MemoryFormat to TensorOptions, but not codegen."
This diff adds MemoryFormat field to TensorOptions, and teaches
all kernels that take TensorOptions to respect it, but doesn't
teach the codegen about it.  As such, it is now possible to specify
memory_format using TensorOptions syntax, e.g.,
at::empty_like(tensor, at::memory_format(MemoryFormat::Contiguous))
in the C++ API, but there isn't any other user visible effect.

The intended end state of this diff stack is to eliminate the
explicit MemoryFormat? arguments from native functions, but
as this change has BC implications I'd prefer to do it separately.
So this starts things off with a non-BC breaking addition to the
API.  For all internal functions that are not bound by codegen,
I switch them to exclusively using TensorOptions (eliminating
MemoryFormat); there's only a few, mostly quantized and to().

To keep things screwed down in the short term, it is a HARD ERROR
to specify both the explicit MemoryFormat argument as well as
TensorOptions.  This caught a few errors in my diff where I needed
to modify memory format settings and then call code later, esp
in empty_like.

Signed-off-by: Edward Z. Yang <ezyang@fb.com>

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

[ghstack-poisoned]
2020-02-28 11:59:01 -08:00
Edward Z. Yang
55b6295e02 Update on "Turn on strict dtype checking for test_torch.py"
Partially addresses #20376

I do this by overriding assertEqual in classes that opt into
this.  This means I have to fix #33821.  The fix is a little
unsatisfactory as idiomatic Python 2 super() calls don't work
(since the class is no longer in scope); hopefully this will just
work when we go to Python 3.

General approach taken:
- A lot of dtype mismatches are because we specified tensor constants
  that infer to some dtype, but the actual dtype needed is something else.
  Those are easy, just annotate the tensor() constructor (often a legacy
  Tensor/FloatTensor call) with dtype
- There are a few cases where the promotion rules are nontrivial.  Some of them
  I just typed out the expected promotion rules manually (based on trial
  and error)
- There are some more complex cases; if it gets too hairy I just
  set exact_dtype=False and nope the fuck out

I don't have time to do it for all the other classes.  But the setup
should work if people just incrementally add the overrides to classes,
and then eventually flip the default.

Signed-off-by: Edward Z. Yang <ezyang@fb.com>

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

[ghstack-poisoned]
2020-02-28 11:59:00 -08:00
Edward Z. Yang
7e5a8c74eb Update base for Update on "Turn on strict dtype checking for test_torch.py"
Partially addresses #20376

I do this by overriding assertEqual in classes that opt into
this.  This means I have to fix #33821.  The fix is a little
unsatisfactory as idiomatic Python 2 super() calls don't work
(since the class is no longer in scope); hopefully this will just
work when we go to Python 3.

General approach taken:
- A lot of dtype mismatches are because we specified tensor constants
  that infer to some dtype, but the actual dtype needed is something else.
  Those are easy, just annotate the tensor() constructor (often a legacy
  Tensor/FloatTensor call) with dtype
- There are a few cases where the promotion rules are nontrivial.  Some of them
  I just typed out the expected promotion rules manually (based on trial
  and error)
- There are some more complex cases; if it gets too hairy I just
  set exact_dtype=False and nope the fuck out

I don't have time to do it for all the other classes.  But the setup
should work if people just incrementally add the overrides to classes,
and then eventually flip the default.

Signed-off-by: Edward Z. Yang <ezyang@fb.com>

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

[ghstack-poisoned]
2020-02-28 11:59:00 -08:00
Jerry Zhang
f5f1e5e7f6 [quant][graphmode][refactor] Factor out getInvokedMethod (#33649)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/33649

Test Plan:
.

Imported from OSS

Differential Revision: D20123589

fbshipit-source-id: 0853d757434fb85c6d86666ff9fc991f8c4cb4bc
2020-02-27 23:48:09 -08:00
Jerry Zhang
7f1112820a [quant][graphmode][refactor] Move check for weight outside of insertObserverFor (#33276)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/33276

att

Test Plan:
.

Imported from OSS

Differential Revision: D20123593

fbshipit-source-id: 45dc8488ddf02225ba2c20374c9385edd77a4912
2020-02-27 23:48:04 -08:00
Jerry Zhang
7c13f576ea [quant][graphmode][refactor] Checks for bias and weight (#33273)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/33273

- Move the check for bias to valueNeedsToBeQuantized
- Move TORCH_CHECK inside the functions for checking if a value is bias or weight

Test Plan:
.

Imported from OSS

Differential Revision: D20123595

fbshipit-source-id: 4b805d57dcaf41a6436506d021dd5f6518bc88fd
2020-02-27 23:47:59 -08:00
Jerry Zhang
97541a5106 [quant][graphmode][refactor] Move values_to_skip check inside valueNeedsToBeQuantized (#33275)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/33275

att

Test Plan:
.

Imported from OSS

Differential Revision: D20123592

fbshipit-source-id: 2b56ea8bab27eb9ea2bf792c83e48a7af8917e1a
2020-02-27 23:46:29 -08:00
Wanchao Liang
64aab3260a [jit] allow RRef local creation with IValue objects (#33263)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/33263

This PR allow PyRRef local creation to inspect the pyobject, if it
founds that we could turn it to an IValue, turn to an IValue first,
otherwise hold it as a PyObjectType

Test Plan:
Imported from OSS

https://fb.quip.com/aGxRAh2lCg05

Differential Revision: D19871243

Pulled By: wanchaol

fbshipit-source-id: ae5be3c52fb1e6db33c64e64ef64bc8b9ea63a9a
2020-02-27 22:49:53 -08:00
Igor Sugak
1507573a52 [caffe2] fix no return statement in constexpr function Clang error in TypeIndex.h (#33576)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/33576

`throw` statement at the end of `constexpr` is ill-formed according to Clang. It happens when Clang is driving CUDA compilation and compiles for device the effected code. Due to its compilation model it requires host code to be well-formed even when compiling for device.

Fix the error by guarding the entire definition of `type_index_impl` with `__CUDA_ARCH__` check.

Test Plan:
```lang=bash
buck build mode/opt -c fbcode.cuda_use_clang=true //fblearner/flow/projects/dper:workflow
buck build mode/opt //fblearner/flow/projects/dper:workflow
```
Execute tests on devgpu:
```
buck test mode/dev-nosan -j 8 //caffe2/caffe2/python/operator_test/... //caffe2/test:cuda
```

Reviewed By: smessmer

Differential Revision: D20008881

fbshipit-source-id: b0dc9abf0dc308b8b8637b54646a0411baf7fef3
2020-02-27 22:29:58 -08:00
peter
c18cb1eb52 Improve dll loading logic on Windows (#33856)
Summary:
The way it works on the Anaconda distribution of Python 3.8 is a bit different. Loading DLLs explicitly  (e.g. `ctype.CDLL`) relies on paths appended by `os.add_dll_directory`. But if you try to load DLLs implicitly (e.g. `from torch._C import *`), it will rely on `PATH`.

Fixes https://github.com/pytorch/vision/issues/1916.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/33856

Differential Revision: D20150080

Pulled By: soumith

fbshipit-source-id: cdbe76c138ea259ef7414c6634d4f7e0b1871af3
2020-02-27 21:58:35 -08:00
Meghan Lele
cb8d9f99aa [JIT] Implement Tensor.tolist() (#33472)
Summary:
**Summary**
This commit adds an implementation of `Tensor.tolist()` to the JIT interpreter.

**Testing**
This commit adds several unit tests that test that this function works correctly for
0D, 1D, 2D and 3D tensors of type `float`, `int` and `bool`.

```
(base) meghanl-mbp:pytorch meghanl$ python test/test_jit.py TestList.test_to_list -v
Fail to import hypothesis in common_utils, tests are not derandomized
test_to_list (jit.test_list_dict.TestList)
Unit tests for Tensor.tolist() function. ... ok

----------------------------------------------------------------------
Ran 1 test in 0.329s

OK
```
Pull Request resolved: https://github.com/pytorch/pytorch/pull/33472

Differential Revision: D20109738

Pulled By: SplitInfinity

fbshipit-source-id: a6e3fee5e3201d5e1f0c4ca45048488ae2bf5e33
2020-02-27 21:45:46 -08:00
Wanchao Liang
5029ff001b [Revert] manual revert of D19918320 (#33920)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/33920

revert D19918320

Test Plan: revert diff

Reviewed By: zhaojuanmao

Differential Revision: D20151299

fbshipit-source-id: c346554ae9074991331479e434e54b0cc513f1a4
2020-02-27 21:22:36 -08:00
Edward Z. Yang
897c9956de Update on "Add MemoryFormat to TensorOptions, but not codegen."
This diff adds MemoryFormat field to TensorOptions, and teaches
all kernels that take TensorOptions to respect it, but doesn't
teach the codegen about it.  As such, it is now possible to specify
memory_format using TensorOptions syntax, e.g.,
at::empty_like(tensor, at::memory_format(MemoryFormat::Contiguous))
in the C++ API, but there isn't any other user visible effect.

The intended end state of this diff stack is to eliminate the
explicit MemoryFormat? arguments from native functions, but
as this change has BC implications I'd prefer to do it separately.
So this starts things off with a non-BC breaking addition to the
API.  For all internal functions that are not bound by codegen,
I switch them to exclusively using TensorOptions (eliminating
MemoryFormat); there's only a few, mostly quantized and to().

To keep things screwed down in the short term, it is a HARD ERROR
to specify both the explicit MemoryFormat argument as well as
TensorOptions.  This caught a few errors in my diff where I needed
to modify memory format settings and then call code later, esp
in empty_like.

Signed-off-by: Edward Z. Yang <ezyang@fb.com>

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

[ghstack-poisoned]
2020-02-27 19:33:08 -08:00
Michael Suo
8f84deddd1 [jit] fix up refs in overview.md (#33919)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/33919

Test Plan: Imported from OSS

Differential Revision: D20154953

Pulled By: suo

fbshipit-source-id: 2ef83cce8da88212bed7edc813c9b233267ea81b
2020-02-27 19:22:51 -08:00
Michael Suo
d6485b411b [jit] add top-level readme to csrc/jit (#33916)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/33916

Test Plan: Imported from OSS

Differential Revision: D20150771

Pulled By: suo

fbshipit-source-id: c7550954ddd6a294ce833348bf9fa058503e9bd7
2020-02-27 19:21:05 -08:00
Michael Suo
bd7e9c490a [jit] stop printing crap in test_jit (#33917)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/33917

Test Plan: Imported from OSS

Differential Revision: D20150750

Pulled By: suo

fbshipit-source-id: 9a35298a8856d423fb6b9043174853cccf968706
2020-02-27 19:06:43 -08:00
lixinyu
d66c320b10 disable leaky_relu_ backward calculation with negative slope (#33639)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/33639

Test Plan: Imported from OSS

Differential Revision: D20045735

Pulled By: glaringlee

fbshipit-source-id: b3becf30a8fe9ee178792bd88f6ee10102504ed5
2020-02-27 18:54:57 -08:00
Edward Z. Yang
582d0eb924 Update on "Turn on strict dtype checking for test_torch.py"
Partially addresses #20376

I do this by overriding assertEqual in classes that opt into
this.  This means I have to fix #33821.  The fix is a little
unsatisfactory as idiomatic Python 2 super() calls don't work
(since the class is no longer in scope); hopefully this will just
work when we go to Python 3.

General approach taken:
- A lot of dtype mismatches are because we specified tensor constants
  that infer to some dtype, but the actual dtype needed is something else.
  Those are easy, just annotate the tensor() constructor (often a legacy
  Tensor/FloatTensor call) with dtype
- There are a few cases where the promotion rules are nontrivial.  Some of them
  I just typed out the expected promotion rules manually (based on trial
  and error)
- There are some more complex cases; if it gets too hairy I just
  set exact_dtype=False and nope the fuck out

I don't have time to do it for all the other classes.  But the setup
should work if people just incrementally add the overrides to classes,
and then eventually flip the default.

Signed-off-by: Edward Z. Yang <ezyang@fb.com>

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

[ghstack-poisoned]
2020-02-27 18:49:58 -08:00
Edward Z. Yang
80675eb4e4 Update base for Update on "Turn on strict dtype checking for test_torch.py"
Partially addresses #20376

I do this by overriding assertEqual in classes that opt into
this.  This means I have to fix #33821.  The fix is a little
unsatisfactory as idiomatic Python 2 super() calls don't work
(since the class is no longer in scope); hopefully this will just
work when we go to Python 3.

General approach taken:
- A lot of dtype mismatches are because we specified tensor constants
  that infer to some dtype, but the actual dtype needed is something else.
  Those are easy, just annotate the tensor() constructor (often a legacy
  Tensor/FloatTensor call) with dtype
- There are a few cases where the promotion rules are nontrivial.  Some of them
  I just typed out the expected promotion rules manually (based on trial
  and error)
- There are some more complex cases; if it gets too hairy I just
  set exact_dtype=False and nope the fuck out

I don't have time to do it for all the other classes.  But the setup
should work if people just incrementally add the overrides to classes,
and then eventually flip the default.

Signed-off-by: Edward Z. Yang <ezyang@fb.com>

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

[ghstack-poisoned]
2020-02-27 18:49:58 -08:00
Jerry Zhang
997b5b5797 [quant][graphmode][refactor] Simplify signature for insertObserverFor (#33274)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/33274

att

Test Plan:
.

Imported from OSS

Differential Revision: D20123588

fbshipit-source-id: e656d96e0b6004bfcca5df2ab222184d4e1dd6ad
2020-02-27 17:24:41 -08:00
Michael Suo
db4a24e008 [jit] remove some unused/redundant files (#33806)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/33806

as title

Test Plan: Imported from OSS

Differential Revision: D20122117

Pulled By: suo

fbshipit-source-id: 209d29ed2c873181140c9fb5cdc305c200ce4008
2020-02-27 17:16:12 -08:00
Vitaly Fedyunin
877ab3afe3 Better handing of Autograd+Fork errors. (#33885)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/33885

Fixes: #32835
Fixes: #5834

Can not combine with CUDA's implementation as each of them requires individual `std::once_flag` as well as different `forked_autograd_child` functions. CUDA version relays to python module, autograd uses TORCH_CHECK to report error to python and cpp.

Test Plan: Imported from OSS

Differential Revision: D20144024

Pulled By: VitalyFedyunin

fbshipit-source-id: e7cf30568fff5110e9df7fe5b23f18ed992fa17f
2020-02-27 16:07:29 -08:00
Simón Sepúlveda Osses
746e5218e7 Mistake in MSELoss documentation (#33836)
Summary:
Replaced `sum` with `mean` in [line 392](https://github.com/pytorch/pytorch/blob/master/torch/nn/modules/loss.py#L392)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/33836

Differential Revision: D20142053

Pulled By: ailzhang

fbshipit-source-id: 2bfe19944ffc5534902dd9087023e70ddf5746c3
2020-02-27 15:34:46 -08:00
Ailing Zhang
48fd410e44 Try fix XLAPreAutograd with *_like functions. (#33848)
Summary:
In *_like functions we call
`globalLegacyTypeDispatch().initForDispatchKeySet(c10::detail::multi_dispatch_key_set(self, options));` -> `dispatchKeyToBackend` and thus this change.
`self` has both `XLAPreAutograd` and `XLATensorId` in key set.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/33848

Differential Revision: D20135898

Pulled By: ailzhang

fbshipit-source-id: a8585f39f3fa77b53718f20d3144f4f2f3cb8e53
2020-02-27 15:28:40 -08:00
Gregory Chanan
87e97ced20 Split UnaryOpsKernel into smaller files for faster compilation. (#33888)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/33888

Test Plan: Imported from OSS

Differential Revision: D20143653

Pulled By: gchanan

fbshipit-source-id: de708030e93e96091e0c01a89b4342872d0657dd
2020-02-27 15:13:01 -08:00
Eli Uriegas
aff1da5aac .circleci: Remove trailing slash, fix conda upload (#33903)
Summary:
Conda registers a suffixed slash as a new user so it was failing to
upload the anaconda packages.

In the future this should be handled through a single variable that can
be used for both but until then this will have to do.

Bug was introduced in https://github.com/pytorch/pytorch/issues/33842

Signed-off-by: Eli Uriegas <eliuriegas@fb.com>
Pull Request resolved: https://github.com/pytorch/pytorch/pull/33903

Differential Revision: D20148679

Pulled By: seemethere

fbshipit-source-id: 27c95f5d906ce84aa34bf5d76fd6f1ef5df08fb9
2020-02-27 14:56:02 -08:00
Jongsoo Park
a7fe200f5f [caffe2] simplify caffe2 code with fbgemm handling block size 1 emb (#33774)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/33774

Simplify caffe2 code using D19246900

Test Plan: CI

Reviewed By: jianyuh

Differential Revision: D20102410

fbshipit-source-id: 8de4d9cfac66898db0718ac6477339fd5e5428e3
2020-02-27 14:45:28 -08:00
Jack Cao
524dad13a8 Add device to the test tensor. Default device type is CPU, in pytorch… (#33635)
Summary:
…/xla this will result in a failure since it is comparing a XLA tensor with a CPU tensor.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/33635

Differential Revision: D20043517

Pulled By: ailzhang

fbshipit-source-id: d84038ea675e4d4a9c02e7a8b0924bdb12f40501
2020-02-27 14:40:07 -08:00
HearyShen
edd5c009f7 fix docs mistakes in lr_scheduler.MultiplicativeLR (#33805)
Summary:
This PR is referenced to an issue: [The docs of `MultiplicativeLR` use `LambdaLR` as example](https://github.com/pytorch/pytorch/issues/33752#issue-570374087)

https://github.com/pytorch/pytorch/issues/33752
Pull Request resolved: https://github.com/pytorch/pytorch/pull/33805

Differential Revision: D20121314

Pulled By: mruberry

fbshipit-source-id: 5afa63bbe83d35ce4e55705b8cbd96326a907651
2020-02-27 14:11:57 -08:00
Gregory Chanan
d97560999b Split BinaryCompareKernel.cu into a file-per-kernel to speed up compilation. (#33871)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/33871

Test Plan: Imported from OSS

Differential Revision: D20140862

Pulled By: gchanan

fbshipit-source-id: a4fde38c1c7c5905e3855fa490ea2e87bb24c703
2020-02-27 13:48:36 -08:00
Meghan Lele
5eacdfb21f Revert D20127441: [pytorch][PR] [JIT] Introduce a fake Tensor creation node for IR unit tests
Test Plan: revert-hammer

Differential Revision:
D20127441

Original commit changeset: 56da4f23ac46

fbshipit-source-id: 7d4602e5011bec6f6871eab16af05a3198694e5d
2020-02-27 13:48:31 -08:00
Gregory Chanan
c4d611a0f5 Split BinaryMiscOpsKernels into more files for faster build times. (#33873)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/33873

Test Plan: Imported from OSS

Differential Revision: D20140974

Pulled By: gchanan

fbshipit-source-id: 88b982881e8034f3b03cdb6911ae4239d2bb1596
2020-02-27 13:47:06 -08:00
Brian Vaughan
910acafc79 Revert D20124224: [jit] stop printing crap in test_jit
Test Plan: revert-hammer

Differential Revision:
D20124224

Original commit changeset: 9241d21fdf94

fbshipit-source-id: 0680f9db922f9a33a4e859eedd142b87a51bbede
2020-02-27 13:40:34 -08:00
svcscm
53630f7681 Updating submodules
Summary:
GitHub commits:

ae68f84fcd
6cb0beaf0e
401fb54029
fe8777e593
44fcf005eb
72ee067b90
01a3c124d4
c94f8f43b9
a09b292a28
472e40a902
967d4bc051

Test Plan: n/a

Reviewed By: wittgenst

fbshipit-source-id: e8e43b1cbc365fd7f5b068d625c4020240358690
2020-02-27 13:35:14 -08:00
Brian Vaughan
243af17d65 Revert D20103905: [jit] Fix flipped PackedSequence outputs in script
Test Plan: revert-hammer

Differential Revision:
D20103905

Original commit changeset: 84081213ed21

fbshipit-source-id: 2b260654fac87e52fbaf8035018e4ea484928af1
2020-02-27 13:29:35 -08:00
Brian Vaughan
a7cf5c859f Revert D20136865: fix lint
Test Plan: revert-hammer

Differential Revision:
D20136865

Original commit changeset: 4bf7ac324a0a

fbshipit-source-id: 94cc83cda180f744cec174d269f1b82babff0e5c
2020-02-27 13:21:44 -08:00
iurii zdebskyi
908eee5583 remove .data from test/distributed/ (#33874)
Summary:
`.data` calls are unsafe and should not be used.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/33874

Differential Revision: D20141059

Pulled By: izdeby

fbshipit-source-id: 8e11afc74f0cb04f5b18b458068fb813a6d51708
2020-02-27 13:14:29 -08:00
Meghan Lele
390d4d6df3 [JIT] Introduce a fake Tensor creation node for IR unit tests (#33595)
Summary:
**Summary**
There is often a need to create a Tensor when writing IR by hand for JIT
optimisation pass unit tests. The only options for this today are real
Tensor creation functions like `aten::ones`. Any test that uses these functions
must also use the same default arguments as the Python/C++ API, which means
that all of the tests have to be updated when the API is updated. This commit
introduces a new primitive, `prim::MakeTestTensor` with schema `() -> Tensor` that
should be used in unit tests instead of real Tensor creation functions. This new
primitive has no public-facing API, so the maintenance burden is much lower.

**Testing**
This commit updates the alias analysis and DCE tests to use `prim::MakeTestTensor` instead of
`aten::rand`, `aten::ones`, and `aten::zeros`.

```
$ ./bin/test_jit
CUDA not available. Disabling CUDA and MultiCUDA tests
Note: Google Test filter = *-*_CUDA:*_MultiCUDA
[==========] Running 75 tests from 1 test case.
[----------] Global test environment set-up.
[----------] 75 tests from JitTest
[ RUN      ] JitTest.ADFormulas
[       OK ] JitTest.ADFormulas (82 ms)
[ RUN      ] JitTest.Attributes
[       OK ] JitTest.Attributes (0 ms)
...
...
...
[ RUN      ] JitTest.LiteInterpreterPrim
[       OK ] JitTest.LiteInterpreterPrim (0 ms)
[ RUN      ] JitTest.LiteInterpreterLoadOrigJit
[       OK ] JitTest.LiteInterpreterLoadOrigJit (2 ms)
[----------] 75 tests from JitTest (150 ms total)

[----------] Global test environment tear-down
[==========] 75 tests from 1 test case ran. (150 ms total)
[  PASSED  ] 75 tests.
```

**Fixes**
This pull request fixes https://github.com/pytorch/pytorch/issues/33500.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/33595

Differential Revision: D20127441

Pulled By: SplitInfinity

fbshipit-source-id: 56da4f23ac46335227254f606c6481718108f378
2020-02-27 13:10:20 -08:00
Michael Suo
dbe850af5b [jit] do the code reorg (#33851)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/33851

Rationale and context described in #33828.

Script to reproduce the move:
https://gist.github.com/suo/16cbefaaeb67ca5a7c6caffd49b7f6e9
ghstack-source-id: 99079645

Test Plan: Make sure CI passes

Reviewed By: jamesr66a

Differential Revision: D20133869

fbshipit-source-id: 390e9241a9c85366d9005c492ac31f10aa96488e
2020-02-27 13:02:51 -08:00
Jerry Zhang
afbd04449e [quant][graphmode] Swap dequantize after inline for ops that doesn't require observation (#33173)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/33173

How to deal with ops that’s defined for both floating point and quantized Tensor?

Category of ops: the ones that doesn’t require observers, which means the quantization parameters(scale/zero_point) of the output of this op can be inferred from the quantization parameters of inputs.
For example:
avg_pool, max_pool, flatten, transpose, upsample

Another related topic to previous one is how do we deal with things like adaptive_avg_pool2d that does not require to be observed and it works with quantized tensor as well? If we insert quant/dequant for them, even the quant fusion becomes a numerically changing operation because the scale/zero_point for input and output are different.

Proposal

We can swap the operator with dequantize whenever we see it. For example, for pattern
Let’s say aten::general_op is defined for both floating point and quantized

%r = aten::conv(...)
%q = quantize(%r)
%dq = dequantize(%q)
%f = aten::general_op(%dq)
...

We detect that all inputs of aten::general_op is produced by dequantize, we’ll first delete all the dequantize for the inputs and then insert dequantize for each use of the output of the aten::general_op, note that this should work generally for all the case we might encounter.

After transformation we’ll have:

%r = aten::conv(...)
%q = quantize(%r)
%x = aten::general_op(%q)
%f = dequantize(%x)
...

1. Multiple inputs
    1. We need to make sure all inputs of the aten::general_op are produced by dequantize before we do this transformation
2. Input used by multiple operators
    1. We already did this by inserting dequantize for each use of the value
3. Output used by multiple operators
    1. We’ll reuse the code that inserts dequantize(might need some refactor)

Note that current concat does not belong to this category right now since it does not inherit quantization parameters from inputs.

Test Plan:
python test/test_jit.py

Imported from OSS

Differential Revision: D20123590

fbshipit-source-id: de2febe1f37e4079457a23acaeccbc6d9c9e1f8a
2020-02-27 12:42:29 -08:00
Lu Fang
6647a44e8c Automatic update of fbcode/onnx to 9fdae4c68960a2d44cd1cc871c74a6a9d469fa1f (#33858)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/33858

Previous import was 04a29addfd5b912812addb8dea5f8763fbfaad01

Included changes:
- **[9fdae4c6](https://github.com/onnx/onnx/commit/9fdae4c6)**: Copy sizes in some optimizers to remain shape information (#2574) <daquexian>
- **[c978d102](https://github.com/onnx/onnx/commit/c978d102)**: Implement CELU node as a Function (#2575) <Jeremy Cochoy>
- **[c677aef4](https://github.com/onnx/onnx/commit/c677aef4)**: Fix CI build break (#2603) <Changming Sun>
- **[d343755d](https://github.com/onnx/onnx/commit/d343755d)**: Allow function body to rely on other operator sets (#2597) <Ke Zhang>

Test Plan: ci

Reviewed By: hl475

Differential Revision: D20135343

fbshipit-source-id: d719c4ba2ae26892a5fa921691c84eba64b59291
2020-02-27 12:40:39 -08:00
Gregory Chanan
bd77abffe3 Kill some unused (TH)Storage-based APIs. (#33815)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/33815

Test Plan: Imported from OSS

Differential Revision: D20119333

Pulled By: gchanan

fbshipit-source-id: 15042ca0fabdc88b53d662b6dd964968f64997f4
2020-02-27 12:23:25 -08:00
Edward Z. Yang
d5f7429756 Update on "Turn on strict dtype checking for test_torch.py"
Partially addresses #20376

I do this by overriding assertEqual in classes that opt into
this.  This means I have to fix #33821.  The fix is a little
unsatisfactory as idiomatic Python 2 super() calls don't work
(since the class is no longer in scope); hopefully this will just
work when we go to Python 3.

General approach taken:
- A lot of dtype mismatches are because we specified tensor constants
  that infer to some dtype, but the actual dtype needed is something else.
  Those are easy, just annotate the tensor() constructor (often a legacy
  Tensor/FloatTensor call) with dtype
- There are a few cases where the promotion rules are nontrivial.  Some of them
  I just typed out the expected promotion rules manually (based on trial
  and error)
- There are some more complex cases; if it gets too hairy I just
  set exact_dtype=False and nope the fuck out

I don't have time to do it for all the other classes.  But the setup
should work if people just incrementally add the overrides to classes,
and then eventually flip the default.

Signed-off-by: Edward Z. Yang <ezyang@fb.com>

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

[ghstack-poisoned]
2020-02-27 12:13:21 -08:00
Edward Z. Yang
5cb03ebf0e Update base for Update on "Turn on strict dtype checking for test_torch.py"
Partially addresses #20376

I do this by overriding assertEqual in classes that opt into
this.  This means I have to fix #33821.  The fix is a little
unsatisfactory as idiomatic Python 2 super() calls don't work
(since the class is no longer in scope); hopefully this will just
work when we go to Python 3.

General approach taken:
- A lot of dtype mismatches are because we specified tensor constants
  that infer to some dtype, but the actual dtype needed is something else.
  Those are easy, just annotate the tensor() constructor (often a legacy
  Tensor/FloatTensor call) with dtype
- There are a few cases where the promotion rules are nontrivial.  Some of them
  I just typed out the expected promotion rules manually (based on trial
  and error)
- There are some more complex cases; if it gets too hairy I just
  set exact_dtype=False and nope the fuck out

I don't have time to do it for all the other classes.  But the setup
should work if people just incrementally add the overrides to classes,
and then eventually flip the default.

Signed-off-by: Edward Z. Yang <ezyang@fb.com>

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

[ghstack-poisoned]
2020-02-27 12:13:21 -08:00
Edward Z. Yang
211c43fcb8 Update on "Add MemoryFormat to TensorOptions, but not codegen."
This diff adds MemoryFormat field to TensorOptions, and teaches
all kernels that take TensorOptions to respect it, but doesn't
teach the codegen about it.  As such, it is now possible to specify
memory_format using TensorOptions syntax, e.g.,
at::empty_like(tensor, at::memory_format(MemoryFormat::Contiguous))
in the C++ API, but there isn't any other user visible effect.

The intended end state of this diff stack is to eliminate the
explicit MemoryFormat? arguments from native functions, but
as this change has BC implications I'd prefer to do it separately.
So this starts things off with a non-BC breaking addition to the
API.  For all internal functions that are not bound by codegen,
I switch them to exclusively using TensorOptions (eliminating
MemoryFormat); there's only a few, mostly quantized and to().

To keep things screwed down in the short term, it is a HARD ERROR
to specify both the explicit MemoryFormat argument as well as
TensorOptions.  This caught a few errors in my diff where I needed
to modify memory format settings and then call code later, esp
in empty_like.

Signed-off-by: Edward Z. Yang <ezyang@fb.com>

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

[ghstack-poisoned]
2020-02-27 10:25:15 -08:00
Edward Z. Yang
4dc03e06d4 Update on "Turn on strict dtype checking for test_torch.py"
Partially addresses #20376

I do this by overriding assertEqual in classes that opt into
this.  This means I have to fix #33821.  The fix is a little
unsatisfactory as idiomatic Python 2 super() calls don't work
(since the class is no longer in scope); hopefully this will just
work when we go to Python 3.

General approach taken:
- A lot of dtype mismatches are because we specified tensor constants
  that infer to some dtype, but the actual dtype needed is something else.
  Those are easy, just annotate the tensor() constructor (often a legacy
  Tensor/FloatTensor call) with dtype
- There are a few cases where the promotion rules are nontrivial.  Some of them
  I just typed out the expected promotion rules manually (based on trial
  and error)
- There are some more complex cases; if it gets too hairy I just
  set exact_dtype=False and nope the fuck out

I don't have time to do it for all the other classes.  But the setup
should work if people just incrementally add the overrides to classes,
and then eventually flip the default.

Signed-off-by: Edward Z. Yang <ezyang@fb.com>

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

[ghstack-poisoned]
2020-02-27 10:25:14 -08:00
Edward Z. Yang
b04101af79 Update base for Update on "Turn on strict dtype checking for test_torch.py"
Partially addresses #20376

I do this by overriding assertEqual in classes that opt into
this.  This means I have to fix #33821.  The fix is a little
unsatisfactory as idiomatic Python 2 super() calls don't work
(since the class is no longer in scope); hopefully this will just
work when we go to Python 3.

General approach taken:
- A lot of dtype mismatches are because we specified tensor constants
  that infer to some dtype, but the actual dtype needed is something else.
  Those are easy, just annotate the tensor() constructor (often a legacy
  Tensor/FloatTensor call) with dtype
- There are a few cases where the promotion rules are nontrivial.  Some of them
  I just typed out the expected promotion rules manually (based on trial
  and error)
- There are some more complex cases; if it gets too hairy I just
  set exact_dtype=False and nope the fuck out

I don't have time to do it for all the other classes.  But the setup
should work if people just incrementally add the overrides to classes,
and then eventually flip the default.

Signed-off-by: Edward Z. Yang <ezyang@fb.com>

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

[ghstack-poisoned]
2020-02-27 10:25:14 -08:00
Edward Z. Yang
77213e5873 Update on "Add MemoryFormat to TensorOptions, but not codegen."
This diff adds MemoryFormat field to TensorOptions, and teaches
all kernels that take TensorOptions to respect it, but doesn't
teach the codegen about it.  As such, it is now possible to specify
memory_format using TensorOptions syntax, e.g.,
at::empty_like(tensor, at::memory_format(MemoryFormat::Contiguous))
in the C++ API, but there isn't any other user visible effect.

The intended end state of this diff stack is to eliminate the
explicit MemoryFormat? arguments from native functions, but
as this change has BC implications I'd prefer to do it separately.
So this starts things off with a non-BC breaking addition to the
API.  For all internal functions that are not bound by codegen,
I switch them to exclusively using TensorOptions (eliminating
MemoryFormat); there's only a few, mostly quantized and to().

To keep things screwed down in the short term, it is a HARD ERROR
to specify both the explicit MemoryFormat argument as well as
TensorOptions.  This caught a few errors in my diff where I needed
to modify memory format settings and then call code later, esp
in empty_like.

Signed-off-by: Edward Z. Yang <ezyang@fb.com>

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

[ghstack-poisoned]
2020-02-27 09:52:03 -08:00
Edward Z. Yang
858a6c21f0 Update on "Turn on strict dtype checking for test_torch.py"
Partially addresses #20376

I do this by overriding assertEqual in classes that opt into
this.  This means I have to fix #33821.  The fix is a little
unsatisfactory as idiomatic Python 2 super() calls don't work
(since the class is no longer in scope); hopefully this will just
work when we go to Python 3.

General approach taken:
- A lot of dtype mismatches are because we specified tensor constants
  that infer to some dtype, but the actual dtype needed is something else.
  Those are easy, just annotate the tensor() constructor (often a legacy
  Tensor/FloatTensor call) with dtype
- There are a few cases where the promotion rules are nontrivial.  Some of them
  I just typed out the expected promotion rules manually (based on trial
  and error)
- There are some more complex cases; if it gets too hairy I just
  set exact_dtype=False and nope the fuck out

I don't have time to do it for all the other classes.  But the setup
should work if people just incrementally add the overrides to classes,
and then eventually flip the default.

Signed-off-by: Edward Z. Yang <ezyang@fb.com>

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

[ghstack-poisoned]
2020-02-27 09:52:03 -08:00
Edward Z. Yang
98f0dd5c99 Update base for Update on "Turn on strict dtype checking for test_torch.py"
Partially addresses #20376

I do this by overriding assertEqual in classes that opt into
this.  This means I have to fix #33821.  The fix is a little
unsatisfactory as idiomatic Python 2 super() calls don't work
(since the class is no longer in scope); hopefully this will just
work when we go to Python 3.

General approach taken:
- A lot of dtype mismatches are because we specified tensor constants
  that infer to some dtype, but the actual dtype needed is something else.
  Those are easy, just annotate the tensor() constructor (often a legacy
  Tensor/FloatTensor call) with dtype
- There are a few cases where the promotion rules are nontrivial.  Some of them
  I just typed out the expected promotion rules manually (based on trial
  and error)
- There are some more complex cases; if it gets too hairy I just
  set exact_dtype=False and nope the fuck out

I don't have time to do it for all the other classes.  But the setup
should work if people just incrementally add the overrides to classes,
and then eventually flip the default.

Signed-off-by: Edward Z. Yang <ezyang@fb.com>

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

[ghstack-poisoned]
2020-02-27 09:52:03 -08:00