huggingface / diffusers

🤗 Diffusers: State-of-the-art diffusion models for image and audio generation in PyTorch and FLAX.
https://huggingface.co/docs/diffusers
Apache License 2.0
26.04k stars 5.36k forks source link

DPM/UniPC schedulers (possibly more) seem to have massive stability issues on model KohakuXL vs ComfyUI #5646

Closed Xynonners closed 6 months ago

Xynonners commented 1 year ago

Describe the bug

The model KohakuXL in diffusers, seems to run into a massive noise/stability issue that doesn't seem to be present within ComfyUI/AUTO1111, on UniPC/DPM schedulers (possibly more) that doesn't go away with high step counts. At 15S: test At 30S: test Euler A 30S: test

Reproduction

import torch
from accelerate.utils import ProjectConfiguration
from accelerate import Accelerator
from diffusers import StableDiffusionXLPipeline, DPMSolverMultistepScheduler, EulerAncestralDiscreteScheduler
accelerator_config = ProjectConfiguration(
    project_dir="test",
    automatic_checkpoint_naming=True,
    total_limit=10,
)
accelerator = Accelerator(
    log_with="aim",
    mixed_precision="bf16",
    project_config=accelerator_config,
    gradient_accumulation_steps=16,
)
pipeline = StableDiffusionXLPipeline.from_single_file("models/kohakuXLBeta_beta71.safetensors").to(accelerator.device)
pipeline.scheduler = DPMSolverMultistepScheduler.from_config(pipeline.scheduler.config)
generator = torch.Generator(device=accelerator.device).manual_seed(42)
ims = pipeline(width=1024, height=1024, guidance_scale=14.0, prompt="realistic car 3 d render sci - fi car and sci - fi robotic factory structure in the coronation of napoleon painting and digital billboard with point cloud in the middle, unreal engine 5, keyshot, octane, artstation trending, ultra high detail, ultra realistic, cinematic, 8 k, 1 6 k, in style of zaha hadid, in style of nanospace,", num_inference_steps=15, generator=generator)
for img in ims.images:
    img.save("test.png")

Logs

Not Applicable

System Info

Who can help?

@yiyixuxu @patrickvonplaten

patrickvonplaten commented 1 year ago

Can you try whether the fix to DPM provided here: https://github.com/huggingface/diffusers/pull/5541 could help?

nhnt11 commented 12 months ago

In my experience, #5541 helps but not completely. I just filed https://github.com/huggingface/diffusers/issues/5689 to document another issue we found.

Xynonners commented 11 months ago

@patrickvonplaten using euler_at_final with either default, use_karras_sigmas, or use_lu_lambdas does help the issue slightly, but it is still very apparent.

use_karras_sigmas tends to be less noisy than default, while use_lu_lambdas tends to have larger but less splotches.

yiyixuxu commented 11 months ago

hi @Xynonners

sorry I can't reproduce this. I tried this script - think euler indeed looks better but I would say dpm output is more or less within the expected range, unlike the output you provided. Did I miss anything here?

import torch
from diffusers import StableDiffusionXLPipeline, DPMSolverMultistepScheduler, EulerAncestralDiscreteScheduler

pipeline = StableDiffusionXLPipeline.from_pretrained("KBlueLeaf/kohaku-xl-beta7.1", torch_dtype=torch.float16)
pipeline.enable_model_cpu_offload()
generator = torch.Generator(device="cuda").manual_seed(42)
ims = pipeline(prompt="realistic car 3 d render sci - fi car and sci - fi robotic factory structure in the coronation of napoleon painting and digital billboard with point cloud in the middle, unreal engine 5, keyshot, octane, artstation trending, ultra high detail, ultra realistic, cinematic, 8 k, 1 6 k, in style of zaha hadid, in style of nanospace,", num_inference_steps=30, generator=generator)
ims.images[0].save("euler.png")

pipeline.scheduler = DPMSolverMultistepScheduler.from_config(pipeline.scheduler.config)
generator = torch.Generator(device="cuda").manual_seed(42)
ims = pipeline(prompt="realistic car 3 d render sci - fi car and sci - fi robotic factory structure in the coronation of napoleon painting and digital billboard with point cloud in the middle, unreal engine 5, keyshot, octane, artstation trending, ultra high detail, ultra realistic, cinematic, 8 k, 1 6 k, in style of zaha hadid, in style of nanospace,", num_inference_steps=30, use_lu_lambdas =True, euler_at_final = True, generator=generator)

ims.images[0].save("dpm.png")

euler yiyi_test_5_out_euler

dpm yiyi_test_5_out_dpm

Xynonners commented 11 months ago

@yiyixuxu I narrowed it down to the guidance_scale parameter, it seems like DPM is unstable at high guidance scale.

import torch
from diffusers import StableDiffusionXLPipeline, DPMSolverMultistepScheduler, EulerAncestralDiscreteScheduler

pipeline = StableDiffusionXLPipeline.from_single_file("UpDraft/models/kohakuXLBeta_beta71.safetensors", torch_dtype=torch.float16)
pipeline.enable_model_cpu_offload()
generator = torch.Generator(device="cuda").manual_seed(42)
ims = pipeline(guidance_scale=14.0, prompt="realistic car 3 d render sci - fi car and sci - fi robotic factory structure in the coronation of napoleon painting and digital billboard with point cloud in the middle, unreal engine 5, keyshot, octane, artstation trending, ultra high detail, ultra realistic, cinematic, 8 k, 1 6 k, in style of zaha hadid, in style of nanospace,", num_inference_steps=30, generator=generator)
ims.images[0].save("euler.png")

pipeline.scheduler = DPMSolverMultistepScheduler.from_config(pipeline.scheduler.config)
generator = torch.Generator(device="cuda").manual_seed(42)
ims = pipeline(guidance_scale=14.0, prompt="realistic car 3 d render sci - fi car and sci - fi robotic factory structure in the coronation of napoleon painting and digital billboard with point cloud in the middle, unreal engine 5, keyshot, octane, artstation trending, ultra high detail, ultra realistic, cinematic, 8 k, 1 6 k, in style of zaha hadid, in style of nanospace,", num_inference_steps=30, use_lu_lambdas =True, euler_at_final = True, generator=generator)
ims.images[0].save("dpm.png")

Also, the introduction of accelerate also, while making the model much slower, also seems to serve to destabilize it a larger amount. dpm: dpm dpm + accelerate: test

Xynonners commented 11 months ago

lowered to 15, seems like euler even has noise issues at this point (cfg 14) dpm: dpm euler: euler

patrickvonplaten commented 10 months ago

@yiyixuxu can you look into this to see if it has been fixed?

patrickvonplaten commented 8 months ago

Gentle re-ping

github-actions[bot] commented 8 months ago

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the contributing guidelines are likely to be ignored.

github-actions[bot] commented 7 months ago

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the contributing guidelines are likely to be ignored.

yiyixuxu commented 7 months ago

cc @Beinsezii here since you have been testing our schedulers is this still an issue?

Beinsezii commented 7 months ago

DPMSolverMultistep has been my default ever since I added ZSNR and I've never once seen images like that across a fair variety of XL models. Closest I can think of is running a funky noise schedule directly on bf16 but that should be fixed forever since I added an upcast in step() with #7097

@Xynonners should probably try again on the latest pytorch/diffusers.

github-actions[bot] commented 6 months ago

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the contributing guidelines are likely to be ignored.

yiyixuxu commented 6 months ago

closing this for now! feel free to re-open if you continue to see issue