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

Extend Matmul to support matrix multiplication with multiple heads #18570

Merged
merged 12 commits into from
Jul 24, 2019

Conversation

czhu15
Copy link
Contributor

@czhu15 czhu15 commented Jul 10, 2019

With the support of multiple head, the multiplication of two big matrixes is split into multiplication of several (head_number) small matrixes. e.g. if Mat A is [3, 24] and Mat B is [24, 4], when multiple A and B with head_number as 4, Mat A will be split as 4 matrix of [3, 6] and Mat B will be 4 matrix of [6, 4]. The result of final matrix will be 4 matrix of [3, 4], i.e. [3, 16].

Use this new extension, we can avoid head split/merge in Transformer.

first part of #16342

With the support of multiple head, the multiplication of two big matrixes is
split into multiplication of several (head_number) small matrixes. e.g. if
Mat A is [3, 24] and Mat B is [24, 4], when multiple A and B with head_number
as 4, Mat A will be split as 4 matrix of [3, 6] and Mat B will be 4 matrix of
[6, 4]. The result of final matrix will be 4 matrix of [3, 4], i.e. [3, 16].

test=develop
@luotao1 luotao1 added the Intel label Jul 10, 2019
To support matmul with multiple heads, it requires MKL stride feature
of matrix multiplication.

test=develop
To support matmul with multiple heads, it requires MKL stride feature
of matrix multiplication.

test=develop
@bingyanghuang
Copy link
Contributor

@yihuaxu Please help review this PR. @wojtuss could you help assign someone in your team to help review this PR?

@yihuaxu
Copy link
Contributor

yihuaxu commented Jul 17, 2019

@yihuaxu Please help review this PR. @wojtuss could you help assign someone in your team to help review this PR?

LGTM

@czhu15 czhu15 force-pushed the matmul_with_multiple_head branch from 5ce5a01 to a8a3040 Compare July 23, 2019 03:44
numpy can handle it correctly without user's manual handling.

test=develop
Copy link

@wojtuss wojtuss left a comment

Choose a reason for hiding this comment

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

LGTM

paddle/fluid/operators/math/blas.h Show resolved Hide resolved
paddle/fluid/operators/math/blas_impl.h Show resolved Hide resolved
paddle/fluid/operators/matmul_op.cc Show resolved Hide resolved
Copy link
Contributor

@luotao1 luotao1 left a comment

Choose a reason for hiding this comment

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

LGTM

if transpose_X:
shape_X = [M]
else:
shape_X = [K]
Copy link
Contributor

Choose a reason for hiding this comment

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

reduce 4 lines to 1 line.
shape_X = [M] if transpose_X else [K]
You can update in your next PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants