Skip to content

cuda: use MT2 FP8 attention on RTX PRO 4500 - #1731

Merged
ashhart merged 2 commits into
ashhart:mainfrom
Maxrio9:cuda/pro4500-attention
Nov 4, 2026
Merged

ashhart merged 2 commits into
ashhart:mainfrom
Maxrio9:cuda/pro4500-attention

Conversation

@Maxrio9

@Maxrio9 Maxrio9 commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Update (nvcc 13.0, rebased on main 37a4a84a): this branch now carries only the source and tests (see the receipts branch for the evidence: nvcc 13.0 run). Full CUDA contract under nvcc 13.0.88: 511 kernels pass gates 1-4, 0 fail, 340/340 controls caught, 213 limit problems, identical to untouched main under the same compiler; the new launches pass their live limit checks. The earlier numbers below are from the 13.3 run on 94b90c9d.

The FP8 MT2 attention tile is selected only for SM120/82SM and its supported cached-token range. BF16/FP32 arithmetic and serving features stay unchanged; graph-cache identity records the tile choice. Fixes #1701. No GDN fusion; the MLP change remains separate in #1730.

Draft: numerical qualification completed; the global backend gate fails only on unchanged main limit-record gaps.

The full unfiltered CUDA integration run reports 465 kernels passing gates1–4, zero numerical failures, eight declared known findings;322/322 controls caught, zero missed;223 limit-record problems. A limits-only control with unmodified main production kernels/registry reproduces the identical168 missing static records and55 live mismatches. The three new launches (MLP128 and both MT2 forms) all pass their own live limit checks. Full backend qualification therefore remains red; the PR stays draft pending maintainer review of that unchanged baseline.

Complete numerical run and main-only limit diagnosis contains the exact SUMMARY, full/partial logs, source/binary/build hashes, baseline control and every failure. One combined integration binary contains the two independently benchmarked changes plus a disclosed five-file test-only fixture-lifetime fix; math/shapes/seeds/controls/bounds stay unchanged. This does not claim an unmodified-source, single-contribution-only or globally passing backend run.

Independent current-main94b90c9d native-binary override0/1/0 bracket on RTX PRO4500:

Decode 8K 32K
Drafted +2.390% +3.474%
Plain +1.066% +2.045%

The fixture labels are8K/32K; exact rendered inputs are8,210/32,785 tokens, with128 output tokens. Prefix reuse and per-request cache counts are retained; these are decode measurements, not cold-prefill claims.

All matched tokens, vision PNG/JPEG/WebP, tools/schema/reasoning, cancellation/recovery, fallbacks and context checks pass. Short classic is +0.018%; short community is -0.379%. These are workload-specific results from one bracket, with no confidence interval. Earlier source01e25d3a brackets remain separate.

Raw current-main bracket, exact medians, hashes, fixtures, source patch and build identities. The public code branch retains its original01e25d3a ancestry; the receipt identifies the separately rebased94b90c9d test source and new binary.

Complete receipt and retained failures. Includes replacement registration, live/compiled launch records, host chip/shape/cache dispatch controls, four clean sanitizer runs, independent old-source overrides and completed60-request cold supplement. Newer host graph passes285/285 steps with108 fresh tests and cached remainder using a disclosed common test-fixture repair; original mock-fixture crashes reproduced on untouched main are retained. This is not an unmodified-source host pass or fullGPU qualification.

Desktop only: RTX PRO4500 Blackwell SM120/82SM,200W;5900X,31.24GiB physical RAM,24GiB test budget;driver615.78.08,Zig0.17.0,nvcc13.3.73. Native Zig/CUDA. Qwen3.8-27B affine4/group64 revision22d8d538154e0e5b6f8dcb1fcc74a60a0798104c and BF16 DFlash2 revision50307d4c4cde6860d4eee73e2547cd786fe8e8a4.131072context,vision/reasoning/tools/schema,FP8KV,int8prefill,8GiBhost cache,parallel1,upstream0.5GiB reserve. Explicit1.1.6 version label is recipe compatibility metadata, not release provenance. No physical5090/PRO6000 qualification; override testing instructions remain in the existing PR comment.

  • Independent8K/32K served receipt, tokens/features equal.
  • Replacement/launch/host dispatch and sanitizer evidence attached with scope limits.
  • Cold prompt supplement and negative controls retained.
  • Complete unfiltered numerical run and publish final SUMMARY, including all failures.
  • Resolve unchanged main compiler-record gaps / obtain maintainer scope decision before marking ready.
  • Maintainer release/cross-platform/previous-release and standard-server gates where applicable.

