Commit Graph

20 Commits

Author SHA1 Message Date
Jiewen Tan
3c2676de3d [LTC] Restore GetPythonFrames (#89122)
Summary:
pytorch/pytorch@936e930 delete the registration of GetPythonFramesFunction. Restore that and add a test case to prevent regression.

Test Plan:
python test/lazy/test_debug_util.py

Fixes pytorch/xla#4206.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/89122
Approved by: https://github.com/JackCaoG
2022-11-18 03:37:14 +00:00
Jiewen Tan
3b8245ab12 [LTC] Make ComputePostOrder accept const T pointers (#88773)
Summary:
Since `c10::ArrayRef` now support `c10::ArrayRef<const T>`, let's restore `ComputePostOrder` to accept `const Node*` again, which is more suitable for the context of the given helpers.

Test Plan:
CI.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/88773
Approved by: https://github.com/JackCaoG
2022-11-10 18:34:19 +00:00
Sahan Paliskara
936e93058b Delete torch::deploy from pytorch core (#85953)
As we have migrated torch::deploy over to https://github.com/pytorch/multipy, we can now delete it from pytorch core as ongoing development will happen there.

This PR was created due to syncing issues with https://github.com/pytorch/pytorch/pull/85443 which is where the review history can be found.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/85953
Approved by: https://github.com/seemethere, https://github.com/malfet
2022-10-06 07:20:16 +00:00
Antonio Kim
bab1304f59 Add step closures (#84300)
Ports over the step closure functionality from PyTorch/XLA to Lazy Tensor Core:

References:
205ae574c0/torch_xla/core/xla_model.py (L852-L900)
205ae574c0/torch_xla/utils/closures.py (L7-L83)

CC: @wconstab @JackCaoG @Krovatkin
Pull Request resolved: https://github.com/pytorch/pytorch/pull/84300
Approved by: https://github.com/JackCaoG, https://github.com/wconstab
2022-09-06 20:55:34 +00:00
Nikolay Korovaiko
d9ff56ccc0 python bindings for create_metric_report (#79679)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/79679
Approved by: https://github.com/JackCaoG, https://github.com/wconstab
2022-07-06 20:06:17 +00:00
Brian Hirsh
c2d395cf8e functionalization <> LTC integration (take 3) (#80251)
new PR for https://github.com/pytorch/pytorch/pull/75527.

It looks like there's a bug in the windows CI scripts that was causing
flaky failures, that disappear when I create a new PR. example failure:
https://github.com/pytorch/pytorch/runs/6999272635?check_suite_focus=true
Pull Request resolved: https://github.com/pytorch/pytorch/pull/80251
Approved by: https://github.com/wconstab
2022-06-26 23:10:21 +00:00
Michael Suo
30fb2c4aba [lint] autoformat test/cpp and torch/csrc
Let's have some fun.

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

Approved by: https://github.com/ezyang
2022-06-11 21:11:16 +00:00
John Clow
73480bcbe0 Adding support for nonzero in LazyTensor shape functions
Pull Request resolved: https://github.com/pytorch/pytorch/pull/77572

Approved by: https://github.com/Krovatkin
2022-05-18 17:32:48 +00:00
Bin Bao
25c6ebd12c Revert "Revert "[LT] Codegen ReuseNode for supported ops""
Summary: Fixed a XLC build failure by generating an always-return-false
default CanBeReused method.

This reverts commit 3cade9d454.

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

Approved by: https://github.com/alanwaketan
2022-05-16 20:14:42 +00:00
PyTorch MergeBot
3cade9d454 Revert "[LT] Codegen ReuseNode for supported ops"
This reverts commit 6066e5929f.

Reverted https://github.com/pytorch/pytorch/pull/76738 on behalf of https://github.com/malfet
2022-05-14 00:33:10 +00:00
Bin Bao
6066e5929f [LT] Codegen ReuseNode for supported ops
Summary:
1. Update the codegen script to add a TrieCache lookup (ReuseNode)
before creating a new IR node. The following is an example generated
code,

```
    at::Tensor LazyNativeFunctions::add(const at::Tensor & self, const at::Tensor & other, const at::Scalar & alpha) {
        ...
        torch::lazy::NodePtr node = torch::lazy::ReuseNode<AddTensor>(lazy_self->GetIrValue(), lazy_other->GetIrValue(), node_alpha);
        if (!node) {
            auto out_meta = at::meta::add(self, other, alpha);
            std::vector<Shape> shapes{Shape(out_meta.scalar_type(), out_meta.sizes().vec())};
            TORCH_INTERNAL_ASSERT(shapes.size() == 1);
            if(symbolicShapeEnabled()){
                std::vector<jit::IValue> inputs = { self, other, alpha };
                char* schema_str = "aten::add.Tensor(Tensor self, Tensor other, *, Scalar alpha=1) -> Tensor";
                applySymbolicShapesOnLT(schema_str, inputs, shapes);
            }

            node = torch::lazy::MakeNode<AddTensor>(lazy_self->GetIrValue(), lazy_other->GetIrValue(), node_alpha, std::move(shapes));
            CacheNode(node);
        }
        ...
    }
```
2. TrieCache lookup depends on each IR node subclass to provide its own
comparison function. The following is an example generated code,

```
  bool CanBeReused(const torch::lazy::Value& self, const torch::lazy::Value& other, const torch::lazy::Value& alpha) const {
    size_t i = 0;
    return (operand(i++) == self &&
        operand(i++) == other &&
        operand(i++) == alpha);
  }
```

3. DeviceData is specially handled.

4. Non-codegen op changes are coming a separate PR.

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

Approved by: https://github.com/JackCaoG, https://github.com/wconstab
2022-05-13 19:13:58 +00:00
Bin Bao
65b9778d30 [LT] Add a flag to control IR reusing
Pull Request resolved: https://github.com/pytorch/pytorch/pull/76488

Approved by: https://github.com/wconstab, https://github.com/JackCaoG
2022-05-03 14:48:15 +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
Will Constable
a4ce113649 Avoid compiling ts backend binidngs in fbcode build
Fixes #ISSUE_NUMBER

Pull Request resolved: https://github.com/pytorch/pytorch/pull/76337
Approved by: https://github.com/shunting314
2022-04-25 21:45:54 +00:00
Shunting Zhang
a9d43d6f6e Dynamo+LTC: add pybind to set force fallback config and use that in test_extract_compiled_graph.py (#75292)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/75292

- Follow the convention in [this doc](https://docs.google.com/document/d/1Vi96ITGoK7BW01ZEccexs4pvCQKF4_LdV8w7TfIWPvM/edit) to setup config for ltc force fallback ops.
- Pybinds are added to read/set the config.
- Use the added pybinds in the unit test which needs to force fallbacks.

Test Plan:
```
pytest test/lazy/test_extract_compiled_graph.py
```

Reviewed By: malfet

Differential Revision: D35417678

Pulled By: shunting314

fbshipit-source-id: 1e05b8c831174872d70257a0ddd958863d6ca80d
(cherry picked from commit 9366bde7ef20837dcf03b7d8e18f9017a58c80fa)
2022-04-07 02:39:20 +00:00
Will Constable
22d227fd29 Fix lazy ts backend build flags (#75237)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/75237

applies 'OVRSOURCE' logic to one more place missed in D35331263 (8b7e2bf7a6) so that lazy TS backend is not compiled in internal builds

Test Plan: CI

Reviewed By: malfet, shunting314

Differential Revision: D35377758

fbshipit-source-id: 5dcd3d36e50a8917470a917f2120353972dc31ba
(cherry picked from commit 8b8ed7bdaa553eec2ef8b5461d1bd867979049dd)
2022-04-05 00:46:00 +00:00
Nikita Shulga
8b7e2bf7a6 Skip TorchScript backend for OVRSource as well (#75138)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/75138

(Note: this ignores all push blocking failures!)

Test Plan: CI

Reviewed By: wconstab

Differential Revision: D35331263

fbshipit-source-id: e426c4017359c9f98188c0df5226775be7b1f700
(cherry picked from commit bf1768f3be06e9de643978d70591d9cd15ef11b3)
2022-04-02 04:01:57 +00:00
Shunting Zhang
19747cbbe6 Dynamo+LTC: merging related code from staging branch to master (#75046)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/75046

Merge the code needed for dynamic+ltc integration from the staging branch to the master branch.

Test Plan:
Unit test
```
pytest test_extract_compiled_graph
```
test thru dynamo
```
LTC_TS_CUDA=1 time python torchbench.py --speedup-ltc -dcuda --nvfuser --randomize-input --only <model name>
```

Reviewed By: alanwaketan

Differential Revision: D35300646

Pulled By: shunting314

fbshipit-source-id: 09ed20d3bb8ef80e4b93ba87ea3356a07d2dccdb
(cherry picked from commit 2b56771cdfd2cfa825c65ee9fd42338fb372fb32)
2022-04-02 00:23:15 +00:00
Will Constable
ff206ed09e Add lazy tensor python bindings (#74508)
Summary:
This adds a minimal set of python bindings for lazy tensor and the torchscript backend.

It targets the APIs that are used by the `test_ts_opinfo.py` test (which it also lands, from lazy_tensor_staging, where it is [lazy_tensor_core/test/test_lazy.py](https://github.com/pytorch/pytorch/blob/lazy_tensor_staging/lazy_tensor_core/test/test_lazy.py)).

We should land more python bindings obviously.  I just wanted to focus on a minimal set that can also be tested, and use it to agree on how we organize the bindings, then others could easily contribute bindings on top of this infrastructure.

cc JackCaoG

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

Reviewed By: pbelevich

Differential Revision: D35032152

Pulled By: wconstab

fbshipit-source-id: 526505ab355b7ad27037ece0ff814b2a4b69f1e2
(cherry picked from commit b4f73dd147472cb38003204aff228087c0230fda)
2022-03-29 13:40:11 +00:00
Will Constable
328cfd50e7 Move debug_util and python_util to torch/csrc/lazy (#72607)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/72607

since python isn't available from libtorch, most of lazy tensor
code can't depend on python.
separate python_util into libtorch_python library
make debug_util and IR dump work with or without python by providing
a default function for 'maybe getting python stacktrace' that returns
an empty stacktrace
use a registration mechanism on libtorch_python library load to update
the 'maybe' function to use the real python stacktrace getter

Test Plan:
OSS build tests:
- test_ptltc by itself works
- LTC_SAVE_TENSORS_FILE=log test_ptltc works, and log contains
empty stacktrces
- python examply.py by itself works
- LTC_SAVE_TENSORS_FILE=log test_ptltc works, and log contains
real stacktraces

fbcode build: rely on CI to run test/lazy

Reviewed By: desertfire

Differential Revision: D34115046

fbshipit-source-id: 8d6222963c146da36b3c1b5ff8a638bbc3f1442e
(cherry picked from commit 3717688ade)
2022-02-11 18:00:40 +00:00