Manjushri commited on
Commit
c21f92d
1 Parent(s): 7c1a22d

Update app.py

Browse files

I may he clearing the torch cache too much... And having to recompile the pipes ... Slower, this should fix it

Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -17,19 +17,19 @@ if torch.cuda.is_available():
17
  pipe.enable_xformers_memory_efficient_attention()
18
  pipe = pipe.to(device)
19
  pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead", fullgraph=True)
20
- torch.cuda.empty_cache()
21
 
22
  refiner = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0", use_safetensors=True, torch_dtype=torch.float16, variant="fp16")
23
  refiner.enable_xformers_memory_efficient_attention()
24
  refiner = refiner.to(device)
25
  refiner.unet = torch.compile(refiner.unet, mode="reduce-overhead", fullgraph=True)
26
- torch.cuda.empty_cache()
27
 
28
  upscaler = DiffusionPipeline.from_pretrained("stabilityai/sd-x2-latent-upscaler", torch_dtype=torch.float16, use_safetensors=True)
29
  upscaler.enable_xformers_memory_efficient_attention()
30
  upscaler = upscaler.to(device)
31
  upscaler.unet = torch.compile(upscaler.unet, mode="reduce-overhead", fullgraph=True)
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)
@@ -47,11 +47,11 @@ def genie (prompt, negative_prompt, height, width, scale, steps, seed, upscaling
47
  if upscaling == 'Yes':
48
  image = refiner(prompt=prompt, prompt_2=prompt_2, negative_prompt=negative_prompt, negative_prompt_2=negative_prompt_2, image=int_image).images[0]
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, prompt_2=prompt_2, negative_prompt=negative_prompt, negative_prompt_2=negative_prompt_2, image=int_image).images[0]
54
- torch.cuda.empty_cache()
55
  return (image, image)
56
 
57
  gr.Interface(fn=genie, inputs=[gr.Textbox(label='What you want the AI to generate. 77 Token Limit. A Token is Any Word, Number, Symbol, or Punctuation. Everything Over 77 Will Be Truncated!'),
 
17
  pipe.enable_xformers_memory_efficient_attention()
18
  pipe = pipe.to(device)
19
  pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead", fullgraph=True)
20
+ #torch.cuda.empty_cache()
21
 
22
  refiner = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0", use_safetensors=True, torch_dtype=torch.float16, variant="fp16")
23
  refiner.enable_xformers_memory_efficient_attention()
24
  refiner = refiner.to(device)
25
  refiner.unet = torch.compile(refiner.unet, mode="reduce-overhead", fullgraph=True)
26
+ #torch.cuda.empty_cache()
27
 
28
  upscaler = DiffusionPipeline.from_pretrained("stabilityai/sd-x2-latent-upscaler", torch_dtype=torch.float16, use_safetensors=True)
29
  upscaler.enable_xformers_memory_efficient_attention()
30
  upscaler = upscaler.to(device)
31
  upscaler.unet = torch.compile(upscaler.unet, mode="reduce-overhead", fullgraph=True)
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)
 
47
  if upscaling == 'Yes':
48
  image = refiner(prompt=prompt, prompt_2=prompt_2, negative_prompt=negative_prompt, negative_prompt_2=negative_prompt_2, image=int_image).images[0]
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, prompt_2=prompt_2, negative_prompt=negative_prompt, negative_prompt_2=negative_prompt_2, image=int_image).images[0]
54
+ #torch.cuda.empty_cache()
55
  return (image, image)
56
 
57
  gr.Interface(fn=genie, inputs=[gr.Textbox(label='What you want the AI to generate. 77 Token Limit. A Token is Any Word, Number, Symbol, or Punctuation. Everything Over 77 Will Be Truncated!'),