Skip to content

Make videos on the computer you already own. FreeVideo runs MiniMax H3 in as little as 8 GB of VRAM and 16 GB of RAM, and adapts its acceleration path to your hardware.

Early reference geometry check for scaled passes

Bowen Xue1812fa3bbc4f
diff --git a/freevideo_engine/comfy_progress.py b/freevideo_engine/comfy_progress.py
index 51da6f5..d51268d 100644
--- a/freevideo_engine/comfy_progress.py
+++ b/freevideo_engine/comfy_progress.py
@@ -2,6 +2,8 @@
from copy import deepcopy
from pathlib import Path
import heapq
+import json
+import os
import threading
import time
import uuid
@@ -173,6 +175,7 @@ class ReportDownloads:
"""Only server-registered runs are readable; clients never supply a path."""
def __init__(self):
self.runs = {}
+ self.roots = set()
self.lock = threading.Lock()
def register(self, output):
@@ -181,11 +184,59 @@ class ReportDownloads:
self.runs[token] = Path(output)
while len(self.runs) > 64:
del self.runs[next(iter(self.runs))]
+ self._remember(token, Path(output))
return token
- def snapshot(self, token):
+ def _lookup(self, token):
with self.lock:
output = self.runs.get(token)
+ if output is None and isinstance(token, str) and len(token) == 32 and token.isalnum():
+ output = self._recall(token)
+ return output
+
+ @staticmethod
+ def _index(output):
+ # The run folder is <output>/FreeVideo/<date>/<run>; any other layout is not persisted.
+ root = output.parent.parent.parent
+ return (root / '.agent' / 'report-ids.json') if root.name == 'FreeVideo' else None
+
+ def _remember(self, token, output):
+ """Keep the token readable after the service restarts: a failed run's report is otherwise unreachable."""
+ index = self._index(output)
+ if index is None:
+ return
+ try:
+ try:
+ rows = json.loads(index.read_text('utf-8'))
+ except (OSError, ValueError):
+ rows = {}
+ rows = {key: value for key, value in (rows if isinstance(rows, dict) else {}).items()
+ if isinstance(value, str)}
+ self.roots.add(index.parent.parent)
+ rows[token] = output.relative_to(index.parent.parent).as_posix()
+ while len(rows) > 256:
+ del rows[next(iter(rows))]
+ index.parent.mkdir(parents=True, exist_ok=True)
+ temporary = index.with_name('report-ids.%s.tmp' % uuid.uuid4().hex)
+ temporary.write_text(json.dumps(rows), 'utf-8')
+ os.replace(temporary, index)
+ except Exception:
+ pass # Reports stay readable in this process; the index is only a convenience.
+
+ def _recall(self, token):
+ """The registered output of an earlier service, from the index beside its runs."""
+ for root in self.roots:
+ try:
+ rows = json.loads((root / '.agent' / 'report-ids.json').read_text('utf-8'))
+ relative = rows.get(token) if isinstance(rows, dict) else None
+ if isinstance(relative, str) and relative and not Path(relative).is_absolute() and '..' not in Path(relative).parts:
+ return root / relative
+ except (OSError, ValueError):
+ continue
+ return None
+
+ def snapshot(self, token):
+ output = self._lookup(token)
if output is None:
raise KeyError('Unknown report')
from .support_report import write
@@ -203,8 +254,7 @@ class ReportDownloads:
"""The newest frame preview picture of a registered run, or KeyError."""
from .frame_preview import FILE
from .diagnostics import is_link
- with self.lock:
- output = self.runs.get(token)
+ output = self._lookup(token)
if output is None:
raise KeyError('Unknown run')
path = output.parent / FILE
@@ -294,6 +344,11 @@ def register():
if server is None or getattr(server, '_freevideo_progress', False):
return
server._freevideo_progress = True
+ try:
+ import folder_paths
+ REPORTS.roots.add(Path(folder_paths.get_output_directory()).resolve() / 'FreeVideo')
+ except Exception:
+ pass # Without it only runs of this process (and their index folders) are found.
report_lock = asyncio.Lock()
@server.routes.get('/freevideo/report/{report_id}')
diff --git a/freevideo_engine/step_cache.py b/freevideo_engine/step_cache.py
index a033517..b39e8a8 100644
--- a/freevideo_engine/step_cache.py
+++ b/freevideo_engine/step_cache.py
@@ -100,6 +100,13 @@ class StepCache:
self.accumulated = 0.
# ---- shared ------------------------------------------------------------------------------------
+ def forget(self):
+ """Drop every earlier step: the packed sequence changed length (an early reference ended), so the
+ cached residuals, velocities and rate belong to another layout and cannot be compared with it."""
+ self.previous = self.tail = self.anchor = None
+ self.prev_input = self.prev_diff = self.prev_out = self.rate = None
+ self.consecutive, self.accumulated = 0, 0.
+
def in_window(self):
start, end = WINDOWS.get(self.kind, (0., 1.))
progress = self.step / self.steps
@@ -132,6 +139,8 @@ class StepCache:
audio, video = (now - then for now, then in zip(self._samples(after), self.before))
self.before = None
hit, scores = False, None
+ if self.previous is not None and (self.previous[0].shape != audio.shape or self.previous[1].shape != video.shape):
+ self.forget()
if self.previous is not None and self.tail is not None and self.in_window() and self.consecutive < 2:
scores = (_relative(audio, self.previous[0]), _relative(video, self.previous[1]))
decisive = scores[1]
@@ -162,6 +171,8 @@ class StepCache:
# Copies: float32 latents make .float() a view, and the sampler updates them in place.
current_in = (_copy(video_in[stride]), _copy(audio_in[stride]))
current_out = (_copy(video_out[stride]), _copy(audio_out[stride]))
+ if self.prev_input is not None and any(a.shape != b.shape for a, b in zip(self.prev_input, current_in)):
+ self.forget()
if self.prev_input is not None and self.prev_out is not None:
rates = []
for i in range(2):
@@ -176,6 +187,9 @@ class StepCache:
def _easycache(self, video_in, audio_in):
reuse = False
+ if self.prev_input is not None and (self.prev_input[0].shape[0] != video_in.shape[0]
+ or self.prev_input[1].shape[0] != audio_in.shape[0]):
+ self.forget()
if self.rate is not None and self.prev_diff is not None and self.in_window():
stride = (slice(None), slice(None, None, STRIDE))
current = (video_in[stride].float(), audio_in[stride].float())
diff --git a/freevideo_engine/two_pass.py b/freevideo_engine/two_pass.py
index 12dec3b..22444da 100644
--- a/freevideo_engine/two_pass.py
+++ b/freevideo_engine/two_pass.py
@@ -298,8 +298,10 @@ def stage_tokens(canvas):
refinement = None
if sampling.get('enabled'):
steps(sampling)
- expected = plan(canvas, task=canvas.get('task', 't2va'),
- base_steps=sampling['base_steps'], refine_steps=sampling['refine_steps'])
+ # The receipt records a non-default upscale factor and a staged first pass; the check replays both.
+ expected = plan(canvas, task=canvas.get('task', 't2va'), base_steps=sampling['base_steps'],
+ refine_steps=sampling['refine_steps'], staged=sampling.get('staged', False),
+ scale=sampling.get('scale', 2))
if any(sampling.get(key) != expected[key] for key in ('first', 'second')):
raise ValueError('Early reference sampling geometry disagrees with the request')
from .geometry import geometry