Skip to content

SenseNova Loop CUDA: MTP drafting with the checkpoint's own head (--drafter mtp) - #3867

Draft
Maxrio9 wants to merge 18 commits into
ashhart:mainfrom
Maxrio9:sensenova-loop-mtp
Draft

Maxrio9 wants to merge 18 commits into
ashhart:mainfrom
Maxrio9:sensenova-loop-mtp

Conversation

@Maxrio9

@Maxrio9 Maxrio9 commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

With --drafter mtp, SenseNova-Loop-9B on CUDA drafts with its own MTP head. Greedy output equals plain decoding token for token on #3723's 11 prompts (alone, at 4 concurrent streams and on a resumed chat). Forced rejections at every draft depth leave the state clean. Decode goes from 25.9 to 59.2 tok/s at one stream on code and from 100.3 to 216.0 tok/s aggregate at 4 streams. Qwen3.6 MTP samples match main; decode results are below.

What this changes

serve <SenseNova-Loop-9B> --backend cuda --drafter mtp loads the checkpoint's mtp.safetensors and drafts with it. Before this, every drafter was refused for sensenova_loop.

Checks on this head

  • Head commit: 497cfed9d, tested as is. It is the previous c81b1f949 rebased onto the new qwen3_5 cuda: SenseNova-Loop-9B (sensenova_loop) in BF16, text only #3723 head; the only conflict was main's engine.tap_rows becoming e.tapRows() next to this PR's tapNorm, and setTaps folds the Loop tap check into the existing loop line so cuda_engine.zig stays at 600 lines.
  • Lean checker: 168 findings on the base and 168 on the tested tree, 0 new.
  • Tests:
    • zig build test-cuda-host: pass, except cuda.stager "every byte lands where the mapping would have put it" on my machine, which coincides with a Btrfs checksum error on its O_DIRECT temp file; it passes in CI and this PR does not touch the stager.
    • test-gradient-serving, test-qwen-serving-host and test-serve-drafter-host: pass.
    • test-qwen35-loop-host: pass.
    • The dense_serving_test.zig launch-sequence hash and the gradient-serving pins are unchanged and pass.
  • CUDA builds: zig build native -Dsm=120 -Dnative-fp-decode=true and compile-cuda-tests pass.
  • Device check: tf-cuda-test qwen-loop-mtp (needs TF_LOOP9B_DIR; TF_LOOP9B_MTP defaults to it) passes on SM120.
  • CI: green on 497cfed9d: all 9 jobs pass.
  • Not run: chips other than SM120; tensor parallel and pipeline stages (refused).

