File size: 2,770 Bytes
6ecea59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
---
license: apache-2.0
base_model: black-forest-labs/FLUX.2-klein-4B
base_model_relation: quantized
pipeline_tag: text-to-image
library_name: coreai
tags:
  - coreai
  - ios
  - text-to-image
  - flux
  - react-native
---

# FLUX.2 klein 4B for Core AI on iPhone

[black-forest-labs/FLUX.2-klein-4B](https://huggingface.co/black-forest-labs/FLUX.2-klein-4B) (4B parameters, step-distilled text-to-image) exported to Apple Core AI for iOS with the [`apple/coreai-models`](https://github.com/apple/coreai-models) recipe. It runs on iOS 27 and macOS 27 with the `FlowTransformerPipeline` from the `CoreAIDiffusion` product of `coreai-models`, and generates 512x512 images in 4 steps.

## Files

`ios/` holds the text-to-image components of the recipe's iOS export, 4-bit weights (4.0 GB):

| File | Size | |
| --- | --- | --- |
| `Transformer_512.aimodel` | 2.0 GB | DiT, 25 blocks, 512x512 |
| `TextEncoder.aimodel` | 1.6 GB | Qwen3 text encoder |
| `VAEDecoder_half.aimodel` | 95 MB | latent to 512x512 image |
| `tokenizer/`, `metadata.json`, `vae_bn_*.npy` | 11 MB | |

The image-to-image transformer and VAE encoder of the full iOS export are left out. The pipeline loads one component at a time by default (`lazyModelLoading`), so it fits in the memory an iPhone 17 Pro gives an app.

## Use

With [`@react-native-ai/core-ai`](https://github.com/callstackincubator/ai), download the `ios` folder and pass its path:

```typescript
import { coreAI } from '@react-native-ai/core-ai'
import { generateImage } from 'ai'

const { image } = await generateImage({
  model: coreAI.imageModel({
    id: 'flux2-klein-4b',
    source: { type: 'file', uri: fluxModelPath },
  }),
  prompt: 'a red apple on a wooden table',
  size: '512x512',
  seed: 42,
  providerOptions: { 'core-ai': { stepCount: 4 } },
})
```

In Swift:

```swift
import CoreAIDiffusionPipeline

let pipeline = try await FlowTransformerPipeline(from: modelURL)
let configuration = PipelineConfiguration(
    prompt: "a red apple on a wooden table",
    seed: 42,
    stepCount: 4,
    guidanceScale: 1.0,
    schedulerType: .discreteFlow
)
let image = try await pipeline.generateImages(configuration: configuration) { _ in true }.images[0]
```

## Export

From [`apple/coreai-models`](https://github.com/apple/coreai-models) at `5de95c6` (1.0.0), with `coreai-core` 1.0.0b3. This is `--platform iOS` (4-bit, single-function, 512) without the image-to-image components:

```bash
uv run coreai.diffusion.export flux2-klein-4b --single-function \
    --components transformer_512 text_encoder vae_decoder_half
```

## License

Apache-2.0, as the original model. The weights were converted to Core AI and quantized to 4 bits, and are otherwise unchanged. FLUX.2 [klein] is by [Black Forest Labs](https://bfl.ai).