Skip to content

ggml-hexagon 2.0 : support for int-hmx, automatic f32 -> f16 lowering, and generic dma pipelines - #32582

Merged
max-krasnyansky merged 18 commits into
ggml-org:masterfrom
qualcomm:hexagon-int-hmx
Nov 26, 2026
Merged

max-krasnyansky merged 18 commits into
ggml-org:masterfrom
qualcomm:hexagon-int-hmx

Conversation

@max-krasnyansky

@max-krasnyansky max-krasnyansky commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Overview

This PR started as a focused effort to enable new HMX integer modes (w8a8 and w8a16) with dynamic quantization.
In the process I realized that we have to also enable lowering of the internal inputs/outputs from f32 -> f16 in order to properly optimize things. And last but not least we also needed to finally re-work the DMA pipelines which was long overdue. So this turned into ggml-hexagon 2.0 kind of update.

Unfortunately, the changes require big surgery through every op/kernel/solver/fusion to properly support mixed types. I considered breaking op updates into individual PRs, but they are not usable by themselves and a flood of PRs would be counter-productive. So instead I went with clean commits (per-op/per-feature) that are reviewable by themselves.
(asked Antigravity to group a bunch of my commits into clean buckets per op/infra/etc).

In order not to pepper the ops & u-kernels with a bunch of if(f16), I reflowed all dispatch paths and specialized u-kernels.
In other words, lots of changes, but very focused on these specific updates and optimization of the data flow.
Initially to get things going I needed a ton of test infra, so the later commits basically trim all that down to a bare minimum.

btw, we're missing a bunch of f16 support in the CPU backend ops and I'm going to follow up with a PR that adds support for that to improve testing coverage.

The PR includes:

  • New HMX mode (w8a8) with dynamic quantization with 2K kgroup (enabled by default in hybrid mode)
  • New unified graph lowering pass that lowers f32 -> f16 (where safe, ie no explicit ggml_prec_...) and collapses dims
  • All Hexagon ops now support mixed f32/f16 inputs and outputs
  • All Hexagon ops now use DMA for all inputs and outputs (removes the need for explicit dirty range tracking)
  • New env vars to configure the new features
  • Documentation updates

Tested on all supported platforms (Android, Linux, Window v73 ... v85, single/dual/quad-NPU) and popular model families (Gemma4, Qwen3.x, LFM2.x/3, ...)

Additional information

The perf bump is quite noticeable :)
Here is an example with Gemma-4 on Galaxy S26+

./scripts/snapdragon/run.py --target adb --devices HTP0 -- llama-completion -m ../gguf/gemma-4-E2B_q4_0-it.gguf --jinja -st -f ../sample_prompt_4096.txt -n 128 --ctx-size $((32 * 1024))

master

0.07.259.790 I common_perf_print: prompt eval time =     696.82 ms /  3912 tokens (    0.18 ms per token,  5614.10 tokens per second)
0.07.259.790 I common_perf_print:        eval time =    3609.49 ms /   127 runs   (   28.42 ms per token,    35.19 tokens per second)

this-PR

0.06.326.481 I common_perf_print: prompt eval time =     472.50 ms /  3912 tokens (    0.12 ms per token,  8279.42 tokens per second)
0.06.326.482 I common_perf_print:        eval time =    3265.74 ms /   127 runs   (   25.71 ms per token,    38.89 tokens per second)

Most models see big gains but not uniformly so we'll probably need to tune the kernels further.
Here is a detailed perf sweep across multiple devices

Details
# Hexagon Backend Performance Sweep: origin/master vs hexagon-int-hmx

- Baseline (`origin/master`): commit `87f816e87` (`GGML_HEXAGON_OPPOLL=1`)
- Branch (`hexagon-int-hmx`): build `b2b343e260` (best of `OPPOLL=50` default and `OPPOLL=1` shown in headline tables)
- Common flags: `llama-bench -fa 1 -ngl 99 -t 6 -p 1024,4096 -n 128 -r 1 --delay 30` (30s cooldown between tests and invocations, `VERBOSE=0`, `PROFILE=0`)
- Quantization: all models `Q4_0`, F16 KV cache

