Commit graph

36724 commits

Author SHA1 Message Date
Hao Lu
993a35a8cb [Static Runtime] Support clamp.Tensor (#58191)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/58191

There are two clamp overloads: clamp.Scalar and clamp.Tensor. SR needs to support both or has checks in place to avoid runtime errors. Supporting both is not too hard so here we are.

Reviewed By: edvgha

Differential Revision: D28371949

fbshipit-source-id: 0ec6b8a0b8c6277e50d8e51e4e7a45aa62211e22
2021-05-13 17:46:59 -07:00
lezcano
1f3807ce5d More stable and faster implementation of the gradient of torch.linalg.eigh (#55049)
Summary:
This PR:
- Renames symeig_backward to eigh_backward
- Improves the stability and speed of the gradient computation by doing `V(A + B)Vh` instead of `VAVh + VBVh`  when both the gradients of the eigenvectors and eigenvalues are defined.
- Updates the comments of the function to make them arguably clearer

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

Reviewed By: ngimel

Differential Revision: D28396823

Pulled By: mruberry

fbshipit-source-id: a144482bfb1054e281b58ae1fe3cf1015bab505d
2021-05-13 17:17:35 -07:00
Ivan Yashchuk
b0833533a7 Update internal code for torch.linalg.solve (#56613)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/56613

Replace linalg_solve_helper with `lu_stub` + `lu_solve_stub`.
Once `lu_stub` and `lu_solve_stub` have cuSOLVER-based codepath,
`torch.linalg.solve` will have it as well.

Test Plan: Imported from OSS

Reviewed By: agolynski

Differential Revision: D28379394

Pulled By: mruberry

fbshipit-source-id: b47f66bc1ee12715da11dcffc92e31e67fa8c8f6
2021-05-13 16:57:29 -07:00
Nikolay Korovaiko
d304bb070a Gelu Backward, Contribution from Kevin Stephano (#58249)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/58249

Test Plan: Imported from OSS

Reviewed By: ejguan

Differential Revision: D28425381

Pulled By: Krovatkin

fbshipit-source-id: 21b7ac972220b6c35b285e3b66f05eb392002408
2021-05-13 16:36:44 -07:00
Sam Estep
3a898c26c0 Print stderrs in tools/mypy_wrapper.py (#58265)
Summary:
Uncovered while investigating https://github.com/pytorch/pytorch/issues/58253.

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

Test Plan:
Before this PR:

```
$ mypy tools/stats_utils/foo.txt
mypy: can't read file 'tools/stats_utils/foo.txt': No such file or directory
$ echo $?
2
$ tools/mypy_wrapper.py $PWD/tools/stats_utils/foo.txt
$ echo $?
2
```

After this PR:

```
$ mypy tools/stats_utils/foo.txt
mypy: can't read file 'tools/stats_utils/foo.txt': No such file or directory
$ echo $?
2
$ tools/mypy_wrapper.py $PWD/tools/stats_utils/foo.txt > /dev/null
mypy: can't read file 'tools/stats_utils/foo.txt': No such file or directory
mypy: can't read file 'tools/stats_utils/foo.txt': No such file or directory
$ echo $?
2
```

Reviewed By: zhouzhuojie

Differential Revision: D28426439

Pulled By: samestep

fbshipit-source-id: c47a85a696ed44c9873416decc9fed8d99bc556c
2021-05-13 16:25:42 -07:00
zhouzhuojie
7756cb6a5b Migrate pytorch_python_doc_build to github action (#57371)
Summary:
# Changes

This PR migrates `pytorch_python_doc_build` from circleci to github actions.

Noticeable changes
- Refactor `docker cp` into a single `docker run` with volume mount, because the in circleci volume is not accessible from its remote docker engine
- `pytorch_python_doc_push` job will have a race condition with circleci, which will be migrated in separate PRs

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

Reviewed By: samestep

Differential Revision: D28416289

Pulled By: zhouzhuojie

fbshipit-source-id: 04caccccf3d7eb7e2225846a406a53ccda356d44
2021-05-13 15:42:52 -07:00
Sam Estep
3f9126f399 Only quicklint files that exist (#58261)
Summary:
Fixes https://github.com/pytorch/pytorch/issues/58253.

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

Test Plan: The repro steps for https://github.com/pytorch/pytorch/issues/58253.

Reviewed By: janeyx99

Differential Revision: D28425900

Pulled By: samestep

fbshipit-source-id: b4abe910bd9ba5a34ec5a413d4df21b85f96a89f
2021-05-13 15:16:07 -07:00
Natalia Gimelshein
f6532468c8 Make norm and vector_norm use the same kernels. (#58214)
Summary:
Fixes a few problems with `torch.norm` (incorrect behavior for empty inputs and negative p, https://github.com/pytorch/pytorch/issues/52783, and incorrect imaginary part for complex).
Most importantly, makes linalg_norm and vector_norm use the same kernels, reducing compile time and binary size.

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

Reviewed By: ejguan

Differential Revision: D28422439

Pulled By: ngimel

fbshipit-source-id: afe088a866963068e8c85eb9c3b2218a21ff2d48
2021-05-13 15:06:37 -07:00
Sam Estep
26aeec35a1 Disable more of quicklint test (#58257)
Summary:
Essentially a followup to https://github.com/pytorch/pytorch/issues/57968. For now, this test is just too flaky to run on every PR.

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

Test Plan: The repro steps in https://github.com/pytorch/pytorch/issues/58253.

Reviewed By: walterddr

Differential Revision: D28424862

Pulled By: samestep

fbshipit-source-id: 00aed872fe505db67e48414b1234505a71099262
2021-05-13 14:45:45 -07:00
Martin Yuan
d833caaf6b [PyTorch Mobile][Forward/backward compatibility] Number of arguments for operators (#56845)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/56845

Handle forward/backward compatibility caused by added default arguments in mobile. As an example,

In older version, operator aten::foo's schema is
```
foo(Tensor a, Tensor b) -> Tensor
```
In the new version, the schema is updated to
```
foo(Tensor a, Tensor b, int groups=1) -> Tensor
```

## Model file
Serialize the number of specified arguments to each operator into the bytecode operator table. Before the operator table contains operator name and overload name:
```
('operators', (('aten::foo', ''),))
```
Now the number of specified arguments is added:
```
# bytecode version 6
('operators', (('aten::foo', '', 2),))
```
where "2" means the number of specified arguments.

Since there's bytecode schema change, the bytecode version number is bumped. This PR is to be landed after #56002 , where the version number is bumped from 4 to 5. This PR bumps the version number from 5 to 6.

## Runtime and backward compatibility
When the operator is found (either jit or c10), we have the OperatorHandle, where the operator schema can be accessed by
```
op.value().schema().arguments()
```
Adaptation is implemented to handle backward compatibility. For the example above, the new runtime holds the updated schema:
```
foo(Tensor a, Tensor b, int groups=1) -> Tensor
```
Whereas the model file carries
```
(('aten::foo', ''), 2)
```
We can implement a wrapper around the original function pointer to push the default argument to the stack.

## Deliver time and forward compatibility
At model delivery time, two checks can be done:
### Operator check
Two APIs to be provided:
* Runtime: An API to get a runtime’s ops and their schemas (i.e. the # of args). D27920185(WIP)
* Model: An API to get a model’s ops and their schema requirements (i.e. the # of args required).

The APIs can be used to check
* runtime.ops() is a superset of model.ops()
* for each op in model.ops() validate their schemas are compatible with those in runtime.ops() -- i.e. the # args required in a model op are <= # args in the runtime op.

Note that only root ops in the model needs to be checked here. For transient ops it's not necessary. For example, if a root op, "aten::root" calls "aten::foo", it's "aten::root"'s responsibility to adapt to "aten::foo"'s change, or "aten::root" itself needs to be updated too.
### Bytecode version backport (PR coming)
When delivering a model with bytecode v6, if the runtime only works with bytecode v5 and lower, backport is needed.
* The number of arguments is removed from the operator table
* The bytecode version is changed from 6 to 5

Note that this backport is a pure format change, it does not guarantee the backported model always runs in old runtime. The operator check mentioned before should be done first, before it’s back ported to v5.

Test Plan: Imported from OSS

Reviewed By: gmagogsfm

Differential Revision: D27986544

Pulled By: iseeyuan

fbshipit-source-id: 143e19d4798cfb96b65095538dd648eead4e3fda
2021-05-13 14:20:47 -07:00
Jeffrey Wan
e1bb9d2d99 Reimplement spectral_norm using new parametrization functionality (#57784)
Summary:
Adds a new file under `torch/nn/utils/parametrizations.py` which should contain all the parametrization implementations

For spectral_norm we add the `SpectralNorm` module which can be registered using `torch.nn.utils.parametrize.register_parametrization` or using a wrapper: `spectral_norm`, the same API the old implementation provided.

Most of the logic is borrowed from the old implementation:
 - Just like the old implementation, there should be cases when retrieving the weight should perform another power iteration (thus updating the weight) and cases where it shouldn't. For example in eval mode `self.training=True`, we do not perform power iteration.

There are also some differences/difficulties with the new implementation:
 - Using new parametrization functionality as-is there doesn't seem to be a good way to tell whether a 'forward' call was the result of parametrizations are unregistered (and leave_parametrizations=True) or when the injected property's getter was invoked. The issue is that we want perform power iteration in the latter case but not the former, but we don't have this control as-is. So, in this PR I modified the parametrization functionality to change the module to eval mode before triggering their forward call
 - Updates the vectors based on weight on initialization to fix https://github.com/pytorch/pytorch/issues/51800 (this avoids silently update weights in eval mode). This also means that we perform twice any many power iterations by the first forward.
 - right_inverse is just the identity for now, but maybe it should assert that the passed value already satisfies the constraints
 - So far, all the old spectral_norm tests have been cloned, but maybe we don't need so much testing now that the core functionality is already well tested

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

Reviewed By: ejguan

Differential Revision: D28413201

Pulled By: soulitzer

fbshipit-source-id: e8f1140f7924ca43ae4244c98b152c3c554668f2
2021-05-13 14:16:13 -07:00
BowenBao
51cd89ecc6 [ONNX] Handle mixed mask, index input for index_put (#57604)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/57604

Test Plan: Imported from OSS

Reviewed By: malfet

Differential Revision: D28393524

Pulled By: SplitInfinity

fbshipit-source-id: 6c0cd9db981a7e4ece2fdd375a814a13449e1ab0

Co-authored-by: David <jiafa@microsoft.com>
2021-05-13 13:42:56 -07:00
BowenBao
01374d69e4 [ONNX] ListUnpack on dynamic tensor list (#56592) (#57603)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/57603

With explicit list unpack code from user, it is possible to observe `prim::ListUnpack` with a `ONNX::Sequence` object.
 This PR supports the conversion.

Test Plan: Imported from OSS

Reviewed By: malfet

Differential Revision: D28393527

Pulled By: SplitInfinity

fbshipit-source-id: 1e6234d349b94c97c6ff20880a801433a9a428e9

Co-authored-by: BowenBao <bowbao@microsoft.com>
2021-05-13 13:42:55 -07:00
BowenBao
8e29863a0d [ONNX] Handle NoneType in Assign Output Shapes (#54623) (#57602)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/57602

Needed for ONNX Export of Huggingface-reformer models

Test Plan: Imported from OSS

Reviewed By: malfet

Differential Revision: D28393517

Pulled By: SplitInfinity

fbshipit-source-id: bab6f91e624bb31e804fe2cf7ec0970164a6f29e

Co-authored-by: shubhambhokare1 <shubhambhokare1@gmail.com>
2021-05-13 13:42:53 -07:00
BowenBao
bfe7728f18 [ONNX] Process const folding progressively when converts to ONNX (#54569) (#57601)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/57601

This PR automatically solves onnx const attribute issue in PR https://github.com/pytorch/pytorch/pull/53784.

Test Plan: Imported from OSS

Reviewed By: malfet

Differential Revision: D28393525

Pulled By: SplitInfinity

fbshipit-source-id: 833dac7c71f24a88af62d5dd2be0a702ed34d053

Co-authored-by: David <jiafa@microsoft.com>
2021-05-13 13:42:51 -07:00
BowenBao
346dc88bfa [ONNX] Support registering custom export for prim::PythonOp from torch.autograd.Function (#55630) (#57600)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/57600

Demo script:

```python
import torch

class MyReLU(torch.autograd.Function):
    staticmethod
    def forward(ctx, input, scalar_tuple, scalar, scalar_list):
        ctx.save_for_backward(input)
        return input.clamp(min=scalar)
    staticmethod
    def backward(ctx, grad_output):
        input, = ctx.saved_tensors
        grad_input = grad_output.clone()
        grad_input[input < 0] = 0
        return grad_input

class MyModule(torch.nn.Module):
    def __init__(self):
        super().__init__()
        self.linear_a = torch.nn.Linear(2, 2)
        self.linear_b = torch.nn.Linear(2, 2)
        self.relu = MyReLU.apply
    def forward(self, x):
        h = self.linear_a(x)
        h = self.relu(h, (5, 3), 2, [1, 2, 3])
        h = self.linear_b(h)
        return h

"""
User define how to export prim::PythonOp into custom op.
"""
def symbolic_pythonop(g, n, *args, **kwargs):
    # Print information:
    print('arguments of ', kwargs['name'], ':')
    print('original node: ', n)
    for i, out in enumerate(n.outputs()):
        print('original output {}: {}, requires grad: {}'.format(i, out, out.requiresGrad()))
    import torch.onnx.symbolic_helper as sym_helper
    for i, arg in enumerate(args):
        print('arg {}: {}, requires grad: {}'.format(i, arg, arg.requiresGrad() if sym_helper._is_value(arg) else False))
    for k, v in kwargs.items():
        print('key: ', k, ' v: ', v)

    # TODO: all inputs (tensors and scalars) are in args.
    #       backend can define CustomDomain::PythonOp and how info are stored however it deem fit.
    return g.op("CustomDomain::PythonOp", args[0], name_s=kwargs['name'])

torch.onnx.register_custom_op_symbolic("::prim_PythonOp", symbolic_pythonop, 9)

# Define input.
x = torch.tensor([[0.3971, 0.7544],
                  [0.5695, 0.4388]], requires_grad=True)

model = MyModule()
# Forward.
y = model(x)

torch.onnx.export(model, (x,), 'model.onnx', opset_version=12, verbose=True)
```

Test Plan: Imported from OSS

Reviewed By: malfet

Differential Revision: D28393528

Pulled By: SplitInfinity

fbshipit-source-id: e0d55b7c737c5916fda08a3b26b3306037f970df

Co-authored-by: BowenBao <bowbao@microsoft.com>
2021-05-13 13:42:49 -07:00
BowenBao
2b0f481d3f Add support to to(device) op. (#56857) (#57599)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/57599

Currently, if we call tensor.to() method and pass a device as the parameter. It will fail, because in symbolic function of to() we didn't handle such case.

So add a check in the beginning of this symbolic function, if this is a device cast, we return self directly. A test has also been added.

Test Plan: Imported from OSS

Reviewed By: malfet

Differential Revision: D28393523

Pulled By: SplitInfinity

fbshipit-source-id: c41e3c0293932fc90dedb544daadd9c5d4b48792

Co-authored-by: Jay Zhang <jiz@microsoft.com>
2021-05-13 13:42:48 -07:00
BowenBao
9e56314d2c onnx.symbolic_helper.parse_args: document and clean up (#56956) (#57598)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/57598

Add a doc string to explain what it does and how to use it.

Remove hack around a bug in Python 2's functools.wrap().
Python 2 is no longer supported.

Test Plan: Imported from OSS

Reviewed By: malfet

Differential Revision: D28393519

Pulled By: SplitInfinity

fbshipit-source-id: aae8c5e7b49e2ad2d24a0e86f8ba47f1cd080e46

Co-authored-by: Gary Miguel <garymiguel@microsoft.com>
2021-05-13 13:42:46 -07:00
BowenBao
dc0071dfa5 [ONNX] Special post process for onnx::Cast and onnx::ConstantOfShape shape type inference (#55962) (#57597)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/57597

* Special post process for onnx::Cast and onnx::ConstantOfShape
* Update `test_pytorch_onnx_shape_inference.py` to be unit test over shape inference patterns.

Test Plan: Imported from OSS

Reviewed By: malfet

Differential Revision: D28393529

Pulled By: SplitInfinity

fbshipit-source-id: fc26032ddb842d4e299447da39564b28049752ed

Co-authored-by: BowenBao <bowbao@microsoft.com>
2021-05-13 13:42:44 -07:00
BowenBao
ac9e79e561 Add a new operator for fill_() function. (#56859) (#57596)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/57596

Add the corresponding symbolic function and test for fill_() function.

Test Plan: Imported from OSS

Reviewed By: malfet

Differential Revision: D28393520

Pulled By: SplitInfinity

fbshipit-source-id: 3e177f88d3776d0d4a9d5e7ec7df4e6629738799

Co-authored-by: Jay Zhang <jiz@microsoft.com>
2021-05-13 13:42:43 -07:00
BowenBao
6d7fe76317 [ONNX] Warning when using __len__ to calculate tensor shape (#55151) (#57595)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/57595

Difference in traced graph and outputs, when using len(tensor) as compared to tensor.shape[0]

An example model is (with tensor.shape):
```
# Test len fix with variable inputs
import torch
import onnxruntime

class Model(torch.nn.Module):
    def forward(self, x):
        return x.size(1) + x.shape[0]

# Call export
dummy_x = torch.randn(3, 5)
model = Model()

import io
onnx_io = io.BytesIO()
torch.onnx.export(model, (dummy_x,), onnx_io,
                  input_names=['input'],
                  dynamic_axes={'input': {0:'h'}},
                  verbose=True)

# Call onnxruntime runtime and compare outputs on dynamic inputs
ort_session = onnxruntime.InferenceSession(onnx_io.getvalue())

x = torch.randn(2, 5)
print(model(x))
print(ort_session.run(None, {ort_session.get_inputs()[0].name: x.numpy()}))
```
The output graph is as follows:
```
graph(%input : Float(*, 5, strides=[5, 1], requires_grad=0, device=cpu)):
  %1 : Long(2, strides=[1], device=cpu) = onnx::Shape(%input)
  %2 : Long(device=cpu) = onnx::Constant[value={1}]()
  %3 : Long(device=cpu) = onnx::Gather[axis=0](%1, %2) # test/onnx/test_m.py:9:0
  %4 : Long(2, strides=[1], device=cpu) = onnx::Shape(%input)
  %5 : Long(device=cpu) = onnx::Constant[value={0}]()
  %6 : Long(device=cpu) = onnx::Gather[axis=0](%4, %5) # test/onnx/test_m.py:9:0
  %7 : Long(requires_grad=0, device=cpu) = onnx::Add(%3, %6) # test/onnx/test_m.py:9:0
  return (%7)
```
Torch output: 7
ORT output: 7

Now replacing tensor.shape[0] with len(tensor), the graph looks like:
```
graph(%input : Float(*, 5, strides=[5, 1], requires_grad=0, device=cpu)):
  %1 : Long(2, strides=[1], device=cpu) = onnx::Shape(%input)
  %2 : Long(device=cpu) = onnx::Constant[value={1}]()
  %3 : Long(device=cpu) = onnx::Gather[axis=0](%1, %2) # test/onnx/test_m.py:9:0
  %4 : Long(requires_grad=0, device=cpu) = onnx::Constant[value={3}]()
  %5 : Long(requires_grad=0, device=cpu) = onnx::Add(%3, %4)
  return (%5)
```
Torch output: 7
ORT output: 8

In the case with __len__, %4 is traced as a constant

**Workaround to avoid the mismatch when using len to get tensor.shape**

Add the following pattern around _export call
```
    import builtins
    len_backup = builtins.len
    builtins.len = lambda x : x.__len__()

    # Call export
    _export(model, args, .....

    builtins.len = len_backup

```

Test Plan: Imported from OSS

Reviewed By: malfet

Differential Revision: D28393526

Pulled By: SplitInfinity

fbshipit-source-id: a7d50740442c7e913119f9f92deab48aa8c02843

Co-authored-by: shubhambhokare1 <shubhambhokare1@gmail.com>
2021-05-13 13:42:41 -07:00
BowenBao
3bc8a2264d [ONNX] Support .item() export & NumberType to tensor conversion (#55697) (#57594)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/57594

Support .item() export & NumberType to tensor conversion

Test Plan: Imported from OSS

Reviewed By: malfet

Differential Revision: D28393516

Pulled By: SplitInfinity

fbshipit-source-id: 94d0aec0a8fe144ee2567dc3c9c19fcb18ed21fa

Co-authored-by: BowenBao <bowbao@microsoft.com>
2021-05-13 13:41:29 -07:00
Sam Estep
061c7a1e17 Overwrite with ln if libc10.so already exists (#58243)
Summary:
This should fix the issue noted in https://github.com/pytorch/pytorch/pull/57622#issuecomment-840612300 and demonstrated in [this run](https://github.com/pytorch/pytorch/runs/2566809365). Please review this PR carefully, because I do not know enough context to know whether this is the right thing to do.

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

Test Plan: n/a

Reviewed By: walterddr

Differential Revision: D28414358

Pulled By: samestep

fbshipit-source-id: 0eb1c598f353ebac7f0a85c290be6fce4e00b6d5
2021-05-13 13:31:29 -07:00
albanD
9b95568dc3 update abs forward ad formula (#58235)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/58235

this is to make the opinfo change python only

Test Plan: Imported from OSS

Reviewed By: ejguan

Differential Revision: D28412937

Pulled By: albanD

fbshipit-source-id: 1d6eb1e4baaa837c300ee8aa00b57986ba3e3eb2
2021-05-13 13:19:27 -07:00
albanD
3c4a90ce38 Revert "Revert D28387764: Codegen inplace forward AD formula from out of place one if needed" (#58231)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/58231

This reverts commit 066e7699eb.

Test Plan: Imported from OSS

Reviewed By: ejguan

Differential Revision: D28412480

Pulled By: albanD

fbshipit-source-id: 7a231aa81b9e89537e6dca19642c4f12cd4b5ea5
2021-05-13 13:18:16 -07:00
Xue Haotian
098d9975a7 Port heaviside to structured kernel (#57933)
Summary:
Port heaviside to structured kernel
Related https://github.com/pytorch/pytorch/issues/55070

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

Reviewed By: mruberry

Differential Revision: D28362533

Pulled By: ezyang

fbshipit-source-id: 96b4591db3f609434784bd0ef9e54c61c918fb88
2021-05-13 10:48:11 -07:00
anjali411
770f8cea2d Add support for real and imag tensor attributes (#54692)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/54692

Test Plan: Imported from OSS

Reviewed By: ejguan

Differential Revision: D28412240

Pulled By: anjali411

fbshipit-source-id: e6965c55539a44260a812fdaa4a982f02067bb05
2021-05-13 10:44:27 -07:00
Lijiang Fang
8888565597 T90561249: Enforce kernel launch checks (#58178)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/58178

https://www.internalfb.com/T90561249: change the test to enforce

Test Plan:
buck test //caffe2/test:kernel_launch_checks

before fixing LinearAlgebra.cu and file close: https://www.internalfb.com/intern/testinfra/testconsole/testrun/1970324893386017/

after: https://www.internalfb.com/intern/testinfra/testconsole/testrun/2814749824394650/

Reviewed By: r-barnes

Differential Revision: D28390166

fbshipit-source-id: 8a217ce8c0b204922005c731aa38bc03f70fabcc
2021-05-13 10:41:20 -07:00
Jacob Szwejbka
1de9f51782 [Pytorch Edge] Runtime ops compatibility api (#57570)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/57570

Move runtime ops compatibility api to OSS and introduce schema information
ghstack-source-id: 128789159

Test Plan: unit test and manually ran it for a runtime with all (non custom) ops, and the bixray models unittest {P412728176}

Reviewed By: raziel

Differential Revision: D28203104

fbshipit-source-id: 432a7d0247bccfb2e1ce90e8d41f81596efa3d67
2021-05-13 10:20:41 -07:00
Eli Uriegas
2294fd61c6 .github: Add windows.4xlarge to scale-config.yml (#58198)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/58198

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

Test Plan: Imported from OSS

Reviewed By: samestep

Differential Revision: D28401791

Pulled By: seemethere

fbshipit-source-id: dabaf58417114cc6138feca26d0121036476e04b
2021-05-13 10:07:22 -07:00
lezcano
d8c6b74b0b Deprecate torch.solve (#57741)
Summary:
Deprecate deprecate deprecate.

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

Reviewed By: agolynski

Differential Revision: D28379337

Pulled By: mruberry

fbshipit-source-id: a7a35ce1d3f25d8593698d89761c6c2d940db31a
2021-05-13 09:54:21 -07:00
nikithamalgi
020e2ff115 Add tests for PDT (#58211)
Summary:
This is a duplicate of the PR https://github.com/pytorch/pytorch/issues/56029

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

Reviewed By: gmagogsfm

Differential Revision: D28403903

Pulled By: nikithamalgifb

fbshipit-source-id: 290c46709c77c1a6fd647a2348419d12bf0a5ed6
2021-05-13 09:51:09 -07:00
Ivan Yashchuk
5e65428503 Fix NumPy compatibility issue for torch.linalg.cond (#58041)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/58041

The shape of the returned result was different for NumPy and PyTorch for
`ord={-2, 2, None}`. Now it's fixed.

Test Plan: Imported from OSS

Reviewed By: ngimel

Differential Revision: D28405147

Pulled By: mruberry

fbshipit-source-id: 30293a017a0c0a7e9e3aabd470386235fef7b6a6
2021-05-13 09:42:18 -07:00
Ivan Yashchuk
a49406b331 Fixed batched version of torch.linalg.cond for singular inputs (#58040)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/58040

This PR uses `torch.linalg.inv_ex` to determine the non-invertible
inputs and return the condition number of infinity for such inputs.

Added OpInfo entry for `torch.linalg.cond`.

Test Plan: Imported from OSS

Reviewed By: ngimel

Differential Revision: D28405146

Pulled By: mruberry

fbshipit-source-id: 524b9a38309851fa6461cb787ef3fba5aa7d5328
2021-05-13 09:42:17 -07:00
Ivan Yashchuk
c1430c3425 Add torch.linalg.inv_ex without checking for errors by default (#58039)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/58039

The new function has the following signature
`inv_ex(Tensor inpit, *, bool check_errors=False) -> (Tensor inverse, Tensor info)`.
When `check_errors=True`, an error is thrown if the matrix is not invertible; `check_errors=False` - responsibility for checking the result is on the user.

`linalg_inv` is implemented using calls to `linalg_inv_ex` now.

Resolves https://github.com/pytorch/pytorch/issues/25095

Test Plan: Imported from OSS

Reviewed By: ngimel

Differential Revision: D28405148

Pulled By: mruberry

fbshipit-source-id: b8563a6c59048cb81e206932eb2f6cf489fd8531
2021-05-13 09:42:15 -07:00
lezcano
9e156b01e5 linalg.eig backwards and linalg.eigvals (#57276)
Summary:
This PR adds backwards support for `eig` and `eigvals`.

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

Reviewed By: ngimel

Differential Revision: D28405056

Pulled By: mruberry

fbshipit-source-id: 27ef03f139f44d75f4d319b0f3e77e99eea9bb01
2021-05-13 09:42:13 -07:00
Nikita Shulga
2afcb7e8fd Move Azure MultiGPU tests back to nightly (#58242)
Summary:
As its currently broken on master

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

Reviewed By: samestep

Differential Revision: D28414152

Pulled By: malfet

fbshipit-source-id: 2566be294d62e39f9f7d316a039ab9372d685577
2021-05-13 09:41:02 -07:00
Yi Wang
e507771294 [RPC Framework] Replace Python Pickler with internal RPC pickler for RemoteModule (#58019)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/58019

In order to support sending `RemoteModule` over PRC, previously the pickling/unpickling of `RemoteModule` was implemented based on `__setstate__` and `__getstate__`. However, this means that the user can call regular Python pickler/unpickler to invoke the same logic,which should not be allowed.

This PR ensures that the pickling can only happen over RPC and not via regular python pickle.

Additionally, when a new attribute is added to `RemoteModule`, if it's not added to either `_REMOTE_MODULE_PICKLED_ATTRIBUTES` or `_REMOTE_MODULE_ATTRIBUTES_IGNORE_FOR_PICKLING`, this attribute will be ignored and an error message will be printed to std.err. However, it will not raise an exception like before, because such exception raised at the RPC layer will somehow cause timeout.

#Closes: https://github.com/pytorch/pytorch/issues/57516
ghstack-source-id: 128868501

Test Plan:
buck test mode/dev-nosan caffe2/test/distributed/rpc:process_group_agent -- test_send_remote_module_over_the_wire
buck test mode/dev-nosan caffe2/test/distributed/rpc:process_group_agent -- test_remote_module_py_pickle_not_supported
buck test mode/dev-nosan caffe2/test/distributed/rpc:process_group_agent -- test_send_remote_module_with_a_new_attribute_ignored_over_the_wire
buck test mode/dev-nosan caffe2/test/distributed/rpc:process_group_agent -- RemoteModule

buck test mode/dev-nosan //caffe2/torch/fb/csrc/concurrency/test:atomic_int_interprocess_test -- --exact 'caffe2/torch/fb/csrc/concurrency/test:atomic_int_interprocess_test - test_multiple_processes (caffe2.torch.fb.csrc.concurrency.test.atomic_int_interprocess_test.ForkMultipleProcessTest)'
buck test mode/dev //caffe2/torch/distributed/fb/test:app_test -- --exact 'caffe2/torch/distributed/fb/test:app_test - test_custom_init_rpc (caffe2.torch.distributed.fb.test.app_test.TestRpc)'

Reviewed By: mrshenli

Differential Revision: D28318270

fbshipit-source-id: 7e7df2a6690f0860c4531a244d38789db424496f
2021-05-13 09:37:42 -07:00
Mikhail Zolotukhin
470cd64514 [TensorExpr] Remove disabled tests that we do not plan to re-enable. (#58207)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/58207

We probably don't even know what these tests check and there are no
plans on re-enabling them - let's just nuke them to keep the code clean.

Test Plan: Imported from OSS

Reviewed By: bertmaher

Differential Revision: D28403251

Pulled By: ZolotukhinM

fbshipit-source-id: fe12e978636a74f309f57e3408ab78d459fe4d29
2021-05-13 09:19:20 -07:00
Mikhail Zolotukhin
a0f4b7cd48 [TensorExpr] Re-enable skipped tests, they seem to be working now. (#58206)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/58206

Tested on CUDA with and without `PYTORCH_TENSOREXPR_DONT_USE_LLVM=1`.

Closes #48053.

Test Plan: Imported from OSS

Reviewed By: bertmaher

Differential Revision: D28403250

Pulled By: ZolotukhinM

fbshipit-source-id: 1ae1cfed691e0077a37db646937e580fbd32b23f
2021-05-13 09:18:09 -07:00
Edmund Chang
dd3bd0286b T89509943 - Improve error message during Glow ONNXIFI (#58069)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/58069

We want to tell user 5821 means ONNXIFI_EVENT_STATE_NONSIGNALLED in the error message.

Added that status code to the mapping and the error message output.

Reviewed By: hl475

Differential Revision: D28359864

fbshipit-source-id: 87f50ddd4ded9ced03ec6af6a1a4ef85bd2195d6
2021-05-13 09:02:36 -07:00
Jeffrey Wan
e71b526e7e Add inference mode python bindings and tests (#58045)
Summary:
Fixes https://github.com/pytorch/pytorch/issues/56608

 - Adds binding to the `c10::InferenceMode` RAII class in `torch._C._autograd.InferenceMode` through pybind. Also binds the `torch.is_inference_mode` function.
 - Adds context manager `torch.inference_mode` to manage an instance of `c10::InferenceMode` (global).  Implemented in `torch.autograd.grad_mode.py` to reuse the `_DecoratorContextManager` class.
 - Adds some tests based on those linked in the issue + several more for just the context manager

Issues/todos (not necessarily for this PR):
- Improve short inference mode description
- Small example
- Improved testing since there is no direct way of checking TLS/dispatch keys
-

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

Reviewed By: agolynski

Differential Revision: D28390595

Pulled By: soulitzer

fbshipit-source-id: ae98fa036c6a2cf7f56e0fd4c352ff804904752c
2021-05-13 08:55:35 -07:00
Rong Rong (AI Infra)
002ce5c1df port addmm to structure kernel (#57417)
Summary:
Port addmm to structure kernel

Follow ups
- migrate `mm` and `addbmm` to structure
- move TORCH_CHECKS currently in `addmm_cpu_impl_` and `addmm_out_cuda_impl` to meta

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

Reviewed By: bdhirsh

Differential Revision: D28291001

Pulled By: walterddr

fbshipit-source-id: 4eafaa30a465e225fbb4d2a69a36f1e037df9122
2021-05-13 08:33:42 -07:00
Jeff Daily
52e9a192b1 [ROCm] add 4.2 to nightly builds (#58143)
Summary:
Depends on https://github.com/pytorch/builder/pull/764.

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

Reviewed By: agolynski

Differential Revision: D28385532

Pulled By: malfet

fbshipit-source-id: 1a37b1d4636327f8e1d0d5cfaa03f652565f8e38
2021-05-13 08:14:23 -07:00
Gregory Chanan
e8574b84bf Fix legacy tensor constructor/new matching incorrect signature with d… (#58108)
Summary:
…evice.

Previously, it was possible for torch.Tensor(tensor, device) or Tensor.new(tensor, device) to map to IntArrayRef or PyObject*.

PyObject* was not a problem because that would error out later.
But IntArrayRef would create an uninitialized tensor, which is confusing.

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

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

Reviewed By: agolynski, mruberry

Differential Revision: D28372426

Pulled By: gchanan

fbshipit-source-id: 795ab4f0561939d002a661c5cc14c6cdb579f31a
2021-05-13 08:11:08 -07:00
anjali411
ab5c273950 Remove the matmul complex backward skip (#58138)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/58138

related https://github.com/pytorch/pytorch/issues/55754

Test Plan: Imported from OSS

Reviewed By: pbelevich

Differential Revision: D28403156

Pulled By: anjali411

fbshipit-source-id: dca4dd643f190b314a8a4c01c698c6a1e5229f6f
2021-05-13 07:48:08 -07:00
mfkasim91
cf7d56d8f2 Gradgradcheck to runs successfully with unrelated inputs (#58049)
Summary:
Fixes https://github.com/pytorch/pytorch/issues/57649

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

Reviewed By: agolynski

Differential Revision: D28390033

Pulled By: albanD

fbshipit-source-id: a0809b918321f3ea6fc59bfbec1f37e566d3611d
2021-05-13 06:42:29 -07:00
Ilia Cherniavskii
6997e7bd39 Update Kineto submodule (#58179)
Summary:
Update Kineto submodule, minor api changes

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

Test Plan: CI

Reviewed By: gdankel

Differential Revision: D28391369

Pulled By: ilia-cher

fbshipit-source-id: 61fbf63d9ec2db66fac203944679e4b99cb0d568
2021-05-13 04:03:04 -07:00
Ilia Cherniavskii
2b99bce1d7 [profiler] CUDA event fallback (#58133)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/58133

Adding CUDA event fallback for cases when CUPTI tracing is not
available, this corresponds to the legacy profiler GPU profiling

Test Plan: python test/test_profiler.py -v

Reviewed By: gdankel

Differential Revision: D28379596

Pulled By: ilia-cher

fbshipit-source-id: 2db3b2cd8c1c3e6e596784ab00a226c69db2ef27
2021-05-13 03:41:03 -07:00
Tugsbayasgalan (Tugsuu) Manlaibaatar
fee7e8b91d Striding for lists Part 2 (#49352)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/49352

In this PR, we replace all definitions of slice to take None parameters for the start, end, and step. This will simplify the compiler logic

Test Plan:
test_jit test cases

Imported from OSS

Reviewed By: jamesr66a, nikithamalgifb

Differential Revision: D25929903

fbshipit-source-id: 5bfc6bad514a8aafbef2dacc706f95f867fe85f1
2021-05-13 00:16:02 -07:00