Skip to content

qwen27 metal: serve SenseNova-Loop-9B natively (BF16 and AWQ g128, 512K YaRN, images) - #3859

Closed
gilby wants to merge 6 commits into
ashhart:mainfrom
gilby:sensenova-loop-metal
Closed

gilby wants to merge 6 commits into
ashhart:mainfrom
gilby:sensenova-loop-metal

Conversation

@gilby

@gilby gilby commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Adds native Metal inference support for sensenova/SenseNova-Loop-9B (sensenova_loop / sensenova_loop_text) through the qwen27 lane backend in both BF16 and AWQ W4A16 (group_size=128) weights, including the 56-step looped execution schedule (stem 0..3, trunk 4..27 run twice, tail 28..31), two-stream Sinkhorn-Knopp mHC kernels, OutSplits sibling linear stacking (281 -> 226 dense dispatches/token), fused XS128 AWQ xsum+scale (Q27_XS=128), 512K static YaRN scaling (factor=2.0, honoring o.rope_yarn), model.visual. image inputs, 2048-row wide_prompt chunks, Copy-Draft enabled by default for config.looped, and the tf-sensenova-oracle Hugging Face trace verifier.

Review updates since initial posting

  1. Isolated non-looped qwen27 / shared paths:
    • zig/src/families/qwen27/decode_round.zig: scoped relaxed verify-tail and loop.encodeAttnProj to r.model.config.looped; restored strict accepted or head != .all check and "accepted round" test case in zig/qwen27_bank_boundary_host.zig.
    • zig/src/families/qwen27/attention.zig: preserved existing chunks * plan.tiles * 16 <= scratch.tail_chunks * scratch.limits.rows * 16 bound when wide_prompt == false.
    • zig/src/native/metal.zig & zig/src/families/qwen27/{config,model,yarn}.zig: scoped --rope-yarn acceptance and factor != 1 YaRN resolution to SenseNova (isSenseNova / config.looped), checked resolved senseNovaMaxContext ceiling instead of hardcoding 524,288, read generation_config.json only when isSenseNovaRoot, and kept root.get("max_position_embeddings") fallback gated to looped.
    • zig/src/core/qwen_vl/weights.zig: kept loadWith defaulting to NoVisionTower on "vision_tower."; SenseNova opts into "model.visual." via loadWithPrefixes, and unit test checks shards.headersFor without emitting std.log.err.
    • zig/src/families/qwen27/widths.zig: hashes x.kind in costShape only when x.kind != .affine so existing affine checkpoints retain prior timed cost keys.
  2. Aligned sensenova_loop config.json parser & fixture with qwen3_5 cuda: SenseNova-Loop-9B (sensenova_loop) in BF16, text only #3723: Merged config alignment (20f85515c) per @Maxrio9's note (use_gate, strict root keys, iterations=20, pre_scale=1, layer_types, non-tied head, mHC range validation).
  3. Dropped unused kernels/fields & added missing receipts: Removed unused sn_awq_int4_embed, sn_awq_quantize_bf16, awq_quant.metal, and LinearGpu.quantizeBf16ToAwq; removed unused qwen27_served.Options.drafts field in this base PR; added bit-exact factor-2 YaRN test in zig/src/core/rope_yarn.zig against transformers 5.14.1 (0x3f88df4e + 32 u32 words); enabled lone Copy-Draft for looped in qwen27_lanes.zig and ordered "copy" first in tools/conformance_profiles/sensenova-loop-metal.json so conformance.py passes 7/7 on both BF16 and AWQ.