## Headline Delta Summary (Branch Best vs Master)

| Device      | Model        | pp1024 base | pp1024 new | pp1024 % | pp4096 base | pp4096 new | pp4096 % | tg128 base | tg128 new | tg128 % |
| ----------- | ------------ | ----------: | ---------: | -------: | ----------: | ---------: | -------: | ---------: | --------: | ------: |
| QRD (v85)   | Qwen3.5-0.8B |     5604.94 |    7307.27 |   +30.4% |     5388.45 |    6853.25 |   +27.2% |     102.08 |    132.88 |  +30.2% |
| QRD (v85)   | Qwen3.5-4B   |     1572.13 |    2451.83 |   +56.0% |     1405.74 |    2309.58 |   +64.3% |      28.03 |     31.36 |  +11.9% |
| QRD (v85)   | Gemma4-E2B   |     7487.79 |   11713.75 |   +56.4% |     7069.14 |   11072.28 |   +56.6% |      50.20 |     55.16 |   +9.9% |
| QRD (v85)   | LFM2.5-8B    |     2415.60 |    4045.04 |   +67.5% |     2313.72 |    3732.18 |   +61.3% |      68.12 |     77.36 |  +13.6% |
| QRD (v85)   | Granite4-1B  |     2630.38 |    3323.76 |   +26.4% |     2551.07 |    3246.63 |   +27.3% |      57.79 |     67.95 |  +17.6% |
| S26+ (v81)  | Qwen3.5-0.8B |     4334.68 |    6430.10 |   +48.3% |     4208.94 |    6092.61 |   +44.8% |      78.02 |     99.16 |  +27.1% |
| S26+ (v81)  | Qwen3.5-4B   |     1325.01 |    2149.24 |   +62.2% |     1271.83 |    2058.91 |   +61.9% |      19.97 |     22.55 |  +12.9% |
| S26+ (v81)  | Gemma4-E2B   |     5876.42 |    9169.11 |   +56.0% |     5678.93 |    8868.31 |   +56.2% |      37.36 |     41.22 |  +10.3% |
| S26+ (v81)  | LFM2.5-8B    |     1969.34 |    2947.76 |   +49.7% |     1894.83 |    2738.83 |   +44.5% |      50.61 |     55.06 |   +8.8% |
| S26+ (v81)  | Granite4-1B  |     2019.76 |    2715.20 |   +34.4% |     1990.37 |    2630.68 |   +32.2% |      43.71 |     50.41 |  +15.3% |
| S24U (v75)  | Qwen3.5-0.8B |     2319.93 |    3043.19 |   +31.2% |     2230.79 |    2850.21 |   +27.8% |      63.27 |     73.10 |  +15.5% |
| S24U (v75)  | Qwen3.5-4B*  |      750.68 |    1126.63 |   +50.1% |      615.02 |    1062.87 |   +72.8% |      14.39 |     14.01 |   -2.6% |
| S24U (v75)  | Gemma4-E2B*  |     3743.36 |    5176.50 |   +38.3% |     3511.73 |    4970.35 |   +41.5% |      22.00 |     22.56 |   +2.5% |
| S24U (v75)  | Granite4-1B  |     1263.00 |    1525.95 |   +20.8% |     1236.30 |    1476.51 |   +19.4% |      36.71 |     36.43 |   -0.8% |
| IQ9 (2xv73) | Qwen3.5-0.8B |     2481.98 |    3453.03 |   +39.1% |     2404.84 |    3294.03 |   +37.0% |      65.36 |     90.94 |  +39.1% |
| IQ9 (2xv73) | Qwen3.5-2B   |     1691.47 |    2158.71 |   +27.6% |     1656.18 |    2108.44 |   +27.3% |      38.22 |     46.54 |  +21.8% |
| IQ9 (2xv73) | Granite4-1B  |     1313.17 |    1584.98 |   +20.7% |     1296.76 |    1559.74 |   +20.3% |      36.05 |     46.02 |  +27.7% |

## Per-Device Details (Master vs OPPOLL=50 vs OPPOLL=1)

### QRD - Hexagon v85 (HTP0, DMA64, -ub 1024)

| Model        | Metric | master (poll=1) | branch (poll=50) | branch (poll=1) | best vs master |
| ------------ | ------ | --------------: | ---------------: | --------------: | -------------: |
| Qwen3.5-0.8B | pp1024 |         5604.94 |          7074.68 |         7307.27 |         +30.4% |
|              | pp4096 |         5388.45 |          6567.16 |         6853.25 |         +27.2% |
|              | tg128  |          102.08 |           132.65 |          132.88 |         +30.2% |
| Qwen3.5-4B   | pp1024 |         1572.13 |          2411.91 |         2451.83 |         +56.0% |
|              | pp4096 |         1405.74 |          2309.58 |         2273.61 |         +64.3% |
|              | tg128  |           28.03 |            31.36 |           31.00 |         +11.9% |
| Gemma4-E2B   | pp1024 |         7487.79 |         10846.79 |        11713.75 |         +56.4% |
|              | pp4096 |         7069.14 |         11012.82 |        11072.28 |         +56.6% |
|              | tg128  |           50.20 |            55.16 |           54.92 |          +9.9% |
| LFM2.5-8B    | pp1024 |         2415.60 |          3972.04 |         4045.04 |         +67.5% |
|              | pp4096 |         2313.72 |          3610.04 |         3732.18 |         +61.3% |
|              | tg128  |           68.12 |            77.36 |           75.90 |         +13.6% |
| Granite4-1B  | pp1024 |         2630.38 |          3095.12 |         3323.76 |         +26.4% |
|              | pp4096 |         2551.07 |          3202.40 |         3246.63 |         +27.3% |
|              | tg128  |           57.79 |            67.95 |           66.83 |         +17.6% |

### Galaxy S26+ (v81) - Hexagon v81 (HTP0, DMA64, -ub 1024)

| Model        | Metric | master (poll=1) | branch (poll=50) | branch (poll=1) | best vs master |
| ------------ | ------ | --------------: | ---------------: | --------------: | -------------: |
| Qwen3.5-0.8B | pp1024 |         4334.68 |          6273.17 |         6430.10 |         +48.3% |
|              | pp4096 |         4208.94 |          5944.73 |         6092.61 |         +44.8% |
|              | tg128  |           78.02 |            99.16 |           98.90 |         +27.1% |
| Qwen3.5-4B   | pp1024 |         1325.01 |          2130.87 |         2149.24 |         +62.2% |
|              | pp4096 |         1271.83 |          2020.32 |         2058.91 |         +61.9% |
|              | tg128  |           19.97 |            22.55 |           22.54 |         +12.9% |
| Gemma4-E2B   | pp1024 |         5876.42 |          8448.08 |         9169.11 |         +56.0% |
|              | pp4096 |         5678.93 |          8465.07 |         8868.31 |         +56.2% |
|              | tg128  |           37.36 |            41.22 |           41.15 |         +10.3% |
| LFM2.5-8B    | pp1024 |         1969.34 |          2911.69 |         2947.76 |         +49.7% |
|              | pp4096 |         1894.83 |          2639.22 |         2738.83 |         +44.5% |
|              | tg128  |           50.61 |            55.06 |           54.62 |          +8.8% |
| Granite4-1B  | pp1024 |         2019.76 |          2674.41 |         2715.20 |         +34.4% |
|              | pp4096 |         1990.37 |          2468.05 |         2630.68 |         +32.2% |
|              | tg128  |           43.71 |            49.67 |           50.41 |         +15.3% |

### Galaxy S24 Ultra - Hexagon v75 (HTP0, DMA64 off, -ub 1024)

