Skip to content

GDN Decode kernel optimization#2671

Merged
helloworld1 merged 2 commits into
mainfrom
gdn-decode-kernel-opt
May 21, 2026
Merged

GDN Decode kernel optimization#2671
helloworld1 merged 2 commits into
mainfrom
gdn-decode-kernel-opt

Conversation

@helloworld1
Copy link
Copy Markdown
Collaborator

@helloworld1 helloworld1 commented May 19, 2026

Description

Optimize gdn decode kernel

  • Fuse silu in decode kernel, this is almost free to do in kernel
  • For GQA, compute qk first and then repeat instead of repeat qk and then compute.
  • Default block size is not optimal for pipelining. We have enough VMEM to fit everything in 1 block but we want more blocks to overlap the DMAs in first / last block

+--------+---------+---------+--------------+------------+------------+--------------+
| Decode | GDN Old | GDN New | GDN % | Kernel Old | Kernel New | Kernel % |
| Tokens | (us) | (us) | Difference | (us) | (us) | Difference |
+--------+---------+---------+--------------+------------+------------+--------------+
| 64 | 88.9 | 61.3 | -31.05% | 53.6 | 36.7 | -31.53% |
| 128 | 130.8 | 93.7 | -28.36% | 93.6 | 66.6 | -28.85% |
| 256 | 218.8 | 164 | -25.05% | 173.4 | 126 | -27.34% |
| 512 | 377 | 283 | -24.93% | 332 | 239 | -28.01% |
+--------+---------+---------+--------------+------------+------------+--------------+

Tests

Tested E2E benchmark.
Qwen 3.5 397B, total token throughput
1K/8K c64: 2051 -> 2163 (+5.5%)
8K/1K c64: 10745 -> 11522 (+7.2%)

Tested lm_eval mmlu_pro no regression

|       Tasks       |Version|    Filter    |n-shot|  Metric   |   |Value |   |Stderr|
|-------------------|------:|--------------|-----:|-----------|---|-----:|---|-----:|
|mmlu_pro           |    2.0|custom-extract|     5|exact_match|↑  |0.8286|±  |0.0139|
| - biology         |    3.1|custom-extract|     5|exact_match|↑  |0.9400|±  |0.0339|
| - business        |    3.1|custom-extract|     5|exact_match|↑  |0.8800|±  |0.0464|
| - chemistry       |    3.1|custom-extract|     5|exact_match|↑  |0.9400|±  |0.0339|
| - computer_science|    3.1|custom-extract|     5|exact_match|↑  |0.8400|±  |0.0524|
| - economics       |    3.1|custom-extract|     5|exact_match|↑  |0.9000|±  |0.0429|
| - engineering     |    3.1|custom-extract|     5|exact_match|↑  |0.6600|±  |0.0677|
| - health          |    3.1|custom-extract|     5|exact_match|↑  |0.7800|±  |0.0592|
| - history         |    3.1|custom-extract|     5|exact_match|↑  |0.6800|±  |0.0666|
| - law             |    3.1|custom-extract|     5|exact_match|↑  |0.7400|±  |0.0627|
| - math            |    3.1|custom-extract|     5|exact_match|↑  |0.9600|±  |0.0280|
| - other           |    3.1|custom-extract|     5|exact_match|↑  |0.7400|±  |0.0627|
| - philosophy      |    3.1|custom-extract|     5|exact_match|↑  |0.8200|±  |0.0549|
| - physics         |    3.1|custom-extract|     5|exact_match|↑  |0.9400|±  |0.0339|
| - psychology      |    3.1|custom-extract|     5|exact_match|↑  |0.7800|±  |0.0592|

| Groups |Version|    Filter    |n-shot|  Metric   |   |Value |   |Stderr|
|--------|------:|--------------|-----:|-----------|---|-----:|---|-----:|
|mmlu_pro|      2|custom-extract|     5|exact_match|↑  |0.8286|±  |0.0139|

Checklist

Before submitting this PR, please make sure:

  • I have performed a self-review of my code.
  • I have necessary comments in my code, particularly in hard-to-understand areas.
  • I have made or will make corresponding changes to any relevant documentation.

@github-actions
Copy link
Copy Markdown

Description

Start with a short description of what the PR does and how this is a change from
the past.

The rest of the description includes relevant details and context, examples:

  • why is this change being made,
  • the problem being solved and any relevant context,
  • why this is a good solution,
  • some information about the specific implementation,
  • shortcomings of the solution and possible future improvements.

If the change fixes a Github issue, please include a link, e.g.,:
FIXES: #123456

Tests

Please describe how you tested this change, and include any instructions and/or
commands to reproduce.

Checklist

Before submitting this PR, please make sure:

  • I have performed a self-review of my code.
  • I have necessary comments in my code, particularly in hard-to-understand areas.
  • I have made or will make corresponding changes to any relevant documentation.

@helloworld1 helloworld1 marked this pull request as ready for review May 19, 2026 19:36
@helloworld1 helloworld1 force-pushed the gdn-decode-kernel-opt branch from ca42250 to 92374ea Compare May 19, 2026 19:37
@helloworld1 helloworld1 added the ready ONLY add when PR is ready to merge/full CI is needed label May 19, 2026
@helloworld1 helloworld1 force-pushed the gdn-decode-kernel-opt branch 2 times, most recently from 14782f5 to 972fe31 Compare May 20, 2026 16:57
Comment thread tpu_inference/kernels/gdn/fused_gdn_kernel_wrapper.py
@helloworld1 helloworld1 force-pushed the gdn-decode-kernel-opt branch from 972fe31 to 6d19704 Compare May 20, 2026 17:53
@qizzzh qizzzh requested a review from yaochengji May 20, 2026 20:52
@helloworld1 helloworld1 force-pushed the gdn-decode-kernel-opt branch from 6d19704 to c5f1574 Compare May 20, 2026 22:42
Comment thread tpu_inference/kernels/gdn/fused_gdn_decode_kernel.py Outdated
Comment thread tpu_inference/kernels/gdn/fused_gdn_decode_kernel.py Outdated
Comment thread tpu_inference/kernels/gdn/fused_gdn_decode_kernel.py
@helloworld1 helloworld1 force-pushed the gdn-decode-kernel-opt branch from 88403f1 to 0168ba1 Compare May 21, 2026 02:36
Signed-off-by: Haowen Ning <hning@google.com>
Signed-off-by: Haowen Ning <hning@google.com>
@helloworld1 helloworld1 force-pushed the gdn-decode-kernel-opt branch from 0168ba1 to 4faedf5 Compare May 21, 2026 04:30
@lk-chen lk-chen removed their request for review May 21, 2026 14:06
@helloworld1 helloworld1 merged commit b8f2132 into main May 21, 2026
63 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready ONLY add when PR is ready to merge/full CI is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants