nnopt port: Bonsai-27B-llama.cpp
Browse filesFiles changed (19)
- .gitattributes+17-32
- LICENSEAdded+177
- LICENSE-llama.cppAdded+21
- NOTICEAdded+15
- README.mdAdded+78
- config.jsonAdded+34
- m2pro-gpu-q1_0/README.mdAdded+73
- m2pro-gpu-q1_0/build.shAdded+52
- m2pro-gpu-q1_0/deploy.shAdded+22
- m2pro-gpu-q1_0/fetch.shAdded+33
- m2pro-gpu-q1_0/nnopt-prismml-5ae2e169.patchAdded+562
- m2pro-gpu-q1_0/report.htmlAdded+110
- m2pro-gpu-q1_0/report/reproduce.shAdded+14
- m2pro-gpu-q1_0/report/results.csvAdded+81
- m2pro-gpu-q1_0/report/results.jsonAdded+1404
- m2pro-gpu-q1_0/src/CMakeLists.txtAdded+23
- m2pro-gpu-q1_0/src/patches/0001-q1_0-lut-gemv.patchAdded+549
- m2pro-gpu-q1_0/src/run.shAdded+3
- m2pro-gpu-q1_0/src/runner.cppAdded+335
1234567891011121314151617181920212223242526272829303132333435*.7z filter=lfs diff=lfs merge=lfs -text*.arrow filter=lfs diff=lfs merge=lfs -text*.bin filter=lfs diff=lfs merge=lfs -text*.bz2 filter=lfs diff=lfs merge=lfs -text*.ckpt filter=lfs diff=lfs merge=lfs -text*.ftz filter=lfs diff=lfs merge=lfs -text*.gz filter=lfs diff=lfs merge=lfs -text*.h5 filter=lfs diff=lfs merge=lfs -text*.joblib filter=lfs diff=lfs merge=lfs -text*.lfs.* filter=lfs diff=lfs merge=lfs -text*.mlmodel filter=lfs diff=lfs merge=lfs -text*.model filter=lfs diff=lfs merge=lfs -text*.msgpack filter=lfs diff=lfs merge=lfs -text*.npy filter=lfs diff=lfs merge=lfs -text*.npz filter=lfs diff=lfs merge=lfs -text*.onnx filter=lfs diff=lfs merge=lfs -text*.ot filter=lfs diff=lfs merge=lfs -text*.parquet filter=lfs diff=lfs merge=lfs -text*.pb filter=lfs diff=lfs merge=lfs -text*.pickle filter=lfs diff=lfs merge=lfs -text*.pkl filter=lfs diff=lfs merge=lfs -text*.pt filter=lfs diff=lfs merge=lfs -text*.pth filter=lfs diff=lfs merge=lfs -text*.rar filter=lfs diff=lfs merge=lfs -text*.safetensors filter=lfs diff=lfs merge=lfs -textsaved_model/**/* filter=lfs diff=lfs merge=lfs -text*.tar.* filter=lfs diff=lfs merge=lfs -text*.tar filter=lfs diff=lfs merge=lfs -text*.tflite filter=lfs diff=lfs merge=lfs -text*.tgz filter=lfs diff=lfs merge=lfs -text*.wasm filter=lfs diff=lfs merge=lfs -text*.xz filter=lfs diff=lfs merge=lfs -text*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -text1234567891011121314151617181920*.bin filter=lfs diff=lfs merge=lfs -text*.tflite filter=lfs diff=lfs merge=lfs -text*.gguf filter=lfs diff=lfs merge=lfs -text*.onnx filter=lfs diff=lfs merge=lfs -text*.npz filter=lfs diff=lfs merge=lfs -text*.wav filter=lfs diff=lfs merge=lfs -text*.so filter=lfs diff=lfs merge=lfs -text*.bf16 filter=lfs diff=lfs merge=lfs -text*.f16 filter=lfs diff=lfs merge=lfs -text*.f32 filter=lfs diff=lfs merge=lfs -text*.npy filter=lfs diff=lfs merge=lfs -text*.tkb filter=lfs diff=lfs merge=lfs -text*.png filter=lfs diff=lfs merge=lfs -text*.jpg filter=lfs diff=lfs merge=lfs -text*.jpeg filter=lfs diff=lfs merge=lfs -text*.pdf filter=lfs diff=lfs merge=lfs -text*.zip filter=lfs diff=lfs merge=lfs -text*.gz filter=lfs diff=lfs merge=lfs -text*.safetensors filter=lfs diff=lfs merge=lfs -text*.pt filter=lfs diff=lfs merge=lfs -text
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
(a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
123456789101112131415161718192021MIT License
Copyright (c) 2023-2026 The ggml authors
Permission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in allcopies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THESOFTWARE.123456789101112131415This software is copyright 2026-present Prism ML, Inc. It is available under the Apache 2.0 license.If you publicly deploy or redistribute this software, we would appreciate attribution such as: "Created using Bonsai by Prism ML."
This software is built from Qwen3.6-27B, Copyright 2026 Alibaba Cloud, which is available under the Apache 2.0 License: https://huggingface.co/Qwen/Qwen3.6-27B/blob/main/LICENSE
---
This repository is a modified version of prism-ml/Bonsai-27B-gguf by Prism ML, revision f10afb355f104535e3e3e98cf7ab7795c72bd292.
Changes, made by nnopt (https://nnopt.dev):- `m2pro-gpu-q1_0/` (nnopt job NN-53D464): fetched: fetch.sh downloads Bonsai-27B-Q1_0.gguf (original, unchanged). The runtime code (src/, build.sh, deploy.sh, run.sh) is new, written by nnopt's agents for this device.
The runner links llama.cpp (MIT, see LICENSE-llama.cpp).
Created using Bonsai by Prism ML.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778---license: apache-2.0base_model: prism-ml/Bonsai-27B-ggufpipeline_tag: text-generationtags:- on-device- nnopt- llama.cpp- gguf- metal- macos- apple-silicon- gpu- 1-bit- mac-mini-m2-pro---
# Bonsai-27B on Mac mini (M2 Pro) (PrismML llama.cpp Metal)
Ported, optimized and verified on a real Mac mini (M2 Pro) by [nnopt.dev](https://nnopt.dev) — AI agents that port and optimize models for the hardware you ship.
The model is [prism-ml/Bonsai-27B-gguf](https://huggingface.co/prism-ml/Bonsai-27B-gguf) by Prism ML, and it is theirs. The PrismML llama.cpp Metal port in this repository is nnopt's work: nnopt job NN-53D464.
Created using Bonsai by Prism ML.
| | ||---|---|| Device | Mac mini (M2 Pro), macOS || Chip | Apple M2 Pro || Processor | GPU (Apple M2 Pro, Metal), all layers || Runtime | PrismML llama.cpp fork 5ae2e169, Metal backend, with nnopt's patch || Precision | Q1_0 - 1.125-bit, as given || Modality | text -> text || Weights | fetched: fetch.sh downloads Bonsai-27B-Q1_0.gguf (original, unchanged) || nnopt job | NN-53D464 (optimize) || Folder | [`m2pro-gpu-q1_0/`](https://huggingface.co/nnopt-dev/Bonsai-27B-llama.cpp/tree/main/m2pro-gpu-q1_0) |
Run 2 of an optimize chain: NN-A8E243 (lookup-table Q1_0 GEMV, GDN rows mode) then NN-53D464 (repacked Q1_0 tile layout + packed-index LUT GEMV, fused decode conv-state step). The patch holds the result of both; NN-A8E243's LUT kernel was reworked in NN-53D464, its rows mode is in src/runner.cpp.
## Verified results
nnopt built the folder from a clean copy, deployed it to the device and checked it against the model's reference code on hidden inputs. The full report is `report.html` in the folder.
- Passed. Next-token agreement 100.0% (bar at least 98.0%)- Speed target: decode 29.4 tokens/s (bar at least 19.0 tokens/s)- Decode 29.4 tokens/s (was 15.9, 1.8x faster)- Prefill 86.0 tokens/s (was 87.3, 1.0x slower)- Time to first token 1.82 s (was 1.80 s)- Load time 1.04 s (was 564 ms, 1.8x slower)- Peak memory 4,532 MB (was 4,208 MB, 8% more)
## Use it
```mkdir Bonsai-27B-llama.cpp && cd Bonsai-27B-llama.cppcurl -fsSL https://huggingface.co/nnopt-dev/Bonsai-27B-llama.cpp/resolve/main/config.json -o config.jsonhf download nnopt-dev/Bonsai-27B-llama.cpp --include "m2pro-gpu-q1_0/*" --local-dir .cd m2pro-gpu-q1_0bash fetch.shbash build.sh # copies the fork, applies src/patches/, builds bin/nnopt_runner (~30 s)bash deploy.sh ~/bonsai27becho 'Explain quantum computing in simple terms.' > p.txtsh ~/bonsai27b/run.sh --prompt-file p.txt --max-new-tokens 128 --out out.json --metrics m.json```
Needs: macOS on Apple silicon with Xcode command line tools, CMake >= 3.14, rsync, patch, git, curl; ~4.6 GB free memory. `nnopt-prismml-5ae2e169.patch` is the same change as src/patches/ as a git diff.
`README.md` in the folder has every flag, the requirements and the known limits; `REPRO.md` (where present) reproduces the measurements.
## License
Apache 2.0, like prism-ml/Bonsai-27B-gguf: see LICENSE and NOTICE. The runner links llama.cpp (MIT, LICENSE-llama.cpp).
## Made with nnopt
[nnopt](https://nnopt.dev) is a platform where AI agents port, optimize and benchmark a model for a specific device. They write the runtime code on the real device, and a locked verification kit then checks the result against the model's own reference code before anything ships. Every number on this page comes from that check.
Want your model on your device? Start a job at [nnopt.dev](https://nnopt.dev).12345678910111213141516171819202122232425262728293031323334{ "nnopt_manifest": 1, "repo": "nnopt-dev/Bonsai-27B-llama.cpp", "model": { "name": "Bonsai-27B", "source_repo": "prism-ml/Bonsai-27B-gguf", "source_revision": "f10afb355f104535e3e3e98cf7ab7795c72bd292", "authors": "Prism ML", "license": "apache-2.0" }, "variants": [ { "id": "m2pro-gpu-q1_0", "device": "Mac mini (M2 Pro)", "chip": "Apple M2 Pro", "os": "macOS", "processor": "GPU (Apple M2 Pro, Metal), all layers", "runtime": "PrismML llama.cpp fork 5ae2e169, Metal backend, with nnopt's patch", "runtime_version": "5ae2e169eac202d2f065606539c3ad6ab8b51333", "precision": "Q1_0 - 1.125-bit, as given", "weights": "fetched: fetch.sh downloads Bonsai-27B-Q1_0.gguf (original, unchanged)", "nnopt_job": "NN-53D464", "job_kind": "optimize", "verified": { "verdict": "Passed. Next-token agreement 100.0% (bar at least 98.0%); Speed target: decode 29.4 tokens/s (bar at least 19.0 tokens/s)", "speed": "Decode 29.4 tokens/s (was 15.9, 1.8x faster); Prefill 86.0 tokens/s (was 87.3, 1.0x slower); Time to first token 1.82 s (was 1.80 s); Load time 1.04 s (was 564 ms, 1.8x slower); Peak memory 4,532 MB (was 4,208 MB, 8% more)" }, "history": "Run 2 of an optimize chain: NN-A8E243 (lookup-table Q1_0 GEMV, GDN rows mode) then NN-53D464 (repacked Q1_0 tile layout + packed-index LUT GEMV, fused decode conv-state step). The patch holds the result of both; NN-A8E243's LUT kernel was reworked in NN-53D464, its rows mode is in src/runner.cpp.", "fetch": "m2pro-gpu-q1_0/fetch.sh" } ], "license": "apache-2.0", "made_by": "nnopt (https://nnopt.dev)"}12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273# Bonsai-27B (Q1_0) on Mac mini M2 Pro: faster decode on the PrismML llama.cpp fork (Metal)
- **Model**: prism-ml/Bonsai-27B-gguf, `Bonsai-27B-Q1_0.gguf` (hybrid gated-delta-net + attention, 64 blocks).- **Device**: Mac mini (M2 Pro), Apple GPU, macOS on Apple silicon.- **Runtime**: the customer's PrismML llama.cpp fork (5ae2e169), Metal backend, with our patches (`src/patches/0001-q1_0-lut-gemv.patch`) and a small C++ runner over `llama.h` (`src/runner.cpp`).- **Precision**: Q1_0_g128 1-bit weights as published (reordered in memory at load), fp32 activations and accumulation, f16 KV cache. **Processor**: GPU, all layers.
## Requirements- macOS on Apple silicon (arm64), Xcode command line tools (`/usr/bin/clang`, `clang++`), CMake >= 3.14, rsync, patch.- The customer's inputs folder (`inputs/reference_code` = the fork, `inputs/weights/Bonsai-27B-Q1_0.gguf`). build.sh finds it via `$NNOPT_INPUTS_DIR`, or in `inputs/` or `work/inputs/` next to this folder or any parent folder.
## Build bash build.sh # copies the fork to build/llama-src, applies src/patches, builds bin/nnopt_runner (~30 s)
## Deploy bash deploy.sh DEST # DEST/run.sh, DEST/nnopt_runner, DEST/port.json, DEST/Bonsai-27B-Q1_0.gguf (APFS clone)
## Run sh DEST/run.sh --prompt-file prompt.txt --max-new-tokens 128 [--ignore-eos] [--repeat R] --out out.json --metrics m.json sh DEST/run.sh --score-tokens tokens.json --top-k 10 --out out.json --metrics m.json
Generation is greedy (argmax, ties to the lowest id), with the vocab's default special tokens and no chat template.`out.json` = `{"prompt_tokens", "tokens", "text"}`; `m.json` holds load_ms and per-run total_ms, ttft_ms and token_ms.
## Check nnopt-verify check --split public --bundle <work>/reference --port DEST --executor local
## Measured (this Mac)| | starting version | this port ||---|---|---|| decode tok/s, kit bench (outside clock) | 15.85 | 27.48 || decode tok/s, kit sustained run (median) | - | 30.07 || decode ms/token, in-process (p000, 128 tokens) | ~63 | 33.1 || public check | - | all metrics 1.0 (1185 positions) |
Roofline: 54.6 tok/s (3.6 GB of weights per token at ~200 GB/s). Details, profile and what was tried: NOTES.md.
## Known limits- Weights are read into Metal buffers (not mmapped) and repacked at load. Warm load takes ~1 s; the first launch after a build takes ~18 s while Metal compiles the shaders.- Speed work targets decode. Prefill uses the fork's kernels (adapted to the repacked layout, same speed).- The repacked Q1_0 layout is internal to this build's Metal kernels. Do not mix these patched libraries with an unpatched loader or mmap loading (the loader refuses mmap for Q1_0 Metal tensors).
## Verified by nnopt
**Passed** prism-ml/Bonsai-27B-gguf on Mac mini (M2 Pro) (2026-10-16). nnopt built this folder from a clean copy, deployed it to the device and ran it on hidden inputs; the full report is report.html.
| Check | Measured | Bar | Result ||---|---|---|---|| Speed target: decode | 29.4 tokens/s | at least 19.0 tokens/s | pass || Outputs match your reference code | Next-token agreement 100.0% | at least 98.0% (original precision) | pass || Runs on llama.cpp | src/runner.cpp:164: llama_model * model = llama_model_load_from_file(model_path.c_str(), mparams); | the runtime you asked for | pass |
| Speed | This port | Starting version | Change ||---|---|---|---|| Prefill, tokens/s | 86.0 | 87.3 | 1.0× slower || Decode, tokens/s | 29.4 | 15.9 | 1.9× faster || Time to first token | 1.82 s | 1.80 s | 1.0× slower || Load time | 1.04 s | 564 ms | 1.8× slower || Peak memory | 4,532 MB | 4,208 MB | 8% more |
| Measurement | Median ||---|---|| Prefill | 86.043 tokens/s || Decode | 29.3804 tokens/s || Time to first token | 1824.67 ms || Load time | 1037.93 ms || Peak memory | 4532.0 MB || Sustained speed after 11 min, % of start | 100.0 % |12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152#!/bin/bash# Builds the customer's PrismML llama.cpp fork (Metal) with our speed patches (src/patches)# plus a small contract runner over llama.h. Outputs stay in ./build and ./bin.set -euo pipefailcd "$(dirname "$0")"ROOT="$(pwd)"
# Locate the customer's inputs (reference_code + weights).find_inputs() { local cands=("${NNOPT_INPUTS_DIR:-}") # this folder and every ancestor: DIR/inputs and DIR/work/inputs (job layout) local d="$ROOT" while [ "$d" != "/" ]; do cands+=("$d/inputs" "$d/work/inputs") d="$(dirname "$d")" done for d in "${cands[@]}"; do if [ -n "$d" ] && [ -f "$d/reference_code/include/llama.h" ]; then (cd "$d" && pwd); return 0 fi done echo "build.sh: cannot find the inputs folder (set NNOPT_INPUTS_DIR)" >&2; exit 1}INPUTS="$(find_inputs)"echo "inputs: $INPUTS"
# Apple toolchain explicitly (PATH may hold an Android NDK clang).export CC=/usr/bin/clang CXX=/usr/bin/clang++
# Copy the fork (minus the parts this build never uses) and apply our patches (src/patches, in order).# rsync --delete resets every file to the customer's version first, so the patches always apply cleanly.LLAMA_SRC="$ROOT/build/llama-src"mkdir -p "$LLAMA_SRC"rsync -a --delete --exclude /.git --exclude /models --exclude /docs --exclude /tools --exclude /examples \ --exclude /media --exclude /app --exclude /benches "$INPUTS/reference_code/" "$LLAMA_SRC/"for p in src/patches/*.patch; do [ -f "$p" ] || continue echo "applying $p" patch -d "$LLAMA_SRC" -p1 --forward --quiet < "$p"done
cmake -S src -B build/cmake \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang++ \ -DLLAMA_SRC="$LLAMA_SRC"cmake --build build/cmake --target nnopt_runner -j "$(sysctl -n hw.ncpu)"
mkdir -p bincp build/cmake/nnopt_runner bin/nnopt_runnerecho "$INPUTS/weights/Bonsai-27B-Q1_0.gguf" > bin/model_path.txt(cd "$INPUTS/reference_code" && git rev-parse HEAD 2>/dev/null || echo unknown) > bin/llama_commit.txtecho "built bin/nnopt_runner"12345678910111213141516171819202122#!/bin/bash# Installs the runner, run.sh, port.json and the GGUF weights into DEST (this Mac is the device).set -euo pipefailcd "$(dirname "$0")"DEST="${1:?usage: deploy.sh DEST}"[ -x bin/nnopt_runner ] || { echo "run build.sh first" >&2; exit 1; }MODEL_SRC="$(cat bin/model_path.txt)"[ -f "$MODEL_SRC" ] || { echo "weights not found: $MODEL_SRC" >&2; exit 1; }mkdir -p "$DEST"cp bin/nnopt_runner "$DEST/nnopt_runner"cp src/run.sh "$DEST/run.sh"# APFS clone when possible (instant, no extra space); plain copy otherwise.if ! cmp -s "$MODEL_SRC" "$DEST/Bonsai-27B-Q1_0.gguf" 2>/dev/null; then rm -f "$DEST/Bonsai-27B-Q1_0.gguf" cp -c "$MODEL_SRC" "$DEST/Bonsai-27B-Q1_0.gguf" 2>/dev/null || cp "$MODEL_SRC" "$DEST/Bonsai-27B-Q1_0.gguf"ficat > "$DEST/port.json" <<JSON{"contract": 1, "model_type": "text_to_text", "runtime": "PrismML llama.cpp fork $(cut -c1-8 bin/llama_commit.txt), Metal (all layers on GPU)", "precision": "Q1_0_g128 weights (as published), f16 KV cache"}JSONecho "deployed to $DEST"123456789101112131415161718192021222324252627282930313233#!/usr/bin/env bash# Run once after downloading this folder: bash fetch.sh# Downloads the original GGUF and the PrismML llama.cpp fork; build.sh applies src/patches/.set -euo pipefailcd "$(dirname "$0")"REPO=nnopt-dev/Bonsai-27B-llama.cpp
# The repository's manifest first (Hugging Face counts a download when config.json is requested).curl -fsSL "https://huggingface.co/$REPO/resolve/main/config.json" -o ../config.json
sha256_of() { if command -v sha256sum >/dev/null 2>&1; then sha256sum "$1" | cut -d" " -f1; else shasum -a 256 "$1" | cut -d" " -f1; fi; }get() { # get URL FILE SHA256: download once, check the sha256 if [ -f "$2" ] && [ "$(sha256_of "$2")" = "$3" ]; then return 0; fi mkdir -p "$(dirname "$2")" curl -fL --retry 3 -o "$2.part" "$1" [ "$(sha256_of "$2.part")" = "$3" ] || { echo "fetch.sh: sha256 mismatch for $1" >&2; rm -f "$2.part"; exit 1; } mv "$2.part" "$2"}git_at() { # git_at URL COMMIT DIR: the exact commit, shallow if [ "$(git -C "$3" rev-parse HEAD 2>/dev/null || true)" = "$2" ]; then return 0; fi rm -rf "$3"; mkdir -p "$3" git -C "$3" init -q && git -C "$3" remote add origin "$1" git -C "$3" fetch -q --depth 1 origin "$2" && git -C "$3" -c advice.detachedHead=false checkout -q FETCH_HEAD}
# The fork, unchanged, at 5ae2e169 (build.sh finds it in inputs/reference_code and copies it before patching).git_at https://github.com/PrismML-Eng/llama.cpp 5ae2e169eac202d2f065606539c3ad6ab8b51333 inputs/reference_code# The original weights, unchanged.get "https://huggingface.co/prism-ml/Bonsai-27B-gguf/resolve/f10afb355f104535e3e3e98cf7ab7795c72bd292/Bonsai-27B-Q1_0.gguf" \ "inputs/weights/Bonsai-27B-Q1_0.gguf" 17ef842e47450caeb8eaa3ebfbbab5d2f2278b62b79be107985fb69a2f819aa0mkdir -p binecho "$PWD/inputs/weights/Bonsai-27B-Q1_0.gguf" > bin/model_path.txtecho "fetch.sh: done. Next: bash build.sh, then bash deploy.sh ~/bonsai27b"123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562diff --git a/ggml/src/ggml-metal/ggml-metal-device.cpp b/ggml/src/ggml-metal/ggml-metal-device.cppindex 9a4bb00dc..a35c65ee5 100644--- a/ggml/src/ggml-metal/ggml-metal-device.cpp+++ b/ggml/src/ggml-metal/ggml-metal-device.cpp@@ -602,6 +602,17 @@ ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_dsv4_hc(ggml_met return res; } +ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_conv_state_step(ggml_metal_library_t lib) {+ const char * name = "kernel_conv_state_step_f32";++ ggml_metal_pipeline_with_params res = ggml_metal_library_get_pipeline(lib, name);+ if (!res.pipeline) {+ res = ggml_metal_library_compile_pipeline(lib, name, name, nullptr);+ }++ return res;+}+ ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_ssm_conv(ggml_metal_library_t lib, const ggml_tensor * op, bool silu) { GGML_ASSERT(op->src[0]->type == GGML_TYPE_F32); GGML_ASSERT(op->src[1]->type == GGML_TYPE_F32);@@ -909,6 +920,16 @@ bool ggml_metal_ptq1_multicol_enabled(const ggml_tensor * op) { op->src[1]->ne[1] >= 2 && op->src[1]->ne[1] <= 4; } +bool ggml_metal_q1_0_lut_supported(const ggml_tensor * op) {+ static const bool enabled = !getenv("NNOPT_Q1_LUT") || atoi(getenv("NNOPT_Q1_LUT")) != 0;+ const ggml_tensor * src0 = op->src[0];+ const ggml_tensor * src1 = op->src[1];+ return enabled && src0->type == GGML_TYPE_Q1_0 && src1->type == GGML_TYPE_F32 &&+ src0->ne[0] % 1024 == 0 && src0->ne[1] >= 512 && src1->ne[1] == 1 &&+ src0->ne[2] == 1 && src0->ne[3] == 1 && src1->ne[2] == 1 && src1->ne[3] == 1 &&+ src1->nb[0] == sizeof(float);+}+ ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_mul_mv(ggml_metal_library_t lib, const ggml_tensor * op) { GGML_TENSOR_LOCALS( int32_t, ne0, op->src[0], ne); GGML_TENSOR_LOCALS( int32_t, ne1, op->src[1], ne);@@ -963,6 +984,16 @@ ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_mul_mv(ggml_meta nr1 = 2; } suffix = nr1 == 2 ? "_nr1_2" : nr1 == 3 ? "_nr1_3" : nr1 == 4 ? "_nr1_4" : "";+ if (nr1 == 1 && ggml_metal_q1_0_lut_supported(op)) {+ // lookup-table decode kernel, see kernel_mul_mv_q1_0_f32_lut+ static const int lut_nr = getenv("NNOPT_Q1_LUT_NR") ? atoi(getenv("NNOPT_Q1_LUT_NR")) : 4;+ static const int lut_nsg = getenv("NNOPT_Q1_LUT_NSG") ? atoi(getenv("NNOPT_Q1_LUT_NSG")) : 16;+ nsg = lut_nsg;+ nr0 = lut_nr;+ smem = 16*(1024/4)*sizeof(float);+ snprintf(ptq1_suffix, sizeof(ptq1_suffix), "_lut_%d", lut_nr);+ suffix = ptq1_suffix;+ } } break; case GGML_TYPE_Q2_0: {diff --git a/ggml/src/ggml-metal/ggml-metal-device.h b/ggml/src/ggml-metal/ggml-metal-device.hindex 5efc4c82f..5cd6c8858 100644--- a/ggml/src/ggml-metal/ggml-metal-device.h+++ b/ggml/src/ggml-metal/ggml-metal-device.h@@ -6,6 +6,7 @@ extern "C" { #endif +bool ggml_metal_q1_0_lut_supported(const struct ggml_tensor * op); bool ggml_metal_ptq1_multicol_enabled(const struct ggml_tensor * op); struct ggml_metal_buffer_id {@@ -133,6 +134,7 @@ struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_tri struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_soft_max (ggml_metal_library_t lib, const struct ggml_tensor * op); struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_lightning_indexer (ggml_metal_library_t lib, const struct ggml_tensor * op); struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_dsv4_hc (ggml_metal_library_t lib, enum ggml_op op);+struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_conv_state_step (ggml_metal_library_t lib); struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_ssm_conv (ggml_metal_library_t lib, const struct ggml_tensor * op, bool silu); struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_ssm_conv_batched (ggml_metal_library_t lib, const struct ggml_tensor * op, int ssm_conv_bs, bool silu); struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_ssm_scan (ggml_metal_library_t lib, const struct ggml_tensor * op);diff --git a/ggml/src/ggml-metal/ggml-metal-impl.h b/ggml/src/ggml-metal/ggml-metal-impl.hindex 6a68c7006..14e2e7f5d 100644--- a/ggml/src/ggml-metal/ggml-metal-impl.h+++ b/ggml/src/ggml-metal/ggml-metal-impl.h@@ -918,6 +918,18 @@ typedef struct { uint64_t nb2; } ggml_metal_kargs_ssm_conv; +// decode conv-state step of the gated delta net, see ggml_metal_op_conv_state_step+typedef struct {+ int32_t nch; // channels+ int32_t sA; // first element of the state slot copies, in the 4-wide conv input+ int32_t sB;+ int32_t silu;+ uint64_t nb00; // state (concat src0) element (k, c) at c*nb01 + k*nb00+ uint64_t nb01;+ uint64_t nb11; // new input (concat src1) element (0, c) at c*nb11+ uint64_t nb1; // conv input (concat dst) row stride+} ggml_metal_kargs_conv_state_step;+ typedef struct { int64_t d_state; int64_t d_inner;diff --git a/ggml/src/ggml-metal/ggml-metal-ops.cpp b/ggml/src/ggml-metal/ggml-metal-ops.cppindex dc2a9072c..9ffa82e9f 100644--- a/ggml/src/ggml-metal/ggml-metal-ops.cpp+++ b/ggml/src/ggml-metal/ggml-metal-ops.cpp@@ -566,9 +566,119 @@ int ggml_metal_op_encode(ggml_metal_op_t ctx, int idx) { return res; } +// Decode conv-state step of the gated delta net (src/models/delta-net-base.cpp build_conv_state, then+// ggml_ssm_conv and ggml_silu in qwen35.cpp), for one token and one sequence:+// conv_input = CONCAT(conv_states [3, C], x^T [1, C]) -> 2 x CPY(view of conv_input [3, C] at element s, state slot)+// -> SSM_CONV(conv_input, kernel [4, C]) (-> SILU)+// encoded as one thread-per-channel kernel instead of 4-5 dependent dispatches. Returns the number of fused nodes,+// 0 when the pattern does not match (the generic kernels run).+static int ggml_metal_op_conv_state_step(ggml_metal_op_t ctx, int idx) {+ ggml_tensor * op = ctx->node(idx);++ if (!ctx->use_fusion || idx + 4 > ctx->n_nodes()) {+ return 0;+ }++ const ggml_tensor * s0 = op->src[0];+ const ggml_tensor * s1 = op->src[1];+ const int64_t nch = op->ne[1];++ if (((const int32_t *) op->op_params)[0] != 0 || op->type != GGML_TYPE_F32 || s0->type != GGML_TYPE_F32 ||+ s1->type != GGML_TYPE_F32 || !ggml_is_contiguous(op) ||+ op->ne[0] != 4 || op->ne[2] != 1 || op->ne[3] != 1 ||+ s0->ne[0] != 3 || s0->ne[1] != nch || s0->ne[2] != 1 || s0->ne[3] != 1 ||+ s1->ne[0] != 1 || s1->ne[1] != nch || s1->ne[2] != 1 || s1->ne[3] != 1) {+ return 0;+ }++ ggml_tensor * cpy[2] = { ctx->node(idx + 1), ctx->node(idx + 2) };+ int32_t sidx[2];+ for (int j = 0; j < 2; ++j) {+ const ggml_tensor * v = cpy[j]->src[0];+ const ggml_tensor * d = cpy[j]->src[1];+ if (cpy[j]->op != GGML_OP_CPY || v->view_src != op || v->type != GGML_TYPE_F32 ||+ d->type != GGML_TYPE_F32 || !ggml_is_contiguous(d) || ggml_nelements(d) != 3*nch ||+ v->ne[0] != 3 || v->ne[1] != nch || v->ne[2] != 1 || v->ne[3] != 1 ||+ v->nb[0] != sizeof(float) || v->nb[1] != op->nb[1] || cpy[j]->data != d->data) {+ return 0;+ }+ const size_t offs = (const char *) v->data - (const char *) op->data;+ if (offs % sizeof(float) != 0 || offs/sizeof(float) > 1) {+ return 0;+ }+ sidx[j] = (int32_t) (offs/sizeof(float));+ }++ ggml_tensor * conv = ctx->node(idx + 3);+ if (conv->op != GGML_OP_SSM_CONV || conv->src[0] != op || conv->type != GGML_TYPE_F32 ||+ conv->src[1]->type != GGML_TYPE_F32 || !ggml_is_contiguous(conv->src[1]) ||+ conv->src[1]->ne[0] != 4 || conv->src[1]->ne[1] != nch ||+ conv->ne[0] != nch || conv->ne[1] != 1 || conv->ne[2] != 1 || !ggml_is_contiguous(conv)) {+ return 0;+ }++ // conv followed by a silu that is its only consumer (as in ggml_metal_op_ssm_conv)+ ggml_tensor * out = conv;+ int n_fuse = 4;+ {+ static constexpr ggml_op ops[2] = { GGML_OP_SSM_CONV, GGML_OP_UNARY };+ if (ctx->can_fuse(idx + 3, ops, 2)) {+ ggml_tensor * un = ctx->node(idx + 4);+ if (ggml_get_unary_op(un) == GGML_UNARY_OP_SILU && un->src[0] == conv &&+ un->type == GGML_TYPE_F32 && ggml_is_contiguous(un) && ggml_are_same_shape(un, conv)) {+ out = un;+ n_fuse = 5;+ }+ }+ }++ for (int i = 1; i < n_fuse; ++i) {+ if (!ggml_metal_op_concurrency_check(ctx, ctx->node(idx + i))) {+ ggml_metal_op_concurrency_reset(ctx);+ }+ }++ ggml_metal_kargs_conv_state_step args = {+ /*.nch =*/ (int32_t) nch,+ /*.sA =*/ sidx[0],+ /*.sB =*/ sidx[1],+ /*.silu =*/ n_fuse == 5 ? 1 : 0,+ /*.nb00 =*/ s0->nb[0],+ /*.nb01 =*/ s0->nb[1],+ /*.nb11 =*/ s1->nb[1],+ /*.nb1 =*/ op->nb[1],+ };++ ggml_metal_encoder_t enc = ctx->enc;++ auto pipeline = ggml_metal_library_get_pipeline_conv_state_step(ctx->lib);++ ggml_metal_encoder_set_pipeline(enc, pipeline);+ ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), 0);+ ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(s0), 1);+ ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(s1), 2);+ ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op), 3);+ ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(cpy[0]), 4);+ ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(cpy[1]), 5);+ ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(conv->src[1]), 6);+ ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(out), 7);++ const int nth = 256;+ ggml_metal_encoder_dispatch_threadgroups(enc, (nch + nth - 1)/nth, 1, 1, nth, 1, 1);++ return n_fuse;+}+ int ggml_metal_op_concat(ggml_metal_op_t ctx, int idx) { ggml_tensor * op = ctx->node(idx); + {+ const int n_fuse = ggml_metal_op_conv_state_step(ctx, idx);+ if (n_fuse > 0) {+ return n_fuse;+ }+ }+ ggml_metal_library_t lib = ctx->lib; ggml_metal_encoder_t enc = ctx->enc; diff --git a/ggml/src/ggml-metal/kernels/dequantize.h b/ggml/src/ggml-metal/kernels/dequantize.hindex 70e773a21..88856df43 100644--- a/ggml/src/ggml-metal/kernels/dequantize.h+++ b/ggml/src/ggml-metal/kernels/dequantize.h@@ -45,10 +45,31 @@ void dequantize_bf16_t4(device const bfloat4 * src, short il, thread type4 & reg } #endif +// Q1_0 weights in Metal buffers are stored repacked (llama-model-loader.cpp, q1_0_repack_tiles): each+// 1024-weight tile of a row (8 blocks, 144 bytes) holds the 8 fp16 block scales (16 B), then the 8 x 16 B of+// sign bits. Tiles start 16-byte aligned, so the address the original layout gives block i of a tile,+// tile + 18*i, has (address & 15) == 2*i: every kernel keeps its block_q1_0 pointer arithmetic and finds+// the block's scale and bits from that address.+struct q1_0_loc {+ half d;+ device const uint8_t * qs;+};++static inline q1_0_loc q1_0_locate(device const block_q1_0 * xb) {+ device const char * p = (device const char *) xb;+ const short i = (short) ((((ulong) p) & 15) >> 1);+ device const char * tile = p - 18*i;+ q1_0_loc res;+ res.d = ((device const half *) tile)[i];+ res.qs = (device const uint8_t *) (tile + 16 + 16*i);+ return res;+}+ template <typename type4x4> void dequantize_q1_0(device const block_q1_0 * xb, short il, thread type4x4 & reg) {- device const uint8_t * qs = xb->qs;- const float d = xb->d;+ const q1_0_loc blk = q1_0_locate(xb);+ device const uint8_t * qs = blk.qs;+ const float d = blk.d; const float neg_d = -d; const int byte_offset = il * 2; // il*16 bits = il*2 bytes@@ -80,10 +101,11 @@ void dequantize_q1_0(device const block_q1_0 * xb, short il, thread type4x4 & re template <typename type4> void dequantize_q1_0_t4(device const block_q1_0 * xb, short il, thread type4 & reg) {- const float d = xb->d;+ const q1_0_loc blk = q1_0_locate(xb);+ const float d = blk.d; const float neg_d = -d; const int base = il * 4;- const uint8_t byte = xb->qs[base / 8];+ const uint8_t byte = blk.qs[base / 8]; const int s = base % 8; float4 reg_f;diff --git a/ggml/src/ggml-metal/kernels/mul_mv.metal b/ggml/src/ggml-metal/kernels/mul_mv.metalindex d204fff39..1248901a4 100644--- a/ggml/src/ggml-metal/kernels/mul_mv.metal+++ b/ggml/src/ggml-metal/kernels/mul_mv.metal@@ -2,7 +2,8 @@ #include "dequantize.h" // Q1_0 dot product: dot = d * (2 * Σ(yl[i] where bit=1) - sumy) inline float block_q_n_dot_y(device const block_q1_0 * qb_curr, float sumy, thread float * yl, int il) {- device const uint8_t * qs = qb_curr->qs + il / 8;+ const q1_0_loc blk = q1_0_locate(qb_curr);+ device const uint8_t * qs = blk.qs + il / 8; const uint8_t b0 = qs[0]; const uint8_t b1 = qs[1]; @@ -26,7 +27,7 @@ inline float block_q_n_dot_y(device const block_q1_0 * qb_curr, float sumy, thre acc += select(0.0f, yl[14], bool(b1 & 0x40)); acc += select(0.0f, yl[15], bool(b1 & 0x80)); - return qb_curr->d * (2.0f * acc - sumy);+ return blk.d * (2.0f * acc - sumy); } // Q2_0 dot: d * (sum_lo(y) + 2*sum_hi(y) - sumy) via per-bit conditional adds@@ -430,6 +431,110 @@ kernel void kernel_mul_mv_q1_0_f32( kernel_mul_mv_q1_0_f32_impl<N_R0_Q1_0, constant ggml_metal_kargs_mul_mv &>(args, src0, src1, dst, nullptr, tgpig, tiisg, sgitg); } +// Q1_0 single-column mat-vec through a lookup table (decode, ne11 == 1), on the repacked layout+// (see q1_0_locate in dequantize.h): a row's 1024-wide K tile is 16 B of block scales, then 128 B of bits.+// The bit-select dot (block_q_n_dot_y) costs ~3 ALU ops per weight, which caps it well below the memory+// bandwidth. Here the threadgroup first builds, for each group of 4 consecutive src1 values of the tile, the+// 16 signed sums +-y0 +-y1 +-y2 +-y3 in threadgroup memory; then every 4 weight bits of every row cost one+// table read and one add. Same math as block_q_n_dot_y: d*(2*sum(y where bit=1) - sum(y)) == d*sum(+-y), fp32.+// Lane l of a row reads the tile's bits 32l..32l+31 (block l/4) with one coalesced 32-bit load: 8 nibbles,+// groups g = 8l + j. Table layout tab[n*GT + pos], pos = (g%8)*32 + (g/8 + 4*(g%8))%32: both the build+// (consecutive g) and the lookups (lane l reads g = 8l + j) hit 32 different banks.+template<short NR>+kernel void kernel_mul_mv_q1_0_f32_lut(+ constant ggml_metal_kargs_mul_mv & args,+ device const char * src0,+ device const char * src1,+ device char * dst,+ threadgroup char * shmem [[threadgroup(0)]],+ uint3 tgpig[[threadgroup_position_in_grid]],+ ushort tiisg[[thread_index_in_simdgroup]],+ ushort sgitg[[simdgroup_index_in_threadgroup]]) {+ const short NSG = FC_mul_mv_nsg;++ constexpr short KT = 1024;+ constexpr short GT = KT/4; // groups of 4 per tile+ constexpr short TB = 144; // bytes per row tile++ threadgroup float * tab = (threadgroup float *) shmem;++ const int r1 = tgpig.y;++ const int first_row = (tgpig.x*NSG + sgitg)*NR;+ const short tid = sgitg*N_SIMDWIDTH + tiisg;++ device const float * y = (device const float *) (src1 + (uint64_t) r1*args.nb11);++ device const char * ax[NR];+ FOR_UNROLL (short r = 0; r < NR; ++r) {+ const int row = min(first_row + r, args.ne01 - 1);+ ax[r] = src0 + (uint64_t) row*args.nb01;+ }++ float acc[NR] = { 0.f };++ const int ntiles = args.ne00/KT;++ // table offsets of the lane's groups j and j + 4, packed in the two 16-bit halves+ uint offp[4];+ FOR_UNROLL (short j = 0; j < 4; ++j) {+ offp[j] = (uint) (j*32 + ((tiisg + 4*j) & 31)) | ((uint) ((j + 4)*32 + ((tiisg + 4*(j + 4)) & 31)) << 16);+ }++ for (int t = 0; t < ntiles; ++t) {+ uint u [NR];+ half dh[NR];+ FOR_UNROLL (short r = 0; r < NR; ++r) {+ device const char * tb = ax[r] + t*TB;+ dh[r] = ((device const half *) tb)[tiisg/4];+ u [r] = ((device const uint *) (tb + 16))[tiisg];+ }++ threadgroup_barrier(mem_flags::mem_threadgroup);++ for (short g = tid; g < GT; g += NSG*N_SIMDWIDTH) {+ const float4 yv = ((device const float4 *) (y + t*KT))[g];+ const float a[4] = { -yv[0] - yv[1], yv[0] - yv[1], -yv[0] + yv[1], yv[0] + yv[1] };+ const float b[4] = { -yv[2] - yv[3], yv[2] - yv[3], -yv[2] + yv[3], yv[2] + yv[3] };+ const short pos = (g%8)*32 + ((g/8 + 4*(g%8)) & 31);+ FOR_UNROLL (short n = 0; n < 16; ++n) {+ tab[n*GT + pos] = a[n%4] + b[n/4];+ }+ }++ threadgroup_barrier(mem_flags::mem_threadgroup);++ FOR_UNROLL (short r = 0; r < NR; ++r) {+ // two table indices per 32-bit op: nibbles j and j + 4 land in the two 16-bit halves as n*GT+ const uint w = u[r];+ const uint m = 0x0F000F00u;+ const ushort2 x0 = as_type<ushort2>(((w << 8) & m) | offp[0]);+ const ushort2 x1 = as_type<ushort2>(((w << 4) & m) | offp[1]);+ const ushort2 x2 = as_type<ushort2>(((w ) & m) | offp[2]);+ const ushort2 x3 = as_type<ushort2>(((w >> 4) & m) | offp[3]);+ const float s = ((tab[x0[0]] + tab[x0[1]]) + (tab[x1[0]] + tab[x1[1]]))+ + ((tab[x2[0]] + tab[x2[1]]) + (tab[x3[0]] + tab[x3[1]]));+ acc[r] += (float) dh[r] * s;+ }+ }++ device float * dst_f32 = (device float *) dst + (uint64_t) r1*args.ne0;++ FOR_UNROLL (short r = 0; r < NR; ++r) {+ const float tot = simd_sum(acc[r]);++ if (tiisg == 0 && first_row + r < args.ne01) {+ dst_f32[first_row + r] = tot;+ }+ }+}++typedef decltype(kernel_mul_mv_q1_0_f32_lut<4>) kernel_mul_mv_q1_0_f32_lut_t;++template [[host_name("kernel_mul_mv_q1_0_f32_lut_2")]] kernel kernel_mul_mv_q1_0_f32_lut_t kernel_mul_mv_q1_0_f32_lut<2>;+template [[host_name("kernel_mul_mv_q1_0_f32_lut_4")]] kernel kernel_mul_mv_q1_0_f32_lut_t kernel_mul_mv_q1_0_f32_lut<4>;+template [[host_name("kernel_mul_mv_q1_0_f32_lut_8")]] kernel kernel_mul_mv_q1_0_f32_lut_t kernel_mul_mv_q1_0_f32_lut<8>;+ // Q1_0 multi-column mat-vec: each q1_0 block is read once and dotted against nr1 // src1 columns (the spec-decode verify batch, ne11 = k+1 rows). tpb threads // cooperate on one block, slice width SW = QK1_0/tpb. Register budget (M5 Pro):@@ -506,14 +611,14 @@ void kernel_mul_mv_q1_0_f32_nc_impl( } FOR_UNROLL (short row = 0; row < nr0; row++) {- device const block_q1_0 * qb = ax[row] + ib;- device const uint8_t * qs = qb->qs + il/8;+ const q1_0_loc blk = q1_0_locate(ax[row] + ib);+ device const uint8_t * qs = blk.qs + il/8; uint8_t b[SW/8]; FOR_UNROLL (short i = 0; i < SW/8; i++) { b[i] = qs[i]; }- const float d = qb->d;+ const float d = blk.d; FOR_UNROLL (short c = 0; c < nr1; c++) { sumf[row][c] += q1_0_dot_y_sw<SW>(b, d, sumy[c], yl[c]);@@ -681,8 +786,8 @@ void kernel_mul_mv_q1_0_f32_pc_impl( int pcw[nr0]; FOR_UNROLL (short row = 0; row < nr0; row++) {- device const block_q1_0 * qb = ax[row] + ib;- device const uint8_t * qs = qb->qs; // 2-byte aligned: assemble from bytes+ const q1_0_loc blk = q1_0_locate(ax[row] + ib);+ device const uint8_t * qs = blk.qs; // 2-byte aligned: assemble from bytes int pc = 0; FOR_UNROLL (short j = 0; j < 4; j++) {@@ -692,7 +797,7 @@ void kernel_mul_mv_q1_0_f32_pc_impl( pc += popcount(wj); } - d [row] = qb->d;+ d [row] = blk.d; pcw[row] = pc; } diff --git a/ggml/src/ggml-metal/kernels/ssm.metal b/ggml/src/ggml-metal/kernels/ssm.metalindex b89be5454..8a4768412 100644--- a/ggml/src/ggml-metal/kernels/ssm.metal+++ b/ggml/src/ggml-metal/kernels/ssm.metal@@ -66,6 +66,41 @@ kernel void kernel_ssm_conv_f32_f32_4( x[0] = FC_ssm_conv_silu ? sumf / (1.0f + exp(-sumf)) : sumf; } +// Decode (one token) conv-state step of the gated delta net in one thread per channel: the graph's+// CONCAT(state[3], x) -> two CPYs of 3-wide windows into the state cache slots -> SSM_CONV (+ SILU).+// Same math as kernel_ssm_conv_f32_f32_4: dot(conv input row, kernel row), then the same silu.+kernel void kernel_conv_state_step_f32(+ constant ggml_metal_kargs_conv_state_step & args,+ device const char * src0,+ device const char * src1,+ device char * cin,+ device float * dstA,+ device float * dstB,+ device const float4 * w,+ device float * dst,+ uint i[[thread_position_in_grid]]) {+ if ((int) i >= args.nch) {+ return;+ }++ device const char * s = src0 + i*args.nb01;+ const float4 v = float4(*(device const float *) (s),+ *(device const float *) (s + args.nb00),+ *(device const float *) (s + 2*args.nb00),+ *(device const float *) (src1 + i*args.nb11));++ *(device float4 *) (cin + i*args.nb1) = v;++ FOR_UNROLL (short k = 0; k < 3; ++k) {+ dstA[3*i + k] = v[args.sA + k];+ dstB[3*i + k] = v[args.sB + k];+ }++ const float sumf = dot(v, w[i]);++ dst[i] = args.silu ? sumf / (1.0f + exp(-sumf)) : sumf;+}+ constant short FC_ssm_conv_bs [[function_constant(FC_SSM_CONV + 0)]]; // Batched version: each threadgroup processes multiple tokens for better efficiencydiff --git a/src/llama-model-loader.cpp b/src/llama-model-loader.cppindex 23d74c30a..ada919e6d 100644--- a/src/llama-model-loader.cpp+++ b/src/llama-model-loader.cpp@@ -1440,6 +1440,36 @@ void llama_model_loader::load_data_for(struct ggml_tensor * cur) const { } } +// Q1_0 weights in Metal buffers use the repacked layout the Metal kernels read (q1_0_locate in+// ggml-metal kernels/dequantize.h): each 1024-weight tile of a row, 8 blocks of {fp16 d, 16 B bits} = 144 B,+// is rewritten as the 8 scales (16 B) followed by the 8 x 16 B of bits. Same bytes, same size.+static bool q1_0_metal_repack(const ggml_tensor * cur) {+ if (cur->type != GGML_TYPE_Q1_0 || cur->buffer == nullptr) {+ return false;+ }+ const char * name = ggml_backend_buft_name(ggml_backend_buffer_get_type(cur->buffer));+ return strncmp(name, "MTL", 3) == 0;+}++static void q1_0_repack_tiles(void * data, const ggml_tensor * cur) {+ constexpr size_t BS = 18; // block_q1_0: fp16 d, then 16 bytes of bits+ constexpr size_t TB = 8*BS; // 144 bytes per 1024-weight tile+ if (cur->ne[0] % 1024 != 0 || !ggml_is_contiguous(cur)) {+ throw std::runtime_error(format("tensor '%s': the Metal Q1_0 kernels need ne0 %% 1024 == 0 and a contiguous tensor",+ ggml_get_name(cur)));+ }+ const size_t ntiles = ggml_nbytes(cur)/TB;+ uint8_t * p = (uint8_t *) data;+ uint8_t tmp[TB];+ for (size_t t = 0; t < ntiles; ++t, p += TB) {+ memcpy(tmp, p, TB);+ for (int i = 0; i < 8; ++i) {+ memcpy(p + 2*i, tmp + i*BS, 2);+ memcpy(p + 16 + 16*i, tmp + i*BS + 2, 16);+ }+ }+}+ bool llama_model_loader::load_all_data( struct ggml_context * ctx, llama_buf_map & bufs,@@ -1585,6 +1615,11 @@ bool llama_model_loader::load_all_data( } GGML_ASSERT(buf_mmap || cur->data); // either we have a buffer to allocate the tensor in, or it is already allocated+ if (q1_0_metal_repack(cur) || (buf_mmap && cur->type == GGML_TYPE_Q1_0 &&+ strncmp(ggml_backend_buft_name(ggml_backend_buffer_get_type(buf_mmap)), "MTL", 3) == 0)) {+ throw std::runtime_error(format("tensor '%s': Q1_0 weights on Metal need load_mode NONE, not mmap (repacked layout)",+ ggml_get_name(cur)));+ } if (buf_mmap && cur->data == nullptr) { ggml_backend_tensor_alloc(buf_mmap, cur, data); if (lmlocks) {@@ -1609,6 +1644,15 @@ bool llama_model_loader::load_all_data( return std::make_pair(cur, ggml_validate_row_data(cur->type, cur->data, n_size)); })); }+ } else if (q1_0_metal_repack(cur)) {+ read_buf.resize(n_size);+ file->seek(weight->offs, SEEK_SET);+ file->read_raw(read_buf.data(), n_size);+ if (check_tensors && !ggml_validate_row_data(cur->type, read_buf.data(), n_size)) {+ throw std::runtime_error(format("tensor '%s' has invalid data", ggml_get_name(cur)));+ }+ q1_0_repack_tiles(read_buf.data(), cur);+ ggml_backend_tensor_set(cur, read_buf.data(), 0, n_size); } else { // If upload_backend is valid load the tensor in chunks to pinned memory and upload the buffers asynchronously to the GPU. if (upload_backend) {123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>nnopt report · prism-ml/Bonsai-27B-gguf</title><link rel="preconnect" href="https://fonts.googleapis.com"><link rel="preconnect" href="https://fonts.gstatic.com" crossorigin><link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500;600&family=IBM+Plex+Sans+Condensed:wght@600;700&family=IBM+Plex+Sans:wght@400;500;600&display=swap"><style>:root { --bg: #f3f5f2; --panel: #ffffff; --ink: #17201d; --ink-2: #33403b; --muted: #5a6762; --line: #cfd8d3; --accent: #0b6e79; --accent-soft: #dcefee; --keep: #1d7a3e; --keep-soft: #dcf1e2; --stop: #b3261e; --stop-soft: #f9dedb; --warn: #9a5b00; --warn-soft: #fbecd2; --grid: #e3e9e5; --display: "IBM Plex Sans Condensed", "Arial Narrow", system-ui, sans-serif; --body: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif; --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace; color-scheme: light;}@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --bg: #111715; --panel: #18201d; --ink: #e4ebe7; --ink-2: #c3cec9; --muted: #9aa8a2; --line: #2c3833; --accent: #4fc1cc; --accent-soft: #123236; --keep: #6fd394; --keep-soft: #143222; --stop: #ff8a80; --stop-soft: #3d1715; --warn: #f0b45a; --warn-soft: #3a2a10; --grid: #222c28; color-scheme: dark; }}:root[data-theme="dark"] { --bg: #111715; --panel: #18201d; --ink: #e4ebe7; --ink-2: #c3cec9; --muted: #9aa8a2; --line: #2c3833; --accent: #4fc1cc; --accent-soft: #123236; --keep: #6fd394; --keep-soft: #143222; --stop: #ff8a80; --stop-soft: #3d1715; --warn: #f0b45a; --warn-soft: #3a2a10; --grid: #222c28; color-scheme: dark;}* { box-sizing: border-box; }body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.55 var(--body); }.wrap { max-width: 1040px; margin: 0 auto; padding: 28px 20px 80px; display: grid; gap: 36px; }h1, h2, h3 { font-family: var(--display); margin: 0; line-height: 1.15; text-wrap: balance; }h1 { font-size: clamp(28px, 4.5vw, 40px); font-weight: 700; letter-spacing: -0.01em; }h2 { font-size: 22px; font-weight: 600; }h3 { font-size: 16px; font-weight: 600; }p { margin: 0; max-width: 72ch; }code, .mono { font-family: var(--mono); font-size: 0.88em; }.eyebrow { font: 500 12px var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }.sub { color: var(--muted); font-size: 13px; }section { display: grid; gap: 14px; min-width: 0; }header { display: grid; gap: 10px; }.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; display: grid; gap: 4px; min-width: 0; }.tile .v { font: 700 26px/1.1 var(--display); font-variant-numeric: tabular-nums; }.tile .k { font: 500 12px var(--mono); color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }.tile.pass { border-color: var(--keep); background: var(--keep-soft); }.tile.fail { border-color: var(--stop); background: var(--stop-soft); }.tile.na { border-style: dashed; }.badge { display: inline-flex; align-items: center; gap: 6px; font: 600 12px/1 var(--mono); padding: 4px 8px; border-radius: 99px; border: 1px solid currentColor; white-space: nowrap; }.badge.pass { color: var(--keep); } .badge.fail { color: var(--stop); } .badge.skip { color: var(--muted); } .badge.warn { color: var(--warn); }.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 4px 0; overflow-x: auto; }table { border-collapse: collapse; width: 100%; font-size: 14px; }th, td { text-align: left; padding: 8px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }tr:last-child td { border-bottom: 0; }th { font: 500 12px var(--mono); color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }td.num { font-family: var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }.flags { display: grid; gap: 6px; }.flag { border-left: 3px solid var(--warn); background: var(--warn-soft); padding: 8px 12px; border-radius: 4px; font-size: 14px; }.flag.bad { border-color: var(--stop); background: var(--stop-soft); }.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 12px; }.chart { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px 8px; display: grid; gap: 6px; min-width: 0; }.chart svg { width: 100%; height: auto; display: block; overflow: visible; }.chart .ln { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }.chart .pt { fill: var(--accent); stroke: var(--panel); stroke-width: 2; }.chart .hit { fill: transparent; }.chart .hit:hover + .pt, .chart .pt:hover { r: 5; }.chart .gl { stroke: var(--grid); stroke-width: 1; }.chart text { fill: var(--muted); font: 11px var(--mono); }details { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; }summary { cursor: pointer; font-weight: 500; }pre { font: 12px/1.5 var(--mono); white-space: pre-wrap; word-break: break-word; margin: 10px 0 0; color: var(--ink-2); }.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; font-size: 14px; }.kv dt { color: var(--muted); font: 500 12px/1.9 var(--mono); text-transform: uppercase; letter-spacing: .05em; }.kv dd { margin: 0; font-family: var(--mono); font-size: 13px; word-break: break-all; }footer { color: var(--muted); font-size: 12px; }.figs { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }figure { margin: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px; display: grid; gap: 8px; min-width: 0; }figure svg { width: 100%; height: auto; display: block; border-radius: 4px; }figure .frame { fill: var(--grid); }figcaption { font-size: 13px; color: var(--ink-2); display: grid; gap: 2px; }.box { fill: none; stroke-width: 2; vector-effect: non-scaling-stroke; }.box.ref { stroke: var(--ink); stroke-dasharray: 6 4; }.box.ref.missed { stroke: var(--stop); stroke-width: 3; }.box.port { stroke: var(--accent); }.box.port.extra { stroke: var(--warn); stroke-width: 3; }.box.borderline { stroke: var(--muted); stroke-width: 1; opacity: .7; }.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; font: 12px var(--mono); color: var(--muted); }.legend i { display: inline-block; width: 18px; height: 0; vertical-align: middle; margin-right: 6px; border-top: 2px solid; }.vlm { display: grid; grid-template-columns: minmax(120px, 200px) 1fr; gap: 12px; align-items: start; }.vlm img { width: 100%; border-radius: 4px; display: block; }.said { display: grid; gap: 6px; font-size: 14px; }.said .who { font: 500 11px var(--mono); color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }.said p { white-space: pre-wrap; word-break: break-word; }mark { background: var(--stop-soft); color: var(--ink); border-bottom: 2px solid var(--stop); padding: 0 1px; }@media (max-width: 560px) { .vlm { grid-template-columns: 1fr; } }@media print { body { background: #fff; } .wrap { padding: 0; } }</style></head><body><main class="wrap"><header><span class="eyebrow">nnopt verification report · Text to text</span><h1>prism-ml/Bonsai-27B-gguf on mac-mini-m2pro</h1><p class="sub">Job NN-53D464 · 2026-10-16 07:42 UTC ·nnopt-verify 0.1.0 · reference bundle <span class="mono">b8e1d595699387ed</span></p></header><div class="tiles"><div class="tile pass"><span class="k">Correctness</span><span class="v">PASS</span><span class=sub>original precision policy</span></div><div class="tile pass"><span class="k">Speed target</span><span class="v">MET</span><span class=sub>Decode speed 29.38 tok/s vs 19.02 tok/s required</span></div><div class="tile pass"><span class="k">Runtime</span><span class="v">PASS</span><span class=sub>llama.cpp, as asked</span></div><div class="tile "><span class="k">Decode</span><span class="v">29.38 tok/s</span><span class=sub>warm, median</span></div><div class="tile "><span class="k">Peak memory</span><span class="v">4532 MB</span><span class=sub>process tree</span></div><div class="tile "><span class="k">Load time</span><span class="v">1038 ms</span></div></div><section><h2>Correctness</h2><p>The port ran on 20 inputs (6 hidden, generated fresh for this job and never shown to theporting agent) and was compared with the reference outputs captured from your code. Thresholds are for the<b>original</b> precision policy.</p><div class="panel"><table><thead><tr><th>Check</th><th>Value</th><th>Threshold</th><th>Result</th></tr></thead><tbody><tr><td>All cases ran<div class=sub>20/20 cases produced valid output</div></td><td class=num>1.00</td><td class=num>>= 1.00</td><td><span class="badge pass">✓ PASS</span></td></tr><tr><td>Tokenizer matches<div class=sub>prompt token ids identical</div></td><td class=num>1.00</td><td class=num>>= 1.00</td><td><span class="badge pass">✓ PASS</span></td></tr><tr><td>Next-token agreement (teacher-forced)<div class=sub>teacher-forced top-1 agreement over 1862 positions (0 near-ties forgiven)</div></td><td class=num>1.00</td><td class=num>>= 0.980</td><td><span class="badge pass">✓ PASS</span></td></tr><tr><td>Top-k overlap<div class=sub>mean top-10 overlap</div></td><td class=num>1.00</td><td class=num>>= 0.900</td><td><span class="badge pass">✓ PASS</span></td></tr><tr><td>Greedy continuation matched<div class=sub>mean matched prefix of 32 greedy tokens; 100% of prompts exact</div></td><td class=num>1.00</td><td class=num>>= 0.750</td><td><span class="badge pass">✓ PASS</span></td></tr></tbody></table></div><details><summary>Per-case results (20 cases)</summary><div class="panel" style="margin-top:10px"><table><thead><tr><th>Case</th><th>Split</th><th>Agreement</th><th>Top-k overlap</th><th>Greedy</th><th>Tokens</th></tr></thead><tbody><tr><td class=num>p000</td><td>public · builtin</td><td class=num>1.00</td><td class=num>1.00</td><td class=num>1.00</td><td class=num>yes</td></tr><tr><td class=num>p001</td><td>public · builtin</td><td class=num>1.00</td><td class=num>1.00</td><td class=num>1.00</td><td class=num>yes</td></tr><tr><td class=num>p002</td><td>public · customer</td><td class=num>1.00</td><td class=num>1.00</td><td class=num>1.00</td><td class=num>yes</td></tr><tr><td class=num>p003</td><td>public · customer</td><td class=num>1.00</td><td class=num>1.00</td><td class=num>1.00</td><td class=num>yes</td></tr><tr><td class=num>p004</td><td>public · customer</td><td class=num>1.00</td><td class=num>1.00</td><td class=num>1.00</td><td class=num>yes</td></tr><tr><td class=num>p005</td><td>public · customer</td><td class=num>1.00</td><td class=num>1.00</td><td class=num>1.00</td><td class=num>yes</td></tr><tr><td class=num>p006</td><td>public · customer</td><td class=num>1.00</td><td class=num>1.00</td><td class=num>1.00</td><td class=num>yes</td></tr><tr><td class=num>p007</td><td>public · customer</td><td class=num>1.00</td><td class=num>1.00</td><td class=num>1.00</td><td class=num>yes</td></tr><tr><td class=num>p008</td><td>public · customer</td><td class=num>1.00</td><td class=num>1.00</td><td class=num>1.00</td><td class=num>yes</td></tr><tr><td class=num>p009</td><td>public · customer</td><td class=num>1.00</td><td class=num>1.00</td><td class=num>1.00</td><td class=num>yes</td></tr><tr><td class=num>p010</td><td>public · customer</td><td class=num>1.00</td><td class=num>1.00</td><td class=num>1.00</td><td class=num>yes</td></tr><tr><td class=num>p011</td><td>public · customer</td><td class=num>1.00</td><td class=num>1.00</td><td class=num>1.00</td><td class=num>yes</td></tr><tr><td class=num>p012</td><td>public · customer</td><td class=num>1.00</td><td class=num>1.00</td><td class=num>1.00</td><td class=num>yes</td></tr><tr><td class=num>p013</td><td>public · customer</td><td class=num>1.00</td><td class=num>1.00</td><td class=num>1.00</td><td class=num>yes</td></tr><tr><td class=num>h000</td><td>hidden · generated</td><td class=num>1.00</td><td class=num>1.00</td><td class=num>1.00</td><td class=num>yes</td></tr><tr><td class=num>h001</td><td>hidden · generated</td><td class=num>1.00</td><td class=num>1.00</td><td class=num>1.00</td><td class=num>yes</td></tr><tr><td class=num>h002</td><td>hidden · generated</td><td class=num>1.00</td><td class=num>1.00</td><td class=num>1.00</td><td class=num>yes</td></tr><tr><td class=num>h003</td><td>hidden · generated</td><td class=num>1.00</td><td class=num>1.00</td><td class=num>1.00</td><td class=num>yes</td></tr><tr><td class=num>h004</td><td>hidden · generated</td><td class=num>1.00</td><td class=num>1.00</td><td class=num>1.00</td><td class=num>yes</td></tr><tr><td class=num>h005</td><td>hidden · generated</td><td class=num>1.00</td><td class=num>1.00</td><td class=num>1.00</td><td class=num>yes</td></tr></tbody></table></div></details></section><section><h2>Runtime</h2><p>Asked for <b>Metal (llama.cpp fork)</b>. Clean build, the port's own code and build log: uses llama.cpp.</p><ul><li class="mono">src/runner.cpp:164: llama_model * model = llama_model_load_from_file(model_path.c_str(), mparams);</li><li class="mono">build log: [ 98%] Linking CXX static library libllama.a</li></ul></section><section><h2>Speed and memory</h2><p>2 warm-up runs, then 5 timed runs of 3 requests each (the firstrequest of each run is cold). Timed on the device's own clock.</p><div class="panel"><table><thead><tr><th>Metric (warm requests)</th><th>Median</th><th>p10</th><th>p90</th><th>n</th></tr></thead><tbody><tr><td>Decode speed</td><td class=num>29.38 tok/s</td><td class=num>26.49 tok/s</td><td class=num>29.99 tok/s</td><td class=num>10</td></tr><tr><td>Prefill speed</td><td class=num>86.04 tok/s</td><td class=num>86.01 tok/s</td><td class=num>86.38 tok/s</td><td class=num>10</td></tr><tr><td>Time to first token</td><td class=num>1825 ms</td><td class=num>1818 ms</td><td class=num>1825 ms</td><td class=num>10</td></tr><tr><td>End-to-end speed</td><td class=num>20.85 tok/s</td><td class=num>19.34 tok/s</td><td class=num>21.14 tok/s</td><td class=num>10</td></tr><tr><td>Request time</td><td class=num>6138 ms</td><td class=num>6054 ms</td><td class=num>6619 ms</td><td class=num>10</td></tr><tr><td>Time to first token (cold)</td><td class=num>1810 ms</td><td class=num>1810 ms</td><td class=num>1810 ms</td><td class=num>5</td></tr><tr><td>Load time</td><td class=num>1038 ms</td><td class=num>1032 ms</td><td class=num>1044 ms</td><td class=num>5</td></tr><tr><td>Process wall time</td><td class=num>20361 ms</td><td class=num>19901 ms</td><td class=num>20521 ms</td><td class=num>5</td></tr><tr><td>Peak RSS (process tree)</td><td class=num>4532 MB</td><td></td><td></td><td></td></tr><tr><td>Peak memory (self-reported)</td><td class=num>4530 MB</td><td></td><td></td><td></td></tr></tbody></table></div><p class="sub">External cross-check (paired --max-new-tokens N vs 1, 5 pairs, device clock): Decode speed: 27.60 tok/s. Graded values are capped by it.</p><p class="sub">Roofline: not computed (no environment specs or model facts were given).</p></section><section><h2>Sustained run</h2><p>The model ran continuously while the kit sampled temperature,clocks and power.</p><div class="charts"><div class="chart"><h3>Decode speed over time</h3><svg viewBox="0 0 460 190" role="img" aria-label="Decode speed over time"><line class="gl" x1="46" x2="448" y1="164.0" y2="164.0"/><text x="40" y="168.0" text-anchor="end">30</text><line class="gl" x1="46" x2="448" y1="125.5" y2="125.5"/><text x="40" y="129.5" text-anchor="end">30</text><line class="gl" x1="46" x2="448" y1="87.0" y2="87.0"/><text x="40" y="91.0" text-anchor="end">30</text><line class="gl" x1="46" x2="448" y1="48.5" y2="48.5"/><text x="40" y="52.5" text-anchor="end">30</text><line class="gl" x1="46" x2="448" y1="10.0" y2="10.0"/><text x="40" y="14.0" text-anchor="end">30</text><text x="46.0" y="182" text-anchor="middle">32s</text><text x="146.5" y="182" text-anchor="middle">174s</text><text x="247.0" y="182" text-anchor="middle">317s</text><text x="347.5" y="182" text-anchor="middle">459s</text><text x="448.0" y="182" text-anchor="middle">602s</text><path class="ln" d="M46.0,106.7 L90.3,67.3 L134.7,67.3 L179.7,67.3 L224.8,106.7 L269.3,146.2 L314.2,146.2 L359.0,27.8 L403.2,146.2 L448.0,146.2"/><g><title>32 s: 30 tok/s</title><circle class="hit" cx="46.0" cy="106.7" r="10"/><circle class="pt" cx="46.0" cy="106.7" r="4"/></g><g><title>95 s: 30 tok/s</title><circle class="hit" cx="90.3" cy="67.3" r="10"/><circle class="pt" cx="90.3" cy="67.3" r="4"/></g><g><title>158 s: 30 tok/s</title><circle class="hit" cx="134.7" cy="67.3" r="10"/><circle class="pt" cx="134.7" cy="67.3" r="4"/></g><g><title>221 s: 30 tok/s</title><circle class="hit" cx="179.7" cy="67.3" r="10"/><circle class="pt" cx="179.7" cy="67.3" r="4"/></g><g><title>285 s: 30 tok/s</title><circle class="hit" cx="224.8" cy="106.7" r="10"/><circle class="pt" cx="224.8" cy="106.7" r="4"/></g><g><title>348 s: 30 tok/s</title><circle class="hit" cx="269.3" cy="146.2" r="10"/><circle class="pt" cx="269.3" cy="146.2" r="4"/></g><g><title>412 s: 30 tok/s</title><circle class="hit" cx="314.2" cy="146.2" r="10"/><circle class="pt" cx="314.2" cy="146.2" r="4"/></g><g><title>476 s: 30 tok/s</title><circle class="hit" cx="359.0" cy="27.8" r="10"/><circle class="pt" cx="359.0" cy="27.8" r="4"/></g><g><title>538 s: 30 tok/s</title><circle class="hit" cx="403.2" cy="146.2" r="10"/><circle class="pt" cx="403.2" cy="146.2" r="4"/></g><g><title>602 s: 30 tok/s</title><circle class="hit" cx="448.0" cy="146.2" r="10"/><circle class="pt" cx="448.0" cy="146.2" r="4"/></g></svg></div></div><dl class="kv"><dt>Duration</dt><dd>633.2 s</dd><dt>Runs</dt><dd>10</dd><dt>Sustained / initial speed</dt><dd>100.0%</dd><dt>Max temperature</dt><dd>–</dd><dt>GPU clock min / max</dt><dd>– / –</dd><dt>Mean power</dt><dd>–</dd><dt>Energy per token</dt><dd>–</dd></dl></section><section><h2>Environment and reproducibility</h2><dl class="kv"><dt>device</dt><dd>Mac mini (M2 Pro)</dd><dt>gpu</dt><dd>Apple M2 Pro GPU, 19 cores</dd><dt>name</dt><dd>Mac mini (M2 Pro)</dd><dt>executor</dt><dd>local</dd><dt>os</dt><dd>darwin</dd><dt>reference python</dt><dd>3.12.14</dd><dt>reference numpy</dt><dd>2.5.4</dd><dt>reference nnopt_verify</dt><dd>0.1.0</dd><dt>reference platform</dt><dd>macOS-27.0.1-arm64-arm-64bit</dd></dl><p class="sub">reproduce.sh re-runs the check and benchmark against the same frozen reference bundle; results.csv and results.json hold every number in this report.</p></section><footer>Generated by nnopt-verify 0.1.0. Correctness is graded on all inputs; speed figures are medians of warm requests unless marked cold.</footer></main></body></html>1234567891011121314#!/bin/sh# Reproduce the numbers in report.html with nnopt-verify 0.1.0.# Needs: the frozen reference bundle, the port deployed on the device (./deploy.sh), and the device reachable.# Connection: this machine.set -eBUNDLE=${BUNDLE:-./reference-bundle} # bundle digest b8e1d595699387ed56affd6be5a6b8698a0229f4007f8f68156d694d690355c3PORT_DIR=${PORT_DIR:-/tmp/nnopt-device/port} # where deploy.sh put the portOUT=${OUT:-./reproduced}mkdir -p "$OUT"
nnopt-verify check --bundle "$BUNDLE" --port "$PORT_DIR" --executor local --precision original --split all --out "$OUT/check.json"nnopt-verify bench --bundle "$BUNDLE" --port "$PORT_DIR" --executor local --warmup 2 --runs 5 --repeat 3 --max-new-tokens 128 --sustained-s 600.0 --env-specs '{"device": "Mac mini (M2 Pro)", "gpu": "Apple M2 Pro GPU, 19 cores", "name": "Mac mini (M2 Pro)"}' --out "$OUT/bench.json"nnopt-verify grade --check "$OUT/check.json" --bench "$OUT/bench.json" --speed-target '{"metric": "tokens_per_s", "value": 19.02, "direction": "higher"}' --out "$OUT/grade.json"nnopt-verify report --check "$OUT/check.json" --bench "$OUT/bench.json" --grade "$OUT/grade.json" --bundle "$BUNDLE" --out "$OUT/report"123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081section,name,value,unit_or_op,threshold,passed
grade,correctness,True,,,True
grade,speed_target_met,True,,,True
check,cases_completed,1.0,>=,1.0,True
check,tokenizer_match,1.0,>=,1.0,True
check,next_token_agreement,1.0,>=,0.98,True
check,topk_overlap,1.0,>=,0.9,True
check,greedy_prefix,1.0,>=,0.75,True
check_metric,tokenizer_match,1.0,,,
check_metric,next_token_agreement,1.0,,,
check_metric,topk_overlap,1.0,,,
check_metric,greedy_prefix,1.0,,,
check_metric,greedy_exact,1.0,,,
check_metric,positions,1862,,,
check_metric,ties_forgiven,0,,,
check_metric,top_k,10,,,
bench,tokens_per_s.median,29.3804,tok/s,,
bench,tokens_per_s.p10,26.4903,tok/s,,
bench,tokens_per_s.p90,29.9945,tok/s,,
bench,tokens_per_s.min,26.3562,tok/s,,
bench,tokens_per_s.max,30.0148,tok/s,,
bench,tokens_per_s.n,10,tok/s,,
bench,prefill_tokens_per_s.median,86.043,tok/s,,
bench,prefill_tokens_per_s.p10,86.0103,tok/s,,
bench,prefill_tokens_per_s.p90,86.3823,tok/s,,
bench,prefill_tokens_per_s.min,86.0011,tok/s,,
bench,prefill_tokens_per_s.max,86.6422,tok/s,,
bench,prefill_tokens_per_s.n,10,tok/s,,
bench,ttft_ms.median,1824.67,ms,,
bench,ttft_ms.p10,1817.5,ms,,
bench,ttft_ms.p90,1825.36,ms,,
bench,ttft_ms.min,1812.05,ms,,
bench,ttft_ms.max,1825.56,ms,,
bench,ttft_ms.n,10,ms,,
bench,e2e_tokens_per_s.median,20.8546,tok/s,,
bench,e2e_tokens_per_s.p10,19.3377,tok/s,,
bench,e2e_tokens_per_s.p90,21.1426,tok/s,,
bench,e2e_tokens_per_s.min,19.267,tok/s,,
bench,e2e_tokens_per_s.max,21.1496,tok/s,,
bench,e2e_tokens_per_s.n,10,tok/s,,
bench,total_ms.median,6137.98,ms,,
bench,total_ms.p10,6054.13,ms,,
bench,total_ms.p90,6619.21,ms,,
bench,total_ms.min,6052.13,ms,,
bench,total_ms.max,6643.47,ms,,
bench,total_ms.n,10,ms,,
bench,cold_ttft_ms.median,1809.74,ms,,
bench,cold_ttft_ms.p10,1809.72,ms,,
bench,cold_ttft_ms.p90,1809.96,ms,,
bench,cold_ttft_ms.min,1809.71,ms,,
bench,cold_ttft_ms.max,1810.01,ms,,
bench,cold_ttft_ms.n,5,ms,,
bench,load_ms.median,1037.93,ms,,
bench,load_ms.p10,1031.94,ms,,
bench,load_ms.p90,1043.5,ms,,
bench,load_ms.min,1030.59,ms,,
bench,load_ms.max,1045.89,ms,,
bench,load_ms.n,5,ms,,
bench,wall_ms.median,20361.1,ms,,
bench,wall_ms.p10,19900.6,ms,,
bench,wall_ms.p90,20520.8,ms,,
bench,wall_ms.min,19874.6,ms,,
bench,wall_ms.max,20616.8,ms,,
bench,wall_ms.n,5,ms,,
bench,peak_rss_mb,4532.0,MB,,
bench,self_reported_peak_mem_mb,4530.1,MB,,
graded,tokens_per_s,29.3804,tok/s,,
graded,prefill_tokens_per_s,86.043,tok/s,,
graded,ttft_ms,1824.67,ms,,
graded,e2e_tokens_per_s,20.8546,tok/s,,
graded,total_ms,6137.98,ms,,
graded,cold_ttft_ms,1809.74,ms,,
graded,load_ms,1037.93,ms,,
graded,wall_ms,20361.1,ms,,
graded,peak_mem_mb,4532.0,MB,,
graded,time_to_first_token_ms,1824.67,ms,,
roofline,mem_bandwidth_gbps,,,,
roofline,peak_gflops,,,,
sustained,seconds,633.2,,,
sustained,iterations,10,,,
sustained,sustained_ratio,0.9995,,,123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404{ "kit_version": "0.1.0", "job": { "job_id": "NN-53D464", "kind": "optimize", "model": "prism-ml/Bonsai-27B-gguf", "environment": "mac-mini-m2pro", "outcome": "passed", "failure_reason": null, "fingerprint": { "name": "Mac mini (M2 Pro)", "gpu": "Apple M2 Pro GPU, 19 cores" }, "backend": { "requested": "Metal (llama.cpp fork)", "required": [ "llama.cpp" ], "avoided": [], "passed": true, "reason": "uses llama.cpp", "evidence": { "llama.cpp": [ "src/runner.cpp:164: llama_model * model = llama_model_load_from_file(model_path.c_str(), mparams);", "build log: [ 98%] Linking CXX static library libllama.a" ] } } }, "grade": { "correctness": true, "speed_target_met": true, "details": { "kit_version": "0.1.0", "bundle_digest": "b8e1d595699387ed56affd6be5a6b8698a0229f4007f8f68156d694d690355c3", "model_type": "text_to_text", "precision": "original", "split": "all", "final": true, "correctness": { "passed": true, "failed_checks": [], "flags": [], "metrics": { "tokenizer_match": 1.0, "next_token_agreement": 1.0, "topk_overlap": 1.0, "greedy_prefix": 1.0, "greedy_exact": 1.0, "positions": 1862, "ties_forgiven": 0, "top_k": 10 }, "errors": [] }, "benchmark": { "tokens_per_s": 29.3804, "prefill_tokens_per_s": 86.043, "ttft_ms": 1824.67, "load_ms": 1037.93, "peak_mem_mb": 4532.0, "flags": [] }, "speed": { "metric": "tokens_per_s", "higher_is_better": true, "target": { "metric": "tokens_per_s", "value": 19.02, "direction": "higher" }, "measured": 29.3804, "required": 19.02, "ratio_to_required": 1.545, "met": true } } }, "check": { "kind": "check", "model_type": "text_to_text", "precision": "original", "split": "all", "bundle_digest": "b8e1d595699387ed56affd6be5a6b8698a0229f4007f8f68156d694d690355c3", "port": { "dir": "/tmp/nnopt-device/port", "port_json": { "contract": 1, "model_type": "text_to_text", "runtime": "PrismML llama.cpp fork 5ae2e169, Metal (all layers on GPU)", "precision": "Q1_0_g128 weights (as published), f16 KV cache" }, "tree_sha256": "00d98a077f021ba9bb6447fc53d0b91c7deb4073c0e3ef3221f863d1eb532037", "external_sha256": {} }, "executor": { "executor": "local", "os": "darwin" }, "thresholds": { "tokenizer_match_min": 1.0, "next_token_agreement_min": 0.98, "topk_overlap_min": 0.9, "greedy_prefix_min": 0.75, "tie_margin": 0.05 }, "checks": [ { "name": "cases_completed", "value": 1.0, "op": ">=", "threshold": 1.0, "passed": true, "detail": "20/20 cases produced valid output" }, { "name": "tokenizer_match", "value": 1.0, "op": ">=", "threshold": 1.0, "passed": true, "detail": "prompt token ids identical" }, { "name": "next_token_agreement", "value": 1.0, "op": ">=", "threshold": 0.98, "passed": true, "detail": "teacher-forced top-1 agreement over 1862 positions (0 near-ties forgiven)" }, { "name": "topk_overlap", "value": 1.0, "op": ">=", "threshold": 0.9, "passed": true, "detail": "mean top-10 overlap" }, { "name": "greedy_prefix", "value": 1.0, "op": ">=", "threshold": 0.75, "passed": true, "detail": "mean matched prefix of 32 greedy tokens; 100% of prompts exact" } ], "metrics": { "tokenizer_match": 1.0, "next_token_agreement": 1.0, "topk_overlap": 1.0, "greedy_prefix": 1.0, "greedy_exact": 1.0, "positions": 1862, "ties_forgiven": 0, "top_k": 10 }, "cases": [ { "id": "p000", "split": "public", "origin": "builtin", "ref_tokens": 32, "generate": { "rc": 0, "wall_ms": 18930.0, "peak_rss_mb": 4532.0 }, "tokenizer_match": true, "greedy_matched": 32, "greedy_fraction": 1.0, "port_text": " Paris.\n\n<think>\nHere's a thinking process:\n\n1. **Analyze User Input:**\n - Statement: \"The capital of France is", "ref_text": " Paris.\n\n<think>\nHere's a thinking process:\n\n1. **Analyze User Input:**\n - Statement: \"The capital of France is", "score": { "rc": 0, "wall_ms": 1926.0, "peak_rss_mb": 4557.0 }, "positions": 37, "agreement": 1.0, "topk_overlap": 1.0, "ties_forgiven": 0 }, { "id": "p001", "split": "public", "origin": "builtin", "ref_tokens": 32, "generate": { "rc": 0, "wall_ms": 2531.0, "peak_rss_mb": 4526.0 }, "tokenizer_match": true, "greedy_matched": 32, "greedy_fraction": 1.0, "port_text": " fibonacci(n - 1) + fibonacci(n - 2)\n\ndef main():\n n = int(input(\"Enter a number: \"))\n print", "ref_text": " fibonacci(n - 1) + fibonacci(n - 2)\n\ndef main():\n n = int(input(\"Enter a number: \"))\n print", "score": { "rc": 0, "wall_ms": 1926.0, "peak_rss_mb": 4571.0 }, "positions": 51, "agreement": 1.0, "topk_overlap": 1.0, "ties_forgiven": 0 }, { "id": "p002", "split": "public", "origin": "customer", "ref_tokens": 32, "generate": { "rc": 0, "wall_ms": 2638.0, "peak_rss_mb": 4522.0 }, "tokenizer_match": true, "greedy_matched": 32, "greedy_fraction": 1.0, "port_text": "\n\n<think>\nHere's a thinking process:\n\n1. **Understand User Request:**\n - **Topic:** Quantum computing\n - **Requirement", "ref_text": "\n\n<think>\nHere's a thinking process:\n\n1. **Understand User Request:**\n - **Topic:** Quantum computing\n - **Requirement", "score": { "rc": 0, "wall_ms": 1904.0, "peak_rss_mb": 4561.0 }, "positions": 40, "agreement": 1.0, "topk_overlap": 1.0, "ties_forgiven": 0 }, { "id": "p003", "split": "public", "origin": "customer", "ref_tokens": 32, "generate": { "rc": 0, "wall_ms": 3681.0, "peak_rss_mb": 4527.0 }, "tokenizer_match": true, "greedy_matched": 32, "greedy_fraction": 1.0, "port_text": " we cannot dedicate. The living cannot dedicate. The dead cannot be dedicated. We are merely the living, dedicating for the dead. We are the living,", "ref_text": " we cannot dedicate. The living cannot dedicate. The dead cannot be dedicated. We are merely the living, dedicating for the dead. We are the living,", "score": { "rc": 0, "wall_ms": 3074.0, "peak_rss_mb": 4673.0 }, "positions": 154, "agreement": 1.0, "topk_overlap": 1.0, "ties_forgiven": 0 }, { "id": "p004", "split": "public", "origin": "customer", "ref_tokens": 32, "generate": { "rc": 0, "wall_ms": 3692.0, "peak_rss_mb": 4529.0 }, "tokenizer_match": true, "greedy_matched": 32, "greedy_fraction": 1.0, "port_text": " \"and I am sure you will be pleased to hear that it is let to a young man of good fortune, and of good character. I am sure you", "ref_text": " \"and I am sure you will be pleased to hear that it is let to a young man of good fortune, and of good character. I am sure you", "score": { "rc": 0, "wall_ms": 3064.0, "peak_rss_mb": 4676.0 }, "positions": 156, "agreement": 1.0, "topk_overlap": 1.0, "ties_forgiven": 0 }, { "id": "p005", "split": "public", "origin": "customer", "ref_tokens": 32, "generate": { "rc": 0, "wall_ms": 3585.0, "peak_rss_mb": 4526.0 }, "tokenizer_match": true, "greedy_matched": 32, "greedy_fraction": 1.0, "port_text": " the biosphere by providing oxygen and organic carbon to the biosphere, and by forming the base of the food web.\nThe process of photosynthesis is divided", "ref_text": " the biosphere by providing oxygen and organic carbon to the biosphere, and by forming the base of the food web.\nThe process of photosynthesis is divided", "score": { "rc": 0, "wall_ms": 3095.0, "peak_rss_mb": 4667.0 }, "positions": 148, "agreement": 1.0, "topk_overlap": 1.0, "ties_forgiven": 0 }, { "id": "p006", "split": "public", "origin": "customer", "ref_tokens": 32, "generate": { "rc": 0, "wall_ms": 3424.0, "peak_rss_mb": 4525.0 }, "tokenizer_match": true, "greedy_matched": 32, "greedy_fraction": 1.0, "port_text": " if n < 2:\n return False\n if n == 2:\n return True\n if n % 2 == ", "ref_text": " if n < 2:\n return False\n if n == 2:\n return True\n if n % 2 == ", "score": { "rc": 0, "wall_ms": 2710.0, "peak_rss_mb": 4646.0 }, "positions": 122, "agreement": 1.0, "topk_overlap": 1.0, "ties_forgiven": 0 }, { "id": "p007", "split": "public", "origin": "customer", "ref_tokens": 1, "generate": { "rc": 0, "wall_ms": 1863.0, "peak_rss_mb": 4524.0 }, "tokenizer_match": true, "greedy_matched": 1, "greedy_fraction": 1.0, "port_text": "<|im_end|>", "ref_text": "<|im_end|>", "score": { "rc": 0, "wall_ms": 1925.0, "peak_rss_mb": 4580.0 }, "positions": 60, "agreement": 1.0, "topk_overlap": 1.0, "ties_forgiven": 0 }, { "id": "p008", "split": "public", "origin": "customer", "ref_tokens": 32, "generate": { "rc": 0, "wall_ms": 2666.0, "peak_rss_mb": 4523.0 }, "tokenizer_match": true, "greedy_matched": 32, "greedy_fraction": 1.0, "port_text": "<think>\nThinking Process:\n\n1. **Deconstruct the request:**\n * Topic: Autumn leaves.\n * Form: Haiku", "ref_text": "<think>\nThinking Process:\n\n1. **Deconstruct the request:**\n * Topic: Autumn leaves.\n * Form: Haiku", "score": { "rc": 0, "wall_ms": 1966.0, "peak_rss_mb": 4578.0 }, "positions": 58, "agreement": 1.0, "topk_overlap": 1.0, "ties_forgiven": 0 }, { "id": "p009", "split": "public", "origin": "customer", "ref_tokens": 32, "generate": { "rc": 0, "wall_ms": 3317.0, "peak_rss_mb": 4526.0 }, "tokenizer_match": true, "greedy_matched": 32, "greedy_fraction": 1.0, "port_text": " a profond\u00e9ment transform\u00e9 la France et le monde entier.\nLa R\u00e9volution fran\u00e7aise a profond\u00e9ment transform\u00e9 la France et le monde entier.\nLa R\u00e9", "ref_text": " a profond\u00e9ment transform\u00e9 la France et le monde entier.\nLa R\u00e9volution fran\u00e7aise a profond\u00e9ment transform\u00e9 la France et le monde entier.\nLa R\u00e9", "score": { "rc": 0, "wall_ms": 2668.0, "peak_rss_mb": 4636.0 }, "positions": 116, "agreement": 1.0, "topk_overlap": 1.0, "ties_forgiven": 0 }, { "id": "p010", "split": "public", "origin": "customer", "ref_tokens": 32, "generate": { "rc": 0, "wall_ms": 2912.0, "peak_rss_mb": 4524.0 }, "tokenizer_match": true, "greedy_matched": 32, "greedy_fraction": 1.0, "port_text": " the same side always faces Earth. The Moon's orbit is inclined 5.1 degrees relative to Earth's equatorial plane. The Moon's orbit is also", "ref_text": " the same side always faces Earth. The Moon's orbit is inclined 5.1 degrees relative to Earth's equatorial plane. The Moon's orbit is also", "score": { "rc": 0, "wall_ms": 2313.0, "peak_rss_mb": 4615.0 }, "positions": 96, "agreement": 1.0, "topk_overlap": 1.0, "ties_forgiven": 0 }, { "id": "p011", "split": "public", "origin": "customer", "ref_tokens": 32, "generate": { "rc": 0, "wall_ms": 2675.0, "peak_rss_mb": 4522.0 }, "tokenizer_match": true, "greedy_matched": 32, "greedy_fraction": 1.0, "port_text": " 1 large onion, diced\n2. 2 cloves garlic, minced\n3. 1 can (28 oz) whole peeled tomatoes\n4.", "ref_text": " 1 large onion, diced\n2. 2 cloves garlic, minced\n3. 1 can (28 oz) whole peeled tomatoes\n4.", "score": { "rc": 0, "wall_ms": 1911.0, "peak_rss_mb": 4563.0 }, "positions": 42, "agreement": 1.0, "topk_overlap": 1.0, "ties_forgiven": 0 }, { "id": "p012", "split": "public", "origin": "customer", "ref_tokens": 32, "generate": { "rc": 0, "wall_ms": 3005.0, "peak_rss_mb": 4527.0 }, "tokenizer_match": true, "greedy_matched": 32, "greedy_fraction": 1.0, "port_text": "\u8f85\u4ee5\u5730\u5792\u3001\u58d5\u6c9f\u3001\u5173\u9698\u3001\u5821\u5792\u3001\u54e8\u53f0\u3001\u70ae\u53f0\u3001\u6697\u9053\u3001\u6697\u7a9f\u7b49\uff0c\u6784\u6210\u4e00\u4e2a\u7acb\u4f53\u9632\u5fa1\u4f53\u7cfb\u3002\u957f\u57ce", "ref_text": "\u8f85\u4ee5\u5730\u5792\u3001\u58d5\u6c9f\u3001\u5173\u9698\u3001\u5821\u5792\u3001\u54e8\u53f0\u3001\u70ae\u53f0\u3001\u6697\u9053\u3001\u6697\u7a9f\u7b49\uff0c\u6784\u6210\u4e00\u4e2a\u7acb\u4f53\u9632\u5fa1\u4f53\u7cfb\u3002\u957f\u57ce", "score": { "rc": 0, "wall_ms": 2282.0, "peak_rss_mb": 4589.0 }, "positions": 69, "agreement": 1.0, "topk_overlap": 1.0, "ties_forgiven": 0 }, { "id": "p013", "split": "public", "origin": "customer", "ref_tokens": 32, "generate": { "rc": 0, "wall_ms": 2421.0, "peak_rss_mb": 4522.0 }, "tokenizer_match": true, "greedy_matched": 32, "greedy_fraction": 1.0, "port_text": ", there was a young girl named Lily who lived in a small village. She was curious and brave, and she loved to explore the world around her. One", "ref_text": ", there was a young girl named Lily who lived in a small village. She was curious and brave, and she loved to explore the world around her. One", "score": { "rc": 0, "wall_ms": 1906.0, "peak_rss_mb": 4556.0 }, "positions": 36, "agreement": 1.0, "topk_overlap": 1.0, "ties_forgiven": 0 }, { "id": "h000", "split": "hidden", "origin": "generated", "ref_tokens": 32, "generate": { "rc": 0, "wall_ms": 2552.0, "peak_rss_mb": 4523.0 }, "tokenizer_match": true, "greedy_matched": 32, "greedy_fraction": 1.0, "port_text": " of the time were not aware of the fact that the bridge would be built on a fault line. The bridge was built with a length of 100", "ref_text": " of the time were not aware of the fact that the bridge would be built on a fault line. The bridge was built with a length of 100", "score": { "rc": 0, "wall_ms": 1940.0, "peak_rss_mb": 4574.0 }, "positions": 53, "agreement": 1.0, "topk_overlap": 1.0, "ties_forgiven": 0 }, { "id": "h001", "split": "hidden", "origin": "generated", "ref_tokens": 32, "generate": { "rc": 0, "wall_ms": 2617.0, "peak_rss_mb": 4525.0 }, "tokenizer_match": true, "greedy_matched": 32, "greedy_fraction": 1.0, "port_text": " ses nombreux temples et ses rues pav\u00e9es. La ville est divis\u00e9e en deux parties : le centre-ville et les quartiers p\u00e9riph\u00e9riques. Le centre-ville", "ref_text": " ses nombreux temples et ses rues pav\u00e9es. La ville est divis\u00e9e en deux parties : le centre-ville et les quartiers p\u00e9riph\u00e9riques. Le centre-ville", "score": { "rc": 0, "wall_ms": 1920.0, "peak_rss_mb": 4560.0 }, "positions": 40, "agreement": 1.0, "topk_overlap": 1.0, "ties_forgiven": 0 }, { "id": "h002", "split": "hidden", "origin": "generated", "ref_tokens": 32, "generate": { "rc": 0, "wall_ms": 2813.0, "peak_rss_mb": 4523.0 }, "tokenizer_match": true, "greedy_matched": 32, "greedy_fraction": 1.0, "port_text": " there exists a convex polygon with n sides such that the sum of the interior angles is equal to the sum of the exterior angles.\n\n<think>\nHere's a", "ref_text": " there exists a convex polygon with n sides such that the sum of the interior angles is equal to the sum of the exterior angles.\n\n<think>\nHere's a", "score": { "rc": 0, "wall_ms": 1903.0, "peak_rss_mb": 4566.0 }, "positions": 45, "agreement": 1.0, "topk_overlap": 1.0, "ties_forgiven": 0 }, { "id": "h003", "split": "hidden", "origin": "generated", "ref_tokens": 32, "generate": { "rc": 0, "wall_ms": 3006.0, "peak_rss_mb": 4524.0 }, "tokenizer_match": true, "greedy_matched": 32, "greedy_fraction": 1.0, "port_text": " total += i;\n }\n printf(\"%d\\n\", total);\n return 0;\n}\n\n<think>\nHere's a thinking", "ref_text": " total += i;\n }\n printf(\"%d\\n\", total);\n return 0;\n}\n\n<think>\nHere's a thinking", "score": { "rc": 0, "wall_ms": 2349.0, "peak_rss_mb": 4591.0 }, "positions": 70, "agreement": 1.0, "topk_overlap": 1.0, "ties_forgiven": 0 }, { "id": "h004", "split": "hidden", "origin": "generated", "ref_tokens": 32, "generate": { "rc": 0, "wall_ms": 2592.0, "peak_rss_mb": 4522.0 }, "tokenizer_match": true, "greedy_matched": 32, "greedy_fraction": 1.0, "port_text": ":\n1. It is the only province in Canada that is predominantly French-speaking.\n2. It is the only province in Canada that has a constitution that", "ref_text": ":\n1. It is the only province in Canada that is predominantly French-speaking.\n2. It is the only province in Canada that has a constitution that", "score": { "rc": 0, "wall_ms": 1907.0, "peak_rss_mb": 4560.0 }, "positions": 40, "agreement": 1.0, "topk_overlap": 1.0, "ties_forgiven": 0 }, { "id": "h005", "split": "hidden", "origin": "generated", "ref_tokens": 32, "generate": { "rc": 0, "wall_ms": 6791.0, "peak_rss_mb": 4539.0 }, "tokenizer_match": true, "greedy_matched": 32, "greedy_fraction": 1.0, "port_text": " the text describes a series of observations and experiments related to fishing, photography, and mirror mechanics. The key elements include:\n\n1. **Fishing Observations", "ref_text": " the text describes a series of observations and experiments related to fishing, photography, and mirror mechanics. The key elements include:\n\n1. **Fishing Observations", "score": { "rc": 0, "wall_ms": 6535.0, "peak_rss_mb": 4945.0 }, "positions": 429, "agreement": 1.0, "topk_overlap": 1.0, "ties_forgiven": 0 } ], "flags": [], "errors": [], "passed": true, "started_at": "2026-10-16T07:26:42Z", "seconds": 146.17 }, "bench": { "kind": "bench", "model_type": "text_to_text", "bundle_digest": "b8e1d595699387ed56affd6be5a6b8698a0229f4007f8f68156d694d690355c3", "case": "p000", "port": { "dir": "/tmp/nnopt-device/port", "port_json": { "contract": 1, "model_type": "text_to_text", "runtime": "PrismML llama.cpp fork 5ae2e169, Metal (all layers on GPU)", "precision": "Q1_0_g128 weights (as published), f16 KV cache" }, "tree_sha256": "00d98a077f021ba9bb6447fc53d0b91c7deb4073c0e3ef3221f863d1eb532037", "external_sha256": {} }, "executor": { "executor": "local", "os": "darwin" }, "environment": { "device": "Mac mini (M2 Pro)", "gpu": "Apple M2 Pro GPU, 19 cores", "name": "Mac mini (M2 Pro)" }, "model_facts": {}, "config": { "warmup": 2, "runs": 5, "repeat": 3, "max_new_tokens": 128, "external_check": true, "sustained_s": 600.0, "sustained_repeat": 10, "sample_interval_s": 2.0, "mem_interval_ms": 200, "timeout_s": 1800.0, "case": null, "prompt_tokens": 128, "batch": 1, "external_min_s": 2.0, "external_max_repeat": 500, "resolution": null, "seconds": 10.0, "time_budget_s": 8980.1, "adapt": true }, "precision": "original", "flags": [], "errors": [], "method": { "warmup": 2, "runs": 5, "repeat": 3, "adapted": false, "first_run_s": 7.3, "time_budget_s": 8980, "estimate_s": 818 }, "started_at": "2026-10-16T07:29:08Z", "inputs": { "prompt_tokens_target": 128, "prompt_tokens_estimate": 154, "prompt_from": [ "p000", "p001", "p002", "p003" ] }, "timed_telemetry": { "samples": 0 }, "runs": [ { "wall_ms": 20616.8, "load_ms": 1030.585, "peak_rss_mb": 4529.0, "peak_hwm_mb": null, "self_peak_mem_mb": 4527.3, "requests": [ { "total_ms": 6600.802, "ttft_ms": 1809.737, "prompt_tokens": 157, "new_tokens": 128, "tokens_per_s": 26.507676268220116, "prefill_tokens_per_s": 86.7529370289716, "e2e_tokens_per_s": 19.39158302279026 }, { "total_ms": 6195.819, "ttft_ms": 1825.557, "prompt_tokens": 157, "new_tokens": 128, "tokens_per_s": 29.06004262444677, "prefill_tokens_per_s": 86.00114923828727, "e2e_tokens_per_s": 20.659092849549026 }, { "total_ms": 6616.514, "ttft_ms": 1824.999, "prompt_tokens": 157, "new_tokens": 128, "tokens_per_s": 26.505186772868285, "prefill_tokens_per_s": 86.02744439859967, "e2e_tokens_per_s": 19.34553452165294 } ] }, { "wall_ms": 19939.6, "load_ms": 1045.894, "peak_rss_mb": 4531.0, "peak_hwm_mb": null, "self_peak_mem_mb": 4529.9, "requests": [ { "total_ms": 6523.721, "ttft_ms": 1810.005, "prompt_tokens": 157, "new_tokens": 128, "tokens_per_s": 26.94264991781431, "prefill_tokens_per_s": 86.74009187819922, "e2e_tokens_per_s": 19.62070419627081 }, { "total_ms": 6175.975, "ttft_ms": 1818.109, "prompt_tokens": 157, "new_tokens": 128, "tokens_per_s": 29.14270425019953, "prefill_tokens_per_s": 86.35345845601117, "e2e_tokens_per_s": 20.72547249624553 }, { "total_ms": 6082.926, "ttft_ms": 1824.754, "prompt_tokens": 157, "new_tokens": 128, "tokens_per_s": 29.825004720335393, "prefill_tokens_per_s": 86.03899484533258, "e2e_tokens_per_s": 21.042504873477007 } ] }, { "wall_ms": 20361.1, "load_ms": 1033.983, "peak_rss_mb": 4529.0, "peak_hwm_mb": null, "self_peak_mem_mb": 4527.2, "requests": [ { "total_ms": 6548.573, "ttft_ms": 1809.903, "prompt_tokens": 157, "new_tokens": 128, "tokens_per_s": 26.800768992143364, "prefill_tokens_per_s": 86.74498025584796, "e2e_tokens_per_s": 19.546243128083017 }, { "total_ms": 6643.473, "ttft_ms": 1824.872, "prompt_tokens": 157, "new_tokens": 128, "tokens_per_s": 26.356197576848555, "prefill_tokens_per_s": 86.03343138587255, "e2e_tokens_per_s": 19.267030964075566 }, { "total_ms": 6054.358, "ttft_ms": 1819.932, "prompt_tokens": 157, "new_tokens": 128, "tokens_per_s": 29.992258691024475, "prefill_tokens_per_s": 86.26695942485763, "e2e_tokens_per_s": 21.141795711452804 } ] }, { "wall_ms": 20376.8, "load_ms": 1039.908, "peak_rss_mb": 4532.0, "peak_hwm_mb": null, "self_peak_mem_mb": 4530.1, "requests": [ { "total_ms": 6539.003, "ttft_ms": 1809.708, "prompt_tokens": 157, "new_tokens": 128, "tokens_per_s": 26.853896828174175, "prefill_tokens_per_s": 86.75432721742955, "e2e_tokens_per_s": 19.574849560399343 }, { "total_ms": 6087.32, "ttft_ms": 1825.341, "prompt_tokens": 157, "new_tokens": 128, "tokens_per_s": 29.798363624034756, "prefill_tokens_per_s": 86.01132610290352, "e2e_tokens_per_s": 21.027315797428095 }, { "total_ms": 6600.9, "ttft_ms": 1824.583, "prompt_tokens": 157, "new_tokens": 128, "tokens_per_s": 26.589524941497817, "prefill_tokens_per_s": 86.04705842376039, "e2e_tokens_per_s": 19.391295126422158 } ] }, { "wall_ms": 19874.6, "load_ms": 1037.926, "peak_rss_mb": 4529.0, "peak_hwm_mb": null, "self_peak_mem_mb": 4527.1, "requests": [ { "total_ms": 6556.858, "ttft_ms": 1809.728, "prompt_tokens": 157, "new_tokens": 128, "tokens_per_s": 26.753006553433337, "prefill_tokens_per_s": 86.75336846200092, "e2e_tokens_per_s": 19.521545227912515 }, { "total_ms": 6052.126, "ttft_ms": 1820.886, "prompt_tokens": 157, "new_tokens": 128, "tokens_per_s": 30.014841984855504, "prefill_tokens_per_s": 86.2217623728229, "e2e_tokens_per_s": 21.149592721632033 }, { "total_ms": 6099.979, "ttft_ms": 1812.051, "prompt_tokens": 157, "new_tokens": 128, "tokens_per_s": 29.61803463117851, "prefill_tokens_per_s": 86.64215300783478, "e2e_tokens_per_s": 20.983678796271263 } ] } ], "summary": { "tokens_per_s": { "n": 10, "median": 29.3804, "mean": 28.6902, "min": 26.3562, "max": 30.0148, "p10": 26.4903, "p90": 29.9945 }, "prefill_tokens_per_s": { "n": 10, "median": 86.043, "mean": 86.1644, "min": 86.0011, "max": 86.6422, "p10": 86.0103, "p90": 86.3823 }, "ttft_ms": { "n": 10, "median": 1824.67, "mean": 1822.11, "min": 1812.05, "max": 1825.56, "p10": 1817.5, "p90": 1825.36 }, "e2e_tokens_per_s": { "n": 10, "median": 20.8546, "mean": 20.4733, "min": 19.267, "max": 21.1496, "p10": 19.3377, "p90": 21.1426 }, "total_ms": { "n": 10, "median": 6137.98, "mean": 6260.94, "min": 6052.13, "max": 6643.47, "p10": 6054.13, "p90": 6619.21 }, "cold_ttft_ms": { "n": 5, "median": 1809.74, "mean": 1809.82, "min": 1809.71, "max": 1810.01, "p10": 1809.72, "p90": 1809.96 }, "load_ms": { "n": 5, "median": 1037.93, "mean": 1037.66, "min": 1030.59, "max": 1045.89, "p10": 1031.94, "p90": 1043.5 }, "wall_ms": { "n": 5, "median": 20361.1, "mean": 20233.8, "min": 19874.6, "max": 20616.8, "p10": 19900.6, "p90": 20520.8 }, "peak_rss_mb": 4532.0, "peak_hwm_mb": null, "self_reported_peak_mem_mb": 4530.1 }, "external": { "available": true, "method": "paired --max-new-tokens N vs 1", "pairs": 5, "tokens_per_s": 27.6 }, "graded": { "tokens_per_s": 29.3804, "prefill_tokens_per_s": 86.043, "ttft_ms": 1824.67, "e2e_tokens_per_s": 20.8546, "total_ms": 6137.98, "cold_ttft_ms": 1809.74, "load_ms": 1037.93, "wall_ms": 20361.1, "peak_mem_mb": 4532.0, "time_to_first_token_ms": 1824.67 }, "sustained": { "seconds": 633.2, "iterations": 10, "failed_iterations": 0, "self_report_correction": null, "metric": "tokens_per_s", "series": [ { "t_s": 31.64, "tokens_per_s": 29.97, "rc": 0 }, { "t_s": 94.56, "tokens_per_s": 29.98, "rc": 0 }, { "t_s": 157.5, "tokens_per_s": 29.98, "rc": 0 }, { "t_s": 221.4, "tokens_per_s": 29.98, "rc": 0 }, { "t_s": 285.3, "tokens_per_s": 29.97, "rc": 0 }, { "t_s": 348.5, "tokens_per_s": 29.96, "rc": 0 }, { "t_s": 412.2, "tokens_per_s": 29.96, "rc": 0 }, { "t_s": 475.7, "tokens_per_s": 29.99, "rc": 0 }, { "t_s": 538.4, "tokens_per_s": 29.96, "rc": 0 }, { "t_s": 602.0, "tokens_per_s": 29.96, "rc": 0 } ], "telemetry": [], "telemetry_summary": { "samples": 0 }, "first_window": 29.98, "last_window": 29.96, "window_s": 126.6, "sustained_ratio": 0.9995 }, "roofline": { "mem_bandwidth_gbps": null, "peak_gflops": null }, "seconds": 800.36 }, "reference": { "format": "nnopt-reference-bundle", "version": 1, "job_id": "NN-53D464", "model_type": "text_to_text", "precision_policy": "original", "model": { "kind": "contract", "program": "/tmp/nnopt-device/port", "where": "device", "environment": "mac-mini-m2pro", "starting_version": "agent" }, "runner": { "kind": "contract", "program": "/tmp/nnopt-device/port", "where": "device", "environment": "mac-mini-m2pro", "starting_version": "agent" }, "params": { "max_new_tokens": 32, "top_k": 10, "long_words": 300 }, "tools": { "python": "3.12.14", "numpy": "2.5.4", "nnopt_verify": "0.1.0", "platform": "macOS-27.0.1-arm64-arm-64bit" }, "created_at": "2026-10-16T05:07:31Z", "cases": [ { "id": "p000", "split": "public", "origin": "builtin", "files": { "input": "inputs/p000.txt", "output": "outputs/p000.json" }, "meta": {} }, { "id": "p001", "split": "public", "origin": "builtin", "files": { "input": "inputs/p001.txt", "output": "outputs/p001.json" }, "meta": {} }, { "id": "p002", "split": "public", "origin": "customer", "files": { "input": "inputs/p002.txt", "input_meta": "inputs/p002.json", "output": "outputs/p002.json" }, "meta": { "name": "found_model_card_quickstart" } }, { "id": "p003", "split": "public", "origin": "customer", "files": { "input": "inputs/p003.txt", "input_meta": "inputs/p003.json", "output": "outputs/p003.json" }, "meta": { "name": "found_gettysburg" } }, { "id": "p004", "split": "public", "origin": "customer", "files": { "input": "inputs/p004.txt", "input_meta": "inputs/p004.json", "output": "outputs/p004.json" }, "meta": { "name": "found_pride_prejudice" } }, { "id": "p005", "split": "public", "origin": "customer", "files": { "input": "inputs/p005.txt", "input_meta": "inputs/p005.json", "output": "outputs/p005.json" }, "meta": { "name": "found_wiki_photosynthesis" } }, { "id": "p006", "split": "public", "origin": "customer", "files": { "input": "inputs/p006.txt", "input_meta": "inputs/p006.json", "output": "outputs/p006.json" }, "meta": { "name": "found_python_code" } }, { "id": "p007", "split": "public", "origin": "customer", "files": { "input": "inputs/p007.txt", "input_meta": "inputs/p007.json", "output": "outputs/p007.json" }, "meta": { "name": "found_math_word_problem" } }, { "id": "p008", "split": "public", "origin": "customer", "files": { "input": "inputs/p008.txt", "input_meta": "inputs/p008.json", "output": "outputs/p008.json" }, "meta": { "name": "found_chat_template_qwen" } }, { "id": "p009", "split": "public", "origin": "customer", "files": { "input": "inputs/p009.txt", "input_meta": "inputs/p009.json", "output": "outputs/p009.json" }, "meta": { "name": "found_french_text" } }, { "id": "p010", "split": "public", "origin": "customer", "files": { "input": "inputs/p010.txt", "input_meta": "inputs/p010.json", "output": "outputs/p010.json" }, "meta": { "name": "found_wiki_moon" } }, { "id": "p011", "split": "public", "origin": "customer", "files": { "input": "inputs/p011.txt", "input_meta": "inputs/p011.json", "output": "outputs/p011.json" }, "meta": { "name": "found_recipe_list" } }, { "id": "p012", "split": "public", "origin": "customer", "files": { "input": "inputs/p012.txt", "input_meta": "inputs/p012.json", "output": "outputs/p012.json" }, "meta": { "name": "found_chinese_text" } }, { "id": "p013", "split": "public", "origin": "customer", "files": { "input": "inputs/p013.txt", "input_meta": "inputs/p013.json", "output": "outputs/p013.json" }, "meta": { "name": "found_short_prompt" } }, { "id": "h000", "split": "hidden", "origin": "generated", "files": { "input": "inputs/h000.txt", "output": "outputs/h000.json" }, "meta": {} }, { "id": "h001", "split": "hidden", "origin": "generated", "files": { "input": "inputs/h001.txt", "output": "outputs/h001.json" }, "meta": {} }, { "id": "h002", "split": "hidden", "origin": "generated", "files": { "input": "inputs/h002.txt", "output": "outputs/h002.json" }, "meta": {} }, { "id": "h003", "split": "hidden", "origin": "generated", "files": { "input": "inputs/h003.txt", "output": "outputs/h003.json" }, "meta": {} }, { "id": "h004", "split": "hidden", "origin": "generated", "files": { "input": "inputs/h004.txt", "output": "outputs/h004.json" }, "meta": {} }, { "id": "h005", "split": "hidden", "origin": "generated", "files": { "input": "inputs/h005.txt", "output": "outputs/h005.json" }, "meta": {} } ], "splits": { "public": [ "p000", "p001", "p002", "p003", "p004", "p005", "p006", "p007", "p008", "p009", "p010", "p011", "p012", "p013" ], "hidden": [ "h000", "h001", "h002", "h003", "h004", "h005" ] }, "notes": [], "determinism": { "generate_repeatable": true, "score_repeatable": true }, "customer_expectations": [], "capture_plan": { "time_budget_s": 8722, "budget_share": 0.8, "hidden_floor": 3, "hidden_planned": 6, "hidden_captured": 6, "hidden_dropped": 0, "seconds_per_case": 13.7, "seconds": 123 }, "frozen_at": "2026-10-16T05:09:33Z" }}1234567891011121314151617181920212223cmake_minimum_required(VERSION 3.14)project(nnopt_runner CXX C)
# LLAMA_SRC: the customer's PrismML llama.cpp fork, built unchanged.if(NOT LLAMA_SRC) message(FATAL_ERROR "set -DLLAMA_SRC=<path to the llama.cpp fork>")endif()
set(LLAMA_BUILD_TESTS OFF CACHE BOOL "" FORCE)set(LLAMA_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)set(LLAMA_BUILD_SERVER OFF CACHE BOOL "" FORCE)set(LLAMA_BUILD_TOOLS OFF CACHE BOOL "" FORCE)set(LLAMA_BUILD_COMMON OFF CACHE BOOL "" FORCE)set(LLAMA_CURL OFF CACHE BOOL "" FORCE)set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)set(GGML_METAL ON CACHE BOOL "" FORCE)set(GGML_METAL_EMBED_LIBRARY ON CACHE BOOL "" FORCE)
add_subdirectory(${LLAMA_SRC} llama.cpp)
add_executable(nnopt_runner runner.cpp)target_link_libraries(nnopt_runner PRIVATE llama)target_compile_features(nnopt_runner PRIVATE cxx_std_17)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549--- a/ggml/src/ggml-metal/ggml-metal-device.cpp 2026-10-15 23:29:33+++ b/ggml/src/ggml-metal/ggml-metal-device.cpp 2026-10-15 23:29:33@@ -602,6 +602,17 @@ return res; } +ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_conv_state_step(ggml_metal_library_t lib) {+ const char * name = "kernel_conv_state_step_f32";++ ggml_metal_pipeline_with_params res = ggml_metal_library_get_pipeline(lib, name);+ if (!res.pipeline) {+ res = ggml_metal_library_compile_pipeline(lib, name, name, nullptr);+ }++ return res;+}+ ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_ssm_conv(ggml_metal_library_t lib, const ggml_tensor * op, bool silu) { GGML_ASSERT(op->src[0]->type == GGML_TYPE_F32); GGML_ASSERT(op->src[1]->type == GGML_TYPE_F32);@@ -909,6 +920,16 @@ op->src[1]->ne[1] >= 2 && op->src[1]->ne[1] <= 4; } +bool ggml_metal_q1_0_lut_supported(const ggml_tensor * op) {+ static const bool enabled = !getenv("NNOPT_Q1_LUT") || atoi(getenv("NNOPT_Q1_LUT")) != 0;+ const ggml_tensor * src0 = op->src[0];+ const ggml_tensor * src1 = op->src[1];+ return enabled && src0->type == GGML_TYPE_Q1_0 && src1->type == GGML_TYPE_F32 &&+ src0->ne[0] % 1024 == 0 && src0->ne[1] >= 512 && src1->ne[1] == 1 &&+ src0->ne[2] == 1 && src0->ne[3] == 1 && src1->ne[2] == 1 && src1->ne[3] == 1 &&+ src1->nb[0] == sizeof(float);+}+ ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_mul_mv(ggml_metal_library_t lib, const ggml_tensor * op) { GGML_TENSOR_LOCALS( int32_t, ne0, op->src[0], ne); GGML_TENSOR_LOCALS( int32_t, ne1, op->src[1], ne);@@ -963,6 +984,16 @@ nr1 = 2; } suffix = nr1 == 2 ? "_nr1_2" : nr1 == 3 ? "_nr1_3" : nr1 == 4 ? "_nr1_4" : "";+ if (nr1 == 1 && ggml_metal_q1_0_lut_supported(op)) {+ // lookup-table decode kernel, see kernel_mul_mv_q1_0_f32_lut+ static const int lut_nr = getenv("NNOPT_Q1_LUT_NR") ? atoi(getenv("NNOPT_Q1_LUT_NR")) : 4;+ static const int lut_nsg = getenv("NNOPT_Q1_LUT_NSG") ? atoi(getenv("NNOPT_Q1_LUT_NSG")) : 16;+ nsg = lut_nsg;+ nr0 = lut_nr;+ smem = 16*(1024/4)*sizeof(float);+ snprintf(ptq1_suffix, sizeof(ptq1_suffix), "_lut_%d", lut_nr);+ suffix = ptq1_suffix;+ } } break; case GGML_TYPE_Q2_0: {--- a/ggml/src/ggml-metal/ggml-metal-device.h 2026-10-15 23:29:33+++ b/ggml/src/ggml-metal/ggml-metal-device.h 2026-10-15 23:29:33@@ -6,6 +6,7 @@ extern "C" { #endif +bool ggml_metal_q1_0_lut_supported(const struct ggml_tensor * op); bool ggml_metal_ptq1_multicol_enabled(const struct ggml_tensor * op); struct ggml_metal_buffer_id {@@ -133,6 +134,7 @@ struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_soft_max (ggml_metal_library_t lib, const struct ggml_tensor * op); struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_lightning_indexer (ggml_metal_library_t lib, const struct ggml_tensor * op); struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_dsv4_hc (ggml_metal_library_t lib, enum ggml_op op);+struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_conv_state_step (ggml_metal_library_t lib); struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_ssm_conv (ggml_metal_library_t lib, const struct ggml_tensor * op, bool silu); struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_ssm_conv_batched (ggml_metal_library_t lib, const struct ggml_tensor * op, int ssm_conv_bs, bool silu); struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_ssm_scan (ggml_metal_library_t lib, const struct ggml_tensor * op);--- a/ggml/src/ggml-metal/ggml-metal-impl.h 2026-10-15 23:29:33+++ b/ggml/src/ggml-metal/ggml-metal-impl.h 2026-10-15 23:29:33@@ -917,6 +917,18 @@ uint64_t nb1; uint64_t nb2; } ggml_metal_kargs_ssm_conv;++// decode conv-state step of the gated delta net, see ggml_metal_op_conv_state_step+typedef struct {+ int32_t nch; // channels+ int32_t sA; // first element of the state slot copies, in the 4-wide conv input+ int32_t sB;+ int32_t silu;+ uint64_t nb00; // state (concat src0) element (k, c) at c*nb01 + k*nb00+ uint64_t nb01;+ uint64_t nb11; // new input (concat src1) element (0, c) at c*nb11+ uint64_t nb1; // conv input (concat dst) row stride+} ggml_metal_kargs_conv_state_step; typedef struct { int64_t d_state;--- a/ggml/src/ggml-metal/ggml-metal-ops.cpp 2026-10-15 23:29:33+++ b/ggml/src/ggml-metal/ggml-metal-ops.cpp 2026-10-15 23:29:33@@ -564,10 +564,120 @@ } return res;+}++// Decode conv-state step of the gated delta net (src/models/delta-net-base.cpp build_conv_state, then+// ggml_ssm_conv and ggml_silu in qwen35.cpp), for one token and one sequence:+// conv_input = CONCAT(conv_states [3, C], x^T [1, C]) -> 2 x CPY(view of conv_input [3, C] at element s, state slot)+// -> SSM_CONV(conv_input, kernel [4, C]) (-> SILU)+// encoded as one thread-per-channel kernel instead of 4-5 dependent dispatches. Returns the number of fused nodes,+// 0 when the pattern does not match (the generic kernels run).+static int ggml_metal_op_conv_state_step(ggml_metal_op_t ctx, int idx) {+ ggml_tensor * op = ctx->node(idx);++ if (!ctx->use_fusion || idx + 4 > ctx->n_nodes()) {+ return 0;+ }++ const ggml_tensor * s0 = op->src[0];+ const ggml_tensor * s1 = op->src[1];+ const int64_t nch = op->ne[1];++ if (((const int32_t *) op->op_params)[0] != 0 || op->type != GGML_TYPE_F32 || s0->type != GGML_TYPE_F32 ||+ s1->type != GGML_TYPE_F32 || !ggml_is_contiguous(op) ||+ op->ne[0] != 4 || op->ne[2] != 1 || op->ne[3] != 1 ||+ s0->ne[0] != 3 || s0->ne[1] != nch || s0->ne[2] != 1 || s0->ne[3] != 1 ||+ s1->ne[0] != 1 || s1->ne[1] != nch || s1->ne[2] != 1 || s1->ne[3] != 1) {+ return 0;+ }++ ggml_tensor * cpy[2] = { ctx->node(idx + 1), ctx->node(idx + 2) };+ int32_t sidx[2];+ for (int j = 0; j < 2; ++j) {+ const ggml_tensor * v = cpy[j]->src[0];+ const ggml_tensor * d = cpy[j]->src[1];+ if (cpy[j]->op != GGML_OP_CPY || v->view_src != op || v->type != GGML_TYPE_F32 ||+ d->type != GGML_TYPE_F32 || !ggml_is_contiguous(d) || ggml_nelements(d) != 3*nch ||+ v->ne[0] != 3 || v->ne[1] != nch || v->ne[2] != 1 || v->ne[3] != 1 ||+ v->nb[0] != sizeof(float) || v->nb[1] != op->nb[1] || cpy[j]->data != d->data) {+ return 0;+ }+ const size_t offs = (const char *) v->data - (const char *) op->data;+ if (offs % sizeof(float) != 0 || offs/sizeof(float) > 1) {+ return 0;+ }+ sidx[j] = (int32_t) (offs/sizeof(float));+ }++ ggml_tensor * conv = ctx->node(idx + 3);+ if (conv->op != GGML_OP_SSM_CONV || conv->src[0] != op || conv->type != GGML_TYPE_F32 ||+ conv->src[1]->type != GGML_TYPE_F32 || !ggml_is_contiguous(conv->src[1]) ||+ conv->src[1]->ne[0] != 4 || conv->src[1]->ne[1] != nch ||+ conv->ne[0] != nch || conv->ne[1] != 1 || conv->ne[2] != 1 || !ggml_is_contiguous(conv)) {+ return 0;+ }++ // conv followed by a silu that is its only consumer (as in ggml_metal_op_ssm_conv)+ ggml_tensor * out = conv;+ int n_fuse = 4;+ {+ static constexpr ggml_op ops[2] = { GGML_OP_SSM_CONV, GGML_OP_UNARY };+ if (ctx->can_fuse(idx + 3, ops, 2)) {+ ggml_tensor * un = ctx->node(idx + 4);+ if (ggml_get_unary_op(un) == GGML_UNARY_OP_SILU && un->src[0] == conv &&+ un->type == GGML_TYPE_F32 && ggml_is_contiguous(un) && ggml_are_same_shape(un, conv)) {+ out = un;+ n_fuse = 5;+ }+ }+ }++ for (int i = 1; i < n_fuse; ++i) {+ if (!ggml_metal_op_concurrency_check(ctx, ctx->node(idx + i))) {+ ggml_metal_op_concurrency_reset(ctx);+ }+ }++ ggml_metal_kargs_conv_state_step args = {+ /*.nch =*/ (int32_t) nch,+ /*.sA =*/ sidx[0],+ /*.sB =*/ sidx[1],+ /*.silu =*/ n_fuse == 5 ? 1 : 0,+ /*.nb00 =*/ s0->nb[0],+ /*.nb01 =*/ s0->nb[1],+ /*.nb11 =*/ s1->nb[1],+ /*.nb1 =*/ op->nb[1],+ };++ ggml_metal_encoder_t enc = ctx->enc;++ auto pipeline = ggml_metal_library_get_pipeline_conv_state_step(ctx->lib);++ ggml_metal_encoder_set_pipeline(enc, pipeline);+ ggml_metal_encoder_set_bytes (enc, &args, sizeof(args), 0);+ ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(s0), 1);+ ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(s1), 2);+ ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(op), 3);+ ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(cpy[0]), 4);+ ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(cpy[1]), 5);+ ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(conv->src[1]), 6);+ ggml_metal_encoder_set_buffer (enc, ggml_metal_get_buffer_id(out), 7);++ const int nth = 256;+ ggml_metal_encoder_dispatch_threadgroups(enc, (nch + nth - 1)/nth, 1, 1, nth, 1, 1);++ return n_fuse; } int ggml_metal_op_concat(ggml_metal_op_t ctx, int idx) { ggml_tensor * op = ctx->node(idx);++ {+ const int n_fuse = ggml_metal_op_conv_state_step(ctx, idx);+ if (n_fuse > 0) {+ return n_fuse;+ }+ } ggml_metal_library_t lib = ctx->lib; ggml_metal_encoder_t enc = ctx->enc;--- a/ggml/src/ggml-metal/kernels/dequantize.h 2026-10-15 23:29:33+++ b/ggml/src/ggml-metal/kernels/dequantize.h 2026-10-15 23:29:33@@ -44,11 +44,32 @@ reg = (type4)(*(src)); } #endif++// Q1_0 weights in Metal buffers are stored repacked (llama-model-loader.cpp, q1_0_repack_tiles): each+// 1024-weight tile of a row (8 blocks, 144 bytes) holds the 8 fp16 block scales (16 B), then the 8 x 16 B of+// sign bits. Tiles start 16-byte aligned, so the address the original layout gives block i of a tile,+// tile + 18*i, has (address & 15) == 2*i: every kernel keeps its block_q1_0 pointer arithmetic and finds+// the block's scale and bits from that address.+struct q1_0_loc {+ half d;+ device const uint8_t * qs;+};++static inline q1_0_loc q1_0_locate(device const block_q1_0 * xb) {+ device const char * p = (device const char *) xb;+ const short i = (short) ((((ulong) p) & 15) >> 1);+ device const char * tile = p - 18*i;+ q1_0_loc res;+ res.d = ((device const half *) tile)[i];+ res.qs = (device const uint8_t *) (tile + 16 + 16*i);+ return res;+} template <typename type4x4> void dequantize_q1_0(device const block_q1_0 * xb, short il, thread type4x4 & reg) {- device const uint8_t * qs = xb->qs;- const float d = xb->d;+ const q1_0_loc blk = q1_0_locate(xb);+ device const uint8_t * qs = blk.qs;+ const float d = blk.d; const float neg_d = -d; const int byte_offset = il * 2; // il*16 bits = il*2 bytes@@ -80,10 +101,11 @@ template <typename type4> void dequantize_q1_0_t4(device const block_q1_0 * xb, short il, thread type4 & reg) {- const float d = xb->d;+ const q1_0_loc blk = q1_0_locate(xb);+ const float d = blk.d; const float neg_d = -d; const int base = il * 4;- const uint8_t byte = xb->qs[base / 8];+ const uint8_t byte = blk.qs[base / 8]; const int s = base % 8; float4 reg_f;--- a/ggml/src/ggml-metal/kernels/mul_mv.metal 2026-10-15 23:29:33+++ b/ggml/src/ggml-metal/kernels/mul_mv.metal 2026-10-15 23:29:33@@ -2,7 +2,8 @@ #include "dequantize.h" // Q1_0 dot product: dot = d * (2 * Σ(yl[i] where bit=1) - sumy) inline float block_q_n_dot_y(device const block_q1_0 * qb_curr, float sumy, thread float * yl, int il) {- device const uint8_t * qs = qb_curr->qs + il / 8;+ const q1_0_loc blk = q1_0_locate(qb_curr);+ device const uint8_t * qs = blk.qs + il / 8; const uint8_t b0 = qs[0]; const uint8_t b1 = qs[1]; @@ -26,7 +27,7 @@ acc += select(0.0f, yl[14], bool(b1 & 0x40)); acc += select(0.0f, yl[15], bool(b1 & 0x80)); - return qb_curr->d * (2.0f * acc - sumy);+ return blk.d * (2.0f * acc - sumy); } // Q2_0 dot: d * (sum_lo(y) + 2*sum_hi(y) - sumy) via per-bit conditional adds@@ -429,7 +430,111 @@ ushort sgitg[[simdgroup_index_in_threadgroup]]) { kernel_mul_mv_q1_0_f32_impl<N_R0_Q1_0, constant ggml_metal_kargs_mul_mv &>(args, src0, src1, dst, nullptr, tgpig, tiisg, sgitg); }++// Q1_0 single-column mat-vec through a lookup table (decode, ne11 == 1), on the repacked layout+// (see q1_0_locate in dequantize.h): a row's 1024-wide K tile is 16 B of block scales, then 128 B of bits.+// The bit-select dot (block_q_n_dot_y) costs ~3 ALU ops per weight, which caps it well below the memory+// bandwidth. Here the threadgroup first builds, for each group of 4 consecutive src1 values of the tile, the+// 16 signed sums +-y0 +-y1 +-y2 +-y3 in threadgroup memory; then every 4 weight bits of every row cost one+// table read and one add. Same math as block_q_n_dot_y: d*(2*sum(y where bit=1) - sum(y)) == d*sum(+-y), fp32.+// Lane l of a row reads the tile's bits 32l..32l+31 (block l/4) with one coalesced 32-bit load: 8 nibbles,+// groups g = 8l + j. Table layout tab[n*GT + pos], pos = (g%8)*32 + (g/8 + 4*(g%8))%32: both the build+// (consecutive g) and the lookups (lane l reads g = 8l + j) hit 32 different banks.+template<short NR>+kernel void kernel_mul_mv_q1_0_f32_lut(+ constant ggml_metal_kargs_mul_mv & args,+ device const char * src0,+ device const char * src1,+ device char * dst,+ threadgroup char * shmem [[threadgroup(0)]],+ uint3 tgpig[[threadgroup_position_in_grid]],+ ushort tiisg[[thread_index_in_simdgroup]],+ ushort sgitg[[simdgroup_index_in_threadgroup]]) {+ const short NSG = FC_mul_mv_nsg;++ constexpr short KT = 1024;+ constexpr short GT = KT/4; // groups of 4 per tile+ constexpr short TB = 144; // bytes per row tile++ threadgroup float * tab = (threadgroup float *) shmem; + const int r1 = tgpig.y;++ const int first_row = (tgpig.x*NSG + sgitg)*NR;+ const short tid = sgitg*N_SIMDWIDTH + tiisg;++ device const float * y = (device const float *) (src1 + (uint64_t) r1*args.nb11);++ device const char * ax[NR];+ FOR_UNROLL (short r = 0; r < NR; ++r) {+ const int row = min(first_row + r, args.ne01 - 1);+ ax[r] = src0 + (uint64_t) row*args.nb01;+ }++ float acc[NR] = { 0.f };++ const int ntiles = args.ne00/KT;++ // table offsets of the lane's groups j and j + 4, packed in the two 16-bit halves+ uint offp[4];+ FOR_UNROLL (short j = 0; j < 4; ++j) {+ offp[j] = (uint) (j*32 + ((tiisg + 4*j) & 31)) | ((uint) ((j + 4)*32 + ((tiisg + 4*(j + 4)) & 31)) << 16);+ }++ for (int t = 0; t < ntiles; ++t) {+ uint u [NR];+ half dh[NR];+ FOR_UNROLL (short r = 0; r < NR; ++r) {+ device const char * tb = ax[r] + t*TB;+ dh[r] = ((device const half *) tb)[tiisg/4];+ u [r] = ((device const uint *) (tb + 16))[tiisg];+ }++ threadgroup_barrier(mem_flags::mem_threadgroup);++ for (short g = tid; g < GT; g += NSG*N_SIMDWIDTH) {+ const float4 yv = ((device const float4 *) (y + t*KT))[g];+ const float a[4] = { -yv[0] - yv[1], yv[0] - yv[1], -yv[0] + yv[1], yv[0] + yv[1] };+ const float b[4] = { -yv[2] - yv[3], yv[2] - yv[3], -yv[2] + yv[3], yv[2] + yv[3] };+ const short pos = (g%8)*32 + ((g/8 + 4*(g%8)) & 31);+ FOR_UNROLL (short n = 0; n < 16; ++n) {+ tab[n*GT + pos] = a[n%4] + b[n/4];+ }+ }++ threadgroup_barrier(mem_flags::mem_threadgroup);++ FOR_UNROLL (short r = 0; r < NR; ++r) {+ // two table indices per 32-bit op: nibbles j and j + 4 land in the two 16-bit halves as n*GT+ const uint w = u[r];+ const uint m = 0x0F000F00u;+ const ushort2 x0 = as_type<ushort2>(((w << 8) & m) | offp[0]);+ const ushort2 x1 = as_type<ushort2>(((w << 4) & m) | offp[1]);+ const ushort2 x2 = as_type<ushort2>(((w ) & m) | offp[2]);+ const ushort2 x3 = as_type<ushort2>(((w >> 4) & m) | offp[3]);+ const float s = ((tab[x0[0]] + tab[x0[1]]) + (tab[x1[0]] + tab[x1[1]]))+ + ((tab[x2[0]] + tab[x2[1]]) + (tab[x3[0]] + tab[x3[1]]));+ acc[r] += (float) dh[r] * s;+ }+ }++ device float * dst_f32 = (device float *) dst + (uint64_t) r1*args.ne0;++ FOR_UNROLL (short r = 0; r < NR; ++r) {+ const float tot = simd_sum(acc[r]);++ if (tiisg == 0 && first_row + r < args.ne01) {+ dst_f32[first_row + r] = tot;+ }+ }+}++typedef decltype(kernel_mul_mv_q1_0_f32_lut<4>) kernel_mul_mv_q1_0_f32_lut_t;++template [[host_name("kernel_mul_mv_q1_0_f32_lut_2")]] kernel kernel_mul_mv_q1_0_f32_lut_t kernel_mul_mv_q1_0_f32_lut<2>;+template [[host_name("kernel_mul_mv_q1_0_f32_lut_4")]] kernel kernel_mul_mv_q1_0_f32_lut_t kernel_mul_mv_q1_0_f32_lut<4>;+template [[host_name("kernel_mul_mv_q1_0_f32_lut_8")]] kernel kernel_mul_mv_q1_0_f32_lut_t kernel_mul_mv_q1_0_f32_lut<8>;+ // Q1_0 multi-column mat-vec: each q1_0 block is read once and dotted against nr1 // src1 columns (the spec-decode verify batch, ne11 = k+1 rows). tpb threads // cooperate on one block, slice width SW = QK1_0/tpb. Register budget (M5 Pro):@@ -506,14 +611,14 @@ } FOR_UNROLL (short row = 0; row < nr0; row++) {- device const block_q1_0 * qb = ax[row] + ib;- device const uint8_t * qs = qb->qs + il/8;+ const q1_0_loc blk = q1_0_locate(ax[row] + ib);+ device const uint8_t * qs = blk.qs + il/8; uint8_t b[SW/8]; FOR_UNROLL (short i = 0; i < SW/8; i++) { b[i] = qs[i]; }- const float d = qb->d;+ const float d = blk.d; FOR_UNROLL (short c = 0; c < nr1; c++) { sumf[row][c] += q1_0_dot_y_sw<SW>(b, d, sumy[c], yl[c]);@@ -681,8 +786,8 @@ int pcw[nr0]; FOR_UNROLL (short row = 0; row < nr0; row++) {- device const block_q1_0 * qb = ax[row] + ib;- device const uint8_t * qs = qb->qs; // 2-byte aligned: assemble from bytes+ const q1_0_loc blk = q1_0_locate(ax[row] + ib);+ device const uint8_t * qs = blk.qs; // 2-byte aligned: assemble from bytes int pc = 0; FOR_UNROLL (short j = 0; j < 4; j++) {@@ -692,7 +797,7 @@ pc += popcount(wj); } - d [row] = qb->d;+ d [row] = blk.d; pcw[row] = pc; } --- a/ggml/src/ggml-metal/kernels/ssm.metal 2026-10-15 23:29:33+++ b/ggml/src/ggml-metal/kernels/ssm.metal 2026-10-15 23:29:33@@ -66,6 +66,41 @@ x[0] = FC_ssm_conv_silu ? sumf / (1.0f + exp(-sumf)) : sumf; } +// Decode (one token) conv-state step of the gated delta net in one thread per channel: the graph's+// CONCAT(state[3], x) -> two CPYs of 3-wide windows into the state cache slots -> SSM_CONV (+ SILU).+// Same math as kernel_ssm_conv_f32_f32_4: dot(conv input row, kernel row), then the same silu.+kernel void kernel_conv_state_step_f32(+ constant ggml_metal_kargs_conv_state_step & args,+ device const char * src0,+ device const char * src1,+ device char * cin,+ device float * dstA,+ device float * dstB,+ device const float4 * w,+ device float * dst,+ uint i[[thread_position_in_grid]]) {+ if ((int) i >= args.nch) {+ return;+ }++ device const char * s = src0 + i*args.nb01;+ const float4 v = float4(*(device const float *) (s),+ *(device const float *) (s + args.nb00),+ *(device const float *) (s + 2*args.nb00),+ *(device const float *) (src1 + i*args.nb11));++ *(device float4 *) (cin + i*args.nb1) = v;++ FOR_UNROLL (short k = 0; k < 3; ++k) {+ dstA[3*i + k] = v[args.sA + k];+ dstB[3*i + k] = v[args.sB + k];+ }++ const float sumf = dot(v, w[i]);++ dst[i] = args.silu ? sumf / (1.0f + exp(-sumf)) : sumf;+}+ constant short FC_ssm_conv_bs [[function_constant(FC_SSM_CONV + 0)]]; // Batched version: each threadgroup processes multiple tokens for better efficiency--- a/src/llama-model-loader.cpp 2026-10-15 23:29:33+++ b/src/llama-model-loader.cpp 2026-10-15 23:29:33@@ -1437,6 +1437,36 @@ if (check_tensors && !ggml_validate_row_data(cur->type, cur->data, ggml_nbytes(cur))) { throw std::runtime_error(format("tensor '%s' has invalid data", ggml_get_name(cur)));+ }+}++// Q1_0 weights in Metal buffers use the repacked layout the Metal kernels read (q1_0_locate in+// ggml-metal kernels/dequantize.h): each 1024-weight tile of a row, 8 blocks of {fp16 d, 16 B bits} = 144 B,+// is rewritten as the 8 scales (16 B) followed by the 8 x 16 B of bits. Same bytes, same size.+static bool q1_0_metal_repack(const ggml_tensor * cur) {+ if (cur->type != GGML_TYPE_Q1_0 || cur->buffer == nullptr) {+ return false;+ }+ const char * name = ggml_backend_buft_name(ggml_backend_buffer_get_type(cur->buffer));+ return strncmp(name, "MTL", 3) == 0;+}++static void q1_0_repack_tiles(void * data, const ggml_tensor * cur) {+ constexpr size_t BS = 18; // block_q1_0: fp16 d, then 16 bytes of bits+ constexpr size_t TB = 8*BS; // 144 bytes per 1024-weight tile+ if (cur->ne[0] % 1024 != 0 || !ggml_is_contiguous(cur)) {+ throw std::runtime_error(format("tensor '%s': the Metal Q1_0 kernels need ne0 %% 1024 == 0 and a contiguous tensor",+ ggml_get_name(cur)));+ }+ const size_t ntiles = ggml_nbytes(cur)/TB;+ uint8_t * p = (uint8_t *) data;+ uint8_t tmp[TB];+ for (size_t t = 0; t < ntiles; ++t, p += TB) {+ memcpy(tmp, p, TB);+ for (int i = 0; i < 8; ++i) {+ memcpy(p + 2*i, tmp + i*BS, 2);+ memcpy(p + 16 + 16*i, tmp + i*BS + 2, 16);+ } } } @@ -1585,6 +1615,11 @@ } GGML_ASSERT(buf_mmap || cur->data); // either we have a buffer to allocate the tensor in, or it is already allocated+ if (q1_0_metal_repack(cur) || (buf_mmap && cur->type == GGML_TYPE_Q1_0 &&+ strncmp(ggml_backend_buft_name(ggml_backend_buffer_get_type(buf_mmap)), "MTL", 3) == 0)) {+ throw std::runtime_error(format("tensor '%s': Q1_0 weights on Metal need load_mode NONE, not mmap (repacked layout)",+ ggml_get_name(cur)));+ } if (buf_mmap && cur->data == nullptr) { ggml_backend_tensor_alloc(buf_mmap, cur, data); if (lmlocks) {@@ -1609,6 +1644,15 @@ return std::make_pair(cur, ggml_validate_row_data(cur->type, cur->data, n_size)); })); }+ } else if (q1_0_metal_repack(cur)) {+ read_buf.resize(n_size);+ file->seek(weight->offs, SEEK_SET);+ file->read_raw(read_buf.data(), n_size);+ if (check_tensors && !ggml_validate_row_data(cur->type, read_buf.data(), n_size)) {+ throw std::runtime_error(format("tensor '%s' has invalid data", ggml_get_name(cur)));+ }+ q1_0_repack_tiles(read_buf.data(), cur);+ ggml_backend_tensor_set(cur, read_buf.data(), 0, n_size); } else { // If upload_backend is valid load the tensor in chunks to pinned memory and upload the buffers asynchronously to the GPU. if (upload_backend) {123# nnopt contract entry point (text_to_text): generate or score, see nnopt_runner.cd "$(dirname "$0")" || exit 1exec ./nnopt_runner --model ./Bonsai-27B-Q1_0.gguf "$@"123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335// nnopt contract runner (text_to_text) over the customer's PrismML llama.cpp fork.// Runs the model the way llama-cli does on Metal (-ngl 99, n_batch 2048, n_ubatch 512,// flash attention auto, f16 KV cache), with greedy decoding instead of sampling.#include "llama.h"
#include <sys/resource.h>#include <sys/sysctl.h>
#include <algorithm>#include <chrono>#include <cstdio>#include <cstdlib>#include <cstring>#include <fstream>#include <sstream>#include <string>#include <vector>
using clk = std::chrono::steady_clock;static const clk::time_point t_start = clk::now();
static double ms_since(clk::time_point t) { return std::chrono::duration<double, std::milli>(clk::now() - t).count();}
static void die(const std::string & msg) { fprintf(stderr, "nnopt_runner: %s\n", msg.c_str()); exit(1);}
static std::string read_file(const std::string & path) { std::ifstream f(path, std::ios::binary); if (!f) die("cannot read " + path); std::stringstream ss; ss << f.rdbuf(); return ss.str();}
static void write_file(const std::string & path, const std::string & data) { std::ofstream f(path, std::ios::binary | std::ios::trunc); if (!f) die("cannot write " + path); f << data;}
// Replace invalid UTF-8 with U+FFFD (like Python's errors="replace") so the JSON stays valid.static std::string sanitize_utf8(const std::string & s) { std::string out; size_t i = 0, n = s.size(); while (i < n) { unsigned char c = s[i]; int len = c < 0x80 ? 1 : (c >> 5) == 0x6 ? 2 : (c >> 4) == 0xE ? 3 : (c >> 3) == 0x1E ? 4 : 0; bool ok = len > 0 && i + len <= n; for (int k = 1; ok && k < len; k++) ok = (((unsigned char) s[i + k]) & 0xC0) == 0x80; if (ok) { out.append(s, i, len); i += len; } else { out += "\xEF\xBF\xBD"; i += 1; } } return out;}
static std::string json_str(const std::string & s) { std::string o = "\""; for (unsigned char c : s) { switch (c) { case '"': o += "\\\""; break; case '\\': o += "\\\\"; break; case '\n': o += "\\n"; break; case '\r': o += "\\r"; break; case '\t': o += "\\t"; break; default: if (c < 0x20) { char b[8]; snprintf(b, sizeof b, "\\u%04x", c); o += b; } else o += (char) c; } } return o + "\"";}
template <typename T>static std::string json_arr(const std::vector<T> & v, const char * fmt) { std::string o = "["; char b[64]; for (size_t i = 0; i < v.size(); i++) { snprintf(b, sizeof b, fmt, v[i]); if (i) o += ", "; o += b; } return o + "]";}
// Parses {"tokens": [int, ...]}.static std::vector<llama_token> parse_tokens_json(const std::string & s) { size_t p = s.find("\"tokens\""); if (p == std::string::npos) die("no \"tokens\" key in score input"); p = s.find('[', p); size_t e = s.find(']', p); if (p == std::string::npos || e == std::string::npos) die("malformed tokens array"); std::vector<llama_token> out; const char * c = s.c_str() + p + 1; const char * end = s.c_str() + e; while (c < end) { char * nx; long v = strtol(c, &nx, 10); if (nx == c) { c++; continue; } out.push_back((llama_token) v); c = nx; } return out;}
static int perf_cores() { int n = 0; size_t sz = sizeof n; if (sysctlbyname("hw.perflevel0.physicalcpu", &n, &sz, nullptr, 0) != 0 || n <= 0) n = 4; return n;}
static double peak_mem_mb() { struct rusage ru; getrusage(RUSAGE_SELF, &ru); return ru.ru_maxrss / (1024.0 * 1024.0); // bytes on macOS}
// Greedy argmax, ties to the lowest id.static llama_token argmax(const float * logits, int n_vocab) { int best = 0; for (int i = 1; i < n_vocab; i++) if (logits[i] > logits[best]) best = i; return best;}
int main(int argc, char ** argv) { std::string model_path, prompt_file, score_file, out_path, metrics_path; int max_new = 128, repeat = 1, top_k = 0; bool ignore_eos = false; for (int i = 1; i < argc; i++) { std::string a = argv[i]; auto next = [&]() -> std::string { if (i + 1 >= argc) die("missing value for " + a); return argv[++i]; }; if (a == "--model") model_path = next(); else if (a == "--prompt-file") prompt_file = next(); else if (a == "--max-new-tokens") max_new = std::stoi(next()); else if (a == "--ignore-eos") ignore_eos = true; else if (a == "--repeat") repeat = std::max(1, std::stoi(next())); else if (a == "--score-tokens") score_file = next(); else if (a == "--top-k") top_k = std::stoi(next()); else if (a == "--out") out_path = next(); else if (a == "--metrics") metrics_path = next(); else die("unknown argument " + a); } if (model_path.empty() || out_path.empty() || metrics_path.empty()) die("need --model, --out, --metrics"); const bool score = !score_file.empty(); if (!score && prompt_file.empty()) die("need --prompt-file or --score-tokens"); if (score && top_k <= 0) die("--score-tokens needs --top-k > 0"); if (score) repeat = 1;
// Inputs are read while loading. std::string prompt_text; std::vector<llama_token> score_tokens; if (score) score_tokens = parse_tokens_json(read_file(score_file)); else prompt_text = read_file(prompt_file);
llama_backend_init();
llama_model_params mparams = llama_model_default_params(); mparams.n_gpu_layers = 999; // -ngl 99: every layer on the Metal GPU // read the weights into Metal buffers (no mmap): the loader repacks the Q1_0 tensors into the tile layout // the patched Metal kernels read (src/patches, q1_0_locate) mparams.load_mode = LLAMA_LOAD_MODE_NONE; llama_model * model = llama_model_load_from_file(model_path.c_str(), mparams); if (!model) die("failed to load model " + model_path); const llama_vocab * vocab = llama_model_get_vocab(model); const int n_vocab = llama_vocab_n_tokens(vocab);
std::vector<llama_token> prompt; if (!score) { int n = -llama_tokenize(vocab, prompt_text.data(), (int32_t) prompt_text.size(), nullptr, 0, true, true); prompt.resize(n); if (llama_tokenize(vocab, prompt_text.data(), (int32_t) prompt_text.size(), prompt.data(), n, true, true) != n) die("tokenize failed"); if (prompt.empty()) die("empty prompt"); } else { if (score_tokens.empty()) die("empty score input"); for (llama_token t : score_tokens) if (t < 0 || t >= n_vocab) die("token id out of range"); }
// Context: 4096 by default (llama-cli's fit minimum), larger only if a request needs it. const int need = score ? (int) score_tokens.size() : (int) prompt.size() + max_new; int n_ctx = 4096; if (need > n_ctx) n_ctx = ((need + 255) / 256) * 256; if (n_ctx > (int) llama_model_n_ctx_train(model)) die("request longer than the model's context");
llama_context_params cparams = llama_context_default_params(); cparams.n_ctx = n_ctx; cparams.n_batch = 2048; cparams.n_ubatch = 512; cparams.n_seq_max = 1; cparams.n_threads = perf_cores(); cparams.n_threads_batch = perf_cores(); cparams.flash_attn_type = LLAMA_FLASH_ATTN_TYPE_AUTO; cparams.type_k = GGML_TYPE_F16; cparams.type_v = GGML_TYPE_F16; cparams.no_perf = true; // n_rs_seq 1: the fork's "rows mode" for the gated delta net, which reads and writes the recurrent state in // the cache inside the fused GDN kernel instead of gathering and copying back 3 MB per layer each token // (same math, identical outputs). NNOPT_RS_SEQ overrides it for A/B runs. cparams.n_rs_seq = getenv("NNOPT_RS_SEQ") ? (uint32_t) atoi(getenv("NNOPT_RS_SEQ")) : 1; llama_context * ctx = llama_init_from_model(model, cparams); if (!ctx) die("failed to create context"); llama_memory_t mem = llama_get_memory(ctx); const int n_batch = (int) llama_n_batch(ctx);
// Warm the Metal pipelines once so load_ms covers shader compilation (not timed as a request). { llama_token t0 = score ? score_tokens[0] : prompt[0]; llama_batch b = llama_batch_get_one(&t0, 1); if (llama_decode(ctx, b) != 0) die("warmup decode failed"); llama_synchronize(ctx); llama_memory_clear(mem, true); } const double load_ms = ms_since(t_start); fprintf(stderr, "nnopt_runner: loaded in %.1f ms (n_ctx %d, n_vocab %d)\n", load_ms, n_ctx, n_vocab);
std::string runs_json; std::string out_json;
if (score) { const int L = (int) score_tokens.size(); clk::time_point t0 = clk::now(); llama_memory_clear(mem, true); llama_batch batch = llama_batch_init(n_batch, 0, 1); std::vector<std::vector<int>> top_ids(L); std::vector<std::vector<float>> top_logits(L); std::vector<int> idx(n_vocab); for (int s = 0; s < L; s += n_batch) { const int n = std::min(n_batch, L - s); batch.n_tokens = n; for (int j = 0; j < n; j++) { batch.token[j] = score_tokens[s + j]; batch.pos[j] = s + j; batch.n_seq_id[j] = 1; batch.seq_id[j][0] = 0; batch.logits[j] = 1; } if (llama_decode(ctx, batch) != 0) die("decode failed (score)"); for (int j = 0; j < n; j++) { const float * lg = llama_get_logits_ith(ctx, j); const int k = std::min(top_k, n_vocab); for (int v = 0; v < n_vocab; v++) idx[v] = v; std::partial_sort(idx.begin(), idx.begin() + k, idx.end(), [&](int a, int b) { return lg[a] > lg[b] || (lg[a] == lg[b] && a < b); }); for (int q = 0; q < k; q++) { top_ids[s + j].push_back(idx[q]); top_logits[s + j].push_back(lg[idx[q]]); } } } llama_batch_free(batch); const double total = ms_since(t0); std::string ids = "[", lgs = "["; for (int i = 0; i < L; i++) { if (i) { ids += ", "; lgs += ", "; } ids += json_arr(top_ids[i], "%d"); lgs += json_arr(top_logits[i], "%.9g"); } out_json = "{\"top_ids\": " + ids + "], \"top_logits\": " + lgs + "]}\n"; char b[128]; snprintf(b, sizeof b, "{\"total_ms\": %.3f}", total); runs_json = b; } else { const int P = (int) prompt.size(); llama_batch batch = llama_batch_init(std::max(n_batch, 1), 0, 1); std::vector<llama_token> gen; for (int r = 0; r < repeat; r++) { gen.clear(); std::vector<double> token_ms; clk::time_point t0 = clk::now(); llama_memory_clear(mem, true); // prefill: logits only for the last prompt token for (int s = 0; s < P; s += n_batch) { const int n = std::min(n_batch, P - s); batch.n_tokens = n; for (int j = 0; j < n; j++) { batch.token[j] = prompt[s + j]; batch.pos[j] = s + j; batch.n_seq_id[j] = 1; batch.seq_id[j][0] = 0; batch.logits[j] = (s + j == P - 1); } if (llama_decode(ctx, batch) != 0) die("decode failed (prefill)"); } llama_token tok = argmax(llama_get_logits_ith(ctx, -1), n_vocab); const double ttft = ms_since(t0); token_ms.push_back(ttft); gen.push_back(tok); clk::time_point tp = clk::now(); while ((int) gen.size() < max_new && (ignore_eos || !llama_vocab_is_eog(vocab, tok))) { batch.n_tokens = 1; batch.token[0] = tok; batch.pos[0] = P + (int) gen.size() - 1; batch.n_seq_id[0] = 1; batch.seq_id[0][0] = 0; batch.logits[0] = 1; if (llama_decode(ctx, batch) != 0) die("decode failed (generate)"); tok = argmax(llama_get_logits_ith(ctx, -1), n_vocab); gen.push_back(tok); token_ms.push_back(ms_since(tp)); tp = clk::now(); } const double total = ms_since(t0); char b[256]; snprintf(b, sizeof b, "{\"total_ms\": %.3f, \"ttft_ms\": %.3f, \"prompt_tokens\": %d, \"new_tokens\": %d, \"token_ms\": ", total, ttft, P, (int) gen.size()); if (r) runs_json += ", "; runs_json += std::string(b) + json_arr(token_ms, "%.3f") + "}"; fprintf(stderr, "nnopt_runner: run %d: ttft %.1f ms, %d tokens in %.1f ms\n", r, ttft, (int) gen.size(), total); } llama_batch_free(batch);
std::string text; { int n = llama_detokenize(vocab, gen.data(), (int32_t) gen.size(), nullptr, 0, false, true); text.resize(n < 0 ? -n : n); n = llama_detokenize(vocab, gen.data(), (int32_t) gen.size(), &text[0], (int32_t) text.size(), false, true); if (n < 0) die("detokenize failed"); text.resize(n); } out_json = "{\"prompt_tokens\": " + json_arr(prompt, "%d") + ", \"tokens\": " + json_arr(gen, "%d") + ", \"text\": " + json_str(sanitize_utf8(text)) + "}\n"; }
write_file(out_path, out_json); char b[128]; snprintf(b, sizeof b, "{\"load_ms\": %.3f, \"peak_mem_mb\": %.1f, \"runs\": [", load_ms, peak_mem_mb()); write_file(metrics_path, std::string(b) + runs_json + "]}\n");
llama_free(ctx); llama_model_free(model); llama_backend_free(); return 0;}.gitattributes+17-32
LICENSEAdded+177
LICENSE-llama.cppAdded+21
NOTICEAdded+15
README.mdAdded+78
config.jsonAdded+34
m2pro-gpu-q1_0/README.mdAdded+73
m2pro-gpu-q1_0/build.shAdded+52
m2pro-gpu-q1_0/deploy.shAdded+22
m2pro-gpu-q1_0/fetch.shAdded+33
m2pro-gpu-q1_0/nnopt-prismml-5ae2e169.patchAdded+562
m2pro-gpu-q1_0/report.htmlAdded+110
m2pro-gpu-q1_0/report/reproduce.shAdded+14
m2pro-gpu-q1_0/report/results.csvAdded+81
m2pro-gpu-q1_0/report/results.jsonAdded+1404
m2pro-gpu-q1_0/src/CMakeLists.txtAdded+23
m2pro-gpu-q1_0/src/patches/0001-q1_0-lut-gemv.patchAdded+549
m2pro-gpu-q1_0/src/run.shAdded+3
m2pro-gpu-q1_0/src/runner.cppAdded+335