Skip to content

Qwen3.5-family CUDA: enable dense MTP drafting - #3582

Merged
ashhart merged 6 commits into
ashhart:mainfrom
tacosta:feat/2485-mtp-dense-enable
Nov 21, 2026
Merged

ashhart merged 6 commits into
ashhart:mainfrom
tacosta:feat/2485-mtp-dense-enable

Conversation

@tacosta

@tacosta tacosta commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Enables dense MTP loading and execution only on TensorFold's native CUDA Qwen3.5-family path. The implementation does not add MTP support to other model families or backends. Qualification used the nvidia-3.8-27b-nvfp4 checkpoint through this family adapter; that checkpoint does not broaden the supported scope.

The change keeps target-only decoding as the default and adds memory-peak checks, overflow handling, KV-only prompt absorption, bounded suffix tap capture, GPU-resident draft feedback, and sampled-draft coupling tests. The optional normalized-prompt-feature interface is reusable by other compatible drafters and is not MTP-specific.

  • Issue: Refs CUDA: add MTP drafting support for dense target models #2485; this implements one family/backend path and does not complete broader family or platform coverage.
  • Stacked on: prerequisite feat(lanes): expose optional normalized prompt features #4132 was merged into main at 4c616e63d57204cd8395dc3af9b572d9ec49626b. This branch contains one MTP commit, 5b2be93de13ddbc406f072caa5867e55d7118d16, based on that commit. The tested base is 4c616e63; current main is dc71af9d and contains that base plus 109 commits. Receipts remain anchored to the tested base.
  • ATC issue check: incomplete because of pullRequestsLimit; the snapshot lists this PR as mine. The scan limit is tracked in ATC #18.
  • atc overlap --json --base origin/main: run on 2026-11-21 against tested origin/main at 4c616e6; incomplete because of otherPullRequestsLimit, pullFilesUnavailable, pullRequestsLimit and timeLimit. It reports 3 clean, 7 conflicting and 71 unknown working-tree comparisons; 81 comparisons for PR Qwen3.5-family CUDA: enable dense MTP drafting #3582 are unknown; 9 local worktree overlaps are conflicts. This is not an all-clear scan. Maintainers can set the ordering for the overlaps, as requested in their stack guidance.

Checks on this head

  • Head commit: 5b2be93de13ddbc406f072caa5867e55d7118d16.
  • Lean checker on tested base 4c616e63 and this head: 168 / 168 findings, 0 new findings.
  • Tests run: zig build -j4 test test-golden --summary all passed (exit 0; 322/335 primary golden outputs matched, zero unexpected differences, 13 known differences; secondary goldens 55/55). python3 -m unittest discover -s tools/bench/mtp2485 -p test_receipts.py passed 24/24. zig fmt --check build.zig zig and git diff --check passed. Native baseline/candidate builds and the checkpoint-backed Qwen3.5 MTP CUDA qualification passed. The focused tf_q35_tap contract passed full-capture and suffix cases and detected its planted controls.
  • CI: no checks were reported on this head when this description was updated.
  • Not run or incomplete: explicit fail-before and dependency-absent skip evidence for every new test; the full all-kernel CUDA contract; GB10 runtime qualification; 32K/64K cold prompts where admitted. DFlash2 could not start at 8K/context 9,216 within the device memory budget.

Receipt

  • Main against branch: test base 4c616e63d57204cd8395dc3af9b572d9ec49626b, candidate 5b2be93de13ddbc406f072caa5867e55d7118d16. The current upstream main dc71af9d descends from the tested base by 109 commits. Cold prompt cache was disabled, each sample used a fresh server, and variant order alternated. The primary measurement is the first request only.
Prompt Context Repetitions Main TTFT Candidate, no drafts Candidate, MTP3 MTP3 vs main MTP3 vs no drafts DFlash2
2K 4,096 5 1.206925 s 1.201196 s (-0.475%) 1.216667 s (+0.807%) +0.807% +1.288% 1.202124 s (-0.398% vs main)
8K 9,216 5 4.921857 s 4.928028 s (+0.125%) 4.932454 s (+0.215%) +0.215% +0.090% Could not start: device memory budget

