Skip to content

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.

Y1.013 · unified Quality picker; Customize disclosure for power users

mrbizarroafffcc22cfd3
diff --git a/README.md b/README.md
index 19a9d37..15d52e4 100644
--- a/README.md
+++ b/README.md
@@ -99,6 +99,17 @@ and step count change.
| **Standard** | Q4 distilled | ~7 min | The daily driver. Q4 weights (~25 GB on disk). |
| **High** | Q8 two-stage + TeaCache | ~12 min | Sharper detail, fewer artifacts on faces and text. Optional Q8 download (~25 GB extra). Required for FFLF. |
+Standard T2V/I2V also has an opt-in **Speed** control:
+
+- **Exact** is the default full sampler.
+- **Boost** skips up to two stable middle denoise calls.
+- **Turbo** skips up to three stable middle denoise calls.
+
+Boost/Turbo are experimental acceleration modes. They keep the same
+prompt, seed, dimensions, and output format, but they are not bit-for-bit
+or visually identical to Exact. They are disabled for High, Extend, and
+FFLF.
+
---
## Hardware tiers
@@ -317,6 +328,15 @@ Wall-clock times on an **M4 Mac Studio, 64 GB**:
| High (Q8 two-stage) | 1280×704 | 121 | s1=15 + s2=3 | ~12 min |
| FFLF (Q8) | 768×416 | 121 | s1=15 + s2=3 | ~5 min |
+Experimental Speed smoke test on the same 64 GB machine, I2V Standard,
+768×512, 121 frames, 8 steps:
+
+| Speed | Time | Notes |
+|---|---:|---|
+| Exact | 186 s | Full sampler |
+| Boost | 145 s | 2 cached denoise calls |
+| Turbo | 126 s | 3 cached denoise calls |
+
M-Max divides by ~3×. M-Ultra by ~6×. Compact tier (< 48 GB) takes
roughly 2× longer at clamped resolutions because of swap pressure.
@@ -376,6 +396,9 @@ output gallery with sidecar params, and the Pinokio install scripts.
render is the safest single thing a user can do. The panel surfaces
the exit signal name (SIGKILL / SIGSEGV / SIGABRT) when the helper
dies non-gracefully so issues are diagnosable.
+- **Boost/Turbo are quality trade-offs.** They are useful for fast
+ iteration, but Exact remains the default and safest choice for final
+ renders, faces, typography, and client work.
- **Localhost only.** The panel binds to `127.0.0.1` with no auth.
Not designed for LAN exposure or tunneling.
- **A2V (audio → video) not yet wired.** Upstream supports it; the
diff --git a/VERSION b/VERSION
index 88c62f4..b7bc815 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-Y1.012
+Y1.013
diff --git a/mlx_ltx_panel.py b/mlx_ltx_panel.py
index 0f9ca07..787661a 100644
--- a/mlx_ltx_panel.py
+++ b/mlx_ltx_panel.py
@@ -3930,6 +3930,105 @@ HTML = r"""<!doctype html>
opacity: 0.45; cursor: not-allowed; pointer-events: none;
}
+ /* Quality pills (Y1.013) — richer than the standard pill-btn so each
+ button can carry: name, dimensions+time, model+tier requirement.
+ Same .pill-btn skeleton; just looser padding and explicit children
+ for the three lines of content. */
+ .quality-row .pill-quality {
+ padding: 12px 8px 10px;
+ gap: 4px;
+ min-height: 76px;
+ justify-content: flex-start;
+ }
+ .pill-quality .ql-name {
+ font-size: 13px; font-weight: 600;
+ color: inherit; /* picks up muted/active colour from .pill-btn */
+ }
+ .pill-quality .ql-spec {
+ font-size: 10.5px;
+ color: var(--text);
+ opacity: 0.85;
+ font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
+ letter-spacing: 0;
+ }
+ .pill-quality .ql-tier {
+ font-size: 9.5px;
+ color: var(--muted);
+ letter-spacing: 0.04em;
+ text-transform: uppercase;
+ }
+ .pill-quality.active .ql-name { color: var(--accent-bright); }
+ .pill-quality.active .ql-spec { opacity: 1; }
+ .pill-quality.active .ql-tier { color: var(--accent-bright); opacity: 0.7; }
+
+ /* Customize disclosure inside the form — sub-tier UI, lighter than
+ a top-level <details>. Subtle border, indented body, distinct
+ chevron so it doesn't compete with the LoRAs section header. */
+ .customize-section {
+ margin-top: 8px;
+ border: 1px solid var(--border);
+ border-radius: 8px;
+ background: rgba(255,255,255,0.012);
+ overflow: hidden;
+ }
+ .customize-section > summary { list-style: none; cursor: pointer; }
+ .customize-section > summary::-webkit-details-marker { display: none; }
+ .cz-summary {
+ display: flex; align-items: center; gap: 10px;
+ padding: 8px 12px;
+ font-size: 12px;
+ color: var(--muted);
+ user-select: none;
+ transition: background 100ms;
+ }
+ .cz-summary:hover { background: rgba(255,255,255,0.02); color: var(--text); }
+ .customize-section[open] .cz-summary { color: var(--text); }
+ .cz-summary .cz-chevron {
+ display: inline-block; width: 12px;
+ font-size: 10px;
+ transform: rotate(-90deg);
+ transition: transform 140ms ease;
+ color: var(--muted);
+ }
+ .customize-section[open] .cz-summary .cz-chevron {
+ transform: rotate(0deg);
+ color: var(--accent-bright, #58a6ff);
+ }
+ .cz-summary .cz-title {
+ font-weight: 600;
+ font-size: 12px;
+ letter-spacing: 0;
+ }
+ .cz-summary .cz-meta {
+ margin-left: auto;
+ font-size: 11px; font-weight: 400;
+ color: var(--muted);
+ font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
+ }
+ .cz-body {
+ padding: 12px 14px 14px;
+ border-top: 1px solid var(--border);
+ display: flex; flex-direction: column; gap: 14px;
+ }
+ .cz-control { display: block; }
+ .cz-label {
+ font-size: 11px; font-weight: 600;
+ color: var(--muted);
+ text-transform: uppercase;
+ letter-spacing: 0.06em;
+ margin-bottom: 6px;
+ display: flex; align-items: baseline; gap: 8px;
+ }
+ .cz-label .cz-label-hint {
+ font-weight: 400;
+ letter-spacing: 0;
+ text-transform: none;
+ font-size: 10.5px;
+ color: var(--muted);
+ opacity: 0.85;
+ }
+ .cz-control .row { gap: 8px; }
+
/* Mode-specific blocks (image/audio/extend sections) */
.mode-only { display: none; }
.mode-only.show { display: block; }
@@ -4969,20 +5068,32 @@ HTML = r"""<!doctype html>
</div>
<input type="hidden" name="mode" id="mode" value="t2v">
+ <!-- Quality picker (Y1.013): one decision instead of four. Each
+ button bundles dimensions + model + step count + tier
+ recommendation, with the actual specs visible on the pill so
+ power users can read what they're getting. Aspect, custom
+ W/H, and the experimental Speed setting moved into the
+ Customize disclosure below. Beginners pick a button; power
+ users open Customize. -->
<h2>Quality</h2>
- <div class="pill-group cols-3" id="qualityGroup">
- <button type="button" class="pill-btn" data-quality="draft"><span>Draft</span><span class="sub">half size · ~2 min</span></button>
- <button type="button" class="pill-btn active" data-quality="standard"><span>Standard</span><span class="sub">full size · ~7 min</span></button>
- <button type="button" class="pill-btn disabled" data-quality="high" id="qualityHigh"><span>High</span><span class="sub" id="highSub">Q8 not installed</span></button>
+ <div class="pill-group cols-3 quality-row" id="qualityGroup">
+ <button type="button" class="pill-btn pill-quality" data-quality="quick">
+ <span class="ql-name">Quick</span>
+ <span class="sub ql-spec">640×480 · ~2 min</span>
+ <span class="ql-tier">Q4 · any Mac</span>
+ </button>
+ <button type="button" class="pill-btn pill-quality active" data-quality="standard">
+ <span class="ql-name">Standard</span>
+ <span class="sub ql-spec">1280×704 · ~7 min</span>
+ <span class="ql-tier">Q4 · standard tier+</span>
+ </button>
+ <button type="button" class="pill-btn pill-quality disabled" data-quality="high" id="qualityHigh">
+ <span class="ql-name">High</span>
+ <span class="sub ql-spec" id="highSpec">1280×704 · ~12 min</span>
+ <span class="ql-tier" id="highSub">Q8 not installed</span>
+ </button>
</div>
<input type="hidden" name="quality" id="quality" value="standard">
-
- <h2>Speed</h2>
- <div class="pill-group cols-3" id="accelGroup">
- <button type="button" class="pill-btn active" data-accel="off"><span>Exact</span><span class="sub">full sampler</span></button>
- <button type="button" class="pill-btn" data-accel="boost"><span>Boost</span><span class="sub">faster · conservative</span></button>
- <button type="button" class="pill-btn" data-accel="turbo"><span>Turbo</span><span class="sub">fastest · experimental</span></button>
- </div>
<input type="hidden" name="accel" id="accel" value="off">
<div id="warnBanner" class="warn-banner"></div>
@@ -5216,22 +5327,56 @@ HTML = r"""<!doctype html>
</label>
</details>
- <!-- Sizing for non-extend modes -->
+ <!-- Sizing for non-extend modes. The headline Quality picker above
+ sets sensible defaults; this disclosure lets power users override
+ aspect, exact dimensions, and the experimental sampler speed. -->
<div class="mode-only" id="sizingSection">
- <h2>Aspect</h2>
- <div class="pill-group cols-2" id="aspectGroup">
- <button type="button" class="pill-btn active" data-aspect="landscape"><span>16 : 9</span><span class="sub">horizontal</span></button>
- <button type="button" class="pill-btn" data-aspect="vertical"><span>9 : 16</span><span class="sub">vertical</span></button>
- </div>
- <input type="hidden" id="aspect" value="landscape">
-
- <!-- Manual W/H fields only shown in T2V (where they're the primary
- control). In image flows they're auto-set from aspect + quality
- so the input image drives the framing without surprise crops. -->
- <div id="dimsRow" class="row" style="margin-top:10px">
- <div><label class="lbl">Width</label><input name="width" id="width" value="1280" type="number" min="32" step="32"></div>
- <div><label class="lbl">Height</label><input name="height" id="height" value="704" type="number" min="32" step="32"></div>
- </div>
+ <details id="customizeDetails" class="customize-section">
+ <summary class="cz-summary">
+ <span class="cz-chevron" aria-hidden="true">▾</span>
+ <span class="cz-title">Customize</span>
+ <span class="cz-meta" id="customizeSummary">16:9 · default speed</span>
+ </summary>
+ <div class="cz-body">
+ <!-- Aspect — only relevant when the active Quality preset has
+ multiple aspects (Standard / High at 1280×704 vs 704×1280).
+ Hidden when Quick is active (640×480 is 4:3 only). -->
+ <div id="aspectRow" class="cz-control">
+ <div class="cz-label">Aspect ratio</div>
+ <div class="pill-group cols-2" id="aspectGroup">
+ <button type="button" class="pill-btn active" data-aspect="landscape"><span>16 : 9</span><span class="sub">horizontal</span></button>
+ <button type="button" class="pill-btn" data-aspect="vertical"><span>9 : 16</span><span class="sub">vertical</span></button>
+ </div>
+ <input type="hidden" id="aspect" value="landscape">
+ </div>
+
+ <!-- Width × height. Setting custom dimensions makes the form
+ leave the active preset (the Quality pill stays highlighted
+ but the Customize summary shows "custom" so the user knows
+ they've deviated). -->
+ <div id="dimsRow" class="cz-control">
+ <div class="cz-label">Width × height</div>
+ <div class="row">
+ <div><input name="width" id="width" value="1280" type="number" min="32" step="32" aria-label="Width"></div>
+ <div><input name="height" id="height" value="704" type="number" min="32" step="32" aria-label="Height"></div>
+ </div>
+ </div>
+
+ <!-- Speed — experimental sampler acceleration. Boost/Turbo
+ skip 2-3 stable middle denoise calls. Off at High quality
+ (the two-stage HQ sampler doesn't support skipping). -->
+ <div class="cz-control">
+ <div class="cz-label">Speed
+ <span class="cz-label-hint">experimental — skip stable denoise steps</span>
+ </div>
+ <div class="pill-group cols-3" id="accelGroup">
+ <button type="button" class="pill-btn active" data-accel="off"><span>Exact</span><span class="sub">full sampler</span></button>
+ <button type="button" class="pill-btn" data-accel="boost"><span>Boost</span><span class="sub">~10-15% faster</span></button>
+ <button type="button" class="pill-btn" data-accel="turbo"><span>Turbo</span><span class="sub">~20-25% faster</span></button>
+ </div>
+ </div>
+ </div>
+ </details>
<div class="row3" style="margin-top:10px">
<div><label class="lbl">Duration (s)</label><input id="duration" value="5" type="number" min="1" max="20" step="1"></div>
@@ -5621,11 +5766,37 @@ function setMode(mode) {
// the next 1.5s poll tick.
if (LAST_STATUS) updateModelsCard(LAST_STATUS);
}
+// Quality presets (Y1.013) — each one bundles the backend quality value
+// (which selects the model + sampler) with the canonical dimensions.
+// Backend still routes only on `quality == 'high'` vs anything else, so
+// 'quick' and 'standard' both run Q4 distilled — they just differ in
+// pixel count. The richer label is preserved in the sidecar so the
+// info modal can show "Quick" / "Standard" / "High" verbatim.
+const QUALITY_PRESETS = {
+ quick: { w: 640, h: 480 }, // 4:3, ~3× fewer pixels than standard
+ standard: { w: 1280, h: 704 }, // 16:9 default, the canonical render
+ high: { w: 1280, h: 704 }, // same dims, different model (Q8)
+};
+
function setQuality(q) {
+ // Tolerate legacy values from old sidecars: 'draft' → 'standard'.
+ if (q === 'draft' || !QUALITY_PRESETS[q]) q = 'standard';
document.getElementById('quality').value = q;
document.querySelectorAll('#qualityGroup .pill-btn').forEach(b => b.classList.toggle('active', b.dataset.quality === q));
+ // Set canonical dimensions for the preset, respecting the current
+ // aspect choice. Quick is 4:3 only — landscape orientation only.
+ const preset = QUALITY_PRESETS[q];
+ const aspect = document.getElementById('aspect').value || 'landscape';
+ const vertical = (aspect === 'vertical' && q !== 'quick');
+ document.getElementById('width').value = vertical ? preset.h : preset.w;
+ document.getElementById('height').value = vertical ? preset.w : preset.h;
+ // Hide the Aspect row when Quick is active (only 4:3 supported); show
+ // it for Standard/High where 16:9 vs 9:16 is a real choice.
+ const aspectRow = document.getElementById('aspectRow');
+ if (aspectRow) aspectRow.style.display = (q === 'quick') ? 'none' : '';
applyQuality();
updateAccelAvailability();
+ updateCustomizeSummary();
if (LAST_STATUS) updateModelsCard(LAST_STATUS);
}
function setAccel(a) {
@@ -5633,6 +5804,7 @@ function setAccel(a) {
const v = allowed ? a : 'off';
document.getElementById('accel').value = v;
document.querySelectorAll('#accelGroup .pill-btn').forEach(b => b.classList.toggle('active', b.dataset.accel === v));
+ updateCustomizeSummary();
updateDerived();
}
function updateAccelAvailability() {
@@ -5644,10 +5816,38 @@ function updateAccelAvailability() {
if (!allowed && document.getElementById('accel').value !== 'off') setAccel('off');
}
function setAspect(a) {
+ if (!ASPECTS[a]) return;
document.getElementById('aspect').value = a;
document.querySelectorAll('#aspectGroup .pill-btn').forEach(b => b.classList.toggle('active', b.dataset.aspect === a));
applyAspect(a);
}
+
+// Compose the right-aligned line in the Customize summary. Reflects the
+// current effective state: aspect, custom-dims callout, speed setting.
+function updateCustomizeSummary() {
+ const el = document.getElementById('customizeSummary');
+ if (!el) return;
+ const q = document.getElementById('quality').value;
+ const w = parseInt(document.getElementById('width').value || 0);
+ const h = parseInt(document.getElementById('height').value || 0);
+ const aspect = document.getElementById('aspect').value || 'landscape';
+ const accel = document.getElementById('accel').value || 'off';
+ const parts = [];
+ // Aspect (Quick is fixed 4:3, no choice; Standard/High show landscape/vertical).
+ if (q === 'quick') parts.push('4:3 · 640×480');
+ else parts.push(aspect === 'vertical' ? '9:16' : '16:9');
+ // Flag custom dims if they don't match the preset.
+ const preset = QUALITY_PRESETS[q] || QUALITY_PRESETS['standard'];
+ const vertical = (aspect === 'vertical' && q !== 'quick');
+ const expectedW = vertical ? preset.h : preset.w;
+ const expectedH = vertical ? preset.w : preset.h;
+ if (q !== 'quick' && (w !== expectedW || h !== expectedH)) {
+ parts.push(`${w}×${h} custom`);
+ }
+ // Speed
+ parts.push(accel === 'off' ? 'exact speed' : (accel === 'boost' ? 'boost' : 'turbo'));
+ el.textContent = parts.join(' · ');
+}
function setExtendMode(m) {
// Fast = no-CFG path, fits in 64 GB at 1280×704. Quality = upstream
// defaults, requires headroom. Both are exposed on the form via hidden
@@ -5727,31 +5927,31 @@ document.getElementById('i2vMode').addEventListener('change', () => {
function applyAspect(key) {
if (!ASPECTS[key]) return;
document.getElementById('aspect').value = key;
- // Defer the actual sizing to applyQuality — it reads aspect + quality and
- // picks half-size (Draft) or full-size (Standard/High) of the chosen aspect.
- applyQuality();
+ // Aspect controls dimensions only when the active preset has a choice
+ // (Standard / High at 1280×704 vs 704×1280). Quick is fixed 4:3 and
+ // ignores the aspect picker (the row is hidden in that state, so this
+ // path normally won't fire — defensive in case of programmatic calls).
+ const q = document.getElementById('quality').value;
+ if (q === 'quick') return;
+ const preset = QUALITY_PRESETS[q] || QUALITY_PRESETS['standard'];
+ const vertical = (key === 'vertical');
+ document.getElementById('width').value = vertical ? preset.h : preset.w;
+ document.getElementById('height').value = vertical ? preset.w : preset.h;
+ updateCustomizeSummary();
+ updateDerived();
}
+// applyQuality is kept as a tiny shim — old call sites (mode switching,
+// etc.) call it expecting "set steps for the active quality." The
+// dimensions are now owned by setQuality / applyAspect.
function applyQuality() {
const q = document.getElementById('quality').value;
- if (q === 'draft' || q === 'standard') {
- document.getElementById('steps').value = 8;
- } else if (q === 'high') {
+ if (q === 'high') {
document.getElementById('steps').value = 18;
+ } else {
+ document.getElementById('steps').value = 8; // quick + standard
}
- // Draft and Standard both keep the same aspect ratio. Draft halves each
- // dimension (1280×704 → 640×352 for 16:9; 704×1280 → 352×640 for 9:16).
- // Same ratio, ~25% the pixel count, ~3× faster — a real preview of the
- // final shot at draft cost. Standard restores full size.
- const aspect = document.getElementById('aspect').value || 'landscape';
- const a = ASPECTS[aspect] || ASPECTS.landscape;
- if (q === 'draft') {
- document.getElementById('width').value = Math.round(a.w / 2 / 32) * 32;
- document.getElementById('height').value = Math.round(a.h / 2 / 32) * 32;
- } else if (q === 'standard' || q === 'high') {
- document.getElementById('width').value = a.w;
- document.getElementById('height').value = a.h;
- }
+ updateCustomizeSummary();
updateDerived();
}
@@ -5844,7 +6044,9 @@ function updateDerived() {
el.addEventListener('input', e => { document.getElementById('duration').value = framesToDuration(parseInt(e.target.value) || 0); updateDerived(); });
el.addEventListener('blur', () => { snapFramesTo8kPlus1(); updateDerived(); });
} else {
- el.addEventListener('input', updateDerived);
+ // width / height: also refresh the Customize summary so "custom" flags
+ // appear/disappear as the user types away from the preset values.
+ el.addEventListener('input', () => { updateCustomizeSummary(); updateDerived(); });
}
});
// Picker hidden inputs no longer take user input — their value changes
@@ -6382,11 +6584,22 @@ async function loadParams() {
else if (p.mode === 'keyframe') setMode('keyframe');
else if (p.mode === 'i2v_clean_audio' || p.mode === 'i2v') { setMode('i2v'); document.getElementById('i2vMode').value = p.mode; document.getElementById('mode').value = p.mode; }
else setMode('t2v');
+ // Apply quality + aspect FIRST (these stomp on width/height), then
+ // override with explicit sidecar values so any custom dims survive.
if (p.quality) setQuality(p.quality);
- if (p.accel) setAccel(p.accel);
- document.getElementById('prompt').value = p.prompt || '';
+ // Snap aspect from the sidecar's recorded dims; only call when quality
+ // isn't 'quick' (Quick has no aspect choice and the row is hidden).
+ if (p.quality !== 'quick' && p.width && p.height) {
+ for (const [k, a] of Object.entries(ASPECTS)) {
+ if ((a.w === p.width && a.h === p.height) ||
+ (a.h === p.width && a.w === p.height)) { setAspect(k); break; }
+ }
+ }
+ // Now load explicit dims — overrides whatever the preset/aspect set.
if (p.width) document.getElementById('width').value = p.width;
if (p.height) document.getElementById('height').value = p.height;
+ if (p.accel) setAccel(p.accel);
+ document.getElementById('prompt').value = p.prompt || '';
if (p.frames) { document.getElementById('frames').value = p.frames; document.getElementById('duration').value = framesToDuration(p.frames); }
if (p.steps) document.getElementById('steps').value = p.steps;
if (p.seed != null) document.getElementById('seed').value = p.seed;
@@ -6399,9 +6612,7 @@ async function loadParams() {
// Extend-specific: restore source video path
if (p.video_path) document.getElementById('video_path').value = p.video_path;
if (p.label) document.getElementById('preset_label').value = p.label;
- for (const [k, a] of Object.entries(ASPECTS)) {
- if (a.w === p.width && a.h === p.height) { setAspect(k); break; }
- }
+ updateCustomizeSummary();
updateDerived();
}
@@ -8079,8 +8290,9 @@ setInterval(refreshVersionPill, 5 * 60 * 1000);
setInterval(poll, 1500);
poll();
setMode('t2v');
-setQuality('standard');
-setAspect('landscape');
+setAspect('landscape'); // sets aspect first so Standard preset orients correctly
+setQuality('standard'); // bundles quality + dims; respects current aspect
+updateCustomizeSummary();
updateDerived();
// Wire the picker components (I2V image + FFLF start/end) and seed the
diff --git a/mlx_warm_helper.py b/mlx_warm_helper.py
index 3dc752f..45d3299 100644
--- a/mlx_warm_helper.py
+++ b/mlx_warm_helper.py
@@ -493,6 +493,183 @@ def cover_crop_to_size(src_path: str, w: int, h: int) -> str:
return out_path
+# ---- one-stage acceleration --------------------------------------------------
+# Experimental but useful: standard Q4 T2V/I2V spends most wall time inside the
+# denoise loop's X0Model call. The "boost" and "turbo" modes below reuse the
+# previous x0 prediction for 2 or 3 locally-stable middle steps. This is opt-in
+# per job; "off" restores the upstream sampler exactly.
+_ORIGINAL_DENOISE_LOOP = None
+_CURRENT_ACCEL_MODE = None
+
+
+def _scalar(x) -> float:
+ import mlx.core as mx
+
+ mx.eval(x)
+ return float(x)
+
+
+def _relative_mae(mx, current, previous) -> float:
+ if current is None or previous is None:
+ return 999.0
+ diff = mx.mean(mx.abs(current - previous))
+ base = mx.maximum(mx.mean(mx.abs(previous)), 1e-6)
+ return _scalar(diff / base)
+
+
+def _build_adaptive_x0_loop(max_skips: int, video_thresh: float, audio_thresh: float):
+ import mlx.core as mx
+ import ltx_pipelines_mlx.utils.samplers as samplers
+
+ def denoise_loop_adaptive_x0(
+ model,
+ video_state,
+ audio_state,
+ video_text_embeds,
+ audio_text_embeds,
+ sigmas=None,
+ video_positions=None,
+ audio_positions=None,
+ video_attention_mask=None,
+ audio_attention_mask=None,
+ show_progress=True,
+ ):
+ if sigmas is None:
+ sigmas = samplers.DISTILLED_SIGMAS
+
+ if video_positions is None and video_state.positions is not None:
+ video_positions = video_state.positions
+ if audio_positions is None and audio_state.positions is not None:
+ audio_positions = audio_state.positions
+ if video_attention_mask is None and video_state.attention_mask is not None:
+ video_attention_mask = video_state.attention_mask
+ if audio_attention_mask is None and audio_state.attention_mask is not None:
+ audio_attention_mask = audio_state.attention_mask
+
+ video_x = video_state.latent
+ audio_x = audio_state.latent
+ steps = list(zip(sigmas[:-1], sigmas[1:]))
+ iterator = samplers.tqdm(steps, desc="Denoising", disable=not show_progress)
+
+ video_uniform = samplers._is_uniform_mask(video_state.denoise_mask)
+ audio_uniform = samplers._is_uniform_mask(audio_state.denoise_mask)
+ last_video_latent = None
+ last_audio_latent = None
+ last_video_x0 = None
+ last_audio_x0 = None
+ skip_count = 0
+
+ for idx, (sigma, sigma_next) in enumerate(iterator):
+ sigma_arr = mx.array([sigma], dtype=mx.bfloat16)
+ batch = video_x.shape[0]
+ protected = idx <= 1 or idx >= len(steps) - 2
+ v_delta = _relative_mae(mx, video_x, last_video_latent)
+ a_delta = _relative_mae(mx, audio_x, last_audio_latent)
+ can_skip = (
+ not protected
+ and skip_count < max_skips
+ and last_video_x0 is not None
+ and last_audio_x0 is not None
+ and v_delta <= video_thresh
+ and a_delta <= audio_thresh
+ )
+
+ if can_skip:
+ skip_count += 1
+ video_x0, audio_x0 = last_video_x0, last_audio_x0
+ emit({
+ "event": "log",
+ "line": (
+ "accel:adaptive_x0 "
+ f"step={idx} decision=cached "
+ f"v_delta={v_delta:.5f} a_delta={a_delta:.5f} skips={skip_count}"
+ ),
+ })
+ else:
+ call_kwargs = dict(
+ video_latent=video_x,
+ audio_latent=audio_x,
+ sigma=mx.broadcast_to(sigma_arr, (batch,)),
+ video_text_embeds=video_text_embeds,
+ audio_text_embeds=audio_text_embeds,
+ video_positions=video_positions,
+ audio_positions=audio_positions,
+ video_attention_mask=video_attention_mask,
+ audio_attention_mask=audio_attention_mask,
+ )
+ if not video_uniform:
+ call_kwargs["video_timesteps"] = samplers._compute_per_token_timesteps(
+ sigma,
+ video_state.denoise_mask,
+ )
+ if not audio_uniform:
+ call_kwargs["audio_timesteps"] = samplers._compute_per_token_timesteps(
+ sigma,
+ audio_state.denoise_mask,
+ )
+ video_x0, audio_x0 = model(**call_kwargs)
+ last_video_x0, last_audio_x0 = video_x0, audio_x0
+ last_video_latent, last_audio_latent = video_x, audio_x
+ emit({
+ "event": "log",
+ "line": (
+ "accel:adaptive_x0 "
+ f"step={idx} decision=full "
+ f"v_delta={v_delta:.5f} a_delta={a_delta:.5f} skips={skip_count}"
+ ),
+ })
+
+ video_x0 = samplers.apply_denoise_mask(video_x0, video_state.clean_latent, video_state.denoise_mask)
+ audio_x0 = samplers.apply_denoise_mask(audio_x0, audio_state.clean_latent, audio_state.denoise_mask)
+ video_x = samplers.euler_step(video_x, video_x0, sigma, sigma_next)
+ audio_x = samplers.euler_step(audio_x, audio_x0, sigma, sigma_next)
+ mx.async_eval(video_x, audio_x)
+
+ samplers.aggressive_cleanup()
+ return samplers.DenoiseOutput(video_latent=video_x, audio_latent=audio_x)
+
+ return denoise_loop_adaptive_x0
+
+
+def configure_acceleration(mode: str) -> str:
+ """Configure the one-stage sampler acceleration mode for this helper.
+
+ mode: off | boost | turbo
+ boost: skip at most 2 stable middle X0Model calls.
+ turbo: skip at most 3 stable middle X0Model calls.
+ """
+ global _ORIGINAL_DENOISE_LOOP, _CURRENT_ACCEL_MODE
+
+ requested = (mode or "off").strip().lower()
+ if requested not in {"off", "boost", "turbo"}:
+ requested = "off"
+
+ import ltx_pipelines_mlx.ti2vid_one_stage as ti2vid
+ import ltx_pipelines_mlx.utils.samplers as samplers
+
+ if _ORIGINAL_DENOISE_LOOP is None:
+ _ORIGINAL_DENOISE_LOOP = samplers.denoise_loop
+
+ if requested == _CURRENT_ACCEL_MODE:
+ return requested
+
+ if requested == "off":
+ samplers.denoise_loop = _ORIGINAL_DENOISE_LOOP
+ ti2vid.denoise_loop = _ORIGINAL_DENOISE_LOOP
+ elif requested == "boost":
+ loop = _build_adaptive_x0_loop(max_skips=2, video_thresh=0.02, audio_thresh=0.02)
+ samplers.denoise_loop = loop
+ ti2vid.denoise_loop = loop
+ else:
+ loop = _build_adaptive_x0_loop(max_skips=3, video_thresh=0.03, audio_thresh=0.03)
+ samplers.denoise_loop = loop
+ ti2vid.denoise_loop = loop
+
+ _CURRENT_ACCEL_MODE = requested
+ emit({"event": "log", "line": f"accel:mode {requested}"})
+ return requested
+
+
# ---- ready -------------------------------------------------------------------
emit({
"event": "ready",
@@ -561,6 +738,7 @@ for line in sys.__stdin__:
"line": f"step:get_pipe kind={('i2v' if needs_image else 't2v')}"})
pipe = get_pipe("i2v" if needs_image else "t2v", loras=loras)
emit({"event": "log", "line": "step:get_pipe done"})
+ accel_mode = configure_acceleration(p.get("accel", "off"))
kwargs = dict(
prompt=p["prompt"],
@@ -590,7 +768,7 @@ for line in sys.__stdin__:
else:
kwargs["image"] = None
- emit({"event": "log", "line": f"step:generate_and_save mode={mode} {kwargs['width']}x{kwargs['height']} {kwargs['num_frames']}f steps={kwargs['num_steps']}"})
+ emit({"event": "log", "line": f"step:generate_and_save mode={mode} {kwargs['width']}x{kwargs['height']} {kwargs['num_frames']}f steps={kwargs['num_steps']} accel={accel_mode}"})
out_path = pipe.generate_and_save(**kwargs)
emit({"event": "log", "line": "step:generate_and_save done"})
elapsed = round(time.time() - t0, 2)
@@ -604,6 +782,10 @@ for line in sys.__stdin__:
_last_activity = time.time()
emit({"event": "error", "id": job_id, "error": str(exc), "trace": traceback.format_exc()})
finally:
+ try:
+ configure_acceleration("off")
+ except Exception:
+ pass
_is_busy = False
continue
@@ -616,6 +798,7 @@ for line in sys.__stdin__:
_is_busy = True
try:
t0 = time.time()
+ configure_acceleration("off")
# Extend supports LoRAs via the same _pending_loras hook;
# the dev transformer picks them up at load time just like T2V/I2V.
loras = p.get("loras") or []
@@ -674,6 +857,7 @@ for line in sys.__stdin__:
_is_busy = True
try:
t0 = time.time()
+ configure_acceleration("off")
pipe = get_hq_pipe(model_dir)
kwargs = dict(
prompt=p["prompt"],
@@ -725,6 +909,7 @@ for line in sys.__stdin__:
_is_busy = True
try:
t0 = time.time()
+ configure_acceleration("off")
for k in ("start_image", "end_image"):
img = p.get(k)
if not img or not os.path.exists(img):