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.

Keep eight heads on the small first pass for requests without LoRA, and bound the decoder cache

Bowen Xued6fc6e6d4779
diff --git a/freevideo_engine/decode.py b/freevideo_engine/decode.py
index 3f2ca80..d3c9431 100644
--- a/freevideo_engine/decode.py
+++ b/freevideo_engine/decode.py
@@ -26,7 +26,7 @@ def decode_to_file(latents, audio_latents, out_path, *, base, offload=False, pre
preload=False, pin_weights=False, artifacts_dir=None, phase_callback=None,
stream_output=False, stream_weights=False, resident_blocks=0, model_cache=None,
linear_compute_cache=False, continuation=None, audio_lead_in_callback=None, output_size=None,
- hide_tail_frames=0):
+ hide_tail_frames=0, ram_budget_bytes=None):
from .continuation import validate_hide_tail
validate_hide_tail(hide_tail_frames)
def phase(name):
@@ -70,10 +70,21 @@ def decode_to_file(latents, audio_latents, out_path, *, base, offload=False, pre
count = resident_blocks if offload else layers
if stream_weights:
from .streamed_weights import SafetensorLayers
+ room = None
+ if ram_budget_bytes is not None:
+ # Converted layers are private memory: keep them inside the request's own
+ # working-memory budget, so they can neither trip an explicit budget nor
+ # lift the peak that later plans take as demonstrated.
+ def room():
+ import os
+ from .ram import ProcessMemory
+ from .system import memory_sample
+ used = memory_sample(ProcessMemory().sample(os.getpid()))
+ return ram_budget_bytes - used if type(used) is int and used >= 0 else None
weight_source = SafetensorLayers((Path(base)/'vae').glob('*.safetensors'),
[f'decoder.transformer_blocks.{index}.' for index in range(count, layers)],
intermediate_dtype=torch.float32 if linear_compute_cache else None,
- keep_converted=True)
+ keep_converted=True, converted_room=room)
vae, compute_cache_metrics = load_video_decoder(base, resident_blocks=count, weight_source=weight_source,
linear_fp16=linear_compute_cache)
vae.eval().requires_grad_(False)
diff --git a/freevideo_engine/policy.py b/freevideo_engine/policy.py
index d11c80c..b1cb74e 100644
--- a/freevideo_engine/policy.py
+++ b/freevideo_engine/policy.py
@@ -102,7 +102,9 @@ WINDOWS_SMALL_HEAD8_FRAMES = 243
# 672x384x277 first pass of a 1344x768 11.5 s request measured head 4/8 at
# 22.3/15.5, 19.7/17.6 and 21.6/17.4 s per warm step on an RTX PRO 6000 held to
# an 8 GB laptop's 6.96 GB budget, 3.50 and 3.87 GiB reserved, no allocator
-# retry. Ampere and the int8 paths keep 243.
+# retry, all without LoRA. Requests with LoRA, Ampere FP8 and the two Windows
+# int8 paths above the small canvas (windows_int8_full, windows_int8_staged_head8)
+# keep 243.
WINDOWS_SMALL_HEAD8_LONG_FRAMES = 294
# Int8 without LoRA reaches full resolution at the same frame count. With the
# Windows allocator (no expandable segments; its four-head workspace measured
@@ -1214,7 +1216,8 @@ def _choose(hardware: Hardware, *, vram_gib=None, ram_gib=None, attention='auto'
# by moving attention outputs to the host just to widen the group.
windows_small_head8 = (desktop and not ampere and legs == ['sage2', 'sage2']
and effective_tokens is not None
- and canvas['frames'] <= WINDOWS_SMALL_HEAD8_LONG_FRAMES
+ and (canvas['frames'] <= WINDOWS_SMALL_HEAD8_FRAMES
+ or (not lora and canvas['frames'] <= WINDOWS_SMALL_HEAD8_LONG_FRAMES))
and effective_tokens <= WINDOWS_SMALL_HEAD8_TOKENS)
windows_int8_full = (desktop and not lora and legs == ['sage2', 'sage2']
and effective_tokens is not None
diff --git a/freevideo_engine/streamed_weights.py b/freevideo_engine/streamed_weights.py
index 36e172f..2748e89 100644
--- a/freevideo_engine/streamed_weights.py
+++ b/freevideo_engine/streamed_weights.py
@@ -390,31 +390,17 @@ def _low_page_priority(enabled):
CONVERTED_RESERVE = int(1.5 * 2**30)
-def _cgroup_headroom(mount='/sys/fs/cgroup', membership='/proc/self/cgroup'):
- """Room left under this process's cgroup v2 memory limit, or None without one.
+def converted_fits(size, reserve=CONVERTED_RESERVE, room=None):
+ """Whether one more converted layer may stay in RAM as a private copy.
- Private copies count against the limit while clean file pages do not, so
- only anonymous, shared and kernel memory is taken as used.
+ ``room`` is what the request's own RAM budget still allows, when it has one.
"""
- try:
- root = Path(mount)
- for line in Path(membership).read_text(encoding='utf-8').splitlines():
- if line.startswith('0::'):
- root = root / line[3:].lstrip('/')
- limit = (root / 'memory.max').read_text(encoding='utf-8').strip()
- if limit == 'max':
- return None
- stat = dict(row.split() for row in (root / 'memory.stat').read_text(encoding='utf-8').splitlines())
- return int(limit) - sum(int(stat.get(name, 0)) for name in ('anon', 'shmem', 'kernel'))
- except (OSError, ValueError):
- return None
-
-
-def converted_fits(size, reserve=CONVERTED_RESERVE):
- """Whether one more converted layer may stay in RAM as a private copy."""
+ from .hardware import cgroup_memory
from .system import system_memory
+ if room is not None and room < size:
+ return False
available = system_memory()['available_bytes']
- headroom = _cgroup_headroom()
+ headroom = cgroup_memory()['reclaimable_available_bytes']
if headroom is not None:
available = min(available, headroom)
return available - size >= reserve
@@ -436,7 +422,7 @@ def host_view_fits(size, reserve=HOST_VIEW_RESERVE):
class SafetensorLayers:
def __init__(self, paths, prefixes, *, intermediate_dtype=None, direct_read=None, host_views=False,
- host_view_reserve=HOST_VIEW_RESERVE, keep_converted=False):
+ host_view_reserve=HOST_VIEW_RESERVE, keep_converted=False, converted_room=None):
from .system import windows
self.direct_read = windows() if direct_read is None else direct_read
self.prefixes = tuple(prefixes)
@@ -446,6 +432,7 @@ class SafetensorLayers:
# the same layers once per clip; converting reads the whole FP32 layer
# each time, from disk once the file cache cannot hold them.
self.keep_converted = keep_converted and intermediate_dtype is not None
+ self.converted_room = converted_room
self.converted = {}
self.converted_bytes = 0
self.converted_hits = 0
@@ -753,7 +740,8 @@ class SafetensorLayers:
with self.cache_lock:
if index in self.converted:
return
- if not converted_fits(size):
+ room = self.converted_room() if self.converted_room is not None else None
+ if (self.converted_room is not None and room is None) or not converted_fits(size, room=room):
self.converted_refused += 1
return
# A tensor that needed no conversion may still map the checkpoint.
diff --git a/freevideo_engine/worker.py b/freevideo_engine/worker.py
index 9b6950f..ac81259 100644
--- a/freevideo_engine/worker.py
+++ b/freevideo_engine/worker.py
@@ -659,7 +659,8 @@ def generate(request, resident=None):
**({'continuation': continuation} if continuation is not None else {}),
**({'audio_lead_in_callback': keep_audio_lead_in}
if continuation is not None and continuation_data is not None else {}),
- model_cache=resident, phase_callback=decode_phase, output_size=output_size, **decoder))
+ model_cache=resident, phase_callback=decode_phase, output_size=output_size,
+ ram_budget_bytes=request.get('ram_budget_bytes'), **decoder))
if continuable and continuation_data is not None:
if continuation is not None:
# Every continuation of a film carries its first frame on, used or not: a later