cb1cyf commited on
Commit
387b7ca
·
1 Parent(s): 9916f36

feat: speedup

Browse files
Files changed (1) hide show
  1. app.py +28 -24
app.py CHANGED
@@ -47,6 +47,8 @@ SAVE_DIR = "output/gradio"
47
  pipeline = None
48
  accelerator = None
49
  save_images = False
 
 
50
 
51
  def load_pipeline(accelerator, weight_dtype, args):
52
  pipeline = OmniGen2Pipeline.from_pretrained(
@@ -83,7 +85,7 @@ def load_pipeline(accelerator, weight_dtype, args):
83
  pipeline = pipeline.to(accelerator.device)
84
  return pipeline
85
 
86
- @spaces.GPU(duration=300)
87
  def run(
88
  instruction,
89
  width_input,
@@ -103,8 +105,13 @@ def run(
103
  max_pixels: int = 1024 * 1024,
104
  seed_input: int = -1,
105
  align_res: bool = True,
106
- progress=gr.Progress(),
107
  ):
 
 
 
 
 
 
108
  input_images = [image_input_1, image_input_2, image_input_3]
109
  input_images = [img for img in input_images if img is not None]
110
 
@@ -116,10 +123,6 @@ def run(
116
 
117
  generator = torch.Generator(device=accelerator.device).manual_seed(seed_input)
118
 
119
- def progress_callback(cur_step, timesteps):
120
- frac = (cur_step + 1) / float(timesteps)
121
- progress(frac)
122
-
123
  if scheduler == 'euler':
124
  pipeline.scheduler = FlowMatchEulerDiscreteScheduler()
125
  elif scheduler == 'dpmsolver++':
@@ -147,11 +150,8 @@ def run(
147
  num_images_per_prompt=num_images_per_prompt,
148
  generator=generator,
149
  output_type="pil",
150
- step_func=progress_callback,
151
  )
152
 
153
- progress(1.0)
154
-
155
  vis_images = [to_tensor(image) * 2 - 1 for image in results.images]
156
  output_image = create_collage(vis_images)
157
 
@@ -185,7 +185,6 @@ def get_examples(base_dir="assets/examples/OmniGen2"):
185
  with open(config_path, "r", encoding="utf-8") as f:
186
  config = json.load(f)
187
  _example = [config.get(k, None) for k in example_keys]
188
- _example.append(50) # steps
189
  examples.append(_example)
190
  return examples
191
 
@@ -215,8 +214,6 @@ tips = """
215
 
216
  💡 We provide step-by-step instructions in our <a href='https://github.com/bytedance/UMO' target='_blank'> Github Repo</a>. Additionally, try the examples and comparison provided below the demo to quickly get familiar with UMO and spark your creativity!
217
 
218
- ❗️ Since the generation of OmniGen2 itself is quite slow with default 50 steps, we recommand using less steps to save your free quota but with some performance degradation.
219
-
220
  <details>
221
  <summary style="cursor: pointer; color: #d34c0e; font-weight: 500;"> ⚡️ Tips from the based OmniGen2</summary>
222
 
@@ -290,6 +287,25 @@ def main(args):
290
  label="Width", minimum=256, maximum=2048, value=1024, step=128
291
  )
292
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
293
  with gr.Accordion("Advanced Options", open=False):
294
  with gr.Row(equal_height=True):
295
  align_res = gr.Checkbox(
@@ -348,17 +364,6 @@ def main(args):
348
  outputs=[cfg_range_start]
349
  )
350
 
351
- with gr.Row(equal_height=True):
352
- scheduler_input = gr.Dropdown(
353
- label="Scheduler",
354
- choices=["euler", "dpmsolver++"],
355
- value="euler",
356
- info="The scheduler to use for the model.",
357
- )
358
-
359
- num_inference_steps = gr.Slider(
360
- label="Inference Steps", minimum=20, maximum=100, value=50, step=1
361
- )
362
  with gr.Row(equal_height=True):
363
  num_images_per_prompt = gr.Slider(
364
  label="Number of images per prompt",
@@ -448,7 +453,6 @@ def main(args):
448
  align_res,
449
  output_image,
450
  output_image_omnigen2,
451
- num_inference_steps,
452
  ],
453
  label="We provide examples for academic research. The vast majority of images used in this demo are either generated or from open-source datasets. If you have any concerns, please contact us, and we will promptly remove any inappropriate content.",
454
  examples_per_page=15
 
47
  pipeline = None
48
  accelerator = None
49
  save_images = False
50
+ enable_taylorseer = False
51
+ enable_teacache = False
52
 
53
  def load_pipeline(accelerator, weight_dtype, args):
54
  pipeline = OmniGen2Pipeline.from_pretrained(
 
85
  pipeline = pipeline.to(accelerator.device)
86
  return pipeline
87
 
88
+ @spaces.GPU(duration=600)
89
  def run(
90
  instruction,
91
  width_input,
 
105
  max_pixels: int = 1024 * 1024,
106
  seed_input: int = -1,
107
  align_res: bool = True,
 
108
  ):
109
+ if enable_taylorseer:
110
+ pipeline.enable_taylorseer = True
111
+ elif enable_teacache:
112
+ pipeline.transformer.enable_teacache = True
113
+ pipeline.transformer.teacache_rel_l1_thresh = 0.05
114
+
115
  input_images = [image_input_1, image_input_2, image_input_3]
116
  input_images = [img for img in input_images if img is not None]
117
 
 
123
 
124
  generator = torch.Generator(device=accelerator.device).manual_seed(seed_input)
125
 
 
 
 
 
126
  if scheduler == 'euler':
127
  pipeline.scheduler = FlowMatchEulerDiscreteScheduler()
128
  elif scheduler == 'dpmsolver++':
 
150
  num_images_per_prompt=num_images_per_prompt,
151
  generator=generator,
152
  output_type="pil",
 
153
  )
154
 
 
 
155
  vis_images = [to_tensor(image) * 2 - 1 for image in results.images]
156
  output_image = create_collage(vis_images)
157
 
 
185
  with open(config_path, "r", encoding="utf-8") as f:
186
  config = json.load(f)
187
  _example = [config.get(k, None) for k in example_keys]
 
188
  examples.append(_example)
189
  return examples
190
 
 
214
 
215
  💡 We provide step-by-step instructions in our <a href='https://github.com/bytedance/UMO' target='_blank'> Github Repo</a>. Additionally, try the examples and comparison provided below the demo to quickly get familiar with UMO and spark your creativity!
216
 
 
 
217
  <details>
218
  <summary style="cursor: pointer; color: #d34c0e; font-weight: 500;"> ⚡️ Tips from the based OmniGen2</summary>
219
 
 
287
  label="Width", minimum=256, maximum=2048, value=1024, step=128
288
  )
289
 
290
+ with gr.Accordion("Speed Up Options", open=True):
291
+ with gr.Row(equal_height=True):
292
+ global enable_taylorseer
293
+ global enable_teacache
294
+ enable_taylorseer = gr.Checkbox(label="Whether to use TaylorSeer to speed up inference", value=True)
295
+ enable_teacache = gr.Checkbox(label="Whether to use TeaCache to speed up inference", value=False)
296
+
297
+ with gr.Row(equal_height=True):
298
+ scheduler_input = gr.Dropdown(
299
+ label="Scheduler",
300
+ choices=["euler", "dpmsolver++"],
301
+ value="euler",
302
+ info="The scheduler to use for the model.",
303
+ )
304
+
305
+ num_inference_steps = gr.Slider(
306
+ label="Inference Steps", minimum=20, maximum=100, value=50, step=1
307
+ )
308
+
309
  with gr.Accordion("Advanced Options", open=False):
310
  with gr.Row(equal_height=True):
311
  align_res = gr.Checkbox(
 
364
  outputs=[cfg_range_start]
365
  )
366
 
 
 
 
 
 
 
 
 
 
 
 
367
  with gr.Row(equal_height=True):
368
  num_images_per_prompt = gr.Slider(
369
  label="Number of images per prompt",
 
453
  align_res,
454
  output_image,
455
  output_image_omnigen2,
 
456
  ],
457
  label="We provide examples for academic research. The vast majority of images used in this demo are either generated or from open-source datasets. If you have any concerns, please contact us, and we will promptly remove any inappropriate content.",
458
  examples_per_page=15