-
Notifications
You must be signed in to change notification settings - Fork 84
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
Open
ccssu
wants to merge
10
commits into
main
Choose a base branch
from
dev_support_diffusers_ipa
base: main
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Install:
step 1:
pip install diffusers==0.27
step2. OneDiff Installation Guide
step3. OneDiffx Installation Guide
Usage:
script_00.py