multimodalart HF Staff commited on
Commit
a13e9e4
·
verified ·
1 Parent(s): e35b35d

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +10 -5
app.py CHANGED
@@ -1,5 +1,5 @@
1
  import os
2
- os.environ.setdefault("PYTORCH_CUDA_ALLOC_CONF", "expandable_segments:True")
3
  import spaces
4
  import sys
5
  import time
@@ -447,7 +447,8 @@ def infer_chunk(
447
 
448
  def decode_video(pred_latent):
449
  """Decode latent tensor to video frames."""
450
- latents = pred_latent.to(vae.dtype)
 
451
  latents_mean = (
452
  torch.tensor(vae.config.latents_mean)
453
  .view(1, vae.config.z_dim, 1, 1, 1)
@@ -546,13 +547,17 @@ def generate(
546
 
547
  pred_latent = torch.cat(pred_latent_lst, dim=2)
548
 
549
- # Clean up caches
550
  transformer.clear_cache("pos")
551
  streaming_vae.clear_cache()
552
  torch.cuda.empty_cache()
553
 
554
- # Decode video
555
- video = decode_video(pred_latent)
 
 
 
 
556
 
557
  # Save to temp file
558
  from diffusers.utils import export_to_video
 
1
  import os
2
+ os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "expandable_segments:True"
3
  import spaces
4
  import sys
5
  import time
 
447
 
448
  def decode_video(pred_latent):
449
  """Decode latent tensor to video frames."""
450
+ vae_device = next(vae.parameters()).device
451
+ latents = pred_latent.to(vae_device).to(vae.dtype)
452
  latents_mean = (
453
  torch.tensor(vae.config.latents_mean)
454
  .view(1, vae.config.z_dim, 1, 1, 1)
 
547
 
548
  pred_latent = torch.cat(pred_latent_lst, dim=2)
549
 
550
+ # Clean up caches and free VRAM before VAE decode
551
  transformer.clear_cache("pos")
552
  streaming_vae.clear_cache()
553
  torch.cuda.empty_cache()
554
 
555
+ # Decode video - move pred_latent to CPU, then decode frame-by-frame
556
+ pred_latent_cpu = pred_latent.cpu()
557
+ del pred_latent
558
+ torch.cuda.empty_cache()
559
+
560
+ video = decode_video(pred_latent_cpu)
561
 
562
  # Save to temp file
563
  from diffusers.utils import export_to_video