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.

Reserve non-local room for the locked residual buffer of large requests

Bowen Xue38d59723323a
diff --git a/freevideo_engine/adaptive.py b/freevideo_engine/adaptive.py
index 8a371cd..9963b8e 100644
--- a/freevideo_engine/adaptive.py
+++ b/freevideo_engine/adaptive.py
@@ -363,6 +363,9 @@ def nonlocal_exhausted(failure):
Page-locked host memory counts against that budget. A 20 s request failed
with non-local usage at 13.14 of 13.24 GiB, 10.68 GiB of VRAM free and no
caching-allocator OOM; the failed allocation itself is not in the usage.
+ A 1920x1088 request failed with usage at 13.9 of 15.2 GiB: the allocation
+ that did not fit was the 2 GiB residual buffer, so the margin is the pin
+ reserve rather than one GiB.
"""
gpu = failure.get('gpu') if isinstance(failure.get('gpu'), dict) else {}
values = [gpu.get(key) for key in ('nonlocal_budget_bytes', 'nonlocal_usage_bytes',
@@ -370,7 +373,8 @@ def nonlocal_exhausted(failure):
if not all(type(value) is int and value >= 0 for value in values) or not values[0]:
return False
budget, usage, local_budget, local_usage = values
- return (usage >= budget - 2**30 and local_usage <= local_budget - 2 * 2**30
+ from .windows_gpu_memory import NONLOCAL_PIN_RESERVE
+ return (usage >= budget - NONLOCAL_PIN_RESERVE and local_usage <= local_budget - 2 * 2**30
and not gpu.get('allocator_ooms'))
diff --git a/freevideo_engine/runtime.py b/freevideo_engine/runtime.py
index 34f796e..49226a7 100644
--- a/freevideo_engine/runtime.py
+++ b/freevideo_engine/runtime.py
@@ -162,10 +162,11 @@ class Engine:
validate_catalog(manifest, len(model.transformer_blocks))
# Locked buffers allocated after the weights must also fit the Windows
# non-local budget: CPU attention readouts grow with this request's rows.
- from .windows_gpu_memory import NONLOCAL_PIN_RESERVE, nonlocal_readout_bytes
+ from .windows_gpu_memory import NONLOCAL_PIN_RESERVE, nonlocal_readout_bytes, nonlocal_residual_bytes
readouts = (nonlocal_readout_bytes(self.canvas, model.config.num_attention_heads * model.config.attention_head_dim)
if attention_cpu_outputs else 0)
- self.nonlocal_reserve_bytes = NONLOCAL_PIN_RESERVE + readouts
+ self.nonlocal_reserve_bytes = NONLOCAL_PIN_RESERVE + readouts + (
+ nonlocal_residual_bytes(residual_host_headroom(self.canvas)) if residual_offload else 0)
# RAM views fill during the first pass; leave what the refine pass will
# still allocate. A 20 s request that let views take that room drove
# physical availability to 0.01 GiB when its full-size readouts arrived.
diff --git a/freevideo_engine/windows_gpu_memory.py b/freevideo_engine/windows_gpu_memory.py
index 8786df3..ec35807 100644
--- a/freevideo_engine/windows_gpu_memory.py
+++ b/freevideo_engine/windows_gpu_memory.py
@@ -117,6 +117,20 @@ def nonlocal_readout_bytes(canvas, attention_width, text_rows=1024):
return int(1.25 * (rows + video) * attention_width * 2)
+def nonlocal_residual_bytes(headroom_bytes):
+ """Non-local room the locked residual staging buffer needs beyond the base reserve.
+
+ The base reserve was sized with the 1 GiB residual of a 72,576-row request.
+ A 1920x1088 request (147,721 rows, 2.04 GiB residual) on a 31.9 GB machine
+ pinned weights up to the base reserve, then failed with
+ cudaErrorMemoryAllocation at the first full-resolution step with non-local
+ usage at 13.9 of 15.2 GiB: the residual plus the transfer slots no longer
+ fit. Larger requests need the extra room, with half again for the
+ slots and driver allocations that grow beside it.
+ """
+ return int(1.5 * max(0, headroom_bytes - 2**30))
+
+
def nonlocal_pin_capacity(reserve=NONLOCAL_PIN_RESERVE):
"""Bytes this process may still page-lock inside its non-local budget, or None if unreadable."""
reader = None