-
Notifications
You must be signed in to change notification settings - Fork 712
Reformulating matrix multiplication scale equation to reduce math ops and improve power and performance. #6437
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
Reformulating matrix multiplication scale equation to reduce math ops and improve power and performance. #6437
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/6437
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: ✅ No FailuresAs of commit 9443a2b with merge base 4f12131 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
This pull request was exported from Phabricator. Differential Revision: D64479405 |
… and improve power and performance. (pytorch#6437) Summary: This diff simplifies the the matrix multiplication scale equation in q_linear op. The existing equation in q_linear op is: ``` for i in K / 4 sums[c] = mat1_tex . (qmat2(c) scales[c]) out += sums ``` where c = [0, 4), out, sums, mat1_tex and qmat2 are vectors and scales is a scalar. The dot product is associative with respect to scalar multiplication as mentioned in https://en.wikipedia.org/wiki/Dot_product ie. (ac1).(bc2) = c1c2(a.b) Thus, the multiplication can be rearranged as: ``` for i in K / 4 sums[c] = (mat1_tex . qmat2(c)) scales[c] out += sums ``` Using distributive property of multiplication ie. ab + ac + ad ... = a(b + c+ d...) the code can be further simplified to: ``` for i in K / 4 sums[c] = mat1_tex . qmat2(c) out += sums out *= scale ``` This rearrangement significantly reduces redundant multiplications. Reviewed By: SS-JIA Differential Revision: D64479405
4257a44 to
2fcaa06
Compare
|
This pull request was exported from Phabricator. Differential Revision: D64479405 |
… and improve power and performance. (pytorch#6437) Summary: This diff simplifies the the matrix multiplication scale equation in q_linear op. The existing equation in q_linear op is: ``` for i in K / 4 sums[c] = mat1_tex . (qmat2(c) scales[c]) out += sums ``` where c = [0, 4), out, sums, mat1_tex and qmat2 are vectors and scales is a scalar. The dot product is associative with respect to scalar multiplication as mentioned in https://en.wikipedia.org/wiki/Dot_product ie. (ac1).(bc2) = c1c2(a.b) Thus, the multiplication can be rearranged as: ``` for i in K / 4 sums[c] = (mat1_tex . qmat2(c)) scales[c] out += sums ``` Using distributive property of multiplication ie. ab + ac + ad ... = a(b + c+ d...) the code can be further simplified to: ``` for i in K / 4 sums[c] = mat1_tex . qmat2(c) out += sums out *= scale ``` This rearrangement significantly reduces redundant multiplications. Reviewed By: SS-JIA Differential Revision: D64479405
2fcaa06 to
50f551d
Compare
|
This pull request was exported from Phabricator. Differential Revision: D64479405 |
… and improve power and performance. (pytorch#6437) Summary: This diff simplifies the the matrix multiplication scale equation in q_linear op. The existing equation in q_linear op is: ``` for i in K / 4 sums[c] = mat1_tex . (qmat2(c) scales[c]) out += sums ``` where c = [0, 4), out, sums, mat1_tex and qmat2 are vectors and scales is a scalar. The dot product is associative with respect to scalar multiplication as mentioned in https://en.wikipedia.org/wiki/Dot_product ie. (ac1).(bc2) = c1c2(a.b) Thus, the multiplication can be rearranged as: ``` for i in K / 4 sums[c] = (mat1_tex . qmat2(c)) scales[c] out += sums ``` Using distributive property of multiplication ie. ab + ac + ad ... = a(b + c+ d...) the code can be further simplified to: ``` for i in K / 4 sums[c] = mat1_tex . qmat2(c) out += sums out *= scale ``` This rearrangement significantly reduces redundant multiplications. Reviewed By: SS-JIA, jorgep31415 Differential Revision: D64479405
50f551d to
9443a2b
Compare
|
This pull request was exported from Phabricator. Differential Revision: D64479405 |
Summary:
This diff simplifies the the matrix multiplication scale equation in q_linear op.
The existing equation in q_linear op is:
where c = [0, 4), out, sums, mat1_tex and qmat2 are vectors and scales is a scalar.
The dot product is associative with respect to scalar multiplication as mentioned in https://en.wikipedia.org/wiki/Dot_product ie. (ac1).(bc2) = c1c2(a.b)
Thus, the multiplication can be rearranged as:
Using distributive property of multiplication ie. ab + ac + ad ... = a(b + c+ d...) the code can be further simplified to:
This rearrangement significantly reduces redundant multiplications.
Reviewed By: SS-JIA
Differential Revision: D64479405