Repository navigation
cuda: fuse GDN alpha/beta projections and postprocessing - #123
Draft
GenerelSchwerz wants to merge 7 commits into
Draft
GenerelSchwerz wants to merge 7 commits into
GenerelSchwerz wants to merge 7 commits into
Conversation
Assisted-by: Codex
Assisted-by: Codex
Assisted-by: Codex
Assisted-by: Codex
Assisted-by: Codex
Assisted-by: Codex
Assisted-by: Codex
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.
Overview
GDN alpha/beta gates currently require separate projections, pointwise kernels and, for packed banks, output copies. This PR recognizes closed graph cuts and writes the final gates in compatible projection kernels, shares rounded activation preparation when the original two GEMMs must remain, and combines postprocessing when producer fusion is unsuitable. Admission follows tensor contracts and existing CUDA selectors; there are no model-name rules or weight repacking.
Review against
reference/upstream-kernels-20261001, official basedcd387a412ca54e172a8d60eb71ef6753850c8ca. This is an owner-requested review PR in the maintained fork. Related independent work: preparation reuse in #117/#118/#119, convolution/SiLU/QK in #121, and routed expert gate/up pairing in #122. This PR concerns recurrent attention gates, not MoE expert routing.Coverage
Logical cut closure, extra consumers, computed parameters, original skipped writes, physical ranges including NONE/leaf reads, padding, mutation, standard allocation dependencies and concurrent-stream exclusions remain guarded. Unsupported cuts execute the original graph. Private source-program allocation dependencies are separate integration work.
Isolated benefit
RTX 5070 Ti, SM120. Each figure is complete-component time against its stated frozen control, with actual optimized dispatch and complete downstream outputs checked. Rows are separate experiments and their gains cannot be added.
c03ed102fa1591844c673b5374cad68cb8df474cb8df474cb8df474cb8df474cAll reported pairs improved in every rotated repetition (four pairs; five for initial rounded N2/N8). Other small or flat outcomes remain recorded.
Two measured exclusions are deliberate. Unrestricted rounded-input tiling was 57.08% slower at N17 and 99.93%-242.81% slower at tested N24/N31/N32/N129, so the final matcher retains original GEMMs above sixteen columns. A packed ordinary-MMQ epilogue prototype was 11.16%/7.01% slower in whole-primary/split-fixup Q4 cases and added 26.29 MB of CUDA code; that prototype is not included.
Correctness and regressions
Ordinary vector/MMF pairing and materialized postprocessing preserve their original arithmetic and qualified full GPU outputs byte-for-byte. The new BF16 cuBLAS replacement preserves operand rounding, but cuBLAS summation order is opaque and its outputs are not claimed byte-identical. Its broad qualification covers eleven admitted numerical/layout groups and eleven original declines: midpoint rounding, cancellation, softplus thresholds, scalar/head factors, extreme factors, strided/batched inputs and odd heads. Twenty-two actual CPU graphs provide 396 per-output/update checks at the unchanged 5e-4 NMSE bound; admitted-case CPU maximum was 1.314e-11. An extreme head-factor fixture has a 0.84375 absolute difference from original CUDA on million-scale outputs, NMSE 8.827e-12. Full differences are retained; the smaller ordinary-case absolute error is not a universal bound.
Independent MMF qualification includes twenty admitted layouts, selector and alias declines, actual CPU graphs, existing backend checks and two clean memchecks. Scaled-beta post qualification covers fourteen layouts, exact-inplace admission, partial/gate overlap declines and a separately saved extra consumer, CPU references and two clean memchecks. Tiled rounded qualification adds N9/N16, larger rejected shapes and batched/strided planes with actual original rounded-input references.
The final integrated DLL passes an independent raw audit of 138 commands, 56 actual profiles, 96 complete three-update component payloads and thirty model output files. Sixteen new-path pairs match individually qualified outputs, canonical kernel inventories and full launch geometry exactly; ten existing-path pairs include original N17/N32 GEMM admission. Four scaled-input alias controls and two clean memchecks pass. Final old-path mean costs versus
b8df474cwere BF16 N1 0.793% more, Q4 N8 0.026% more, packed BF16 MMF 0.734% more, and materialized MMF 0.009% less, with mixed repetition signs. Final fixed-token model means at C1/C3/C4 were 0.019% less, 0.064% more and 0.071% less, with mixed signs and exact saved logits. These are regression checks, not new model gains.Earlier matching Qwen3.5-0.8B Q4_0 fixed-token execution improved 2.10%/1.75% at three/four columns versus initial PR123, while one column used 0.14% more time. Later extension model comparisons are essentially flat with small losses retained. Runs use MTP disabled, 128 fixed steps, 32 warmups, per-process prewarm and four rotated pairs, saving full-vocabulary logits at steps 0, 1, 126, 127. These results do not establish free-generation throughput, native MTP benefit, or actual new MMF/rounded-producer dispatch in that model.
Cost, limits and evidence
The final CUDA library is 87,311,648 bytes, +4,860,552 bytes against
b8df474c; separate MMF adds 768 producer variants. All final compiled resource records match the independently qualified implementations, including selected complete SASS checks. Existing BF16 GDN MMVF has eleven resource changes and a larger N1 instruction body; ordinary selected kernels remain instruction-identical. These are bounded static checks, not a zero-runtime-cost claim. Cached build times are not matched compile-cost evidence.Native FP4 matrix activation paths, separate quantized MMQ producer pairing, non-aligned MMF seams, arbitrary dynamic/LoRA expression pairing, and shared preparation through scaled long-bank cuts are not newly optimized. A single-grid BF16 tiler could reduce repeated bank scans, but remains a source-only next step after measured serial-tiling regression. Existing execution is retained; it is not counted as equivalent optimized coverage. Other GPU generations, HIP/MUSA producer dispatch, native 35B/MTP, full perplexity/CI and the combined PR stack are unqualified. No universal model coverage or speedup is claimed.
Commands, frozen source/helper/DLL hashes, complete GPU/CPU payloads, SQLite profiles, resource/SASS dumps, rejected results and independent reviews are retained under
/home/gencoolpc/moe-cache-tests/results/upstream-kernel-series-20261001, notablyFLOATING-EXPERT/INTEGRATED-FINAL-SOURCE-V2andINTEGRATED-FINAL-PROOF-V1. Each GPU suite holds the ordered shared build/GPU locks for its entire run; timing/model/profile work is serial. Immutable harness corrections preserve successful results and failures without repeating qualified runs or changing numeric policy.Requirements