Commit
·
2ec69c0
1
Parent(s):
679791d
try clearing memory
Browse files
app.py
CHANGED
|
@@ -9,6 +9,7 @@ from sdxl_models import SDXLUNet, SDXLVae, SDXLControlNetPreEncodedControlnetCon
|
|
| 9 |
import torchvision.transforms.functional as TF
|
| 10 |
from diffusion import make_sigmas
|
| 11 |
from huggingface_hub import hf_hub_download
|
|
|
|
| 12 |
|
| 13 |
pipe = AutoPipelineForInpainting.from_pretrained("diffusers/stable-diffusion-xl-1.0-inpainting-0.1", torch_dtype=torch.float16, variant="fp16")
|
| 14 |
pipe.text_encoder.to("cuda")
|
|
@@ -20,6 +21,9 @@ comparing_vae.to(torch.float16)
|
|
| 20 |
comparing_controlnet = SDXLControlNetPreEncodedControlnetCond.load(hf_hub_download("williamberman/sdxl_controlnet_inpainting", "sdxl_controlnet_inpaint_pre_encoded_controlnet_cond_checkpoint_200000.safetensors"))
|
| 21 |
comparing_controlnet.to(torch.float16)
|
| 22 |
|
|
|
|
|
|
|
|
|
|
| 23 |
def read_content(file_path: str) -> str:
|
| 24 |
"""read the content of target file
|
| 25 |
"""
|
|
@@ -51,6 +55,9 @@ def predict(dict, prompt="", negative_prompt="", guidance_scale=7.5, steps=20, s
|
|
| 51 |
pipe.vae.to('cpu')
|
| 52 |
pipe.unet.to('cpu')
|
| 53 |
|
|
|
|
|
|
|
|
|
|
| 54 |
comparing_unet.to('cuda')
|
| 55 |
comparing_vae.to('cuda')
|
| 56 |
comparing_controlnet.to('cuda')
|
|
@@ -75,6 +82,9 @@ def predict(dict, prompt="", negative_prompt="", guidance_scale=7.5, steps=20, s
|
|
| 75 |
comparing_unet.to('cpu')
|
| 76 |
comparing_vae.to('cpu')
|
| 77 |
comparing_controlnet.to('cpu')
|
|
|
|
|
|
|
|
|
|
| 78 |
|
| 79 |
return output.images[0], out[0], gr.update(visible=True)
|
| 80 |
|
|
|
|
| 9 |
import torchvision.transforms.functional as TF
|
| 10 |
from diffusion import make_sigmas
|
| 11 |
from huggingface_hub import hf_hub_download
|
| 12 |
+
import gc
|
| 13 |
|
| 14 |
pipe = AutoPipelineForInpainting.from_pretrained("diffusers/stable-diffusion-xl-1.0-inpainting-0.1", torch_dtype=torch.float16, variant="fp16")
|
| 15 |
pipe.text_encoder.to("cuda")
|
|
|
|
| 21 |
comparing_controlnet = SDXLControlNetPreEncodedControlnetCond.load(hf_hub_download("williamberman/sdxl_controlnet_inpainting", "sdxl_controlnet_inpaint_pre_encoded_controlnet_cond_checkpoint_200000.safetensors"))
|
| 22 |
comparing_controlnet.to(torch.float16)
|
| 23 |
|
| 24 |
+
gc.collect()
|
| 25 |
+
torch.cuda.empty_cache()
|
| 26 |
+
|
| 27 |
def read_content(file_path: str) -> str:
|
| 28 |
"""read the content of target file
|
| 29 |
"""
|
|
|
|
| 55 |
pipe.vae.to('cpu')
|
| 56 |
pipe.unet.to('cpu')
|
| 57 |
|
| 58 |
+
gc.collect()
|
| 59 |
+
torch.cuda.empty_cache()
|
| 60 |
+
|
| 61 |
comparing_unet.to('cuda')
|
| 62 |
comparing_vae.to('cuda')
|
| 63 |
comparing_controlnet.to('cuda')
|
|
|
|
| 82 |
comparing_unet.to('cpu')
|
| 83 |
comparing_vae.to('cpu')
|
| 84 |
comparing_controlnet.to('cpu')
|
| 85 |
+
|
| 86 |
+
gc.collect()
|
| 87 |
+
torch.cuda.empty_cache()
|
| 88 |
|
| 89 |
return output.images[0], out[0], gr.update(visible=True)
|
| 90 |
|