Receipt

  • Main against branch: Qwen3.6-35B-A3B MTP, main 11a0de0cf against this head, alternated main/head/main/head (table below). Loop-9B plain against --drafter mtp is on the same binary, because main cannot serve this model.

  • Boxes it reaches: CUDA qwen3_5 MTP drafting (dense Loop and MoE Qwen3.6), the Loop tap rule, server --drafter selection.

  • New switch: none. --drafter mtp is a new value of an existing flag, for sensenova_loop on CUDA only, and it is off unless given.

  • Environment:

    • TensorFold 497cfed9d, Zig 0.17.0, nvcc 13.4.
    • RTX PRO 4500 Blackwell (SM120, 32 GB), Linux.
    • sensenova/SenseNova-Loop-9B at 329a65f7, plus mtp.safetensors (sha256 3b84d5143ad5c97cbeffb4ffe9d2db9f620e3cbbfa334f987a04a3cb902d08a6), Apache-2.0.
    • TensorFold/Qwen3.6-35B-A3B-MLX-4bit-MTP at f84b054c.
  • Paths run: decode at 1 and 4 streams, greedy and sampled; prompt-cache resume; forced rejection at depths 0–2. Not run: other SMs.

  • Losslessness (Loop-9B):

    • Settings: --context 8192 --prompt-cache-gib 0, 256 tokens or to EOS, raw token IDs through /v1/completions.
    • The 11 prompts are 11/11 identical with --drafter mtp at --parallel 1, and 11/11 identical with the 11 sent 4 at a time at --parallel 4.
    • Plain at 4 streams also equals plain alone, 11/11.
  • Resume: a two-turn chat of 6907 then 6970 prompt tokens, served with --drafter mtp and the prompt cache on. Turn 2 resumes at 4096 cached tokens, and both turns equal plain decoding with --prompt-cache-gib 0.

  • Rollback (tf-cuda-test qwen-loop-mtp): a wrapper replaces draft k of every round with a token the target cannot pick and keeps drafts 0..k−1 as proposed. In every run, all 64 tokens equal plain, and a fresh stream afterwards equals its plain reference.

    forced wrong at accepted / proposed rounds
    k = 0 0 / 66 63
    k = 1 26 / 58 38
    k = 2 29 / 52 35
    none 35 / 84 29
  • Exactness (bench_concurrent.py --alone --serial, levels 1 and 4, greedy and sampled with fixed seeds): equal throughout with and without the drafter: alone 2/2 and 8/8 per prompt; serial against "draft": false 1/1 greedy and 4/4 sampled.

  • Acceptance (11 prompts, depth 3): 863 of 1603 drafts accepted (53.8%), 1.56 accepted drafts and 2.57 tokens per round; at 4 streams, 864 of 1613 accepted (53.6%) and 2.56 tokens per round.

  • Decode, Loop-9B (tok/s, bench_concurrent.py aggregate; separate bench_openai.py 1-stream medians are not identical):

    plain --drafter mtp
    code, 1 stream, greedy 25.9 59.2
    chat, 1 stream, greedy 25.9 43.9
    code, 4 streams, greedy 100.3 216.0
    chat, 4 streams, greedy 100.2 169.1
    code, 1 stream, sampled 25.9 47.6
    chat, 1 stream, sampled 25.9 42.3
    code, 4 streams, sampled 100.2 178.3
    chat, 4 streams, sampled 100.2 143.4
  • Memory and load: not rerun.

  • Qwen3.6-35B-A3B MTP, main against branch (--context 8192 --parallel 4 --prompt-cache-gib 0 --drafter <its folder>; bench_openai.py decode medians at 1 stream, bench_concurrent.py aggregates at 4):

    • Samples (greedy and seeded sampled) are byte-identical across all four runs.
    • --alone --serial is equal on every run.
    tok/s, code / chat main head main head Welch p, code / chat
    1 stream, greedy 410.6 / 307.9 409.1 / 307.8 410.5 / 308.0 410.5 / 308.1 0.912 / 0.307
    1 stream, sampled 353.8 / 281.5 353.8 / 281.4 353.8 / 281.4 353.8 / 281.3 0.998 / 0.894
    4 streams, greedy 1327.0 / 975.9 1328.1 / 977.2 1328.0 / 975.9 1327.5 / 976.8 0.668 / 0.114
    4 streams, sampled 777.1 / 667.6 777.8 / 665.8 778.3 / 664.6 777.6 / 665.8 1.000 / 0.874

    Welch tests compare main and head repetitions pooled across both runs: n=6 per side at 1 stream and n=2 per side at 4 streams.

  • Prompt speed: n/a. Prompt processing is unchanged; drafting starts after the prompt. Cold TTFT is in qwen3_5 cuda: SenseNova-Loop-9B (sensenova_loop) in BF16, text only #3723.

  • Licence: mtp.safetensors is part of sensenova/SenseNova-Loop-9B, Apache-2.0.

Checklist

  • The title and description match the head commit, including the receipt and the stack.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency.
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.
  • 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. The target's sums are unchanged; the draft's own norms keep FP32 1 + w except the q/k head norms (BF16 RNE pre-shift, draft-only).
  • Decode and prompt processing are no slower than main at one stream and the widest admitted; with --drafter, no slower than without it, greedy and sampled. Prompt speed was not rerun.

@AIFlowML

Copy link
Copy Markdown
Contributor

On exact head 497cfed9d, I ran zig build test-qwen35-loop-host -Dcpu=apple_m1 -j4 --summary all with Zig 0.17.0 on the Mac. It passed 213 tests with 2 skips. This covers the Loop configuration and execution-slot host tests. The CUDA rollback check still uses the pinned SenseNova-Loop-9B revision and matching MTP side file listed in the receipt.

