Skip to content

[ET-VK] Activation transpose preprocess shaders + dispatch helper - #19995

Merged
meta-codesync[bot] merged 2 commits into
gh/SS-JIA/554/basefrom
gh/SS-JIA/554/head
Jun 5, 2026
Merged

meta-codesync[bot] merged 2 commits into
gh/SS-JIA/554/basefrom
gh/SS-JIA/554/head

Conversation

@SS-JIA

@SS-JIA SS-JIA commented Jun 3, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Adds a generic "preprocess" dispatch path for transposing/casting an activation tensor into a vectorized layout that downstream compute kernels can consume. This is split out from the upcoming q4gsw GEMM commit so the transpose machinery can be reused by other operators that consume pre-transposed activations.

Two compute shaders are added under runtime/graph/ops/glsl/:

  • transpose_cast_contig_to_vectorized — transposes a contiguous [M, K] tensor into [K, ceil(M/4)] packed as a vec4 along the inner dim, with optional dtype cast.
  • transpose_cast_contig_to_vectorized_4x4 — same idea but produces a 4x4 vectorized tile per output element, used by tile-style GEMM kernels.

runtime/graph/ops/impl/Preprocess.{cpp,h} wraps these shaders behind add_transpose_cast_node (and a 4x4 variant). The dispatch self-gates to {0, 0, 0} when M==1 so that GEMV paths sharing a graph with a GEMM prefill can leave the preprocess in place as a no-op rather than rebuilding the graph at decode time. The matching resize_transpose_cast_node keeps the transposed tensor's virtual size in sync with the source activation across virtual_resize.

To support callers that want to invoke the standard prepack path for the activation directly, Staging.h now declares add_prepack_standard_node (previously file-private). Transpose.cpp is reduced to the includes it actually uses.

No new ops are dispatched yet; the next commit wires this infrastructure into et_vk.q4gsw_linear.default.

Differential Revision: D107447235

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Jun 3, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 3 New Failures, 4 Unrelated Failures

As of commit e30ba3e with merge base b1385db (image):

NEW FAILURES - The following jobs have failed:

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

BROKEN TRUNK - The following jobs failed but was 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.

@linux-foundation-easycla

linux-foundation-easycla Bot commented Jun 3, 2026 •

Copy link
Copy Markdown

CLA Missing ID

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

github-actions Bot commented Jun 3, 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.

@metascroy

Copy link
Copy Markdown
Contributor

@claude review this code

@metascroy

Copy link
Copy Markdown
Contributor

@SS-JIA I don't see any new unit tests added for this. Is it covered by existing ones?

@claude

claude Bot commented Jun 3, 2026 •

Copy link
Copy Markdown

Claude finished @metascroy's task in 1m 23s —— View job


Code Review: [ET-VK] Activation transpose preprocess shaders + dispatch helper

  • Read and analyze GLSL shaders
  • Read and analyze C++ implementation (Preprocess.cpp/h)
  • Review changes to Staging.h and Transpose.cpp
  • Post review feedback

Overall this is clean, well-structured infrastructure. The self-gating M==1 → {0,0,0} pattern for GEMV bypass is clever, and the dynamic dispatch setup integrates well with the existing DynamicDispatchNode patterns (RotaryEmbedding, Q8ta, etc.). A few observations:


1. Missing #include for DynamicDispatchNode in Preprocess.cpp

Preprocess.cpp uses DynamicDispatchNode (line 102) but doesn't explicitly include DynamicDispatchNode.h. It works transitively via Common.h → ComputeGraph.h → DynamicDispatchNode.h, but other files in this codebase (e.g., SDPA.cpp) include it explicitly. Not a bug, but an explicit include would make the dependency clearer and be robust to future refactoring.

2. Unused #include <executorch/backends/vulkan/runtime/graph/ops/OperatorRegistry.h> in Preprocess.cpp

No operator is registered in this file (no VK_REGISTER_OP macro). This include appears to be vestigial — perhaps from an earlier iteration where the op was registered here.

3. 4x4 YAML only generates buffer output, but shader has texture2d path

The transpose_cast_contig_to_vectorized_4x4.yaml only generates combos with OUT_STORAGE: buffer, while the shader has a full #else path for imageStore (texture2d output). This is fine if the texture2d path isn't needed yet, but it means the imageStore codepath is dead code that won't be compiled/tested until a combo is added. Consider either:

  • Adding a comment in the YAML noting the texture2d combos are deliberately omitted for now, or
  • Removing the #else branch from the 4x4 shader to reduce dead code (and adding it back when needed)

4. shader.kernel_name.find("4x4") string matching in dispatch functions

In transpose_cast_global_wg_size (line 41) and transpose_cast_local_wg_size (line 59), the is_4x4 logic uses string::find on the kernel name. This is pragmatic but fragile — if any future kernel name accidentally contains "4x4" it would match. Since these functions are only called from the one DynamicDispatchNode created in this file, the risk is low, but passing a flag via resize_args or a dedicated struct would be more robust.

5. Shader bounds checking covers K correctly in 4x4 variant

The 4x4 shader handles K not being a multiple of 4 correctly — it checks k + 1 < K, k + 2 < K, k + 3 < K before writing. Good.

6. add_prepack_standard_node default-arg fix is correct

Moving the default value from the definition to the declaration in Staging.h (line 38: const bool transpose_hw = false) is the right fix for making the function callable from other TUs. The change in Staging.cpp (removing = false from the definition) is proper C++.

7. Transpose.cpp cleanup looks correct

The removed includes (OperatorRegistry.h, impl/Common.h, utils/ShaderNameUtils.h, DynamicDispatchNode.h) are not used in the remaining code — Transpose.cpp only uses Transpose.h, Logging.h, and <algorithm>.


Minor nits

  • Preprocess.cpp:30 — (void)args; suppresses the unused-arg warning. Consider using [[maybe_unused]] on the parameter instead for modern C++ style, though I see this pattern is common in the existing codebase, so matching convention is fine.
  • Preprocess.h — The header comment block is helpful and well-scoped. Might consider mentioning the resize_transpose_cast_node behavior (that the resize function is auto-wired) since callers won't see it from the header alone, but this is a style preference.

Verdict: This is solid infrastructure code. The main actionable item is the unused OperatorRegistry.h include in Preprocess.cpp. The dead texture2d codepath in the 4x4 shader is worth a brief comment. Everything else looks good to ship.


@SS-JIA

SS-JIA commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

@SS-JIA I don't see any new unit tests added for this. Is it covered by existing ones?

It is tested in the subsequent commit, where fp16 gemm consists of transpose input -> gemm

[ghstack-poisoned]
@meta-codesync
meta-codesync Bot merged commit 84e022b into gh/SS-JIA/554/base Jun 5, 2026
170 of 178 checks passed
@meta-codesync
meta-codesync Bot deleted the gh/SS-JIA/554/head branch June 5, 2026 00:23
@meta-codesync
meta-codesync Bot temporarily deployed to cherry-pick-bot June 5, 2026 00:23 Inactive

This branch was previously deployed

1 inactive deployment
cherry-pick-bot — e30ba3e5 Deployed Jun 5, 2026 by meta-codesync[bot] via Try to create a PR with ghstack /orig branch #1265
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants