bonsai-image-ternary-4B on Samsung Galaxy S26+ (OpenCL)
Ported and verified on a real Samsung Galaxy S26+ by nnopt.dev β AI agents that port and optimize models for the hardware you ship.
The model is prism-ml/bonsai-image-ternary-4B-unpacked by Prism ML, and it is theirs. The OpenCL port in this repository is nnopt's work: nnopt job NN-C9116E.
Created using Bonsai Image by Prism ML.
| Device | Samsung Galaxy S26+, Android 16 |
| Chip | Snapdragon 8 Elite Gen 5 (SM8850) |
| Processor | GPU (Adreno 840) |
| Runtime | custom C++ OpenCL runtime (no other engine) |
| Precision | fp32 activations and accumulation; DiT block linears ternary 2-bit + bf16 scale per 128 kept packed; text encoder, VAE and other weights bf16 |
| Modality | text -> image |
| Weights | included: build/weights/te.bin, dit.bin, vae.bin with their .idx files, tokenizer.json and .stamp, the exact packs verified on the phone (made from the original checkpoint by tools/convert.py; DiT linears stay ternary, 2-bit + bf16 scale per 128; text encoder and VAE bf16) |
| nnopt job | NN-C9116E (port) |
| Folder | sm8850-gpu-ternary/ |
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. Matches the reference 2 of 2 cases
- Max abs error 0.062 (bar rtol 0.01, atol 0.01xrms)
- Time per call 35,181 ms (35.2 s: Qwen3 text encoder 512 tokens + one ternary DiT step at 512x512 + VAE decode; transformer 10.0 s, vae decoder 4.0 s)
- Load time 1.13 s
- Peak memory 5,728 MB
Use it
mkdir Bonsai-Image-Ternary-4B-OpenCL && cd Bonsai-Image-Ternary-4B-OpenCL
curl -fsSL https://huggingface.co/nnopt-dev/Bonsai-Image-Ternary-4B-OpenCL/resolve/main/config.json -o config.json
hf download nnopt-dev/Bonsai-Image-Ternary-4B-OpenCL --include "sm8850-gpu-ternary/*" --local-dir .
cd sm8850-gpu-ternary
bash fetch.sh
bash deploy.sh /data/local/tmp/nnopt/port # adb: program into DEST, weight packs into /data/local/tmp/nnopt/bonsai_image_weights
adb shell "cd /data/local/tmp/nnopt/port && sh ./run.sh --prompt 'A cat holding a sign that says hello world' \
--seed 0 --png /data/local/tmp/nnopt/cat.png --metrics /data/local/tmp/nnopt/cat.json"
adb pull /data/local/tmp/nnopt/cat.png
Needs: An Adreno phone with ~6 GB free RAM and ~7 GB free storage (tested: Galaxy S26+); adb. Rebuilding needs Linux x86-64 or macOS arm64 with git, curl, python3 (venv), unzip and the hf CLI.
Included weight files (verified on the phone):
| File | Size | sha256 |
|---|---|---|
sm8850-gpu-ternary/build/weights/te.bin |
6,228,466,688 bytes | b384a6e93c705076c2a9dd3418e5e47be82ba9948cd8c2b0b3cc2c4adf79bfa4 |
sm8850-gpu-ternary/build/weights/dit.bin |
1,367,734,272 bytes | f30d70cee51edb96b2f278c390c4560923c68e0c9c0977f9481e0468be8ac2b1 |
sm8850-gpu-ternary/build/weights/vae.bin |
99,317,260 bytes | 54ac1a1045def03fecaa091e13663989639779185ad05efc107b353152b6e5e5 |
sm8850-gpu-ternary/build/weights/te.idx |
6,414 bytes | eb7466449abfd0c7dc427dfd09b8c49167d8c8f716f0f02ab2ae13a5ba6ac32b |
sm8850-gpu-ternary/build/weights/dit.idx |
7,614 bytes | 4ca7c3c7ef4165e9f6fd50b833f62cca21715a47f4536164521746327e2fbb7a |
sm8850-gpu-ternary/build/weights/vae.idx |
4,104 bytes | d52f0646dd0c9b533b6025833e102295eea57b48c20da969f2203c4cdcc9cb07 |
sm8850-gpu-ternary/build/weights/tokenizer.json |
4,561,647 bytes | 58e0ac44f0a640c2b4a1cfbea927ef695fd0c2b4d2e0e614e6a3e33684e89069 |
Optional: rebuild from the original weights instead.
hf download prism-ml/bonsai-image-ternary-4B-unpacked --revision 30bbc032dd26939bff95c3d523477ad5065c3e1a --local-dir inputs/weights
rm -f build/weights/.stamp && INPUTS_DIR="$PWD/inputs" bash build.sh # NDK r27d + numpy into .deps/, rebuilds the program and build/weights/
Determinism checked: re-running tools/convert.py and tools/tokjson.py on the pinned original weights gives byte-identical files (same sha256 for te.bin, dit.bin, vae.bin, the .idx files, tokenizer.json).
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-image-ternary-4B-unpacked: see LICENSE and NOTICE.
Made with nnopt
nnopt 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.
- Downloads last month
- 3
Model tree for nnopt-dev/Bonsai-Image-Ternary-4B-OpenCL
Base model
black-forest-labs/FLUX.2-klein-4B