I also checked the stated #3723 dependency against main 210e3b0c5. The trial merges of parent c1ec09679 and this head both conflict in contract_controls_set.cu, cuda_refusal.zig and gradient-serving.tsv. The parent rebase is the first step. After replaying this commit, please recheck the SenseNova block in cuda_refusal.zig, where this patch permits MTP, and rerun TF_LOOP9B_DIR=<checkpoint-dir> tf-cuda-test qwen-loop-mtp on SM 120. The expected rollback result is all 64 tokens matching plain at each forced rejection depth 0, 1 and 2, followed by a fresh stream matching its plain reference. I did the host checks only.

Igor Lessio - AIFLOW LABS

@Maxrio9

Maxrio9 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for checking the parent dependency and identifying the CUDA rollback test. I have a local restack on top of the locally integrated #3723, but it has not been pushed: the published head remains 497cfed9d, and the parent and current-main integration need to be coordinated first.

On that local restack, the SenseNova-Loop-9B MTP check passed on SM120, including plain-versus-MTP parity, forced rejection at depths 0, 1 and 2, and a fresh-prompt replay. The test also exercised the two-stream shared pass; disabling it as a negative control produced the expected NoSharedMtpPass failure. The changed Qwen tap kernel contracts passed their gates and caught both planted controls. These results are for the local restack, not the published head; the device memory-admission boundary remains untested.

I asked about the parent integration order at #3723 (comment). Once that is settled, I will update this stack and rerun the checks needed for the resulting published head.

@Maxrio9

Maxrio9 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

/atc depends 3723

Maxrio9 and others added 16 commits November 26, 2026 12:29
…nsenova_loop

Physical layers keep one weight copy; each execution owns its delta-net or KV slot (42 + 14 for SenseNova-Loop-9B).
Plain Qwen checkpoints get the identity schedule. Drafting, learning, pockets and stages are refused for loop models.

Refs ashhart#3717
Route, plain norm, mixer, merge around both halves of layers 4..27; streams enter at each pass's first layer and leave at
its last. FP32 dt_bias rounds to BF16 at load, as the reference holds it. Execution counts are cached in the geometry.

Refs ashhart#3717
…the reviewed launch sequence

qwen35_learn and the qwen35 GPU test mains pass null loops. kernels.zig registers the qwen35_mhc image.
The launch sequence's three norm add flags come from the schedule's decision, main's values on the plain schedule.
Other backends decide their own drafting for this model type.
…iterations and pre_scale

Accept loop_settings.use_gate absent or false, ignore unknown loop_settings keys, and no longer require layer_types.
Streams 4 parses but is refused at admission, as are fixed_identity and more than 1000 iterations. The route kernel
takes the Sinkhorn iteration count and pre_scale (defaults 20 and 1.0, the default path unchanged). A shared case
table, zig/tests/fixtures/sensenova_loop_config.json, runs through the CUDA reader and admission.
…al does

The route kernel takes pre_scale as an f32. A positive f64 such as 1e-50
passed the reader and the finite check, then ran as 0. Admission now
refuses it with UnsupportedSenseNovaMhc, matching ashhart#3859's reader. Two
fixture cases: 1e-30 (a normal f32) accepts, 1e-50 is refused at admission.
Follows main's 0ac3062, which moved deltaScan into cuda_forward.zig to keep the engine under 600 lines: the engine
keeps that one, and cuda_delta_scan.zig, the same helper moved for the same reason, goes.
…e (ten blank lines fewer)

Main's 0ac3062 moved deltaScan out of the engine to keep it under 600 lines, the room ashhart#3723 had made the same way,
so the loop schedule's fields and set-up put cuda_engine.zig at 610. Ten blank lines between adjacent Engine members
go; no code changes.
… schedule

Follows main's f16f9a5 (a launch trace for unread prompt chunks), whose test builds an Engine by hand and runs
forward.body: with ashhart#3723 the forward walks e.steps, so the test sets them from its geometry's schedule, one step for
its one layer, as Engine.init does.
… blank lines fewer)

Main's fceb497 (keep the main scan owner and both prompt fixture lifetimes) left cuda_engine.zig at 600 lines; with
the loop schedule and the earlier ten blank lines out, it stood at 604. Four more blank lines between adjacent Engine
members go; no code changes.
…oday's main

