Skip to content

feat(cuda): Ampere (sm_80/86) runs the bf16 kernels; FP8 prompts stay at 8.9 and NVFP4 runs W4A16 below it - #363

Closed
gilby wants to merge 1 commit into
ashhart:mainfrom
gilby:ampere-sm80
Closed

gilby wants to merge 1 commit into
ashhart:mainfrom
gilby:ampere-sm80

Conversation

@gilby

@gilby gilby commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Part of #311. CUDA builds and runs from compute capability 8.0 instead of 8.9 for every path that
needs only bf16 tensor cores; FP8 stays at 8.9:

  • build.MIN_CAPABILITY is 8.0 (bf16 MMA, ldmatrix, cp.async) and build.FP8 is 8.9; build.has() asks the GPU,
    and a refusal names the missing feature.
  • The FP8 prompt kernels (qmm_prefill8.cu) build from 8.9; below it qmm_prefill8_none.cu refuses them by name, so
    bf16 prompts work.
  • The NVFP4 lane matmuls and experts build from 8.0 (bf16 MMA, e4m3 scales converted in software); the checkpoint-math
    extension stays at 8.9, and precision.own_math already runs W4A16 below it.
  • capacity.floor: 8.0 for every format with bf16 prompts, 8.9 with --prefill-fp8.

No kernel arithmetic changes: sm_89+ builds the same code as before, and below 8.9 the existing W4A16 / bf16-prompt
paths run.

Receipt

  • Environment, with the TensorFold commit, MLX or PyTorch version, machine and GPU, checkpoint and revision: one NVIDIA A40 (sm_86) in a VM, torch 2.13.0+cu130, CUDA 13.0, Triton 3.7.1; v0.6.5 (609ca41) vs this branch. RadixArk/Qwen3.8-27B-NVFP4-BF16-LMHead @ 009632f with z-lab/Qwen3.8-27B-DFlash2 @ 50307d4. Server: tensorfold serve <checkpoint> --backend cuda --drafter <drafter> --context 65536 --parallel P (P = 1 and 4). Startup: "startup estimate 27.88 GiB within
    39.72 GiB" (31.07 at --parallel 4), "precision: full (NVIDIA A40, SM 8.6 has neither the block-scaled FP4 nor the FP8 mma):
    bf16 activations, the stored weights". SM clock median 1,425 MHz under load, 73 °C peak, no throttling.
  • Exactness, from tools/bench_concurrent.py --alone --serial or token_sha against "draft": false: v0.6.5 refuses: "TensorFold's CUDA kernels need compute capability 8.9 or newer (FP8 MMA); this GPU (NVIDIA A40) is 8.6". On
    this branch: token_sha drafted == "draft": false on two prompts (6972e271bc22, 077d971998da), the same in two runs.
    --levels 2,4 --alone --serial at --parallel 4: 0 failed, alone 6/6 and 12/12, serial 4/4 and 1/1, 0 unequal in all 8 cells.
  • Decode speed before and after, from tools/bench_openai.py: before is the refusal above. After, --tokens 256 --reps 5,
    medians of two runs: fibonacci-raw greedy 43.4 / 43.1, sampled 49.2 / 49.4; gpu-chat greedy 29.0 / 28.7, sampled
    26.0 / 26.1 tok/s. Concurrent aggregate (greedy, N=2 / N=4): code 49.9 / 79.7, chat 37.5 / 55.0.
  • Prompt speed before and after, from tools/prefill_cold.py: after, 3 reps, median: 2k 1,194 tok/s, 8k 1,265, 16k 1,243.
    No before (refused).
  • On v0.6.5: this branch rebased onto v0.6.5 (609ca41) as 409ab3e. Mac host suite (M5 Ultra): 5001 passed, 1 failed, 597 skipped; the one failure, test_glm5_prompt_kernels::test_fused_index_scores_are_the_three_ops, fails on v0.6.5 too. CUDA on v0.6.5 (one DGX Spark, GB10, sm_121 unchanged): pytest tests/cuda tests/test_cuda_build.py -k "qwen27 or qwen36 or nvfp4 or b16 or qmm or moe or build or distributed or dflash or dspark or exl3 or graph": 681 passed, 0 failed, 81 skipped.
  • Tests run, with pass, fail and skip counts: on the A40, pytest tests/cuda tests/test_cuda_build.py -k "qwen27 or nvfp4 or b16 or qmm or build or distributed" on the e4m3 change stacked on this one (this branch plus one kernel helper):
    371 passed, 0 failed, 59 skipped (one GPU visible). On one DGX Spark (GB10), the CUDA selection above: unchanged
    behaviour on sm_121 (same build, same kernels).
  • Checked on v0.6.5 (2026-10-04): one NVIDIA A40, the same checkpoint, drafter and --context 65536 --parallel 1: fresh == resumed (2,296 of 2,301 tokens from the prompt cache) == "draft": false, token_sha 8b07e71904c8; 19 × 23 drafted == "draft": false 7773d573571d. Fail-before: this branch's tests on v0.6.5's tree, on the A40: the tests/cuda files error at collection (no build.has), tests/test_cuda_build.py 3 failed, 19 passed; on this branch 62 passed, 25 skipped, 0 failed; without CUDA 22 passed, 3 skipped. On one DGX Spark (GB10), tools/prefill_cold.py (2k / 8k / 16k, 3 reps, median tok/s; runs v0.6.5, this, this, v0.6.5, each side the mean of its two) on RadixArk/Qwen3.8-27B-NVFP4-BF16-LMHead + z-lab/Qwen3.8-27B-DFlash2 at --context 131072 --parallel 1, a checkpoint v0.6.5 serves: v0.6.5 → this 2,590 → 2,600 / 2,851 → 2,853 / 2,735 → 2,741.
  • Not run, and why: sm_80 (A100) and RTX 30 (no hardware).
    Metal untouched.

