add aoti for speed up

#3
by linoyts HF Staff - opened
Files changed (2) hide show
  1. app.py +34 -2
  2. requirements.txt +5 -4
app.py CHANGED
@@ -6,8 +6,7 @@ import sys
6
  os.environ["TORCH_COMPILE_DISABLE"] = "1"
7
  os.environ["TORCHDYNAMO_DISABLE"] = "1"
8
 
9
- # memory-efficient attention
10
- subprocess.run([sys.executable, "-m", "pip", "install", "xformers==0.0.32.post2", "--no-build-isolation"], check=False)
11
 
12
  # --- clone + install the NATIVE LTX-2 codebase at the pinned commit the working ZeroGPU spaces use ---
13
  LTX_REPO_URL = "https://github.com/Lightricks/LTX-2.git"
@@ -224,6 +223,38 @@ if not SKIP_STAGE_2:
224
  _preload_pin(getattr(pipeline, "stage_2_model_ledger", None), "stage2")
225
  print("Pipeline ready (all components preloaded + pinned for ZeroGPU packing).")
226
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
227
 
228
  def _duration(*args, **kwargs):
229
  nf = next((a for a in args if isinstance(a, int) and a in FRAME_CHOICES), DEFAULT_FRAMES)
@@ -270,6 +301,7 @@ with gr.Blocks(title="LTX-2.3 Colorize") as demo:
270
  "motion identity. Using [LTX 2.3 Distilled](https://huggingface.co/Lightricks/LTX-2.3) "
271
  "with the [Colorization IC-LoRA](https://huggingface.co/Lightricks/LTX-2.3-22b-IC-LoRA-Colorization)."
272
  )
 
273
  with gr.Row():
274
  with gr.Column():
275
  video_in = gr.Video(label="Input video (any clip — recolored as B&W)")
 
6
  os.environ["TORCH_COMPILE_DISABLE"] = "1"
7
  os.environ["TORCHDYNAMO_DISABLE"] = "1"
8
 
9
+ # (removed runtime xformers install -> would pull torch 2.8 and break the AOTI .pt2; SDPA used)
 
10
 
11
  # --- clone + install the NATIVE LTX-2 codebase at the pinned commit the working ZeroGPU spaces use ---
12
  LTX_REPO_URL = "https://github.com/Lightricks/LTX-2.git"
 
223
  _preload_pin(getattr(pipeline, "stage_2_model_ledger", None), "stage2")
224
  print("Pipeline ready (all components preloaded + pinned for ZeroGPU packing).")
225
 
226
+ # ============================ AOTI (native bf16 transformer graph) ============================
227
+ AOTI_REPO = os.environ.get("AOTI_REPO", "linoyts/LTX-2.3-Native-Transformer-GroupA-sm120-cu130-r20")
228
+ import types as _types
229
+ from dataclasses import replace as _dc_replace
230
+ from ltx_core.model.transformer.transformer_args import TransformerArgs as _TA
231
+ _TA_FIELDS = list(_TA.__dataclass_fields__.keys())
232
+ def _flatten_ta(ta):
233
+ out = []
234
+ for f in _TA_FIELDS:
235
+ v = getattr(ta, f)
236
+ if torch.is_tensor(v):
237
+ out.append(v)
238
+ elif isinstance(v, tuple) and len(v) > 0 and all(torch.is_tensor(x) for x in v):
239
+ out.extend(v)
240
+ return out
241
+ def _install_aoti():
242
+ velocity = pipeline.stage_1_model_ledger.transformer().velocity_model
243
+ spaces.aoti_load(module=velocity, repo_id=AOTI_REPO)
244
+ def _proc(self, video, audio, perturbations):
245
+ for blk in self.transformer_blocks:
246
+ o = blk(*(_flatten_ta(video) + _flatten_ta(audio)))
247
+ video = _dc_replace(video, x=o[0]); audio = _dc_replace(audio, x=o[1])
248
+ return video, audio
249
+ velocity._process_transformer_blocks = _types.MethodType(_proc, velocity)
250
+ print(f"[AOTI] loaded {AOTI_REPO} + patched block loop", flush=True)
251
+ print(f"[AOTI] base torch={torch.__version__} cuda={torch.version.cuda}", flush=True)
252
+ try:
253
+ _install_aoti(); print("[AOTI] OK", flush=True)
254
+ except Exception as _e:
255
+ import traceback; traceback.print_exc(); print(f"[AOTI] FAILED ({_e!r}) -> EAGER", flush=True)
256
+ # ==============================================================================================
257
+
258
 
259
  def _duration(*args, **kwargs):
260
  nf = next((a for a in args if isinstance(a, int) and a in FRAME_CHOICES), DEFAULT_FRAMES)
 
301
  "motion identity. Using [LTX 2.3 Distilled](https://huggingface.co/Lightricks/LTX-2.3) "
302
  "with the [Colorization IC-LoRA](https://huggingface.co/Lightricks/LTX-2.3-22b-IC-LoRA-Colorization)."
303
  )
304
+ gr.Markdown("⚡ **Accelerated with [AOTI](https://huggingface.co/linoyts/LTX-2.3-Native-Transformer-GroupA-sm120-cu130-r20)** — precompiled transformer for faster inference.")
305
  with gr.Row():
306
  with gr.Column():
307
  video_in = gr.Video(label="Input video (any clip — recolored as B&W)")
requirements.txt CHANGED
@@ -1,11 +1,12 @@
 
1
  transformers==4.57.6
2
  accelerate
3
- torch==2.8.0
4
- torchaudio==2.8.0
5
  einops
6
  scipy
7
  av
8
- scikit-image>=0.25.2
9
- flashpack==0.1.2
10
  imageio[ffmpeg]
11
  pillow
 
 
 
 
1
+ --extra-index-url https://download.pytorch.org/whl/cu130
2
  transformers==4.57.6
3
  accelerate
4
+ torchaudio==2.11.0
 
5
  einops
6
  scipy
7
  av
 
 
8
  imageio[ffmpeg]
9
  pillow
10
+ spaces
11
+ sentencepiece
12
+ ftfy