mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #4885] [Engine] Metal: opt-in silu(z) output gate for the GDN kernels (function constant 12) #5234
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#5234
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/4885
Author: @keithhu1982
Created: 11/1/2026
Status: 🔄 Open
Base:
main← Head:metal-gdn-silu-z📝 Commits (1)
1373b5a[Engine] Metal: opt-in silu(z) output gate for the GDN kernels (function constant 12)📊 Changes
3 files changed (+459 additions, -4 deletions)
View changed files
📝
metal/kernels/gdn.metal(+12 -1)📝
metal/kernels/gdn_prompt.metal(+13 -3)➕
metal/tests/q36_gdn_parity.cpp(+434 -0)📄 Description
Problem and result
The Metal GDN kernels (
gdn_stepingdn.metal,gdn_postingdn_prompt.metal) gate the gated-delta output withsigmoid(z), the Flash-Next gate. Qwen3.6-35B-A3B (
qwen35moe) uses rms(o) * gamma * silu(z), so the Mac engine cannotreuse these kernels for it today.
This PR adds an opt-in function constant 12 (
GDN_SILU_Z). When it is true the gate is silu(z) = z * sigmoid(z). When itis unset or false, the arithmetic is unchanged. Nothing in the tree sets the constant yet, so no existing pipeline changes
behaviour.
Related discussion
#3932 (Qwen3.6-35B-A3B on the Mac engine). The scope has not been agreed there yet, so this is a draft. It is the smallest
self-contained piece of that port, and it is useful to look at on its own: it is the only change to a kernel that
Flash-Next also uses. The full port (separate
metal/src/qwen35/path, no changes undersrc/,include/,setup.pyorserve/) is on themetal-qwen36branch of my fork, rebased onc62d5e3a, if you want to see where it leads.Approach
A function constant rather than a second kernel, so the Flash-Next pipelines compile to the same code and the two models
share one GDN implementation. The declaration is guarded because
gdn.metalandgdn_prompt.metalcan share onetranslation unit.
metal/tests/q36_gdn_parity.cppcovers the Qwen3.6 shapes (h_k 16, h_v 32, C 8192, z 4096) with the constant on, againsta double-precision CPU reference: decode windows 1..8, verify/commit, fold keep 1..T bitwise, plane mode,
gdn_postand theprompt chain (
gdn_pre/gdn_scanr_4/gdn_post).Validation
Revision: this branch on
c62d5e3a. Apple M5 Pro, 64 GB, macOS 26.5, Metal build (cmake -S metal -B build-metal -G Ninja -DCMAKE_BUILD_TYPE=Release, thenninja -C build-metal gdn_parity gdn_prompt_parity q36_gdn_parity).Passed:
build-metal/gdn_parity: ALL PASS.build-metal/gdn_prompt_parity: ALL PASS.build-metal/q36_gdn_parity: PASS.to
gdn_parityandgdn_prompt_parity(not part of this PR) and ran the same binaries withSTRATA_METAL_KERNELSpointing at the kernels ofc62d5e3aand at this branch's, twice each:gdn_parity:66c63985874a54e1with both kernel sets, both runs.gdn_prompt_parity:3016dcb224b5d59dwith both kernel sets, both runs.1.0fto1.0000001fin thec62d5e3akernels changes the hashes(
fcf92c820ee74cf1,09ce8dfb05bd4923), so the hash does see the gate.metal-qwen36), real model Unsloth UD-Q6_K_XL against llama.cpp Metal one token ata time (
metal/tools/q36_gate.py all): mean KL 3.73e-4 (median 1.6e-8), top-1 99.7 % over 10 prompts x 128 steps; 8 of 10greedy runs identical for 128 tokens, the 2 divergences at llama.cpp near-ties (margins 0.08); layers and MTP gates PASS.
Failed:
None observed.
Not run:
bitwise kernel hashes above are the evidence for the default path.
metal/kernels/*.metaland adds one file undermetal/tests/, which thosebuilds do not compile.
Limits
On its own this PR does not make any model use silu(z). It only matters together with the Qwen3.6 Metal path from #3932.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.