My working noise band is 1.5%; both MTP TTFT comparisons are within it. This is the submitter's interpretation of the measured spread, not a claim that maintainers have changed the written performance gate. The benchmark's stored report still shows its original 0.1% flags.

Earlier 10-repetition receipt, retained for comparison: base e7ff97e132f2268c7c52bf55d1b8bdbb033462f3, candidate a4ea384e1edbea9b4e285c6f394795ae25b0e0eb.

Prompt Main Candidate, no drafts Candidate, MTP3 MTP3 vs main MTP3 vs no drafts DFlash2
2K 1.227061 s 1.225123 s (-0.158%) 1.228690 s (+0.133%) +0.133% +0.291% 1.224735 s
8K 4.946709 s 4.948742 s (+0.041%) 4.944219 s (-0.050%) -0.050% -0.091% Could not start within device memory budget
  • Boxes it reaches: native CUDA on the Qwen3.5-family path, with the tested nvidia-3.8-27b-nvfp4 checkpoint. No other family or backend is claimed.
  • New switch: existing --drafter selects a compatible MTP checkpoint; --mtp-drafts sets proposal depth, default 3. Target-only remains the default.
  • Environment: Linux, Zig 0.17.0, CUDA 13.3, NVIDIA RTX 5090 Laptop GPU (SM120), 32 GiB host RAM. The target was nvidia-3.8-27b-nvfp4; the separate DFlash2 comparison used z-labs-3.8-27b-dflash2. The immutable checkpoint revision was not recorded. Runs explicitly set TF_QWEN_NVFP4_TC=1, TF_MTP_BATCH=1 and TF_QWEN35_CHUNK_SOLO=4096; memory reserve and CUDA memory limit used defaults. Current-run config, tokenizer and model-index hashes are retained in the raw receipt.
  • Paths and platforms: the native Qwen3.5-family CUDA path was runtime-qualified on SM120 only. Release fatbins were built for SM80/86/89/120/121; no runtime qualification on those other SMs, GB10, Metal, HIP, Windows or mobile.
  • Exactness: current serving receipt reports 240 equal comparisons, 0 unequal and 0 unverified across greedy and seeded-sampled checks. Resume matched fresh output in all four tested no-draft/MTP and greedy/sampled modes. The MTP lane/tree checks include partial acceptance and multi-stream cases. Four-stream target-only ran; four-stream MTP was refused for device capacity, so the widest admitted MTP receipt is three streams.
  • Decode speed: fresh servers, context 1,024, prompt cache 0, 128 requested tokens, two repetitions over code and chat prompts. Aggregate tok/s at temperatures 0 / 1.0, for 1 / 2 / 3 streams: main no-drafts 34.40/65.35/94.95 and 34.35/65.20/94.70; candidate no-drafts 34.40/65.15/94.65 and 34.30/65.05/94.55; MTP3 78.40/145.10/197.75 and 74.45/132.05/181.30. Sampling used top-p 0.95, top-k 20 and seed 1234.
  • Drafter memory: MTP3 peak process GPU memory 21,490 MiB versus 20,836 MiB for target-only (+654 MiB); host RSS peak was about 4,063 MiB. Four-stream MTP was not admitted.
  • Prompt speed: current cold TTFT table above. An additional cold 2,571-token request measured 1.651854 s on main, 1.590601 s candidate without drafts and 1.602920 s with MTP3; this is a separate prompt fixture.
  • Licence of new weights: n/a; no weights are added.
  • Raw LocalATC artifacts: inference receipt art_2485-enable_job_20261120_235324_28aa56_1dc5be; focused MTP CUDA art_2485-enable_job_20261120_223327_fb1c2b_9a45bf; incomplete full-contract run art_2485-enable_job_20261120_223649_7c94ab_864d19. Comparison scripts are included under tools/bench/mtp2485.
Kernel contract
  • Kernel: tf_q35_tap, which supports bounded MTP suffix capture while preserving full capture for other consumers.
  • Focused tap contract: full capture and suffix cases passed; planted controls were detected.
  • Full all-kernel CUDA contract: incomplete. LocalATC stopped the run at 94.5% host RAM before a SUMMARY. Partial output contained 1,639 passes and 135 planted control failures, all matched by CONTROL/KNOWN, with no unmatched failures. This is not a full-suite pass.
  • Runtime chips/backends not tested: CUDA other than SM120, GB10, Metal, HIP, Windows and mobile.

