-
Notifications
You must be signed in to change notification settings - Fork 122
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
dev_support_diffusers_ipa #837
base: main
Are you sure you want to change the base?
Conversation
script_01.pyimport torch
from transformers import CLIPVisionModelWithProjection
from diffusers import DPMSolverMultistepScheduler, StableDiffusionXLPipeline
from diffusers.image_processor import IPAdapterMaskProcessor
from diffusers.utils import logging
from diffusers.utils.logging import set_verbosity
import os
def load_image(url, cache_dir="."):
from diffusers.utils import load_image as _load_image
file_name = url.split("/")[-1]
file_path = os.path.join(cache_dir, file_name)
if os.path.exists(file_path):
image = _load_image(file_path)
else:
image = _load_image(url)
image.save(file_path)
return image
set_verbosity(logging.ERROR) # to not show cross_attention_kwargs...by AttnProcessor2_0 warnings
# load & process masks
composition_mask = load_image(
"https://huggingface.co/datasets/OzzyGT/testing-resources/resolve/main/1024_whole_mask.png"
)
female_mask = load_image(
"https://huggingface.co/datasets/OzzyGT/testing-resources/resolve/main/ip_adapter_None_20240321125641_mask.png"
)
male_mask = load_image(
"https://huggingface.co/datasets/OzzyGT/testing-resources/resolve/main/ip_adapter_None_20240321125344_mask.png"
)
background_mask = load_image(
"https://huggingface.co/datasets/OzzyGT/testing-resources/resolve/main/ip_adapter_6_20240321130722_mask.png"
)
print(f'--'*20, 'start', '--'*20)
processor = IPAdapterMaskProcessor()
masks1 = processor.preprocess([composition_mask], height=1024, width=1024)
masks2 = processor.preprocess([female_mask, male_mask, background_mask], height=1024, width=1024)
masks2 = masks2.reshape(1, masks2.shape[0], masks2.shape[2], masks2.shape[3]) # output -> (1, 3, 1024, 1024)
masks = [masks1, masks2]
# load images
ip_composition_image = load_image(
"https://huggingface.co/datasets/OzzyGT/testing-resources/resolve/main/ip_adapter__20240321125152.png"
)
ip_female_style = load_image(
"https://huggingface.co/datasets/OzzyGT/testing-resources/resolve/main/ip_adapter__20240321125625.png"
)
ip_male_style = load_image(
"https://huggingface.co/datasets/OzzyGT/testing-resources/resolve/main/ip_adapter__20240321125329.png"
)
ip_background = load_image(
"https://huggingface.co/datasets/OzzyGT/testing-resources/resolve/main/ip_adapter__20240321130643.png"
)
image_encoder = CLIPVisionModelWithProjection.from_pretrained(
"h94/IP-Adapter", subfolder="models/image_encoder", torch_dtype=torch.float16
).to("cuda")
pipeline = StableDiffusionXLPipeline.from_pretrained(
"RunDiffusion/Juggernaut-XL-v9", torch_dtype=torch.float16, image_encoder=image_encoder, variant="fp16"
).to("cuda")
pipeline.scheduler = DPMSolverMultistepScheduler.from_config(pipeline.scheduler.config)
pipeline.scheduler.config.use_karras_sigmas = True
pipeline.load_ip_adapter(
["ostris/ip-composition-adapter", "h94/IP-Adapter"],
subfolder=["", "sdxl_models"],
weight_name=[
"ip_plus_composition_sdxl.safetensors",
"ip-adapter_sdxl_vit-h.safetensors",
],
image_encoder_folder=None,
)
pipeline.set_ip_adapter_scale([1.0, [0.75, 0.75, 0.3]])
prompt = "high quality, cinematic photo, cinemascope, 35mm, film grain, highly detailed"
negative_prompt = "anime, cartoon"
from onediff.infer_compiler import oneflow_compile
pipeline.unet = oneflow_compile(pipeline.unet)
for _ in range(10):
image = pipeline(
prompt=prompt,
negative_prompt="",
ip_adapter_image=[ip_composition_image, [ip_female_style, ip_male_style, ip_background]],
cross_attention_kwargs={"ip_adapter_masks": masks},
guidance_scale=6.5,
num_inference_steps=25,
).images[0]
image.save("yiyi_test_mask_multi_out.png") |
Example: diffusers feature to set ip_adapters scale on runtime.
|
did you try different output resolutions when use ipadapter? i think it will trigger recompile. |
src/infer_compiler_registry/register_diffusers/unet_2d_condition_oflow.py
Show resolved
Hide resolved
…ediff into dev_support_diffusers_ipa
@@ -0,0 +1,155 @@ | |||
import argparse |
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.
这个参考 sdxl 提供一个专门的文件夹和 readme 作为加速报告吧
is this pr finished? |
Install:
step 1:
pip install diffusers==0.27
step2. OneDiff Installation Guide
step3. OneDiffx Installation Guide
Usage:
script_00.py