@Maxrio9

Maxrio9 commented Oct 31, 2026

Copy link
Copy Markdown
Contributor Author

Testing request: RTX 5090 and RTX PRO 6000 Blackwell owners

Could someone with either card test this improvement independently? Please specify the PRO 6000 edition (Workstation, Max-Q or Server) and power limit. Use only PR #1731; do not combine it with the companion PR.

A startup-only experimental override is now included:

Setting Effect
TF_CUDA_TEST_ATTN_MT2=0 Original kernel path: baseline
TF_CUDA_TEST_ATTN_MT2=1 Candidate path on SM120, including other SM counts
Unset Existing automatic policy: candidate only on SM120/82 SMs

Other architectures cannot be forced on. Model/shape, precision, KV, context and graph guards remain in place. For attention, wider windows are still selected only at 8192<=cached<65536; the override does not force every attention shape. The flags are read at startup, so restart the server between arms. Exporting the flag only in the benchmark client does nothing.

Commands below assume Linux/Bash.

1. Isolated checkout and one build

git clone --filter=blob:none --no-checkout https://github.com/ashhart/TensorFold.git tensorfold-pr1731-test
cd tensorfold-pr1731-test
git fetch origin pull/1731/head
git checkout --detach FETCH_HEAD
git rev-parse HEAD
zig build native -Dsm=120 -Dnvcc="$(command -v nvcc)" -Dversion=pr1731-test -j4

Use Zig 0.17.0 and preferably the same CUDA 13.0 or 13.3 toolchain for all arms; record full versions. Reuse your qualified grammar/media library setup. Use the same TensorFold/Qwen3.8-27B-MLX-4bit revision 22d8d538154e0e5b6f8dcb1fcc74a60a0798104c and BF16 z-lab/Qwen3.8-27B-DFlash2 revision 50307d4c4cde6860d4eee73e2547cd786fe8e8a4 throughout.

2. Server terminal: baseline, candidate, baseline again

Set MODEL_DIR and DRAFTER_DIR to your existing checkpoint directories. Stop other GPU workloads during each measured arm. Start with 0, then repeat with 1, then 0 again. Set ARM respectively to baseline, candidate, baseline-repeat; each invocation gets fresh calibration storage.

unset TF_CUDA_TEST_MLP128 TF_CUDA_TEST_ATTN_MT2
MODEL_DIR=/path/to/Qwen3.8-27B-MLX-4bit
DRAFTER_DIR=/path/to/Qwen3.8-27B-DFlash2
ARM=baseline
TF_CUDA_TEST_ATTN_MT2=0 TENSORFOLD_MEMORY_RESERVE_GIB=0.5 HOME="$(mktemp -d)"   ./zig-out/native/bin/tensorfold-native serve "$MODEL_DIR"   --drafter "$DRAFTER_DIR" --name bench --host 127.0.0.1 --port 18080   --context 131072 --parallel 1 --kv-cache fp8 --prompt-precision int8   --vision --prompt-cache-gib 8 --max-tokens 2048   >"$ARM-server.log" 2>&1

Confirm the log says experimental MT2 override=0, enabled=false for baseline and override=1, enabled=true for candidate. An enabled device flag permits the candidate only on its eligible shapes; it does not mean every launch uses it. Keep the same power settings, context, vision, caches and precision in all arms. If this configuration cannot fit, report that rather than silently reducing features in one arm.

3. Client terminal: identical sequence for every arm

Wait until /health is ready and warming is false. Set ARM to match the server terminal, then run:

ARM=baseline
RECEIPT=docs/receipts/rtx-pro-4500-attention-20261030
python3 tools/bench_openai.py http://127.0.0.1:18080 bench   --tokens 256 --reps 5 --temperatures 0,1 --output "$ARM-short.json"
python3 "$RECEIPT/testing/replay_long.py" http://127.0.0.1:18080   "$RECEIPT/testing/fixture-8192.json" --model bench --repetitions 3   --output "$ARM-long8k.json"
python3 "$RECEIPT/testing/replay_long.py" http://127.0.0.1:18080   "$RECEIPT/testing/fixture-32768.json" --model bench --repetitions 3   --output "$ARM-long32k.json"

The long replay runs both draft=true and draft=false, checks repeated hashes, and asserts drafted/plain token equality. After all three arms, also check baseline/candidate hashes:

