Commit Graph

3930 Commits

Author SHA1 Message Date
Michael Suo
b825e1d472 Revert autoformat of tools/fast_nvcc/fast_nvcc.py
This was an Meta-internal change that seems to have deleted a bunch of
types and is thus causing us to fail mypy type checking. Reverting that
portion of the change.

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

Approved by: https://github.com/qihqi
2022-05-12 04:02:46 +00:00
Natalia Gimelshein
257c55f422 make clamp_min/max use minimum/maximum kernels, make clamp* correctly propagate nans (#77306)
Since clamp_min and maximum is the same op, reuse the same kernel (it also correctly propagate nans from both input and boundary, clamp* propagated from input only).
Also fixed codegen to make Tensor? overloads come before Scalar? overloads, cc @alband.
Fixes #67428 and #76795 (scalar overloads for clamp* are still not fixed, will do in the next PR).

Pull Request resolved: https://github.com/pytorch/pytorch/pull/77306
Approved by: https://github.com/albanD
2022-05-12 03:35:23 +00:00
John Reese
d973ece80f [black][codemod] formatting changes from black 22.3.0
Summary:
Applies the black-fbsource codemod with the new build of pyfmt.

paintitblack

Test Plan:
Probably going to have to ignore signals and just land it.

**Static Docs Preview: pyre**
|[Full Site](https://our.intern.facebook.com/intern/staticdocs/eph/D36324783/V4/pyre/)|

|**Modified Pages**|

**Static Docs Preview: classyvision**
|[Full Site](https://our.intern.facebook.com/intern/staticdocs/eph/D36324783/V4/classyvision/)|

|**Modified Pages**|

**Static Docs Preview: antlir**
|[Full Site](https://our.intern.facebook.com/intern/staticdocs/eph/D36324783/V4/antlir/)|

|**Modified Pages**|

Reviewed By: lisroach

Differential Revision: D36324783

fbshipit-source-id: 280c09e88257e5e569ab729691165d8dedd767bc
(cherry picked from commit 704f50c9e6bb4386802f440aee814a7d3c7b4c31)
2022-05-12 03:04:35 +00:00
Henry Tu
f6eb811786 Add RefineTypes JIT pass for Tuple (#76919)
Consider the following JIT graph, where the type of `%a` and `%b` are out of sync with tuple `%c`.
Before:
```
graph(%a : Float(123), %b : Float(4, 5, 6)):
    c : (Tensor, Tensor) = prim::TupleConstruct(%a, %b)
    return (%c)
```
After:
```
graph(%a : Float(123), %b : Float(4, 5, 6)):
    c : (Float(123), Float(4, 5, 6)) = prim::TupleConstruct(%a, %b)
    return (%c)
```
This PR adds a pass `RefineTypes(...)` to update all such instances with the correct type. This is also available via Python by using `torch._C._jit_pass_refine_types(...)`.

A unit test has been added for unnamed tuples, but no test exists for `NamedTuple` (though it was tested manually) since it isn't supported by the parser:
```
RuntimeError:
unknown type specifier:

        graph(%a : Float(123), %b : Float(4, 5, 6)):
          %c : NamedTuple(Tensor : Tuple, Tensor : Tuple) = prim::TupleConstruct(%a, %b)
               ~~~~~~~~~~ <--- HERE
          return (%c)
```

cc: @ke1337 @antoniojkim @wconstab @eellison
Pull Request resolved: https://github.com/pytorch/pytorch/pull/76919
Approved by: https://github.com/eellison
2022-05-12 00:48:39 +00:00
Eli Uriegas
ba55296504 tools: add ability to grab git tag (#77279)
Adds the ability to grab the git tag when using
`generate_torch_version.py` so that users who build from source on a
specific tag will get the version that they expect.

Behavior is now this:
1. Check if git tag is available on current commit
2. If tag available use tagged version, do not attempt to grab other versions
3. If tag is not available, use previous workflow for determining version

Signed-off-by: Eli Uriegas <eliuriegas@fb.com>

Fixes https://github.com/pytorch/pytorch/issues/77052

Pull Request resolved: https://github.com/pytorch/pytorch/pull/77279
Approved by: https://github.com/ezyang
2022-05-11 21:51:51 +00:00
Ivan Yashchuk
545d90f032 Sparse CSR: enable autograd for torch.sparse.addmm and torch.sparse.mm
This PR updates the derivative rule for `torch.sparse.addmm` to be
working with CSR sparse matrix. Notably `torch.sparse.sampled_addmm` is
used in the backward function.

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

Approved by: https://github.com/cpuhrsch
2022-05-11 18:57:40 +00:00
PyTorch MergeBot
85bd65a880 Revert "[test] try to fix torch.tensor for functionalization"
This reverts commit 9edee09ed6.

Reverted https://github.com/pytorch/pytorch/pull/76319 on behalf of https://github.com/janeyx99
2022-05-11 18:48:42 +00:00
Brian Hirsh
9edee09ed6 [test] try to fix torch.tensor for functionalization
Pull Request resolved: https://github.com/pytorch/pytorch/pull/76319

Approved by: https://github.com/ezyang
2022-05-11 17:27:34 +00:00
Nikolay Korovaiko
99339fddd9 move SymInt and SymIntArrayRef to c10/core (#77009)
Fixes #ISSUE_NUMBER

Pull Request resolved: https://github.com/pytorch/pytorch/pull/77009
Approved by: https://github.com/ezyang, https://github.com/malfet
2022-05-11 16:21:31 +00:00
Michael Suo
6cbe9d1f58 [ci] delete old linter stuff
lintrunner has been running for a while, so delete redundant linter
things

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

Approved by: https://github.com/janeyx99
2022-05-11 07:40:44 +00:00
Nikita Vedeneev
afd8bd772c nn.functional.glu: forward AD support (#77186)
To knock out functions in https://github.com/pytorch/pytorch/issues/71117.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/77186
Approved by: https://github.com/soulitzer
2022-05-10 23:58:35 +00:00
PyTorch MergeBot
12f67ed2c0 Revert "[ci] delete old linter stuff"
This reverts commit 3a68155ce0.

Reverted https://github.com/pytorch/pytorch/pull/76984 on behalf of https://github.com/janeyx99
2022-05-10 23:17:40 +00:00
Michael Suo
3a68155ce0 [ci] delete old linter stuff
lintrunner has been running for a while, so delete redundant linter
things

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

Approved by: https://github.com/janeyx99
2022-05-10 22:06:18 +00:00
yanbing-j
cd33e412a2 Enable fp32/bf16 PRelu forward and backward in MkldnnCPU path (#60427)
Enable fp32/bf16 PRelu forward and backward in MkldnnCPU path.

Fixes https://github.com/pytorch/pytorch/issues/58896

Pull Request resolved: https://github.com/pytorch/pytorch/pull/60427
Approved by: https://github.com/VitalyFedyunin, https://github.com/ngimel, https://github.com/malfet
2022-05-10 17:29:11 +00:00
Ivan Yashchuk
890bdf13e1 Remove deprecated torch.solve (#70986)
The time has come to remove deprecated linear algebra related functions. This PR removes `torch.solve`.

cc @jianyuh @nikitaved @pearu @mruberry @walterddr @IvanYashchuk @xwang233 @Lezcano
Pull Request resolved: https://github.com/pytorch/pytorch/pull/70986
Approved by: https://github.com/Lezcano, https://github.com/albanD
2022-05-10 13:44:07 +00:00
PyTorch MergeBot
f94abd59f7 Revert "Sparse CSR: enable autograd for torch.sparse.addmm and torch.sparse.mm"
This reverts commit 721a8ca697.

Reverted https://github.com/pytorch/pytorch/pull/76591 on behalf of https://github.com/janeyx99
2022-05-10 13:21:46 +00:00
Ivan Yashchuk
721a8ca697 Sparse CSR: enable autograd for torch.sparse.addmm and torch.sparse.mm
This PR updates the derivative rule for `torch.sparse.addmm` to be
working with CSR sparse matrix. Notably `torch.sparse.sampled_addmm` is
used in the backward function.

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

Approved by: https://github.com/cpuhrsch
2022-05-10 08:44:55 +00:00
PyTorch MergeBot
7eaf4780ba Revert "[LT] Store OpKind for each IR subclass in a static field"
This reverts commit ac37ddc795.

Reverted https://github.com/pytorch/pytorch/pull/76711 on behalf of https://github.com/malfet
2022-05-09 20:50:09 +00:00
PyTorch MergeBot
2c5bf12584 Revert "stft: remove non-center overload and python functional wrapper"
This reverts commit d23ecbfc9a.

Reverted https://github.com/pytorch/pytorch/pull/73434 on behalf of https://github.com/albanD
2022-05-09 19:59:46 +00:00
PyTorch MergeBot
4ebc4890dd Revert "Add linalg.lu_solve"
This reverts commit fc5b4a5a33.

Reverted https://github.com/pytorch/pytorch/pull/72935 on behalf of https://github.com/malfet
2022-05-09 19:12:30 +00:00
Jane Xu
3fb0b098ae [disable bot] Handle empty bodies (#77078)
Fixes problem where the disable bot just breaks when the issue body is empty. Disable bot started failing when #77020 was introduced as it had no issue description.

This PR simply adds a condition.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/77078
Approved by: https://github.com/ezyang, https://github.com/malfet
2022-05-09 14:21:56 +00:00
Edward Z. Yang
e3dcd175f7 Support Tensor source for x.set_(storage, offset, size, strides)
This is convenient for cases where we don't have Storage bound
correctly (e.g., meta tensors).  It is also consistent with a universe
where we get rid of storages, although arguably this is never
gonna happen.

Signed-off-by: Edward Z. Yang <ezyangfb.com>

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

Approved by: https://github.com/ngimel
2022-05-07 03:18:07 +00:00
Nikita Shulga
d0dcebe0a7 [xplat] Move BatchLinearAlgebraKernel.cpp to aten_native_source_non_codegen_list
Summary:
For some reason `aten/src/ATen/native/BatchLinearAlgebraKernel.cpp` were part of `aten_cpu_source_non_codegen_list` rather than `aten_native_source_non_codegen_list`
Fixes linking issues after https://github.com/pytorch/pytorch/pull/67833
```
stderr: ld.lld: error: undefined symbol: at::TensorIteratorBase::for_each(c10::function_ref<void (char**, long long const*, long long, long long)>, long long)
>>> referenced by TensorIterator.h:352 (buck-out/gen/fe3a39b8/xplat/caffe2/aten_headerAndroid#header-mode-symlink-tree-with-header-map,headers/ATen/TensorIterator.h:352)
>>>               buck-out/gen/fe3a39b8/xplat/caffe2/aten_cpuAndroid#android-x86,compile-pic-BatchLinearAlgebraKernel.cpp.o93aa6b34/aten/src/ATen/native/BatchLinearAlgebraKernel.cpp.o:(at::native::(anonymous namespace)::unpack_pivots_cpu_kernel(at::TensorIterator&, long long))
clang: error: linker command failed with exit code 1 (use -v to see invocation)

    When running <c++ link>.
    When building rule //xplat/caffe2:aten_cpuAndroid#android-x86,shared (ovr_config//platform/android:fbsource-base)."
```

Test Plan: CI

Reviewed By: dreiss, cccclai

Differential Revision: D36215453

fbshipit-source-id: 5f9c7cab742bb87a70b5acda46ef85817e50575c
(cherry picked from commit a1691c34f6bae484f710ac9321bfd8a8c999189e)
2022-05-07 01:54:35 +00:00
Michael Suo
7eb7b090b0 [lint] make grep_linter.py portable
grep_linter.py was using the `-P` flag of `grep`, which is available in
GNU grep but notably *not* available in the BSD grep that is installed
on Macs.

Use `-E` instead, which uses ERE instead of PCRE. Sadly we were actually
using two PCRE features in our linters:
- Negative lookaheads. I changed these to less-accurate-but-still-good-enough
  versions that use `[^...]` expressions.
- Apparently ERE doesn't support the `\t` atom lol. So I used a literal tab
  character instead (and then had to disable the TAB linter for
  `.lintrunner.toml` lol.

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

Approved by: https://github.com/ezyang
2022-05-07 00:33:53 +00:00
PyTorch MergeBot
828fb8c620 Revert "Add OpInfo based meta tensor tests"
This reverts commit d9fda18c4b.

Reverted https://github.com/pytorch/pytorch/pull/76905 on behalf of https://github.com/ezyang
2022-05-06 23:11:35 +00:00
Michael Suo
2c0268c41f [ci] fix bugs in test stats upload
- Run attempt detection was broken because it was comparing a str
  (retrieved from the CLI input) to an int (retrieved from the
  filename). Make them both ints so they will actually compare equal.
- `root.findall` only searches direct children, which didn't work for cpp
  unittests and pytest-generated reports. Change to `root.iter` which
  does a recursive search.

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

Approved by: https://github.com/janeyx99
2022-05-06 21:37:49 +00:00
Edward Z. Yang
d9fda18c4b Add OpInfo based meta tensor tests
https://github.com/pytorch/pytorch/pull/75994 was taking too long to
ship so I extracted out the CrossRef gadget and had it run on a simple
OpInfo invocation only.

TODO: There are failures that correspond to known bugs and need to be
skipped.

Signed-off-by: Edward Z. Yang <ezyangfb.com>

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

Approved by: https://github.com/anjali411, https://github.com/mruberry, https://github.com/albanD
2022-05-06 20:12:28 +00:00
Bin Bao
ac37ddc795 [LT] Store OpKind for each IR subclass in a static field
Summary: Currently OpKind is stored as an object field called op_ for each IR
node, and one usage of op_ is to avoid dynamic_cast in NodeCast when we
need to downcast a base-node pointer into a concrete sub-node pointer.
As a result, we need to construct and pass in an op when downcasting
nodes, and this becomes quite anonnying when we start to implement the
trie-based IR node reusing. More importantly, the op for each subclass
should be unique for that subclass and thus making it a const static field
is a more logical design.

In this PR, we still keep the object-level op_ for easier XLA adoption. As
furture work, we can come back to remove op_, make the op() method
virtual, and get rid of OpKind in all the node constructors.

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

Approved by: https://github.com/wconstab, https://github.com/JackCaoG
2022-05-06 19:14:46 +00:00
Sherlockk Huang
8b6a78f39f Python Interface for Jiterator
This PR allows user to author a CUDA kernel in python.

```
from torch.cuda.jiterator import create_jit_fn

code_string = "template <typename T> T my_kernel(T x, T y, T alpha) { return  -x * y + x - y + alpha; }"
jitted_fn = create_jit_fn(code_string, alpha=0)

a = torch.rand(3, device='cuda')
b = torch.rand(3, device='cuda')
result = jitted_fn(a, b, alpha=1.0)
```

Limitations:
- Only supports elementwise kernel
- 1~8 tensor inputs (empty input, e.g. factory methods, is not supported)
- inputs tensors must live in cuda device
- cpu Scalar is not supported
- kwargs must be pre-declared when calling create_jit_fn
- kwargs must be convertible to at::Scalar, one of float64, int64_t, bool. (complex not support for now)

TODOs:
- [x] consolidate union and c10::variant implementation
- [x] plug into existing op testing framework
- [ ] rename files, place files in the right folder
- [ ] place util functions in the right file
- [x] enforce assumptions in python interface e.g <8 inputs, kwargs types
- [x] Add user-facing documentation
Pull Request resolved: https://github.com/pytorch/pytorch/pull/76394
Approved by: https://github.com/mruberry
2022-05-06 18:44:28 +00:00
lezcano
fc5b4a5a33 Add linalg.lu_solve
This PR adds `linalg.lu_solve`. While doing so, I found a bug in MAGMA
when calling the batched MAGMA backend with trans=True. We work around
that by solving the system solving two triangular systems.

We also update the heuristics for this function, as they were fairly
updated. We found that cuSolver is king, so luckily we do not need to
rely on the buggy backend from magma for this function.

We added tests testing this function left and right. We also added tests
for the different backends. We also activated the tests for AMD, as
those should work as well.

Fixes https://github.com/pytorch/pytorch/issues/61657

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

Approved by: https://github.com/IvanYashchuk, https://github.com/mruberry
2022-05-05 19:02:13 +00:00
Nikita Vedeneev
33fabe9a2e functional.max_unpool: OpInfo tests + simpler backward + forward ad + fwad over backward ad
Resolves https://github.com/pytorch/pytorch/issues/67657, https://github.com/pytorch/pytorch/issues/67658, https://github.com/pytorch/pytorch/issues/67660.

These are not necessarily bugs because we cannot produce arbitrary samples coming from `max_pool` to the gradcheck's eternal satisfaction.

This PR also replaces low-level complicated backward kernels with much simpler high-level and well-tested counterparts. The replacement is also faster (before: parallel for loop, after: memory layout optimized TensorIterator's parallelization coming from `gather`).

cc @albanD @mruberry @jbschlosser @walterddr
Pull Request resolved: https://github.com/pytorch/pytorch/pull/68625
Approved by: https://github.com/albanD
2022-05-05 10:13:51 +00:00
lezcano
7cb7cd5802 Add linalg.lu
This PR modifies `lu_unpack` by:
- Using less memory when unpacking `L` and `U`
- Fuse the subtraction by `-1` with `unpack_pivots_stub`
- Define tensors of the correct types to avoid copies
- Port `lu_unpack` to be a strucutred kernel so that its `_out` version
does not incur on extra copies

Then we implement `linalg.lu` as a structured kernel, as we want to
compute its derivative manually. We do so because composing the
derivatives of `torch.lu_factor` and `torch.lu_unpack` would be less efficient.

This new function and `lu_unpack` comes with all the things it can come:
forward and backward ad, decent docs, correctness tests, OpInfo, complex support,
support for metatensors and support for vmap and vmap over the gradients.

I really hope we don't continue adding more features.

This PR also avoids saving some of the tensors that were previously
saved unnecessarily for the backward in `lu_factor_ex_backward` and
`lu_backward` and does some other general improvements here and there
to the forward and backward AD formulae of other related functions.

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

Approved by: https://github.com/IvanYashchuk, https://github.com/nikitaved, https://github.com/mruberry
2022-05-05 09:17:05 +00:00
lezcano
1a4eea57be Improve derivative of QR decomposition
We derive and implement a more concise rule for the forward and backward
derivatives of the QR decomposition. While doing this we:
- Fix the composite compliance of `linalg.qr` and we make it support batches
- Improve the performance and simplify the implementation of both foward and backward
- Avoid saving the input matrix for the backward computation.

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

Approved by: https://github.com/nikitaved, https://github.com/albanD
2022-05-05 09:14:57 +00:00
PyTorch MergeBot
da15d76e83 Revert "Add ZT fastpath for remainder.Tensor JVP"
This reverts commit 7471f614ae.

Reverted https://github.com/pytorch/pytorch/pull/76479 on behalf of https://github.com/anjali411
2022-05-05 05:05:51 +00:00
Nikita Karetnikov
7471f614ae Add ZT fastpath for remainder.Tensor JVP
See #69687.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/76479
Approved by: https://github.com/anjali411
2022-05-05 03:35:23 +00:00
Justin Chu
5dd1c67776 [ONNX] Format ONNX python with black
Format all onnx python code with black and isort with

```sh
isort torch/onnx/ test/onnx
black torch/onnx/ test/onnx
```

Updated lintrunner config to include these paths.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/76754
Approved by: https://github.com/suo, https://github.com/BowenBao
2022-05-05 00:19:22 +00:00
Bin Bao
f05710dd40 [LT] Add a trie data structure for caching IR nodes
Summary: TrieCache provides a way to look up an IR node before we
actually create it. If the lookup hits in TrieCache, we reuse the
existing node and move the current pointer in TrieCache to point to that
node; if the lookup misses, we create a new node and insert it into TrieCache.

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

Approved by: https://github.com/wconstab, https://github.com/JackCaoG
2022-05-04 23:48:03 +00:00
mikey dagitses
096ff0ecca introduce new --gen-dir flag to generate_code and use it in fbcode (#75800)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/75800

This leads to more similarities between OSS CMake and eventually OSS
Bazel. We will be able to generate files with the same names and not
have different file lists between the builds.
ghstack-source-id: 155300043

Test Plan: Verified locally and in CI.

Reviewed By: dreiss

Differential Revision: D35648586

fbshipit-source-id: 9f1638b5665ebcc64466883f65ef24a2bfd05228
(cherry picked from commit 7f2acff1baa8dfafddefdc720714f8d39feda436)
2022-05-04 15:26:25 +00:00
samdow
6779366f27 add nested mode to python mode
Pull Request resolved: https://github.com/pytorch/pytorch/pull/75965

Approved by: https://github.com/albanD, https://github.com/ezyang, https://github.com/zou3519
2022-05-04 13:01:06 +00:00
Pearu Peterson
5adf97d492 Add docstrings to sparse compressed tensor factory functions
Pull Request resolved: https://github.com/pytorch/pytorch/pull/76651

Approved by: https://github.com/cpuhrsch
2022-05-04 03:36:14 +00:00
Shintaro Iwasaki
20e4d6c4dc [PyTorch][AMD] fix hipify_python (#76720)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/76720

This PR fixes an issue in hipify_python introduced by https://github.com/pytorch/pytorch/pull/76141.

https://github.com/pytorch/pytorch/pull/76141 made all the `includes` paths "absolute", but this was not done for `args.extra_include_dir`; `new_dir`, which is a relative path, is directly added to `includes`. This PR fixes it by passing the absolute path (`abs_new_dir`).

Test Plan: CI

Reviewed By: albanD

Differential Revision: D36089556

fbshipit-source-id: 1607075a4cb13696c1b25923f56b08a8cb3c6578
(cherry picked from commit 2ca648728f01c03320015f90d33404e75f978206)
2022-05-03 22:59:10 +00:00
Michael Suo
fb0f285638 [lint] upgrade mypy to latest version
Fixes https://github.com/pytorch/pytorch/issues/75927.

Had to fix some bugs and add some ignores.

To check if clean:
```
lintrunner --paths-cmd='git grep -Il .' --take MYPY,MYPYSTRICT
```

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

Approved by: https://github.com/malfet
2022-05-03 20:51:34 +00:00
Nikita Shulga
8473173c36 Remove breakpad dependency
This functionality does not seem to be used
and there are some requests to update dependency.

Add `third_party` to torch_cpu include directories if compiling with
Caffe2 support, as `caffe2/quantization/server/conv_dnnlowp_op.cc` depends on `third_party/fbgemm/src/RefImplementations.h`

Pull Request resolved: https://github.com/pytorch/pytorch/pull/75394
Approved by: https://github.com/janeyx99, https://github.com/seemethere
2022-05-03 20:21:55 +00:00
PyTorch MergeBot
3d7428d9ac Revert "[lint] upgrade mypy to latest version"
This reverts commit 9bf18aab94.

Reverted https://github.com/pytorch/pytorch/pull/76753 on behalf of https://github.com/suo
2022-05-03 20:01:18 +00:00
Michael Suo
9bf18aab94 [lint] upgrade mypy to latest version
Fixes https://github.com/pytorch/pytorch/issues/75927.

Had to fix some bugs and add some ignores.

To check if clean:
```
lintrunner --paths-cmd='git grep -Il .' --take MYPY,MYPYSTRICT
```

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

Approved by: https://github.com/malfet
2022-05-03 19:43:28 +00:00
Michael Suo
84641d0dba [lint] fix pip init for lint when user has a global install
Closes https://github.com/suo/lintrunner/issues/4.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/76707
Approved by: https://github.com/janeyx99
2022-05-03 19:36:59 +00:00
Peter Bell
d23ecbfc9a stft: remove non-center overload and python functional wrapper
Pull Request resolved: https://github.com/pytorch/pytorch/pull/73434

Approved by: https://github.com/anjali411
2022-05-03 14:30:35 +00:00
mikey dagitses
596c54c699 add support for filtering out Bazel targets from common structure (#76173)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/76173

We need this facility temporarily to sequence some changes without
breakage. This is generally not a good idea since the main purpose of
this effort is to replicate builds in OSS Bazel.
ghstack-source-id: 155215491

Test Plan: Manual test and rely on CI.

Reviewed By: dreiss

Differential Revision: D35815290

fbshipit-source-id: 89bacda373e7ba03d6a3fcbcaa5af42ae5eac154
(cherry picked from commit 1b808bbc94c939da1fd410d81b22d43bdfe1cda0)
2022-05-03 12:13:19 +00:00
mikey dagitses
eb27c85160 move generate-code into shared build structure (#75699)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/75699

ghstack-source-id: 155255334

Test Plan: Rely on CI.

Reviewed By: dreiss

Differential Revision: D35587412

fbshipit-source-id: 5ab79c07029de279a1fae36519654a73bb61d430
(cherry picked from commit 4896b72a6c0cc087e36889d21d2d885009d94a6d)
2022-05-03 09:53:37 +00:00
Richard Zou
b34739fbef [composite compliance] fix index_copy backward
Replace x.clone().index_fill_(...) with index_fill, they do the same
thing with similar perf.

Test Plan:
- wait for tests

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

Approved by: https://github.com/ngimel, https://github.com/albanD
2022-05-03 00:07:30 +00:00
samdow
598e7e5f19 [Reland] Change 'python mode' to 'torch dispatch mode'
Changes Python Mode name to Torch Dispatch Mode because there is now a Torch Function Mode, so Torch Dispatch Mode and Torch Function Mode are consistent with each other
Pull Request resolved: https://github.com/pytorch/pytorch/pull/76562
Approved by: https://github.com/zou3519, https://github.com/albanD
2022-05-02 20:06:43 +00:00
Ivan Yashchuk
d7db6a7b02 Sparse CSR: Add backward for torch.sparse.sampled_addmm
Pull Request resolved: https://github.com/pytorch/pytorch/pull/68084

Approved by: https://github.com/cpuhrsch
2022-05-02 17:58:20 +00:00
PyTorch MergeBot
395a620a4f Revert "Change 'python mode' to 'torch dispatch mode'"
This reverts commit 7203a73986.

Reverted https://github.com/pytorch/pytorch/pull/76562 on behalf of https://github.com/janeyx99
2022-05-02 14:42:11 +00:00
samdow
7203a73986 Change 'python mode' to 'torch dispatch mode'
Changes Python Mode name to Torch Dispatch Mode because there is now a Torch Function Mode, so Torch Dispatch Mode and Torch Function Mode are consistent with each other
Pull Request resolved: https://github.com/pytorch/pytorch/pull/76562
Approved by: https://github.com/zou3519
2022-05-02 13:33:58 +00:00
Jane Xu
0708630d9f Allow sharding for distributed tests
Addresses my mistake introduced in https://github.com/pytorch/pytorch/pull/76536#issuecomment-1112657429

Also allows for sharding 1 in run_test.py
Pull Request resolved: https://github.com/pytorch/pytorch/pull/76570
Approved by: https://github.com/jeffdaily, https://github.com/seemethere
2022-04-29 03:55:07 +00:00
Pearu Peterson
ff10e45993 Unsafe Sparse Compressed tensor factory function
Pull Request resolved: https://github.com/pytorch/pytorch/pull/75961

Approved by: https://github.com/cpuhrsch
2022-04-28 23:32:36 +00:00
rraminen
7422ccea8b Hipify fixes for a successful DeepSpeed build
These commits are required to build DeepSpeed on ROCm without the hipify errors.

a41829d9ed
663c718462

cc: @jeffdaily

Pull Request resolved: https://github.com/pytorch/pytorch/pull/76141
Approved by: https://github.com/jeffdaily, https://github.com/pruthvistony, https://github.com/albanD
2022-04-28 13:19:59 +00:00
Antonio Kim
f3f327e103 Decouple LTC from TS Backend using Lazy IR Builder
Next stage of breaking up https://github.com/pytorch/pytorch/pull/74710

IR builder class introduced to decouple the explicit usage of `TsNode` in core lazy tensors.

Requires https://github.com/pytorch/pytorch/pull/75324 to be merged in first.

**Background**
- there are ~ 5 special ops used in lazy core but defined as :public {Backend}Node.  (DeviceData, Expand, Scalar...)
- we currently require all nodes derive from {Backend}Node, so that backends can make this assumption safely
- it is hard to have shared 'IR classes' in core/ because they depend on 'Node'

**Motivation**

1. avoid copy-paste of "special" node classes for each backend
2. in general decouple and remove all dependencies that LTC has on the TS backend

**Summary of changes**
- new 'IRBuilder' interface that knows how to make 5 special ops
- move 'special' node classes to `ts_backend/`
- implement TSIRBuilder that makes the special TS Nodes
- new backend interface API to get the IRBuilder
- update core code to call the builder

CC: @wconstab @JackCaoG @henrytwo

Partially Fixes #74628

Pull Request resolved: https://github.com/pytorch/pytorch/pull/75433
Approved by: https://github.com/wconstab
2022-04-28 02:07:02 +00:00
anjali411
b204ad863f Revert "Revert "Allow specifying tags for aten operators in native_functions.yaml""
This reverts commit ea44645c9a.

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

Approved by: https://github.com/osalpekar
2022-04-28 02:04:57 +00:00
Baoshuo Ren
4120cfd018 chore: remove git.io
All links on git.io will stop redirecting after April 29, 2022.

- https://github.blog/changelog/2022-04-25-git-io-deprecation/

Pull Request resolved: https://github.com/pytorch/pytorch/pull/76426
Approved by: https://github.com/ngimel
2022-04-27 23:02:45 +00:00
Mikayla Gawarecki
676a4a3969 Prototype _index_reduce (CPU-only)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/75981

Approved by: https://github.com/cpuhrsch
2022-04-27 23:01:00 +00:00
Natalia Gimelshein
04b3313379 remove unneeded overload for nansum
Per title, fixes a few OpInfo skips

Pull Request resolved: https://github.com/pytorch/pytorch/pull/76356
Approved by: https://github.com/albanD, https://github.com/mruberry
2022-04-27 16:02:54 +00:00
dzdang
6e292f1a21 [quant][core][gpu][improvement] Integrated quantized cudnn max pool2d with existing quantized_max_pool2d (#76129)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/76129

Previously, quantized_max_pool2d_cudnn was made available to the
frontend through torch.ops.quantized.max_pool2d.
We improve the integration by also making it available through
torch.max_pool2d, which is made possible by registering
quantized_max_pool2d_cudnn in native_functions.yaml under
quantized_max_pool2d, which is called in max_pool2d.

Ideally and ultimately, we will get rid of the quantized_max_pool2d
registration in native_functions.yaml, and directly register
quantized_max_pool2d and quantized_max_pool2d_cudnn under max_pool2d,
but current support for quantized dispatch keys blocks us from doing so.

Test Plan:
```
python test/run_tests.py
```

```
python test/run_tests.py
```

Differential Revision:
D35789078
D35789078

Reviewed By: jerryzh168

Pulled By: dzdang

fbshipit-source-id: 5d8220255bfab663b4779b5d3c66dea9f79d8ee7
(cherry picked from commit c27164da29043f7dc9a4c27d24a93cd37162c23e)
2022-04-27 01:52:45 +00:00
Brian Hirsh
40d96f0afd Revert "functionalization: add support for zero_()"
This reverts commit 7d44b3675b.

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

Approved by: https://github.com/datumbox, https://github.com/albanD
2022-04-26 19:27:27 +00:00
Scott Wolchok
e816e17655 [PyTorch] Add native fast path for transformer encoder inference (#76333)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/76333

The current PyTorch multi-head attention and transformer
implementations are slow. This should speed them up for inference.
ghstack-source-id: 154737857

(Note: this ignores all push blocking failures!)

Test Plan: CI

Reviewed By: cpuhrsch

Differential Revision: D35239925

fbshipit-source-id: 5a7eb8ff79bc6afb4b7d45075ddb2a24a6e2df28
2022-04-26 12:58:03 -04:00
Jane Xu
5b65361a57 Fixes black lint
Fixes lint failure caused by race condition on trunk. Ran `lintrunner -a tools/setup_helpers/generate_code.py`
Pull Request resolved: https://github.com/pytorch/pytorch/pull/76372
Approved by: https://github.com/ezyang, https://github.com/zengk95
2022-04-26 15:04:18 +00:00
mikey dagitses
03e85e5700 remove unused --ninja-global from codegen (#75869)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/75869

ghstack-source-id: 154696012

Test Plan: Verified nothing uses this and relying on CI for confirmation.

Reviewed By: dreiss

Differential Revision: D35674694

fbshipit-source-id: c1d602aa4d85642594160a33606093c33817988f
(cherry picked from commit cac15ca941be298a692570491e96f2db6095e3c1)
2022-04-26 12:06:09 +00:00
mikey dagitses
f010b15db9 remove unused all_generator_source from generate_code (#75868)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/75868

This is unused in OSS and internally.
ghstack-source-id: 154696014

Test Plan: I manually verified it is unused and am relying on CI to confirm.

Reviewed By: dreiss

Differential Revision: D35674693

fbshipit-source-id: 945ec0590e9d939eab8944ae48bae72cb61e6261
(cherry picked from commit 01a29161b0a3b386078df3cd081358786a6d8f53)
2022-04-26 12:06:09 +00:00
Kevin Stephano
b17b2b1cc7 Add NVFuser Python Frontend
New functionality.

1. Adds Pybind11 bindings for NVFuser.
2. Requires a build file change and JIT python file change outside of NVFuser's code area.

Example:
```
import torch

from torch._C._nvfuser import Fusion, FusionDefinition

# Construct and Define Fusion
fusion = Fusion()

with FusionDefinition(fusion) as fd :
    t0 = fd.define_tensor(3)
    t1 = fd.define_tensor(1)
    s0 = fd.define_scalar()

    fd.add_input(t0)
    fd.add_input(t1)
    fd.add_input(s0)

    c0 = fd.define_constant(3.0)

    t1_b = fd.Ops.broadcast(t1, [True, True, False])
    t2 = fd.Ops.add(t0, t1)
    t3 = fd.Ops.mul(t2, c0)
    t4 = fd.Ops.mul(t3, s0)
    t5 = fd.Ops.relu(t4)
    t6 = fd.Ops.sum(t5, [-1], False)

    fd.add_output(t6)

fusion.print_ir()

# Execute Fusion
input1 = torch.ones(2, 4, 8, device='cuda')
input2 = torch.ones(8, device='cuda')

# Kernel compilation should be cached for the 2nd iteration
# with input tensors of the same shape
for _ in range(5) :
    outputs = fusion.execute([input1, input2, 2.0])

print(outputs[0])
```

Pull Request resolved: https://github.com/pytorch/pytorch/pull/76353
Approved by: https://github.com/csarofeen, https://github.com/mruberry
2022-04-26 06:10:19 +00:00
Edward Z. Yang
d286197e81 Add black linter
Signed-off-by: Edward Z. Yang <ezyangfb.com>

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

Approved by: https://github.com/suo
2022-04-26 02:01:32 +00:00
Brian Hirsh
74e93f727a remove _is_foreach_op codegen special cases, clean up mutable return type checks
Pull Request resolved: https://github.com/pytorch/pytorch/pull/76190

Approved by: https://github.com/ezyang
2022-04-25 21:34:17 +00:00
Brian Hirsh
ea5209c9fd functionalization: add native fill() op
Pull Request resolved: https://github.com/pytorch/pytorch/pull/76084

Approved by: https://github.com/ezyang
2022-04-25 21:34:16 +00:00
Brian Hirsh
5da76acd1d functionalization: add a copy() native function
Pull Request resolved: https://github.com/pytorch/pytorch/pull/76083

Approved by: https://github.com/albanD
2022-04-25 21:31:48 +00:00
Brian Hirsh
7d44b3675b functionalization: add support for zero_()
Pull Request resolved: https://github.com/pytorch/pytorch/pull/75913

Approved by: https://github.com/albanD
2022-04-25 21:31:48 +00:00
mikey dagitses
f4200600e4 move Bazel version header generation to shared build structure (#75332)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/75332

ghstack-source-id: 154678044

Test Plan: Rely on OSS CI.

Reviewed By: malfet

Differential Revision: D35434229

fbshipit-source-id: 7cdd33fa32d0c485f44477e414c24c9bc4b74963
(cherry picked from commit 60285c613e8703c52f36f0bf1178e35c04574ffa)
2022-04-25 17:51:30 +00:00
Elias Ellison
0d7be81c9c [JIT] Add Context Manager to force strict fusion
Fixes https://github.com/pytorch/pytorch/issues/75464 Adds a context manager that will throw if the ops in the context are not fused.

API is :
```
with torch.jit.strict_fusion():
    ...
```

A few TODOs:
[+] Compose/figure out how to do with autodiff - right now it will run on autodiff as well
[+] Support all of the nvfuser operators that are added in guarding
[+] Figure out what to do with control flow that isn't taken (right now it will just error). this is probably a source of the original issue :/  - will just error
[+] (After those are figured out) add to docs

Pull Request resolved: https://github.com/pytorch/pytorch/pull/75777
Approved by: https://github.com/davidberard98
2022-04-25 16:08:57 +00:00
Jon Janzen
2387efd356 Revert "[PyTorch] Add native fast path for transformer encoder inference"
This reverts commit b369b89f23.

This has internal changes and should not have been landed via mergebot.

Ref: https://github.com/pytorch/pytorch/pull/75809#issuecomment-1108717166
2022-04-25 11:40:02 -04:00
Scott Wolchok
b369b89f23 [PyTorch] Add native fast path for transformer encoder inference
Pull Request resolved: https://github.com/pytorch/pytorch/pull/75809

The current PyTorch multi-head attention and transformer
implementations are slow. This should speed them up for inference.

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

**NOTE FOR REVIEWERS**: This PR has internal Facebook specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D35239925/)!

Approved by: https://github.com/ezyang
2022-04-25 06:11:36 +00:00
Edward Yang
36420b5e8c Rename tools/codegen to torchgen (#76275)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/76275

In preparation for addressing
https://github.com/pytorch/pytorch/issues/73212

Diff was generated with:

```
git mv tools/codegen torchgen
git grep -l 'tools.codegen' | xargs sed -i 's/tools.codegen/torchgen/g'
sed -i "s/\${TOOLS_PATH}\/codegen/\${TORCH_ROOT}\/torchgen/g" caffe2/CMakeLists.txt
```

and a manual edits to:

* tools/test/test_gen_backend_stubs.py
* torchgen/build.bzl
* torchgen/gen_backend_stubs.py

aka this diff:

```
 diff --git a/tools/test/test_gen_backend_stubs.py b/tools/test/test_gen_backend_stubs.py
index 3dc26c6d2d..104054575e 100644
 --- a/tools/test/test_gen_backend_stubs.py
+++ b/tools/test/test_gen_backend_stubs.py
@@ -9,7 +9,7 @@ from torchgen.gen_backend_stubs import run
 from torchgen.gen import _GLOBAL_PARSE_NATIVE_YAML_CACHE  # noqa: F401

 path = os.path.dirname(os.path.realpath(__file__))
-gen_backend_stubs_path = os.path.join(path, '../torchgen/gen_backend_stubs.py')
+gen_backend_stubs_path = os.path.join(path, '../../torchgen/gen_backend_stubs.py')

 # gen_backend_stubs.py is an integration point that is called directly by external backends.
 # The tests here are to confirm that badly formed inputs result in reasonable error messages.
 diff --git a/torchgen/build.bzl b/torchgen/build.bzl
index ed04e35a43..d00078a3cf 100644
 --- a/torchgen/build.bzl
+++ b/torchgen/build.bzl
@@ -1,6 +1,6 @@
 def define_targets(rules):
     rules.py_library(
-        name = "codegen",
+        name = "torchgen",
         srcs = rules.glob(["**/*.py"]),
         deps = [
             rules.requirement("PyYAML"),
@@ -11,6 +11,6 @@ def define_targets(rules):

     rules.py_binary(
         name = "gen",
-        srcs = [":codegen"],
+        srcs = [":torchgen"],
         visibility = ["//visibility:public"],
     )
 diff --git a/torchgen/gen_backend_stubs.py b/torchgen/gen_backend_stubs.py
index c1a672a655..beee7a15e0 100644
 --- a/torchgen/gen_backend_stubs.py
+++ b/torchgen/gen_backend_stubs.py
@@ -474,7 +474,7 @@ def run(
 ) -> None:

     # Assumes that this file lives at PYTORCH_ROOT/torchgen/gen_backend_stubs.py
-    pytorch_root = pathlib.Path(__file__).parent.parent.parent.absolute()
+    pytorch_root = pathlib.Path(__file__).parent.parent.absolute()
     template_dir = os.path.join(pytorch_root, "aten/src/ATen/templates")

     def make_file_manager(install_dir: str) -> FileManager:
```

run_all_fbandroid_tests

Test Plan: sandcastle

Reviewed By: albanD, ngimel

Differential Revision: D35770317

fbshipit-source-id: 153ac4a7fef15b1e750812a90bfafdbc8f1ebcdf
(cherry picked from commit c6d485d1d4648fa1c8a4c14c5bf3d8e899b9b4dd)
2022-04-25 01:38:06 +00:00
PyTorch MergeBot
77f23d6460 Revert "stft: remove non-center overload and python functional wrapper"
This reverts commit 6b7d89c4f1.

Reverted https://github.com/pytorch/pytorch/pull/73434 on behalf of https://github.com/osalpekar
2022-04-23 23:21:27 +00:00
Priya Ramani
5622c8b445 [Pytorch][3/4 Static dispatch] Move static dispatch logic to Operators.cpp (#76058)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/76058

Move static dispatch logic into Operators.cpp instead of having them duplicated in Functions.h and TensorBody.h
ghstack-source-id: 154616593

Test Plan:
Builds lite predictor with lightweight_dispatch enabled
```
buck build --config pt.enable_lightweight_dispatch=1 --config pt.static_dispatch_backend="CPU;QuantizedCPU;CompositeExplicitAutograd" //xplat/caffe2/fb/lite_predictor:lite_predictor_flatbuffer
```

Reviewed By: larryliu0820, bdhirsh

Differential Revision: D35702065

fbshipit-source-id: 263fe77936b63e41c4efea953be518e81a2c55c6
(cherry picked from commit 2e71198bf952bd1e5562cac2d589791e05e0fb2f)
2022-04-23 02:30:52 +00:00
Will Constable
9d8ff02e27 Make LTC codegen customizable enough for XLA migration (#76180)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/76180

Provides string variables to let xla customize the generated code sufficiently enough to facilitate their migration onto LTC.

Some/all of these custom variables are expected to be short-lived for migration and eventually revert to using the original content that points to LTC functionality.

Test Plan: Imported from OSS

Reviewed By: huiguoo

Differential Revision: D35861778

Pulled By: wconstab

fbshipit-source-id: ef7aae55334628e2e7ff0c22e5c86ab95439256d
(cherry picked from commit 971f075e0c21804558f46c685508bd23daa42d4f)
2022-04-23 02:28:32 +00:00
Peter Bell
6b7d89c4f1 stft: remove non-center overload and python functional wrapper
Pull Request resolved: https://github.com/pytorch/pytorch/pull/73434

Approved by: https://github.com/anjali411
2022-04-23 00:17:01 +00:00
Will Constable
88b61d132c Make GenLazyNativeFuncDefinition abstract and extensible (#75343)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/75343

- Rename LazyIr generator classes for consistency
- clean up dead code

Test Plan: Imported from OSS

Reviewed By: bdhirsh

Differential Revision: D35455171

Pulled By: wconstab

fbshipit-source-id: 47feaf0fc6d0f7cc383993fcf2edb17297639705
(cherry picked from commit dabda11b80db2ac9a52adf5fb7926098040f7ff0)
2022-04-22 19:37:57 +00:00
Priya Ramani
be3ad8c637 [PyTorch][2/4] Support static dispatch with multiple backends (#75605)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/75605

Usecase: Milan models have multiple backends and need to use static dispatch to save on static initialization time and to hit native functions directly from the unboxed APIs.

This change passes in List[BackendIndex] and adds ability to generate code for multiple static backends with 1 or 0 kernels
ghstack-source-id: 154525738

(Note: this ignores all push blocking failures!)

Test Plan:
Builds lite_predictor_flatbuffer with multiple backends

```
buck build --config pt.enable_lightweight_dispatch=1 --config pt.static_dispatch_backend=CPU,QuantizedCPU,CompositeExplicitAutograd //xplat/caffe2/fb/lite_predictor:lite_predictor_flatbuffer
```

Reviewed By: larryliu0820

Differential Revision: D35510644

fbshipit-source-id: f985718ad066f8578b006b4759c4a3bd6caac176
(cherry picked from commit a6999729c8cc26c54b8d5684f6585d6c50d8d913)
2022-04-22 18:35:48 +00:00
mikey dagitses
3326fa60cc move setup_helpers programs to shared build structure (#74849)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/74849

ghstack-source-id: 154189187

Test Plan: Rely on CI.

Reviewed By: malfet

Differential Revision: D35191356

fbshipit-source-id: 406b5e95a5704b4b62d846a259839bf61f3e4aba
(cherry picked from commit 46ec2b1b57ba273ae9e3316640d40b0578b5dfc2)
2022-04-22 16:48:57 +00:00
Antonio Kim
2c2c13d21b Decouple Lazy Node Shape Cache (#75324)
Summary:
Next stage of breaking up https://github.com/pytorch/pytorch/pull/74710

Move shape cache implementation to the backend interface. Also, clean up some of the hashing logic in the base node class.

CC: wconstab JackCaoG henrytwo

Partially Fixes https://github.com/pytorch/pytorch/issues/74628

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

Reviewed By: anjali411

Differential Revision: D35730823

Pulled By: wconstab

fbshipit-source-id: cf6fa326319b9324e5f422a78817b6fb5bf7e9b8
(cherry picked from commit faec5043df56639e2fd23de2d91ae796e4f3df70)
2022-04-21 17:27:05 -07:00
David Berard
272890998e [JIT] pass more exception info through the JIT interpreter
If TORCH_SHOW_CPP_STACKTRACES=1, then dump e.what() into the RuntimeError, which should make it easier to debug exceptions that happen within interpreted sections.

Test:
```patch
diff --git a/test/cpp/jit/test_dce.cpp b/test/cpp/jit/test_dce.cpp
index 6f9161d0d9..7c574787cf 100644
--- a/test/cpp/jit/test_dce.cpp
+++ b/test/cpp/jit/test_dce.cpp
@@ -3,6 +3,10 @@
 #include <torch/csrc/jit/ir/irparser.h>
 #include <torch/csrc/jit/passes/dead_code_elimination.h>
 #include <torch/csrc/jit/testing/file_check.h>
+#include <torch/csrc/jit/runtime/interpreter.h>
+#include <test/cpp/jit/test_utils.h>
+
+#include <ATen/ATen.h>

 namespace torch {
 namespace jit {
@@ -48,5 +52,30 @@ graph():
   // Check that dead code elimin
   testing::FileCheck().run(input, *graph);
 }
+
+TEST(EliminateDeadCodeTest, interpreterfailure) {
+  const std::string input = R"IR(
+graph(%x.1 : Tensor):
+  %2 : int = prim::Constant[value=128]() # /data/users/dberard/scripts/DGB/sz.py:4:38
+  %3 : int = prim::Constant[value=256]() # /data/users/dberard/scripts/DGB/sz.py:4:43
+  %5 : int = prim::Constant[value=1]() # /data/users/dberard/scripts/DGB/sz.py:4:53
+  %4 : int[] = prim::ListConstruct(%2, %3)
+  %6 : Tensor[] = aten::split_with_sizes(%x.1, %4, %5) # /data/users/dberard/scripts/DGB/sz.py:4:11
+  return (%6)
+)IR";
+  auto graph = std::make_shared<Graph>();
+  parseIR(input, graph.get());
+
+  //auto stack = createStack({at::randn({2, 383}, at::kCPU)});
+  auto stack = createStack({at::Tensor{}});
+
+  Code code(graph, "");
+  InterpreterState interpreter{code};
+  interpreter.run(stack);
+ ASSERT_EQ(2, stack.size());
+  ASSERT_FALSE(stack[0].toTensor().defined());
+  ASSERT_FALSE(stack[1].toTensor().defined());
+}
+
 } // namespace jit
 } // namespace torch
```

^ use this to repro the interpreter issue: `TORCH_SHOW_CPP_STACKTRACES=1 ./bin/test_jit --gtest_filter="EliminateDeadCodeTest.interpreterfailure"` and the stack trace is shown.

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

Approved by: https://github.com/eellison
2022-04-21 18:26:49 +00:00
Jay Chae
77665e9a53 [kineto] ClientInterface stub for ProfilerKineto (#75525)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/75525

Creating injection point for ProfilerKineto to attach global callback. We'll disable the KinetoObserver via `'kineto.disable_libkineto_observer=1'` and enable this to swap out the implementations.

Test Plan:
1. add temporary logs in the stub + registration method
2. `buck build mode/opt //kineto/libkineto/fb/integration_tests:trace_tester --config 'kineto.disable_libkineto_observer=1' --config "kineto.enable_libkineto_client=1`
3. `./buck-out/gen/kineto/libkineto/fb/integration_tests/trace_tester --test_ondemand --libkineto_runner_iterations 1000000` should see log for registration
4. `dyno gputrace` should see log for start/stop

Reviewed By: aaronenyeshi, robieta

Differential Revision: D35456304

fbshipit-source-id: c0a23a57181818e5a0ee495410163d90874355a9
(cherry picked from commit 5dfc723937356693fc041f5a011161e83a8d2528)
2022-04-21 00:08:32 +00:00
Mengwei Liu
128dd6b150 [pytorch] Relax the check that makes sure number of outs equals number of returns (#76049)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/76049

## Context
We are trying to add an out variant for an existing operator, e.g.,:
```
chunk.out(Tensor self, int chunks, int dim=0, *, Tensor(a!)[] out) -> Tensor(a!)[]
```
Notice the out argument is a mutable list of tensors. The existing guideline defined in [model.py](https://fburl.com/nn299ifx) requires the same argument type to be returned from this operator. Given the fact that we don't support mutable tensor list as a return type and it seems not useful to add such a return type.

The solution I'm proposing is to relax the constraint that the number of outs needs to be the same as the number of returns, so we can return a `void`.
```
chunk.out(Tensor self, int chunks, int dim=0, *, Tensor(a!)[] out) -> ()
```

Test Plan: Rely on existing CI

Reviewed By: ezyang, iseeyuan

Differential Revision: D35737310

fbshipit-source-id: 66b5738cc1dcd13d532a6c97fea979bd58f381df
(cherry picked from commit 9aac5493285cd4f49a07053edfa5916c449a930c)
2022-04-20 23:10:41 +00:00
Edward Z. Yang
a11c1bbdd0 Run Black on all of tools/
Signed-off-by: Edward Z. Yang <ezyangfb.com>

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

Approved by: https://github.com/albanD
2022-04-20 17:29:41 +00:00
Nikolay Korovaiko
69e048b090 List of SymInt rebase on master
Fixes #ISSUE_NUMBER

Pull Request resolved: https://github.com/pytorch/pytorch/pull/75115
Approved by: https://github.com/ezyang
2022-04-20 02:09:55 +00:00
Elias Ellison
f65eb09d6b [JIT] Move Shape Function definition to python
Moves jit shape function registration to python. Like jit decompositions, a script must be run after adding new definitions which serializes them in a c++ file.

This was a request so that torch-mlir could define functions in python and upstream their shape functions. cc @silvasean  @makslevental
Pull Request resolved: https://github.com/pytorch/pytorch/pull/75546
Approved by: https://github.com/davidberard98
2022-04-19 20:59:44 +00:00
Elias Ellison
0c671c15ec [JIT] Remove CSE Hoisting
This has led to a couple bugs, and I don't think the additional complexity was worth keeping in codebase.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/75756
Approved by: https://github.com/davidberard98
2022-04-19 20:59:25 +00:00
PyTorch MergeBot
f80d0f4e7c Revert "exclude slow tests from sharding calc for linux-bionic-py3.7-clang9-test"
This reverts commit 5364752b7d.

Reverted https://github.com/pytorch/pytorch/pull/75918 on behalf of https://github.com/clee2000
2022-04-19 20:42:53 +00:00
Catherine Lee
5364752b7d exclude slow tests from sharding calc for linux-bionic-py3.7-clang9-test
Fixes #ISSUE_NUMBER

Sharding for linux-bionic-py3.7-clang9 previously included slow test times in the calculation for how long a test takes, causing the sharding to be uneven:

| Duration      | Count | Name|
| ----------- | ----------- | ---|
| 11.2m      | 221       |linux-bionic-py3.7-clang9 / test (default, 1, 2, linux.2xlarge)|
| 1.1h   | 218        | linux-bionic-py3.7-clang9 / test (default, 2, 2, linux.2xlarge)|

Numbers taken from https://hud.pytorch.org/metrics from 04/10/2022 12:20 PM to 04/17/2022 12:20 PM.

The duration of these jobs on this PR are 39m and 38m.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/75918
Approved by: https://github.com/seemethere, https://github.com/janeyx99
2022-04-19 20:25:30 +00:00
Ivan Yashchuk
bba4780232 Enable autograd wrt sparse CSR tensors
This pull request enables accumulating gradients for the CSR tensor.
Functions that work and are tested:
- tensor.abs()
- tensor.neg()
- tensor.conj_physical()
- torch.addmm

`torch.mm` also works, but tests will be added later.

In addition, this PR adds throwing an error when trying to access strides, storage, and contiguity info on a CSR tensor.

`tensor.to_sparse_csr().to_sparse_csr()` was failing and now fixed.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/75435
Approved by: https://github.com/cpuhrsch
2022-04-19 18:42:45 +00:00
Scott Wolchok
0a5e788ab2 [PyTorch] Add NestedTensorCPU and NestedTensorCUDA dispatch keys (#75808)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/75808

Just as it is often difficult to write a single kernel that can handle both CPU and CUDA, so can it be difficult to do the same for NestedTensor.
ghstack-source-id: 154171542

(Note: this ignores all push blocking failures!)

Test Plan: CI?

Reviewed By: bdhirsh

Differential Revision: D35603836

fbshipit-source-id: fb0ebb19d34531ed96ce176aca325f8e2b5f90e6
(cherry picked from commit 0bcd753f93c04256c1b745f84a74ecccf0dceef5)
2022-04-19 18:12:12 +00:00
George Qi
f5517761aa add operator header
Pull Request resolved: https://github.com/pytorch/pytorch/pull/71502

Approved by: https://github.com/zrphercule, https://github.com/cpuhrsch
2022-04-19 15:23:25 +00:00
Edward Z. Yang
0f98fc05a7 Reformat tools/codegen with black
To do https://github.com/pytorch/pytorch/pull/75972 in a lint free
way I need to reformat all the imports (which are now incorrectly
indented).  This is a pain to do manually, so I plan to ask black to
do it for me.  But the files are not black compliant.  So first reformat
everything with black.

This commit was generated with:

```
black tools/codegen
```

Signed-off-by: Edward Z. Yang <ezyangfb.com>

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

Approved by: https://github.com/bdhirsh
2022-04-19 14:51:32 +00:00
Edward Z. Yang
7541068254 Annotate some long lines with noqa: B950
When we reformat the file with Black, these lines will exceed
the lint limit.

Signed-off-by: Edward Z. Yang <ezyangfb.com>

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

Approved by: https://github.com/bdhirsh
2022-04-19 14:51:32 +00:00
Peter Bell
cc56fac213 Fix complex to real casting warning in _to_copy backward
Fixes #75781

A Real->Complex cast should result in a gradient with no imaginary
component, so discarding the imaginary component is expected.

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

Approved by: https://github.com/albanD
2022-04-19 14:04:13 +00:00
Brian Hirsh
4c7b4b5770 fix out= op handling for functionalization
Pull Request resolved: https://github.com/pytorch/pytorch/pull/75818

Approved by: https://github.com/ezyang
2022-04-18 20:05:21 +00:00
Brian Hirsh
cb17973a2b split out functionalization codegen to use view_copy operators
Pull Request resolved: https://github.com/pytorch/pytorch/pull/75302

Approved by: https://github.com/ezyang
2022-04-18 20:05:21 +00:00
Pearu Peterson
e9791cd8c9 Validate Sparse Compressed tensor arguments
Pull Request resolved: https://github.com/pytorch/pytorch/pull/75946

Approved by: https://github.com/cpuhrsch
2022-04-18 02:21:22 +00:00
Michael Andreas Dagitses
ef50186a7d remove unused //:tools_jit target and dependency from generate-code
Pull Request resolved: https://github.com/pytorch/pytorch/pull/74837

This is no longer used.

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

Approved by: https://github.com/malfet
2022-04-17 20:54:46 +00:00
Michael Andreas Dagitses
92a5815502 stop creating jit/generated/ directory
Pull Request resolved: https://github.com/pytorch/pytorch/pull/74836

I don't believe this is used any more.

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

Approved by: https://github.com/albanD, https://github.com/malfet
2022-04-17 20:54:36 +00:00
PyTorch MergeBot
d79d9fa283 Revert "Remove breakpad dependency"
This reverts commit 9aa3c7fd83.

Reverted https://github.com/pytorch/pytorch/pull/75394 on behalf of https://github.com/malfet
2022-04-17 17:58:51 +00:00
Nikita Shulga
9aa3c7fd83 Remove breakpad dependency
This functionality does not seem to be used
and there are some requests to update dependency

Pull Request resolved: https://github.com/pytorch/pytorch/pull/75394
Approved by: https://github.com/janeyx99, https://github.com/seemethere
2022-04-17 17:43:45 +00:00
Michael Andreas Dagitses
9663886009 remove dead code from generate_code program
Pull Request resolved: https://github.com/pytorch/pytorch/pull/74835

Nothing uses these values any more.

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

Approved by: https://github.com/albanD, https://github.com/malfet
2022-04-16 14:29:15 +00:00
Michael Suo
d8374efb53 [lint] fix spurious annotations on formatting linters
We would for some reason report formatting-based lints as showing up at
line 1 column 1. This removes them for now. Maybe eventually we can
recover better line numbers from the formatting diff and post messages
for each diff cluster, but that requires actual changes to the linting
engine.

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

Approved by: https://github.com/janeyx99
2022-04-16 04:05:30 +00:00
Peter Bell
702c7f00e2 Exclude mobile TorchScript models from linter checks
Pull Request resolved: https://github.com/pytorch/pytorch/pull/75906

Approved by: https://github.com/suo
2022-04-16 00:04:49 +00:00
Michael Suo
3e0e137555 [lint] add test ownership lint to lintrunner
Pull Request resolved: https://github.com/pytorch/pytorch/pull/75898

Approved by: https://github.com/seemethere, https://github.com/janeyx99
2022-04-15 20:20:40 +00:00
Nikita Shulga
3c238c6c5a Revert "Add support to Tensor[]? for structured kernel codegen."
This reverts commit ac2de5a03a.
2022-04-15 12:16:20 -07:00
Yukio Siraichi
ac2de5a03a Add support to Tensor[]? for structured kernel codegen.
This PR turns the previously introduced `ITensorList` into a more general `IList`
class. It is a container wrapper for arbitrary types (given their appropriate
implementations).

In summary, I have:

- Renamed `ITensorList` (its iterators and macros, for consistency) to `IList`
- Made `IList` a templated function (for an arbitrary type `T`), given that they:
     - Specialize `IListTagImpl<T, Tag>`, for all `IListTag`
- Introduced type aliases (for both list and iterator types):
     - `at::ITensorList` -> `c10::IList<at::Tensor>`
     - `at::IOptTensorRefList` -> `c10::IList<at::OptionalTensorRef>`
- Added support for `Tensor?[]` in the structured codegen

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

Approved by: https://github.com/ezyang
2022-04-15 16:51:30 +00:00
Michael Suo
123297a8c0 [lint] use python to run flake8 and mypy in linter
Previously we were just using whatever version the shell picked up, but
malfet reported that this can (and is) overridden on some machines.

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

Approved by: https://github.com/malfet
2022-04-15 04:22:45 +00:00
Michael Suo
356f1478d8 [lint] add actionlint to lintrunner
Pull Request resolved: https://github.com/pytorch/pytorch/pull/75857

Approved by: https://github.com/malfet
2022-04-15 04:03:54 +00:00
Michael Suo
cbbb96c271 [lint] add shellcheck to lintrunner
As title

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

Approved by: https://github.com/malfet
2022-04-15 04:03:54 +00:00
Michael Suo
d2e7e4e2e4 [lint] add back some omitted clangtidy folders
as title, some more inclusions were added.

tested by confirming that the following command is clean:
```
lintrunner --paths-cmd='git grep -Il .' --take CLANGTIDY
```

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

Approved by: https://github.com/seemethere
2022-04-15 02:23:44 +00:00
Michael Suo
1c60b9aaa5 [ci] use lintrunner in CI
This changes our lint workflows to use lintrunner for the linters that
are currently supported

+ some random fixes to make things lint clean on master
+ changes to Makefile to use lintrunner

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

Approved by: https://github.com/t10-13rocket, https://github.com/seemethere, https://github.com/janeyx99
2022-04-15 00:08:21 +00:00
PyTorch MergeBot
db6165215e Revert "[ci] use lintrunner in CI"
This reverts commit 4c3ee53522.

Reverted https://github.com/pytorch/pytorch/pull/68460 on behalf of https://github.com/malfet
2022-04-14 23:27:27 +00:00
Peter Bell
39717d3034 Remove histogramdd functional wrapper
Merge once the forward compatibility period is expired for the histogramdd
operator.

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

Approved by: https://github.com/ezyang, https://github.com/albanD
2022-04-14 20:56:24 +00:00
Michael Suo
4c3ee53522 [ci] use lintrunner in CI
This changes our lint workflows to use lintrunner for the linters that
are currently supported

+ some random fixes to make things lint clean on master
+ changes to Makefile to use lintrunner

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

Approved by: https://github.com/t10-13rocket, https://github.com/seemethere, https://github.com/janeyx99
2022-04-14 17:43:41 +00:00
Scott Wolchok
97c993ca7a [PyTorch] Add NestedTensor support functions for transformers
Pull Request resolved: https://github.com/pytorch/pytorch/pull/75491

Here are the NestedTensor kernels we'll need for the improved transformer implementation.

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

**NOTE FOR REVIEWERS**: This PR has internal Facebook specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D35409275/)!

Approved by: https://github.com/cpuhrsch
2022-04-14 16:30:23 +00:00
Michael Andreas Dagitses
8a1a93a923 port Bazel //tools/autograd to shared build structure
Pull Request resolved: https://github.com/pytorch/pytorch/pull/74749

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

**NOTE FOR REVIEWERS**: This PR has internal Facebook specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D35145072/)!

Approved by: https://github.com/albanD
2022-04-14 07:40:49 +00:00
PyTorch MergeBot
715e07b97f Revert "Remove histogramdd functional wrapper"
This reverts commit 8cc338e5c2.

Reverted https://github.com/pytorch/pytorch/pull/74201 on behalf of https://github.com/suo
2022-04-14 03:56:48 +00:00
Michael Andreas Dagitses
8cc7221a65 move generate_code resources into tools/autograd library
Pull Request resolved: https://github.com/pytorch/pytorch/pull/75463

This better matches how the corresponding Bazel library does it.

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

**NOTE FOR REVIEWERS**: This PR has internal Facebook specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D35480501/)!

Approved by: https://github.com/albanD, https://github.com/malfet
2022-04-14 03:05:30 +00:00
Peter Bell
8cc338e5c2 Remove histogramdd functional wrapper
Merge once the forward compatibility period is expired for the histogramdd
operator.

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

Approved by: https://github.com/ezyang
2022-04-14 02:47:39 +00:00
BowenBao
aa51ee2345 Enable numel tracing
clang-format

resolve onnx test failure

update expect file

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

Approved by: https://github.com/garymm, https://github.com/eellison, https://github.com/malfet
2022-04-13 22:23:41 +00:00
Nikolay Korovaiko
ce842f43f2 Relanding shape cache (75400) (#75710)
Summary:
https://github.com/pytorch/pytorch/pull/75400

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

Reviewed By: malfet

Differential Revision: D35598920

Pulled By: Krovatkin

fbshipit-source-id: 2bbbb3d0c24214b5dbb4ca605e7daa94671f96b0
(cherry picked from commit 572f2f9df5bfd73cd7b83536f619bc86d820ccd8)
2022-04-13 17:17:30 +00:00
PyTorch MergeBot
db1801099b Revert "Relanding shape cache (75400)"
This reverts commit 89486821ed.

Reverted https://github.com/pytorch/pytorch/pull/75710 on behalf of https://github.com/malfet
2022-04-13 17:14:38 +00:00
Michael Suo
fe1e6de73a [lint] fixes to mypy linter
I thought I landed this already, but:
- Don't run one mypy instance per file, run one per config
- Do the same for flake8
- Properly handle stub files

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

Approved by: https://github.com/janeyx99
2022-04-13 17:14:24 +00:00
soulitzer
d7b29f3ee6 Add forward AD codegen support for single formula returning multiple outputs
Pull Request resolved: https://github.com/pytorch/pytorch/pull/75583

Approved by: https://github.com/albanD
2022-04-13 15:03:47 +00:00
soulitzer
8721abc429 Add forward AD support for norm, dist, F.pairwise_dist, F.normalize
Pull Request resolved: https://github.com/pytorch/pytorch/pull/74205

Approved by: https://github.com/albanD
2022-04-13 15:03:20 +00:00
PyTorch MergeBot
3471b0eb3d Revert "Remove histogramdd functional wrapper"
This reverts commit 7c9017127f.

Reverted https://github.com/pytorch/pytorch/pull/74201 on behalf of https://github.com/malfet
2022-04-13 12:54:24 +00:00
Nikolay Korovaiko
89486821ed Relanding shape cache (75400)
https://github.com/pytorch/pytorch/pull/75400
Pull Request resolved: https://github.com/pytorch/pytorch/pull/75710
Approved by: https://github.com/malfet
2022-04-13 07:28:32 +00:00
Peter Bell
7c9017127f Remove histogramdd functional wrapper
Merge once the forward compatibility period is expired for the histogramdd
operator.

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

Approved by: https://github.com/ezyang
2022-04-13 03:02:59 +00:00
PyTorch MergeBot
c274f66268 Revert "Adding Caching of calculated Symbolic Shapes"
This reverts commit 9a7bfaa929.

Reverted https://github.com/pytorch/pytorch/pull/75400 on behalf of https://github.com/mehtanirav
2022-04-12 21:53:31 +00:00
John Clow
9a7bfaa929 Adding Caching of calculated Symbolic Shapes
Pull Request resolved: https://github.com/pytorch/pytorch/pull/75400

Approved by: https://github.com/eellison
2022-04-12 11:19:58 +00:00
Pavithran Ramachandran
6402e62454 Refractor flatbuffer jit code
Pull Request resolved: https://github.com/pytorch/pytorch/pull/75239

Refractor flatbuffer_serializer to move JIT related code to a separate file .

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

**NOTE FOR REVIEWERS**: This PR has internal Facebook specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D35301020/)!

Approved by: https://github.com/iseeyuan
2022-04-11 23:41:48 +00:00
Salil Desai
ca0ef52382 [PyTorch Edge] Add Quantized Softmax Op (Naive Implementation) (Re-land)
Summary: Reland of D34943147 (8d7242a18b) + Revert of D35404312, after mitigation of S267077

Test Plan: ```buck test caffe2/test:quantization -- test_qsoftmax```

Differential Revision: D35432475

Pull Request resolved: https://github.com/pytorch/pytorch/pull/75415
Approved by: https://github.com/kimishpatel
2022-04-11 22:39:50 +00:00
Brian Hirsh
23b8414391 code-generate non-aliasing {view}_copy kernels (#73442)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/73442

Test Plan: Imported from OSS

Reviewed By: ezyang

Differential Revision: D35016025

Pulled By: bdhirsh

fbshipit-source-id: 2a7f303ec76f5913b744c7822a531d55a57589c9
(cherry picked from commit 3abe13c2a787bcbe9c41b0a335c96e5a3d3642fb)
2022-04-11 19:48:55 +00:00
Edward Z. Yang
0a1bc5f501 Miscellaneous __torch_function__ fixes
I figured these out by unconditionally turning on a no-op torch function
mode on the test suite and then fixing errors as they showed up.  Here's
what I found:

- _parse_to failed internal assert when __torch_function__'ed because it
  claims its name is "to" to the argument parser; added a name override
  so we know how to find the correct name

- Infix operator magic methods on Tensor did not uniformly handle
  __torch_function__ and TypeError to NotImplemented.  Now, we always
  do the __torch_function__ handling in
  _wrap_type_error_to_not_implemented and your implementation of
  __torch_function__ gets its TypeErrors converted to NotImplemented
  (for better or for worse; see
  https://github.com/pytorch/pytorch/issues/75462 )

- A few cases where code was incorrectly testing if a Tensor was
  Tensor-like in the wrong way, now use is_tensor_like (in grad
  and in distributions).  Also update docs for has_torch_function to
  push people to use is_tensor_like.

- is_grads_batched was dropped from grad in handle_torch_function, now
  fixed

- Report that you have a torch function even if torch function is
  disabled if a mode is enabled.  This makes it possible for a mode
  to return NotImplemented, pass to a subclass which does some
  processing and then pass back to the mode even after the subclass
  disables __torch_function__ (so the tensors are treated "as if"
  they are regular Tensors).  This brings the C++ handling behavior
  in line with the Python behavior.

- Make the Python implementation of overloaded types computation match
  the C++ version: when torch function is disabled, there are no
  overloaded types (because they all report they are not overloaded).

Signed-off-by: Edward Z. Yang <ezyangfb.com>

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

Approved by: https://github.com/zou3519
2022-04-11 16:52:16 +00:00
Brian Hirsh
466100295d fix external backend device guard codegen for factory ops
Pull Request resolved: https://github.com/pytorch/pytorch/pull/75443

Approved by: https://github.com/ezyang
2022-04-11 13:49:51 +00:00
Nikolay Korovaiko
4a85145bbd Ansley's rebase of DimensionNode onto master (#75352)
Summary:
Fixes #ISSUE_NUMBER

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

Reviewed By: wconstab

Differential Revision: D35455859

Pulled By: Krovatkin

fbshipit-source-id: e24c81d63dc66d03b752cc8de5cb551d84b003ac
(cherry picked from commit 4ad371cb4cc88860ce8ec398d82083f6759e3fcf)
2022-04-08 17:22:56 +00:00
sehoon
7a915a1576 fix 'pytorch/tools/code_coverage/README.md' for renamed options
README Instructions of the coverage tool should be fixed.

1. Some CMAKE options are not consistent with 'pytorch/CmakeLists.txt'.

- 'CODE_COVERAGE' should be 'USE_CPP_CODE_COVERAGE'.
- 'CMAKE_BUILD_CONFIG' should be 'CMAKE_BUILD_TYPE'.

2. Some arguments of 'oss_coverage.py' are incorrect.

- Both '--interested-only' and '--interested-folder' doesn't work. I guess both of them were meant to be '--interest-only'
Pull Request resolved: https://github.com/pytorch/pytorch/pull/75091
Approved by: https://github.com/ezyang
2022-04-08 15:57:40 +00:00
Richard Zou
68b18666a9 forward-mode AD formula for F.dropout
Here's what native_dropout does:
- it randomly drops out things in the input with probability p by
multiplying the input with a random mask
- it scales the output with `(p == 1 ? 0.0 : 1.0 / (1.0 - p))`

Further, native_dropout returns two things: the output and the mask
used.

Derivation of formula:
- dropout(x, mask) = mask * x * (p == 1 ? 0.0 : 1.0 / (1.0 - p))
- therefore the formula for `x` is: x_tangent * mask * (p == 1 ? 0.0 : 1.0 / (1.0 - p))

Test Plan:
- OpInfo

Fixes #ISSUE_NUMBER

Pull Request resolved: https://github.com/pytorch/pytorch/pull/75288
Approved by: https://github.com/soulitzer
2022-04-08 14:17:58 +00:00
mikey dagitses
d92213f741 move setup_helpers programs to their own package (#74838)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/74838

This matches structure of internal builds.
ghstack-source-id: 153272856

Test Plan: Should be a no-op, rely on CI to validate.

Reviewed By: ezyang

Differential Revision: D35187899

fbshipit-source-id: 44b51145df54c41836149704d0d84d4a882f158e
(cherry picked from commit af48ae5e7dd6ea7d6dc3acfb367d76508f7d6b0c)
2022-04-08 11:17:48 +00:00
Ivan Yashchuk
38a758e251 Add forward AD for rsub, polar, and FFT
This PR adds forward AD support for:
- torch.rsub
- tensor.\_\_rsub\_\_
- torch.polar
- torch.fft.fft
- torch.fft.fft2
- torch.fft.fftn
- torch.fft.hfft
- torch.fft.hfft2
- torch.fft.hfftn
- torch.fft.rfft
- torch.fft.rfft2
- torch.fft.rfftn
- torch.fft.ifft
- torch.fft.ifft2
- torch.fft.ifftn
- torch.fft.ihfft
- torch.fft.ihfft2
- torch.fft.ihfftn
- torch.fft.irfft
- torch.fft.irfft2
- torch.fft.irfftn
- torch.stft
- torch.istft

Ref. https://github.com/pytorch/pytorch/issues/71117

Pull Request resolved: https://github.com/pytorch/pytorch/pull/75326
Approved by: https://github.com/soulitzer
2022-04-08 05:01:01 +00:00
Michael Suo
8e95a2cda6 [wip] Correctly use pip3 and python3 for upload-test-stats
Pull Request resolved: https://github.com/pytorch/pytorch/pull/75456

Approved by: https://github.com/ZolotukhinM
2022-04-08 03:36:10 +00:00