MohamedRashad commited on
Commit
36a40e7
·
1 Parent(s): c9ecbc4

Enhance image generation pipeline by enabling tiling, slicing, and sequential CPU offload in app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -3
app.py CHANGED
@@ -24,9 +24,10 @@ from live_preview_helpers import flux_pipe_call_that_returns_an_iterable_of_imag
24
  llm_client = Client("Qwen/Qwen2.5-72B-Instruct")
25
 
26
  device = "cuda" if torch.cuda.is_available() else "cpu"
27
- taef1 = AutoencoderTiny.from_pretrained("madebyollin/taef1", torch_dtype=torch.bfloat16).to(device)
28
  pipe = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch.bfloat16).to(device)
29
- good_vae = AutoencoderKL.from_pretrained("black-forest-labs/FLUX.1-dev", subfolder="vae", torch_dtype=torch.bfloat16).to(device)
 
 
30
  torch.cuda.empty_cache()
31
 
32
  pipe.flux_pipe_call_that_returns_an_iterable_of_images = flux_pipe_call_that_returns_an_iterable_of_images.__get__(pipe)
@@ -92,7 +93,6 @@ def generate_item_image(object_t2i_prompt):
92
  height=1024,
93
  generator=torch.Generator("cpu").manual_seed(0),
94
  output_type="pil",
95
- good_vae=good_vae,
96
  ):
97
  yield trial_id, image
98
  # img_path = t2i_client.predict(
 
24
  llm_client = Client("Qwen/Qwen2.5-72B-Instruct")
25
 
26
  device = "cuda" if torch.cuda.is_available() else "cpu"
 
27
  pipe = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch.bfloat16).to(device)
28
+ pipe.vae.enable_tiling()
29
+ pipe.vae.enable_slicing()
30
+ pipe.enable_sequential_cpu_offload() # offloads modules to CPU on a submodule level (rather than model level)
31
  torch.cuda.empty_cache()
32
 
33
  pipe.flux_pipe_call_that_returns_an_iterable_of_images = flux_pipe_call_that_returns_an_iterable_of_images.__get__(pipe)
 
93
  height=1024,
94
  generator=torch.Generator("cpu").manual_seed(0),
95
  output_type="pil",
 
96
  ):
97
  yield trial_id, image
98
  # img_path = t2i_client.predict(