Skip to content

[ET-VK][q8ta] Support input broadcasting in q8ta_add - #23573

Open
pytorchbot wants to merge 1 commit into
mainfrom
gh/SS-JIA/665/orig
Open

pytorchbot wants to merge 1 commit into
mainfrom
gh/SS-JIA/665/orig

Conversation

@pytorchbot

Copy link
Copy Markdown
Collaborator

This PR was created by the merge bot to help merge the original PR into the main branch.
ghstack PR number: #23554 by @SS-JIA
^ Please use this as the source of truth for the PR details, comments, and reviews
ghstack PR base: https://github.com/pytorch/executorch/tree/gh/SS-JIA/665/base
ghstack PR head: https://github.com/pytorch/executorch/tree/gh/SS-JIA/665/head
Merge bot PR base: https://github.com/pytorch/executorch/tree/main
Merge bot PR head: https://github.com/pytorch/executorch/tree/gh/SS-JIA/665/orig
Differential Revision: D123950526
@diff-train-skip-merge

## Ulterior Motive

Correct results for int8 models on the ET-VK backend. A common pattern adds a per-sample context row to every row of a sequence, e.g. a `[1, 1, 512]` tensor added to a `[1, 60, 512]` tensor. In int8 models on ET-VK, this add was wrong for every row after the first.

## Rationale

**What**: `q8ta_add` now broadcasts its inputs against the output.

**Why**: The quantized binary pattern fuses any `dequantize -> add -> quantize` into `q8ta_add`, including adds whose inputs broadcast. The shader read both inputs at the output's tensor index, so broadcast adds silently produced wrong results on every GPU.

## Details

- Broadcast add, e.g. `[1, 60, 512] + [1, 1, 512]`
  - **Before**: Input B is read at the output index. Only index 0 of a broadcast dim holds data; other indices read block padding or past the end of B's buffer. Rows 1-59 are off by up to 0.27 on Adreno and Mali; row 0 is exact.
  - **After**: Matches the reference on every row.
- Implementation in `q8ta_binary.glsl`, applied to both inputs:
  - Each input's tensor index is clamped to `size - 1` per dim, so size 1 dims read index 0.
  - If a block dim is broadcast, the loaded block is replicated: block outer dim copies row 0 to all 4 rows; block inner (packed) dim copies byte 0 to all 4 bytes of each int32.
  - Broadcast dims are detected from the metadata UBOs at runtime, so it holds after dynamic resize.
- `test_q8ta_binary`: optional input B shape, broadcasting reference, and 8 broadcast shapes (including broadcast input A and lower-rank B) across all 5 int8 layouts, with runtime-quantized and constant B.

Authored with Claude Code.

Differential Revision: [D123950526](https://our.internmc.facebook.com/intern/diff/D123950526/)


ghstack-source-id: 443893319
Pull-Request: #23554
@pytorchbot
pytorchbot requested a review from SS-JIA as a code owner October 8, 2026 02:45
@pytorch-bot

pytorch-bot Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ No Failures

As of commit b0b4aa3 with merge base 4ca434e (image):
💚 Looks good so far! There are no failures yet. 💚

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

@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 8, 2026
@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

This branch was successfully deployed

1 active deployment
cadence — b0b4aa37 Deployed Oct 8, 2026 by pytorchbot via hifi-op-test / hifi4 #32415
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants