-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
151 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# DeepVisor | ||
DeepVisor is a JIT compiler for PyTorch programs. It can extract the operator graph from PyTorch programs and optimize the graph with a wide range of deep learning graph compilers. | ||
|
||
# Installation | ||
DeepVisor now supports Python 3.9. The support of other Python versions is working in progress. | ||
|
||
1. Install CUDA. CUDA 11.8 is recommended. | ||
2. Install dependencies: | ||
```bash | ||
pip install -r requirements.txt -f https://download.pytorch.org/whl/torch_stable.html | ||
``` | ||
3. Install DeepVisor: | ||
```bash | ||
pip install -e . | ||
``` | ||
4. Compile a shared library to disable Python integer cache by LD_PRELOAD. This script will generates a ``ldlong.v3.9.12.so'' file in build/ directory. You need to set the LD_PRELOAD environment variable to this file when running the PyTorch program. | ||
```bash | ||
cd scripts | ||
./compile_longobj.sh | ||
``` | ||
|
||
# Example Usage | ||
|
||
The following script compiles and runs a simple PyTorch program with DeepVisor. | ||
|
||
```python | ||
LD_PRELOAD=build/ldlong.v3.9.12.so python test/example.py | ||
``` | ||
|
||
# Citation | ||
If you find DeepVisor useful in your research, please consider citing the following paper: | ||
|
||
> DeepVisor: Effective Operator Graph Instantiation for Deep Learning by Execution State Monitoring; Chen Zhang, Rongchao Dong, Haojie Wang, Runxin Zhong, Jike Chen, and Jidong Zhai, Tsinghua University; will be appeared in USENIX ATC'24. | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import torch | ||
from frontend.compile import compile | ||
from frontend.utils import SetConfig | ||
|
||
|
||
class Example(torch.nn.Module): | ||
|
||
def __init__(self): | ||
super(Example, self).__init__() | ||
self.conv = torch.nn.Conv2d(3, 3, 3) | ||
self.relu = torch.nn.ReLU() | ||
|
||
def forward(self, x): | ||
x = self.conv(x) | ||
x = self.relu(x) | ||
return x | ||
|
||
|
||
with torch.no_grad(): | ||
model = Example().eval() | ||
x = torch.randn(1, 3, 4, 4) | ||
expect_output = model(x) | ||
print("expect:", expect_output) | ||
|
||
# set the graph compiler to inductor | ||
with SetConfig({'backend': 'inductor'}): | ||
compiled = compile(model) | ||
# run the python code to compile the model. The fx graph and the guards will be printed out | ||
output1 = compiled(x) | ||
print("output1:", output1) | ||
|
||
# run the compiled model. "guard cache hit" means we find the compiled record and use it directly | ||
output2 = compiled(x) | ||
print("output2", output2) | ||
assert torch.allclose(expect_output, output1) | ||
assert torch.allclose(expect_output, output2) |