Skip to content

Instantly share code, notes, and snippets.

@alfredplpl
Created August 5, 2025 06:36
Show Gist options
  • Save alfredplpl/feaf3f1ce0f9647009b240edea3075dc to your computer and use it in GitHub Desktop.
Save alfredplpl/feaf3f1ce0f9647009b240edea3075dc to your computer and use it in GitHub Desktop.
# 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")
@alfredplpl
Copy link
Author

生成物
qwenimage_nf4 (5)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment