|
import torch |
|
import time |
|
from PIL import Image |
|
import numpy as np |
|
from lyrasd_model import LyraSdXLControlnetTxt2ImgPipeline |
|
import GPUtil |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lib_path = "./lyrasd_model/lyrasd_lib/libth_lyrasd_cu12_sm80.so" |
|
model_path = "./models/helloworldSDXL20Fp16" |
|
torch.classes.load_library(lib_path) |
|
|
|
|
|
pipe = LyraSdXLControlnetTxt2ImgPipeline() |
|
|
|
start = time.perf_counter() |
|
pipe.reload_pipe(model_path) |
|
print(f"pipeline load cost: {time.perf_counter() - start}") |
|
|
|
|
|
start = time.perf_counter() |
|
pipe.load_controlnet_model_v2("canny", "./models/controlnet-canny-sdxl-1.0") |
|
print(f"controlnet load cost: {time.perf_counter() - start}") |
|
|
|
|
|
print(pipe.get_loaded_controlnet()) |
|
|
|
|
|
|
|
|
|
control_img = Image.open("control_bird_canny.png") |
|
|
|
|
|
prompt = "a bird" |
|
negative_prompt = "" |
|
height, width = 1024, 1024 |
|
steps = 20 |
|
guidance_scale = 7.5 |
|
generator = torch.Generator().manual_seed(123) |
|
num_images = 1 |
|
guess_mode = False |
|
|
|
|
|
|
|
|
|
controlnet_images = [[control_img]] |
|
controlnet_scale = [0.5] |
|
controlnet_names = ['canny'] |
|
|
|
|
|
for batch in [1]: |
|
print(f"cur batch: {batch}") |
|
for _ in range(3): |
|
start = time.perf_counter() |
|
images = pipe(prompt=prompt, height=height, width=width, num_inference_steps=steps, |
|
guidance_scale=guidance_scale, negative_prompt=negative_prompt, num_images_per_prompt=batch, |
|
generator=generator, controlnet_images=controlnet_images, |
|
controlnet_scale=controlnet_scale, controlnet_names=controlnet_names, |
|
guess_mode=guess_mode |
|
) |
|
print("cur cost: ", time.perf_counter() - start) |
|
GPUtil.showUtilization(all=True) |
|
|
|
for i, image in enumerate(images): |
|
image.save(f"./outputs/res_controlnet_sdxl_txt2img_{i}.png") |
|
|