Checklist

  • The title and description match the current head, the Qwen3.5-family scope, receipt and stack.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency; fail-before and dependency-absent evidence remains to be collected.
  • Comments and docstrings are one line. No measurements or development history are in source.
  • No personal data, machine names, internal hosts or local paths are in the diff or its commits. No AI attribution lines.
  • Every token still goes through lane rounds; no serial path or forced draft-off mode.
  • Drafted output matched target-only, resumed output matched fresh, and concurrent comparisons matched solo for admitted cases.
  • No target precision is traded for speed.
  • Decode and prompt speed: all measured cold TTFT deltas are within the submitter's 1.5% noise band, and MTP decode is faster in the admitted one-to-three-stream cases. The strict no-slower gate and the incomplete all-kernel contract remain for maintainer review.

@ashhart

ashhart commented Nov 16, 2026

Copy link
Copy Markdown
Owner

Thanks @tacosta, the shape of this is right: the optional normalized view in the lanes stays off by default, the drafter path keeps the target only path intact, and the tap capture with suffix retention is the careful part. Keeping it a draft was the right call, and your own body names what is open.

On the red checks: your pre rebase run already had one failing host test, a terminated contract process and an InvalidCharacter exit in the qualification, and the rebase addressed none of them, so that is where to look first. Run the host suite on the rebased head and fix or gate the failing test. The tree mode flag read directly in one spot, beside the sanctioned reader two lines below, is ours to move, and we will. Once CI is green, the device cells are ours on a GB10: the same prompt DFlash2 comparison and the 2K and 8K first token times against main, with the full equality matrix. The cold first token question at 2K is the one your own numbers leave open, and it decides whether the default changes.

  • Synthena

@tacosta

tacosta commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for the review @ashhart. I reran the full host suite on the rebased local head 7e3fd9f770c7a3f0af5e0a945ad15affd1abe644 through LocalATC: zig build -j4 test test-golden exited 0 with umask 022. The golden comparison reported 322/335 equal and zero unexpected differences; the remaining 13 are categorized as known differences.

I traced the earlier serve --config host-test failure: this shell's default umask is 0002, so the fixture created by writeFile is group-writable (0664) and the test's initial read correctly refuses it. With umask 022, that fixture is 0644 and the test passes. I have not changed or gated this generic test in the MTP branch, so the rerun establishes a passing host suite under 022 but does not make the fixture independent of the caller's umask.

The focused MTP CUDA qualification passed 33/33, and the focused tap contract passed 2/2 with both planted controls detected. The broader kernel-contract run was terminated by LocalATC's host-memory safety limit, and the earlier checkpoint-backed qualification's InvalidCharacter result still needs a fresh real-checkpoint run; I am not treating those as cleared by the focused tests.

The DFlash2 same-prompt diagnostic arm is now present locally and its runner tests pass 19/19, but I have not collected the GPU comparison. The 2K cold first-token result and the full equality matrix remain open for the device qualification. I have not pushed this newer local head. I also left the direct TF_MTP_TREES read for your team as you noted.

@tacosta

tacosta commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @ashhart. I fetched remote main; origin/main advanced from 077998f7d to 9489c3817.

Before rebasing, I reran ATC 0.9.6 for #2485, including the affected areas (core, models, CUDA and tests). It still returns complete: false, advice: incomplete, limitation pullRequestsLimit, although the claim is mine; it lists #1444 as another PR. A selected overlap scan over the seven previously identified PRs is also incomplete (selectedPullUnavailable; #2824 was not inspected) and reports textual conflicts with #1444, #2415, #2841, #2951, #2952 and #2992, as well as local worktrees.

The contributor instructions say to stop issue-dependent work when the check is incomplete, so I have not rebased, started the post-rebase build/qualification, or pushed. Could you point me to a supported way to get complete ATC coverage or confirm the scope of overlaps that is cleared for #2485?

@tacosta
tacosta force-pushed the feat/2485-mtp-dense-enable branch from db705bf to a4ea384 Compare November 17, 2026 23:07
@tacosta

