Skip to content

Conversation

@trivedivivek
Copy link
Contributor

Summary: This diff introduces performance improvements in the 4-bit quant matrix multiplication operation by adjusting the position of the -8 operation. Resulting in overall reduction in math operation performed during shader runtime.

Differential Revision: D85721578

@trivedivivek trivedivivek requested a review from SS-JIA as a code owner October 29, 2025 00:48
@pytorch-bot
Copy link

pytorch-bot bot commented Oct 29, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/15436

Note: Links to docs will display an error until the docs builds have been completed.

❗ 2 Active SEVs

There are 2 currently active SEVs. If your PR is affected, please view them below:

❌ 2 New Failures, 1 Unrelated Failure

As of commit f0c9c4d with merge base 3485495 (image):

NEW FAILURES - The following jobs have failed:

FLAKY - The following job failed but was likely due to flakiness present on trunk:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-codesync
Copy link

meta-codesync bot commented Oct 29, 2025

@trivedivivek has exported this pull request. If you are a Meta employee, you can view the originating Diff in D85721578.

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 29, 2025
@trivedivivek trivedivivek added the release notes: vulkan Changes to the Vulkan backend delegate label Oct 29, 2025
trivedivivek added a commit to trivedivivek/executorch that referenced this pull request Oct 29, 2025
…peration. (pytorch#15436)

Summary:

This diff introduces performance improvements in the 4-bit quant matrix multiplication operation by adjusting the position of the -8 operation. Resulting in overall reduction in math operation performed during shader runtime.

Differential Revision: D85721578
trivedivivek added a commit to trivedivivek/executorch that referenced this pull request Oct 29, 2025
…peration. (pytorch#15436)

Summary:

This diff introduces performance improvements in the 4-bit quant matrix multiplication operation by adjusting the position of the -8 operation. Resulting in overall reduction in math operation performed during shader runtime.

The thinking here is as follows:
* The 4 bit integer weights are unsigned ranging from 0 - 15, and thus to get unsigned number 8 is subtracted from the input.
* Assume WS[] is array of signed weights, M[] is matrix, S is the sum
The main loop essentially performs:
S += ( WS[i] - 8 ) * M[i],       for i = [0, N)
* This equation can rewritten as:
S += WS[i] * M[i] - 8 * M[i], for i = [0, N)
* 8 * M[i] need not be performed in the main loop.
Also 8 * M[i], for i = [0, N)
Can be substituted with A += M[i], for i = [0, N)
and A *= 8

Thus, splitting parts of this equation results in a significant reduction in math ops while producing the same result.

Differential Revision: D85721578
@trivedivivek trivedivivek force-pushed the export-D85721578 branch 2 times, most recently from 1d800aa to a54693c Compare October 29, 2025 13:06
trivedivivek added a commit to trivedivivek/executorch that referenced this pull request Oct 29, 2025
…peration. (pytorch#15436)

Summary:

This diff introduces performance improvements in the 4-bit quant matrix multiplication operation by adjusting the position of the -8 operation. Resulting in overall reduction in math operation performed during shader runtime.

The thinking here is as follows:
* The 4 bit integer weights are unsigned ranging from 0 - 15, and thus to get unsigned number 8 is subtracted from the input.
* Assume WS[] is array of signed weights, M[] is matrix, S is the sum
The main loop essentially performs:
S += ( WS[i] - 8 ) * M[i],       for i = [0, N)
* This equation can rewritten as:
S += WS[i] * M[i] - 8 * M[i], for i = [0, N)
* 8 * M[i] need not be performed in the main loop.
Also 8 * M[i], for i = [0, N)
Can be substituted with A += M[i], for i = [0, N)
and A *= 8

Thus, splitting parts of this equation results in a significant reduction in math ops while producing the same result.

Differential Revision: D85721578
trivedivivek added a commit to trivedivivek/executorch that referenced this pull request Oct 29, 2025
…peration. (pytorch#15436)

Summary:

This diff introduces performance improvements in the 4-bit quant matrix multiplication operation by adjusting the position of the -8 operation. Resulting in overall reduction in math operation performed during shader runtime.

The thinking here is as follows:
* The 4 bit integer weights are unsigned ranging from 0 - 15, and thus to get unsigned number 8 is subtracted from the input.
* Assume WS[] is array of signed weights, M[] is matrix, S is the sum
The main loop essentially performs:
S += ( WS[i] - 8 ) * M[i],       for i = [0, N)
* This equation can rewritten as:
S += WS[i] * M[i] - 8 * M[i], for i = [0, N)
* 8 * M[i] need not be performed in the main loop.
Also 8 * M[i], for i = [0, N)
Can be substituted with A += M[i], for i = [0, N)
and A *= 8

Thus, splitting parts of this equation results in a significant reduction in math ops while producing the same result.

Reviewed By: SS-JIA

Differential Revision: D85721578
…peration. (pytorch#15436)

Summary:

This diff introduces performance improvements in the 4-bit quant matrix multiplication operation by adjusting the position of the -8 operation. Resulting in overall reduction in math operation performed during shader runtime.

The thinking here is as follows:
* The 4 bit integer weights are unsigned ranging from 0 - 15, and thus to get unsigned number 8 is subtracted from the input.
* Assume WS[] is array of signed weights, M[] is matrix, S is the sum
The main loop essentially performs:
S += ( WS[i] - 8 ) * M[i],       for i = [0, N)
* This equation can rewritten as:
S += WS[i] * M[i] - 8 * M[i], for i = [0, N)
* 8 * M[i] need not be performed in the main loop.
Also 8 * M[i], for i = [0, N)
Can be substituted with A += M[i], for i = [0, N)
and A *= 8

Thus, splitting parts of this equation results in a significant reduction in math ops while producing the same result.

Reviewed By: SS-JIA

Differential Revision: D85721578
trivedivivek added a commit to trivedivivek/executorch that referenced this pull request Oct 29, 2025
…peration. (pytorch#15436)

Summary:

This diff introduces performance improvements in the 4-bit quant matrix multiplication operation by adjusting the position of the -8 operation. Resulting in overall reduction in math operation performed during shader runtime.

The thinking here is as follows:
* The 4 bit integer weights are unsigned ranging from 0 - 15, and thus to get unsigned number 8 is subtracted from the input.
* Assume WS[] is array of signed weights, M[] is matrix, S is the sum
The main loop essentially performs:
S += ( WS[i] - 8 ) * M[i],       for i = [0, N)
* This equation can rewritten as:
S += WS[i] * M[i] - 8 * M[i], for i = [0, N)
* 8 * M[i] need not be performed in the main loop.
Also 8 * M[i], for i = [0, N)
Can be substituted with A += M[i], for i = [0, N)
and A *= 8

Thus, splitting parts of this equation results in a significant reduction in math ops while producing the same result.

Reviewed By: SS-JIA

Differential Revision: D85721578
@meta-codesync meta-codesync bot merged commit 48c4e45 into pytorch:main Oct 29, 2025
145 of 148 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported meta-exported release notes: vulkan Changes to the Vulkan backend delegate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants