Skip to content

qwen3_5 cuda: SenseNova-Loop-9B (sensenova_loop) in BF16, text only - #3723

Open
Maxrio9 wants to merge 15 commits into
ashhart:mainfrom
Maxrio9:sensenova-loop-cuda
Open

Maxrio9 wants to merge 15 commits into
ashhart:mainfrom
Maxrio9:sensenova-loop-cuda

Conversation

@Maxrio9

@Maxrio9 Maxrio9 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Review status, head d358d0b17: the requested host-KV and snapshot hooks, mHC launch fingerprint, and separate nvcc 13.0 records are published. The SenseNova loader still rounds checkpoint FP32 dt_bias to BF16. Correcting that and rerunning the device and exact-output gates remain open. The earlier vLLM reference also cast dt_bias to BF16, so its token comparisons below do not validate preservation of the stored FP32 values. The historical receipts below are labeled with their measured heads and do not qualify the current head.

What this changes

SenseNova-Loop-9B (model_type: sensenova_loop), a looped Qwen3.5-style hybrid, runs on the qwen3_5 CUDA engine in plain BF16, text only:

  • Execution schedule: physical layers run 0–3, 4–27, 4–27, 28–31 (56 executions). Weights stay one copy per physical layer, and each execution owns its delta-net or KV slot (42 + 14).
  • mHC kernels: two-stream routing with a log-space Sinkhorn on FP32 routers, plus stream enter/merge/leave. The Sinkhorn iteration count and pre_scale come from the config (release values 20 and 1.0).

Plain Qwen checkpoints get the identity schedule.

Commits

  • 80c95606e execution schedule and per-execution state slots for sensenova_loop
  • 09971de2a two-stream mHC kernels (enter, route, merge, leave) with host reference and contract cases
  • e240669bd two-stream mHC in the sensenova_loop forward
  • 653af6c9f read-cost test passes finish's pending flag
  • e547b3515 Engine.init callers pass loops; re-pin kernels.zig and the reviewed launch sequence
  • 18adcc42a server refuses --drafter for sensenova_loop only on CUDA
  • 17dd3af00 config rules shared with Metal; any mHC iterations and pre_scale
  • b254e74f1 register nvcc 13.4 contract records
  • c1ec09679 refuse pre_scale that rounds to f32 zero

Implementation and historical checks

  • Config and schedule: loop_settings and mhc are read from the config root and validated as the reference execution_plan does. The schedule carries per-execution delta and attention slots and mHC boundary flags, and --loops 1..4 overrides the trained count.
  • Config rules (aligned with Metal, see SenseNova-Loop-9B (sensenova_loop) on Metal: M5 Ultra and M3 Ultra, BF16 and AWQ 4-bit, 512K YaRN, vision and MTP #3781):
    • loop_settings.use_gate is accepted when absent or false; true is refused, since loop_gate isn't loaded.
    • Unknown loop_settings keys are ignored, as the reference does; unknown mhc keys are refused.
    • layer_types is optional and falls back to full_attention_interval, as for plain Qwen3.5.
    • mhc.streams may be 2 or 4; 4 streams and fixed_identity: true are refused at admission (UnsupportedSenseNovaMhc).
    • Any mHC iterations from 1 to 1000 and any finite pre_scale > 0 that stays finite and positive in f32 run: both are route-kernel arguments, and the release values take the same path as before.
    • A tied head is refused until there's a tied checkpoint to test against.
    • zig/tests/fixtures/sensenova_loop_config.json holds 87 cases (30 accept, 52 refused by the reader, 5 refused at admission). They run through the CUDA reader and admission in test-qwen35-loop-host and test-cuda-host.
  • Geometry and state: state, KV, reuse, prefix and cost sizing count execution slots; physical counts have separate helpers. The forward walks the schedule.
  • Weights: BF16 text weights load through the existing BF16 lane path with an untied lm_head. FP32 routers are uploaded once per physical layer. The vision tower, loop_gate and MTP are skipped and left out of byte accounting.
  • Refusals for this model type: drafter/DFlash/DSpine/MTP drafts, learning, pockets, pipeline stages and image input. serve defaults to plain decoding.
  • mHC kernels: qwen35_mhc.cu with a CPU reference, a contract runner case per kernel at rows 1–512 (including a 3-iteration route and a pre_scale 1.75 route), planted controls and launch records.
  • mHC in the forward: decode and prompt passes run route, plain norm, mixer and merge around both halves of layers 4–27. Streams enter at each pass's first layer and leave at its last.
  • dt_bias (known issue): this head rounds the checkpoint's FP32 dt_bias to BF16 at load. The earlier vLLM reference also rounded it, so that comparison does not validate preservation of the checkpoint values. An FP32 correction is required; A_log stays FP32.

Not done

Historical checks (not the current head)

  • Measured head commit: c1ec09679 on main 11a0de0cf. It is the previous head f70b5ca6a (on dffe42485) rebased; the only conflicts were three lines where main renamed max_rows to grid_rows, added the living import, and added contract_embed_controls.cuh next to contract_mhc_controls.cuh.
  • Receipts on c1ec09679: parity, chat template and tools, resume, Loop-9B concurrency/decode/prefill, Qwen3.8-27B against main 11a0de0cf, the host suite and the build. Ran on the previous head (same PR code, main dffe42485): teacher-forced KL, long context, Qwen3.8-27B at 4 streams, and the full kernel contract.
  • CI: green on c1ec09679: all 9 jobs pass, including zig, zig-b and zig-windows.
  • Lean checker: 168 findings, the same set as main 11a0de0cf.
  • Host suite: zig fmt --check, test-kernel-contract, test-gradient-serving, test-qwen-serving-host, test-qwen35-loop-host and test-qwen35-loop-refusal-host pass.
  • CUDA build: zig build native -Dnvcc=<nvcc 13.4> -Dsm=120 -Dnative-fp-decode=true passes.
  • Kernel contract: the full unfiltered run has 0 gate failures and 0 missed controls, but fails on limit problems also present on main (see below).

Receipt

  • Environment:
    • TensorFold c1ec09679 (measured historical head) and c6415563d (the previous head's tree, on dffe42485) where marked, Zig 0.17.0, nvcc 13.4.
    • RTX PRO 4500 Blackwell (SM120), Linux.
    • Checkpoint sensenova/SenseNova-Loop-9B at revision 329a65f7 (Apache-2.0).
  • Fidelity against an independent reference:
    • Reference: vLLM nightly with [Model] Add SenseNova Loop support vllm-project/vllm#64832 (86014ad4), BF16 weights, BF16 KV, greedy, prefix caching off.
    • Prompts: 11 public prompts (8 chat with thinking off, 3 raw continuations), given as identical token IDs through /v1/completions.
    • TensorFold settings: --context 8192 --parallel 1 --prompt-cache-gib 0.
    • Result: 10/11 prompts equal token for token through the reference's full length (4 to 64 tokens).
    • The 11th (the Fibonacci code prompt) diverges at token 29, where the reference's top two tokens have identical logprobs (−0.7321 and −0.7321, margin 0.0); TensorFold took the other one.
  • Teacher-forced fidelity (previous head): vLLM 0.32.0rc1.dev100+g77154ca61 with [Model] Add SenseNova Loop support vllm-project/vllm#64832, BF16 weights and KV, prefix caching off; reference top-64 plus tail, 219 held-out rows across 6 categories and 94,235 scored positions.
    • Mean KL 0.000416 (95% position bootstrap 0.000407–0.000426), top-1 agreement 0.992, PPL 1.228 for both at three decimals. The position bootstrap does not account for within-sequence correlation.
    • On the same positions, ExLlamaV3 BF16 KL is 0.000335 and ExLlamaV3 8.0bpw is 0.000480.
    • TensorFold logits were dumped with its qwen35-cuda window tool and BF16 KV; the server does not report logprobs for this backend. Tool equivalence to server prefill has not been measured.
    • Rows above 4090 tokens were not scored (21 rows).
  • Gate review: parity and loop9b were marked done by hand after review: parity returned nonzero for the reference tie, and loop9b for raw-token resume retaining no state.
  • Load: the model needs 17.36 GiB, with 0.73 GiB per stream at an 8k window. It loads in 12.1 s.
  • Same-engine exactness (bench_concurrent.py --alone --serial, --context 8192 --parallel 4, 256 tokens, code and chat prompts):
    • Greedy: concurrent equals alone 3/3 at 1 stream and 12/12 at 4 streams per prompt; serial equal.
    • Sampled (temperature 1.0, fixed seeds): alone equal 2/2 at 1 stream and 8/8 at 4 streams per prompt.
  • Resume: a two-turn chat with thinking off (turn 1 is 6907 prompt tokens, turn 2 is 6970), --context 16384 --parallel 1. With the prompt cache on, turn 1 keeps one 309 MiB state at 4096 (all 42 delta-net and 14 KV slots), and turn 2 resumes there (cached_tokens 4096). Both turns match a server with --prompt-cache-gib 0 exactly. A repeated raw-token completion keeps no state, as with every qwen3_5 model: the planned cache only marks chat history boundaries on its 4096-token grid.
  • Decode (bench_openai.py, greedy, 256 tokens, no drafts): 25.9 tok/s at one stream on both prompts; about 100 tok/s aggregate (25.2 per stream) at 4 streams.
  • Cold prefill TTFT (bench_cache.py --require-cold, --prompt-cache-gib 0): median of 4: 0.75 s at 2048 tokens, 3.06 s at 8192, 13.1 s at 32768 (13.0 on the previous head).
  • Long context (previous head; --context 135168 --parallel 1 --prompt-cache-gib 0, BF16 KV; FP8 KV is refused for this model type): cold TTFT (median of 3 boots) 12.9 s at 32768 tokens, 28.1 s at 65536 and 64.4 s at 131072; decode right after the prompt 24.3, 22.9 and 20.7 tok/s; peak GPU memory 25.7 GB. At --context 229376 the model still loads on the 32 GB card: a 221,184-token prompt takes 126.7 s to first token, decodes at 17.9 tok/s and peaks at 30.9 GB.
  • Chat template and tools (thinking off unless noted): server prompt token counts equal HF apply_chat_template for plain (18), system plus multi-turn (39), thinking on (20), tools (300) and tool result (334). The tools case returns get_weather with {"city":"Berlin"}, and thinking on returns separate reasoning.
  • Qwen3.8-27B no-regression (4-bit TF-native checkpoint, DFlash2 drafter, FP8 KV, --context 32768, runs alternated main/head/main/head, main 11a0de0cf):
    • Greedy samples are byte-identical across all four runs (36 of 36 hashes); bench_concurrent --alone --serial is equal on main and head.
    • Decode medians (tok/s), code / chat: main 219.13 / 161.35, head 219.38 / 161.40; Welch p=0.99 / 0.91, 6 samples per side.
    • At --parallel 4 on the previous head against main dffe42485 (aggregate tok/s, 6 samples per side): greedy code 438.7 / 438.4 (p=0.53), chat 318.7 / 323.6 (p=0.064); sampled code 456.8 / 457.3 (p=0.79), chat 294.3 / 289.9 (p=0.30). Greedy tokens are identical at both widths, and concurrent equals alone.
Kernel contract
  • Kernels registered: qwen35_mhc_enter, qwen35_mhc_route, qwen35_mhc_merge and qwen35_mhc_leave, all new; none replaces an existing kernel.
  • Planted controls: one per kernel (contract_mhc_controls.cuh). All four are red as planted.
  • Full unfiltered SUMMARY (previous head c6415563d, SM120, nvcc 13.4, zig build kernel-contract -Dsm=120): 719 kernels pass gates 1–4, 0 fail; 433 controls red as planted, 0 missed; 8 known findings and 597 limit problems. Main 81de26f64 has 710 kernels pass, 429 controls red, the same 8 known findings and 577 limit problems. The live per-launch limit problem set is identical; the extra 20 are static “no compiled usage recorded” entries for 4 new mHC kernels across 5 SMs, of the same kind as 183 on main. Both runs fail on limits.
  • Chips I cannot run: every SM except SM120.

Checklist

  • The description and receipt are updated for the current head; the detailed receipts below are historical.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency. On main, loop_schedule_test, loop_geometry_test, cuda_mhc_test, the mhc_ref tests, the qwen35_loop_config_host case table and the contract_mhc cases fail: main has no loop schedule, mHC kernels or sensenova_loop reader. The host tests need no GPU; the contract cases run only under kernel-contract.
  • 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. The mHC kernels run per row inside the same rounds. Drafts are refused for this model type (no drafter exists for it), not turned off on an advertised path, and plain Qwen checkpoints keep drafts.
  • Drafted output equals "draft": false (drafts are refused for this model type), a resumed prompt equals a fresh one, and concurrent equals solo.
  • No precision traded for speed. The current SenseNova loader rounds stored FP32 dt_bias to BF16; the maintainer requested preserving FP32 and a new exact-output comparison. Prior reference matches do not establish that property.
  • 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. Qwen3.8-27B decode is level with main (Receipt). This model has no main baseline, and --drafter is refused for it.

@ashhart

ashhart commented Nov 18, 2026

Copy link
Copy Markdown
Owner

Thanks @Maxrio9. Running the looped schedule on the existing qwen3_5 CUDA engine, with one copy of the weights and a delta-net or KV slot per execution, is a clean way in. The plain path reads unchanged:

  • The identity schedule gives the norms main's add flags: loop_schedule.decide on a step outside the loop is first_add = pending and second_add = true, with pending starting at g.first != 0. The re-pinned launch sequence in dense_serving_test.zig is that rewrite.
  • dt_bias is rounded to BF16 only when g.loop is set (cuda_weights.zig), so other Qwen3.5 checkpoints keep the stored tensor.
  • The receipts cover fidelity within an exact reference tie, concurrent equal to solo (greedy and sampled), resume, chat template and tools, and Qwen3.8-27B unchanged.

Before it can land:

  1. Rebase onto current main. Three files no longer apply cleanly:
    • zig/src/core/contract/registry.zig is at 600 lines on main, so the mhc_cuda_records line takes it to 601. Please make room, for example by moving that set beside the others in registry_joins.zig.
    • zig/tests/fixtures/gradient-serving.tsv: main re-pinned zig/src/cuda/kernels.zig, so the row needs the merged file's hash.
    • zig/kernels/cuda/contract_controls_set.cu: main added contract_nemo_audio_controls.cuh at the end, so keep both includes.
  2. CI and receipts on the head: zig and zig-b failed on the earlier head. Please post green CI on the rebased head, and rerun the Qwen3.8-27B token comparison there, since the receipts were taken on b279e13ed on an older base.
  3. Two items you list as not done: the full unfiltered kernel contract on SM120, and the checklist boxes left open. Please run the contract, and tick each box or say why it can't be ticked. For "new tests fail before the change", naming which tests would fail on main is enough.
  4. qwen27 metal: serve SenseNova-Loop-9B natively (BF16 and AWQ g128, 512K YaRN, images) #3859 serves the same model on Metal, with its own reader of the same config.json (zig/src/families/sensenova_loop/config.zig) where this PR has qwen3_5/loop_config.zig. Both also add the model's row to zig/src/cli/hub.zig. Please compare the two readers, so that both engines accept and refuse the same loop_settings and mhc values. If one should use the other's, say which.
  • Synthena

@ashhart

ashhart commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Thank you @Maxrio9. The rebase fixes all three apply problems: registry.zig stays at 600 with the mHC set in registry_joins, the controls file keeps both includes, and the gradient-serving pin is updated.

Three things still need your side. Please post green zig and zig-b CI on the head you want landed and rerun the Qwen3.8-27B token comparison there, since the current receipt is from the older base. Please run the full unfiltered kernel contract on SM120 and tick or explain each open checklist box. Last, compare your loop_settings/mhc reader with the one in #3859 so both engines accept and refuse the same values, and tell us which reader should be shared.

  • Synthena

gilby added a commit to gilby/TensorFold that referenced this pull request Nov 19, 2026
@ashhart
ashhart force-pushed the sensenova-loop-cuda branch from 8f55e46 to 0fc4521 Compare November 19, 2026 18:42
@Maxrio9
Maxrio9 force-pushed the sensenova-loop-cuda branch from 0fc4521 to c1ec096 Compare November 20, 2026 09:31
@Maxrio9

Maxrio9 commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, Synthena, and thanks for the rebase and re-pin. CI on 0fc45211f failed in zig, zig-b and zig-windows on one test: registry_sets_test "a compiler's records: its own set, else the newest below it" (expected 13.4, found 13.3). The mHC 13.4 set had moved to registry_joins.zig (cuda_sets_after), but cuda_sets in registry_cuda_sets.zig never appended it, so setFor(13.4) fell back to 13.3. Main alone passes this test.

The new head c1ec09679 is on main 11a0de0cf:

  1. CI fix. cuda_sets now ends with ++ joins.cuda_sets_after (cuda: register nvcc 13.4 contract records). Your re-pin of gradient-serving.tsv is folded into the rebase, recomputed against the merged kernels.zig. registry.zig stays under 600 lines.

    • CI on this head: green on c1ec09679: all 9 jobs pass, including zig, zig-b and zig-windows.
  2. Receipts (RTX PRO 4500, SM120, nvcc 13.4). I first rebased onto dffe42485 and ran everything there, then main moved again; the second rebase only touched three lines (max_rows → grid_rows, the living import, the controls include list), and I reran the serving gates on this head:

    • Qwen3.8-27B against main 11a0de0cf (4-bit TF-native, DFlash2, FP8 KV, --context 32768, greedy, 256 tokens, alternating main/head/main/head): greedy tokens are byte-identical in all four runs, and bench_concurrent --alone --serial is equal on both. Decode medians over 6 samples each: code 219.1 (main) vs 219.4 (head) tok/s, Welch p = 0.99; chat 161.4 vs 161.4, p = 0.91. At 4 streams on the previous head against dffe42485 (aggregate): greedy code 438.7 vs 438.4 (p = 0.53) and chat 318.7 vs 323.6 (p = 0.064); sampled within ±1.5%, none significant.
    • Loop-9B, this head: unchanged from 8f55e46a2. 10/11 prompts token-identical to vLLM, and the 11th diverges at the same exact tie (token 29, margin 0.0). The parity output is byte-identical to the earlier head's. Concurrent equals solo, greedy (3/3, 12/12) and sampled (2/2, 8/8). A two-turn chat resumes at 4096 and matches cache off. Chat template and tools match HF. Decode is 25.9 tok/s at 1 stream and about 100 tok/s aggregate at 4. Cold TTFT is 0.75 / 3.06 / 13.1 s at 2k / 8k / 32k.
    • New: teacher-forced fidelity (previous head), which was under "Not done". Against the vLLM BF16 reference (BF16 KV, top-64 plus tail) on 219 held-out rows (94,235 positions, 6 categories): mean KL 0.000416 (95% position bootstrap 0.000407–0.000426), top-1 agreement 0.992, PPL equal to the reference. For scale on the same positions, ExLlamaV3's BF16 engine gives 0.000335. Details are in the description.
    • New: long context (previous head, BF16 KV, --context 135168): cold TTFT 64.3 s at 128k tokens, decode 20.7 tok/s right after, 25.7 GB peak on the 32 GB card.
  3. Full unfiltered kernel contract on SM120 (previous head; no kernel changed in the second rebase).

    • Previous head (c6415563d, on dffe42485): 719 kernels: 719 pass gates 1-4, 0 fail, 8 known findings; 433 controls: 433 red as planted, 0 missed; 597 limit problems. The four mHC kernels and their four planted controls are among them, all red as planted.
    • Main 81de26f64, same toolchain, for comparison: 710 kernels: 710 pass gates 1-4, 0 fail, 8 known findings; 429 controls: 429 red as planted, 0 missed; 577 limit problems.
    • The 8 known findings are main's own: six qwen35 attention cases (tf_q35_attn_merge skips a chunk with a NaN key) and two GLM relu cases.
    • Both runs fail the limit gate the same way with nvcc 13.4. The live per-launch failures are the same set on head and main (395 lines, recorded 0, 0: main has no 13.4 usage records for those launches). The static table check differs by 20 problems (203 against 183), which are exactly the four mHC kernels × five SMs reported as no compiled usage recorded, the same kind as main's 183 (for example tf_q35_attn_partial_*, fn_row_topk). I can only measure their usage with 13.4, which is the set this PR records. If you'd like base records for them, tell me which toolchain CI pins and I'll add them. One visible effect of the CI fix: the head's live check reads checked against nvcc 13.4's records, where main reads 13.3's records (the newest set at or below it).
    • Every checklist box is ticked or says why it can't be.
  4. The readers (qwen27 metal: serve SenseNova-Loop-9B natively (BF16 and AWQ g128, 512K YaRN, images) #3859). I compared them field by field (loop_config.zig / cuda_geometry.zig against families/sensenova_loop/config.zig / qwen27/config.zig at c07419f1f). Both pass the shared 85-case fixture (byte-identical in both PRs). They agree on location, use_gate, unknown keys, absent or null mhc, streams, fixed_identity, the iteration range, layer_types, tied heads, mHC ranges and the one-layer mHC role. Three differences:

    • pre_scale that underflows f32: 1e-50 passed CUDA admission and would have run as 0, while Metal refused it. Fixed on this head (c1ec09679), and the fixture gains two cases: 1e-30 accepts, and 1e-50 is refused at admission. @gilby, 1e-50 already gives admission on qwen27 metal: serve SenseNova-Loop-9B natively (BF16 and AWQ g128, 512K YaRN, images) #3859 (I checked it in a scratch copy of the fixture), and 1e-30 is a normal f32, so both should pass there as they are. Could you take them, so the files stay identical?
    • Loop count and plan caps differ. CUDA admits a config count with up to 512 executions and --loops 1–4. Metal caps plans at 128 executions and has no 4-loop cap. So a config with count 6 (152 executions) loads on CUDA and is refused on Metal, while --loops 5 on a one-layer body loads on Metal and not on CUDA. Neither matters for the release config (56). I'd agree on one rule: config counts up to the reference's eval_count bound, plus a shared execution cap.
    • Integer widths: Metal reads counts and iterations as u32, CUDA as usize. Admission bounds both well below either limit.

    Which reader to share: I'd start from the CUDA loop_config.zig. It is std-only, takes the root object and layer count, and carries none of the engine geometry, RoPE, EOS or plan types. I'd keep Metal's three error names (bad loop settings, bad mHC, crossing boundary) instead of CUDA's single BadLoopConfig. It would move to zig/src/core/sensenova_loop_config.zig as a named module in both build graphs, wired like qwen35_layers. Each engine keeps its own admission with named errors, and the shared fixture runs through the parser and both admissions. I'd do this as a follow-up once both PRs are on main, unless you'd rather have it in one of them.

@AIFlowML

Copy link
Copy Markdown
Contributor

I ran zig build test-qwen35-loop-host test-qwen35-loop-refusal-host test-gradient-serving -Dcpu=apple_m1 -j5 --summary all on c1ec09679 with Zig 0.17.0. It passed 215 tests with two skips. I also copied the byte-identical 87-case CUDA fixture into a scratch copy of Metal #3859 at c07419f1f and ran zig build test-sensenova-loop-config-host -Dcpu=apple_m1. Both readers accepted pre_scale=1e-30 and refused 1e-50 at admission under the same fixture.

I checked the three conflicts against 124052c97 in a scratch merge. Keeping both control includes and both refusal tests, then hashing the combined zig/src/cuda/kernels.zig for the serving pin, passed the three host targets above plus test-kernel-contract (475 passed, two skipped). I widened the local refusal test filter to exercise main's rank/world test as well. The resulting controls source also compiled to an SM120 fatbin with nvcc 13.1, and its symbols include both HCN controls and all four mHC controls. This covers the rebase wiring; the GPU runtime receipts are the author's runs.

Igor Lessio - AIFLOW LABS

@ashhart
ashhart force-pushed the sensenova-loop-cuda branch from c1ec096 to c19ccfe Compare November 21, 2026 21:11
ashhart added a commit to Maxrio9/TensorFold that referenced this pull request Nov 21, 2026
…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.
ashhart added a commit to Maxrio9/TensorFold that referenced this pull request Nov 21, 2026
… 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.
ashhart added a commit to Maxrio9/TensorFold that referenced this pull request Nov 21, 2026
…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
5a19a37c; the two comments become one line.
@AIFlowML

Copy link
Copy Markdown
Contributor

I rechecked c19ccfedf for the release queue. It trial-merged cleanly into the environment fix #4467 at 3f9742cf9, based on main 1eed88bb, without local source edits.

On M5 Max with Zig 0.17.0, this passed 524 tests with 2 skips, including the host kernel contract that contains the CUDA 13.4 registry lookup that failed before the join fix:

zig build test-qwen35-loop-host test-qwen35-loop-refusal-host test-gradient-serving test-kernel-contract -Dcpu=apple_m1 -j4 --summary all

The full SM120 device contract and Qwen3.8-27B token comparison are still separate release checks.

Igor Lessio - AIFLOW LABS

@Maxrio9
Maxrio9 force-pushed the sensenova-loop-cuda branch from c19ccfe to 55bf14d Compare November 23, 2026 10:47
Maxrio9 pushed a commit to Maxrio9/TensorFold that referenced this pull request Nov 23, 2026
…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.
Maxrio9 pushed a commit to Maxrio9/TensorFold that referenced this pull request Nov 23, 2026
… 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.
Maxrio9 pushed a commit to Maxrio9/TensorFold that referenced this pull request Nov 23, 2026
…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 and others added 14 commits November 24, 2026 00:53
…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.
@ashhart
ashhart force-pushed the sensenova-loop-cuda branch from 55bf14d to 79d1cee Compare November 24, 2026 00:55
@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thanks for the careful work on the shared Qwen engine and for addressing the earlier registry, controls, serving-pin and pre_scale issues. The supplied head merges cleanly into the required current main, and the source hash matches the serving fixture.

I found three remaining issues:

  1. cuda_native_loop.zig does not forward kvHostRoom or kvHostRefusal. In TF_QWEN_KV_HOST=1 mode, SenseNova therefore misses the host-memory cap check and host-aware stream planning. Please forward both hooks and add cap/one-stream refusal coverage.
  2. The same wrapper omits snap_spare, snap_trim and snap_reuses. The Qwen snapshot implementation still retains spare host buffers, but the generic prompt cache cannot account for, trim or reuse them for SenseNova. Please forward these hooks and include SenseNova in the capability test.
  3. dense_serving_test.zig does not include try mhc.* calls in its launch-sequence hash. Changes to mHC integration in cuda_forward.zig can therefore leave that test unchanged. Please add the mHC prefix and re-pin it.
  • Synthena

@joshuaswarren

Copy link
Copy Markdown
Contributor

sm_120 kernel-contract run on the RTX 5060 Ti (jw16, boot fc0f7ff9) at head 79d1cee, tf-cuda-test kernel-contract mhc — build: aarch64 -Dcpu=baseline -Dsm=120, nvcc 13.0 (DGX Spark build host).

SUMMARY 9 kernels: 9 pass gates 1-4, 0 fail, 0 known findings; 4 controls: 4 red as planted, 0 missed; 4 limit problems — the new qwen35_mhc kernels (enter/route/merge/leave) launch on sm_120 with real register/shared usage vs 0, 0 records:

  • enter: 256 thr, 17 regs, 0+0 shared
  • route: 256 thr, 39 regs, 1068+0 shared
  • merge: 256 thr, 28 regs, 0+0 shared
  • leave: 256 thr, 18 regs, 0+0 shared

@ashhart

ashhart commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Thanks @Maxrio9, and @joshuaswarren for the focused check. The numerical gates and all four controls pass in that result, but the four compiler 13.0 limit records remain unqualified.

The three source requests are still open: forward both host-KV admission hooks, forward the three snapshot-spare hooks and include the loop entry in their regression, and include mHC calls in the launch fingerprint before re-pinning it. Please retain compiler-specific measurements rather than using the 13.4 records for 13.0.

The current-main list, fixture and source-pin merges remain ours.

  • Synthena

@Maxrio9

Maxrio9 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

I checked the CUDA 13.0 resource records separately from 13.4. With nvcc 13.0.88, serving math flags, and an RTX PRO 4500 (SM120), the driver reported:

mHC kernel Registers Static shared memory
enter 17 0 B
route 39 1,068 B
merge 28 0 B
leave 18 0 B

Those agree with Joshua's SM120 measurements. The compilation used a temporary host-header overlay to work around a glibc declaration conflict. I also compiled SM80, SM86, SM89 and SM121 metadata; those architectures have not had their 13.0 resource records checked on devices here. CUDA 13.1–13.3 remain unqualified.

The three requested source changes are prepared and tested locally but have not been pushed, so the published PR still needs them. A local integration with main 9961ca492 passed the full host suite on retry (899/899 steps; 675 tests passed and 14 skipped, with cached steps) and the host-KV device refusal and generation checks. An earlier full-suite attempt hit a CUDA stager I/O error; the retry passed. The local integration also overlaps #4966 in the shared CUDA source-hash fixture. I saw your note that current-main list, fixture and source-pin merges are yours, so I have not pushed the integration merge. What landing order would you prefer for #3723 and #4966?

@ashhart

ashhart commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Thank you for the compiler-specific measurements and for preparing the wrapper fixes. The supplied head still needs those changes published: the SenseNova wrapper must forward both host-KV hooks and all three snapshot-spare hooks, and the launch-sequence fixture must include the mHC calls. The 13.0 resource values also need to be recorded separately rather than reusing the 13.4 table.

One exactness issue needs a further correction. The loader converts the checkpoint's FP32 dt_bias to BF16 for SenseNova. A reference that performs the same cast does not make that added rounding valid for our engine. Please preserve the stored FP32 values through the target path, with no rounded default or opt-in substitute, and rerun the exact-output comparison after that change.

After those fixes, the remaining device gate is the full mHC numerical and planted-control contract with no unqualified resource records, followed by SenseNova token equality against the serial reference and the unchanged Qwen3.8-27B comparison. We will handle the current-main registration, fixture, and source-pin integration; no rebase is needed from you.

  • Synthena

@Maxrio9

Maxrio9 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Pushed d358d0b17 on the existing branch without rebasing. It forwards the two host-KV hooks and three snapshot-spare hooks, includes the loop entry in the snapshot regression, adds try mhc.* to the launch fingerprint, and adds the independently measured nvcc 13.0 records separately from 13.4.

The FP32 dt_bias correction is still in progress and is not in this head. I also found that the previous vLLM reference run logged FP32-to-BF16 casts for these tensors, so its old token comparison is not evidence for the requested unrounded reference. I will report the corrected comparison and device gates separately when they are available.

@ashhart

ashhart commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Thank you for forwarding the host-KV and snapshot hooks, adding the Loop regression entries, pinning all six mHC calls, and publishing separate compiler-version resource records. Those requested changes are confirmed in the source.

One numerical blocker remains: zig/src/families/qwen3_5/cuda_weights.zig:149-157 still converts checkpoint FP32 dt_bias to BF16, and zig/kernels/cuda/qwen35.cu:199,256 consumes it as BF16. Please preserve four-byte FP32 values through the SenseNova loop loader, size accounting and gdn_pre consumption, while leaving ordinary Qwen and EXL3 BF16 paths unchanged. Replace the rounding regression with exact FP32-bit preservation coverage and re-pin affected source or resource records.

Two added comments also exceed 120 columns: zig/src/families/qwen3_5/cuda_forward.zig:75 and zig/src/families/qwen3_5/loop_config.zig:53. Please shorten those comments only.

After the FP32 fix, the remaining cells are the full mHC contract on the previously named compiler/device pair with zero unqualified limits, a SenseNova serial-reference comparison preserving FP32 dt_bias, and the final-head/current-main Qwen3.8-27B unchanged-checkpoint serial comparison. The nine current-main conflicts remain integration work on our side; no rebase is requested.

  • Synthena

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.

4 participants