From 93584fa973c15c72846afc44b57c56148bd3e74f Mon Sep 17 00:00:00 2001 From: cuijs2026 Date: Sun, 29 Nov 2026 00:46:26 +0800 Subject: [PATCH] =?UTF-8?q?Local=20fast2=20(=E6=9E=81=E9=80=9F=E6=A1=A3)?= =?UTF-8?q?=20Mac=20fixes:=20fast=20schedule=20cursor/hook=20+=20overlay?= =?UTF-8?q?=20activate=20in=20decode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LOCAL-FIXES.md | 41 +++++++++++++++++++++++++++ fixes-2026-11-28-fast2-mac.patch | 46 +++++++++++++++++++++++++++++++ freevideo_engine/macos_runtime.py | 8 ++++-- freevideo_engine/macos_stages.py | 2 ++ 4 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 LOCAL-FIXES.md create mode 100644 fixes-2026-11-28-fast2-mac.patch diff --git a/LOCAL-FIXES.md b/LOCAL-FIXES.md new file mode 100644 index 00000000..f84e9b5c --- /dev/null +++ b/LOCAL-FIXES.md @@ -0,0 +1,41 @@ +# Local patches — FreeVideo macOS fast2 (this checkout is NOT a clean upstream clone) + +**Original upstream source:** https://github.com/FlashML-org/FreeVideo (cloned 2026-11-28) +**Base commit:** `git rev-parse HEAD` at the time of this file +**Status:** 2 fixes to make fast2 mode (the "极速档" / Fastest mode) work on Apple Silicon. Originally un-patched; do **not** delete this file. + +## The two fixes (do not lose on upgrade) + +All fixes are in-place edits under `freevideo_engine/`. The exact diff is saved next to this README as `fixes-2026-11-28-fast2-mac.patch` — apply with `git apply` from this directory. + +1. `freevideo_engine/macos_runtime.py` + - Line ~280: `self.cursor = ScheduleCursor(times)` → `self.cursor = None if fast is not None else ScheduleCursor(times)` + - Line ~337: wrap the `register_forward_pre_hook(self.cursor.before, ...)` call in `if self.cursor is not None:` + - Line ~627: wrap `self.cursor.reset(...)` in `if self.cursor is not None:` + - Why: in fast2 mode the scheduler uses pi-H3's RAW_GRID `(.93, .56, 0.)`. Building the *default*-schedule cursor makes the sampled timestep mismatch ("The request changed the precomputed AdaLN schedule"). CUDA already keeps the cursor None in fast mode; this aligns the macOS runtime. + +2. `freevideo_engine/macos_stages.py` + - In the `phase == 'decode' and value.get('fast_tier') is not None:` branch, before `from .dwd_decode import pixels_to_file`: + ```python + from .macos_vdn import activate + activate() + ``` + - Why: the fast2 decode subprocess imports `src.inference.render` (VDN Mac overlay) at module import time. Without activate, it crashes with `ModuleNotFoundError: No module named 'src'`. + +## Upgrading + +`git pull` (or `git fetch && git merge` / `git rebase`) **keeps this README and the patch file** (untracked), but it **overwrites the two files with upstream versions** — wiping these fixes. + +Safe upgrade flow: +```bash +cd /Users/cuijs/ComfyUI/custom_nodes/FreeVideo +git stash # stash local modifications +git pull # bring upstream version +git stash pop # try to restore local fixes +# if the pop conflicts (likely): discard the stashed edits, apply the saved diff instead +git checkout -- freevideo_engine/macos_runtime.py freevideo_engine/macos_stages.py +git apply ./fixes-2026-11-28-fast2-mac.patch +``` +(If a future upstream release includes these fixes upstream, `git apply` will fail with "already applied" — then it's a no-op re-check, not a problem; see upstream release notes.) + +**Better long-term:** send a PR upstream with these two fixes (or ask the FreeVideo team). When upstream merges them, delete this README and patch file and drop the manual fixes. diff --git a/fixes-2026-11-28-fast2-mac.patch b/fixes-2026-11-28-fast2-mac.patch new file mode 100644 index 00000000..0d5f1b45 --- /dev/null +++ b/fixes-2026-11-28-fast2-mac.patch @@ -0,0 +1,46 @@ +diff --git a/freevideo_engine/macos_runtime.py b/freevideo_engine/macos_runtime.py +index c9b9c60c..95e35d07 100644 +--- a/freevideo_engine/macos_runtime.py ++++ b/freevideo_engine/macos_runtime.py +@@ -277,7 +277,7 @@ class Engine: + fast.install_features(model, steps) + model.rope.to('mps') + times = schedule_timesteps(steps, device='mps', task=schedule_task) +- self.cursor = ScheduleCursor(times) ++ self.cursor = None if fast is not None else ScheduleCursor(times) + tables = None if fast is not None else TableCache(self.cache, manifest['source_id'], steps, + manifest=manifest, timesteps=times, channels=model.config.hidden_size, device='cpu', task=schedule_task) + embeddings = None +@@ -334,7 +334,8 @@ class Engine: + f'transformer_blocks.{index}.', ('adaln_proj.',))) + self._ff_originals.append((layer.ff, layer.ff.forward)) + self.backend.install_chunked_ff(layer.ff, ff_chunk) +- self.schedule_hook = model.register_forward_pre_hook(self.cursor.before, with_kwargs=True) ++ if self.cursor is not None: ++ self.schedule_hook = model.register_forward_pre_hook(self.cursor.before, with_kwargs=True) + if attention_impl == 'mlx': + from .backends.mps_mlx_attention import MLXWindowAttention + self.attention = MLXWindowAttention(batch_bytes=attention_batch_bytes) +@@ -624,7 +625,8 @@ class Engine: + + 2 * continuation['audio'].shape[2]) + self._plan_compute(canvas, prompt.shape[0]) + previous_block_calls = self._block_metrics() +- self.cursor.reset(self.steps - refine_steps if refining and refine_schedule is None else start) ++ if self.cursor is not None: ++ self.cursor.reset(self.steps - refine_steps if refining and refine_schedule is None else start) + progress.start() + resident = getattr(self, 'resident_bytes', 0) + retention = (dict(resident_bytes=resident, working_reserve_bytes=self.reserve_bytes) +diff --git a/freevideo_engine/macos_stages.py b/freevideo_engine/macos_stages.py +index b60cc966..c98ad44b 100644 +--- a/freevideo_engine/macos_stages.py ++++ b/freevideo_engine/macos_stages.py +@@ -550,6 +550,8 @@ def worker(value): + elif phase == 'decode' and value.get('fast_tier') is not None: + # The fastest mode draws its pixels with the adapter's head; the video VAE is never read. No + # continuation, preview or hidden tail reaches this mode (fast_tier.request refuses them). ++ from .macos_vdn import activate ++ activate() + from .dwd_decode import pixels_to_file + initial = torch.load(artifacts / 'latents.pt', map_location='cpu', weights_only=True) + kept = torch.load(artifacts / 'pixel-features.pt', map_location='cpu', weights_only=True) diff --git a/freevideo_engine/macos_runtime.py b/freevideo_engine/macos_runtime.py index c9b9c60c..95e35d07 100644 --- a/freevideo_engine/macos_runtime.py +++ b/freevideo_engine/macos_runtime.py @@ -277,7 +277,7 @@ def path(name): fast.install_features(model, steps) model.rope.to('mps') times = schedule_timesteps(steps, device='mps', task=schedule_task) - self.cursor = ScheduleCursor(times) + self.cursor = None if fast is not None else ScheduleCursor(times) tables = None if fast is not None else TableCache(self.cache, manifest['source_id'], steps, manifest=manifest, timesteps=times, channels=model.config.hidden_size, device='cpu', task=schedule_task) embeddings = None @@ -334,7 +334,8 @@ def path(name): f'transformer_blocks.{index}.', ('adaln_proj.',))) self._ff_originals.append((layer.ff, layer.ff.forward)) self.backend.install_chunked_ff(layer.ff, ff_chunk) - self.schedule_hook = model.register_forward_pre_hook(self.cursor.before, with_kwargs=True) + if self.cursor is not None: + self.schedule_hook = model.register_forward_pre_hook(self.cursor.before, with_kwargs=True) if attention_impl == 'mlx': from .backends.mps_mlx_attention import MLXWindowAttention self.attention = MLXWindowAttention(batch_bytes=attention_batch_bytes) @@ -624,7 +625,8 @@ def host_guard(module, inputs): + 2 * continuation['audio'].shape[2]) self._plan_compute(canvas, prompt.shape[0]) previous_block_calls = self._block_metrics() - self.cursor.reset(self.steps - refine_steps if refining and refine_schedule is None else start) + if self.cursor is not None: + self.cursor.reset(self.steps - refine_steps if refining and refine_schedule is None else start) progress.start() resident = getattr(self, 'resident_bytes', 0) retention = (dict(resident_bytes=resident, working_reserve_bytes=self.reserve_bytes) diff --git a/freevideo_engine/macos_stages.py b/freevideo_engine/macos_stages.py index b60cc966..c98ad44b 100644 --- a/freevideo_engine/macos_stages.py +++ b/freevideo_engine/macos_stages.py @@ -550,6 +550,8 @@ def first_saved(video, audio, metrics): elif phase == 'decode' and value.get('fast_tier') is not None: # The fastest mode draws its pixels with the adapter's head; the video VAE is never read. No # continuation, preview or hidden tail reaches this mode (fast_tier.request refuses them). + from .macos_vdn import activate + activate() from .dwd_decode import pixels_to_file initial = torch.load(artifacts / 'latents.pt', map_location='cpu', weights_only=True) kept = torch.load(artifacts / 'pixel-features.pt', map_location='cpu', weights_only=True)