rahul7star commited on
Commit
6c5fa74
·
verified ·
1 Parent(s): 51b4c5f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -1
app.py CHANGED
@@ -2,6 +2,8 @@ import torch
2
  import spaces
3
  import gradio as gr
4
  from diffusers import DiffusionPipeline
 
 
5
 
6
  # Load the pipeline once at startup
7
  print("Loading Z-Image-Turbo pipeline...")
@@ -10,8 +12,23 @@ pipe = DiffusionPipeline.from_pretrained(
10
  torch_dtype=torch.bfloat16,
11
  low_cpu_mem_usage=False,
12
  )
 
 
 
 
 
 
 
 
13
  pipe.to("cuda")
14
- print("Pipeline loaded!")
 
 
 
 
 
 
 
15
 
16
  @spaces.GPU
17
  def generate_image(prompt, height, width, num_inference_steps, seed, randomize_seed):
 
2
  import spaces
3
  import gradio as gr
4
  from diffusers import DiffusionPipeline
5
+ from optimization import optimize_pipeline_
6
+
7
 
8
  # Load the pipeline once at startup
9
  print("Loading Z-Image-Turbo pipeline...")
 
12
  torch_dtype=torch.bfloat16,
13
  low_cpu_mem_usage=False,
14
  )
15
+
16
+
17
+ pipe.transformer.set_attention_backend(attention_backend)
18
+
19
+ if enable_compile:
20
+ print("Compiling transformer...")
21
+ pipe.transformer = torch.compile(pipe.transformer, mode="max-autotune-no-cudagraphs", fullgraph=False)
22
+
23
  pipe.to("cuda")
24
+
25
+ optimize_pipeline_(
26
+ pipe,
27
+ prompt="prompt",
28
+ num_inference_steps=1,
29
+ guidance_scale=0.0
30
+ )
31
+
32
 
33
  @spaces.GPU
34
  def generate_image(prompt, height, width, num_inference_steps, seed, randomize_seed):