| Model        | Metric | master (poll=1) | branch (poll=50) | branch (poll=1) | best vs master |
| ------------ | ------ | --------------: | ---------------: | --------------: | -------------: |
| Qwen3.5-0.8B | pp1024 |         2319.93 |          3001.52 |         3043.19 |         +31.2% |
|              | pp4096 |         2230.79 |          2779.09 |         2850.21 |         +27.8% |
|              | tg128  |           63.27 |            73.10 |           67.65 |         +15.5% |
| Qwen3.5-4B*  | pp1024 |          750.68 |          1117.11 |         1126.63 |         +50.1% |
|              | pp4096 |          615.02 |          1055.46 |         1062.87 |         +72.8% |
|              | tg128  |           14.39 |            14.01 |           13.45 |          -2.6% |
| Gemma4-E2B*  | pp1024 |         3743.36 |          5176.50 |         4479.15 |         +38.3% |
|              | pp4096 |         3511.73 |          4804.97 |         4970.35 |         +41.5% |
|              | tg128  |           22.00 |            22.56 |           21.91 |          +2.5% |
| Granite4-1B  | pp1024 |         1263.00 |          1517.03 |         1525.95 |         +20.8% |
|              | pp4096 |         1236.30 |          1450.60 |         1476.51 |         +19.4% |
|              | tg128  |           36.71 |            36.36 |           36.43 |          -0.8% |

### IQ9 Ubuntu - Dual Hexagon v73 (HTP0[0-1], DMA64 off, -ub 512)

Multi-session v73 defaults to MM_SELECT=2 / FA_SELECT=2 (FP16 HMX + FP16 lowering).

| Model        | Metric | master (poll=1) | branch (poll=50) | branch (poll=1) | best vs master |
| ------------ | ------ | --------------: | ---------------: | --------------: | -------------: |
| Qwen3.5-0.8B | pp1024 |         2481.98 |          3354.46 |         3453.03 |         +39.1% |
|              | pp4096 |         2404.84 |          3236.87 |         3294.03 |         +37.0% |
|              | tg128  |           65.36 |            90.94 |           90.89 |         +39.1% |
| Qwen3.5-2B   | pp1024 |         1691.47 |          2158.71 |               - |         +27.6% |
|              | pp4096 |         1656.18 |          2108.44 |               - |         +27.3% |
|              | tg128  |           38.22 |            46.54 |               - |         +21.8% |
| Granite4-1B  | pp1024 |         1313.17 |          1566.50 |         1584.98 |         +20.7% |
|              | pp4096 |         1296.76 |          1541.55 |         1559.74 |         +20.3% |
|              | tg128  |           36.05 |            45.29 |           46.02 |         +27.7% |

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: Yes, this is a big one, did multiple rounds of reviews/iterations with Anti.G 4 Neon/Carbon/Argon, Codex with Sol/Terra. Reviewed, cleaned up and tested every generated commit myself.

@github-actions github-actions Bot added documentation Improvements or additions to documentation testing Everything test related ggml changes relating to the ggml tensor library for machine learning Hexagon labels Nov 19, 2026
@max-krasnyansky
max-krasnyansky force-pushed the hexagon-int-hmx branch 2 times, most recently from c8d57dc to 10ac892 Compare November 21, 2026 05:56
@njsyw1997

Copy link
Copy Markdown
Contributor

Another optimization is switching repack format back to HVX friendly. Our internal tests show that on fp16 HMX this will accelerate on some low-end chips since now HMX path is optimized enough and the bottleneck is on the HVX side. With int HMX the case is stronger: the int8 weight tile is itself row-major, so rescale_q4_0_tile_step also drops both shuffles which makes switching the repack format look worthwhile.

It's a big change to all the kernels so maybe do it here is a better choice.

@max-krasnyansky

Copy link
Copy Markdown
Member Author

Another optimization is switching repack format back to HVX friendly. Our internal tests show that on fp16 HMX this will accelerate on some low-end chips since now HMX path is optimized enough and the bottleneck is on the HVX side. With int HMX the case is stronger: the int8 weight tile is itself row-major, so rescale_q4_0_tile_step also drops both shuffles which makes switching the repack format look worthwhile.

It's a big change to all the kernels so maybe do it here is a better choice.

Yep. I'm folding it into this. Came to the same conclusion during experiments.
I'm going to push a big update shortly.

