Optimize RoPEAttention
implementation for onnx export
#10
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
矩阵乘法实现的
RoPEAttention
在TensorRT框架下耗时较高,相比于pytorch下的复数实现,在nvidia-3080-laptop
下,耗时30ms(pytorch) vs 100ms(tensorrt)
. 主要是由于大矩阵乘法耗时较高,所以对这部分做了优化。这个PR的内容是将复数实现的
RoPEAttention
转换为实数运算,既避免了复数运算ONNX/TensorRT
不支持的情况,又保留了复数运算的高效率。推理速度测试:
在sam2原工程上验证,输出结果与原版一致。