tacosta commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

@ashhart — update on the rebased PR head (main base e7ff97e132f2268c7c52bf55d1b8bdbb033462f3, MTP head a4ea384e1edbea9b4e285c6f394795ae25b0e0eb).

The receipt is measured against main at e7ff97e. GitHub main has since advanced to af9777b (21 commits ahead), so this is not a current-main qualification; rebase and requalification remain necessary before merge. The 10-repetition, cold-cache TTFT comparison on the RTX 5090 Laptop measured:

  • 2K: main 1.227061 s; candidate without drafts 1.225123 s; MTP3 1.228690 s. MTP3 is +0.133% vs main and +0.291% vs the candidate without drafts.
  • 8K: main 4.946709 s; candidate without drafts 4.948742 s; MTP3 4.944219 s. MTP3 is -0.050% vs main and -0.091% vs no drafts.
  • Same-prompt DFlash2 at 2K was 1.224735 s with the same output hash. DFlash2 could not start at 8K within the device memory budget.

Greedy and seeded-sampled output equality, resumed equality, and the collected 512-context stream matrix passed. The full all-kernel contract was attempted but LocalATC stopped it at the host-RAM safety threshold before its summary; the PR description records that partial result and the known attention findings. The focused MTP/tap checks pass. CI has started on the rebased head; the current checks are pending.

Against the e7ff97e reference, the 2K cold-TTFT result remains just outside the proposed 0.1% margin. I am leaving the acceptability decision to you: should this remain a merge blocker, or is it acceptable for continued review while the PR stays draft?

@Maxrio9

Maxrio9 commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Hi @tacosta, a heads-up from #3858: I'm about to open a draft PR stacked on #3723 that adds MTP drafting for SenseNova-Loop-9B. It touches the same drafter files as this PR (cuda_mtp.zig, cuda_mtp_absorb.zig, cuda_mtp_batch.zig, cuda_mtp_weights.zig, cuda_drafter_open.zig), because it also needs a dense-MLP arm.

Our scopes differ:

  • Here: the target's own indexed MTP tensors, quantized to affine-4 at load.
  • Mine: a BF16 side file (mtp.safetensors), plus Loop-only parts: taps through the 56-step loop schedule, an optional main_norm, and refusals.

I'll treat this PR as going first and rebase mine onto your dense arm, keeping only the BF16 side-file loader and the Loop parts. If you'd rather structure the dense arm so a BF16 variant can sit beside the affine-4 one, tell me and I'll match it. I won't touch #2485's scope.

@tacosta

tacosta commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

@ashhart — I read your earlier guidance and Maxrio9's latest note before preparing this update.

For pushed head a4ea384, items 1 and 3 appear clear: the PR text identifies the head, stack and receipt baseline; the added source comments/docstrings are single-line and within 120 columns, with no performance results or development history in source.

Items 2 and 4 remain open. The recorded 2K TTFT is +0.133% vs main and +0.291% vs no drafts; 8K is within the proposed margin. Those receipts use the older e7ff97e baseline. The 512-context multi-stream results establish equality, not speed at the widest admitted setting. The PR also doesn't clearly surface the requested drafter memory cost or cancel/partial-acceptance evidence.

For ordering, please consider Maxrio9's overlapping MTP comment: #3582 (comment). It proposes stacking their Loop-specific work on this PR. Please let us know the preferred order, including whether the reusable normalized-feature interface should be its own prerequisite PR; we'll follow that sequence.

@tacosta

tacosta commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

@ashhart — could you confirm the preferred stack before I restack #3582? Your #2485 note suggested keeping the reusable core/lanes normalized-prompt-feature interface in its own prerequisite change. Should I split that out, then put the Qwen3.5 dense MTP change on top? Maxrio9’s comment on this PR proposes stacking the Loop-specific MTP work after #3582; does that order still look right? I’ll follow your order and leave sibling-conflict resolution to you.

@ashhart

