Commit 05b0e0d4 authored by mashun1's avatar mashun1
Browse files

photomaker

parent 763c7445
......@@ -6,5 +6,7 @@ __pycache__/
.idea/
*.bin
*.safetensors
SG16122/
*vscode*
\ No newline at end of file
SG161222/
*vscode*
prof_analyze/
profiler*
\ No newline at end of file
FROM image.sourcefind.cn:5000/dcu/admin/base/pytorch:2.1.0-centos7.6-dtk23.10.1-py38
\ No newline at end of file
FROM image.sourcefind.cn:5000/dcu/admin/base/pytorch:1.13.1-centos7.6-dtk-23.04.1-py39-latest
\ No newline at end of file
......@@ -28,7 +28,7 @@
### Docker(方法一)
docker pull image.sourcefind.cn:5000/dcu/admin/base/pytorch:2.1.0-centos7.6-dtk23.10.1-py38
docker pull image.sourcefind.cn:5000/dcu/admin/base/pytorch:1.13.1-centos7.6-dtk-23.04.1-py39-latest
docker run --shm-size 10g --network=host --name=photomaker --privileged --device=/dev/kfd --device=/dev/dri --group-add video --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -v /opt/hyhal:/opt/hyhal-v 项目地址(绝对路径):/home/ -it <your IMAGE ID> bash
pip install -r requirements.txt
......
......@@ -38,6 +38,7 @@ if device == "mps":
torch_dtype = torch.float16
else:
torch_dtype = torch.float16
pipe = PhotoMakerStableDiffusionXLPipeline.from_pretrained(
base_model_path,
torch_dtype=torch_dtype,
......@@ -58,10 +59,10 @@ pipe.id_encoder.to(device)
pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config)
print("Loading lora...")
lora_path = "./lora/ral-opal-sdxl.safetensors"
pipe.load_lora_weights(os.path.dirname(lora_path), weight_name=os.path.basename(lora_path), adapter_name="xl_more_art-full")
pipe.set_adapters(["photomaker", "xl_more_art-full"], adapter_weights=[1.0, 0.5])
# pipe.set_adapters(["photomaker"], adapter_weights=[1.0])
# lora_path = "./lora/ral-opal-sdxl.safetensors"
# pipe.load_lora_weights(os.path.dirname(lora_path), weight_name=os.path.basename(lora_path), adapter_name="xl_more_art-full")
# pipe.set_adapters(["photomaker", "xl_more_art-full"], adapter_weights=[1.0, 0.5])
pipe.set_adapters(["photomaker"], adapter_weights=[1.0])
pipe.fuse_lora()
@spaces.GPU(enable_queue=True)
......@@ -93,10 +94,7 @@ def generate_image(upload_images, prompt, negative_prompt, style_name, num_steps
if start_merge_step > 30:
start_merge_step = 30
print(start_merge_step)
# with torch.profiler.profile(activities=[
# torch.profiler.ProfilerActivity.CPU,
# torch.profiler.ProfilerActivity.CUDA,
# ]) as p:
images = pipe(
prompt=prompt,
input_id_images=input_id_images,
......@@ -107,8 +105,7 @@ def generate_image(upload_images, prompt, negative_prompt, style_name, num_steps
generator=generator,
guidance_scale=guidance_scale,
).images
# print(p.key_averages().table(sort_by="self_cuda_time_total", row_limit=-1))
# p.export_chrome_trace("profiler_results_dcu61.json")
return images, gr.update(visible=True)
def swap_to_gallery(images):
......
......@@ -4,6 +4,8 @@ import os
import PIL
import numpy as np
import time
import torch
from torchvision import transforms as T
......@@ -469,12 +471,13 @@ class PhotoMakerStableDiffusionXLPipeline(StableDiffusionXLPipeline):
progress_bar.update()
if callback is not None and i % callback_steps == 0:
callback(i, t, latents)
# make sure the VAE is in float32 mode, as it overflows in float16
if self.vae.dtype == torch.float16 and self.vae.config.force_upcast:
self.upcast_vae()
latents = latents.to(next(iter(self.vae.post_quant_conv.parameters())).dtype)
# if self.vae.dtype == torch.float16 and self.vae.config.force_upcast:
# self.upcast_vae()
# latents = latents.to(next(iter(self.vae.post_quant_conv.parameters())).dtype)
latents = latents.to(memory_format=torch.channels_last)
if not output_type == "latent":
image = self.vae.decode(latents / self.vae.config.scaling_factor, return_dict=False)[0]
else:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment