-
Notifications
You must be signed in to change notification settings - Fork 1.1k
qwen-image-edit-2511-lightning #1241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| from diffsynth.pipelines.qwen_image import QwenImagePipeline, ModelConfig, FlowMatchScheduler | ||
| from modelscope import dataset_snapshot_download | ||
| from PIL import Image | ||
| import torch | ||
|
|
||
| pipe = QwenImagePipeline.from_pretrained( | ||
| torch_dtype=torch.bfloat16, | ||
| device="cuda", | ||
| model_configs=[ | ||
| ModelConfig(model_id="Qwen/Qwen-Image-Edit-2511", origin_file_pattern="transformer/diffusion_pytorch_model*.safetensors"), | ||
| ModelConfig(model_id="Qwen/Qwen-Image", origin_file_pattern="text_encoder/model*.safetensors"), | ||
| ModelConfig(model_id="Qwen/Qwen-Image", origin_file_pattern="vae/diffusion_pytorch_model.safetensors"), | ||
| ], | ||
| processor_config=ModelConfig(model_id="Qwen/Qwen-Image-Edit", origin_file_pattern="processor/"), | ||
| ) | ||
|
|
||
| lora = ModelConfig( | ||
| model_id="lightx2v/Qwen-Image-Edit-2511-Lightning", | ||
| origin_file_pattern="Qwen-Image-Edit-2511-Lightning-4steps-V1.0-bf16.safetensors" | ||
| ) | ||
| pipe.load_lora(pipe.dit, lora, alpha=8/64) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| pipe.scheduler = FlowMatchScheduler("Qwen-Image-Lightning") | ||
|
|
||
|
|
||
| dataset_snapshot_download( | ||
| "DiffSynth-Studio/example_image_dataset", | ||
| allow_file_pattern="qwen_image_edit/*", | ||
| local_dir="data/example_image_dataset", | ||
| ) | ||
|
|
||
| prompt = "生成这两个人的合影" | ||
| edit_image = [ | ||
| Image.open("data/example_image_dataset/qwen_image_edit/image1.jpg"), | ||
| Image.open("data/example_image_dataset/qwen_image_edit/image2.jpg"), | ||
| ] | ||
| image = pipe( | ||
| prompt, | ||
| edit_image=edit_image, | ||
| seed=1, | ||
| num_inference_steps=4, | ||
| height=1152, | ||
| width=896, | ||
| edit_image_auto_resize=True, | ||
| zero_cond_t=True, # This is a special parameter introduced by Qwen-Image-Edit-2511 | ||
| cfg_scale=1.0, | ||
| ) | ||
| image.save("image.jpg") | ||
|
|
||
| # Qwen-Image-Edit-2511 is a multi-image editing model. | ||
| # Please use a list to input `edit_image`, even if the input contains only one image. | ||
| # edit_image = [Image.open("image.jpg")] | ||
| # Please do not input the image directly. | ||
| # edit_image = Image.open("image.jpg") | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,63 @@ | ||||||||||||||||||||||
| from diffsynth.pipelines.qwen_image import QwenImagePipeline, ModelConfig, FlowMatchScheduler | ||||||||||||||||||||||
| from modelscope import dataset_snapshot_download | ||||||||||||||||||||||
| from PIL import Image | ||||||||||||||||||||||
| import torch | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| vram_config = { | ||||||||||||||||||||||
| "offload_dtype": "disk", | ||||||||||||||||||||||
| "offload_device": "disk", | ||||||||||||||||||||||
| "onload_dtype": torch.float8_e4m3fn, | ||||||||||||||||||||||
| "onload_device": "cpu", | ||||||||||||||||||||||
| "preparing_dtype": torch.float8_e4m3fn, | ||||||||||||||||||||||
| "preparing_device": "cuda", | ||||||||||||||||||||||
| "computation_dtype": torch.bfloat16, | ||||||||||||||||||||||
| "computation_device": "cuda", | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| pipe = QwenImagePipeline.from_pretrained( | ||||||||||||||||||||||
| torch_dtype=torch.bfloat16, | ||||||||||||||||||||||
| device="cuda", | ||||||||||||||||||||||
| model_configs=[ | ||||||||||||||||||||||
| ModelConfig(model_id="Qwen/Qwen-Image-Edit-2511", origin_file_pattern="transformer/diffusion_pytorch_model*.safetensors"), | ||||||||||||||||||||||
| ModelConfig(model_id="Qwen/Qwen-Image", origin_file_pattern="text_encoder/model*.safetensors"), | ||||||||||||||||||||||
| ModelConfig(model_id="Qwen/Qwen-Image", origin_file_pattern="vae/diffusion_pytorch_model.safetensors"), | ||||||||||||||||||||||
| ], | ||||||||||||||||||||||
|
Comment on lines
+19
to
+23
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
|
||||||||||||||||||||||
| processor_config=ModelConfig(model_id="Qwen/Qwen-Image-Edit", origin_file_pattern="processor/"), | ||||||||||||||||||||||
| ) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| lora = ModelConfig( | ||||||||||||||||||||||
| model_id="lightx2v/Qwen-Image-Edit-2511-Lightning", | ||||||||||||||||||||||
| origin_file_pattern="Qwen-Image-Edit-2511-Lightning-4steps-V1.0-bf16.safetensors" | ||||||||||||||||||||||
| ) | ||||||||||||||||||||||
| pipe.load_lora(pipe.dit, lora, alpha=8/64) | ||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||||
| pipe.scheduler = FlowMatchScheduler("Qwen-Image-Lightning") | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| dataset_snapshot_download( | ||||||||||||||||||||||
| "DiffSynth-Studio/example_image_dataset", | ||||||||||||||||||||||
| allow_file_pattern="qwen_image_edit/*", | ||||||||||||||||||||||
| local_dir="data/example_image_dataset", | ||||||||||||||||||||||
| ) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| prompt = "生成这两个人的合影" | ||||||||||||||||||||||
| edit_image = [ | ||||||||||||||||||||||
| Image.open("data/example_image_dataset/qwen_image_edit/image1.jpg"), | ||||||||||||||||||||||
| Image.open("data/example_image_dataset/qwen_image_edit/image2.jpg"), | ||||||||||||||||||||||
| ] | ||||||||||||||||||||||
| image = pipe( | ||||||||||||||||||||||
| prompt, | ||||||||||||||||||||||
| edit_image=edit_image, | ||||||||||||||||||||||
| seed=1, | ||||||||||||||||||||||
| num_inference_steps=4, | ||||||||||||||||||||||
| height=1152, | ||||||||||||||||||||||
| width=896, | ||||||||||||||||||||||
| edit_image_auto_resize=True, | ||||||||||||||||||||||
| zero_cond_t=True, # This is a special parameter introduced by Qwen-Image-Edit-2511 | ||||||||||||||||||||||
| cfg_scale=1.0, | ||||||||||||||||||||||
| ) | ||||||||||||||||||||||
| image.save("image.jpg") | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Qwen-Image-Edit-2511 is a multi-image editing model. | ||||||||||||||||||||||
| # Please use a list to input `edit_image`, even if the input contains only one image. | ||||||||||||||||||||||
| # edit_image = [Image.open("image.jpg")] | ||||||||||||||||||||||
| # Please do not input the image directly. | ||||||||||||||||||||||
| # edit_image = Image.open("image.jpg") | ||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The calculation for
muwhendynamic_shift_lenis provided can be simplified. Sincebase_shiftandmax_shiftare bothmath.log(3), the call to_calculate_shift_qwen_imagewill always returnmath.log(3). You can directly assign this value tomuand remove the now-unusedbase_shiftandmax_shiftvariables for better readability and maintainability.