ashhart commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Thanks @tacosta, and thanks for the careful receipts. Our answer on the stack is: split the reusable core/lanes normalized-prompt-feature interface into its own prerequisite change, put the Qwen3.5 dense MTP change on top of it, and keep the SenseNova Loop work stacked after this PR. The head still needs a rebase: three files conflict with today's main (cuda_mtp.zig, cuda_native.zig and environment_test.zig). After that, please requalify on current main; the 2K prompt cell is still just over the 0.1% margin, and the full kernel contract and GB10 run are not yet in the receipt. We were unable to run those device checks here.

  • Synthena

@tacosta
tacosta force-pushed the feat/2485-mtp-dense-enable branch from a4ea384 to b154039 Compare November 20, 2026 01:58
@tacosta
tacosta marked this pull request as ready for review November 20, 2026 01:59
@AIFlowML

AIFlowML commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

On exact head b1540392, I ran the CUDA host targets on an M5 Max with Zig 0.17.0:

zig build test-qwen35-mtp-coupled-host test-qwen35-mtp-selection-host \
  test-qwen35-mtp-lifecycle-host test-qwen35-mtp-memory-host \
  test-qwen35-prefill-host -Dcpu=apple_m1 -j6 --summary all
python3 -m unittest discover -s tools/bench/mtp2485 -p test_receipts.py

The host run passed 112/112 and the receipt harness passed 23/23. I also explicitly imported and ran the new suffix and prompt-chunk fixtures in scratch (24/24). Moving the suffix cut one row later failed both the direct and stepped cases (expected 6143, found 6144).

On an RTX 5090 Laptop GPU (SM 120, CUDA 13.1.115), I built the exact-head runner with zig build compile-cuda-tests -Dnvcc=/usr/local/cuda/bin/nvcc -Dsm=120 -Doptimize=ReleaseFast -j5 --summary all (167/167 steps). tf-cuda-test kernel-contract 'qwen35 tap' passed both full capture and the filtered suffix, caught both planted controls and reported zero limit problems.

The prerequisite #4132 trial-merges cleanly into main 9b9218f72. With this MTP commit added, the trial merge has six conflicts: the changelog plus five Qwen3.5 CUDA files. In particular, preserve main's dynamic tapRows() sizing and solo-prefill chunk policy while integrating the typed normalized-row source and bounded suffix capture. Real-checkpoint exactness, the full CUDA contract and the GB10 timing run still need that rebased head.

After #4132 merged, I reran the same five host targets and the Python receipt tests on 5b2be93d. They passed 112/112 and 24/24. The trial merge into dc71af9d2 had one conflict, in CHANGELOG.md. The timing and real-checkpoint checks on the rebased CUDA binary remain open.

I then ran the same five host targets plus check-native-cuda-host on the actual trial merge into dc71af9d2, keeping main's changelog in scratch. All 112 tests passed again and the Linux ARM64 CUDA runner compiled.

Igor Lessio - AIFLOW LABS

@tacosta
tacosta force-pushed the feat/2485-mtp-dense-enable branch from b154039 to 5b2be93 Compare November 21, 2026 01:11
@tacosta tacosta changed the title qwen3.5 CUDA: enable dense MTP drafting Qwen3.5-family CUDA: enable dense MTP drafting Nov 21, 2026
tacosta and others added 6 commits November 21, 2026 20:05
Add dense Qwen3.5 MTP loading and speculative execution with allocator peak checks, overflow handling, KV-only prompt absorption, suffix tap capture, and sampled-draft coupling tests.

Keep the normalized prompt-feature interface reusable by any drafter that consumes normalized rows. Register TF_MTP_TREES once on current main and describe its sampled-tree opt-in.

Repair the receipt runner monotonic timer import and cover its readiness timeout.
Expose the moved scan to incoming host recorders without another implementation. Free both fixture recorders, include incoming tap tests in the covering prefill step, and remove nine blank lines to keep the engine at 600 lines.
Main's lane changes take cuda_native.zig to 601 with this PR; the blank
line between reserve and release goes.
@ashhart
ashhart force-pushed the feat/2485-mtp-dense-enable branch from 8727742 to a57ef3d Compare November 21, 2026 20:05
@ashhart
ashhart merged commit 39a3a1c into ashhart:main Nov 21, 2026
2 of 12 checks passed
@ashhart

ashhart commented Nov 21, 2026

Copy link
Copy Markdown
Owner

Thank you @tacosta. 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.

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.

4 participants