@max-krasnyansky
max-krasnyansky force-pushed the hexagon-int-hmx branch 2 times, most recently from 89a7e49 to 12503e1 Compare November 24, 2026 00:28
@max-krasnyansky max-krasnyansky changed the title hexagon: support for int-hmx and automatic f32 -> f16 lowering ggm-hexagon 2.0 : support for int-hmx, automatic f32 -> f16 lowering, and generic dma pipelines Nov 24, 2026
@max-krasnyansky
max-krasnyansky marked this pull request as ready for review November 24, 2026 00:58
@max-krasnyansky
max-krasnyansky requested review from a team and ggerganov as code owners November 24, 2026 00:58
@max-krasnyansky

Copy link
Copy Markdown
Member Author

@lhez for review and ack

@max-krasnyansky

Copy link
Copy Markdown
Member Author

I'm sure folks will find some regression that will need to adress.
Quick note that if you see any accuracy issues please retest with GGML_HEXAGON_MM_SELECT=2.
But do report either way and I'll followup.

@max-krasnyansky max-krasnyansky added the merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. label Nov 24, 2026
@max-krasnyansky max-krasnyansky changed the title ggm-hexagon 2.0 : support for int-hmx, automatic f32 -> f16 lowering, and generic dma pipelines ggml-hexagon 2.0 : support for int-hmx, automatic f32 -> f16 lowering, and generic dma pipelines Nov 24, 2026
@max-krasnyansky

Copy link
Copy Markdown
Member Author

Quick note on the accuracy validation across Qwen3.5-4B, Gemma4-E2B, LFM2.5-8B-A1B, and Granite4-1B (on v73 ... v85).

The internal FP16 activation lowering (GGML_HEXAGON_OPLOWER=1) is virtually lossless (+0.03% to +0.06% PPL).

Pure W8A8 INT-HMX (KGROUP=2048) causes around a +3.7% to +9.4% PPL increase and causes Qwen3.5-4B to loop on some 16K needle-in-haystack extraction tests.
Shrinking KGROUP down to 256 (-27% prefill speed) still failed Qwen3.5-4B's 16K needle test because post-GLU projections (ffn_down) contain single-channel activation outliers within a 32-element block.
Routing post-GLU and GGML_PREC_F32 projections to FP16 HMX recovered around 95.5% of the PPL gap on Qwen3.5-4B and LFM2.5-8B, and restored all 16K needle retrievals on Qwen3.5-4B.

Hence we have the new hybrid default (GGML_HEXAGON_MM_SELECT=3) that routes post-GLU to FP16 HMX, while GGML_HEXAGON_MM_SELECT=4 allows for pure W8A8 everywhere for less sensitive use-cases.
The hybrid mode has around +40% faster prefill than pure FP16 HMX.

@max-krasnyansky

Copy link
Copy Markdown
Member Author

@jhen0409 when you get the chance give it a go and see if you can run with GGML_HEXAGON_MM_SELECT=3/4 on your IQ9 on both NPUs (ie forcing INT-HMX with dual-NPU). I ended up making MM_SELECT=2 (fp16) the default on IQ9 if both NPUs are enabled because the EVKs don't like running INT-HMX on both (we're looking into it).

@max-krasnyansky

Copy link
Copy Markdown
Member Author

Doing rebases and further cleanups.

@max-krasnyansky

Copy link
Copy Markdown
Member Author

Tested a few models and configs on IQ9 (single NPU), and the following table shows the changes in PPL:

[snip]

The Llama-3.2-1B has significant change. The issue likely lies within hmx-fa-w8a8-kernels.h and hmx-mm-kernels-tiled-int.h code for < v81, though I am not really sure.

Oh. Interesting. I didn't check llama3.2-1b. Thanks for pointing that out. The rest looks pretty good as in my tests.
I'll double check 1b shortly

- Add dma-proxy thread/ring for main-thread DMA offload (clamp n_hvx <= hw_nth - 2)
- Add syncht in hmx-queue after HMX VTCM stores

Assisted-by: Antigravity
- Use 64-col dual-acc (weight.b:deep + mxswapacc) across all arches and :cm activation layout
- Pre-issue chunk-0 weight DMA via dma_proxy, balance 4-row quad output threads, and defer output DMA pop

