Skip to content

[ExecuTorch][Vulkan] Add et_vk.linear_q4gsw_backward kernel (4-bit input-grad)#20943

Open
JCNTH wants to merge 3 commits into
gh/JCNTH/82/basefrom
gh/JCNTH/82/head
Open

[ExecuTorch][Vulkan] Add et_vk.linear_q4gsw_backward kernel (4-bit input-grad)#20943
JCNTH wants to merge 3 commits into
gh/JCNTH/82/basefrom
gh/JCNTH/82/head

Conversation

@JCNTH

@JCNTH JCNTH commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Adds the Vulkan et_vk.linear_q4gsw_backward kernel — the input-gradient of the frozen 4-bit linear_q4gsw base, for on-device adapter training. Computes d_x[M, K] = d_out[M, N] @ dequant(W)[N, K], contracting over N.

Problem: et_vk.linear_q4gsw_backward is registered in the shared Vulkan partitioner (custom_ops_lib.py + op_registry.py) but Vulkan had no runtime kernel, so the op could not run.

Solution: a 4M x 4K register-tiled GLSL kernel that reads the SAME W_4X8 block-packed weight the forward reads, re-deriving the nibble/scale addressing so the training loop stays consistent with the forward with no re-pack. dequant(W[n, k]) = (code - 8) * scale.

Key changes:

  • glsl/q4gsw_backward.{glsl,yaml} — buffer x float; W_4X8 nibble unpack mirroring glsl/q4gsw_linear_gemm__w_4x8.glsl (even-N low nibble, odd-N high, N4_padded ivec4 stride, [num_groups, N] scales).
  • impl/QuantizedLinearBackward.cpp — reuses prepack_q4_w_4x8_nc_buffer + prepack_q4_scales from the forward; 1D tile dispatch ceil(M/4) * ceil(K/4) with a workgroup-count guard; group_size specialization constant.

Constraints: buffer storage, fp32; N % 4 == 0, K % 4 == 0, group_size % 4 == 0 (matches the forward prepack). Weight/scale layout identical to the forward.
@exported-using-ghexport

Differential Revision: D111797529

Differential Revision: D111797529

[ghstack-poisoned]
@JCNTH JCNTH requested a review from SS-JIA as a code owner July 14, 2026 21:50
@pytorch-bot pytorch-bot Bot added the module: vulkan Issues related to the Vulkan delegate and code under backends/vulkan/ label Jul 14, 2026
@pytorch-bot

pytorch-bot Bot commented Jul 14, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 9 New Failures

As of commit 18d25c6 with merge base 7013c8d (image):

NEW FAILURES - The following jobs have failed:

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

This was referenced Jul 14, 2026
@github-actions

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.

[ghstack-poisoned]
[ghstack-poisoned]
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. meta-exported module: vulkan Issues related to the Vulkan delegate and code under backends/vulkan/

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant