Created
August 5, 2025 06:36
-
-
Save alfredplpl/feaf3f1ce0f9647009b240edea3075dc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ref: https://huggingface.co/Qwen/Qwen-Image/discussions/7 | |
from diffusers import DiffusionPipeline, PipelineQuantizationConfig | |
from diffusers import BitsAndBytesConfig | |
import torch | |
quant_config = PipelineQuantizationConfig( | |
quant_mapping={ | |
"transformer": BitsAndBytesConfig( | |
load_in_4bit=True, | |
bnb_4bit_compute_dtype=torch.bfloat16, | |
bnb_4bit_quant_type="nf4", | |
llm_int8_skip_modules=[ | |
"time_text_embed", | |
"img_in", | |
"norm_out", | |
"proj_out", | |
"img_mod", | |
"txt_mod", | |
], | |
), | |
} | |
) | |
pipe = DiffusionPipeline.from_pretrained( | |
"Qwen/Qwen-Image", | |
quantization_config=quant_config, | |
torch_dtype=torch.bfloat16 | |
) | |
pipe.enable_model_cpu_offload() | |
prompt = "Japanese anime style, a cat holding a sign that says hello world" | |
negative_prompt="3d, cg, photo" | |
image = pipe( | |
prompt=prompt, | |
negative_prompt=negative_prompt, | |
num_inference_steps=50, | |
).images[0] | |
image.save("qwenimage_nf4.png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
生成物
