- 
                Notifications
    
You must be signed in to change notification settings  - Fork 679
 
[MMSIG] Support the deployment of SparseInst on TensorRT #2541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| 
           Because of the lack of sparseinst metafile, I didn't finish the regression test.  | 
    
| 
           Great work! Could we also include queryInst in this PR since they are very similar?  | 
    
          
 OK, I will do it.  | 
    
      
        
              This comment was marked as resolved.
        
        
      
    
  This comment was marked as resolved.
| dets = torch.cat([bboxes, scores.unsqueeze(-1)], dim=-1) | ||
| masks = (pred_masks > self.mask_threshold).float() | ||
| 
               | 
          ||
| return dets, labels, masks | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we post the evaluation results of trt model and check if it's aligned with pytorch model?
| 
               | 
          ||
| @FUNCTION_REWRITER.register_rewriter( | ||
| 'projects.SparseInst.sparseinst.SparseInst.predict') | ||
| def sparseinst__predict( | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when build trt engine, there's warning
Profile kMIN values are not self-consistent. /encoder/ppm/Resize_1: IResizeLayer requires that if input dimension is zero, output dimension must be zero too (axis = 3 input dimension = (+ (CEIL_DIV (+ width -800) 416) 1) output dimension = (+ (CEIL_DIV (+ width -32) 32) 1))
Condition '==' violated: 0 != 10. Instruction: CHECK_EQUAL 0 10.
This might lead to failure in some cases.
Running test.py failed after some iterations
Epoch(test) [  50/5000]    eta: 0:03:57  time: 0.0470  data_time: 0.0014  memory: 495  
12/15 02:59:38 - mmengine - INFO - Epoch(test) [ 100/5000]    eta: 0:03:35  time: 0.0413  data_time: 0.0013  memory: 506  
12/15 02:59:40 - mmengine - INFO - Epoch(test) [ 150/5000]    eta: 0:03:24  time: 0.0349  data_time: 0.0014  memory: 501  
12/15 02:59:42 - mmengine - INFO - Epoch(test) [ 200/5000]    eta: 0:03:16  time: 0.0358  data_time: 0.0014  memory: 501  
12/15 02:59:44 - mmengine - INFO - Epoch(test) [ 250/5000]    eta: 0:03:10  time: 0.0344  data_time: 0.0013  memory: 505  
12/15 02:59:46 - mmengine - INFO - Epoch(test) [ 300/5000]    eta: 0:03:07  time: 0.0371  data_time: 0.0013  memory: 501  
12/15 02:59:48 - mmengine - INFO - Epoch(test) [ 350/5000]    eta: 0:03:06  time: 0.0420  data_time: 0.0015  memory: 508  
12/15 02:59:50 - mmengine - INFO - Epoch(test) [ 400/5000]    eta: 0:03:03  time: 0.0340  data_time: 0.0013  memory: 501  
12/15 02:59:52 - mmengine - INFO - Epoch(test) [ 450/5000]    eta: 0:03:01  time: 0.0420  data_time: 0.0014  memory: 508  
12/15 02:59:54 - mmengine - INFO - Epoch(test) [ 500/5000]    eta: 0:02:59  time: 0.0390  data_time: 0.0014  memory: 502  
[12/15/2023-02:59:56] [TRT] [E] 7: [shapeMachine.cpp::executeContinuation::864] Error Code 7: Internal Error (/encoder/ppm/Resize_1: IResizeLayer requires that if input dimension is zero, output dimension must be zero too (axis = 3 input dimension = (+ (CEIL_DIV (+ width -800) 416) 1) output dimension = (+ (CEIL_DIV (+ width -32) 32) 1))
 Condition '==' violated: 0 != 12. Instruction: CHECK_EQUAL 0 12.)
Traceback (most recent call last):
  File "tools/test.py", line 159, in <module>
    main()
  File "tools/test.py", line 153, in main
    runner.test()
  File "/usr/local/lib/python3.8/dist-packages/mmengine/runner/runner.py", line 1791, in test
    metrics = self.test_loop.run()  # type: ignore
  File "/usr/local/lib/python3.8/dist-packages/mmengine/runner/loops.py", line 435, in run
    self.run_iter(idx, data_batch)
  File "/usr/local/lib/python3.8/dist-packages/torch/utils/_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/mmengine/runner/loops.py", line 454, in run_iter
    outputs = self.runner.model.test_step(data_batch)
  File "/usr/local/lib/python3.8/dist-packages/mmengine/model/base_model/base_model.py", line 145, in test_step
    return self._run_forward(data, mode='predict')  # type: ignore
  File "/usr/local/lib/python3.8/dist-packages/mmengine/model/base_model/base_model.py", line 340, in _run_forward
    results = self(**data, mode=mode)
  File "/usr/local/lib/python3.8/dist-packages/torch/nn/modules/module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
  File "/root/workspace/mmdeploy/mmdeploy/codebase/mmdet/deploy/object_detection_model.py", line 296, in forward
    outputs = self.predict(inputs)
  File "/root/workspace/mmdeploy/mmdeploy/codebase/mmdet/deploy/object_detection_model.py", line 313, in predict
    outputs = self.wrapper({self.input_name: imgs})
  File "/usr/local/lib/python3.8/dist-packages/torch/nn/modules/module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
  File "/root/workspace/mmdeploy/mmdeploy/backend/tensorrt/wrapper.py", line 167, in forward
    shape = tuple(self.context.get_binding_shape(idx))
ValueError: __len__() should return >= 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Boomerl From my experience, tensorrt have not supported nn.AdaptiveAvgPool2d which is used in here. This means sparseinst model can only accept static shape for tensorrt backends, which should use configs like configs/mmdet/instance-seg/instance-seg_tensorrt_static-800x1344.py.
You could include this note in docs like https://github.com/open-mmlab/mmdeploy/blob/main/docs/en/04-supported-codebases/mmdet.md#reminder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank u for the guidance, I will check it immediately.
| 
           When I use static deploy config to convert this model to trt, I met an error:  | 
    
          
 @Boomerl could you provide the full script you are running?  | 
    
| 
           
  | 
    
| 
           I used the deploy config below:  | 
    
Thanks for your contribution and we appreciate it a lot. The following instructions would make your pull request more healthy and more easily receiving feedbacks. If you do not understand some items, don't worry, just make the pull request and seek help from maintainers.
Motivation
Support the deployment of real-time instance segmentation algorithm SparseInst on TensorRT backend.
Modification
Support the deployment of real-time instance segmentation algorithm SparseInst on TensorRT backend.
BC-breaking (Optional)
Does the modification introduce changes that break the backward-compatibility of the downstream repositories?
If so, please describe how it breaks the compatibility and how the downstream projects should modify their code to keep compatibility with this PR.
Use cases (Optional)
If this PR introduces a new feature, it is better to list some use cases here, and update the documentation.
Checklist