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

[xpu] support matmul_v2 to encoder adaptive seqlen #8883

Merged
merged 2 commits into from
Apr 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,18 @@ namespace fusion {

class XPUMultiEncoderAdaptiveSeqlenFuser : public FuseBase {
public:
explicit XPUMultiEncoderAdaptiveSeqlenFuser(
const std::string& matmul_type = "matmul")
: matmul_type_(matmul_type) {}

void BuildPattern() override {
auto* mask = VarNode("mask")
->assert_is_op_input("matmul", "X")
->assert_is_op_input("matmul", "Y");
auto* matmul = OpNode("matmul", "matmul")->AsIntermediate();
->assert_is_op_input(matmul_type_, "X")
->assert_is_op_input(matmul_type_, "Y");
auto* matmul = OpNode("matmul", matmul_type_)->AsIntermediate();
auto* matmul_out = VarNode("matmul_out")
->assert_is_op_input("scale", "X")
->assert_is_op_output("matmul", "Out")
->assert_is_op_output(matmul_type_, "Out")
->AsIntermediate();
auto* scale = OpNode("scale", "scale")->AsIntermediate();
auto* scale_out = VarNode("scale_out")
Expand Down Expand Up @@ -140,15 +144,21 @@ class XPUMultiEncoderAdaptiveSeqlenFuser : public FuseBase {
DirectedLink(embedding_seq_lod_node, matched.at("xpu_encoder"));
DirectedLink(embedding_pad_seq_len_node, matched.at("xpu_encoder"));
}

private:
std::string matmul_type_;
};

} // namespace fusion

class XPUMultiEncoderAdaptiveSeqlenFusePass : public ProgramPass {
public:
void Apply(const std::unique_ptr<SSAGraph>& graph) override {
fusion::XPUMultiEncoderAdaptiveSeqlenFuser fuser;
fuser(graph.get());
std::vector<std::string> matmul_types{"matmul", "matmul_v2"};
for (auto& matmul_type : matmul_types) {
fusion::XPUMultiEncoderAdaptiveSeqlenFuser fuser(matmul_type);
fuser(graph.get());
}
}
};

Expand Down