dagloop5 commited on
Commit
bb16e86
Β·
verified Β·
1 Parent(s): d4f9aa4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -14
app.py CHANGED
@@ -78,22 +78,24 @@ from ltx_pipelines.utils.media_io import decode_audio_from_file, encode_video
78
  from ltx_core.loader.primitives import LoraPathStrengthAndSDOps
79
  from ltx_core.loader.sd_ops import LTXV_LORA_COMFY_RENAMING_MAP
80
 
 
81
  from ltx_core.model.transformer import attention as _attn_mod
82
-
83
  print(f"[ATTN] Before patch: memory_efficient_attention={_attn_mod.memory_efficient_attention}")
84
- try:
85
- from xformers.ops import memory_efficient_attention as _mea
86
- from xformers.ops.fmha import cutlass
87
-
88
- def _cutlass_memory_efficient_attention(*args, **kwargs):
89
- # Force CUTLASS and avoid FlashAttention paths that are crashing.
90
- kwargs["op"] = (cutlass.FwOp, cutlass.BwOp)
91
- return _mea(*args, **kwargs)
92
 
93
- _attn_mod.memory_efficient_attention = _cutlass_memory_efficient_attention
94
- print(f"[ATTN] After patch: memory_efficient_attention={_attn_mod.memory_efficient_attention}")
 
 
 
95
  except Exception as e:
96
- print(f"[ATTN] xformers patch FAILED: {type(e).__name__}: {e}")
 
 
 
 
 
 
 
97
 
98
  logging.getLogger().setLevel(logging.INFO)
99
 
@@ -289,8 +291,7 @@ class LTX23DistilledA2VPipeline:
289
  )
290
 
291
  torch.cuda.synchronize()
292
- del video_state # release Stage 1 latent only, keep encoder/transformer on GPU
293
- torch.cuda.empty_cache() # lightweight, no sync
294
 
295
  # ── Upscaling ──
296
  upscaled_video_latent = upsample_video(
@@ -326,6 +327,7 @@ class LTX23DistilledA2VPipeline:
326
  )
327
 
328
  torch.cuda.synchronize()
 
329
 
330
  # ── Decode both video and audio ──
331
  decoded_video = vae_decode_video(
 
78
  from ltx_core.loader.primitives import LoraPathStrengthAndSDOps
79
  from ltx_core.loader.sd_ops import LTXV_LORA_COMFY_RENAMING_MAP
80
 
81
+ # Attention kernels: try FlashAttention-3 first, fall back to xformers
82
  from ltx_core.model.transformer import attention as _attn_mod
 
83
  print(f"[ATTN] Before patch: memory_efficient_attention={_attn_mod.memory_efficient_attention}")
 
 
 
 
 
 
 
 
84
 
85
+ try:
86
+ from kernels import get_kernel
87
+ fa3_kernel = get_kernel("kernels-community/vllm-flash-attn3")
88
+ _attn_mod.memory_efficient_attention = fa3_kernel
89
+ print(f"[ATTN] FA3 kernel applied: {_attn_mod.memory_efficient_attention}")
90
  except Exception as e:
91
+ print(f"[ATTN] FA3 not available ({type(e).__name__}: {e}), trying xformers...")
92
+
93
+ try:
94
+ from xformers.ops import memory_efficient_attention as _mea
95
+ _attn_mod.memory_efficient_attention = _mea
96
+ print(f"[ATTN] xformers applied: {_attn_mod.memory_efficient_attention}")
97
+ except Exception as e2:
98
+ print(f"[ATTN] xformers also FAILED: {type(e2).__name__}: {e2}")
99
 
100
  logging.getLogger().setLevel(logging.INFO)
101
 
 
291
  )
292
 
293
  torch.cuda.synchronize()
294
+ cleanup_memory()
 
295
 
296
  # ── Upscaling ──
297
  upscaled_video_latent = upsample_video(
 
327
  )
328
 
329
  torch.cuda.synchronize()
330
+ cleanup_memory()
331
 
332
  # ── Decode both video and audio ──
333
  decoded_video = vae_decode_video(