ford442 commited on
Commit
4cf56ac
·
verified ·
1 Parent(s): c0a1563

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -3
app.py CHANGED
@@ -34,7 +34,7 @@ FTP_PASS = "GoogleBez12!"
34
  FTP_DIR = "1ink.us/stable_diff/" # Remote directory on FTP server
35
 
36
  DESCRIPTIONXX = """
37
- ## ⚡⚡⚡⚡ REALVISXL V5.0 BF16 (Tester B) ⚡⚡⚡⚡
38
  """
39
 
40
  examples = [
@@ -78,7 +78,42 @@ STYLE_NAMES = list(styles.keys())
78
  HF_TOKEN = os.getenv("HF_TOKEN")
79
 
80
  device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
81
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  def load_and_prepare_model():
83
  #vaeXL = AutoencoderKL.from_pretrained("stabilityai/sdxl-vae", safety_checker=None, use_safetensors=False).to(device=device, dtype=torch.bfloat16)
84
  #vaeRV = AutoencoderKL.from_pretrained("SG161222/RealVisXL_V5.0", subfolder='vae', safety_checker=None, use_safetensors=False).to(device).to(torch.bfloat16) #.to(device=device, dtype=torch.bfloat16)
@@ -100,7 +135,7 @@ def load_and_prepare_model():
100
  return pipe
101
 
102
  # Preload and compile both models
103
- pipe =load_and_prepare_model()
104
 
105
  MAX_SEED = np.iinfo(np.int32).max
106
 
@@ -172,6 +207,7 @@ def generate_30(
172
  "num_inference_steps": num_inference_steps,
173
  "generator": generator,
174
  "output_type": "pil",
 
175
  }
176
  if use_resolution_binning:
177
  options["use_resolution_binning"] = True
@@ -212,6 +248,7 @@ def generate_60(
212
  "num_inference_steps": num_inference_steps,
213
  "generator": generator,
214
  "output_type": "pil",
 
215
  }
216
  if use_resolution_binning:
217
  options["use_resolution_binning"] = True
@@ -252,6 +289,7 @@ def generate_90(
252
  "num_inference_steps": num_inference_steps,
253
  "generator": generator,
254
  "output_type": "pil",
 
255
  }
256
  if use_resolution_binning:
257
  options["use_resolution_binning"] = True
 
34
  FTP_DIR = "1ink.us/stable_diff/" # Remote directory on FTP server
35
 
36
  DESCRIPTIONXX = """
37
+ ## ⚡⚡⚡⚡ REALVISXL V5.0 BF16 (Tester C) ⚡⚡⚡⚡
38
  """
39
 
40
  examples = [
 
78
  HF_TOKEN = os.getenv("HF_TOKEN")
79
 
80
  device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
81
+
82
+ def scheduler_swap_callback(pipeline, step_index, timestep):
83
+ # adjust the batch_size of prompt_embeds according to guidance_scale
84
+ if step_index == int(pipeline.num_timesteps * 0.1):
85
+ print("-- swapping scheduler --")
86
+ # pipeline.scheduler = euler_scheduler
87
+ torch.set_float32_matmul_precision("high")
88
+ # pipe.vae = vae_b
89
+ torch.backends.cudnn.allow_tf32 = True
90
+ torch.backends.cuda.matmul.allow_tf32 = True
91
+ # torch.backends.cudnn.deterministic = True
92
+ torch.backends.cuda.preferred_blas_library="cublaslt"
93
+ if step_index == int(pipeline.num_timesteps * 0.5):
94
+ # torch.set_float32_matmul_precision("medium")
95
+ pipe.unet.to(torch.float64)
96
+ # pipe.guidance_scale=1.0
97
+ # pipe.scheduler.set_timesteps(num_inference_steps*.70)
98
+ # print(f"-- setting step {pipeline.num_timesteps * 0.1} --")
99
+ # pipeline.scheduler._step_index = pipeline.num_timesteps * 0.1
100
+ if step_index == int(pipeline.num_timesteps * 0.9):
101
+ torch.backends.cuda.preferred_blas_library="cublas"
102
+ torch.backends.cudnn.allow_tf32 = False
103
+ torch.backends.cuda.matmul.allow_tf32 = False
104
+ torch.set_float32_matmul_precision("highest")
105
+ pipe.unet.to(torch.bfloat16)
106
+ # pipe.vae = vae_a
107
+ # pipe.unet = unet_a
108
+ # torch.backends.cudnn.deterministic = False
109
+ print("-- swapping scheduler --")
110
+ # pipeline.scheduler = heun_scheduler
111
+ #pipe.scheduler.set_timesteps(num_inference_steps*.70)
112
+ # print(f"-- setting step {pipeline.num_timesteps * 0.9} --")
113
+ # pipeline.scheduler._step_index = pipeline.num_timesteps * 0.9
114
+ return
115
+
116
+
117
  def load_and_prepare_model():
118
  #vaeXL = AutoencoderKL.from_pretrained("stabilityai/sdxl-vae", safety_checker=None, use_safetensors=False).to(device=device, dtype=torch.bfloat16)
119
  #vaeRV = AutoencoderKL.from_pretrained("SG161222/RealVisXL_V5.0", subfolder='vae', safety_checker=None, use_safetensors=False).to(device).to(torch.bfloat16) #.to(device=device, dtype=torch.bfloat16)
 
135
  return pipe
136
 
137
  # Preload and compile both models
138
+ pipe = load_and_prepare_model()
139
 
140
  MAX_SEED = np.iinfo(np.int32).max
141
 
 
207
  "num_inference_steps": num_inference_steps,
208
  "generator": generator,
209
  "output_type": "pil",
210
+ "callback_on_step_end": scheduler_swap_callback
211
  }
212
  if use_resolution_binning:
213
  options["use_resolution_binning"] = True
 
248
  "num_inference_steps": num_inference_steps,
249
  "generator": generator,
250
  "output_type": "pil",
251
+ "callback_on_step_end": scheduler_swap_callback
252
  }
253
  if use_resolution_binning:
254
  options["use_resolution_binning"] = True
 
289
  "num_inference_steps": num_inference_steps,
290
  "generator": generator,
291
  "output_type": "pil",
292
+ "callback_on_step_end": scheduler_swap_callback
293
  }
294
  if use_resolution_binning:
295
  options["use_resolution_binning"] = True