Main re-pinned the reviewed launch sequence for its moved delta scan and MTP's retained-row tap argument
(2099ef3b), and ashhart#3723 re-pinned it for its schedule-driven norm add flags (d3b1945b). The merged sequence hashes to
29de8240; the two comments become one line.
@Maxrio9

Maxrio9 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Restacked onto #3723's new head a4c769e3a (your integration 3397f12f2 plus the FP32 dt_bias commit) as bf46a9234. It is still one commit. Against 497cfed9d it also carries three fixes from the local restack:

  • setTaps refuses a tap inside an mHC block before its streams merge (LoopTapInsideMhc), keeping the configured taps.
  • tf_q35_tap takes an optional residual: R == nullptr writes H directly where the final mHC step leaves the merged row in H. Its 13.4 usage record is added.
  • MTP admission counts the tap ring in each stream's bytes (installMtpTap), and the dense-MTP fixture prices the padded MLP from the geometry's intermediate.

The cherry-pick applied cleanly. The only fixture change is the launch fingerprint in dense_serving_test.zig, re-pinned because the tap launch now passes e.r only while the residual is pending.

Host (Zig 0.17.0): test-qwen35-loop-host test-qwen35-loop-refusal-host test-gradient-serving test-qwen-serving-host pass.

Device, RTX PRO 4500 (SM120), nvcc 13.4.92, TF_LOOP9B_DIR=<SenseNova-Loop-9B> tf-cuda-test qwen-loop-mtp on bf46a9234 passes:

  • Drafting with the checkpoint's own MTP head reproduces plain decoding's 64 tokens.
  • Forced rejection at depths 0, 1 and 2: each run matches plain. The log's acceptance lines read 0/66, 32/93 and 42/63, so drafts were proposed and the rejection depth was reached.
  • After each run, a fresh prompt equals its plain reference.
  • Two streams (a 320-token prompt and a fresh one) share an MTP pass and each matches its plain run (the check fails with NoSharedMtpPass if no pass is shared).

tf-cuda-test kernel-contract "qwen35 tap": SUMMARY 3 kernels: 3 pass gates 1-4, 0 fail, 0 known findings; 2 controls: 2 red as planted, 0 missed; 0 limit problems.

This stays a draft until #3723 lands. GitHub has not run CI on this head because the branch conflicts with main.

The loop loader rounded the checkpoint's FP32 linear_attn.dt_bias to BF16.
It now uploads the stored four-byte values unchanged, sizes them at four
bytes per value head, and tf_q35_gdn_pre reads them as f32 when the engine
serves a loop checkpoint: a + dt_bias and its softplus stay in f32, as in
the reference's F.softplus(a.float() + dt_bias). Other Qwen checkpoints
and EXL3 keep their BF16 tensor and the unchanged BF16 arithmetic.

The rounding regression becomes an exact FP32-bit preservation test. The
launch fingerprint now also covers runPdl launches, so gdn_pre's argument
list is pinned; qwen35.cu and the fingerprint are re-pinned. Two comments
are shortened under 120 columns, and cuda_engine.zig, cuda_geometry.zig
and cuda_native.zig each drop a blank separator to stay under 600 lines.
--drafter mtp serves SenseNova-Loop-9B's own mtp.safetensors (or an mtp/ directory) through the
Qwen MTP drafter: a dense BF16 layer packed in the target's lane format, fed the last layer's
final-normed hidden (the draft's main_norm when it ships one). The Loop engine taps only layers its
schedule runs once; verification and rollback use the per-execution delta-net and KV slots.
DFlash2 and DSpine drafts stay refused for this model type.
@Maxrio9

Maxrio9 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Restacked onto #3723's b1d414da5 as 26ed91e36, replacing bf46a9234. Following the review on #3723, it also deletes a blank separator in cuda_engine.zig, which this commit had brought to 600 lines (now 599). It shortens the two comments it added that ran past 120 columns: in qwen35_rows.cuh and on cuda_native.zig's pool-layout doc. tools/pr_check.py --base upstream/main reports 0 errors. Host loop, refusal, serving-pin and kernel-contract targets: 69/69 steps pass. The kernel change is comment-only, so the earlier device results on bf46a9234 still describe this code.

This branch has not been deployed

No deployments
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.

SenseNova-Loop-9B (sensenova_loop) MTP speculative decoding on CUDA

3 participants