Skip to content

[WIP] feat(gpt-oss-megakernel): fused decode megakernel for GPT-OSS-120B - #988

Draft
vmalepati1 wants to merge 1 commit into
lightseekorg:mainfrom
vmalepati1:feat/gpt-oss-decode-megakernel
Draft

[WIP] feat(gpt-oss-megakernel): fused decode megakernel for GPT-OSS-120B#988
vmalepati1 wants to merge 1 commit into
lightseekorg:mainfrom
vmalepati1:feat/gpt-oss-decode-megakernel

Conversation

@vmalepati1

Copy link
Copy Markdown

Summary

Adds a persistent Triton decode megakernel for GPT-OSS-120B that runs all decoder layers and the final RMSNorm in a single kernel launch on gfx950 (MI350), for world-size 1 decode.

It is gated behind --enable-gpt-oss-megakernel and only applies when the model shape matches (64 attention heads, hidden size 2880). When it cannot run, forward falls back to the standard per-op path.

Variants

Three env-selected variants share one weight snapshot and dispatch path:

  • precise: fp32 dequant, the default when the megakernel is enabled
  • MFMA (TOKENSPEED_GPT_OSS_MEGAKERNEL_MFMA=1): MFMA dot path
  • leader-follower barrier (TOKENSPEED_GPT_OSS_MEGAKERNEL_MSBAR=1): adds a two-phase grid barrier (sharded arrival atomic plus a single published release flag), supersedes MFMA when set

Correctness and performance

The variants are bit-exact to the shipped dot path at bs 1, 4, and 8 across all positions.

Measured decode TPOT on MI350X, world-size 1:

  • precise: 19.1 ms
  • leader-follower barrier: 9.7 ms

Changes

  • New modules under python/tokenspeed/runtime/models/: gpt_oss_megakernel/, gpt_oss_megakernel_mfma/, gpt_oss_megakernel_mfma_msbar/
  • gpt_oss.py: forward override that dispatches to the megakernel when it can run, plus runner selection at weight-load time
  • Two server args (enable_gpt_oss_megakernel, gpt_oss_megakernel_max_bs) wired through server_args and the global env dict

Notes

Draft. Tests and docs are not yet included.

Add a persistent Triton megakernel that runs all decoder layers and the
final RMSNorm of GPT-OSS-120B in a single launch on gfx950 (MI350), for
world-size 1 decode. Gated behind --enable-gpt-oss-megakernel and applied
only when the model shape matches (64 attention heads, hidden size 2880).
When it cannot run, forward falls back to the standard per-op path.

Three env-selected variants share one weight snapshot and dispatch path:
  - precise: fp32 dequant (default when the megakernel is enabled)
  - MFMA (TOKENSPEED_GPT_OSS_MEGAKERNEL_MFMA=1): MFMA dot path
  - leader-follower barrier (TOKENSPEED_GPT_OSS_MEGAKERNEL_MSBAR=1):
    adds a two-phase grid barrier (sharded arrival atomic plus a single
    published release flag), supersedes MFMA when set

The variants are bit-exact to the shipped dot path at bs 1, 4, 8 across all
positions. Measured decode TPOT on MI350X, world-size 1: precise 19.1 ms,
leader-follower barrier 9.7 ms.

Wires two server args (enable_gpt_oss_megakernel, gpt_oss_megakernel_max_bs)
through server_args and the global env dict.

Signed-off-by: vmalepati1 <malepativikas@gmail.com>
@borontion borontion changed the title feat(gpt-oss-megakernel): fused decode megakernel for GPT-OSS-120B [WIP] feat(gpt-oss-megakernel): fused decode megakernel for GPT-OSS-120B Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant