[Vulkan] Fuse SwiGLU elementwise operations - #22979
Draft
mergennachin wants to merge 1 commit into
Draft
mergennachin wants to merge 1 commit into
mergennachin wants to merge 1 commit into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/22979
Note: Links to docs will display an error until the docs builds have been completed. ❌ 2 New FailuresAs of commit 5721f54 with merge base dd8297a ( NEW FAILURES - The following jobs have failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
Contributor
|
@mergennachin has imported this pull request. If you are a Meta employee, you can view this in D121198447. |
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SwiGLU currently runs a sigmoid and two multiplies as separate Vulkan dispatches. Fuse
gate * sigmoid(gate) * upinto one binary kernel. For Qwen3-0.6B, this removes 56 dispatches per token (737 → 681). Models need to be re-exported to use the fusion.The matcher handles either multiply operand order and skips shared sigmoid/SiLU intermediates. The fused op reuses the existing binary-op broadcasting, packing, and dynamic-resize logic for FP16/FP32 buffers and 3D textures. FP16 inputs are evaluated in FP32 with one output conversion, so results can differ slightly from the unfused intermediate rounding.
On an Apple M1 Pro with MoltenVK, Qwen3-0.6B W4 (group size 32, FP16 storage, context limit 1024):
Four alternating pairs per prompt, full warmup, and 64 measured decode tokens per run using the same unprofiled Release runner. All eight pairs favored fusion, with identical generated text within each prompt. Prefill showed no regression in these runs. Both benchmark arms include the W4 specialization from #22973 and the merged view removal from #22898; this PR contains only SwiGLU fusion. Both runners used the same 255-token prefill chunk cap to respect the export's shape bound. Adreno performance has not been measured.
Test plan
All 21 tests in
backends/vulkan/test/test_vulkan_passes.pypassed. The five new SwiGLU tests cover operand order, broadcasting, dynamic projection ordering, shared intermediates, and mixed precision; they were rerun after test cleanup.All 56 cases selected by
vulkan_compute_api_test --gtest_filter='*VulkanSwiGLUTest*'passed on MoltenVK. Each exercises row counts 1 → 7 → 63 → 1, covering FP16/FP32, buffers/textures, packed layouts, odd widths, broadcasting, and the 3072-wide LLM case. Results are checked against an independent float reference and the unfused GPU path with half-precision rounding bounds. Full model runs also exercised prefill chunks up to 255 followed by decode.The new shaders and C++ dispatch code built in Release. Python/C++ lint and formatting checks passed. GPU traces confirmed that the only dispatch-count changes were 28 fewer sigmoid kernels, 56 fewer multiply kernels, and 28 new SwiGLU kernels.
Authored with assistance from OpenAI Codex.
cc @SS-JIA @manuelcandales @digantdesai @cbilgin