Spaces:
Runtime error
Runtime error
Update app.py
Browse filesLoading all pipes to individual memory, because A10G has plenty of VRAM now.
app.py
CHANGED
|
@@ -10,39 +10,47 @@ import os
|
|
| 10 |
login(token=os.environ.get('HF_KEY'))
|
| 11 |
|
| 12 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 13 |
-
torch.cuda.max_memory_allocated(device='cuda')
|
| 14 |
-
torch.cuda.empty_cache()
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
| 18 |
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16, variant="fp16", use_safetensors=True)
|
| 19 |
-
pipe = pipe.to(device)
|
| 20 |
pipe.enable_xformers_memory_efficient_attention()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
torch.cuda.empty_cache()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
generator = torch.Generator(device=device).manual_seed(seed)
|
| 23 |
int_image = pipe(prompt, negative_prompt=negative_prompt, num_inference_steps=steps, height=height, width=width, guidance_scale=scale, num_images_per_prompt=1, generator=generator, output_type="latent").images
|
| 24 |
torch.cuda.empty_cache()
|
| 25 |
if upscaler == 'Yes':
|
| 26 |
-
|
| 27 |
-
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0", torch_dtype=torch.float16, variant="fp16", use_safetensors=True)
|
| 28 |
-
pipe = pipe.to(device)
|
| 29 |
-
pipe.enable_xformers_memory_efficient_attention()
|
| 30 |
-
image = pipe(prompt=prompt, image=int_image).images[0]
|
| 31 |
torch.cuda.empty_cache()
|
| 32 |
-
|
| 33 |
-
pipe = DiffusionPipeline.from_pretrained("stabilityai/sd-x2-latent-upscaler", torch_dtype=torch.float16, use_safetensors=True)
|
| 34 |
-
pipe.to("cuda")
|
| 35 |
-
pipe.enable_xformers_memory_efficient_attention()
|
| 36 |
-
upscaled = pipe(prompt=prompt, negative_prompt=negative_prompt, image=image, num_inference_steps=5, guidance_scale=0).images[0]
|
| 37 |
torch.cuda.empty_cache()
|
| 38 |
return (image, upscaled)
|
| 39 |
else:
|
| 40 |
-
|
| 41 |
-
torch.cuda.max_memory_allocated(device=device)
|
| 42 |
-
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0", torch_dtype=torch.float16, variant="fp16", use_safetensors=True)
|
| 43 |
-
pipe = pipe.to(device)
|
| 44 |
-
pipe.enable_xformers_memory_efficient_attention()
|
| 45 |
-
image = pipe(prompt=prompt, negative_prompt=negative_prompt, image=int_image).images[0]
|
| 46 |
torch.cuda.empty_cache()
|
| 47 |
return (image, image)
|
| 48 |
|
|
|
|
| 10 |
login(token=os.environ.get('HF_KEY'))
|
| 11 |
|
| 12 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
if torch.cuda.is_available():
|
| 15 |
+
PYTORCH_CUDA_ALLOC_CONF={'max_split_size_mb': 6000}
|
| 16 |
+
torch.cuda.max_memory_allocated(device=device)
|
| 17 |
+
torch.cuda.empty_cache()
|
| 18 |
+
|
| 19 |
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16, variant="fp16", use_safetensors=True)
|
|
|
|
| 20 |
pipe.enable_xformers_memory_efficient_attention()
|
| 21 |
+
pipe = pipe.to(device)
|
| 22 |
+
torch.cuda.empty_cache()
|
| 23 |
+
|
| 24 |
+
refiner = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0", use_safetensors=True, torch_dtype=torch.float16, variant="fp16")
|
| 25 |
+
refiner.enable_xformers_memory_efficient_attention()
|
| 26 |
+
refiner = refiner.to(device)
|
| 27 |
torch.cuda.empty_cache()
|
| 28 |
+
|
| 29 |
+
upscaler = DiffusionPipeline.from_pretrained("stabilityai/sd-x2-latent-upscaler", torch_dtype=torch.float16, use_safetensors=True)
|
| 30 |
+
upscaler.enable_xformers_memory_efficient_attention()
|
| 31 |
+
upscaler = upscaler.to(device)
|
| 32 |
+
torch.cuda.empty_cache()
|
| 33 |
+
else:
|
| 34 |
+
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", use_safetensors=True)
|
| 35 |
+
pipe = pipe.to(device)
|
| 36 |
+
refiner = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0", use_safetensors=True)
|
| 37 |
+
refiner = refiner.to(device)
|
| 38 |
+
|
| 39 |
+
torch.cuda.max_memory_allocated(device='cuda')
|
| 40 |
+
torch.cuda.empty_cache()
|
| 41 |
+
|
| 42 |
+
def genie (prompt, negative_prompt, height, width, scale, steps, seed, upscaler):
|
| 43 |
generator = torch.Generator(device=device).manual_seed(seed)
|
| 44 |
int_image = pipe(prompt, negative_prompt=negative_prompt, num_inference_steps=steps, height=height, width=width, guidance_scale=scale, num_images_per_prompt=1, generator=generator, output_type="latent").images
|
| 45 |
torch.cuda.empty_cache()
|
| 46 |
if upscaler == 'Yes':
|
| 47 |
+
image = refiner(prompt=prompt, image=int_image).images[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
torch.cuda.empty_cache()
|
| 49 |
+
upscaled = upscaler(prompt=prompt, negative_prompt=negative_prompt, image=image, num_inference_steps=5, guidance_scale=0).images[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
torch.cuda.empty_cache()
|
| 51 |
return (image, upscaled)
|
| 52 |
else:
|
| 53 |
+
image = refiner(prompt=prompt, negative_prompt=negative_prompt, image=int_image).images[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
torch.cuda.empty_cache()
|
| 55 |
return (image, image)
|
| 56 |
|