Reproduction of
1.58-bit FLUX (Yang et al., 2024).
Ternary ({-1, 0, +1}) quantization of FLUX.1-dev transformer with LoRA compensation, trained via offline flow-matching distillation.
1from diffusers import FluxPipeline
2from models.ternary import quantize_to_ternary
3import torch
4
5pipe = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-dev",
6 torch_dtype=torch.bfloat16).to("cuda")
7
8# Quantize to ternary + LoRA
9quantize_to_ternary(pipe.transformer, lora_rank=128, svd_init=False)
10
11# Load checkpoint
12ckpt = torch.load("ternary_distilled_r128_res1024_s12000_fm_lpips1e-01.pt",
13 map_location="cuda", weights_only=True)
14state = {k: v for k, v in pipe.transformer.named_parameters()}
15for name, tensor in ckpt.items():
16 if name in state:
17 state[name].data.copy_(tensor.to(torch.bfloat16))
18
19# Generate
20image = pipe("A majestic lion resting on a savanna at golden hour",
21 height=1024, width=1024, num_inference_steps=30,
22 guidance_scale=3.5).images[0]
1@misc{ugonfor2026ternaryflux,
2 title={Reproducing 1.58-Bit FLUX: Ternary Quantization with LoRA Compensation},
3 author={Ugon For},
4 year={2026},
5 url={https://github.com/ugonfor/1.58bit-flux}
6}
Based on
1.58-bit FLUX by Yang et al.
Base model:
FLUX.1-dev by Black Forest Labs.