Skip to content

Vulkan: convert quantized linear weight scales to the output dtype - #24023

Merged
SS-JIA merged 1 commit into
pytorch:mainfrom
msluszniak:ms/vulkan-q4gsw-fp32-scales
Oct 26, 2026
Merged

SS-JIA merged 1 commit into
pytorch:mainfrom
msluszniak:ms/vulkan-q4gsw-fp32-scales

Conversation

@msluszniak

@msluszniak msluszniak commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The quantized linear shaders read the weight scales in the output dtype, but quantized_linear_impl prepacked them in their serialized dtype. An fp16 model with fp32 scales (e.g. torchao weight_scale_dtype=torch.float32, or a bf16 checkpoint cast to fp16 around its scales) is accepted by the partitioner and silently produces garbage. This prepacks the scales in the output dtype, as Q4gswLinear already does.

Test plan

Galaxy S26 Ultra (Adreno 840), fp16 8da4w Linear(1536, 2048) g32, vs the same model in fp32:

scales before after
fp32, M=1 / M=8 cos 0.720 / 0.707 (outputs ~130x too large) cos 0.999966 / 0.999998
fp16, M=1 / M=8 cos 0.999966 / 0.999998 unchanged

No unit test: the 8da4w delegate test is disabled on SwiftShader and the q4gsw_linear op test skips fp16 dq8ca references.

cc @SS-JIA @manuelcandales @digantdesai @cbilgin @nil-is-all

The quantized linear shaders read the weight scales in the output dtype, but
quantized_linear_impl prepacked them in whatever dtype they were serialized
in. An fp16 model quantized from a bf16 or fp32 checkpoint can keep fp32
scales (e.g. torchao's weight_scale_dtype=torch.float32), which the
partitioner accepts, and the shaders then read the fp32 bytes as fp16.

Prepack the scales in the output dtype, as Q4gswLinear already does.
@msluszniak
msluszniak requested a review from SS-JIA as a code owner October 20, 2026 13:12
@pytorch-bot pytorch-bot Bot added the module: vulkan Issues related to the Vulkan delegate and code under backends/vulkan/ label Oct 20, 2026
@pytorch-bot

pytorch-bot Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 1 New Failure, 2 Unrelated Failures

As of commit 7947020 with merge base a39d597 (image):

NEW FAILURE - The following job has failed:

BROKEN TRUNK - The following jobs failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

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 20, 2026
@executorch-triage executorch-triage Bot added the community: contribution PRs coming from community (excluding hardware partners) label Oct 20, 2026
@nil-is-all nil-is-all added the release notes: vulkan Changes to the Vulkan backend delegate label Oct 21, 2026
@SS-JIA
SS-JIA merged commit 6747505 into pytorch:main Oct 26, 2026
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. community: contribution PRs coming from community (excluding hardware partners) module: vulkan Issues related to the Vulkan delegate and code under backends/vulkan/ release notes: vulkan Changes to the Vulkan backend delegate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants