> ## Documentation Index
> Fetch the complete documentation index at: https://docs.prismml.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Bonsai Image 4B

> Local image generation with compact 1-bit and ternary diffusion transformers.

Bonsai Image 4B is a family of compact text-to-image models designed to run locally on phones, laptops, and NVIDIA GPUs. It is based on FLUX.2 Klein 4B.

The diffusion transformer is available with either 1-bit binary or ternary weights. A small number of precision-sensitive layers remain at higher precision, while the text encoder and VAE are compressed separately as part of the complete deployment pipeline.

## Specifications

|                     |                                        |
| :------------------ | :------------------------------------- |
| Parameters          | 4B                                     |
| Base model          | FLUX.2 Klein 4B                        |
| Task                | Text-to-image generation               |
| Default resolution  | 512 × 512                              |
| Supported platforms | Apple Silicon, iPhone, and NVIDIA GPUs |
| License             | Apache 2.0                             |

## Variants

| Family                  | Weight format                          | Transformer size | Complete MLX payload | Recommended for                          |
| :---------------------- | :------------------------------------- | :--------------- | :------------------- | :--------------------------------------- |
| Ternary Bonsai Image 4B | Ternary weights with FP16 group scales | 1.21 GB          | 3.88 GB              | Higher image quality and prompt fidelity |
| 1-bit Bonsai Image 4B   | Binary weights with FP16 group scales  | 0.93 GB          | 3.42 GB              | Minimum memory footprint                 |

The Ternary model is the recommended default. It preserves more of the original model's visual quality while reducing the diffusion transformer to 1.21 GB. The 1-bit model brings the diffusion transformer below 1 GB and is optimized for devices where memory capacity and bandwidth are the primary constraints.

## Artifacts

All model repositories are available in the [Bonsai Image collection](https://huggingface.co/collections/prism-ml/bonsai-image) on Hugging Face.

| Family  | Runtime        | Repository                                      | Transformer size |
| :------ | :------------- | :---------------------------------------------- | :--------------- |
| Ternary | MLX            | `prism-ml/bonsai-image-ternary-4B-mlx-2bit`     | 1.21 GB          |
| Ternary | Gemlite / CUDA | `prism-ml/bonsai-image-ternary-4B-gemlite-2bit` | 1.21 GB          |
| 1-bit   | MLX            | `prism-ml/bonsai-image-binary-4B-mlx-1bit`      | 0.93 GB          |
| 1-bit   | Gemlite / CUDA | `prism-ml/bonsai-image-binary-4B-gemlite-1bit`  | 0.93 GB          |

The MLX repositories are intended for Apple Silicon. The Gemlite repositories use low-bit CUDA kernels for NVIDIA GPUs.

## How to run it

Clone the [Bonsai Image demo repository](https://github.com/PrismML-Eng/Bonsai-Image-Demo):

```bash theme={null}
git clone https://github.com/PrismML-Eng/Bonsai-Image-Demo.git
cd Bonsai-Image-Demo
```

Install the required dependencies and download the default ternary model:

```bash theme={null}
./setup.sh
```

The setup script detects your platform and selects the appropriate runtime:

* MLX on Apple Silicon - Gemlite on Linux with an NVIDIA GPU

To install the smaller 1-bit model instead:

```bash theme={null}
BONSAI_VARIANT=binary ./setup.sh
```

### Generate an image

Run a single generation from the command line:

```bash theme={null}
./scripts/generate.sh \
  --prompt "An icy bonsai tree in a rainy forest, with snowy mountains in the background, photorealistic."
```

You can also configure the image size, seed, and output path:

```bash theme={null}
./scripts/generate.sh \
  --prompt "A hand-drawn map of a floating island, intricate ink illustration." \
  --size 1024x1024 \
  --seed 42 \
  --output outputs/floating-island.png \
  --open
```

### Launch the local studio

Start the generation API and browser interface:

```bash theme={null}
./scripts/serve.sh
```

This launches:

| Service             | Address                 |
| :------------------ | :---------------------- |
| Bonsai Image Studio | `http://localhost:3000` |
| Generation API      | `http://localhost:8000` |

Send a generation request from another terminal:

```bash theme={null}
./scripts/send_request.sh \
  --prompt "A compact futuristic city built into a desert canyon at sunset." \
  --size 1024x1024 \
  --seed 42
```

## Performance

For a 512 × 512 image, Bonsai Image 4B generates in approximately:

| Hardware                | Generation time         |
| :---------------------- | :---------------------- |
| iPhone 17 Pro Max       | 9.4 seconds             |
| MacBook Pro with M4 Pro | Approximately 6 seconds |

On an M4 Pro, Bonsai Image 4B is up to 5.6× faster than the full-precision MFLUX pipeline. Mean active memory during 512 × 512 generation is approximately:

| Model                          | Active memory |
| :----------------------------- | :------------ |
| 1-bit Bonsai Image 4B          | 1.50 GB       |
| Ternary Bonsai Image 4B        | 1.96 GB       |
| Full-precision FLUX.2 Klein 4B | 11.74 GB      |

## Run on iPhone

Bonsai Image 4B is also available through [Bonsai Studio](https://apps.apple.com/us/app/bonsai-studio-by-prismml/id6767042620) for iPhone.

The app runs the ternary model directly on the device. Prompts and generated images remain local, and image generation does not require an internet connection.

For the best experience, use an iPhone 15 Pro or newer with at least 8 GB of unified memory.