Checklist

  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo.
  • No precision traded for speed. If the bits change, the description says which sums change and why.
  • Prompt processing is no slower than the last release. (No before on an A40: v0.6.5 refuses it. On one DGX Spark, the 27B NVFP4 + DFlash2, which v0.6.5 serves: +0.1 to +0.4%; see the v0.6.5 check.)
  • The description says which platforms I ran, Metal M1 to M5 and CUDA, and which I could not.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency. (On v0.6.5's tree the new CUDA tests error at collection and tests/test_cuda_build.py fails 3; all pass here and skip without CUDA. See the v0.6.5 check.)
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths. No AI attribution lines.

… at 8.9 and NVFP4 runs W4A16 below it

- build.MIN_CAPABILITY is 8.0 (bf16 MMA, ldmatrix, cp.async) and build.FP8 is 8.9; build.has() asks the GPU, and the
  refusal names the missing feature.
- The FP8 prompt kernels (qmm_prefill8.cu) build from 8.9; below it qmm_prefill8_none.cu refuses them by name, so
  bf16 prompts work.
- The NVFP4 lane matmuls and experts build from 8.0 (bf16 MMA, e4m3 scales converted in software); the
  checkpoint-math extension stays at 8.9, and precision.own_math already runs W4A16 below it.
- capacity.floor: 8.0 for every format with bf16 prompts, 8.9 with --prefill-fp8.
- Tests: Ampere builds and refuses FP8, an sm_70 GPU is refused by name, the floor follows prompt precision; the
  FP8-prompt cases in tests/cuda skip below 8.9.
@ashhart

ashhart commented Oct 6, 2026

Copy link
Copy Markdown
Owner

Thank you, @gilby. Splitting the floor by feature, bf16 paths from 8.0 and FP8 from 8.9, with every refusal naming what's missing and no arithmetic change on 8.9 and up, is the right shape for this. The A40 receipts make it concrete.

The Python engine is frozen (#286), so this won't merge. Zig CUDA builds every kernel for one target list, GB10 at sm_121 by default, so Ampere waits for Zig CUDA to take more targets. When it does, your per-feature floor is the rule we'd give its build, kernel by kernel, with your credit. RTX 30 cards, which are sm_86, are tracked in #139.

@ashhart ashhart closed this Oct 6, 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.

2 participants