VertexC opened a new issue #7399:
URL: https://github.com/apache/tvm/issues/7399
Hi,
I am doing some perf analysis on TVM and find compile pytorch model multiple
time seems to have memory leak.
Here is the script. I am using latest tvm `commit f786` compiled with
clang+llvm-11.0.1-x86_64-linux-gnu-ubuntu-16.04.
```python
import os, psutil
import numpy as np
from tvm import relay
from tvm.relay import testing
import tvm
from tvm import te
from tvm.contrib import graph_runtime
import tvm.testing
import torch
import torchvision
def tvm_build():
input_name = "input0"
shape = [1, 3, 224, 224]
data = torch.randn(shape, dtype=torch.float32)
model = torchvision.models.resnet50(pretrained=False, progress=True)
shape_list = [(input_name, data.shape)]
scripted_model = torch.jit.trace(model, data).eval()
mod, params = relay.frontend.from_pytorch(scripted_model, shape_list)
# TODO: how opt_level affects performance
opt_level = 3
with tvm.transform.PassContext(opt_level=opt_level):
lib = relay.build(mod,
target='llvm',
target_host='llvm',
params=params)
ctx = tvm.cpu()
module = graph_runtime.GraphModule(lib["default"](ctx))
module.set_input(input_name, data)
def main():
process = psutil.Process(os.getpid())
print('Used Memory before building:', process.memory_info().rss / 1024 /
1024, 'MB')
total = 10
for i in range(0, total+1):
tvm_build()
print('Used Memory after building {} times:'.format(i+1),
process.memory_info().rss / 1024 / 1024, 'MB')
if __name__ == "__main__":
main()
```
And the result show the memory usage continue to increase
```bash
Used Memory after building 1 times: 817.33203125 MB
Used Memory after building 2 times: 943.7734375 MB
Used Memory after building 3 times: 1086.84765625 MB
Used Memory after building 4 times: 1276.97265625 MB
Used Memory after building 5 times: 1503.7109375 MB
Used Memory after building 6 times: 1504.33984375 MB
Used Memory after building 7 times: 1662.96875 MB
Used Memory after building 8 times: 1879.96875 MB
Used Memory after building 9 times: 1880.83984375 MB
Used Memory after building 10 times: 1964.89453125 MB
Used Memory after building 11 times: 2152.046875 MB
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]