Repository navigation
Runtime support for Prism Bonsai 2 27B - #29600
Conversation
0b42fe1 to
fc50db4
Compare
|
Yes. I also checked runtime correctness against the PrismML fork on the same Q2_0 model (wikitext-2, 16 chunks, ctx 512):
Greedy generation is coherent on both backends. |
|
Did some minor testing and it looks good. Sadly it does not quiet fit into my 8gig of vram.
edit: Turns out my cpu is slow slow. |
We have a different quantization format on our fork (ternary packing w/ group size 128) that is more low vram friendly (5.9 GB as opposed to 7.2) but didn't want to shove that into this PR. Happy to do that as follow up but wanted to get functional correctness in first. |
|
Tested on Vulkan (AMD Radeon 860M, RDNA 3.5 iGPU, Windows, 64 GB UMA) with wikitext-2,
Master without this PR: PPL ~1.02M on the same file. The PR matches the fork on CPU, and on Vulkan it is as close to the CPU reference as the fork's own Vulkan build. The remaining Vulkan-vs-Vulkan gap comes from the backends, not from this PR. One performance note, outside this PR's scope: this model uses 1024-wide Hadamard blocks, but the Vulkan (and CUDA) FWHT kernels on master stop at 512. The rotation therefore falls back to a dense f32 matmul, about 14 % of prompt processing time here. Porting the fork's wider Vulkan FWHT pipelines (up to 8192) gives, A/B on the same build: pp512 51 -> 56 t/s, pp2048 44 -> 48 t/s, tg 6.0 -> 6.6 t/s, with no KLD change. I can open that as a separate PR if useful. |
|
Thanks for the thorough Vulkan testing, that KLD table is exactly what was needed. We have the wider Vulkan FWHT (1024 to 8192) ready and will open it as a separate PR stacked on #29101 rather than have you duplicate it. It would be great if you could try it on the 860M once it's up. |
|
Tested on AMD Radeon 860M (RDNA 3.5 iGPU, Windows, AMD proprietary driver 25.20.24.17, Builds on the same master (f11d642): A = master + #29600, B = A + #29101 + #29772. Correctness ( Op perf (
Every width from 1024 to 8192 goes through the FWHT on this device despite the 32 KB of shared memory. 64 to 512 in F32 are unchanged here too. Bonsai 2 27B Q2_0 (
One B round was noisy on pp512 (57.8 ± 4.8), the other two were 67.2 and 66.4. KLD against the Prism fork's Vulkan build (wikitext-2,
No accuracy change beyond noise. This supersedes my own port of the wider kernels. |
|
Thanks, that is exactly the cross-vendor check #29772 needed. I'll reference these numbers from that PR. |
|
@CISC @ggerganov this is the runtime side you asked us to upstream, ready for review when you have a moment. Two independent Vulkan and CUDA checks against the fork are in the thread above, and #29672 and #29772 stack on it. |
|
@CISC could you also approve the workflow runs on this PR? CI has not run on the current head yet. |
|
@bri-prism I've just built this branch, added the fwht1024 support, fixed the tensor split mode and I get 39tps average on 2x 5060TI, 1100-1900 tps for pp. (Full 262144 context, 22K prompt full of skills/tools) This is really impressive given that this branch, stock, using split layer I only get 23tps average Thank you so much for this implementation, there's a lot of ground still evidentally for optimisations, but wow, once it has them this has to be the best Qwen 3.8 27b variant for performance. If you get chance, can you try a higher quant variant, I still have around 7GB free across the two GPUs 😂 |
|
@KodeMunkie Thanks for testing this. The wider CUDA FWHT is in #29100, and could you share what you changed for tensor split? I suspect the rotation tensors are picking up the split buffer type from their weights. |
Of course, I've attached patches on the master build it applied to. These should be done in sequence, starting at this PR. The patches are vibe coded as I don't understand the theory well enough. Note, anecdotally I am seeing a change in the language e.g. instead of "How are you this evening?" it asks "How are you, in the evening?" which seems a bit odd. I see other odd phrasing too occasionally, so I assume something is not quite right but I can't tell conclusively (I've just been wanting this build to have my local AI be more performant, and any serious work it does is validated by a secondary Gemma 4 AI anyway). |
|
@KodeMunkie Thanks for the patches. -sm tensor aborts here without your 0002 and runs with it, and none of the three move the logits further from a CPU reference than stock does, so I don't think the odd phrasing comes from them. Could you share your KV cache and sampler settings so I can try to reproduce it? |
|
@bri-prism In which case I think it's just random behaviour, not an issue with this PR. The only reason I mentioned it was incase one of the 3 patches I provided in that zip affected the resulting logits through some bad ops, truncation, wrong types / type overflow I don't have access to my machine at the moment but will do in about an hour. I'll post a zip of my log asap. I have not changed any sampler settings from the what is built into the dev model, I've only set non sampling options such as Q8 k/v |
|
I pulled this PR myself and run some tests on is, as I am very curious about the Prism Bonsai support in Llama.cpp myself. I tried to follow the same methodology as @Tough-Respawn did. It seems this ist the first test on RDNA4 with RADV/Vulkan on Linux here (64kb shared memory). In my opinion this is very promising. I will run some quality based tests as well. Setup
Correctness (
|
| A | B | |
|---|---|---|
-o MUL_MAT_HADAMARD |
32/32 | 32/32 |
-o MUL_MAT |
1132/1132 | 1132/1132 |
KLD, wikitext-2, -c 512, 16 chunks, reference = fork on CPU (-dev none, PPL 10.2709 +/- 0.4368)
| run | mean KLD | same top p | PPL ratio |
|---|---|---|---|
| A, CPU | 0.000190 | 99.44 % | 1.0005 |
| A, Vulkan | 0.001111 | 97.87 % | 1.0021 |
| B, Vulkan | 0.001122 | 97.94 % | 1.0014 |
| fork, Vulkan | 0.001065 | 98.19 % | 1.0017 |
The PR on CPU gives practically the same output as the fork on CPU, and on Vulkan it is as close to the CPU reference as the fork's own Vulkan build.
Op perf (test-backend-ops perf -b Vulkan0 -o MUL_MAT_HADAMARD, n=2048 rows, us/run, two interleaved runs averaged; cases above 512 added locally)
| width | F32 A | F32 B | F16 A | F16 B |
|---|---|---|---|---|
| 512 | 11 | 11 | 34 | 12 |
| 1024 | 100 | 22 | 100 | 23 |
| 2048 | 436 | 67 | 391 | 73 |
| 4096 | 1741 | 197 | 1620 | 196 |
| 8192 | 8777 | 897 | 8511 | 911 |
With #29101 + #29772, the transform is 4.5x faster than A at width 1024 and about 10x at 8192.
llama-bench (-ngl 99 -p 512 -n 128 -r 3)
| pp512 | tg128 | |
|---|---|---|
| A | 679.81 +/- 0.44 | 39.95 +/- 0.08 |
| B | 726.17 +/- 0.54 | 42.01 +/- 0.07 |
Commands
llama-perplexity -m $M -f wiki.test.raw -c 512 --chunks 16 -dev none --kl-divergence-base fork-cpu.kld # fork
llama-perplexity -m $M -f wiki.test.raw -c 512 --chunks 16 [-dev none | -ngl 99] --kl-divergence-base fork-cpu.kld --kl-divergence
test-backend-ops -b Vulkan0 -o MUL_MAT_HADAMARD
test-backend-ops -b Vulkan0 -o MUL_MAT
test-backend-ops perf -b Vulkan0 -o MUL_MAT_HADAMARD
llama-bench -m $M -ngl 99 -p 512 -n 128 -r 3
|
@KodeMunkie Thanks for the settings. Agreed it looks like normal sampling variance, but feel free to post the logs if it keeps happening. |
|
@mjechow Thanks for the RDNA4 run, good to have RADV on Linux covered alongside the Windows results. Looking forward to the quality tests. |
|
Here the summary of the quality tests I made. I compared to Qwen3.8-27B UD-IQ4_XS, as this is my goto model.
|
|
@bri-prism sorry I've been away this weekend, I'll try and get a copy of the logs tomorrow. |
Automated code reviewReviewI reviewed the diff (conversion + runtime + gguf-py + arch tables) and the surrounding code ( Correctness issues to address(point 1) LoRA is silently wrong on a folded model. In (point 2) Conversion validates manifest names against the name mapping, not against the tensors actually written ( Will slow the review(point 3) (point 4) (point 5) Duplicate sign widths silently overwrite: Nits(point 6) Missing blank line between (point 7) In (point 8) The brace-less nested Notes(point 9) No in-tree test covers the runtime path; correctness rests on the community KLD runs in the thread (CPU/CUDA/Metal/Vulkan), which look thorough. Given no small public folded GGUF exists, that is understandable, but a synthetic minimal GGUF fixture for the metadata-validation paths would be a good follow-up. Otherwise the change is well scoped (no ggml backend changes here, those landed separately), ASCII-clean, disclosure is filled in, and errors are actionable throws rather than asserts. The main ask before merge is (point 1). This review was generated automatically by pi coding agent using |
|
Address bot points 1-8 please. |
Assisted-by: Claude Code
|
Addressed bot feedback @CISC |
This comment was marked as spam.
This comment was marked as spam.
Tensor split aborted on qwen35 models with folded Hadamard rotations at ggml-backend-meta.cpp:1086 (split_state.ne[j] % div == 0): the rotation reshape tiles the activation feature axis, and the meta backend had no split state for it. - llama_mul_mat_hadamard reshapes to 4D [n, ne0/n, ne1, ne2*ne3] so the split axis survives the rotation, and asserts ne0 % n == 0. - Split blocks for Hadamard-rotated weights use lcm(type block, rotation block) so shards never cut a rotation block. - ssm_out uses a value_dim split when GDN V is grouped, and views of the GATED_DELTA_NET output carry the matching axis-1 split. - Elementwise MUL/ADD/SUB/DIV of a feature-sharded activation with a full-width mirrored operand slices the operand per shard (ADD_ID is excluded). Split rules by Benjamin Brown (@KodeMunkie), posted on ggml-org#29600; ADD_ID guard added here. Tested on 2x H200: Bonsai 2 27B PQ2_0 and Q2_0 now run under -sm tensor with mean KLD 2.5e-4 vs single GPU (top-1 99.3%). Single-GPU CUDA output and Qwen3-4B / Qwen3.5-4B results (single and tensor) are bit-identical to the base commit.
v0.7.0 has Prism's Hadamard runtime (ggml-org/llama.cpp#29600), so Bonsai 2 27B runs from upstream once its PQ2_0 blocks are split into Q2_0's 64-weight groups: scripts/pq2-to-q2_0.py does that losslessly. The PS5 patches apply as they are. The library gets a Bonsai preset with Prism's sampling; the planner gives it 64k with a q8_0 cache.
* Runtime support for Prism Bonsai 2 27B Assisted-by: Claude Code * address prism hadamard runtime feedback * move hadamard tensors into method, define folded weight * load_* hadamard fixes * cont : clean-up * conversion cleanup Assisted-by: Claude Code * prism hadamard key and methods for converter Assisted-by: Claude Code * address review bot feedback Assisted-by: Claude Code --------- Co-authored-by: Georgi Gerganov <[email protected]>
* Runtime support for Prism Bonsai 2 27B Assisted-by: Claude Code * address prism hadamard runtime feedback * move hadamard tensors into method, define folded weight * load_* hadamard fixes * cont : clean-up * conversion cleanup Assisted-by: Claude Code * prism hadamard key and methods for converter Assisted-by: Claude Code * address review bot feedback Assisted-by: Claude Code --------- Co-authored-by: Georgi Gerganov <[email protected]>
Brings the fork up to ggml-org master as of 2026-10-11, including the upstream Prism Hadamard folded runtime (ggml-org#29600). The fork's own Hadamard runtime is replaced by upstream's; fork-only pieces (target transforms for drafters that borrow the target head and embeddings, DSpark head borrowing) are re-applied on top. Speculative decoding moves to upstream's batch API and fused DFlash encoder, with the fork's DSpark, prompt lookup, beam selection and MTP deferred catch-up ported over. No fork kernels were dropped.
…-org#363) Tensor split aborted on qwen35 models with folded Hadamard rotations at ggml-backend-meta.cpp:1086 (split_state.ne[j] % div == 0): the rotation reshape tiles the activation feature axis, and the meta backend had no split state for it. - llama_mul_mat_hadamard reshapes to 4D [n, ne0/n, ne1, ne2*ne3] so the split axis survives the rotation, and asserts ne0 % n == 0. - Split blocks for Hadamard-rotated weights use lcm(type block, rotation block) so shards never cut a rotation block. - ssm_out uses a value_dim split when GDN V is grouped, and views of the GATED_DELTA_NET output carry the matching axis-1 split. - Elementwise MUL/ADD/SUB/DIV of a feature-sharded activation with a full-width mirrored operand slices the operand per shard (ADD_ID is excluded). Split rules by Benjamin Brown (@KodeMunkie), posted on ggml-org#29600; ADD_ID guard added here. Tested on 2x H200: Bonsai 2 27B PQ2_0 and Q2_0 now run under -sm tensor with mean KLD 2.5e-4 vs single GPU (top-1 99.3%). Single-GPU CUDA output and Qwen3-4B / Qwen3.5-4B results (single and tensor) are bit-identical to the base commit. (cherry picked from commit 71c1473)
…build_lora_mm_id) Ported from agentionai/llama.cpp 79481152a onto upstream's prism.hadamard runtime (ggml-org#29600), which our tree already carries; their runtime port d20ffeafc is therefore not needed.
The fork's MoE cache (the next commits) looks the selected experts up on the device, replays hits and fills into its policy on the host after the batch, streams prompt experts through a ring, prefetches the next layer and computes missed experts on a host thread pool (--moe-cpu-experts). Upstream's cache plans each layer in the scheduler's copy callback after a host synchronization, which the fork's device lookup replaced. Reverts the llama-level parts of: - c4fb579 moe-cache : LRFU/MQ-like hybrid cache, ClassLRU (ggml-org#31233) - e95426f llama_moe_cache: run missed experts on CPU, add tuning script (ggml-org#30966) - cf34d31 moe-cache : ensure CPU part does not wait for the cached experts (ggml-org#31888) - 951d465 llama: move moe-cache code out of llama-graph (ggml-org#32157) Kept: the scheduler's input prefetch and the CPU MUL_MAT_ID skip of negative ids (ggml), and the later upstream fixes in the graph code (ggml-org#32100 cache device check, ggml-org#29600 Hadamard-folded experts).
Bring the ToshLLM AMD Metal fork up to date with upstream: macpro71 was 5 commits ahead / 1475 behind. This is a merge (the branch's established workflow), not a rebase, so published history is preserved. Resolution policy ================== - ggml/src/ggml-metal/** kept verbatim from macpro71 (06290d0). Only the glue needed by upstream's evolved backend ABI was adapted: * added .alloc_buffer_n / .get_alloc_size_n (nullptr = defaults) to the three ggml_backend_buffer_type initializers * exported ggml_backend_meta_pass_counter() (hidden visibility upstream) - Upstream non-Metal changes adopted wholesale. Upstream independently landed evolved versions of the branch's Prism Hadamard support ("Prism Bonsai 2 27B", ggml-org#29600) and Qwen4Exp MTP (ggml-org#29761), using the same prism.hadamard.* metadata keys. The branch's earlier iterations of both were dropped in favour of upstream's, including its loader, graph helpers and LLM_ARCH_QWEN4EXP capability tweak. - Branch-unique features re-applied on top: * TurboQuant: TURBO2_0/3_0/4_0, TQ3_1S/TQ4_1S and Prism PQ2_0/PTQ1_0 types, GGML_OP_TURBO_WHT, turbo quants/kernels, ftypes, tests. Type ids renumbered after upstream claimed 43 for f8_e4m3 (turbo 44..48; PQ2/PTQ1 keep 142/143, the published-GGUF ids). * tosh-moe dynamic expert cache hooks (model, loader, graph, server, bench, CMake TOSH_ENABLE_DYNAMIC_MOE, off by default). * AMD heuristics in the attention builder (TOSH_FA_AMD decomposed prefill, wave widths) merged with upstream's new kv_rows path: kv_rows retains flash attention. * tensor-parallel grouping: llama_model::tensor_group_size and get_split_state_uds (+ dev_offset so each group reads its own slice of --tensor-split). * DeepSeek-V4 KV cache kept in host memory on AMD Metal (upstream's SET_ROWS GPU writes hang the queue), TOSH_MIRROR_OUTPUT_HEAD. * README AMD section, docs, NOTICE, GPL-3.0 text. - Backend safety against upstream features the verbatim kernels lack: decline instead of crashing, so the scheduler falls back to CPU: f8_e4m3 and nvfp4 tensors, flash attention with kv_rows, matmul with non-f32 activations, and type-accurate gates for rope (f16/f32), soft_max (f16/f32), norm/rms_norm/sum/reductions/argmax (f32), repeat/tri/conv_transpose_1d. - tests/CMakeLists.txt: skip upstream's test-metal-graph-optimize when ggml-metal-fusion.cpp is absent (this backend has no fusion pass). test-quantize-fns: give PQ2_0/PTQ1_0 the ternary error thresholds (2-bit codecs; the generic threshold was never meant for them). Verification ============ - clean full build (Release, Metal + embedded libraries, tests/server) - llama-cli generation on the Vega II via the AMD path (TOSH_FA_AMD=1) produces correct text - ctest: test-turbo-quant and test-quantize-fns pass - test-backend-ops -b MTL0: ADD, GATED_DELTA_NET, MUL_MAT (2385/2385) and FLASH_ATTN_EXT with TOSH_FA_AMD=1 (1829/1829) pass; GET_ROWS/SET_ROWS/ CPY/CONT/SCALE/UNARY/etc. pass 1683/1704. Known limitations (fork kernels vs. newer upstream tests, not merge conflicts) ===================================================================== - MUL_MAT_ID fails numerically for large batches with duplicated expert ids (upstream's dup=1 cases, n=33/64) and aborts for n_mats > 1024 (map0 threadgroup limit); real MoE workloads are far below these. - ROPE output differs from the updated CPU reference for extreme freq_scale (1/256) + n_ctx_orig (YARN) parameter sets; default rope is correct. Op-param layout itself matches upstream. - One CPY case with a permuted destination fails.
…-org#363) Tensor split aborted on qwen35 models with folded Hadamard rotations at ggml-backend-meta.cpp:1086 (split_state.ne[j] % div == 0): the rotation reshape tiles the activation feature axis, and the meta backend had no split state for it. - llama_mul_mat_hadamard reshapes to 4D [n, ne0/n, ne1, ne2*ne3] so the split axis survives the rotation, and asserts ne0 % n == 0. - Split blocks for Hadamard-rotated weights use lcm(type block, rotation block) so shards never cut a rotation block. - ssm_out uses a value_dim split when GDN V is grouped, and views of the GATED_DELTA_NET output carry the matching axis-1 split. - Elementwise MUL/ADD/SUB/DIV of a feature-sharded activation with a full-width mirrored operand slices the operand per shard (ADD_ID is excluded). Split rules by Benjamin Brown (@KodeMunkie), posted on ggml-org#29600; ADD_ID guard added here. Tested on 2x H200: Bonsai 2 27B PQ2_0 and Q2_0 now run under -sm tensor with mean KLD 2.5e-4 vs single GPU (top-1 99.3%). Single-GPU CUDA output and Qwen3-4B / Qwen3.5-4B results (single and tensor) are bit-identical to the base commit. (cherry picked from commit 71c1473)
Third procedural failure, found while checking the end state: replay.txt held the 32-step token list instead of 25358 11 198 760. The scripts ran cp \/replay4.bak \# Phase 65 - 測定フェーズ(cap統制・NGL再掃引・Bonsai Q2_0) 対象: 2026-11-27 01:11 〜 作業 worktree: `D:\ghq\github.com\yuubinnkyoku\llama.cpp-c51` ブランチ: `codex/c65-tuning`(`aca91523b8f52813d35106b5a666ce70640aa14f` から作成) push 許可: `codex/c65-tuning` のみ ビルドディレクトリ: `build/c63-test`(fork、hexagon=ON)、 `D:\ghq\github.com\yuubinnkyoku\llama-upstream-c63\build\c65-upcli`(**上流 master**、hexagon=ON)。 --- ## §0 目標0: ゲート - **PASS** | 項目 | 値 | | --- | --- | | 接続 | `192.168.55.15:5555`(再接続で復帰。`100.108.106.81:38769` でも到達可) | | serial / model | `324753221196` / `NX741J` | | **uptime** | 348,116 s(Phase 64 終了時 281,608 s から単調増加 = **再起動なし**) | | **cap0 / tz0(開始時)** | **1,785,600 / 53.0 ℃**(低 cap、温まり気味) | | MemAvailable / SwapFree | 5,610,508 kB / 5,485,772 kB | ### §0.1 unit stage | モード | PASS | FAIL | | --- | --- | --- | | 通常 | **15/15** | **0** | | `--fuzz` | **88/88** | **0** | ### §0.2 基準 hash(標準組) 標準組 = CPU `abecaf60`(dotprod+i8mm)・skel `312ad7b7`・hexagon `9c9bfc48`・base `d950aa96`。 | NGL | sha256(logits.f32) | 既知値 | 判定 | | --- | --- | --- | --- | | 44 | `e788051e16d7e1e63b140a902418c75f779bfe29cfb320bb054598508b09d4eb` | 同左 | **一致** | | 0 | `ede05813034c131e8ecadcb2ecb3eb34e8bf291f0b9ebb49bd7a5541ca97d9e9` | 同左 | **一致** | ### §0.3 `sdot` カウント(恒久規則) `libggml-cpu.so`(`abecaf60`)= **1,376 sdot**(Phase 64 の値と一致)。 上流ビルド(`c65-upcli` の `libggml-cpu.so`)= **1,120 sdot**(0 ではない)。 どちらも 0 でないことを確認した。 --- ## §1 目標3: Bonsai 2.5 27B Q2_0 evidence - **完了(決定的な結果)** 3フェーズ連続で繰り越されていた項目。**結論: fork では「警告なしにゴミを出す」を実測で確認。上流では CPU は正常、HTP はロード時に異常終了。** ### §1.1 下調べ(端末不要・最初に実施) #### (a) fork が持っているもの / 持っていないもの | 要素 | fork | 上流 master | | --- | --- | --- | | `GGML_TYPE_Q2_0`(型 42) | **あり** | あり | | `GGML_TYPE_Q1_0`(型 41) | **あり** | あり | | `ggml_compute_forward_fwht`(CPU FWHT カーネル) | **あり**(`ggml-cpu.c` / `ops.cpp`) | あり | | `GGML_HINT_SRC0_IS_HADAMARD` | **あり** | あり | | `ggml_vec_dot_q2_0_q8_0` | **あり** | あり | | **`LLM_KV_PRISM_HADAMARD_*`(モデル側の結線)** | **0 件(無い)** | あり | | `llama_verify_hadamard_graph` | **無い** | あり | **つまり fork は「カーネルは持っているが、モデル側で Hadamard を適用する配線が無い」。** 上流の `a9d27ac69`(ggml-org#29600, Prism Bonsai 2 27B 対応)が入っていないため。 (この commit は上流 master では rebase されて別 SHA になっているが、`src/llama-arch.h` に `LLM_KV_PRISM_HADAMARD_VERSION` 等が存在することで内容の取り込みを確認した。) 上流のコードには次のコメントがある: ``` // without this check, an arch that skips the transform helpers loads and computes wrong results ``` **警告なしにゴミを出す、と上流自身が明記している。** #### (b) PrismML 自身の記述(HF の `presets/llama.cpp/mtp-hexagon.json` より) ```json "released_build": null, "released_build_note": "No public build runs this model correctly on the Hexagon NPU yet; it needs a fix that is not released." "runtime_note": "The whole model runs on the NPU over four sessions (embedding, 64 layers, draft head, output layer); only sampling runs on the CPU. Without the fix the output is wrong." ``` **「修正なしでは出力が間違っている」とベンダーが明言している。** 指示が警告していた「warningなしにゴミを出す」リスクは、**ベンダーの文書で裏付けられた。** ### §1.2 モデルの入手 | 項目 | 値 | | --- | --- | | リポジトリ | `prism-ml/Ternary-Bonsai-2.5-27B-GGUF`(公開、apache-2.0) | | ファイル | `Ternary-Bonsai-2.5-27B-Q2_0.gguf` | | サイズ | **7,673,194,848 B(7.15 GiB)** | | sha256 | `84496171ca79d4d33fb45612a2afd8303ec494baf916281023b7dc9cb3b3b9fa` | | 取得方法 | PC で curl(約 95 秒)→ sha256 照合 → adb push(722 秒)→ 端末側で **sha256 再照合一致** | **注意**: 端末の空きが 1.9 GB しか無かったため、`runs/` 配下の古い `logits.f32` (968 個、約 9 GB)を削除して 10 GB を確保した。**直近 42 個(Phase 64 の分)は保持。** MTP 版(`-mtp.gguf`、7.37 GB)は**非公開リポジトリ**(`...-gguf-mtp`、カードに 「Private, unreleased model ... do not redistribute」)なので取得していない。 ### §1.3 測定結果(4 通り) 同一モデル・同一端末で、ビルドだけを変えた。 | # | ビルド | 実行 | 結果 | 出力 | | --- | --- | --- | --- | --- | | 1 | **fork** `cli63`(b11708-d0829bf57) | CPU(`-ngl 0`) | **ロード成功・エラーなし** | **`ỉ` / `essiutique柏emer`(ゴミ)** | | 2 | **上流 master** `cli65`(fa9f928) | CPU(`--device none`) | ロード成功 | **`The user's message is just "The`(正常)** | | 3 | 上流 master | HTP `-ngl 99` | **rc 134(SIGABRT)で異常終了** | `dspqueue_read failed: 0x0000002e` | | 4 | 上流 master | HTP `-ngl 8` / `-ngl 20` | **どちらも rc 134** | 同上 | #### (1) fork は「無警告でゴミ」 ``` ftype : Q2_0 modalities : text > The [Start thinking] essiutique柏emer ``` **`ftype Q2_0` と正しく認識し、警告もエラーも出さず、無意味な文字列を生成する。** 指示が警告した通りの挙動である。**Hadamard 変換が適用されていないことの直接的証拠。** #### (2) 上流の CPU は正常 ``` ftype : Q2_0 modalities : text > The [Start thinking] The user's message is just "The [ Prompt: 1.9 t/s | Generation: 1.6 t/s ] ``` **同じモデル・同じ端末で、上流は意味の通る続きを生成する。** 差分はビルドだけ(fork に `ggml-org#29600` が無い)なので、**原因は Hadamard の配線**と確定できる。 **CPU のみの速度: prefill 1.9 t/s、decode 1.6 t/s**(`-c 256`、6 スレッド)。 参考として fork の(ゴミを出す)CPU 実行は 1.4 / 1.2 t/s だった。 #### (3)(4) 上流の HTP は**ロード時に落ちる** ``` ggml-hexagon.cpp:1889: ggml-hex: dspqueue_read failed: 0x0000002e ggml_abort ``` `-ngl 99`(全層)、`-ngl 20`、`-ngl 8` の**すべてで同じ箇所で rc 134**。 層数を減らしても変わらないので、**メモリ量の問題ではなく、このモデルの 重み repack 段階で DSP 側が失敗している**と判断できる。 **したがって graph splits は取得できていない(`splits=0`、計測不能)。** これは測定失敗ではなく、**「この状態では HTP で走らない」という結果そのもの**である。 ### §1.4 GSQ-RCO(現行 27B)との対比 | 項目 | GSQ-RCO IQ2_S(現行) | **Bonsai 2.5 Q2_0(今回)** | | --- | --- | --- | | サイズ | 9.26 GB | **7.15 GB**(77%) | | 型 | IQ2_S/IQ3_S/IQ3_XXS/IQ2_XXS/IQ2_XS + Q2_K 等 | **Q2_0 / Q1_0**(ternary) | | **fork での HTP** | **splits 1(全面オフロード、品質ゲート済み)** | **ロード可・出力はゴミ** | | 上流での HTP | splits 262(型の大半が CPU フォールバック) | **ロード時に異常終了** | | 上流での CPU | 測定対象外 | 1.9 t/s prefill / 1.6 t/s decode(正常出力) | | 速度の比較 | prefill 128 で 27-38 秒(Phase 64 実測) | HTP で走らないため比較不能 | **構造差の読み方**: GSQ は「fork が型を足したので全面 NPU で速い」。 Bonsai は「上流が型(Q2_0)を持っているが、**NPU 側の修正が未リリース**なので上流でも走らない」。 **fork は Hadamard の配線が無いので、そもそも正しい計算ができない。** **どちらの経路も現時点では実用にならない。** ### §1.5 採用判断に必要な材料(まとめ) 1. **fork で Bonsai を使うには `ggml-org#29600`(モデル側 Hadamard 配線)の取り込みが必須。** 3 ファイル競合(`gguf_writer.py` / `llama-graph.cpp` / `llama-model.h`)で、 core 側の変更なので hexagon の積み上げとは別系統。**未実施**。 2. **`ggml-org#29600` を入れても HTP では走らない可能性が高い**(上流 master で既に rc 134)。 ベンダーが「未リリースの修正が必要」と明言しており、**その修正の入手が前提**。 3. **CPU のみなら上流で動く**(1.9 / 1.6 t/s)。ただし 27B を CPU だけで回すのは 実用速度ではない。 4. **品質ゲート(hash/NLL)は別モデルなので使えない。** 今回の evidence は「ロード可否・出力の妥当性・splits・速度・メモリ」に限る。 **推奨: 現時点では採用しない。** ベンダーの Hexagon fix がリリースされ、 かつ fork に `ggml-org#29600` 相当を取り込めた時点で再評価する。 **「fork に Hadamard 配線を足せば動く」という単純な話ではない**ことを今回の 4 通りの測定が示している。 --- ## §2 目標4: 小刻み follow ### §2.1 `ceefd16da` / `27c7a769d` - **既に着地済み** 指示は「競合ゼロで適用済み・未コミットの 2 件を commit して着地」だったが、 **Phase 64 で既にコミット済み**であることを確認した: - `ac99cebf3 hexagon: take the HMX FA sink fix (ggml-org#30581) and HVX softplus (ggml-org#30435)` - `ceefd16da` と `27c7a769d` を 1 コミットにまとめたもの。`in_HEAD=True`。 - 品質は Phase 64 §18 で検証済み(64-step argmax 64/64、d_nll +0.0012、t=+0.51)。 **追加作業なし。** ### §2.2 上流の型対応 - **IQ2_XXS のみ追加されていた** 指示の「型対応(IQ2/IQ3/XS系)が入っていたら evidence 第2測定点を即実施」を判定するため、 上流 master(`fa9f928`)の tiled 型表を確認した: ``` Q1_0, Q2_0, Q4_0, Q4_1, Q5_0, Q5_1, MXFP4, IQ4_NL, NVFP4, IQ2_XXS, Q8_0, Q6_K, Q2_K, Q3_K, Q4_K, Q5_K, F16, F32, BF16 ``` **IQ2_XXS が追加されている。** ただし: - **`IQ2_XS` / `IQ2_S` / `IQ3_XXS` / `IQ3_S` / `IQ4_XS` は依然として無い。** - 27B の構成は IQ3_XXS 82・IQ3_S 64・IQ2_S 62・IQ2_XXS 59・IQ2_XS 46(Phase 64 §15 実測)。 - したがって **上流が tiled で扱える IQ 系は 59 テンソル分だけで、 残り 254 テンソルは CPU フォールバックのまま。** **`htp-repack.h` は `3090e45` 以降変更されていない**(`git log -- htp-repack.h` が 1 件のみ)。 Phase 63 の evidence 測定(splits 262)は `3090e45` で取っているので、 **IQ2_XXS の追加はその測定に既に反映されている。** **結論: 「大きく動いた」とは言えないため、第2測定点の再測定は不要と判断した。** 根拠: 型表が測定点から変わっておらず、変わり得た IQ 系のうち追加されたのは 1 型(59 テンソル)のみ。splits 262 の主因である IQ3_XXS/IQ3_S/IQ2_S は未対応のまま。 **ただし Phase 65 で上流 CLI ビルド(`cli65`)を用意したので、 IQ3 系が入った時点で即測れる状態にはなった。** ### §2.3 ggml-org#31055(KV-head team split)- **未実施** Phase 64 §18.2 で `kv_head_min` / `kv_head_max` を全範囲宣言にして ggml-org#30731 のループを成立させた。**ggml-org#31055 でその宣言を本物のチーム分割に置き換える作業**は 今回は行っていない。理由: 目標1(残置バッチの ABBA)と目標3(Bonsai)を優先したため。 **未実施であることを明記する。** --- ## §3 目標5-1: `build/c59-cpu` の dotprod 確認 - **完了(1 コマンド)** Phase 64 §22.8 の仮説「Phase 59 の『dotprod は 10-15% 遅い』も dotprod 喪失が原因では」 を検証した。 ``` build/c59-cpu/CMakeCache.txt GGML_CPU_ARM_ARCH:STRING=armv8.6-a+dotprod+i8mm ``` **dotprod は正しく入っていた。** したがって: - **Phase 59 の測定は正しい。** dotprod 喪失の産物ではない。 - Phase 59 が「dotprod は遅い」と結論したのは、**当時 ARM で tiled が無効だった**ため。 tiled が無い状態では dotprod は plain 経路にしか影響せず、そこで 10-15% 遅かった。 - **Phase 64 の発見(tiled は SDOT 必須、dotprod があると 3.5 倍速い)と矛盾しない。** 2 つは別の経路の話であり、両立する。 **説明が成立した。** Phase 59 の結論を訂正する必要はない。 --- ## §4 目標1: 残置バッチの ABBA - **測定完了、ただし証拠は弱い(正直に分ける)** Phase 64 で品質 PASS まで行った 2 バッチの速度判定。**判定を出す前に、 測定手順そのもので 1 回失敗した。経緯を残す。** ### §4.1 失敗 1: `WANT_SKEL` ガードで B 腕が全部走っていなかった 最初の ABBA(タグ `abba`、2 ラウンド)は**全 B 腕が rc 2 で拒否されていた**: ``` REFUSING: skel sha256 76b20839... != 312ad7b7... SPLIT_RUN rc 2 dir /data/local/tmp/c46-27b/runs/20261127-014329-10434/ ``` `p53_run.sh`(内部の `run53.sh`)は**インストール済み skel が既定の `WANT_SKEL` (`312ad7b7`)と違うと実行を拒否する**。Phase 63 で記録済みの罠だが、 スクリプト側で踏んだ。しかも私のスクリプトは `rc 2` を検出しても **中断せず、古い run ディレクトリの数値を報告していた**ため、 出力は「全 B 腕が A-512 と完全に同じ数値」という明白な異常になった。 **対策(2 つ)**: 1. `arm()` で skel の sha256 を控え、`pf()` に `WANT_SKEL=$CUR_SKEL` を渡す。 2. `rc != 0` なら `P65A_ABORT` を出して**即中断**(古い値を報告しない)。 **この失敗データは破棄した。** 対策後に B1 腕の単発スモークテストが 84.59 s で完走することを確認してから再測定した。 ### §4.2 測定(修正後、タグ `ab2` 2 ラウンド + `ab3` 1 ラウンド) 3 腕(cpu は全部 `abecaf60`): | 腕 | hexagon | skel | 品質 | | --- | --- | --- | --- | | **A(現標準)** | `9c9bfc48` | `312ad7b7` | 基準 | | **B1(q2_K/Ssm)** | `0b94938e` | `76b20839` | 64-step argmax 63/64、d_nll +0.0007 | | **B2(FA)** | `c9dadbde` | `cdc628a9` | 64-step argmax 64/64、d_nll +0.0012 | 各ラウンドで腕の順序を回し(A->B1->B2 / B1->B2->A / B2->A->B1)、 各腕 prefill 128 と 512 を 1 回ずつ。 ### §4.3 結果(cap を併記) **ラウンド 1(cap 1,555,200 で揃った唯一の組)**: | 腕 | nt | prefill_ms | cap0 | tz0 ℃ | | --- | --- | --- | --- | --- | | A | 128 | 49,477.64 | **1,670,400-1,670,400** | 53.8-63.4 | | A | 512 | 168,549.37 | 1,670,400-1,555,200 | 63.4-62.6 | | B1 | 128 | 51,786.28 | 1,555,200 | 62.6-63.0 | | B1 | 512 | **154,760.82** | 1,555,200 | 63.4-65.7 | | B2 | 128 | **46,863.26** | 1,555,200 | 65.3-63.4 | | B2 | 512 | **146,473.09** | 1,555,200 | 63.4-66.5 | **ラウンド 2(cap が 1,555,200 -> 1,113,600 に降下、途中で混在)**: | 腕 | nt | prefill_ms | cap0 | | --- | --- | --- | --- | | B1 | 128 | 55,878.49 | 1,555,200-1,113,600 | | B1 | 512 | 185,457.34 | 1,113,600-1,555,200 | | B2 | 128 | 60,546.95 | 1,555,200-1,113,600 | | B2 | 512 | 161,985.78 | 1,113,600 | | A | 128 | 58,791.88 | 1,113,600 | | A | 512 | 210,312.56 | 1,113,600 | ### §4.4 判定: **退行は無い。ただし「B2 が最良」とまでは言えない** ラウンド 1 の 512 トークンは 3 腕とも cap 1,555,200 で揃っている: | 腕 | 512 prefill_ms | A との比 | | --- | --- | --- | | A | 168,549.37(cap が 1,670,400 から降下中 = やや有利) | 1.000 | | B1 | 154,760.82 | **0.918(8.2% 速い)** | | B2 | 146,473.09 | **0.869(13.1% 速い)** | 128 トークンは A だけ cap が 1,670,400(1.074 倍)と有利だったので単純比較できない。 A を 1,555,200 に正規化すると 49,477.64 x 1.074 = 53,139。 それに対して B1 51,786(2.5% 速い)、B2 46,863(11.8% 速い)。 **したがって: 両バッチとも現標準に対して退行していない。B2(FA バッチ)が 最も速い可能性が高い。** **ただし証拠は弱い。** 理由を明示する: - **各セル n=1**(1 ラウンド 1 回)。ラウンド 2 は cap が降下中で使えない。 - 512 の A は cap 降下中なので正規化が粗い。 - `decode_ms` は 1,616-6,536 ms と暴れていて比較に使えない (decode probe は 4 forward のみで短すぎる)。 - **この端末は依然として cap が 1.1-1.8 GHz で動き、10-15% の差を 1 ラウンドでは確定できない**(Phase 64 §21.5 の教訓そのまま)。 ### §4.5 載せ替え判断: **見送り(品質は PASS だが速度の証拠が不足)** 指示は「退行がなければ一括で両バッチ載せ替えを検討」だったが、**見送る。** - **退行が無いことは示せた**(3 腕とも同方向、B 系が同等以上)。 - しかし**「B2 が 13% 速い」を確定するには n が足りない**。1 セル 1 回の 測定で標準を差し替えると、Phase 64 で 3 回訂正したのと同じ過ちを繰り返す。 - **品質は両方 PASS 済み**なので、載せ替えの障害は速度の証拠だけである。 **条件付き推奨**: 次フェーズで **cap 1,555,200 前後に揃った状態で各腕 3 回以上** 取れれば、B2(FA バッチ)を単独で載せ替える価値がある。 B1(q2_K)は 8% 程度で B2 より控えめなので、B2 を先に試すのが順序として良い。 ### §4.6 失敗 2: ラウンド 3 の A-128 が「古い値の再読」だった ラウンド 3(タグ `ab3`、cap が 1,113,600 で**全 run 安定**)を追加で取った。 ここで **2 つ目の手順不具合**が出た: | 腕 | nt | prefill_ms | cap0 | | --- | --- | --- | --- | | A | 128 | **210,312.56** | 1,113,600 | | A | 512 | 198,070.36 | 1,113,600 | | B1 | 128 | 62,519.84 | 1,113,600 | | B1 | 512 | **162,393.54** | 1,113,600 | | B2 | 128 | **53,478.04** | 1,113,600 | | B2 | 512 | 171,873.73 | 1,113,600 | **A-128 の 210,312.555389 は、ラウンド 2 の A-512 の値と完全に同一**である。 これは実測値ではなく**前の run のディレクトリを読んだもの**。 **原因**: `pf()` は `R=$(grep -oE "SPLIT_RUN rc [0-9]+ dir .*" $BASE/p53-$T.out | awk '{print $NF}')` で run ディレクトリを求めるが、`p53_run.sh` がログを書き終える前に読むと grep が空になり、フォールバックの `ls -td runs/*/ | head -1` が **直前に終わった run のディレクトリ**を返す。ラウンド先頭の run で起きやすい。 **対策(未実装・次フェーズ)**: ログの生成を待つ、または run 開始時刻より 新しいディレクトリだけを候補にする。あるいは `p53_run.sh` が stdout に `SPLIT_RUN ... dir` を出しているので、ログ経由でなく**標準出力から直接取る**。 **同一値の重複を機械的に検出するチェックも入れるべきである** (`prefill_ms` が既出値と一致したら警告)。今回は手で気づいた。 ### §4.7 修正後の判定 **使えるデータ(cap 1,113,600 で揃ったラウンド 3 の 5 本 + ラウンド 1 の 6 本)**: 512 トークン: | cap | A | B1 | B2 | | --- | --- | --- | --- | | 1,555,200(r1) | 168,549.37 | **154,760.82** | **146,473.09** | | 1,113,600(r3) | 198,070.36 | **162,393.54** | 171,873.73 | 128 トークン: | cap | A | B1 | B2 | | --- | --- | --- | --- | | 1,555,200(r1) | 49,477.64 @1,670,400 | 51,786.28 | **46,863.26** | | 1,113,600(r3) | 測定失敗 | 62,519.84 | **53,478.04** | **確定できること: B1 と B2 はどちらも A より速い。** 512 で 2 回、128 で 1 回、すべての有効な組で B 系が A を上回った (唯一の例外は r1 の 128 で A が 1.074 倍高い cap だったもの)。 **確定できないこと: B1 と B2 のどちらが速いか。** - 512 では r1 は B2 勝ち(146,473 vs 154,761)、r3 は B1 勝ち(162,394 vs 171,874)。 - 128 では B2 が 2 回とも勝ち。 - **順序が cap によって入れ替わるので、n=1-2 では決められない。** **したがって §4.5 の「B2 が最も速い可能性が高い」は撤回し、 「B 系 2 つは A より速いが、B1 と B2 の順序は未確定」に訂正する。** ### §4.8 載せ替え判断(訂正後): **見送り** **退行が無いことは 3 セル x 2 cap で示せた。** 品質も両方 PASS 済み。 それでも見送る理由: - **B1 と B2 の順序が決まっていない**ため、どちらを載せるか決められない。 - 「両方一括」は、片方が片方より遅い可能性を排除できていない状態では選べない。 - **同一値を弾くチェックが無いまま n を増やすと、古い値の混入で誤判定する** (§4.6 で 1 回起きた)。 **次フェーズの条件**: §4.6 の対策(stdout から直接取得 + 重複検出)を入れた上で、 cap 1,555,200 か 1,113,600 の**どちらかに揃った状態で各腕 3 回以上**。 そこで B1/B2 の順序が出れば、速い方を単独で載せ替える。 --- ## §5 目標2: dotprod 後の NGL 再掃引 Phase 61 は「NGL=44 が最良」と結論した。そのときは CPU 1 層のコストが高かった。 Phase 64 で CPU 床が約 2.3 倍速くなったので、**最良点が動いた可能性**を確認した。 ### §5.1 測定 `p65_ngl.sh`(§4.6 の失敗を踏まえて対策済みの版)で NGL 32/36/40/44/48、 prefill 128、各 2 run、ラウンドで順序を反転(32->48 / 48->32)。 **10 run すべて cap 1,555,200 で安定、重複値なし**(スクリプトの検出機構が作動)。 **これが本フェーズで最も品質の高いデータである。** | NGL | r1 (ms) | r2 (ms) | 平均 | 同一 NGL 内の振れ | | --- | --- | --- | --- | --- | | 32 | 50,248.41 | 51,982.83 | 51,115.6 | 3.4% | | **36** | 43,039.04 | 50,691.46 | **46,865.2** | **16.3%** | | 40 | 51,415.90 | 53,107.49 | 52,261.7 | 3.2% | | 44 | 47,586.68 | 55,991.98 | 51,789.3 | **16.2%** | | 48 | 49,737.02 | 50,497.00 | 50,117.0 | 1.5% | ### §5.2 判定: **NGL=44 維持(掃引範囲は平坦)** - **NGL 間の平均の広がりは 11.5%**(46,865〜52,262)、 **同一 NGL 内の run 間の振れは平均 8.1%。** 同程度の大きさである。 - 特に **NGL=36 と 44 は内部の振れが 16%** あり(36 は 43.0k と 50.7k、 44 は 47.6k と 56.0k)、**この 2 点の平均は信頼できない**。 - 内部の振れが小さい 3 点(32: 51.1k、40: 52.3k、48: 50.1k)は **ほぼ同じ値**に収まっている。 **したがって「NGL 32-48 の範囲は平坦で、明確な最良点は無い」。** 36 が最良に見えるのは片方の run が速かったためで、再現性が無い。 **新既定: 44 を維持する。** 変更する根拠が無い。 ただし **Phase 61 が考えていたような「44 に鋭い最適点がある」わけではない** ことが分かった。**32-48 はどれを選んでも同じ**である。 **これは CPU 床が下がったことと整合する**: CPU 層が安くなれば、 CPU/HTP の配分に対する感度が下がる(どちらに置いても大差ない)。 ### §5.3 decode は比較に使えない `decode_ms` は NGL 30 で 1,211.8〜5,285.6 ms と 4.4 倍の幅があった。 **decode probe は 4 forward のみで短すぎる。** Phase 64 の 12-run 測定(中央値 926 ms、IQR 94 ms)は decode 用に 128 token を流していたので、そちらの手法が必要である。 **今回は decode の NGL 依存を判定していない。** ### §5.4 スレッド数の確認は未実施 指示の「スレッド 8 も 1 回だけ確認(4/6/7/8 のスポット)」は**未実施**。 目標1 と目標3 を優先したため。**未達として明記する。** ### §5.5 品質再確認は不要と判断 NGL を変更しないため(44 維持)、配置が変わらず **hash も品質も変わらない**。 64-step の再取得は行っていない。§0.2 の 32-step hash 一致が現行構成の無事を示す。 --- ## §6 判定表 | # | 目標 | 判定 | 根拠 | | --- | --- | --- | --- | | 0 | ゲート | **PASS** | unit 15/15+88/88、`e788051e`/`ede05813` 一致、sdot 1,376 | | 1 | 残置バッチ ABBA | **完了・FA バッチを載せ替え** | 3 ラウンドで **B2 < B1 < A が一貫**。B2 が A より **25.2% 速い**。品質 PASS 済みのため採用(§11)。B1 は不採用(B2 より 21.3% 遅い) | | 2 | NGL 再掃引 | **完了・44 維持** | 32-48 は平坦(§5.2)。**スレッド掃引も完了**(§15、6 維持、4 は 24.6% 遅い) | | 3 | Bonsai Q2_0 | **完了(決定的)** | **fork は無警告でゴミ、上流 CPU は正常、上流 HTP は異常終了**(§1) | | 4 | 小刻み follow | **PARTIAL** | 4-1 は既着地(§2.1)、4-3 は IQ2_XXS のみ追加で再測定不要と判断(§2.2)、**ggml-org#31055 未実施**(§2.3) | | 5 | 検証・訂正 | **PARTIAL** | 5-1 完了(`c59-cpu` は dotprod あり、Phase 59 は正しい)。llama-cli 再ビルドは**上流版のみ実施**(§7) | --- ## §7 llama-cli の再ビルド 指示の「llama-cli の再 build(新 CPU `abecaf60` 対応)」について: - **fork の `cli63` は Phase 63 ビルドのまま**で、CPU は別途 `libs/libggml-cpu.so` (`abecaf60`)を参照する構成なので、**CPU を差し替えれば新 dotprod が効く**。 実際 §1.3 の fork 実行は `cli63` + `abecaf60` で動いている。 - **上流の llama-cli は新規ビルドした**(`cli65`、`p65_build_upstream_cli.ps1`)。 hexagon=ON、`sdot` 1,120 で検証済み。Bonsai の測定に使用。 - **`GGML_CPU_TILED_MM_COUNT` の傍証は今回取っていない**(未実施)。 --- ## §8 「やっていないこと」「確定していないこと」 ### §8.1 やっていないこと - **バッチの載せ替え**(B1/B2 とも見送り。§4.8) - **ggml-org#31055(KV-head team split)**の適応(§2.3) - **スレッド数 4/6/7/8 のスポット比較**(§5.4) - **decode の NGL 依存判定**(§5.3、probe が短すぎる) - **fork への `ggml-org#29600` 取り込み**(Bonsai のモデル側 Hadamard 配線。§1.5) - **`GGML_CPU_TILED_MM_COUNT` の傍証取得**(§7) - **llama-cli の実用プリセット固め** - **MTP の予備調査**(自由裁量項目) ### §8.2 確定していないこと - **B1 と B2 のどちらが速いか**(§4.7。cap によって順序が入れ替わる) - **B 系が A より速いという結論の大きさ**(8-13% と出たが n=1-2。 「退行が無い」は言えるが「13% 速い」は言えない) - **NGL=36 が最良か**(§5.2。内部の振れ 16% で再現しない) - **Bonsai を fork で動かすのに何が必要か**(`ggml-org#29600` だけでは HTP は走らない。 ベンダーの未リリース修正が要る。§1.5) - **上流 HTP が Bonsai で落ちる原因**(`dspqueue_read 0x2e`。層数を減らしても同じ。 メモリ説は否定できたが、repack 段階の何が失敗しているかは未特定) --- ## §9 終了状態 | 項目 | 値 | | --- | --- | | **skel** | **`cdc628a9849b9f211c50bd7f2dca4c54e846b24034afaf189c2a1d2621c8abe2`**(**Phase 65 で載せ替え**。§11) | | **CPU** | `abecaf609042e0921b1dcd651a5982e3882ed0dbbc673026bf9bec3cd36d8c51`(**載せ替えなし**) | | **base** | `d950aa96587fe4bceb27cb1d88f27a3ccbc2d19f951d6a4f89b95b2f28893a27` | | **hexagon** | **`c9dadbdec5801672110679cfda854f7e96bd0a382662440d96ff41e39d842491`**(FA バッチ、**Phase 65 で載せ替え**。§11) | | **sdot カウント** | `libggml-cpu.so` = **1,376**(恒久規則の確認) | | ビルドパス(fork) | `build/c63-test`(hexagon/skel の hash はパス依存) | | ビルドパス(上流) | `D:\ghq\github.com\yuubinnkyoku\llama-upstream-c63\build\c65-upcli`(`origin/master` = `fa9f928`) | | replay | `25358 11 198 760`(復元済み) | | プロセス | **0** | | 前面アプリ停止 | **0 回**(Phase 64 のフェイルセーフ版 `p53_run.sh` を使用) | | 再起動 | **なし**(uptime 348,116 s から単調増加) | | メイン worktree | **9 ファイルのまま保護** | ### §9.1 端末に追加したもの | ファイル | サイズ | 用途 | | --- | --- | --- | | `models/Ternary-Bonsai-2.5-27B-Q2_0.gguf` | 7.15 GiB | Bonsai evidence(sha256 照合済み) | | `cli65/`(11 ファイル) | 約 170 MB | 上流 master の llama-cli 一式 | ### §9.2 端末の空き容量(注意) `runs/` の古い `logits.f32` 968 個(約 9 GB)を削除して Bonsai 用の領域を作った。 **現在の空きは約 2.4 GB のみ。** Bonsai モデル(7.15 GiB)を残したままなので、 **次フェーズで別モデルを入れる場合は Bonsai を削除する必要がある。** 戻す手順: ``` adb shell rm /data/local/tmp/llama.cpp/models/Ternary-Bonsai-2.5-27B-Q2_0.gguf ``` **Bonsai の evidence は取得済みなので、削除して問題ない。** --- ## §10 Phase 66 への引き継ぎ 1. **バッチ載せ替えの決着**: §4.6 の対策(stdout から直接取得・重複検出)を 入れた上で cap を揃え、各腕 3 回以上。B1/B2 の順序が出れば速い方を単独で載せる。 2. **Bonsai は保留**: ベンダーの Hexagon fix のリリースを待つ。 リリースされたら fork に `ggml-org#29600` を取り込み、`cli65` 相当の上流ビルドで 先に splits を測る。**fork への取り込みだけでは動かない**(§1.5)。 3. **上流の IQ3 系 tiled 対応を監視**: IQ2_XXS だけ入った(§2.2)。 IQ3_XXS/IQ3_S/IQ2_S/IQ2_XS が入れば 27B の 254 テンソルが解禁され、 **exit plan のトリガーになる**。`cli65` がすぐ測れる状態にある。 4. **`ggml-org#31055`(KV-head team split)** の適応。decode は全 step FA を通るので 64-step で品質確認。 5. **スレッド数の掃引**(4/6/7/8)。dotprod+tiled で最適値が動いた可能性。 6. **decode probe の改善**: 4 forward では比較不能(§5.3)。Phase 64 の 12-run 方式 (128 token 流す)を NGL 比較にも使う。 --- ## §11 追記: バッチ ABBA を決着させ、**FA バッチを標準に載せ替えた** §4 では「B1 と B2 の順序が未確定」として見送った。その後、 **§4.6 の対策を入れた `p65_abba2.sh` で 3 ラウンド取り直し、順序が確定した。** ### §11.1 決着用の測定(`p65_abba2.sh`、512 tokens、3 ラウンド) §4 の教訓を全部入れた版: - ログを事前削除 + マーカーより新しいことを検証 - 重複値を `DUP!` で検出 - `rc != 0` で即中断 - 腕ごとに `WANT_SKEL` を渡す - ラウンドごとに腕の順序を回す(A->B1->B2 / B1->B2->A / B2->A->B1) | ラウンド | A(標準) | B1(q2_K) | B2(FA) | 速い順 | cap | | --- | --- | --- | --- | --- | --- | | 1 | 186,064.2 | 175,043.6 | **153,007.6** | **B2 < B1 < A** | A は 1,670,400(最も有利)/B2 は 1,113,600(最も不利) | | 2 | 223,304.3 | 200,291.9 | **138,934.0** | **B2 < B1 < A** | 3 腕とも 1,113,600 | | 3 | (**DUP で除外**) | 194,472.0 | **164,212.1** | **B2 < B1** | 3 腕とも 1,113,600 | **重複検出が 3 回目の古い値読み(`dec-r3-A` が B2 と完全同値)を捕まえた。** §4.6 で入れた対策が実際に機能した。**その値は除外した。** **中央値**: A 204,684 / B1 194,472 / **B2 153,008** | 比較 | 差 | | --- | --- | | **B2 vs A** | **25.2% 速い** | | B1 vs A | 5.0% 速い | | **B2 vs B1** | **21.3% 速い** | **3 ラウンドすべてで同じ順序(B2 < B1 < A)。** 特にラウンド 1 は **A が最も高い cap(1,670,400)で最も有利な条件**、 **B2 が最も低い cap(1,113,600)で最も不利な条件**だったにもかかわらず B2 が最速だった。**cap を言い訳にできない結果である。** **§4 で「順序が未確定」としたのは、古い値の混入で B1/B2 が入れ替わって 見えていたため**だった。対策後は一貫している。 ### §11.2 載せ替え判断: **FA バッチを採用** 品質は Phase 64 §18.2 で PASS 済み(64-step argmax **64/64**、 d_nll **+0.0012**、t=+0.51、PPL 19.8280->19.8522)。 速度は 3 ラウンドで一貫して 25.2% 優位。**両方の条件を満たすので採用する。** **B1(q2_K バッチ)は採用しない。** B2 より 21.3% 遅く、 A に対して 5.0% と効果が小さい。B2 に含まれる改善の方が大きい。 ### §11.3 新基準構成 | 項目 | 旧 | **新** | | --- | --- | --- | | CPU | `abecaf60` | `abecaf60`(変更なし) | | **hexagon** | **`c9dadbdec5801672110679cfda854f7e96bd0a382662440d96ff41e39d842491`**(FA バッチ、**Phase 65 で載せ替え**。§11) | | **skel** | **`cdc628a9849b9f211c50bd7f2dca4c54e846b24034afaf189c2a1d2621c8abe2`**(**Phase 65 で載せ替え**。§11) | | base | `d950aa96` | `d950aa96`(変更なし) | ロールバック用: `libggml-hexagon.so.c65prev`(`9c9bfc48`)、 `libggml-htp-v81.so.c65prev`(`312ad7b7`)。`ls -l` でシンボリックリンク 0 を確認済み。 ### §11.4 新基準 hash(各 3 回、すべて一致) | NGL | 旧基準 | **新基準** | 備考 | | --- | --- | --- | --- | | **44** | `e788051e` | **`8259e4b08000c201cc2d7d3c49fddad477b6c0011859c099e213cd93509f3bd8`** | **hash が動いた**(FA 改善が数値を変える) | | **0** | `ede05813` | **`ede05813…`(不変)** | CPU のみの経路は fA の影響を受けない | **NGL=0 が不変であることが重要**: FA バッチの変更はバッチ処理(prefill)の 経路に限られ、1 token の CPU 経路には及ばないことを示す。 ### §11.5 スクリプト期待値の更新 `run53.sh` の `WANT_SKEL` 既定を新 skel に更新した: ```sh WANT=${WANT_SKEL:-cdc628a9849b9f211c50bd7f2dca4c54e846b24034afaf189c2a1d2621c8abe2} ``` 旧版は `run53.sh.bak-c65prev` に残置。 **更新後の確認(`WANT_SKEL` を渡さずに実行)**: - NGL=44 -> `8259e4b0`(一致) - NGL=0 -> `ede05813`(一致) - unit stage **15/15 + 88/88** ### §11.6 訂正の記録 - §4.5 で「B2 が最も速い可能性が高い」と書き、§4.7 で「順序は未確定」に訂正し、 **§11 で「B2 が 25.2% 速い、順序は 3 ラウンドで一貫」に再訂正**した。 - 揺れた原因は**測定手順の不具合(古い値の再読)**であり、測定対象の性質ではなかった。 - **対策(重複検出)が機能したことで、3 回目で確定できた。** - 教訓: **測定スクリプトに「前回と同じ値なら異常」というチェックを入れること。** これは Phase 64 の cap 統制と並ぶ、再現性のための必須条件である。 --- ## §12 追記: 未実施項目とその理由(具体的に) ### §12.1 スレッド数掃引(4/6/7/8)- ~~未実施~~ -> **§15 で実施済み** **理由**: スレッド数は `run53.sh` の**第 5 位置引数**(`NTHREADS=${5:-6}`)で、 環境変数による上書きが無い。測定経路は `p53_run.sh` -> `run_split53.sh off "$STEPS"` -> `run53.sh` で、 `p53_run.sh` は **2 引数しか渡していない**ため、この経路からは NTHREADS に到達できない。 掃引するには次のどれかが要る: 1. `p53_run.sh` / `run_split53.sh` に NTHREADS を通す引数を足す 2. `run53.sh` の `NTHREADS=${5:-6}` を `NTHREADS=${NTHREADS:-${5:-6}}` にする **どちらも「測定経路そのもの」を変更する。** Phase 65 で測定手順の不具合を 2 回踏んだ直後であり、**測定系に手を入れて比較の土台を動かすリスクを避けた。** **次フェーズの推奨**: 上記 2 の 1 行(環境変数での上書きを許す)を入れ、 その変更自体が hash を変えないことを 32-step で確認してから掃引する。 ### §12.2 `GGML_CPU_TILED_MM_COUNT` の傍証 - ~~未実施~~ -> **§16 で実施済み(実 workload で 4,256 回)** Phase 64 で計装を入れ、`GGML_CPU_TILED_MM=1` で 12,800 回の発動を確認済み。 Phase 65 は prefill 512 の測定で tiled が通っていることは前提にしているが、 **計装ビルド(`9a8c95cd`)を現在の標準(`abecaf60`)に載せていない**ため、 今回の run では発動回数を数えていない。 **未実施として明記する。** 必要なら `9a8c95cd` を入れて 1 run 取れば済む。 --- ## §13 Phase 66 への引き継ぎ(更新版) 1. **新標準(FA バッチ)の運用開始**: hexagon `c9dadbde` + skel `cdc628a9`。 基準 hash は **NGL=44 `8259e4b0` / NGL=0 `ede05813`**。 `run53.sh` の `WANT_SKEL` 既定も更新済み。 2. ~~B1(q2_K バッチ)の再評価~~ -> **不要と判明(§14 で訂正)**。 ただし B2 に無い改善(q2_K の帯域削減)を含むので、 3. **スレッド掃引**(§12.1 の 1 行を入れてから)。 4. **Bonsai は保留**: ベンダーの Hexagon fix 待ち。`cli65` で即測れる。 5. **上流の IQ3 系 tiled 対応を監視**: IQ2_XXS のみ入っている(§2.2)。 6. **decode probe の改善**: 4 forward では比較不能(§5.3)。 7. **端末の空き容量**: 2.3 GB のみ。Bonsai モデル(7.15 GiB)は evidence 取得済みで 不要なので、次に別モデルを入れる前に削除する(§9.2)。 --- ## §14 訂正: §13 の「B1 と B2 の組み合わせ」は不要だった §13 で「B1 は B2 に無い改善(q2_K の帯域削減)を含むので、組み合わせれば 加算できる可能性がある」と書いた。**これは誤りだった。** ### §14.1 確認したこと コミット順を確認した: ``` 636f14c q2_K (ggml-org#30035) + CPY round3 + scalar DMA + DCVS <- q2_K はここ 80c7665 FA 改善 (ggml-org#30731) <- B2 はここでビルド ``` `git merge-base --is-ancestor 636f14c 80c7665` -> **True**。 つまり **B2(FA バッチ)は q2_K のコミットを含む子孫でビルドされている。** さらに現在のソースを確認: ``` ggml/src/ggml-hexagon/htp/matmul-ops.c:956 MATMUL_2D_REPACKED_IMPL(q2_k, 336, tiled_vec_dot_q2_k_32x2, ...) ``` **q2_K のタイル 336 が B2 のビルド元ソースに存在する。** ### §14.2 したがって | バッチ | 内容 | | --- | --- | | **B1(`c64q2k`)** | q2_K まで(FA 改善は無い) | | **B2(`c64fa2`)** | **q2_K も FA 改善も両方**(B1 の上位集合) | **B2 は B1 を包含している。**「B2 が B1 より 21.3% 速い」のは、 FA 改善が上に乗っているからであり、**q2_K の効果も B2 の中で既に効いている。** **組み合わせるべきものは何も無い。載せ替えは既に全部入っている。** ### §14.3 この誤りの原因 §13 を書いた時点で「B1 と B2 は並列な選択肢」と暗黙に仮定していた。 実際は**直列(累積)**で、後から積んだ B2 が全部を持つ。 **ブランチが累積である以上、後発バッチが先行バッチを包含するのは当然**であり、 確認せずに書いたのが誤り。 **教訓: バッチを比較するときは、まず「包含関係にあるか」を確認する。** 並列比較だと思い込むと、存在しない統合作業を計画してしまう。 --- ## §15 追記: スレッド数掃引を実施(§12.1 の未実施項目を解消) §12.1 で「測定経路に手を入れる必要があるので見送り」とした項目を、 **最小限の 1 行**で解消して実施した。 ### §15.1 変更(1 行) `run53.sh` の 36 行目: ```sh NTHREADS=${NTHREADS:-${5:-6}} # 旧: NTHREADS=${5:-6} ``` **既定動作が変わらないことを先に確認した**(恒久規則): - 既定(env なし): NGL=44 -> **`8259e4b0`**(新基準と一致) - `NTHREADS=8`: NGL=44 -> **`8259e4b0`**(同一) **スレッド数は 1 token の出力を変えない。** よって掃引しても hash 基準は不変。 旧版 `run53.sh.bak-c65thr` に残置。 ### §15.2 掃引の有効性を先に検証した(重要) 最初の掃引で、ログの `threads 6` が全設定で同じだったため **「上書きが効いていない疑い」**が出た。調べると `threads` は **`GGML_HEXAGON_SPLIT_THREADS`** という別変数の値で、`NTHREADS` とは無関係だった (`NTHREADS` は `P44_NTHREADS` として probe に渡る)。 **そこで決定的なテストを行った**: | NTHREADS | prefill 128 ms | | --- | --- | | **1** | **146,095.78** | | **8** | **51,111.99** | **1 スレッドは 8 スレッドより 2.86 倍遅い。上書きは正しく効いている。** (`applied` 列が `6` と出ていたのは私の読み取り先の誤り。) ### §15.3 結果(cap 1,670,400 で揃ったラウンド 1 が最も信頼できる) | ラウンド | t4 | t6 | t8 | cap | | --- | --- | --- | --- | --- | | 1 | 46,220.24 | **40,622.97** | 43,085.82 | 3 本とも 1,670,400 | | 2 | 61,906.23(cap 降下中) | 46,172.80 | **44,873.64** | t4 のみ 1,555,200 へ降下 | 中央値: **t4 54,063.2 / t6 43,397.9 / t8 43,979.7** | 比較 | 差 | | --- | --- | | t6 vs t8 | **1.3%(ノイズと同じ)** | | t4 vs t6 | **t4 が 24.6% 遅い** | **結論: 6(現行既定)でよい。** 8 と 6 は区別できず、4 は明確に遅い。 `dotprod` を入れても最適スレッド数は動かなかった。 **変更しない。** 既定 6 を維持する。 --- ## §16 追記: tiled 発動の傍証を実 workload で取得(§12.2 を解消) Phase 64 では NGL=0(CPU のみ)で 12,800 回の発動を確認したが、 **実 workload(NGL=44、HTP 併用)での発動は確認していなかった。** 計装ビルド(`9a8c95cd`)を一時的に入れ、NGL=44・prefill 128・実 27B で 1 run: ``` ggml-tiled: calls 4256 rows_ok 4256 supported_ok 8512 ``` | 指標 | 値 | 意味 | | --- | --- | --- | | `supported_ok` | 8,512 | 型・レイアウトの条件を通った matmul | | `rows_ok` | 4,256 | そのうち rows>=8 も通った | | **`calls`** | **4,256** | **実際に tiled カーネルで計算された** | **実 workload でも tiled は 4,256 回発動している。** 半分が `rows_ok` で落ちるのは、 prefill 中でも rows<8 の小さな matmul(正規化後の射影など)があるため。 **これは想定内で、異常ではない。** **計装ビルドは標準ではない**(`9a8c95cd`)。測定後に **`abecaf60` に戻したことを sha256 で確認済み**(`abecaf609042e0921b1dcd651a5982e3882ed0dbbc673026bf9bec3cd36d8c51`)。 **したがって Phase 64 の「tiled は dotprod があると 3.5 倍速い」は、 実 workload で実際に効いている経路の話である**ことが確認できた。 --- ## §17 追記: 上流監視 - HTP 側の FWHT は**既に入っていた** 指示の上流監視項目(ggml-org#32582 の merge 動向、FWHT/Hadamard の Hexagon 入り)を 上流ツリーで直接確認した。 ### §17.1 上流 master の状態 | 項目 | 値 | | --- | --- | | 上流 master(確認時) | `98cc730` | | 直近の hexagon コミット(`244640b7f` 以降) | **1 件**(型表は不変) | | tiled 対象の IQ 系 | **`IQ2_XXS` のみ**(IQ2_XS/IQ2_S/IQ3_XXS/IQ3_S/IQ4_XS は無い) | ### §17.2 **FWHT は Hexagon に入っている** 上流の hexagon バックエンド内の `fwht`/`hadamard` 参照: | ファイル | 参照数 | | --- | --- | | `htp/unary-ops.c` | **29** | | `htp/unary-ops.h` | 4 | | `htp/htp-opnode.cpp` / `.h` | 3 / 3 | | `htp/htp-fusion.cpp` | 2 | | `htp/htp-kparams.cpp` | 2 | | `htp/htp-ops.h` / `main.c` | 1 / 1 | **HTP 側の FWHT カーネルは実装済みである。** 「FWHT が Hexagon に無いのが Bonsai 全面 NPU 化の最後の蓋」という Phase 64 までの理解は**古い**。 ### §17.3 ただし私の測定ビルドにも入っていた 決定的な確認: 私が Bonsai を測った **`fa9f928`** の時点で、 `unary-ops.c` の `fwht` 参照は **24 件**あった(`98cc730` でも 24 件)。 **したがって §1.3 の「上流 HTP はロード時に rc 134 で落ちる」は、 FWHT カーネルが存在する状態で起きた現象である。** ### §17.4 結論の更新(より強く、より正確に) **Bonsai の HTP 動作を妨げているのは FWHT の不在ではない。** 上流 master は FWHT カーネルも Prism Bonsai のモデル対応も持っており、 それでも `-ngl 99/20/8` のすべてで `dspqueue_read failed: 0x2e` で落ちる。 **残る障壁はベンダーの未リリース修正のみ**であり、これは PrismML の preset の 記述("No public build runs this model correctly on the Hexagon NPU yet; it needs a fix that is not released")と一致する。 **fork にとっての追加の事実**: この FWHT は `htp-kparams.cpp` / `htp-fusion.cpp` / `htp-opnode.cpp` という **Op Fusion フレームワークの中**にある。 Phase 64 §17 で「そのフレームワークは取らない」と決めた以上、 **fork がこの HTP FWHT を使えるようになる見込みは薄い。** fork 側で Bonsai を NPU で動かすには、フレームワークごと方針を見直す必要がある。 --- ## §18 失敗 3: スクリプトの replay 復元が**黙って失敗していた** 終了状態の確認で気づいた。3 つ目の手順不具合である。 ### §18.1 症状 `replay.txt` が `25358 11 198 760` ではなく **32-step のトークン列(139 バイト)**になっていた。 ### §18.2 原因 スクリプトが測定終了時に `cp $BASE/replay4.bak $L/replay.txt` で戻そうとしていたが、 **`$BASE/replay4.bak` というファイルは存在しない。** `cp` は失敗するが、スクリプトはその直後に `echo "P65A replay_restored $(cat $L/replay.txt)"` と**成功したかのように表示**していた。 そのため 3 スクリプトすべてで「復元済み」と記録されていたが、実際は未復元だった。 **§4.6 の「古い値を報告した」不具合と同じ種類**: **失敗を検出せず成功を表示する。** ### §18.3 正しい復元元 `libs/` に 3 つの控えがあり、いずれも正しい値を持っていた: | ファイル | 内容 | | --- | --- | | `replay.txt.std` | `25358 11 198 760` | | `replay.txt.p50orig` | `25358 11 198 760` | | `replay.txt.p52bak` | `25358 11 198 760` | `replay.txt.std` から復元し、**`25358 11 198 760` に戻ったことを確認した。** **4 スクリプトすべてで復元先を `$BASE/libs/replay.txt.std` に修正した。** ### §18.4 副次的に分かったこと: `replay.txt` はシンボリックリンク ``` replay.txt -> /data/local/tmp/c45-27b/libs/replay.txt (2026-11-05 作成) ``` **テストディレクトリの外(`c45-27b`)を指している。** したがって `replay.txt` への書き込みは c45-27b 側へ抜ける。 今回の復元は内容が正しいので実害は無いが、 **`*.so` の載せ替え前に `ls -l` で確認する規則は `replay.txt` にも必要**である。 (`libs/` の `libggml-*.so` 3 本は実ファイルであることを確認済み。`^l` が 0 件。) ### §18.5 教訓 **復元・片付けのコマンドも、実行後に値を読んで照合する。** `cp` の成否を `$?` で見ずに `echo` で「復元した」と書くと、 今回のように 3 フェーズ分の記録が嘘になる。 **対策**: スクリプトの最後で `[ "$(cat $L/replay.txt)" = "25358 11 198 760" ] || echo "P65X REPLAY_RESTORE_FAILED"` のように**期待値と比較する**べきである。次フェーズで入れる。/replay.txt at the end, but that file does not exist, so cp failed. The next line echoed replay_restored with whatever was in the file, which read as success in all three scripts. This is the same class as the stale run reads: reporting success without checking. Restored from libs/replay.txt.std, which holds 25358 11 198 760, and confirmed by reading it back. All four sweep scripts now point at that file. Also worth knowing: replay.txt is a symlink to c45-27b/libs/replay.txt, dated 2026-11-05, so it reaches outside the test directory. The three libggml .so files are real files, checked for the l flag. The fix for next time is to compare the restored value against the expected one instead of echoing it, and that is written into the report. Assisted-by: DeepSeek Harness
Overview
Runtime support for Prism Bonsai 2 27B
Additional information
Requirements