Update app.py
Browse files5 unmodified lines67891011121314151666 unmodified lines83848586878889909192939495969798991001011021031041051061071081091101111121131141151165 unmodified linesos.environ["TORCH_COMPILE_DISABLE"] = "1"os.environ["TORCHDYNAMO_DISABLE"] = "1"subprocess.run([sys.executable, "-m", "pip", "install", "flash-attn", "--no-build-isolation"],check=False,)# Clone LTX-2 repo and install packagesLTX_REPO_URL = "https://github.com/Lightricks/LTX-2.git"LTX_REPO_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "LTX-2")66 unmodified linesfrom ltx_core.loader.primitives import LoraPathStrengthAndSDOpsfrom ltx_core.loader.sd_ops import LTXV_LORA_COMFY_RENAMING_MAPfrom flash_attn import flash_attn_functry:from ltx_core.model.transformer import attention as _attn_mod_attn_mod.memory_efficient_attention = flash_attn_funcexcept Exception as e:print(f"[ATTN] FA3 import failed: {e}, using xformers")from xformers.ops import memory_efficient_attention as _mea_attn_mod.memory_efficient_attention = _mea# Attention kernels: try FlashAttention-3 first, fall back to xformersfrom ltx_core.model.transformer import attention as _attn_modprint(f"[ATTN] Before patch: memory_efficient_attention={_attn_mod.memory_efficient_attention}")try:from kernels import get_kernelfa3_kernel = get_kernel("kernels-community/vllm-flash-attn3")_attn_mod.memory_efficient_attention = fa3_kernelprint(f"[ATTN] FA3 kernel applied: {_attn_mod.memory_efficient_attention}")except Exception as e:print(f"[ATTN] FA3 not available ({type(e).__name__}: {e}), trying xformers...")try:from xformers.ops import memory_efficient_attention as _mea_attn_mod.memory_efficient_attention = _meaprint(f"[ATTN] xformers applied: {_attn_mod.memory_efficient_attention}")except Exception as e2:print(f"[ATTN] xformers also FAILED: {type(e2).__name__}: {e2}")logging.getLogger().setLevel(logging.INFO)5 unmodified lines6789101166 unmodified lines787980818283848586878889909192939495969798995 unmodified linesos.environ["TORCH_COMPILE_DISABLE"] = "1"os.environ["TORCHDYNAMO_DISABLE"] = "1"# Clone LTX-2 repo and install packagesLTX_REPO_URL = "https://github.com/Lightricks/LTX-2.git"LTX_REPO_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "LTX-2")66 unmodified linesfrom ltx_core.loader.primitives import LoraPathStrengthAndSDOpsfrom ltx_core.loader.sd_ops import LTXV_LORA_COMFY_RENAMING_MAPfrom ltx_core.model.transformer import attention as _attn_modprint(f"[ATTN] Before patch: memory_efficient_attention={_attn_mod.memory_efficient_attention}")try:from xformers.ops import memory_efficient_attention as _meafrom xformers.ops.fmha import cutlassdef _cutlass_memory_efficient_attention(*args, **kwargs):# Force CUTLASS and avoid FlashAttention paths that are crashing.kwargs["op"] = (cutlass.FwOp, cutlass.BwOp)return _mea(*args, **kwargs)_attn_mod.memory_efficient_attention = _cutlass_memory_efficient_attentionprint(f"[ATTN] After patch: memory_efficient_attention={_attn_mod.memory_efficient_attention}")except Exception as e:print(f"[ATTN] xformers patch FAILED: {type(e).__name__}: {e}")logging.getLogger().setLevel(logging.INFO)
app.py+10-27