Free, open-source AI video generator for Mac. Run LTX-2.5 and MiniMax H3 (Hailuo) locally on Apple Silicon: text-to-video and image-to-video with sound, lip-sync, character LoRA training, songs from lyrics (YuE2) and image editing (Qwen-Image-Edit). One-click install via Pinokio. Offline: no cloud, no API key, no NVIDIA GPU.
Python ai-filmmakingai-videoai-video-generatorapple-siliconhailuoimage-to-videolip-synclocal-ailora-trainingltx-2ltx-2-5ltx-videomacosminimax-h3mlxmusic-generationoffline-aipinokiotext-to-videovideo-generation
fix(train): clean-install safety — resolve model + ffmpeg dynamically
mrbizarro6fa956457663
diff --git a/lora_lab/__init__.py b/lora_lab/__init__.pyindex e69de29..9ec08ef 100644--- a/lora_lab/__init__.py+++ b/lora_lab/__init__.py@@ -0,0 +1,113 @@+"""lora_lab — Phosphene's character + voice LoRA training pipeline.++This package is vendored into Phosphene at+``phosphene-dev.git/lora_lab/`` and runs in the same MLX venv as the+panel helper (``ltx-2-mlx/env/``).++Public install discipline lives in this ``__init__.py`` so every+submodule (preprocess_images, preprocess_audio, train_character,+train_audio) can call ``resolve_default_model_dir()`` and get the right+LTX-2.3 Q4 base regardless of how the user installed Phosphene.+"""++from __future__ import annotations++import os+from pathlib import Path+++def resolve_default_model_dir() -> str:+ """Locate the LTX-2.3 Q4 model directory on this machine.++ Resolution order — first match wins, no directory existence required+ at import time so this is safe to call before any model download:++ 1. ``LTX_MODELS_DIR`` env var (the Phosphene panel sets this when+ it spawns ``lora_lab.train_character`` so the trainer picks up+ the same model root the panel just preflighted). Returns+ ``$LTX_MODELS_DIR/ltx-2.3-mlx-q4``.++ 2. Script-relative walk — look for ``mlx_models/ltx-2.3-mlx-q4``+ in any ancestor of this file up to the nearest ``.git``. This+ is what makes the vendored install (where this file lives at+ ``phosphene-dev.git/lora_lab/__init__.py`` and the model dir+ is at ``phosphene-dev.git/mlx_models/ltx-2.3-mlx-q4``)+ resolve cleanly.++ 3. ``~/.cache/huggingface/hub/models--dgrauet--ltx-2.3-mlx-q4/+ snapshots/<latest>`` — fallback for the authoring tree at+ ``~/AI/projects/lora-lab/`` and any historical installs that+ downloaded via the HF hub directly.++ 4. Worst case (nothing exists yet, no env), return the expected+ vendored path so the eventual error message names a place the+ user can actually inspect.++ Designed to never raise on import. The real failure comes later+ when the trainer tries to ``mx.load`` from a non-existent path and+ gets a clear filesystem error.+ """+ # 1. Explicit env override (set by the Phosphene panel).+ env_dir = os.environ.get("LTX_MODELS_DIR")+ if env_dir:+ candidate = Path(env_dir).expanduser() / "ltx-2.3-mlx-q4"+ if candidate.is_dir():+ return str(candidate)+ # Even if it doesn't exist yet, prefer the env path — it's what+ # the panel expects and the user controls it.+ env_candidate = str(candidate)+ else:+ env_candidate = None++ # 2. Script-relative walk for the vendored install.+ here = Path(__file__).resolve()+ for parent in here.parents:+ candidate = parent / "mlx_models" / "ltx-2.3-mlx-q4"+ if candidate.is_dir():+ return str(candidate)+ # Stop at the nearest repo root to avoid escaping into /Users/.+ if (parent / ".git").exists():+ break++ # 3. HF cache fallback (authoring tree / pre-Pinokio installs).+ legacy_root = (+ Path.home() / ".cache" / "huggingface" / "hub"+ / "models--dgrauet--ltx-2.3-mlx-q4" / "snapshots"+ )+ if legacy_root.is_dir():+ try:+ snapshots = [p for p in legacy_root.iterdir() if p.is_dir()]+ if snapshots:+ snapshots.sort(key=lambda p: p.stat().st_mtime, reverse=True)+ return str(snapshots[0])+ except OSError:+ pass++ # 4. Final fallback — the env path (even if it doesn't exist) or+ # the vendored guess. Don't raise; let the trainer surface the+ # real error when it tries to load.+ if env_candidate:+ return env_candidate+ return str(here.parents[1] / "mlx_models" / "ltx-2.3-mlx-q4")+++def resolve_default_text_encoder() -> str:+ """Locate Gemma 3 12B (LTX's text encoder) the same way.++ Same resolution rules as ``resolve_default_model_dir`` but for+ Gemma. Falls back to the HF repo id (``mlx-community/gemma-3-12b+ -it-4bit``) which mlx-vlm / ltx-trainer-mlx can fetch on first run.+ """+ env_dir = os.environ.get("LTX_MODELS_DIR")+ if env_dir:+ candidate = Path(env_dir).expanduser() / "gemma-3-12b-it-4bit"+ if candidate.is_dir():+ return str(candidate)+ here = Path(__file__).resolve()+ for parent in here.parents:+ candidate = parent / "mlx_models" / "gemma-3-12b-it-4bit"+ if candidate.is_dir():+ return str(candidate)+ if (parent / ".git").exists():+ break+ return "mlx-community/gemma-3-12b-it-4bit"diff --git a/lora_lab/preprocess_audio.py b/lora_lab/preprocess_audio.pyindex 3b49479..a7b2918 100644--- a/lora_lab/preprocess_audio.py+++ b/lora_lab/preprocess_audio.py@@ -56,11 +56,10 @@ from ltx_trainer_mlx.preprocess import _resolve_model_dirlogger = logging.getLogger(__name__)-DEFAULT_MODEL_DIR = str(- Path.home()- / ".cache/huggingface/hub/models--dgrauet--ltx-2.3-mlx-q4"- / "snapshots/53a6f5f39d9c074bc73e6a18ba391f40ddffaa68"-)+# Resolved dynamically — see lora_lab/__init__.py for the resolution+# order. Public Pinokio installs use the vendored mlx_models dir.+from lora_lab import resolve_default_model_dir+DEFAULT_MODEL_DIR = resolve_default_model_dir()AUDIO_SAMPLE_RATE = 16000 # LTX audio VAE expects 16 kHz monodiff --git a/lora_lab/preprocess_images.py b/lora_lab/preprocess_images.pyindex 9f78461..5408d0c 100644--- a/lora_lab/preprocess_images.py+++ b/lora_lab/preprocess_images.py@@ -47,11 +47,11 @@ logger = logging.getLogger(__name__)IMAGE_EXTENSIONS = {".jpg", ".jpeg", ".png", ".webp", ".bmp"}-DEFAULT_MODEL_DIR = str(- Path.home()- / ".cache/huggingface/hub/models--dgrauet--ltx-2.3-mlx-q4"- / "snapshots/53a6f5f39d9c074bc73e6a18ba391f40ddffaa68"-)+# Resolved dynamically — see lora_lab/__init__.py for the resolution+# order. Public Pinokio installs use the vendored mlx_models dir; the+# authoring tree falls back to the HF hub cache.+from lora_lab import resolve_default_model_dir+DEFAULT_MODEL_DIR = resolve_default_model_dir()def _force_eval(*arrays: mx.array) -> None:diff --git a/lora_lab/train_audio.py b/lora_lab/train_audio.pyindex bd9047c..554404a 100644--- a/lora_lab/train_audio.py+++ b/lora_lab/train_audio.py@@ -79,13 +79,13 @@ logger = logging.getLogger(__name__)# Constants (kept in lockstep with the Phase B audio configs)# -----------------------------------------------------------------------# Same Q4 snapshot the rest of the lab uses (matches preprocess_audio +-# train_character + configs/char_audio_lora_*.yaml).-DEFAULT_MODEL_PATH = (- "/Users/salo/.cache/huggingface/hub/models--dgrauet--ltx-2.3-mlx-q4"- "/snapshots/53a6f5f39d9c074bc73e6a18ba391f40ddffaa68"-)-DEFAULT_TEXT_ENCODER = "mlx-community/gemma-3-12b-it-4bit"+# Resolved dynamically — see lora_lab/__init__.py. Vendored installs+# resolve to phosphene-dev.git/mlx_models/ltx-2.3-mlx-q4; the authoring+# tree falls back to the HF hub cache. ``LTX_MODELS_DIR`` env (set by+# the Phosphene panel) takes precedence.+from lora_lab import resolve_default_model_dir, resolve_default_text_encoder+DEFAULT_MODEL_PATH = resolve_default_model_dir()+DEFAULT_TEXT_ENCODER = resolve_default_text_encoder()# The trainer's ``_find_lora_targets`` substring-matches against module paths# in LTXModel. These three names cover the audio attention + audio FF paths,diff --git a/lora_lab/train_character.py b/lora_lab/train_character.pyindex 0a71225..bbace45 100644--- a/lora_lab/train_character.py+++ b/lora_lab/train_character.py@@ -449,11 +449,14 @@ def run_preprocess(# Training (build a temp YAML, hand to the existing trainer wrapper logic)# -----------------------------------------------------------------------DEFAULT_MODEL_PATH = (- "/Users/salo/.cache/huggingface/hub/models--dgrauet--ltx-2.3-mlx-q4"- "/snapshots/53a6f5f39d9c074bc73e6a18ba391f40ddffaa68"-)-DEFAULT_TEXT_ENCODER = "mlx-community/gemma-3-12b-it-4bit"+# Resolved dynamically — see lora_lab/__init__.py. The previous hard-+# coded HF cache snapshot path was correct for the maintainer's machine+# only; clean Pinokio installs have the model at mlx_models/ltx-2.3-mlx-q4/+# inside the panel install dir, and ``LTX_MODELS_DIR`` (set by the panel+# when it spawns this script) points the resolver there.+from lora_lab import resolve_default_model_dir, resolve_default_text_encoder+DEFAULT_MODEL_PATH = resolve_default_model_dir()+DEFAULT_TEXT_ENCODER = resolve_default_text_encoder()def build_trainer_config(diff --git a/scripts/lora_lab_run.sh b/scripts/lora_lab_run.shindex c49eb7a..2ab2086 100755--- a/scripts/lora_lab_run.sh+++ b/scripts/lora_lab_run.sh@@ -18,16 +18,49 @@ PANEL_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"LTX_ROOT="$PANEL_ROOT/ltx-2-mlx"LTX_PY="$LTX_ROOT/env/bin/python"-# ffmpeg is shipped with Pinokio at this fixed path on the dev machine.-# Allow override for non-Pinokio installs.-FFMPEG_DIR="${PHOSPHENE_FFMPEG_DIR:-/Users/salo/pinokio/bin/ffmpeg-env/bin}"-if [[ ! -x "$LTX_PY" ]]; thenecho "fatal: ltx-2-mlx env python not found at $LTX_PY" >&2exit 1fi-if [[ ! -x "$FFMPEG_DIR/ffmpeg" ]]; then- echo "fatal: ffmpeg not found at $FFMPEG_DIR/ffmpeg (override with PHOSPHENE_FFMPEG_DIR)" >&2++# Resolve ffmpeg the same way the panel does — in order:+# 1. $PHOSPHENE_FFMPEG_DIR (explicit override, points at the directory+# containing the ffmpeg binary)+# 2. $LTX_FFMPEG (single-binary path, exported by the panel after+# its own resolver picks it)+# 3. Standard Pinokio install locations (the typical Mac install)+# 4. System PATH+# Previously hard-coded to /Users/.../pinokio/bin/ffmpeg-env/bin which+# only worked on the maintainer's machine — a public install would die+# on this check before any training ever ran.+FFMPEG_DIR=""+if [[ -n "${PHOSPHENE_FFMPEG_DIR:-}" && -x "${PHOSPHENE_FFMPEG_DIR}/ffmpeg" ]]; then+ FFMPEG_DIR="${PHOSPHENE_FFMPEG_DIR}"+elif [[ -n "${LTX_FFMPEG:-}" && -x "${LTX_FFMPEG}" ]]; then+ FFMPEG_DIR="$(dirname "${LTX_FFMPEG}")"+else+ for cand in \+ "${HOME}/pinokio/bin/ffmpeg-env/bin" \+ "${PANEL_ROOT}/../../bin/ffmpeg-env/bin" \+ "/Applications/Pinokio.app/Contents/Resources/bin/ffmpeg-env/bin"; do+ if [[ -x "${cand}/ffmpeg" ]]; then+ FFMPEG_DIR="${cand}"+ break+ fi+ done+ if [[ -z "${FFMPEG_DIR}" ]]; then+ sys_ffmpeg="$(command -v ffmpeg 2>/dev/null || true)"+ if [[ -n "${sys_ffmpeg}" ]]; then+ FFMPEG_DIR="$(dirname "${sys_ffmpeg}")"+ fi+ fi+fi+if [[ -z "${FFMPEG_DIR}" || ! -x "${FFMPEG_DIR}/ffmpeg" ]]; then+ echo "fatal: ffmpeg not found." >&2+ echo " Tried: PHOSPHENE_FFMPEG_DIR, LTX_FFMPEG, ~/pinokio/bin/ffmpeg-env/bin," >&2+ echo " Pinokio.app bundle, system PATH." >&2+ echo " Install Pinokio (which bundles ffmpeg) or set" >&2+ echo " PHOSPHENE_FFMPEG_DIR=/dir/containing/ffmpeg before running this." >&2exit 1fi