Views
No views yet
Silan10/flux-quanto-int8 is an 8-bit quantized version of the
black-forest-labs/FLUX.1-dev
text-to-image model. In this version, the transformer component has been quantized to 8-bit precision using optimum-quanto.quantized_flux.py from this repo:1import torch
2from diffusers import FluxPipeline
3from huggingface_hub import hf_hub_download
4import importlib.util
5
6REPO_ID = "Silan10/flux-quanto-int8"
7FLUX_MODEL_PATH = "black-forest-labs/FLUX.1-dev" # Or local path
8
9# Download and import QuantizedFluxTransformer2DModel
10quantized_flux_path = hf_hub_download(repo_id=REPO_ID, filename="quantized_flux.py")
11spec = importlib.util.spec_from_file_location("quantized_flux", quantized_flux_path)
12quantized_flux = importlib.util.module_from_spec(spec)
13spec.loader.exec_module(quantized_flux)
14QuantizedFluxTransformer2DModel = quantized_flux.QuantizedFluxTransformer2DModel
15
16# Load quantized transformer
17print("Loading quantized transformer...")
18transformer = QuantizedFluxTransformer2DModel.from_pretrained(REPO_ID)
19transformer.to(device="cuda")
20
21# Load rest of pipeline
22print("Loading pipeline...")
23pipe = FluxPipeline.from_pretrained(
24 FLUX_MODEL_PATH,
25 transformer=None,
26 torch_dtype=torch.bfloat16
27)
28pipe.to("cuda")
29
30pipe.transformer = transformer
31pipe.vae.to(torch.float32)
32print("✓ Pipeline ready.")
33
34prompt = "Ultra-detailed nighttime cyberpunk city street, several pedestrians in modern clothes, one person in the foreground looking toward the camera, sharp facial features and detailed hair, wet pavement reflecting colorful neon signs, shop windows with small readable text on signs, a gradient sky fading from deep blue to purple, a mix of strong highlights and deep shadows, highly detailed, 4K, cinematic lighting."
35print("Generating image...")
36
37image = pipe(
38 prompt,
39 num_inference_steps=20,
40 guidance_scale=3.5,
41 max_sequence_length=512,
42 width=1024,
43 height=1024,
44 generator=torch.Generator("cpu").manual_seed(42)
45).images[0]
46
47image.save("output_quanto_int8.png")
48print("✓ Image generated successfully.")
49print("DONE!")