-
Notifications
You must be signed in to change notification settings - Fork 5
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
fix cpu offload setup #85
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
""" | ||
Example of using Hyper-SD with metafusion | ||
|
||
|
||
# https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0 | ||
requires this model to be in models-sd/SDXL/stable-diffusion-xl-base-1.0/sd_xl_base_1.0.safetensors | ||
|
||
and https://huggingface.co/ByteDance/Hyper-SD/blob/main/Hyper-SD15-4steps-lora.safetensors to be in | ||
|
||
models-sd/Lora/Hyper-SDXL-4steps-lora.safetensors | ||
""" | ||
|
||
import time | ||
import random | ||
import PIL.Image | ||
import torch | ||
from multigen.prompting import Cfgen | ||
from multigen.sessions import GenSession | ||
from multigen.pipes import Prompt2ImPipe | ||
|
||
from multigen.worker import ServiceThread | ||
|
||
from multigen.log import setup_logger | ||
setup_logger() | ||
|
||
nprompt = "jpeg artifacts, blur, distortion, watermark, signature, extra fingers, fewer fingers, lowres, bad hands, duplicate heads, bad anatomy, bad crop" | ||
|
||
prompt = "Close-up portrait of a woman wearing suit posing with black background, rim lighting, octane, unreal" | ||
seed = 383947828373273 | ||
|
||
|
||
cfg_file = 'config.yaml' | ||
|
||
|
||
def random_session(pipe, model): | ||
id = str(random.randint(0, 1024*1024*1024*4-1)) | ||
session = dict() | ||
session["images"] = [] | ||
session["user"] = id | ||
session["pipe"] = pipe | ||
session["model"] = model | ||
return { "session_id": id, 'session': session } | ||
|
||
|
||
worker = ServiceThread(cfg_file) | ||
worker.start() | ||
|
||
pipe = "prompt2image" | ||
pipe = "image2image" | ||
model = list(worker.models['base'].keys())[-1] | ||
|
||
count = 5 | ||
c = 0 | ||
def on_new_image(*args, **kwargs): | ||
print(args, kwargs) | ||
print('on new image') | ||
global c | ||
c += 1 | ||
|
||
def on_finish(*args, **kwargs): | ||
print('finish') | ||
print(args, kwargs) | ||
|
||
|
||
# worker.queue_gen(session_id=sess_id, | ||
# images=None, | ||
# prompt=prompt, pipe='Prompt2ImPipe', | ||
# nprompt=nprompt, | ||
# image_callback=on_new_image, | ||
# # lpw=False, | ||
# width=1024, height=1024, steps=4, | ||
# guidance_scale=0, | ||
# count=count, | ||
# seeds=[seed + i for i in range(count)], | ||
# ) | ||
|
||
generator = torch.Generator().manual_seed(92) | ||
init_image = PIL.Image.open('cr.png') | ||
random_sess = random_session(pipe, model) | ||
#worker.queue_gen( | ||
# gen_dir='/tmp/img1', | ||
# image_callback=on_new_image, | ||
# prompt=prompt, count=count, | ||
# images=[init_image], generator=generator, | ||
# num_inference_steps=50, strength=0.82, guidance_scale=3.5, | ||
# **random_sess) | ||
|
||
|
||
pipe = "inpaint" | ||
prompt = "a football player holding a gun, pointing it towards viewer" | ||
|
||
mask = PIL.Image.open('select.png') | ||
random_sess = random_session(pipe, model) | ||
worker.queue_gen( | ||
gen_dir='/tmp/img1_inp', | ||
finish_callback=on_finish, | ||
image_callback=on_new_image, | ||
prompt=prompt, count=count, | ||
image=init_image, mask=mask, generator=generator, | ||
guidance_scale=7, | ||
strength=0.9, steps=30, | ||
**random_sess) | ||
|
||
|
||
|
||
while count != c: | ||
time.sleep(1) | ||
worker.stop() |
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
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
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
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
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
Oops, something went wrong.
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.
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.
I'd keep these checks at least for logs. Or are they not relevant anymore at all?
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.
old api would work just fine. Relevance depends on the clients of our api