KingNish commited on
Commit
3db3884
·
verified ·
1 Parent(s): 92ae8b4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -36
app.py CHANGED
@@ -6,7 +6,6 @@ import torch
6
  import time
7
  from diffusers import DiffusionPipeline, AutoencoderTiny
8
  from custom_pipeline import FluxWithCFGPipeline
9
- from diffusers.hooks import apply_group_offloading
10
 
11
  # --- Torch Optimizations ---
12
  torch.backends.cuda.matmul.allow_tf32 = True
@@ -31,46 +30,11 @@ pipe.vae = AutoencoderTiny.from_pretrained("madebyollin/taef1", torch_dtype=dtyp
31
 
32
  pipe.to(device)
33
 
34
- group_offloading = None
35
-
36
  # --- Inference Function ---
37
  @spaces.GPU
38
  def generate_image(prompt: str, seed: int = 42, width: int = DEFAULT_WIDTH, height: int = DEFAULT_HEIGHT, randomize_seed: bool = False, num_inference_steps: int = DEFAULT_INFERENCE_STEPS, is_enhance: bool = False):
39
  """Generates an image using the FLUX pipeline with error handling."""
40
 
41
- global group_offloading
42
- if not group_offloading:
43
- apply_group_offloading(
44
- pipe.transformer,
45
- offload_type="leaf_level",
46
- offload_device=torch.device("cpu"),
47
- onload_device=torch.device("cuda"),
48
- use_stream=True,
49
- )
50
- apply_group_offloading(
51
- pipe.text_encoder,
52
- offload_device=torch.device("cpu"),
53
- onload_device=torch.device("cuda"),
54
- offload_type="leaf_level",
55
- use_stream=True,
56
- )
57
- apply_group_offloading(
58
- pipe.text_encoder_2,
59
- offload_device=torch.device("cpu"),
60
- onload_device=torch.device("cuda"),
61
- offload_type="leaf_level",
62
- use_stream=True,
63
- )
64
- apply_group_offloading(
65
- pipe.vae,
66
- offload_device=torch.device("cpu"),
67
- onload_device=torch.device("cuda"),
68
- offload_type="leaf_level",
69
- use_stream=True,
70
- )
71
-
72
- group_offloading = True
73
-
74
  if pipe is None:
75
  raise gr.Error("Diffusion pipeline failed to load. Cannot generate images.")
76
 
 
6
  import time
7
  from diffusers import DiffusionPipeline, AutoencoderTiny
8
  from custom_pipeline import FluxWithCFGPipeline
 
9
 
10
  # --- Torch Optimizations ---
11
  torch.backends.cuda.matmul.allow_tf32 = True
 
30
 
31
  pipe.to(device)
32
 
 
 
33
  # --- Inference Function ---
34
  @spaces.GPU
35
  def generate_image(prompt: str, seed: int = 42, width: int = DEFAULT_WIDTH, height: int = DEFAULT_HEIGHT, randomize_seed: bool = False, num_inference_steps: int = DEFAULT_INFERENCE_STEPS, is_enhance: bool = False):
36
  """Generates an image using the FLUX pipeline with error handling."""
37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  if pipe is None:
39
  raise gr.Error("Diffusion pipeline failed to load. Cannot generate images.")
40