Skip to content
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

新增StableDiffusionXL Reference Control支持 #369

Merged
merged 2 commits into from
Jan 18, 2024

Conversation

YibinLiu666
Copy link
Contributor

Copy link

paddle-bot bot commented Jan 1, 2024

Thanks for your contribution!

@YibinLiu666
Copy link
Contributor Author

YibinLiu666 commented Jan 1, 2024

输入:
dog

prompt: a dog
输出:
output2

diffusers输出:
output3

@YibinLiu666
Copy link
Contributor Author

请问readme里面的输出图像应该传到哪里

@shiyutang shiyutang requested a review from JunnYu January 2, 2024 03:14
"stabilityai/stable-diffusion-xl-base-1.0",
torch_dtype=paddle.float16,
use_safetensors=True,
variant="fp16").to('gpu:0')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.to('gpu:0') 这些to其实都不需要,可以删了

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 820 to 821
if hasattr(self, "final_offload_hook") and self.final_offload_hook is not None:
self.final_offload_hook.offload()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的代码当前都没有可以删了。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

"stabilityai/stable-diffusion-xl-base-1.0",
torch_dtype=paddle.float16,
use_safetensors=True,
variant="fp16").to('gpu:0')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.to('gpu:0')删了

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@JunnYu
Copy link
Member

JunnYu commented Jan 2, 2024

这里有跟diffusers的输出结果的对比吗?提供一下相同输入的情况下输出图片的对比

@JunnYu
Copy link
Member

JunnYu commented Jan 2, 2024

readme里面的图片比如直接拖拽到这个回复聊天框里面,然后里面就有上传的地址了 (https://github.com/PaddlePaddle/PaddleMIX/assets/50394665/a668321a-9caf-40aa-9aa9-4107b54b3a40)

image

@YibinLiu666
Copy link
Contributor Author

这里有跟diffusers的输出结果的对比吗?提供一下相同输入的情况下输出图片的对比

已经添加到了上面的comment里面

@YibinLiu666
Copy link
Contributor Author

@Ligoml 梦姐能麻烦打个快乐开源的标签吗

@shiyutang shiyutang added the HappyOpenSource 快乐开源活动issue与PR label Jan 3, 2024
@shiyutang shiyutang requested a review from JunnYu January 3, 2024 02:37
@JunnYu
Copy link
Member

JunnYu commented Jan 4, 2024

哈喽,正常来说,torch的输出结果跟paddle的结果应该大体上一模一样的,你这里需要固定所有的随机因素,然后让两边出个相同结果的图片。当前看你提供的两个图片差距还是很大的,需要再确定一下是哪里从存在问题?
@YibinLiu666

@YibinLiu666
Copy link
Contributor Author

哈喽,正常来说,torch的输出结果跟paddle的结果应该大体上一模一样的,你这里需要固定所有的随机因素,然后让两边出个相同结果的图片。当前看你提供的两个图片差距还是很大的,需要再确定一下是哪里从存在问题? @YibinLiu666

这个随机生成的noise影响还挺大的,我本地一直加载不了huggingface上预训练的模型,一直显示connect timeout,我这里是直接用的github上的图。此外,paddle的seed跟torch的manual_seed有区别,我不太知道怎么让二者的随机种子统一。huggingface diffuser这个pipeline的样例也没有设置随机种子,可能重新跑一次diffuser的样例结果也不是这个。我目前把paddle的seed设置为149生成的图像是这样的,我认为这张图像的质量是超过了diffuser官网给出的图的。
149

@JunnYu
Copy link
Member

JunnYu commented Jan 11, 2024

你可以提供一下你使用对比的两个代码,torch和paddle的。然后我可以告诉你哪里需要对齐,比如 generator 设置的不一样,可能你torch用的是cpu的,paddle用的是gpu的。可能你两边都没有注意到这些细节的区别,正常来说是一样的。

@YibinLiu666
Copy link
Contributor Author

YibinLiu666 commented Jan 17, 2024

你可以提供一下你使用对比的两个代码,torch和paddle的。然后我可以告诉你哪里需要对齐,比如 generator 设置的不一样,可能你torch用的是cpu的,paddle用的是gpu的。可能你两边都没有注意到这些细节的区别,正常来说是一样的。

torch 的代码

import torch
from PIL import Image
from diffusers.utils import load_image
from stable_diffusion_xl_reference import StableDiffusionXLReferencePipeline
from diffusers.schedulers import UniPCMultistepScheduler
input_image = load_image("https://github.com/PaddlePaddle/PaddleMIX/assets/68105073/9c8e5c53-dc9a-46bb-9504-3d75a7c22ed2")

pipe = StableDiffusionXLReferencePipeline.from_pretrained(
    "stabilityai/stable-diffusion-xl-base-1.0",
    torch_dtype=torch.float16,
    use_safetensors=True,
    variant="fp16").to('cuda:0')

pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)