python3 - <<'CHECK'
import json
for size in ['8k', '32k']:
    reference = None
    for arm in ['baseline', 'candidate', 'baseline-repeat']:
        samples = json.load(open(f'{arm}-long{size}.json'))['samples']
        hashes = {(x['drafted'], x['repeat']): x['response']['tensorfold']['token_sha256'] for x in samples}
        if reference is None:
            reference = hashes
        assert hashes == reference, (size, arm, 'token mismatch')
print('Long-fixture hashes match across all three arms.')
CHECK

Please attach

GPU model/edition and power limit; driver, nvcc, Zig, OS and Git SHA; checkpoint revisions and unchanged serving settings; all nine benchmark JSON files and the three server logs. Include the short benchmark's evidence hashes, not just headline tok/s. Report short, 8K, 32K, plain and drafted results separately, including regressions. For the long runs use median server decode tok/s; compare candidate against the geometric mean of the two baseline medians. Report prefill/TTFT separately, and keep cached-token counts visible.

This is a focused performance/exactness request, not a request to run an hours-long full suite. The PR remains draft: full backend contract SUMMARY qualification and the other documented release gates are still outstanding. No GPU run of this newly added override has been performed locally; pure override tests and targeted host checks passed. The original 4500 receipts remain pinned to their original measured commits. Please report failures without disabling hash checks or changing precision.

@ashhart

ashhart commented Nov 1, 2026

Copy link
Copy Markdown
Owner

Thanks @Maxrio9. +2.4% and +3.5% drafted at 8K and 32K with every token equal is a good result, and checking the MT2 tile row by row against tf_q35_attn_rows8 is the right contract case. A few things before it can come out of draft. cuda_engine.zig ends at 605 lines; please move the MT2 functions and flag out so it stays under 600. Short community decode is −0.38% in the bracket, and every one-row decode takes MT2 at any context length, so short chats get the new tile too. We need that shown to be noise, with alternating groups like #1730's, or one-row MT2 limited to the 8,192-plus range you measured. Please also add a one-row, short-cache shape to the MT2 forms' served list. The same limit-record and receipt points as #1730 apply here: the nvcc 13.0 SUMMARY gates it, and we'll add main's 13.3 set ourselves.

@Maxrio9

Maxrio9 commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

Thanks. Taking your points in order:

cuda_engine.zig size. The MT2 functions and flag moved to a new cuda_mt2.zig (Mt2.resolve: device choice, the override and the two entry points). The engine file is now 599 lines (main is 596).

Short decode. I took your second option rather than trying to show −0.38% is noise: MT2 is now selected only from 8,192 cached tokens up, one-row decode included (useMt2 requires cached >= 8192 for every row count; the 16-row upper bound of 65,536 is unchanged). Short chats therefore take the same tile as main, by construction. useMt2 has unit tests at 0, 512, 8191, 8192 and 131071 for one row, and the graph-cache identity still records the tile. I did not run a new served bracket for the short case, since its code path is the one on main; the 8K/32K results above are on the path that is unchanged, but they were measured on 94b90c9d and not re-measured on this commit.

Served list. Added a one-row, short-cache shape (rows=1, k=512) to both MT2 forms. Production no longer dispatches MT2 there, so it is extra numerical coverage of the kernel rather than a served shape; say if you'd rather not have it. It passes gates 1-4 and the controls in the run below.

