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.

Mac: step cache (audio-video EasyCache) on the first pass; high is 20 steps with it

Bowen Xue0de640a8ae8e
diff --git a/freevideo_engine/agent/guide.py b/freevideo_engine/agent/guide.py
index 6a6a068..ef9efb4 100644
--- a/freevideo_engine/agent/guide.py
+++ b/freevideo_engine/agent/guide.py
@@ -73,8 +73,8 @@ GUIDE = {
'quality': [
'Steps per quality: "light" = 8 first-pass steps + 3 refine steps, two-pass (default); "medium" = 8 steps, '
'"high" = 20 steps with a step cache, "max" = 20 steps with a step cache that skips less work, each in one pass. '
- '"max" runs plain 20 steps when the GPU has no room for its cache. On a Mac, "high" is 16 steps and '
- '"max" 20 steps, without a cache.',
+ '"max" runs plain 20 steps when the GPU has no room for its cache. On a Mac, "high" is the same and '
+ '"max" is 20 plain steps.',
'Two-pass generation runs only with 8 first-pass steps. Any other base_steps (for example 20 with '
'two_pass=true) runs in one pass of that many steps; the job notice says so. A preview is always two-pass '
'with 8 steps.',
diff --git a/freevideo_engine/agent/schema.py b/freevideo_engine/agent/schema.py
index bad26ed..12ab2bc 100644
--- a/freevideo_engine/agent/schema.py
+++ b/freevideo_engine/agent/schema.py
@@ -14,7 +14,7 @@ from .. import tiers
S = 'https://json-schema.org/draft/2020-12/schema'
PREFIX = '/freevideo/agent/v1'
# (two_pass, base_steps, refine_steps) of each level on this platform; the step
-# cache a level adds is tiers.step_cache(name, mac) (none on Mac).
+# cache a level adds is tiers.step_cache(name, mac) (on Mac only high has one, easycache-av).
QUALITY = {name: tiers.plan(name, mac=tiers.on_mac()) for name in tiers.TIERS}
ASPECTS = {'16:9': (16, 9), '9:16': (9, 16), '1:1': (1, 1), '4:3': (4, 3), '3:4': (3, 4),
'21:9': (21, 9), '2:3': (2, 3), '3:2': (3, 2)}
diff --git a/freevideo_engine/capabilities.py b/freevideo_engine/capabilities.py
index bf9ea16..817fad6 100644
--- a/freevideo_engine/capabilities.py
+++ b/freevideo_engine/capabilities.py
@@ -245,7 +245,7 @@ def _admit(machine, width, height, frames, steps, two_pass, task='t2va', refine=
references=None, reference_rows=None, step_cache=None):
"""Admission of one request; `step_cache` asks the planner for a first-pass cache.
- The request carries the cache the planner keeps (never one on Mac), so its
+ The request carries the cache the planner keeps (on Mac only the audio-video EasyCache), so its
estimate and history follow what the engine will actually run.
"""
canvas, sampling, request = _request(width, height, frames, steps, two_pass, task, refine,
@@ -266,6 +266,8 @@ def _admit(machine, width, height, frames, steps, two_pass, task='t2va', refine=
for g in (sampling['first'], sampling['second'] or sampling['first'])]
request.update(pass1_resident_blocks=plans[0]['retained_layers'],
pass2_resident_blocks=plans[1]['retained_layers'])
+ if step_cache == 'easycache-av':
+ request['step_cache'] = step_cache
code = 0 if all(p['retained_layers'] == 50 for p in plans) else 1
if admission['state'] == 'tight':
code = 2
diff --git a/freevideo_engine/comfy_bridge.py b/freevideo_engine/comfy_bridge.py
index 606784d..4744945 100644
--- a/freevideo_engine/comfy_bridge.py
+++ b/freevideo_engine/comfy_bridge.py
@@ -1233,10 +1233,10 @@ def generate(prompt, width, height, seconds, seed, output_directory, *,
from .two_pass import sampling_canvas
check(continue_from, sampling_canvas(canvas)[0])
- if step_cache is not None and machine.get('device_backend') == 'mps':
- # The step caches are not ported to Mac yet: the request samples every step,
+ if step_cache == 'fbcache' and machine.get('device_backend') == 'mps':
+ # Only the audio-video EasyCache is ported to Mac: the request samples every step,
# and its identity is that of the same request without a cache.
- logging.warning('[FreeVideo] Step caches are not available on Mac yet; sampling every step.')
+ logging.warning('[FreeVideo] The first-block cache is not available on Mac yet; sampling every step.')
step_cache = None
if continue_from is not None:
validate_route(backend=machine.get('device_backend', 'cuda'))
diff --git a/freevideo_engine/macos_generate.py b/freevideo_engine/macos_generate.py
index 38e47e3..eedc4be 100644
--- a/freevideo_engine/macos_generate.py
+++ b/freevideo_engine/macos_generate.py
@@ -295,6 +295,8 @@ def run(args):
base=base, task=task,
checkpoint=str(Path(args.checkpoint or checkpoint_path()).resolve()),
seed=args.seed, canvas=canvas, sampling=sampling, resources=resource)
+ if getattr(args, 'step_cache', None) == 'easycache-av':
+ engine['step_cache'] = args.step_cache
if output_size:
engine['output_size'] = [output_size['width'], output_size['height']]
if preview:
diff --git a/freevideo_engine/macos_runtime.py b/freevideo_engine/macos_runtime.py
index 618e5a1..3e5a15e 100644
--- a/freevideo_engine/macos_runtime.py
+++ b/freevideo_engine/macos_runtime.py
@@ -128,11 +128,18 @@ def conditioning_tokens(task, canvas, conditions):
class Engine:
+ # Engines built without __init__ (tests) sample without a cache.
+ step_cache = None
+
def __init__(self, cache, *, base, checkpoint, steps=8, budget_bytes=4 * 2**30,
reserve_bytes=2 * 2**30, query_chunk=128, ff_chunk=256, projection_chunk=256,
weight_decoder='cpu', budget_ceiling_bytes=None, attention_chunk=None, task='t2va', canvas=None,
head_chunk=4, window_batch=1, attention_impl='torch', fast_kernels=False,
- resident_bytes=0, attention_batch_bytes=1 << 29, plan_compute=False, memory_retry=False):
+ resident_bytes=0, attention_batch_bytes=1 << 29, plan_compute=False, memory_retry=False,
+ step_cache=None):
+ if step_cache not in (None, 'easycache-av'):
+ raise ValueError('MPS supports the easycache-av step cache only')
+ self.step_cache = step_cache
attention_chunk = projection_chunk if attention_chunk is None else attention_chunk
if type(attention_chunk) is not int or attention_chunk < 1:
raise ValueError('MPS attention row chunk must be a positive integer')
@@ -561,11 +568,18 @@ class Engine:
frame_w=width // 32, step_offset=progress_offset,
total=progress_total if progress_total is not None else active_steps):
self.residency = residency
- video, audio = sampler(self.model, prompt, tags, canvas['frames'], self.steps,
- seed, 'mps', step_seconds=durations,
- **(dict(conditions=conditions) if conditions else {}),
- **(dict(initial_latents=initial_latents, refine_steps=refine_steps, refine_schedule=refine_schedule)
- if refining else {}))
+ from .step_cache import begin_pass, end_pass
+ step_cache = None
+ if not refining and self.step_cache:
+ begin_pass(self.model, active_steps, self.step_cache)
+ try:
+ video, audio = sampler(self.model, prompt, tags, canvas['frames'], self.steps,
+ seed, 'mps', step_seconds=durations,
+ **(dict(conditions=conditions) if conditions else {}),
+ **(dict(initial_latents=initial_latents, refine_steps=refine_steps, refine_schedule=refine_schedule)
+ if refining else {}))
+ finally:
+ step_cache = end_pass(self.model)
self.backend.synchronize()
if not bool(video.isfinite().all()) or not bool(audio.isfinite().all()):
raise ValueError('MPS sampling produced nonfinite video or audio latents')
@@ -588,7 +602,7 @@ class Engine:
max_bytes=max(self.allocator_limits)),
attention_calls={name: value - previous_calls[name]
for name, value in self.attention.backend_calls.items()},
- step_seconds=list(durations),
+ step_seconds=list(durations), step_cache=step_cache,
block_seconds=progress.block_seconds, block_seconds_scope=BLOCK_SECONDS_SCOPE,
conditions=progress.conditions,
load_seconds=self.load_seconds, residency=self._residency_metrics(residency, previous_residency),
diff --git a/freevideo_engine/macos_stages.py b/freevideo_engine/macos_stages.py
index cf8dd13..d51a3e8 100644
--- a/freevideo_engine/macos_stages.py
+++ b/freevideo_engine/macos_stages.py
@@ -354,7 +354,8 @@ def worker(value):
resident_bytes=compute.get('resident_bytes', 0),
attention_batch_bytes=compute.get('attention_batch_bytes', 1 << 29),
plan_compute=bool(compute), memory_retry=retry and bool(compute),
- task=value.get('task', 't2va'), canvas=value['canvas']) as engine:
+ task=value.get('task', 't2va'), canvas=value['canvas'],
+ step_cache=None if refining else value.get('step_cache')) as engine:
result['load_seconds'] = engine.load_seconds
tick = time.monotonic()
# A preview stops after the first pass; joining would also refine.
diff --git a/freevideo_engine/tiers.py b/freevideo_engine/tiers.py
index af1131b..df19dc6 100644
--- a/freevideo_engine/tiers.py
+++ b/freevideo_engine/tiers.py
@@ -16,8 +16,10 @@ REFINE_STEPS only as the neutral value the `refine_steps` field needs; it is
never run for them. `step_cache` is the engine's cache key: None,
'easycache-av' (audio-video EasyCache) or 'fbcache' (first-block cache).
-The caches are not ported to Mac (MPS) yet: there high is one pass of 16
-steps and max one pass of 20, both without a cache (TIERS_MAC).
+On Mac (MPS) only the audio-video EasyCache is ported: high is the same plan
+as everywhere else and max is one pass of 20 steps without a cache (TIERS_MAC).
+Results made before that, one pass of 16 steps without a cache, still count as
+high (LEGACY_MAC_HIGH).
"""
import sys
@@ -30,8 +32,8 @@ TIERS = {
'high': dict(steps=20, two_pass=False, step_cache='easycache-av'),
'max': dict(steps=20, two_pass=False, step_cache='fbcache'),
}
-TIERS_MAC = dict(TIERS, high=dict(steps=16, two_pass=False, step_cache=None),
- max=dict(steps=20, two_pass=False, step_cache=None))
+TIERS_MAC = dict(TIERS, max=dict(steps=20, two_pass=False, step_cache=None))
+LEGACY_MAC_HIGH = dict(steps=16, two_pass=False, step_cache=None)
# Sampling time of a cached pass as a share of the same pass without a cache,
# for estimates that have no run with that cache yet. B200, 20 s clips
@@ -69,9 +71,12 @@ def step_cache(name, mac=False):
def name_for(steps, two_pass, refine_steps=REFINE_STEPS, step_cache=None, mac=False):
"""The level with exactly this plan, or None for custom sampling."""
- return next((name for name, tier in table(mac).items()
- if tier['steps'] == steps and tier['two_pass'] == two_pass
- and (not two_pass or refine_steps == REFINE_STEPS) and tier['step_cache'] == step_cache), None)
+ found = next((name for name, tier in table(mac).items()
+ if tier['steps'] == steps and tier['two_pass'] == two_pass
+ and (not two_pass or refine_steps == REFINE_STEPS) and tier['step_cache'] == step_cache), None)
+ if found is None and mac and (steps, two_pass, step_cache) == tuple(LEGACY_MAC_HIGH.values()):
+ return 'high'
+ return found
def table_level(steps, two_pass, refine_steps=REFINE_STEPS, step_cache=None, mac=False):
@@ -79,7 +84,7 @@ def table_level(steps, two_pass, refine_steps=REFINE_STEPS, step_cache=None, mac
Tables follow the step count only. Prefer the exact level (the cache tells
high from max at 20 steps), then the other platform's table (20 steps
- without a cache is "max", as on Mac; 16 steps is "high"), then the first
+ without a cache is "max", as on Mac; 16 steps is the earlier Mac "high"), then the first
level with that step count.
"""
found = name_for(steps, two_pass, refine_steps, step_cache, mac) or name_for(
diff --git a/web/sampling_effort.js b/web/sampling_effort.js
index 966b2df..4b6281a 100644
--- a/web/sampling_effort.js
+++ b/web/sampling_effort.js
@@ -8,9 +8,12 @@ export const SAMPLING_EFFORTS = frozen([
{name: 'High', zh: '精细', steps: 20, twoPass: false, stepCache: 'easycache-av', color: '#9d7bff'},
{name: 'Max', zh: '极致', steps: 20, twoPass: false, stepCache: 'fbcache', color: '#ffa94d'},
]);
-// Mac (MPS) has no step caches yet: High samples 16 steps and Max 20, both in full.
-const MAC = {High: {steps: 16, stepCache: null}, Max: {stepCache: null}};
+// Mac (MPS) has the audio-video EasyCache only: High is as everywhere, Max samples 20 steps in full.
+const MAC = {Max: {stepCache: null}};
export const SAMPLING_EFFORTS_MAC = frozen(SAMPLING_EFFORTS.map(tier => ({...tier, ...MAC[tier.name]})));
+// Mac results made before the cache came: High was 16 steps without one.
+export const legacyMacEffort = (steps, twoPass, stepCache = null) =>
+ steps === 16 && !twoPass && stepCacheOf(stepCache) === null ? SAMPLING_EFFORTS_MAC.find(tier => tier.name === 'High') : undefined;
export const effortName = (t, tier) => t(tier.name, tier.zh);
export const STEP_CACHES = Object.freeze([null, 'easycache-av', 'fbcache']);
@@ -41,10 +44,10 @@ export function effortFor(steps, twoPass, refine, stepCache = null, levels = SAM
// The level whose sampling table a plan needs, for naming a missing download (tiers.table_level):
// the exact level of either table (the cache tells High from Max at 20 steps; 20 steps
-// without a cache is Max and 16 steps High, as on Mac), else the first level with those steps.
+// without a cache is Max, as on Mac; 16 steps is the earlier Mac High), else the first level with those steps.
export function tableLevel(steps, twoPass, refine, stepCache = null) {
return effortFor(steps, twoPass, refine, stepCache) || effortFor(steps, twoPass, refine, stepCache, SAMPLING_EFFORTS_MAC)
- || SAMPLING_EFFORTS.find(tier => tier.steps === steps && tier.twoPass === twoPass && (!twoPass || refine === 3));
+ || legacyMacEffort(steps, twoPass, stepCache) || SAMPLING_EFFORTS.find(tier => tier.steps === steps && tier.twoPass === twoPass && (!twoPass || refine === 3));
}
export function createSamplingEffort(t, {onChange, onPreview = () => {}, levels = SAMPLING_EFFORTS}) {
diff --git a/web/share.js b/web/share.js
index f0aea76..ad82a6f 100644
--- a/web/share.js
+++ b/web/share.js
@@ -1,6 +1,6 @@
import {api} from '../../scripts/api.js';
import {closeDialog} from './motion.js';
-import {SAMPLING_EFFORTS_MAC, effortFor, effortName} from './sampling_effort.js';
+import {SAMPLING_EFFORTS_MAC, effortFor, effortName, legacyMacEffort} from './sampling_effort.js';
import {fontCSS as bundledFontCSS, fontLoaded, loadFont} from './fonts.js';
import {shareLayout} from './share_layout.js';
import {videoUnavailableText} from './studio_extend.js';
@@ -38,9 +38,9 @@ export function drawShareCard(canvas,frame,logo,record,t) {
const ctx=canvas.getContext('2d'),w=shape.width,y=shape.rect[3],H=shape.footer,pad=44,wide=w>=1000;
const p=record.sampling_plan||{},steps=p.base_steps,refine=p.enabled?p.refine_steps:0;
// Results made with the earlier 8 + 2 default count as Light.
- // A Mac result names its level from the Mac table (High 16 steps, Max 20 without a cache).
+ // A Mac result names its level from the Mac table (Max 20 without a cache; earlier High 16 steps).
const plan=[steps,!!p.enabled,p.enabled&&steps===8&&refine===2?3:refine,p.step_cache??null];
- const tier=effortFor(...plan)||effortFor(...plan,SAMPLING_EFFORTS_MAC), accent=tier?.color||'#8fa3bb';
+ const tier=effortFor(...plan)||effortFor(...plan,SAMPLING_EFFORTS_MAC)||legacyMacEffort(steps,!!p.enabled,p.step_cache??null), accent=tier?.color||'#8fa3bb';
ctx.fillStyle='#0b1016';ctx.fillRect(0,0,w,shape.height);ctx.clearRect(...shape.rect);
const bg=ctx.createLinearGradient(0,y,0,y+H);bg.addColorStop(0,'#131b26');bg.addColorStop(1,'#0b1016');
ctx.fillStyle=bg;ctx.fillRect(0,y,w,H);