result_img = pipe(ref_image=input_image,
      prompt="a dog",
      num_inference_steps=20,
      reference_attn=True,
      reference_adain=False).images[0]
result_img.save("result.png")

paddle的代码

import paddle
from PIL import Image
from ppdiffusers.utils import load_image
from pipline_stable_diffusion_xl_reference import StableDiffusionXLReferencePipeline
from ppdiffusers.schedulers import UniPCMultistepScheduler

input_image = load_image("https://github.com/PaddlePaddle/PaddleMIX/assets/68105073/9c8e5c53-dc9a-46bb-9504-3d75a7c22ed2")

pipe = StableDiffusionXLReferencePipeline.from_pretrained(
    "stabilityai/stable-diffusion-xl-base-1.0",
    use_safetensors=True,
    variant="fp16")

pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)

result_img = pipe(ref_image=input_image,
      prompt="a dog",
      num_inference_steps=20,
      reference_attn=True,
      reference_adain=False).images[0]

result_img.save("output.png")

@JunnYu
Copy link
Member

JunnYu commented Jan 18, 2024

这样比较一下

import torch
from PIL import Image
from diffusers.utils import load_image
from stable_diffusion_xl_reference import StableDiffusionXLReferencePipeline
from diffusers.schedulers import UniPCMultistepScheduler
input_image = load_image("https://github.com/PaddlePaddle/PaddleMIX/assets/68105073/9c8e5c53-dc9a-46bb-9504-3d75a7c22ed2")

pipe = StableDiffusionXLReferencePipeline.from_pretrained(
    "stabilityai/stable-diffusion-xl-base-1.0",
    torch_dtype=torch.float16,
    use_safetensors=True,
    variant="fp16").to('cuda:0')

pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
# 设置全局的gpu seed
torch.cuda.manual_seed(42)
result_img = pipe(ref_image=input_image,
      prompt="a dog",
      num_inference_steps=20,
      reference_attn=True,
      reference_adain=False).images[0]
result_img.save("result.png")
import paddle
from PIL import Image
from ppdiffusers.utils import load_image
from pipline_stable_diffusion_xl_reference import StableDiffusionXLReferencePipeline
from ppdiffusers.schedulers import UniPCMultistepScheduler

input_image = load_image("https://github.com/PaddlePaddle/PaddleMIX/assets/68105073/9c8e5c53-dc9a-46bb-9504-3d75a7c22ed2")

pipe = StableDiffusionXLReferencePipeline.from_pretrained(
    "stabilityai/stable-diffusion-xl-base-1.0",
    use_safetensors=True,
    variant="fp16")

pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
# 设置全局的gpu seed
paddle.seed(42)
result_img = pipe(ref_image=input_image,
      prompt="a dog",
      num_inference_steps=20,
      reference_attn=True,
      reference_adain=False).images[0]

result_img.save("output.png")

@YibinLiu666
Copy link
Contributor Author

paddle:
paddle
torch:
diffuser

可能随机种子还是没有完全对齐, PaddlePaddle/Paddle#26637

@JunnYu
Copy link
Member

JunnYu commented Jan 18, 2024

刚看到paddle的pipeline是用的fp32跑的,这会存在区别。要指定paddle_dtype=paddle.float16
最后就是不同diffusers vs ppddiffusers版本可能也存在区别。
当前这么看,应该没啥问题了。

Copy link
Member

@JunnYu JunnYu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@JunnYu JunnYu merged commit 825fdfd into PaddlePaddle:develop Jan 18, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor HappyOpenSource 快乐开源活动issue与PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants