Skip to content
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

support multi_scale_deform_attn trt plugin #1844

Merged
merged 9 commits into from Mar 17, 2023

Conversation

cxiang26
Copy link
Contributor

@cxiang26 cxiang26 commented Mar 7, 2023

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

This trt plugin refers to mmcv and tensorrt

Modification

Please briefly describe what modification is made in this PR.

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

  1. Pre-commit or other linting tools are used to fix the potential lint issues.
  2. The modification is covered by complete unit tests. If not, please add more unit tests to ensure the correctness.
  3. If the modification has a dependency on downstream projects of a newer version, this PR should be tested with all supported versions of downstream projects.
  4. The documentation has been modified accordingly, like docstring or example tutorials.

@CLAassistant
Copy link

CLAassistant commented Mar 7, 2023

CLA assistant check
All committers have signed the CLA.

@lvhan028 lvhan028 requested a review from AllentDan March 8, 2023 04:38
Copy link
Member

@AllentDan AllentDan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some works to do for you:

  1. add symbolic rewriting of this op in MMDeploy to export ONNX.
  2. add corresponding unit test
  3. update doc description for customized ops

BTW, what model does this op work for?

@AllentDan
Copy link
Member

Please fix the lint issue. You can install pre-commit hook on your localhost like following:

pip install -U pre-commit
cd mmdeploy
pre-commit install

You can run pre-commit run --all-file to check whether there are lint errors.

As for cscr files, you may try clang-format.

@cxiang26
Copy link
Contributor Author

cxiang26 commented Mar 9, 2023

There are some works to do for you:

  1. add symbolic rewriting of this op in MMDeploy to export ONNX.
  2. add corresponding unit test
  3. update doc description for customized ops

BTW, what model does this op work for?
@AllentDan
this plugin is for bevformer

@lvhan028 lvhan028 requested a review from grimoire March 13, 2023 03:32
@grimoire
Copy link
Member

If your code is modified from other repo, please add some comment at the head of the file like https://github.com/open-mmlab/mmdeploy/blob/master/csrc/mmdeploy/backend_ops/torchscript/optimizer/ir/subgraph_matcher.cpp .
Any please provide the unit test so we can test the op.

Copy link
Member

@grimoire grimoire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unit test failed with log:

FAILED tests/test_ops/test_ops.py::test_multi_scale_deformable_attn[backend0] - RuntimeError: CUDA error: an illegal memory access was encountered

@grimoire grimoire added the enhancement New feature or request label Mar 15, 2023
@grimoire
Copy link
Member

result mismatch

E               AssertionError: Tensor-likes are not close!
E               
E               Mismatched elements: 16384 / 16384 (100.0%)
E               Greatest absolute difference: 11.818938732147217 at index (0, 4, 130) (up to 1e-05 allowed)
E               Greatest relative difference: 0.6782912324431448 at index (1, 24, 59) (up to 0.001 allowed)

@cxiang26
Copy link
Contributor Author

result mismatch

E               AssertionError: Tensor-likes are not close!
E               
E               Mismatched elements: 16384 / 16384 (100.0%)
E               Greatest absolute difference: 11.818938732147217 at index (0, 4, 130) (up to 1e-05 allowed)
E               Greatest relative difference: 0.6782912324431448 at index (1, 24, 59) (up to 0.001 allowed)

The mismatch is caused by input[1] & input[2] point to the same address in plugin.cpp, input[1] and input [2] should difference
I have doubled check this plugin, but I can't find the reason resulting in this bug
BTW, the deployed result with this plugin can obtain the right result in my project

@grimoire
Copy link
Member

Sorry, It is my mistake.

input_tensor = input_tensor.int()

input_tensor will be released after the loop, that leads to the error.

You can initialize the inputs before the for loop:

        inputs = dict((name, data.contiguous().int() if data.dtype ==
                       torch.long else data.contiguous())
                      for name, data in inputs.items())
        for input_name, input_tensor in inputs.items():
             ...

Could you please fix it for me in this PR.

Copy link
Member

@grimoire grimoire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@cxiang26
Copy link
Contributor Author

fixed

Sorry, It is my mistake.

input_tensor = input_tensor.int()

input_tensor will be released after the loop, that leads to the error.
You can initialize the inputs before the for loop:

        inputs = dict((name, data.contiguous().int() if data.dtype ==
                       torch.long else data.contiguous())
                      for name, data in inputs.items())
        for input_name, input_tensor in inputs.items():
             ...

Could you please fix it for me in this PR.

fixed

Copy link
Member

@AllentDan AllentDan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lvhan028 lvhan028 merged commit 50bd7e9 into open-mmlab:dev-1.x Mar 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants