Views
No views yet
pip install git+https://github.com/huggingface/transformers.git1import torch
2
3from transformers import (
4 BitsAndBytesConfig as BitsAndBytesConfig,
5 Qwen3ForCausalLM,
6)
7
8from diffusers import Flux2KleinPipeline
9
10dtype = torch.float16
11device = "cuda"
12
13text_encoder_8bit = Qwen3ForCausalLM.from_pretrained(
14 "aifeifei798/FLUX.2-klein-9B-text_encoder-8bit",
15 torch_dtype=dtype,
16)
17
18pipe = Flux2KleinPipeline.from_pretrained(
19 "black-forest-labs/FLUX.2-klein-9B",
20 text_encoder=text_encoder_8bit,
21 torch_dtype=dtype,
22)
23#pipe.to("cuda") # GPU < 32G
24pipe.enable_model_cpu_offload() # save some VRAM by offloading the model to CPU,GPU < 32G
25
26prompt = "A cat holding a sign that says hello world"
27image = pipe(
28 prompt,
29 height=1024,
30 width=1024,
31 guidance_scale=1.0,
32 num_inference_steps=4,
33 generator=torch.Generator(device=device).manual_seed(0),
34).images[0]
35image.save("flux-klein.png")