You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2021/02/20 07:06:19 UTC

[GitHub] [tvm] VertexC edited a comment on issue #7399: TVM compile pytorch model mutliple times seems to have memory leak

VertexC edited a comment on issue #7399:
URL: https://github.com/apache/tvm/issues/7399#issuecomment-782576070


   Hi @masahi 
   
   Thansk for the reply.
   I tried with the fellowing modified script and memory still increases.
   ```python3
   def main()
       process = psutil.Process(os.getpid())
       print('Used Memory before building:', process.memory_info().rss / 1024 / 1024, 'MB')
   
       total = 10
       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)
   
       for i in range(0, total+1):
           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)
   
           print('Used Memory after building {} times:'.format(i+1), process.memory_info().rss / 1024 / 1024, 'MB')
   ```
   
   ```bash
   Used Memory before building: 235.1640625 MB
   ...
   Used Memory after building 1 times: 907.3828125 MB
   Used Memory after building 2 times: 1153.3046875 MB
   Used Memory after building 3 times: 1273.3515625 MB
   Used Memory after building 4 times: 1386.25390625 MB
   Used Memory after building 5 times: 1489.9296875 MB
   ```
   
   btw, if i comment out 
   ```python3
   ctx = tvm.cpu()
   module = graph_runtime.GraphModule(lib["default"](ctx))
   module.set_input(input_name, data)
   ```
   the memory issue seems to be eased
   ```bash
   Used Memory before building: 236.8046875 MB
   ...
   Used Memory after building 1 times: 816.05859375 MB
   Used Memory after building 2 times: 1026.9375 MB
   Used Memory after building 3 times: 1054.21875 MB
   Used Memory after building 4 times: 1062.2734375 MB
   Used Memory after building 5 times: 1079.9296875 MB
   Used Memory after building 6 times: 1061.29296875 MB
   Used Memory after building 7 times: 1079.0703125 MB
   Used Memory after building 8 times: 1096.953125 MB
   Used Memory after building 9 times: 1078.56640625 MB
   Used Memory after building 10 times: 1105.34375 MB
   Used Memory after building 11 times: 1087.70703125 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:
users@infra.apache.org