Assisted-by: Antigravity
hex-fa: cleanup dma_queue usage and mask buffers
hex-fa: fix new op tests and corner cases
hex-fa: cleanup kernel selection and solver
hex-fa: improve decode performance (split-kv)
Alsp pipeline GDN HMX/HVX with batched dispatch and spill-free inversion
rope: optimize init and add common fast-path
…,...)

- Double-buffer vtcm_up/vtcm_wt_scales_up, add 0-spill direct loop0 FP16 GLU strip kernels, trim sub-ULP FP16 sigmoid terms
- Balance 4-row quad GLU threads, defer output DMA pop, and pre-issue chunk-0 weight DMA via dma_proxy

Assisted-by: Antigravity
For now do not include ssm_conv tests that break ggml-metal
Assisted-by: Antigravity
Includes updated tensor tiling description (it is 32x4 now)
@max-krasnyansky

Copy link
Copy Markdown
Member Author

Tested a few models and configs on IQ9 (single NPU), and the following table shows the changes in PPL:
[snip]
The Llama-3.2-1B has significant change. The issue likely lies within hmx-fa-w8a8-kernels.h and hmx-mm-kernels-tiled-int.h code for < v81, though I am not really sure.

Oh. Interesting. I didn't check llama3.2-1b. Thanks for pointing that out. The rest looks pretty good as in my tests. I'll double check 1b shortly

I found & fixed some wrong qf16 casts and in general tightened up all ops.
The latest is all good on PPL for me on those llamas.

### Llama-3.2-1B-Instruct-Q4_0 (G26-v81 + IQ9 v73 Single & Dual NPU)

