-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[Arm]Add fused_attention #9878
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
Merged
sprouteer
merged 14 commits into
PaddlePaddle:develop
from
sprouteer:add_attention_layer
Feb 22, 2023
Merged
[Arm]Add fused_attention #9878
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
8fa178a
add fused_attention test=develop
sprouteer 8468d87
add gemm_prepack_oth_int8 support GemmNBias test=develop
sprouteer f98a950
fix gemm_prepacked_int8 test=develop
sprouteer 12187da
fix fc bug test=develop
sprouteer 126774e
fix int8 gemm trans int32 to fp32 n direction v7
sprouteer e0df8bb
fix fc int8 int8 bug
sprouteer 1864180
fix remain bug
sprouteer abd25ae
rename ernie_attention to transformer_attention
sprouteer 73712f8
fix v7 bug
sprouteer 02d4562
fix code style
sprouteer 84a28e0
fix bug
sprouteer a2dd754
fix bug
sprouteer 6dddbdf
fix v7 bug
sprouteer bc4d779
fix transformer_attention_fuse_pass test=develop
sprouteer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
lite/core/optimizer/mir/fusion/transformer_attention_fuse_pass.cc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,51 @@ | ||||||||||||
| // Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved. | ||||||||||||
| // | ||||||||||||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||||
| // you may not use this file except in compliance with the License. | ||||||||||||
| // You may obtain a copy of the License at | ||||||||||||
| // | ||||||||||||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||
| // | ||||||||||||
| // Unless required by applicable law or agreed to in writing, software | ||||||||||||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||||
| // See the License for the specific language governing permissions and | ||||||||||||
| // limitations under the License. | ||||||||||||
|
|
||||||||||||
| #include "lite/core/optimizer/mir/fusion/transformer_attention_fuse_pass.h" | ||||||||||||
| #include <list> | ||||||||||||
| #include <memory> | ||||||||||||
| #include <vector> | ||||||||||||
| #include "lite/core/optimizer/mir/fusion/transformer_attention_fuser.h" | ||||||||||||
| #include "lite/core/optimizer/mir/pass_registry.h" | ||||||||||||
|
|
||||||||||||
| namespace paddle { | ||||||||||||
| namespace lite { | ||||||||||||
| namespace mir { | ||||||||||||
|
|
||||||||||||
| void TransformerAttentionFusePass::Apply( | ||||||||||||
| const std::unique_ptr<SSAGraph>& graph) { | ||||||||||||
| fusion::TransformerAttentionFuser fuser; | ||||||||||||
| bool has_int8 = false; | ||||||||||||
| for (auto& place : graph->valid_places()) { | ||||||||||||
| if (place.precision == PRECISION(kInt8)) { | ||||||||||||
| has_int8 = true; | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
| if ((has_int8)) { | ||||||||||||
| fuser(graph.get()); | ||||||||||||
| } else { | ||||||||||||
| return; | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| } // namespace mir | ||||||||||||
| } // namespace lite | ||||||||||||
| } // namespace paddle | ||||||||||||
|
|
||||||||||||
| REGISTER_MIR_PASS(transformer_attention_fuse_pass, | ||||||||||||
| paddle::lite::mir::TransformerAttentionFusePass) | ||||||||||||
| .BindTargets({TARGET(kARM)}) | ||||||||||||
| .ExcludeTargets( | ||||||||||||
| {TARGET(kXPU), TARGET(kOpenCL), TARGET(kMetal), TARGET(kNNAdapter)}) | ||||||||||||
|
Comment on lines
+48
to
+50
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
| .BindKernel("fused_attention"); | ||||||||||||
32 changes: 32 additions & 0 deletions
32
lite/core/optimizer/mir/fusion/transformer_attention_fuse_pass.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <memory> | ||
| #include <string> | ||
| #include "lite/core/optimizer/mir/pass.h" | ||
|
|
||
| namespace paddle { | ||
| namespace lite { | ||
| namespace mir { | ||
|
|
||
| class TransformerAttentionFusePass : public ProgramPass { | ||
| public: | ||
| void Apply(const std::unique_ptr<SSAGraph>& graph) override; | ||
| }; | ||
|
|
||
| } // namespace mir | ||
| } // namespace lite | ||
| } // namespace paddle |
Oops, something went wrong.
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.
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.
不需要else