Checks on this head

  • Head commit: c07419f1f8b0d0e6b5fbe28560dcabecd219c2d5
  • Lean checker, python3 tools/pr_check.py --base origin/main --pr 3859: merge base 685851076f2bf2a0710565dc6095ea407c5ea930; 83 changed files; lean 189 vs 189, 0 new; 0 error(s), 0 warning(s).
  • Formatting & diff hygiene: zig fmt --check build.zig zig exit 0; git diff --check origin/main...HEAD exit 0.
  • Host & golden suite on c07419f1f (Apple M5 Ultra):
    • zig build test-golden test-native test-qwen27 test-sensenova-loop-config-host test-kernel-contract test-environment-host test-env-defaults-host dev-tools --summary all: exit 0, 347/347 steps succeeded; 739/747 tests passed (8 skipped) (includes test-golden 322/335 with 0 unexpected diffs, test-native 156/159, test-qwen27 158+21+5, test-sensenova-loop-config-host 3/3, rope_yarn factor-2 word-for-word test, and qwen27_bank_boundary_host; full 1131/1131 build/test 15065/15194 passed earlier on 39386ed14).
  • Python tooling tests: tools/zig 86/86 (3 skipped), tools/tests/test_bench_conformance.py 45/45; tools/tests 366/367 (test_eval_sandbox.py:145 hits unrelated origin/main macOS SIP chflags PermissionError copying /usr/bin/open; skipped on Ubuntu CI pytest).
  • GPU contracts, oracle, conformance, and served receipts (verified at f76202899 / c64b6cf5b; subsequent merges 39386ed14 and c07419f1f only merged upstream CHANGELOG.md, nccl, server, and #3716 config_fields/checkpoint_eos plumbing):
    • ./zig-out/bin/tf-sensenova-oracle: BF16 (exec55=0.9998916, logits=0.9999594, TOP1 4/4, TOP16 16/16, 6/6 greedy exact 4/4, 4/4, 42/42, 64/64, 64/64, 64/64); AWQ g128 (exec55=0.9999162, logits=0.9999633, TOP1 4/4, TOP16 16/16, 6/6 greedy exact 4/4, 42/42, 22/22, 64/64, 96/96, 64/64).
    • python3 tools/conformance.py tools/conformance_profiles/sensenova-loop-metal.json: 7 passed, 0 failed, 0 skipped on both BF16 (drafted == plain: 10/10 equal, 98/108 drafts accepted; resumed == fresh: 6/6 equal, cached_tokens [6107, 6191, 6107, 6191]) and AWQ g128 (drafted == plain: 10/10 equal, 106/116 drafts accepted; resumed == fresh: 6/6 equal, cached_tokens [6107, 6191, 6107, 6191]).
    • tools/bench_concurrent.py --levels 1,4 --temperatures 0,1.0 --tokens 128 --reps 2 --alone --serial: 0 failed, 0 unmeasured, 0 unequal on all 8 cells (alone 2/2 & 8/8, serial 1/1 & 4/4) in both BF16 and AWQ g128.
    • tools/bench_cache_agents.py --trace agent_loops --conversations 2 --rounds 4 --prefix-tokens 4096 --tokens 64: BF16 (qualified: true, 24/24 usage_verified, 22/24 cached_tokens > 0, rebuilt_rows: 71423) and AWQ g128 (qualified: true, 24/24 usage_verified, 22/24 cached_tokens > 0, rebuilt_rows: 71219).
  • CI on c07419f1f: all 9 checks green (benchmark-clients (ubuntu-latest), benchmark-clients (windows-latest), fmt, pytest, release-paths (ubuntu-24.04), zig, zig-b, zig-macos-dev-tools, zig-windows SUCCESS; host-nightly-linux and host-nightly-macos SKIPPED).
  • Not run, and why: CUDA (-Dnvcc), HIP (-Dhip=true), XPU, Windows, and Apple M1/M2/M4 chips — changes target Metal sensenova_loop / qwen27 (looped / wide_prompt gated) and were qualified on Apple M5 Ultra (applegpu_g17, tensor units) and Apple M3 Ultra (applegpu_g15, non-tensor-unit SIMDgroup path).

Receipt

  • Main against branch: On main (685851076), model_type: "sensenova_loop" is refused as UnsupportedModel. Cooled 4-pass A-B-B-A (main 32c4e3d8f vs #3859) on both Apple M5 Ultra and Apple M3 Ultra for Qwen3.5-9B-4bit and Qwen3.8-27B-MLX-4bit shows identical token_sha on all deterministic runs and no regression (0.9895x–1.0685x, full table in Gist).
  • Boxes it reaches: zig/src/families/sensenova_loop/*, zig/kernels/metal/core/sensenova_mhc.metal, zig/kernels/metal/qwen27/{bf16_linear,awq_w4a16,awq_m5_fast,glue,mlp_xs,norm_input,norm_xs}.metal, zig/src/families/qwen27/*, zig/src/core/{rope_yarn,qwen_vl/weights,qwen_vl/tower,contract/sensenova_*}.zig, zig/src/native/{metal,qwen27_engine,qwen27_reserve,qwen27_served,qwen27_lanes,qwen27_images,slide_open_test}.zig, zig/src/cli/hub.zig, zig/src/server/family_sampling.zig, zig/tests/{contract/metal_*,qwen27/sensenova_oracle}.zig, tools/conformance_profiles/sensenova-loop-metal.json.
  • New switch? Default, accepted values, profile row: No new CLI switch or TF_* environment variable in this PR (--rope-yarn already on main is wired into SenseNova checkpoints, resolving against config.json ceiling; Copy-Draft defaults on for looped when TF_QWEN27_COPIES is unset; conformance profile tools/conformance_profiles/sensenova-loop-metal.json).
  • Environment, with the TensorFold commit, Zig and backend toolchain, machine and GPU, checkpoint and revision: Base 685851076f2bf2a0710565dc6095ea407c5ea930, head c07419f1f8b0d0e6b5fbe28560dcabecd219c2d5; Zig 0.17.0; Apple Metal 32023.922; macOS 27.2.1 on Apple M5 Ultra 512 GB (applegpu_g17) and macOS 26.6.2 on Apple M3 Ultra 512 GB (applegpu_g15); sensenova/SenseNova-Loop-9B revision 3e1ba6e8ac98090f9f7c03a55f26269eb3850fb6 (BF16 and quantize_sensenova_awq.py W4A16 g128 conversion).
  • Paths and platforms the change reaches, which I ran and which I could not: Ran native Metal qwen27 / sensenova_loop BF16 & AWQ g128 host tests, Metal kernel contracts on M5 Ultra and M3 Ultra, cooled 4-pass A-B-B-A non-regression on M5 Ultra and M3 Ultra, HF oracle parity, conformance.py 7/7, bench_concurrent.py, and bench_cache_agents.py. Could not run Apple M1/M2/M4, CUDA, HIP, XPU, or Windows.
  • Exactness, from tools/bench_concurrent.py --alone --serial or token_sha against "draft": false: tools/bench_concurrent.py --levels 1,4 --temperatures 0,1.0 --tokens 128 --reps 2 --alone --serial: BF16 (code & chat) and AWQ g128 (code & chat) failed: 0, unmeasured: 0, alone 2/2 at c=1 and 8/8 at c=4 (unequal: 0), serial 1/1 (T=0) and 4/4 (T=1.0) (unequal: 0). conformance.py drafted == plain: 10/10 equal on both BF16 (98/108 drafts accepted) and AWQ (106/116 drafts accepted).
  • Main against this branch, same machine and checkpoint, posted before asking for a run on our machines (or why you can't): main refuses sensenova_loop (UnsupportedModel). For existing qwen27 checkpoints (Qwen3.5-9B-4bit and Qwen3.8-27B-MLX-4bit), cooled 4-pass A-B-B-A (main 32c4e3d8f vs #3859) on M5 Ultra and M3 Ultra shows zero regression and identical token_sha:
    • M5 Ultra (--parallel 4 --prompt-cache-gib 0, TF_QWEN27_SLOT_RESUME=0, cached_tokens == 0): Qwen3.5-9B-4bit prefill 2048 0.3530s -> 0.3522s (1.0022x, sha=0295af491acd), 8192 1.4111s -> 1.4088s (1.0016x, sha=b0bf2d60cd68), decode 120.01 -> 120.16 (T=0 fib, bd2789147d7e) / 130.10 -> 130.12 (T=1.0); Qwen3.8-27B-MLX-4bit prefill 2048 1.0724s -> 1.0721s (1.0003x, 12b2383204bb), 8192 4.3496s -> 4.3475s (1.0005x, 85ea6fe29514), decode 47.21 -> 47.24 (T=0 fib, a10c9b848ed9) / 48.75 -> 48.73 (T=1.0).
    • M3 Ultra: Qwen3.5-9B-4bit prefill 2048 1.6359s -> 1.5421s (1.0608x, 0295af491acd), 8192 6.7437s -> 6.4126s (1.0516x, b0bf2d60cd68), decode 92.24 -> 92.17 (T=0 fib, 92e7d77ab272) / 99.52 -> 99.38 (T=1.0); Qwen3.8-27B-MLX-4bit prefill 2048 5.1365s -> 5.1368s (0.9999x, 12b2383204bb), 8192 21.2363s -> 21.3384s (0.9952x, 85ea6fe29514), decode 118.89 -> 118.61 (T=0 fib, 2b28aa2108de) / 136.88 -> 135.45 (T=1.0).
  • Decode speed before and after, from tools/bench_openai.py & tools/bench_concurrent.py:
    • Apple M5 Ultra (--parallel 4 --context 36864 --prompt-cache-gib 0, bench_openai.py 256 tok 3 reps on 0ff2bcc51): BF16 28.94–29.06 tok/s, AWQ g128 54.30–55.51 tok/s.
    • Apple M5 Ultra bench_concurrent.py (128 tok, 2 reps, --prompt-cache-gib 8): BF16 c=1 29.0–29.3, c=4 agg 103.9–106.4 (per 26.8–27.3); AWQ g128 c=1 54.4–55.9, c=4 agg 191.2–196.3 (per 49.8–50.5).
  • Prompt speed before and after: cold first request ttft_s from tools/bench_cache.py --require-cold (0ff2bcc51, cached_tokens: 0, qualified: true, --prompt-cache-gib 0, plus 4-run median in parens):
    • BF16: 2,048 tok 0.601s (3,405 tok/s, median 0.594s / 3,445 tok/s); 8,192 tok 2.390s (3,427 tok/s, median 2.345s / 3,493 tok/s); 32,768 tok 10.247s (3,198 tok/s, median 10.227s / 3,204 tok/s).
    • AWQ g128: 2,048 tok 0.767s (2,670 tok/s, median 0.735s / 2,786 tok/s); 8,192 tok 2.914s (2,812 tok/s, median 2.885s / 2,840 tok/s); 32,768 tok 12.588s (2,603 tok/s, median 12.543s / 2,613 tok/s).
  • Licence of any new weights or drafter, or "n/a": sensenova/SenseNova-Loop-9B is Apache-2.0 (no external drafter weights in this PR).
Kernel contract, only when a GPU kernel is new or changed
  • Kernels registered with the contract, and the kernel each one replaces: New family kernels (sensenova_mhc_records.zig & sensenova_linear_records.zig; no prior sensenova_loop kernels replaced): sn_mhc_enter, sn_mhc_pre_norm, sn_mhc_post_merge, sn_mhc_post_and_pre_norm (verified against sequential postMerge -> preNorm), sn_bf16_mv_*, sn_bf16_gemm_*, sn_bf16_gemm_splitk_*, sn_bf16_gemm_splitk_sum, sn_awq_lane_*, sn_awq_m5_mv_*, sn_awq_gemm_m5, sn_awq_row_mv_*, sn_awq_qmm_m3, sn_awq_xsum_128, sn_awq_scale_input; plus Q27_XS=128, YaRN q27_rope, q27_head_norm shift, and q27_embed_bf16 tested in the qwen27 contract suite (--only qwen27). (Unused sn_awq_int4_embed and sn_awq_quantize_bf16 were removed.)
  • A planted control for each new kernel, and each one fails as planted: 45 M5 / 37 M3 sensenova controls and 6 M5 / 3 M3 qwen27 controls — all fail red as planted (0 missed).
  • Each backend's SUMMARY line and exit status:
    • Apple M5 Ultra (applegpu_g17, tensor_units=true, exit 0):
      • ./zig-out/bin/tf-kernel-contract --only sensenova: SUMMARY 24 kernels: 24 pass gates 1-4, 0 fail, 0 known findings; 45 controls: 45 red as planted, 0 missed; 0 limit problems; gates 18457 ms, limits 409 ms
      • ./zig-out/bin/tf-kernel-contract --only qwen27: SUMMARY 40 kernels: 40 pass gates 1-4, 0 fail, 0 known findings; 6 controls: 6 red as planted, 0 missed; 0 limit problems; gates 306596 ms, limits 387 ms
    • Apple M3 Ultra (applegpu_g15, tensor_units=false, exit 0):
      • ./zig-out/bin/tf-kernel-contract --only sensenova: SUMMARY 17 kernels: 17 pass gates 1-4, 0 fail, 0 known findings; 37 controls: 37 red as planted, 0 missed; 0 limit problems; gates 13069 ms, limits 43 ms
      • ./zig-out/bin/tf-kernel-contract --only qwen27: SUMMARY 30 kernels: 30 pass gates 1-4, 0 fail, 0 known findings; 3 controls: 3 red as planted, 0 missed; 0 limit problems; gates 117016 ms, limits 33 ms
  • Chips I could not run: Apple M1, M2, M4; CUDA, HIP, XPU.

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. If the bits change, the description says which sums change and why.
  • 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

@ashhart

ashhart commented Nov 18, 2026

Copy link
Copy Markdown
Owner

Thanks @gilby. Running SenseNova-Loop-9B through the qwen27 lane host, with one copy of the trunk weights and a KV or delta-net slot for each of the 56 steps, is a clean way in. The oracle trace, the kernel contracts on both chip classes and the concurrent-equals-alone receipts give a solid base. Only CHANGELOG.md fails to apply on current main, and we settle that when it lands.

Before it can land:

  1. Existing qwen27 models on the default path. Several shared paths change for every qwen27 checkpoint, not only looped ones:

    • decode_round.zig:267 relaxes the verify-tail guard for all models, and qwen27_bank_boundary_host.zig:39 drops the "accepted round" case from its test. Please limit the relaxed guard to config.looped and keep the old test for the other models.
    • Attention Q/K/V for every model now goes through loop.encodeAttnProj (decode_round.zig:517).
    • The M3 prompt bound at attention.zig:476 now compares against pob's byte length instead of the element count.
    • The norm/MLP kernels now get #define Q27_XS 64 instead of 1, and Head and Rope grow. These look identical in arithmetic.

    Please post main against this branch on the same machine for Qwen3.8-27B and the 9B qwen27 shape, on both an M5 and a pre-M5 chip: greedy token_sha for each, plus decode and cold-prompt speed. If you can't, please say why.

  2. Changes the description doesn't mention. Please gate each of these to SenseNova or split it into its own PR:

    • --rope-yarn is now accepted on Metal for qwen3_5 and qwen3_5_moe (native/metal.zig:141). A Qwen3.5-2B checkpoint goes to qwen35.zig, which never reads the flag, so the flag is silently ignored where main refused it. metal.zig:323 also allows 524,288 tokens for any factor instead of checking the resolved ceiling.
    • model.zig:102-106 now reads generation_config.json for every qwen27 checkpoint. A bad file, or more than 8 EOS ids, now refuses a load that main accepted.
    • config.zig:364 now falls back to the root max_position_embeddings.
    • The shared vision loader (core/qwen_vl/weights.zig:100) now falls back to model.visual.. That loader is also used on CUDA, HIP and Flash Next.
    • widths.zig:178,182 hash the new kind, so every existing mixed-width checkpoint loses its timed costs. Hashing kind only when it isn't .affine would keep their old keys.
  3. The same config.json read two ways. qwen3_5 cuda: SenseNova-Loop-9B (sensenova_loop) in BF16, text only #3723 serves this model on CUDA with qwen3_5/loop_config.zig. Your sensenova_loop/config.zig accepts or refuses different things:

    Both build the same schedule for the release config (0-3, then 4-27 twice, then 28-31), with each pass entering and leaving mHC. Separately, sensenova_loop_text is accepted at the root by metal.zig and qwen27/config.zig but refused by sensenova_loop/config.zig:136. A one-layer mHC range gets .enter and never .exit (config.zig:89). Please agree one set of rules with @Maxrio9, or say which reader should be shared.

  4. Exactness receipts still missing:

    • Drafted output against "draft": false. The recipe turns copy drafts on.
    • A resumed prompt against a fresh one with the prompt cache on. Every receipt used --prompt-cache-gib 0.
    • Where the AWQ (group size 128) checkpoint comes from: the repository and revision, or the conversion recipe. quant_method: "loop_awq" suggests your own export.
    • The factor-2 YaRN table checked word for word against transformers, as core/rope_yarn.zig does for factor 4. rope_test.zig checks the GPU within 2% of our own table.
  5. Unused code and CI. quantizeBf16ToAwq (sensenova_loop/linear_quant.zig:65) and sn_awq_int4_embed have no served caller, since widths.zig:142 refuses a quantized embedding. The new drafts option (qwen27_served.zig:27) is never read. Please drop them or say what uses them. Please also post green CI on the head; the description says it was still re-running.

  • Synthena

@gilby

gilby commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

Addressed point 3 (and rebased onto current main via fast-forward merge at commit 20f85515c, resolving CHANGELOG.md, qwen27/model.zig, and metal_main.zig so the PR is MERGEABLE cleanly):

  • Aligned sensenova_loop config.json validation and Metal qwen27 admission with qwen3_5 cuda: SenseNova-Loop-9B (sensenova_loop) in BF16, text only #3723 (8f55e46a2d) per #3781's shared rules, including root-only loop_settings/mhc, optional mhc, .both one-layer mHC handling in MhcRole and qwen27/loop.zig, admission limits (streams != 2, fixed_identity: true, iterations > 1000, non-FP32 pre_scale, tied head), shared core/qwen35_layers.zig pattern reading, and root-only sensenova_loop model_type across native/metal.zig, qwen27/config.zig, and sensenova_loop/config.zig.
  • Added the byte-identical 85-case zig/tests/fixtures/sensenova_loop_config.json and zig/sensenova_loop_config_host.zig (test-sensenova-loop-config-host), passing all 85 shared cases plus FP32 overflow / root sensenova_loop_text checks (1109/1109 steps in zig build test test-golden dev-tools, 24/24 kernels & 45/45 controls in tf-kernel-contract --only sensenova, and x86_64-linux-gnu compile clean with 0 errors in tools/pr_check.py --pr 3859).

(Remaining review points 1, 2, 4, and 5 from #3859 (comment) will be addressed separately.)

@gilby

gilby commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the remaining points (1, 2, 4, and 5; point 3 was answered in comment #7003223145) and merged main through 685851076 (including #3716 config field/EOS integration) at head c07419f1f (only CHANGELOG.md conflicts against newer 8c3e7b809 on main). Full scrubbed logs, JSON outputs, A-B-B-A runs, and the standalone AWQ g128 conversion script are in this public Gist.

1. Existing qwen27 checkpoints on the default path

  • Runtime gating:
    • decode_round.zig:267 now applies the relaxed verify-tail rule only when r.model.config.looped is true; non-looped models retain accepted or head != .all, and zig/qwen27_bank_boundary_host.zig keeps both the non-looped advance(&round, .all) rejection check and the looped check.
    • decode_round.zig:517 gates loop.encodeAttnProj to r.model.config.looped.
    • attention.zig:476 preserves the original element-count bound (chunks * plan.tiles * 16 <= scratch.tail_chunks * scratch.limits.rows * 16) unless g.wide_prompt is set.
    • quant_gpu.zig:569-571 emits #define Q27_XS 64 for existing xg == 64 models (identical XS_T = 4u, XS_S = 2u arithmetic to #define Q27_XS 1), reserving #define Q27_XS 128 (XS_T = 8u, XS_S = 3u) for xg == 128.
  • Cooled 4-pass A-B-B-A (main 32c4e3d8f vs #3859) on Apple M5 Ultra and Apple M3 Ultra:
    • Apple M5 Ultra (--parallel 4 --prompt-cache-gib 0, TF_QWEN27_SLOT_RESUME=0, cached_tokens == 0 on all runs; prefill shows 5-run cold mean / median):
      • Qwen3.5-9B-4bit: prefill 2048 0.3530s / 0.3516s -> 0.3522s / 0.3509s (1.0022x, sha=0295af491acd); 8192 1.4111s / 1.4100s -> 1.4088s / 1.4077s (1.0016x, sha=b0bf2d60cd68); decode fib T=0 120.01 -> 120.16 tok/s (1.0012x, sha=bd2789147d7e), chat T=0 119.99 -> 120.04 tok/s (1.0004x, sha=77bb972258f4), fib T=1.0 130.10 -> 130.12 tok/s (1.0002x), chat T=1.0 129.96 -> 130.06 tok/s (1.0008x).
      • Qwen3.8-27B-MLX-4bit: prefill 2048 1.0724s / 1.0710s -> 1.0721s / 1.0706s (1.0003x, sha=12b2383204bb); 8192 4.3496s / 4.3491s -> 4.3475s / 4.3463s (1.0005x, sha=85ea6fe29514); decode fib T=0 47.21 -> 47.24 tok/s (1.0005x, sha=a10c9b848ed9), chat T=0 47.24 -> 47.22 tok/s (0.9998x, sha=a06fab348fbe), fib T=1.0 48.75 -> 48.73 tok/s (0.9997x), chat T=1.0 48.73 -> 48.71 tok/s (0.9996x).
    • Apple M3 Ultra:
      • Qwen3.5-9B-4bit: prefill 2048 1.6359s / 1.6420s -> 1.5421s / 1.5368s (1.0608x, sha=0295af491acd); 8192 6.7437s / 6.7271s -> 6.4126s / 6.3877s (1.0516x, sha=b0bf2d60cd68); decode fib T=0 92.24 -> 92.17 tok/s (0.9992x, sha=92e7d77ab272), chat T=0 92.15 -> 92.03 tok/s (0.9987x, sha=92e5fdcec8d5), fib T=1.0 99.52 -> 99.38 tok/s (0.9985x), chat T=1.0 99.09 -> 98.98 tok/s (0.9989x).
      • Qwen3.8-27B-MLX-4bit: prefill 2048 5.1365s / 5.1306s -> 5.1368s / 5.1313s (0.9999x, sha=12b2383204bb); 8192 21.2363s / 21.1399s -> 21.3384s / 21.1997s (0.9952x, sha=85ea6fe29514); decode fib T=0 118.89 -> 118.61 tok/s (0.9976x, sha=2b28aa2108de), chat T=0 83.55 -> 83.45 tok/s (0.9989x, sha=a06fab348fbe), fib T=1.0 136.88 -> 135.45 tok/s (0.9895x), chat T=1.0 75.62 -> 75.84 tok/s (1.0030x).

2. Gating changes outside the original description to SenseNova

  • --rope-yarn & ceiling (native/metal.zig, qwen27_engine.zig, qwen27/{config,yarn}.zig): Refuses --rope-yarn on non-SenseNova Metal models again, handles --rope-yarn 1 cleanly via yarn.zig, and checks --context against config.senseNovaMaxContext (covered by new refusal/ceiling tests in zig/src/native/slide_open_test.zig).
  • generation_config.json (qwen27/model.zig:148-152): Read only when cfg.isSenseNovaRoot(a, text) is true.
  • Root max_position_embeddings fallback (qwen27/config.zig:387): Applied only when looped is true.
  • Vision prefix (core/qwen_vl/weights.zig:100-112): loadWith stays strictly "vision_tower." (raising NoVisionTower when absent); only loadWithPrefixes (called by qwen27_images.zig for SenseNova) checks "model.visual." via shards.headersFor without emitting std.log.err.
  • widths.zig:178-183: Hashes x.kind in costShape only when x.kind != .affine, keeping existing affine checkpoints' timed cost keys intact (unit test in widths.zig:496).

4. Exactness, AWQ g128 provenance, and factor-2 YaRN receipts

  • Conformance (7/7 PASS, 0 failed, 0 skipped) with Copy-Draft enabled by default for looped (qwen27_lanes.zig) and "copy" first in tools/conformance_profiles/sensenova-loop-metal.json:
    • drafted == plain: BF16 10/10 equal, 0 unequal, 0 unverified; 98 of 108 drafts accepted (plain_drafted=0); AWQ g128 10/10 equal, 0 unequal, 0 unverified; 106 of 116 drafts accepted (plain_drafted=0).
    • resumed == fresh (with prompt cache on): BF16 6/6 equal, cached_tokens [6107, 6191, 6107, 6191]; AWQ g128 6/6 equal, cached_tokens [6107, 6191, 6107, 6191].
    • Plus concurrent == solo (44/44 equal), repeat == first (10/10 equal), refusals (4/4), cancel (4/4), and evict (3/3, kept: 6277 -> evicted_to: 0).
  • Multi-turn cache & concurrency:
    • tools/bench_concurrent.py --levels 1,4 --temperatures 0,1.0 --tokens 128 --reps 2 --alone --serial: 0 failed, 0 unmeasured, 0 unequal across all 8 cells in both BF16 (c=1 29.0–29.3, c=4 agg 103.9–106.4) and AWQ g128 (c=1 54.4–55.9, c=4 agg 191.2–196.3).
    • tools/bench_cache_agents.py --trace agent_loops --conversations 2 --rounds 4 --prefix-tokens 4096 --tokens 64: BF16 (qualified: true, 24/24 usage_verified, 22/24 cached_tokens > 0, rebuilt_rows: 71423) and AWQ g128 (qualified: true, 24/24 usage_verified, 22/24 cached_tokens > 0, rebuilt_rows: 71219).
  • AWQ W4A16 g128 checkpoint recipe: Converted locally from sensenova/SenseNova-Loop-9B (rev 3e1ba6e8ac98090f9f7c03a55f26269eb3850fb6) using quantize_sensenova_awq.py (included in the Gist), which emits standard "quant_method": "awq", "bits": 4, "group_size": 128, "zero_point": true, "version": "gemm". Note sensenova_loop/awq.zig and config.zig already match this standard AutoAWQ metadata directly.
  • Factor-2 YaRN table (zig/src/core/rope_yarn.zig:41-52): Added a word-for-word u32 unit test for yarn(10000000, 2, 262144) (inv_freq[0..32] and attention_scaling = 0x3f88df4e) against transformers 5.14.1 (torch 2.13.0), complementing qwen27/rope_test.zig.

5. Unused code cleanup, contracts, and CI

  • Removed unused kernels & field: Dropped sn_awq_int4_embed, sn_awq_quantize_bf16, zig/kernels/metal/qwen27/awq_quant.metal, and LinearGpu.quantizeBf16ToAwq (and removed unused Options.drafts from qwen27_served.zig in this base PR).
  • Metal kernel contracts (tf-kernel-contract):
    • M5 Ultra (applegpu_g17, exit 0): --only sensenova 24 kernels: 24 pass gates 1-4, 0 fail, 0 known findings; 45 controls: 45 red as planted, 0 missed; 0 limit problems; --only qwen27 40 kernels: 40 pass gates 1-4, 0 fail, 0 known findings; 6 controls: 6 red as planted, 0 missed; 0 limit problems.
    • M3 Ultra (applegpu_g15, exit 0): --only sensenova 17 kernels: 17 pass gates 1-4, 0 fail, 0 known findings; 37 controls: 37 red as planted, 0 missed; 0 limit problems; --only qwen27 30 kernels: 30 pass gates 1-4, 0 fail, 0 known findings; 3 controls: 3 red as planted, 0 missed; 0 limit problems.
  • Host tests & CI on c07419f1f:
    • M5 Ultra zig fmt --check build.zig zig (exit 0) + zig build test-golden test-native test-qwen27 test-sensenova-loop-config-host test-kernel-contract test-environment-host test-env-defaults-host dev-tools --summary all (347/347 steps succeeded; 739/747 tests passed (8 skipped); prior full 1131/1131 build / 15065/15194 test run also passed on 39386ed14).
    • python3 tools/pr_check.py --base origin/main --pr 3859: 0 error(s), 0 warning(s); lean 189 vs 189, 0 new.
    • GitHub Actions CI on c07419f1f: all 9 checks green (benchmark-clients (ubuntu-latest), benchmark-clients (windows-latest), fmt, pytest, release-paths (ubuntu-24.04), zig, zig-b, zig-macos-dev-tools, zig-windows SUCCESS; host-nightly-{linux,macos} SKIPPED).

@ashhart

ashhart commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Thanks @gilby. All five items are in: the shared paths are gated back to today behavior with the 9B and 27B level within a hair on both chip classes and every token hash equal, the SenseNova-only changes are gated or reverted, one set of config rules now matches the shared table with the fixture to prove it, the exactness receipts and the conversion recipe are posted, and the unused code is gone with green checks on the head.

The three files that moved tonight are the usual take-both lists, which our side takes at landing. Nothing is left for you.

  • Synthena

Maxrio9 added a commit to Maxrio9/TensorFold that referenced this pull request Nov 20, 2026
…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.
@AIFlowML

Copy link
Copy Markdown
Contributor

On M5 Max with Zig 0.17.0, the exact c07419f1 head passed 490 tests with eight skips:

zig build test-sensenova-loop-config-host test-qwen27 test-native \
  test-environment-host test-env-defaults-host -Dcpu=apple_m1 -j5 --summary all

The current trial merge into 210e3b0c now has nine conflicts, including Qwen27 source. The first one I'd resolve is the frame layout: gpu_frame.zig needs main's tail_dims for the last-layer prompt optimization and the PR's h_streams and mhc_coeff for the looped model, with corresponding entries kept in the same order in allocationSizes. The associated decode_round.zig and forward.zig hunks need to keep the ordinary Qwen prompt-tail path and the looped model's mHC path. The test run above was on the exact branch, so the resolved path still needs its own run.

Igor Lessio - AIFLOW LABS

ashhart pushed a commit to gilby/TensorFold that referenced this pull request Nov 21, 2026
The net change of ashhart#3859 at c07419f over its merge base 6858510,
carried as one commit because four of the branch's merge commits hold changes of their own.
@ashhart
ashhart force-pushed the sensenova-loop-metal branch from c07419f to 5c61232 Compare November 21, 2026 00:52
@AIFlowML

AIFlowML commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

I checked the revised head 5c612326d. It merged cleanly into dc71af9d2 in scratch. The new frame layout retains main's prompt tail dimensions alongside the SenseNova loop's stream and coefficient allocations.

zig build test-sensenova-loop-config-host test-qwen27 test-native test-environment-host test-env-defaults-host -Dcpu=apple_m1 -j3 --summary all

Exit 0 on M5 Max with Zig 0.17.0. 505 tests passed and nine skipped across 84 build steps. These are the host checks from my previous review on the resolved tree. The earlier served exactness and throughput receipts remain separate.

After #3377 landed, merging #4278 (917c0af5a) into 37fa51d23 exposed a changelog conflict and a new conflict in decode_round.zig. My scratch resolution kept main's page-promise, grow and release helpers. For reset, it propagates SenseNova's pending keep error before calling main's page-reset helper.

zig build test-sensenova-loop-config-host test-qwen27 test-qwen27-reply-cache-host test-qwen27-startup-host test-kv-pool test-prefill-service-host tf-qwen27-pages-resume -Dcpu=apple_m1 -Dversion=0.0.0 -j3 --summary all
./zig-out/bin/tf-qwen27-pages-resume

351 tests passed with three skips. The synthetic resume run matched the restored, moved and fresh slot digests. These checks are on the scratch resolution.

Igor Lessio - AIFLOW LABS

ashhart pushed a commit to gilby/TensorFold that referenced this pull request Nov 21, 2026
The net change of ashhart#3859 at c07419f over its merge base 6858510,
carried as one commit because four of the branch's merge commits hold changes of their own.
@ashhart
ashhart force-pushed the sensenova-loop-metal branch from 5c61232 to cd8f3ea Compare November 21, 2026 11:29
gilby added a commit to gilby/TensorFold that referenced this pull request Nov 21, 2026
@gilby

gilby commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor Author

Fast-forward commit b61c6f90b3 (residency_owner_tests: export sensenova_loop for #3859) adds pub const sensenova_loop to zig/residency_owner_tests.zig to fix test-metal-residency-owners-host compilation, while preserving @ashhart's commits on 1b394565cc.

Local verification on b61c6f90b3:

  • Targeted macOS host, golden, qwen27, kernel-contract, serving-host, and dev-tools checks passed (test-metal-residency-owners-host compiled and passed).
  • python3 tools/zig/lean_check.py: 7380 files, 167 problems.
  • Trial git merge-tree against current main (127230b4b0): zero source/code conflicts (zig/* auto-merges cleanly); only docs/optimization-ledger.md has a changelog/table conflict.

CI status for b61c6f90b3:

ashhart pushed a commit to Maxrio9/TensorFold that referenced this pull request Nov 21, 2026
…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.
ashhart pushed a commit to gilby/TensorFold that referenced this pull request Nov 21, 2026
The net change of ashhart#3859 at c07419f over its merge base 6858510,
carried as one commit because four of the branch's merge commits hold changes of their own.
ashhart pushed a commit to gilby/TensorFold that referenced this pull request Nov 21, 2026
ashhart pushed a commit to gilby/TensorFold that referenced this pull request Nov 21, 2026
The net change of ashhart#3859 at c07419f over its merge base 6858510,
carried as one commit because four of the branch's merge commits hold changes of their own.
ashhart pushed a commit to gilby/TensorFold that referenced this pull request Nov 21, 2026
@AIFlowML

Copy link
Copy Markdown
Contributor

On main 308d5e1fd, the published tip b61c6f90b conflicts in four paths: the optimization ledger, Qwen27 decode round and forward, and the native Metal adapter.

There is an independently testable parent slice at e44562a32 in the #4415 stack. That slice ends with this PR's residency-test export and precedes the MTP and MLX-affine changes. It trial-merged cleanly into the same main. On M5 Max, zig build test-sensenova-loop-config-host test-qwen27 test-metal-residency-owners-host -Dcpu=apple_m1 -j4 --summary all passed 56/56 steps, with 284 tests passed, five skipped and no failures. git diff --cached --check passed.

That slice gives a tested route for updating the parent first. This run was scoped to family config and host residency, without a live checkpoint.

Igor Lessio - AIFLOW LABS

ashhart pushed a commit to gilby/TensorFold that referenced this pull request Nov 23, 2026
The net change of ashhart#3859 at c07419f over its merge base 6858510,
carried as one commit because four of the branch's merge commits hold changes of their own.
@ashhart

ashhart commented Nov 23, 2026

Copy link
Copy Markdown
Owner

Thanks @gilby for the native SenseNova-Loop work. Everything here is also in #3868, which extends a few of the same lines for MTP drafting, so I'm closing this one to keep the review going on #3868.

  • Synthena

@ashhart ashhart closed this Nov 23, 2026
ashhart pushed a commit to gilby/TensorFold that referenced this pull request Nov 23, 2026
The net change of ashhart#3859 at c07419f over its merge base 6858510,
carried as one commit because four of the branch's merge commits hold changes of their own.
ashhart pushed a commit to gilby/TensorFold that referenced this pull request Nov 23, 2026
ashhart pushed a commit to gilby/TensorFold that referenced this pull request Nov 23, 2026
The net change of ashhart#3859 at c07419f over its merge base 6858510,
carried as one commit because four of the branch's merge commits hold changes of their own.
ashhart pushed a commit to gilby/TensorFold that referenced this pull request Nov 23, 2026
ashhart pushed a commit to Maxrio9/TensorFold that referenced this pull request Nov 24, 2026
…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.
ashhart pushed a commit to gilby/TensorFold that referenced this pull request Nov 24, 2026
The net change of ashhart#3859 at c07419f over its merge base 6858510,
carried as one commit because four of the branch's merge commits hold changes of their own.
ashhart pushed a commit to gilby/TensorFold that referenced this pull request Nov 24, 2026
ashhart pushed a commit to gilby/TensorFold that referenced this pull request Nov 24, 2026
The net change of ashhart#3859 at c07419f over its merge base 6858510,
carried as one commit because four of the branch's merge commits hold changes of their own.
ashhart pushed a commit to gilby/TensorFold that referenced this pull request Nov 24, 2026
The net change of ashhart#3859 at c07419f over its merge base 6858510,
carried as one commit because four of the branch's merge commits hold changes of their own.
ashhart pushed a commit to gilby/TensorFold that referenced this pull request Nov 24, 2026
ashhart pushed a commit to gilby/TensorFold that referenced this pull request Nov 24, 2026
The net change of ashhart#3859 at c07419f over its merge base 6858510,
carried as one commit because four of the branch's merge commits hold changes of their own.
ashhart pushed a commit to gilby/TensorFold that referenced this pull request Nov 24, 2026
The net change of ashhart#3859 at c07419f over its merge base 6858510,
carried as one commit because four of the branch's merge commits hold changes of their own.
ashhart pushed a commit to gilby/TensorFold that referenced this pull request Nov 24, 2026
ashhart pushed a commit to gilby/TensorFold that referenced this pull request Nov 24, 2026
The net change of ashhart#3859 at c07419f over its merge base 6858510,
carried as one commit because four of the branch's merge commits hold changes of their own.
ashhart pushed a commit to gilby/TensorFold that referenced this pull request Nov 24, 2026
The net change of ashhart#3859 at c07419f over its merge base 6858510,
carried as one commit because four of the branch's merge commits hold changes of their own.
ashhart pushed a commit to gilby/TensorFold that referenced this pull request Nov 24, 2026
ashhart pushed a commit to gilby/TensorFold that referenced this pull request Nov 24, 2026
The net change of ashhart#3859 at c07419f over its merge base 6858510,
carried as one commit because four of the branch's merge commits hold changes of their own.
ashhart pushed a commit to gilby/TensorFold that referenced this pull request Nov 25, 2026
The net change of ashhart#3859 at c07419f over its merge base 6858510,
carried as one commit because four of the branch's merge commits hold changes of their own.
ashhart pushed a commit to gilby/TensorFold that referenced this pull request Nov 25, 2026
ashhart pushed a commit to gilby/TensorFold that referenced this pull request Nov 25, 2026
The net change of ashhart#3859 at c07419f over its merge base 6858510,
carried as one commit because four of the branch's merge commits hold changes of their own.
ashhart pushed a commit to gilby/TensorFold that referenced this pull request Nov 25, 2026
The net change of ashhart#3859 at c07419f over its merge base 6858510,
carried as one commit because four of the branch's merge commits hold changes of their own.
ashhart pushed a commit to gilby/TensorFold that referenced this pull request Nov 25, 2026
ashhart pushed a commit to gilby/TensorFold that referenced this pull request Nov 25, 2026
The net change of ashhart#3859 at c07419f over its merge base 6858510,
carried as one commit because four of the branch's merge commits hold changes of their own.
ashhart pushed a commit that referenced this pull request Nov 25, 2026
The net change of #3859 at c07419f over its merge base 6858510,
carried as one commit because four of the branch's merge commits hold changes of their own.
ashhart pushed a commit that referenced this pull request Nov 25, 2026
The net change of #3859 at c07419f over its merge base 6858510,
carried as one commit because four of the branch's merge commits hold changes of their own.
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.

3 participants