nvcc 13.0 SUMMARY (current main 37a4a84a, nvcc 13.0.88; combined binary with #1730 and the fixture fix from #1845):

SUMMARY 511 kernels: 511 pass gates 1-4, 0 fail, 8 known findings; 340 controls: 340 red as planted, 0 missed; 213 limit problems; gates 5503142 ms, limits 1037963 ms

Both MT2 forms pass their live limit checks under 13.0 (242 and 239 registers, 36,992 static bytes, 128 threads, matching the records). The 213 problems are the same 168 missing static records and 45 live mismatches that untouched main reports under the same compiler (identical sorted lists, apart from the three new passing launches), so 13.0 doesn't make the global gate green for me; if CI uses a different entry point, tell me and I'll run it.

Receipts are on the receipts/pro4500-attention branch of my fork with a short README and hashes; this branch now holds only the change (14 files). I didn't force-push, so the old receipt commits remain in its history (moot under squash-merge). TF_CUDA_TEST_ATTN_MT2 now accepts only 0 or 1 and refuses other values by name.

Scope: combined binary, graphical desktop active with a 4 GiB reserve (not headless); the contract is deterministic with no timing gates.

@Maxrio9

Maxrio9 commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

CI update for the current head (024d84b0): the earlier zig failure was the lean check on my new comment in cuda_shapes.zig; that is fixed (zig, zig-macos-dev-tools, zig-windows, fmt, release-paths, desktop-linux, appimage-linux and mobile all pass).

The one remaining red job is desktop: electron/agent/bot-vm/guest.test.ts fails with VM tool refused: [Errno 1] Operation not permitted on the macOS runner (854/855 pass). This pull request changes no files under app/ (only zig/), and the same job passed on #1730, so this looks like a runner-sandbox flake rather than something this change touches. I can't re-run it from a fork (no admin rights); could a maintainer re-run the failed desktop job, please?

@ashhart

ashhart commented Nov 2, 2026

Copy link
Copy Markdown
Owner

Thanks @Maxrio9: asks 2 to 4 are answered. useMt2 now needs cached ≥ 8,192 for every row count, both MT2 forms serve one row at 512/8,191/8,192 and up to 122,779 keys, and nvcc 13.0's SUMMARY is 511 pass, 340/340 controls, with limit problems equal to main's. One mechanical change: on current main, cuda_engine.zig goes from 598 to 601 lines and the lean check reports 425 problems against main's 424. Please rebase and keep it at 600 or fewer. Then it lands with #1730.

@Maxrio9

Maxrio9 commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

@ashhart this is ready for your check. I merged main into the branch rather than rebasing (a rebase would need a force-push). cuda_engine.zig is back to 600 lines (one blank line removed from the import block, since the MT2 code needs three lines there), and the lean check reports 424 problems, the same as main's, so nothing new. Head is now b5d34f7e, merged with main at c7952f39. Main moves quickly, so if it conflicts again by the time you get here, please say and I'll merge again.

On the previous head (dd5fc338), zig, zig-windows, fmt, release-paths, desktop-linux, appimage-linux and mobile passed. desktop and zig-macos-dev-tools show as cancelled: desktop after 9 minutes in the typecheck step, and the macOS job after about 2.5 hours, so neither is a test failure. A re-run of those two would complete the set; I have no re-run rights on a fork.

It is still a draft; I'll mark it ready for review on your word. It lands with #1730.

@Maxrio9
Maxrio9 force-pushed the cuda/pro4500-attention branch from b5d34f7 to f820a50 Compare November 3, 2026 16:27
@ashhart

ashhart commented Nov 4, 2026

Copy link
Copy Markdown
Owner

Thanks @Maxrio9. Every ask is met: MT2 only from 8,192 cached tokens, the one-row short-cache shape in the served list, cuda_engine.zig at 600 lines, and the nvcc 13.0 SUMMARY. The 16:27 push cancelled CI, so we're re-running it on this head, and we've taken it out of draft. We'll squash it so the old receipt commits stay out of main, and land it together with #1730.

@ashhart
ashhart marked this pull request as ready for review November 4, 2026 06:59
@ashhart
ashhart force-pushed the cuda/pro4500-attention branch from f820a50 to ea72b0c Compare November 4, 2026 07:01
ashhart pushed a commit to Maxrio9/TensorFold that referenced this pull request Nov 4, 2026
ashhart#1731's code as one commit onto main; its receipts stay on the contributor's branch.
ashhart added a commit to Maxrio9/TensorFold that referenced this pull request Nov 4, 2026
ashhart pushed a commit to Maxrio9/TensorFold that referenced this pull request Nov 4, 2026
ashhart#1731's code as one commit onto main; its receipts stay on the contributor's branch.
@ashhart
ashhart force-pushed the cuda/pro4500-attention branch from ea72b0c to 3fd29b2 Compare November 4, 2026 09:30
ashhart added a commit to Maxrio9/TensorFold that referenced this pull request Nov 4, 2026
Maxrio9 and others added 2 commits November 4, 2026 10:28
ashhart#1731's code as one commit onto main; its receipts stay on the contributor's branch.
@ashhart
ashhart force-pushed the cuda/pro4500-attention branch from 3fd29b2 to 90d6bd3 Compare November 4, 2026 10:28
@ashhart
ashhart merged commit 3bdc4e5 into ashhart:main Nov 4, 2026
ashhart pushed a commit that referenced this pull request Nov 4, 2026
#1731's code as one commit onto main; its receipts stay on the contributor's branch.
@ashhart

ashhart commented Nov 4, 2026

Copy link
Copy Markdown
Owner

Thank you @Maxrio9. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

@ashhart

ashhart commented Nov 5, 2026

Copy link
Copy Markdown
Owner

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.

CUDA: context-aware FP8 attention row tiles for RTX PRO 4500 Blackwell

2 participants