Views
No views yet
pip install git+https://github.com/huggingface/diffusers1import torch
2
3from diffusers import DiffusionPipeline, GGUFQuantizationConfig, QwenImageTransformer2DModel
4
5
6torch_dtype = torch.bfloat16
7model_id = "Qwen/Qwen-Image"
8
9transformer = QwenImageTransformer2DModel.from_single_file(
10 "https://huggingface.co/OzzyGT/qwen-image-lighting-gguf/blob/main/qwen-image-lighting-Q4_K_S.gguf",
11 quantization_config=GGUFQuantizationConfig(compute_dtype=torch_dtype),
12 torch_dtype=torch_dtype,
13 config="Qwen/Qwen-Image",
14 subfolder="transformer",
15)
16pipe = DiffusionPipeline.from_pretrained(model_id, transformer=transformer, torch_dtype=torch_dtype)
17pipe.enable_model_cpu_offload()
18prompt = "stock photo of two people, a man and a woman, wearing lab coats writing on a white board with markers, the white board has text that reads 'The Diffusers library by Hugging Face makes it easy for developers to run image generation and inference using state-of-the-art diffusion models with just a few lines of code' with sloppy writing and traces clearly made by a human. The photo is taken from the side and has depth of field so some parts of the board looks blurred giving it a more professional look"
19
20generator = torch.Generator(device="cuda").manual_seed(42)
21
22image = pipe(
23 prompt=prompt,
24 negative_prompt="",
25 width=1664,
26 height=928,
27 num_inference_steps=8,
28 true_cfg_scale=1.0,
29 generator=generator,
30).images[0]
31
32image.save("gguf_lighting_qwen.png")
pip install git+https://github.com/huggingface/diffusers1import torch
2from transformers import BitsAndBytesConfig as TransformersBitsAndBytesConfig
3from transformers import Qwen2_5_VLForConditionalGeneration
4
5from diffusers import DiffusionPipeline, GGUFQuantizationConfig, QwenImageTransformer2DModel
6
7
8torch_dtype = torch.bfloat16
9model_id = "Qwen/Qwen-Image"
10
11transformer = QwenImageTransformer2DModel.from_single_file(
12 "https://huggingface.co/OzzyGT/qwen-image-lighting-gguf/blob/main/qwen-image-lighting-Q4_K_S.gguf",
13 quantization_config=GGUFQuantizationConfig(compute_dtype=torch_dtype),
14 torch_dtype=torch_dtype,
15 config="Qwen/Qwen-Image",
16 subfolder="transformer",
17)
18
19quantization_config = TransformersBitsAndBytesConfig(
20 load_in_4bit=True,
21 bnb_4bit_quant_type="nf4",
22 bnb_4bit_compute_dtype=torch.bfloat16,
23)
24
25text_encoder = Qwen2_5_VLForConditionalGeneration.from_pretrained(
26 model_id,
27 subfolder="text_encoder",
28 quantization_config=quantization_config,
29 torch_dtype=torch_dtype,
30)
31text_encoder = text_encoder.to("cpu")
32
33pipe = DiffusionPipeline.from_pretrained(
34 model_id, transformer=transformer, text_encoder=text_encoder, torch_dtype=torch_dtype
35)
36pipe.enable_model_cpu_offload()
37prompt = "stock photo of two people, a man and a woman, wearing lab coats writing on a white board with markers, the white board has text that reads 'The Diffusers library by Hugging Face makes it easy for developers to run image generation and inference using state-of-the-art diffusion models with just a few lines of code' with sloppy writing and traces clearly made by a human. The photo is taken from the side and has depth of field so some parts of the board looks blurred giving it a more professional look"
38
39generator = torch.Generator(device="cuda").manual_seed(42)
40
41image = pipe(
42 prompt=prompt,
43 negative_prompt="",
44 width=1664,
45 height=928,
46 num_inference_steps=8,
47 true_cfg_scale=1.0,
48 generator=generator,
49).images[0]
50
51image.save("gguf_lighting_qwen.png")