dtaddis/localimagegen-flux2-klein-4b-unity
FLUX.2 Klein 4B for Unity 6
A verified, ready-to-run mixed-precision conversion of FLUX.2 Klein 4B for Unity 6 and Unity Inference Engine (formerly Sentis).
The runtime is entirely C# and Unity Inference Engine. It does not require Python, a local web server, or a separate inference process.
These files are designed for Local AI Image Gen, a Unity Asset Store package coming soon from David Addis' publisher page. The package will be available at its direct Asset Store listing once published.
What is included
- Qwen text encoder split into 9 UINT8
.sentisstages - FLUX.2 transformer split into 7 FP16
.sentisstages - VAE decoder split into 6 FP16
.sentisstages - Qwen tokenizer JSON used by the Unity C# tokenizer
- A SHA-256 manifest for all runtime files
The 23 runtime files total approximately 10.23 GiB. Staging the networks keeps peak memory substantially below loading the complete text encoder, transformer, and VAE at the same time.
Verified Unity result
This exact uploaded artifact set was tested end-to-end with:
- Unity
6000.5.5f1 com.unity.ai.inference2.6.1- Windows Editor using Direct3D 12
- NVIDIA GeForce RTX 4090 with 24 GB VRAM
- LocalImageGen's accelerated D3D12 path: the seven FP16 transformer stages run through persistent
GPUComputeworkers, while the UINT8 text encoder and FP16 VAE run on CPU to keep the complete pipeline within 24 GB VRAM - 1024 x 1024 output
- 4 inference steps
- Guidance scale
1.0 - Seed
27101
Prompt:
A copper clockwork fox carries 27 blueberries through Sao Paulo's moonlit greenhouse; watercolor, ultra-detailed.
The Unity C# tokenizer produced 38 prompt tokens. Initialization took 2.459 s; generation took 169.656 s; the complete validation took 172.135 s (2m52s). It produced a valid prompt-aligned image, reported no non-finite tensors, and left the Unity console with zero errors. Peak observed GPU memory was approximately 22.6 GB.
The tested model-content revision is fd953005ff22e26b58fce7da6d9a8b6786c97865. LocalImageGen pins this immutable revision so later model-card-only commits cannot change downloaded runtime artifacts.
Direct3D 12 support
D3D12 acceleration is supported by the current LocalImageGen runtime. The important implementation detail is worker lifetime: all seven transformer workers are created once and reused for every denoising step. Recreating the seven large workers on every step caused Unity's D3D12 backend to retain heap reservations and eventually exhaust GPU memory.
The mixed execution path is deliberate:
- Transformer: D3D12
GPUCompute - Text encoder: CPU
- VAE decoder: CPU
Keeping the text encoder and VAE off the GPU leaves enough room for the persistent FP16 transformer worker set. The verified RTX 4090 run nearly filled 24 GB VRAM, so 24 GB should be treated as the recommended D3D12 configuration for this 1024 x 1024 profile. Other GPU and VRAM configurations have not yet been validated.
LocalImageGen also supports decoding intermediate previews when Show Intermediates is enabled. Intermediate VAE decoding runs on CPU and therefore adds noticeable time; early denoising previews are expected to look noisy.
This remains the high-quality local demonstration tier rather than the lightweight desktop or mobile option.
Precision and file layout
tokenizer/tokenizer.json
text_encoder/stage_0_uint8.sentis ... stage_8_uint8.sentis
transformer/stage_0_fp16.sentis ... stage_6_fp16.sentis
vae_decoder/pre_attention_fp16.sentis
vae_decoder/attention_chunk_fp16.sentis
vae_decoder/post_stage0_fp16.sentis ... post_stage3_fp16.sentisThis is a mixed UINT8/FP16 build. The text encoder uses UINT8 weight storage; the transformer and VAE use FP16 to preserve generation and decoded image quality.
A naively UINT8-quantized transformer was tested and rejected: it retained coarse prompt semantics but produced severely washed, yellow-tinted images. Those transformer artifacts are intentionally not included in this release.
Using it
Install Local Image Generator in a Unity 6 project, then use:
Tools > LocalImageGen > Model Setup
Select Modern 1024 — FLUX.2 Klein 4B, download the pinned repository revision, and assign the downloaded files to the FLUX.2 generator prefab. Inference and tokenization then run inside Unity through the package's public C# API.
Conversion notes
Unity Inference Engine's ONNX importer does not preserve arbitrary offsets in external tensor data. The source graphs were therefore repacked so external initializers are sequential and offset-bearing LayerNorm constants are embedded. Incorrect symbolic rotary-batch metadata was also repaired before the .sentis files were generated.
Python-based tooling was used to convert and validate the source model and to publish this repository. Python is not part of the Unity runtime or public package API.
Provenance and license
The source model is `black-forest-labs/FLUX.2-klein-4B`. The source model and this converted artifact set are distributed under the Apache License 2.0; see LICENSE.
FLUX is a model family from Black Forest Labs. This repository is an independent Unity conversion and is not an official Black Forest Labs or Unity Technologies release.
