litert-community / Bonsai-Image-ternary-4B

huggingface.co
Total runs: 3.0K
24-hour runs: 32
7-day runs: 155
30-day runs: 2.1K
Model's Last Updated: September 05 2026
text-to-image

Introduction of Bonsai-Image-ternary-4B

Model Details of Bonsai-Image-ternary-4B

Bonsai Image 4B — LiteRT (.tflite)

PrismML Bonsai Image 4B — a ternary-weight diffusion transformer built on the FLUX.2-klein-4B architecture — converted to LiteRT for on-device text-to-image. The whole pipeline runs in three fixed-shape .tflite graphs; the host does only tokenization, the FlowMatch-Euler loop, and latent unpatchify ( generate.py in this repo, ~150 lines, no torch and no diffusers).

graph file recipe size
DiT (Flux2Transformer2DModel, 3.88 B) dit_int4b32.tflite int4 block-32 2.11 GiB
text encoder (Qwen3-4B, top 9 layers pruned) textenc_int4.tflite int4 block-128 DRQ 1.68 GiB
text encoder — higher-fidelity variant textenc_int8_weightonly.tflite int8 weight-only 2.91 GiB
VAE decoder (AutoencoderKLFlux2) vae_dec_fp32.tflite fp32 0.19 GiB

Smallest working set: 3.97 GiB (int4 text encoder). Output is fixed at 512×512, 256 prompt tokens, 4 sampling steps by default (the model is step-distilled; more steps also work).

The ternary weights survive int4 exactly

The vendor ships the DiT with ternary weights (every block linear uses values {−scale, 0, +scale} per 128-group). In the int4 block-32 container those land as exactly {−7, 0, +7} — zero rounding decisions, verified in the converted artifact. The int4 file is a lossless container for this model's weights, at 2.11 GiB versus 14.4 GiB fp32.

Quality

Converting without quantizing anything is essentially exact (76.8 dB vs the PyTorch pipeline). With quantization, low PSNR against the PyTorch sample is sampler drift, not degradation : a small weight perturbation amplified through 4 sampling steps lands on a different draw from the same distribution. Across a 6-prompt stress set (legible text, a face, macro texture, a smooth gradient, a cluttered scene), reference-free sharpness stays flat across every recipe (Laplacian variance 1086 → 1069 at the lowest-PSNR variant), text stays legible, and faces stay correct in all columns. Pick a text encoder by size, not by fear: int4 if you want the smallest set, int8 weight-only if you want to track the reference sample more closely.

quality grid

Run it
pip install ai-edge-litert numpy pillow transformers
python generate.py --model-dir . --prompt "a red fox sitting in fresh snow at sunrise" --seed 42 --out fox.png

example

Timings on an Apple-silicon Mac (CPU, 8 threads): DiT ~3.9 s/step, text encoder 2.6 s, VAE 1.3 s — ~19 s per 512×512 image at 4 steps.

On-device (iPhone 17 Pro, CPU via XNNPACK, 6 threads): the 2.11 GiB DiT loads and prepares in 4.5 s; 13 s per DiT step, text encoder 1.8 s, VAE 3.1 s — ** 64 s per 512×512 image** at 4 steps, ~2.9 GiB peak memory. Device output is bit-exact against the Mac run (every DiT step matches to the last float; 51.2 dB PSNR on the final PNG). One integration note: attach the XNNPACK delegate explicitly (with your thread count) when using the C API — without it the runtime falls back to reference kernels, which are orders of magnitude slower on this model.

Conversion

Converted with [litert-torch] via the recipe published at hf-to-litertlm (export scripts, quantization, and the two conversion gotchas: Flux2's float64 RoPE frequency table must be forced to float32 to legalize tfl.pow , and blockwise zero-scales in all-zero blocks need patching for XNNPACK). The text encoder is exported as a prompt embedder — the pipeline reads hidden states from layers (9, 18, 27) only, so the top 9 of 36 layers and the LM head are pruned for free.

License

Apache-2.0, following the upstream prism-ml/bonsai-image-ternary-4B release.

Runs of litert-community Bonsai-Image-ternary-4B on huggingface.co

3.0K
Total runs
32
24-hour runs
40
3-day runs
155
7-day runs
2.1K
30-day runs

More Information About Bonsai-Image-ternary-4B huggingface.co Model

More Bonsai-Image-ternary-4B license Visit here:

https://choosealicense.com/licenses/apache-2.0

Bonsai-Image-ternary-4B huggingface.co

Bonsai-Image-ternary-4B huggingface.co is an AI model on huggingface.co that provides Bonsai-Image-ternary-4B's model effect (), which can be used instantly with this litert-community Bonsai-Image-ternary-4B model. huggingface.co supports a free trial of the Bonsai-Image-ternary-4B model, and also provides paid use of the Bonsai-Image-ternary-4B. Support call Bonsai-Image-ternary-4B model through api, including Node.js, Python, http.

litert-community Bonsai-Image-ternary-4B online free

Bonsai-Image-ternary-4B huggingface.co is an online trial and call api platform, which integrates Bonsai-Image-ternary-4B's modeling effects, including api services, and provides a free online trial of Bonsai-Image-ternary-4B, you can try Bonsai-Image-ternary-4B online for free by clicking the link below.

litert-community Bonsai-Image-ternary-4B online free url in huggingface.co:

https://huggingface.co/litert-community/Bonsai-Image-ternary-4B

Bonsai-Image-ternary-4B install

Bonsai-Image-ternary-4B is an open source model from GitHub that offers a free installation service, and any user can find Bonsai-Image-ternary-4B on GitHub to install. At the same time, huggingface.co provides the effect of Bonsai-Image-ternary-4B install, users can directly use Bonsai-Image-ternary-4B installed effect in huggingface.co for debugging and trial. It also supports api for free installation.

Bonsai-Image-ternary-4B install url in huggingface.co:

https://huggingface.co/litert-community/Bonsai-Image-ternary-4B

Url of Bonsai-Image-ternary-4B

Provider of Bonsai-Image-ternary-4B huggingface.co

litert-community
ORGANIZATIONS

Other API from litert-community