pytorch/torch/_lazy/debug.py
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

21 lines
722 B
Python

import torch._C._lazy
def render_ir_graph(tensors):
"""Return a text dump of the LTC IR graph in dot format for the tensors.
The text can be processed by tools like dot to be rendered in pdf,png etc."""
return torch._C._lazy._get_tensors_dot(tensors)
def dump_ir(tensors, ir_format):
"""Return a dump of the tensors in the specified format.
Valid format are
- text: for LTC IR
- backend: for the activate backend IR
"""
if ir_format == "text":
return torch._C._lazy._get_tensors_text(tensors)
elif ir_format == "backend":
return torch._C._lazy._get_tensors_backend(tensors)
else:
raise RuntimeError(f"Unrecognized IR format: {ir_format}")