| Config                                           |     PPL |   +/- SE |     Delta vs CPU |  Delta vs Master | s/pass | 
| ------------------------------------------------ | ------: | -------: | ---------------: | ---------------: | -----: | 
| CPU reference (`-ngl 0`)                         | 33.3606 |  1.15933 |           0.0000 |          +0.0720 |  1.52s | 
| Master (`abca692003`, v81 `HTP0`, `MM_SELECT=2`) | 33.2886 |  1.15664 |          -0.0720 |           0.0000 |  0.13s | 
| Branch (`ce8732fab8`, v81 `HTP0`, `MM_SELECT=2`) | 33.3035 |  1.15718 |          -0.0571 |          +0.0149 |  0.09s | 
| Branch (`ce8732fab8`, v81 `HTP0`, `MM_SELECT=3`) | 33.5403 |  1.16590 | +0.1797 (+0.54%) | +0.2517 (+0.76%) |  0.07s | 
| Branch (`ce8732fab8`, v81 `HTP0`, `MM_SELECT=4`) | 34.6162 |  1.21246 | +1.2556 (+3.76%) | +1.3276 (+3.99%) |  0.06s | 
| Branch (`ce8732fab8`, v73 `HTP0`, `MM_SELECT=2`) | 33.2350 |  1.15534 |          -0.1256 |          -0.0536 |  0.31s | 
| Branch (`ce8732fab8`, v73 `HTP0[0-1]`, MM_..=2`) | 33.2350 |  1.15534 |          -0.1256 |          -0.0536 |  0.18s | 
| Branch (`ce8732fab8`, v73 `HTP0`, `MM_SELECT=3`) | 33.9466 |  1.18354 | +0.5860 (+1.76%) | +0.6580 (+1.98%) |  0.21s | 
| Branch (`ce8732fab8`, v73 `HTP0[0-1]`, `MM_.=3`) | 33.9466 |  1.18354 | +0.5860 (+1.76%) | +0.6580 (+1.98%) |  0.13s | 

### Llama-3.2-3B-Instruct-Q4_0 (G26-v81)

| Config                                           |     PPL |   +/- SE |     Delta vs CPU |  Delta vs Master | s/pass | 
| ------------------------------------------------ | ------: | -------: | ---------------: | ---------------: | -----: | 
| CPU reference (`-ngl 0`)                         | 19.6849 |  0.67266 |           0.0000 |          +0.0172 |  4.09s | 
| Master (`abca692003`, v81 `HTP0`, `MM_SELECT=2`) | 19.6677 |  0.67201 |          -0.0172 |           0.0000 |  0.28s | 
| Branch (`ce8732fab8`, v81 `HTP0`, `MM_SELECT=2`) | 19.6749 |  0.67224 |          -0.0100 |          +0.0072 |  0.24s | 
| Branch (`ce8732fab8`, v81 `HTP0`, `MM_SELECT=3`) | 19.7467 |  0.67581 | +0.0618 (+0.31%) | +0.0790 (+0.40%) |  0.16s | 
| Branch (`ce8732fab8`, v81 `HTP0`, `MM_SELECT=4`) | 20.2864 |  0.69175 | +0.6015 (+3.06%) | +0.6187 (+3.15%) |  0.14s | 

@max-krasnyansky
max-krasnyansky requested a review from lhez November 26, 2026 03:17
@max-krasnyansky

Copy link
Copy Markdown
Member Author

@lhez please approve again when you get the chance

@max-krasnyansky
max-krasnyansky merged commit e0f884d into ggml-org:master Nov 26, 2026
37 of 42 checks passed
yuubinnkyoku added a commit to yuubinnkyoku/llama.cpp that referenced this pull request Nov 26, 2026
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
Mr-J-369 pushed a commit to Mr-J-369/llama.cpp-Android that referenced this pull request Nov 26, 2026
…, and generic dma pipelines (ggml-org#32582)

* hexagon : add DMA pipeline, htp_tensor_read, and cache/mdev cleanup

- Add dma-proxy thread/ring for main-thread DMA offload (clamp n_hvx <= hw_nth - 2)
- Add syncht in hmx-queue after HMX VTCM stores

* hexagon : add F16/collapse graph lowering and fusion updates

* hexagon : update host kparams solver for W8A8 HMX, F16, and DMA

* hexagon : add INT-HMX W8A8 matmul, F16 support, and DMA writeback

- Use 64-col dual-acc (weight.b:deep + mxswapacc) across all arches and :cm activation layout
- Pre-issue chunk-0 weight DMA via dma_proxy, balance 4-row quad output threads, and defer output DMA pop

* hexagon : add HMX W8A8 Q8_0 KV flash attention and DMA writeback

hex-fa: cleanup dma_queue usage and mask buffers
hex-fa: fix new op tests and corner cases
hex-fa: cleanup kernel selection and solver
hex-fa: improve decode performance (split-kv)

* hexagon : add F16, DMA, and micro-kernel optimizations for unary/norm ops

* hexagon : add mixed F16/F32 and HVX optimizations for binary ops

* hexagon : add F16, DMA, and state fusion for gated-delta-net

Alsp pipeline GDN HMX/HVX with batched dispatch and spill-free inversion

* hexagon : add F16, token-major fusion, and DMA updates for SSM ops

* hexagon : add F16 and HVX optimizations for rope, softmax, and glu

rope: optimize init and add common fast-path

* hexagon : add F16, DMA, and spill fixes for argsort and top-k

* hexagon : add F16 lowering and optimizations for lightning-indexer and dsv4

* hexagon : add F16 and DMA updates for row and concat ops

* hexagon : convert simple ops to dma-pipeline, F16, and warning/mdev cleanup

* hexagon: add support for fusing MUL_MAT_NX with GLU ops (GEGLU,SWIGLU,...)

- Double-buffer vtcm_up/vtcm_wt_scales_up, add 0-spill direct loop0 FP16 GLU strip kernels, trim sub-ULP FP16 sigmoid terms
- Balance 4-row quad GLU threads, defer output DMA pop, and pre-issue chunk-0 weight DMA via dma_proxy

* tests : add F16/mixed-type and Hexagon op test cases

For now do not include ssm_conv tests that break ggml-metal

* hexagon : update trace and run scripts

* hexagon : update Snapdragon backend README and developer docs

Includes updated tensor tiling description (it is 32x4 now)

--
Co-authored-by: Ehsan Bateni <[email protected]>
Co-authored-by: Todor Boinovski <[email protected]>
Co-authored-by: Trivikram Reddy <[email protected]>
Co-authored-by: Yanzhao Wang <[email protected]>

Assisted-by: Antigravity
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation ggml changes relating to the ggml tensor library for machine learning Hexagon testing Everything test related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants