Files
Athena-Deck/video_runtime.py
T

51 lines
3.4 KiB
Python

"""Pinned, unprivileged LTX installation; no host package or driver changes."""
import json
from pathlib import Path
import shutil
import sys
import sysconfig
from image_runtime import ImageRuntime
LTX_REV='a95ab856bf29407b6b066ede0abe1846050db56c'
class VideoRuntime(ImageRuntime):
def paths(self):
marker=self.root/'active.json'
if marker.is_file():
ident=json.loads(marker.read_text()).get('id','')
if len(ident)==32 and all(c in '0123456789abcdef' for c in ident):
base=self.root/ident
if (base/'ready').is_file():return base/'python/bin/python',base/'ltx'
return self.root/'not-installed/bin/python',self.root/'not-installed/ltx'
def status(self):
with self.lock:
python,source=self.paths()
return dict(installed=python.is_file() and (source/'packages/ltx-pipelines').is_dir(),job=dict(self.job) if self.job else None,revision=LTX_REV,required_disk_gib=25)
def start(self):
if not (Path(sysconfig.get_paths()['include'])/'Python.h').is_file():raise ValueError('Python-Entwicklungsheader fehlen (python3-dev). Deck-Installationspaket aktualisieren; native Installation benötigt zusätzlich einen C-Compiler.')
try:return super().start()
except ValueError as exc:raise ValueError(str(exc).replace('Bildlaufzeit','Video-Laufzeit')) from None
def _run(self):
base=self.root/self.job['id'];source=base/'ltx';python=base/'python/bin/python';state='failed';phase='Installation fehlgeschlagen.'
try:
base.mkdir(mode=0o700)
self._phase('Eigene Python-Umgebung erstellen');self._command([sys.executable,'-m','venv',base/'python'])
self._phase('Gepinnte LTX-Pipelines herunterladen')
for args in [['git','init',source],['git','-C',source,'fetch','--depth','1','https://github.com/Lightricks/LTX-2.git',LTX_REV],['git','-C',source,'checkout','--detach','FETCH_HEAD']]:self._command(args)
self._phase('PyTorch CUDA 12.8 installieren · mehrere GiB')
self._command([python,'-m','pip','install','--no-cache-dir','-c',Path(__file__).parent/'deploy/video-requirements.lock','torch==2.11.0','torchaudio==2.11.0','torchvision==0.26.0','--index-url','https://download.pytorch.org/whl/cu128'])
self._phase('LTX-Pipelines und Gemma-4-Unterstützung installieren')
self._command([python,'-m','pip','install','--no-cache-dir','-c',Path(__file__).parent/'deploy/video-requirements.lock','transformers==5.14.1',source/'packages/ltx-core',source/'packages/ltx-pipelines'])
self._phase('Laufzeit prüfen')
self._command([python,'-m','pip','check'])
self._command([python,'-c','import sysconfig; from pathlib import Path; assert (Path(sysconfig.get_paths()["include"])/"Python.h").is_file(); import torch; from ltx_pipelines.distilled import DistilledPipeline; from ltx_core.text_encoders.gemma.gemma_assets import GemmaAssets; assert torch.version.cuda'])
with self.lock:
if self.cancel.is_set():raise InterruptedError()
(base/'ready').write_text(LTX_REV)
marker=self.root/'active.tmp';marker.write_text(json.dumps({'id':base.name}));marker.replace(self.root/'active.json')
state='complete';phase='Video-Laufzeit installiert. Kein Modell gestartet.'
except InterruptedError:state='cancelled';phase='Installation abgebrochen.'
except Exception as exc:phase=str(exc) if isinstance(exc,RuntimeError) else 'Video-Installation fehlgeschlagen; Voraussetzungen und Speicher prüfen.'
finally:
if state!='complete':shutil.rmtree(base,ignore_errors=True)
with self.lock:self.process=None;self.job.update(state=state,phase=phase);self._save()