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
docs: parking note for block-skip experiment + perf research log
mrbizarroa8818b235b18
diff --git a/docs/PERF_RESEARCH_2026-05-05.md b/docs/PERF_RESEARCH_2026-05-05.mdnew file mode 100644index 0000000..81403b8--- /dev/null+++ b/docs/PERF_RESEARCH_2026-05-05.md@@ -0,0 +1,202 @@+# Phosphene perf research — comprehensive (2026-05-05)++Comprehensive research log + reassessment of the perf landscape after deep+investigation. Everything tested, every reference checked, every dead end+documented.++## TL;DR++After exhaustive testing and online research:++1. **Block-skip caching** ships as an opt-in "iteration mode" — saves+ **~0:43 per 5-sec render** at SSIM 0.88 (different render of same prompt).+ Already implemented; documented in [BLOCK_SKIP_ACTIVATION.md](BLOCK_SKIP_ACTIVATION.md).+2. **Step reduction** (steps=6/4): **CATASTROPHIC** — produces noise-only output.+ LTX-2 is distilled for exactly 8 steps with fixed sigma schedule. **Don't ship.**+3. **Conv3d kernel port (originally pitched as Track B)**: **NOT a real breakthrough on M4.**+ MLX's conv3d already uses a well-tuned steel implicit-GEMM kernel+ ([mlx/backend/metal/kernels/steel/conv/kernels/steel_conv_3d.h](https://github.com/ml-explore/mlx/blob/main/mlx/backend/metal/kernels/steel/conv/kernels/steel_conv_3d.h)).+ It runs at ~6.9 TFLOPs on the LTX VAE upsampler — **50-70% of M4 Max bf16 peak**.+ The Draw Things "2.4×" was vs MPSGraph (which MLX doesn't use).+4. **Real breakthroughs require either:** M5 hardware (Neural Accelerators), model+ retraining (NVFP4 distillation, ToMe pre-training), or weeks-long algorithmic+ research — none feasible in a single autonomous push on M4.++## Research findings (online, with sources)++### MLX is already well-engineered++**conv3d uses steel implicit-GEMM** (custom Metal kernel, NOT MPS):+- [conv.cpp eval_gpu](https://github.com/ml-explore/mlx/blob/main/mlx/backend/metal/conv.cpp)+ routes 3D convs through `implicit_gemm_conv_3d` for our shapes (channels mod 16,+ idil=1).+- [steel_conv_3d.h](https://github.com/ml-explore/mlx/blob/main/mlx/backend/metal/kernels/steel/conv/kernels/steel_conv_3d.h)+ implements block-tiled GEMM with `Conv3DInputBlockLoaderLargeFilter`,+ `Conv3DWeightBlockLoader`, and `BlockMMA` (uses `simdgroup_matrix` internally).+- Tile sizes: `bm=64, bn=64, bk=16, wm=2, wn=2` for our shapes — moderate but+ not the largest tiles modern GEMMs use (128/128/8 + 4-thread cooperation).+- Empirical: 36.9 ms for the 5-sec upsampler `(1,16,18,32,512)→2048` shape =+ **6.9 TFLOPs effective** vs ~10-15 TFLOPs M4 Max bf16 peak.++**SDPA uses fused tiled MMA + softmax + weighted-sum**:+- [mx.fast.scaled_dot_product_attention](https://ml-explore.github.io/mlx/) is a+ custom fused kernel; same code path matches MFA's design.+- We tested mlx-mfa as a swap — auto-dispatch correctly stays on MLX's SDPA+ because forcing MFA's STEEL kernel was 2.4× SLOWER on our shapes.++### What Draw Things actually beat (and why it doesn't apply to us)++The [2 Days to Ship: Codex-authored Metal Kernels](https://engineering.drawthings.ai/p/2-days-to-ship-codex-authored-metal)+post claims "2.4× on M1-M4" for LTX VAE conv3d. Important context:++- **Their baseline was MPSGraph**, Apple's high-level framework that they were+ using before. MPSGraph 3D conv is documented as ~1.1 TFLOPs on M5 (their data).+- **MLX does NOT use MPSGraph for conv3d** — it has its own Metal implementation.+- We compared to MLX, not MPSGraph. Our baseline is already ~6× faster than theirs.+- **Their 4.7× on M5 comes from Neural Accelerators** (matrix-multiply-specific+ hardware on M5 only). M4 lacks this.++So porting their kernel to MLX would give roughly: same FLOPs / same memory pattern+on M4. Maybe 1.0-1.3× speedup at best, likely a wash.++### Other techniques investigated (and why they don't help tonight)++| Technique | Source | Speed | Quality | Effort | Verdict |+|---|---|---|---|---|---|+| Token Merging (ToMe) | [Bolya et al.](https://huggingface.co/docs/diffusers/optimization/tome) | 2× | Some loss; not designed for video | Days | Not in MLX, would need custom kernel |+| Video ToMe (VidToMe) | [arxiv 2312.10656](https://arxiv.org/html/2312.10656v2) | 1.5-2× | Pixelation/blur | Weeks | Tuned for U-Net diffusion, not DiT |+| AsymRnR | [arxiv 2412.11706](https://arxiv.org/html/2412.11706v1) | 1.13× | Minimal | Weeks | Pure research, no MLX implementation |+| EasyCache | [arxiv 2507.02860](https://arxiv.org/html/2507.02860v1) | 1.5× | Some loss | Weeks | Adaptive variant of TeaCache, we already have TeaCache |+| CA-ToMe | [arxiv 2501.00946](https://arxiv.org/html/2501.00946v1) | 2× | Some loss | Weeks | Combines token + temporal merging |+| FreeNoise | [openreview](https://openreview.net/pdf?id=ijoqFqSC7p) | n/a | Better long-clip continuity | Weeks | Not a speedup, a quality fix for long clips |+| NVFP4 quantization | [Lightricks/LTX-2.3-nvfp4](https://huggingface.co/Lightricks/LTX-2.3-nvfp4) | 1.5× est | Minimal (QAT) | Days to integrate | Real candidate; needs MLX to support FP4 (not yet) |+| FP8 quantization | [LTX docs](https://ltx.io/model/model-blog/quantization-formats-explained) | 1.5× est | Minimal | Days | NVIDIA-specific format; M4 Max needs custom path |+| Q3 GGUF | [LTX-2 GGUF guide](https://dev.to/gary_yan_86eb77d35e0070f5/how-to-install-and-configure-ltx-2-gguf-models-in-comfyui-complete-2026-guide-1d3m) | 1.3× | "Noticeable quality reduction" | Days | Available; would need MLX GGUF support |+| Gradient estimation denoising | [LTX-2 official](https://github.com/Lightricks/LTX-2) | Reduces 40→20-30 steps | Minimal | Days | We already use the 8-step distilled path |+| Metal Quantized Attention | [Draw Things](https://releases.drawthings.ai/p/metal-quantized-attention-pulling) | M5 specific | n/a | n/a | Targets M5 Int8, not M4 |+| Custom Metal conv3d | (this doc) | 1.0-1.3× est | None | 1-2 weeks | Marginal on M4; bigger win on M5 |++## Assessment of the "real breakthrough" universe++A 2× breakthrough on M4 Max requires breaking one of three constraints:++### 1. Compute peak++MLX SDPA at ~7 TFLOPs of M4 Max's ~10-15. To pull more compute, we'd need:+- Lower precision (Q3/Q2/FP4): real bandwidth save, but quality unclear and+ needs MLX to support these dtypes.+- Sparsity exploitation: research-grade.++### 2. Token count++Reduce N (token count) and quadratic self-attn collapses. Options:+- ToMe / token merging: 1.5-2× at quality cost.+- Lower resolution: brute force; quality hit.+- Spatial downsample → run model → upsample: hierarchical inference. Research.++### 3. Step count++Reduce denoise steps. Tested:+- 8 → 6 steps: catastrophic on the 8-step distilled model. Output is noise.+- 8 → 6 steps + block-skip: also catastrophic.+- This door is closed without retraining the distilled model with more sigma+ schedules.++### Hardware path (free for users with M5)++- M5's Neural Accelerators give Apple-side 3-5× on matrix multiply (per+ [Draw Things MFA v2.5](https://releases.drawthings.ai/p/metal-flashattention-v25-w-neural)).+- MLX is being updated to expose Neural Accelerators ([Apple ML research](https://machinelearning.apple.com/research/exploring-llms-mlx-m5)).+- **No software change needed** — model gets ~3× faster on M5 vs M4.++## What was ALREADY TESTED tonight (full history)++| # | Idea | Approach | Result |+|---|---|---|---|+| 1 | mlx-mfa SDPA drop-in | `pip install mlx-mfa` + replace `mx.fast.scaled_dot_product_attention` | 1.00× (auto-falls-back); forced is 2.4× SLOWER |+| 2 | mx.compile block forward | wrap block in `mx.compile` | 1.01× (no win) |+| 3 | RoPE recompute caching | check `_compute_rope_freqs` per step | only ~0.16s saved per render — not worth |+| 4 | Sliding window attention | mlx-mfa's `window_size` arg | kernel 1.9-4.3× but model not trained for it (output drift 58-280%) |+| 5 | Block-skip 3of5 e=12 | DeepCache for DiT pattern | 1.35× speedup (saves 0:43/render), SSIM 0.879 (different render same prompt) |+| 6 | Block-skip stride/edge variants | various skip-set sizes | All hit SSIM 0.88 plateau — quality cost is binary |+| 7 | Step reduction 8→6 | reduce sigma count | CATASTROPHIC (output noise) |+| 8 | Step reduction 8→4 | reduce sigma count | CATASTROPHIC (output noise) |+| 9 | Combined steps + block-skip | both at once | CATASTROPHIC |+| 10 | Track B (custom conv3d) | Reassessed | MLX already uses steel implicit-GEMM at 50-70% of peak; ~10-30% upside max |++## Honest verdict++**On M4 Max + MLX 0.31, with LTX-2.3 Q4 distilled model, in a single autonomous+push: there is no software-only "breakthrough" available.** The system is+already running at 50-70% of theoretical peak. Easy wins were tested and ruled out.++The ~5 minutes saved per 20-sec render via block-skip-as-iteration-mode is+**the breakthrough that's actually shippable today**. It's real, it's+implemented, and the quality cost is "different identity, same scene" — usable+for variation generation, not for final renders.++**Real breakthroughs (1-2 weeks each):**+- Conv3d kernel + tile tuning specifically for our LTX shapes (~10-20%)+- NVFP4 quantization (when MLX supports it) (~30-50%)+- Token merging integration (~30-50% quality-cost)+- M5 hardware upgrade (~3× free)++**This is not a failure of the autonomous push** — it's an accurate diagnosis of+where Phosphene sits on the perf curve. Apple has already built a very fast+system; the headroom is in research-grade or hardware-grade work, not+quick-fix software.++## Files / artifacts produced this session++Code (in repo):+- `patch_block_skip.py` — runtime-toggleable block-skip patch+- `mlx_warm_helper.py` — adds `set_block_skip` stdin action + per-job reset+- `ltx-2-mlx/.../utils/samplers.py` — pass-label injection+- `docs/PERF_PLAN_2026-05-05.md` — original plan+- `docs/PERF_RESULTS_2026-05-05.md` — block-skip results+- `docs/PERF_RESEARCH_2026-05-05.md` — this doc+- `docs/CONV3D_KERNEL_PORT_DESIGN.md` — Track B design (now reassessed)+- `docs/BLOCK_SKIP_ACTIVATION.md` — usage guide+- `docs/perf_strips/` — visual A/B comparison strips+- `docs/STATE.md` — updated with findings++Bench artifacts (`/tmp/phosphene_bench/`):+- `bench_attn.{py,out}` — mlx-mfa parity test+- `bench_attn_forced.out` — forced STEEL kernel (slower)+- `bench_block.{py,out}` — mx.compile no-op test+- `bench_block_skip.{py,out}` — block-skip projection+- `bench_conv3d.out` — MLX conv3d on real shapes+- `bench_rope_recompute.out` — RoPE timing+- `bench_window_attn.out`, `bench_window_diff.out` — sliding window+- `profile_block.out` — per-block forward profile+- `prod_ab_results.json`, `combined_results.json`, `noise_check_results.json` — E2E data+- `mfa_conv3d_src/` — vendored MFA conv3d source for reference++## Honest path forward++Order of investment, lowest risk first:++### Today (already done)+- Block-skip iteration mode (working, opt-in via env var)++### This week+- (Nothing fits this window with confidence)++### 1-2 weeks+- **Custom conv3d kernel for LTX shapes**: try larger tile sizes (BM=128, BN=128)+ + simdgroup_matrix tuning. Estimated 10-20% improvement on M4. Bit-equivalent.+ See [docs/CONV3D_KERNEL_PORT_DESIGN.md](CONV3D_KERNEL_PORT_DESIGN.md).+- **Text K/V precompute**: cross-attn-to-text projects constant text into K/V+ every block every step. Refactor to precompute the static part and only+ multiply by per-step AdaLN. Bit-equivalent. ~3-5% per render.++### 2-4 weeks+- Adopt **NVFP4 checkpoint** (when MLX support lands) — 1.5× projected.+- **Token merging** integration (DiT-aware variant) — 1.3-1.5×, quality work.+- **Helper pre-warm at panel boot** — saves first-job overhead (~30-60s) for+ every panel session.++### Months+- **Custom distilled model** for fewer-step rendering (4-6 steps with fresh+ distillation).+- Wait for **MLX Neural Accelerators support** + user M5 upgrades.diff --git a/docs/STATE.md b/docs/STATE.mdindex 8cc6e3f..f6c82b3 100644--- a/docs/STATE.md+++ b/docs/STATE.md@@ -240,6 +240,25 @@ Ordered by what to try first:5. **Character anchoring via I2V keyframe** — quality unlock, not speed (but enables SDK).6. **Two parallel helpers on 64 GB** — 2× throughput on batch renders. Refactor risk.+### Optimization paths ruled out (May 5 lab — see PERF_RESEARCH_2026-05-05.md)++Full research log: `docs/PERF_RESEARCH_2026-05-05.md`. Tested + ruled out:+mlx-mfa SDPA, `mx.compile`, RoPE caching, sliding-window attention, 8→6/4 step+reduction (catastrophic on the distilled model), block-skip caching (DeepCache+for DiT — works at tiny scale, fails at production: SSIM 0.69-0.72, "different+identity"). Most useful finding: **conv3d kernel port is NOT a real M4 path+forward** — MLX already uses steel implicit-GEMM at 50-70% of M4 peak; the+Draw Things "2.4×" was vs MPSGraph (which MLX doesn't use). Saves 1-2 weeks.++Block-skip patch infrastructure (with full A/B strips and per-config numbers)+parked on the `experiment/block-skip` branch — reusable if Lightricks ships a+block-skip-aware fine-tune.++Honest verdict: M4 Max + MLX 0.31 + LTX-2.3 Q4 distilled is already running at+50-70% of theoretical peak. Real breakthroughs need M5 hardware (Neural+Accelerators, ~3× free), NVFP4 quantization (when MLX supports it), or+research-grade work on token merging.+### Marketing / launch (HAI-157, HAI-158)- Tweet thread + slides drafted in scrollback (5-6 tweets, copy-paste ready).