apolinario commited on
Commit
d330ff4
·
1 Parent(s): 12192e5

Enable VAE tiling+slicing only when resolution >= 768 (inside @spaces.GPU); reset after the call

Browse files
Files changed (1) hide show
  1. app.py +20 -0
app.py CHANGED
@@ -241,6 +241,16 @@ def generate(
241
  num_inference_steps = int(num_inference_steps)
242
  H = W = int(resolution)
243
 
 
 
 
 
 
 
 
 
 
 
244
  # initial: show the live preview, hide the final slider
245
  yield gr.update(visible=True, value=None, label="Generating Z-Image…"), gr.update(visible=False, value=None), gr.update(value=seed)
246
 
@@ -303,6 +313,9 @@ def generate(
303
  (baseline_01[0].clamp(0, 1).permute(1, 2, 0).float().cpu().numpy() * 255).astype(np.uint8)
304
  )
305
 
 
 
 
306
  # ---- PiD upscaling on the final latent, streaming the 4 internal steps ----
307
  final_sigma = float(pipeline.scheduler.sigmas[-1].item())
308
  pid_img = None
@@ -314,6 +327,13 @@ def generate(
314
  gr.update(),
315
  )
316
 
 
 
 
 
 
 
 
317
  # ---- Done: hide live preview, show the A/B slider ----
318
  yield (
319
  gr.update(visible=False, value=None),
 
241
  num_inference_steps = int(num_inference_steps)
242
  H = W = int(resolution)
243
 
244
+ # Heavy resolutions push the VAE decode over the 48GB MIG budget — slice + tile.
245
+ vae_tiling_enabled = False
246
+ if H >= 768:
247
+ try:
248
+ pipeline.vae.enable_tiling()
249
+ pipeline.vae.enable_slicing()
250
+ vae_tiling_enabled = True
251
+ except Exception as _e:
252
+ print(f"[pid] VAE tiling/slicing not available: {_e}", flush=True)
253
+
254
  # initial: show the live preview, hide the final slider
255
  yield gr.update(visible=True, value=None, label="Generating Z-Image…"), gr.update(visible=False, value=None), gr.update(value=seed)
256
 
 
313
  (baseline_01[0].clamp(0, 1).permute(1, 2, 0).float().cpu().numpy() * 255).astype(np.uint8)
314
  )
315
 
316
+ # Free Z-Image VAE intermediates before PiD takes over the GPU
317
+ torch.cuda.empty_cache()
318
+
319
  # ---- PiD upscaling on the final latent, streaming the 4 internal steps ----
320
  final_sigma = float(pipeline.scheduler.sigmas[-1].item())
321
  pid_img = None
 
327
  gr.update(),
328
  )
329
 
330
+ if vae_tiling_enabled:
331
+ try:
332
+ pipeline.vae.disable_tiling()
333
+ pipeline.vae.disable_slicing()
334
+ except Exception:
335
+ pass
336
+
337
  # ---- Done: hide live preview, show the A/B slider ----
338
  yield (
339
  gr.update(visible=False, value=None),