Skip to content

[models, examples, tests, docs] feat: the GB300 NVFP4 megakernel on a bf16 or FP8 KV cache - #14

Open
JerryGJX wants to merge 3 commits into
mainfrom
gb300-nvfp4-fp8-kv
Open

JerryGJX wants to merge 3 commits into
mainfrom
gb300-nvfp4-fp8-kv

Conversation

@JerryGJX

Copy link
Copy Markdown
Collaborator

What does this PR do?

Adds an FP8 e4m3 KV cache to the GB300's NVFP4 decode megakernel and its draft kernel, beside the bf16 one on main:
serve with engine.kv_cache_dtype=fp8_e4m3 (the default stays bf16). The backend is chosen by the engine's KV cache dtype, as it already is by the GPU and the checkpoint.

  • Two builds of each kernel from the same csrc/, as in the RTX PRO 6000 PR: bf16 KV (no flag: the build on main, its op namespaces unchanged) and FP8 KV (-DMK_KV_FP8=1, op namespaces of its own).
  • blackwell/gpu_backend.py has a backend per KV cache dtype; the build classes carry what depends on the dtype (the cache's view, the scale check, the loaded build's ops). Fp8KvCacheMixin (an FP8 backend refuses calculated KV scales: the kernels read the cache at scale 1) is in deploy/gpu_backend.py. The RTX PRO 6000 PR adds the same class at the same place, so the two merge into one.
  • gpu/gb300.yaml names the KV cache dtype, the deploy README's hardware table gains a KV cache column, and the README's News names the FP8 cache's speed. The RTX PRO 6000 PR edits the same table, run_server.sh, deploy_kernels.py and the recipe test.
  • The bf16 KV path and the bf16 checkpoint's megakernel generate the same code as on main.

How was it verified?

CI's CPU jobs pass locally (pre-commit, the tests job's pytest: 1,128 passed), with new tests for the backend per KV cache dtype, the builds, the cache's view and the scale check.

On GB300 nodes, the branch against the FP8 kernel it was ported from and against main, on one node with the same inputs:

  • Generated code: instruction-identical to the kernels it was ported from (FP8 KV) and to main (bf16 KV, and the bf16 checkpoint's megakernel).

  • Outputs: the accuracy gate, its four sampling variants and decode-only launch dumps are bitwise equal; the acceptance run's 16 answers are the same token for token (acceptance length 3.19).

  • End to end: run_server.sh serves the recipe's 260,096-token window on each cache, and a two-turn chat decodes on the megakernel.

  • Speed: the verify step's period is within the noise at all 12 contexts for both pairs (four rounds):

    context ported kernel, FP8 KV branch, FP8 KV main, bf16 KV branch, bf16 KV
    production (mean of 8 contexts) 4.101 ms 4.101 ms 4.302 ms 4.307 ms
    1,024 3.954 ms 3.953 ms 4.046 ms 4.050 ms
    32,768 4.123 ms 4.120 ms 4.340 ms 4.342 ms
    131,072 4.610 ms 4.609 ms 5.266 ms 5.267 ms
    256,000 5.242 ms 5.242 ms 6.441 ms 6.442 ms

With the DFlash2 checkpoint, measured as the README's GB300 figure (logged robot-control requests through the recipe's server, decode time from the server's metrics; two servers each, over the requests that all four answered to the 2,048-token limit):

KV cache ms per verify step Tokens per verify step Decode tokens/s
bf16 4.287 / 4.286 3.94 / 3.89 919 / 907
FP8 4.107 / 4.130 4.09 / 3.96 997 / 960

Checklist

  • The title reads [module] type: description, for example [envs] fix: the reset of a stale episode. CI checks it against the modules and types of .github/scripts/pr_title.py.
  • One coherent change; unrelated changes go in their own PR.
  • pre-commit run --all-files passes.
  • Tests cover the change, or the section above says why they cannot.
  • A change to a prompt file shows the rendered prompt before and after.
  • A change to 3rdparty/*/patches was exported by the scripts there.
  • No cluster path, host name, account name or credential in the code, the comments or this description.

@JerryGJX
JerryGJX requested a review from Sakits as a code owner November 22, 2026 01:31
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