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 room in Windows virtual memory for GPU allocations when pinning weights (0.3.15) (#124)

Bowen Xue84bc62ac2655
diff --git a/freevideo_engine/offload.py b/freevideo_engine/offload.py
index fcc9d3d..61c29b6 100644
--- a/freevideo_engine/offload.py
+++ b/freevideo_engine/offload.py
@@ -40,12 +40,15 @@ def _pin_reservation(sizes):
@torch.no_grad()
-def pin_layer_weights(layers, max_bytes=None, *, headroom_bytes=None, nonlocal_reserve_bytes=None):
+def pin_layer_weights(layers, max_bytes=None, *, headroom_bytes=None, nonlocal_reserve_bytes=None,
+ commit_reserve_bytes=0):
"""Pack immutable CPU parameters into persistent pinned planes, one per dtype.
This optional mode trades pageable/mapped storage for locked host residency.
Rebinding preserves parameter values and permits direct asynchronous H2D.
"""
+ if type(commit_reserve_bytes) is not int or commit_reserve_bytes < 0:
+ raise ValueError('Commit reserve must be a nonnegative byte count')
layers = list(layers)
layer_groups = []
for layer in layers:
@@ -87,7 +90,14 @@ def pin_layer_weights(layers, max_bytes=None, *, headroom_bytes=None, nonlocal_r
available = memory.get('physical_available_bytes') or memory['available_bytes']
commit_available = memory.get('commit_available_bytes')
if commit_available is not None:
- available = min(available, commit_available)
+ # WDDM charges this process's GPU allocations to system commit as they
+ # are made, so allocator room the request has not reserved yet cannot
+ # back locked pages either. Pinning against commit alone left an 8 GiB
+ # card's request with under 1 GiB of commit once sampling reserved its
+ # workspace, and live pressure then switched off host read-ahead and
+ # the step cache for the rest of the request. The caller passes that
+ # unreserved allocator room; physical RAM is not charged for it.
+ available = min(available, commit_available - commit_reserve_bytes)
live_cap = available - headroom_bytes
max_bytes = live_cap if max_bytes is None else min(max_bytes, live_cap)
from .system import windows
@@ -263,7 +273,8 @@ def unload_streamed_layer(layer, source, index):
@torch.no_grad()
-def prepare_streamed_layer(layer, source, index, *, pin_budget_bytes, headroom_bytes, nonlocal_reserve_bytes=None):
+def prepare_streamed_layer(layer, source, index, *, pin_budget_bytes, headroom_bytes, nonlocal_reserve_bytes=None,
+ commit_reserve_bytes=0):
"""Retain one affordable pinned layer or release it before loading the next.
Return logical pinned bytes and the charged allocator reservation. A partial
@@ -277,7 +288,8 @@ def prepare_streamed_layer(layer, source, index, *, pin_budget_bytes, headroom_b
pinned = 0
if 0 < reserved <= pin_budget_bytes:
pinned = pin_layer_weights([layer], max_bytes=pin_budget_bytes, headroom_bytes=headroom_bytes,
- nonlocal_reserve_bytes=nonlocal_reserve_bytes)
+ nonlocal_reserve_bytes=nonlocal_reserve_bytes,
+ commit_reserve_bytes=commit_reserve_bytes)
if pinned == sum(sizes.values()) and all(value.is_pinned() for _, value in cpu_weights(layer)):
return pinned, reserved
unload_streamed_layer(layer, source, index)
diff --git a/freevideo_engine/release_notes.json b/freevideo_engine/release_notes.json
index 7759005..944ed95 100644
--- a/freevideo_engine/release_notes.json
+++ b/freevideo_engine/release_notes.json
@@ -1,25 +1,40 @@
{
"schema": 1,
- "product_version": "0.3.14",
+ "product_version": "0.3.15",
"en": {
- "summary": "When a FreeVideo script fails to load once, the page now recovers by itself, and when the creative workspace cannot be seen, the page or the node says why.",
+ "summary": "On Windows computers with a small page file, generation keeps its weight read-ahead on and no longer runs out of virtual memory midway.",
"changes": [
- "If the browser fails to load one of FreeVideo's scripts while the ComfyUI page opens, the page refreshes its copies of FreeVideo's files and reloads itself once, returning to the address it was opened with. Before, the page stayed incomplete until a hard reload. The automatic reload is skipped once you have clicked or typed on the page.",
- "If the scripts still fail after that reload, the message says so and suggests Ctrl+F5 or checking browser extensions, and the copied details include what the browser cache held for each failed file.",
- "If a FreeVideo node is on the canvas but neither the creative workspace nor the toolbar that opens it can be seen, the page now says so and names the cause, such as a stylesheet that did not load. This is checked on every visit and whenever another workflow comes to the front, not only when the launcher opens the page.",
- "If FreeVideo’s page scripts do not run in the browser at all, the generating node now shows the cause and what to do in its progress text, since the page itself cannot."
+ "When FreeVideo keeps model weights in system memory on Windows, it now leaves room in virtual memory (commit) for the GPU memory the request will still allocate. Before, a computer with a small page file could run out midway: the weight read-ahead switched off for the rest of the request, or the request stopped and started again with less kept in memory. In a test with a fixed page file and a 7 GB GPU limit, a request that stopped and restarted midway (851 s) now completes without the restart (622 s)."
]
},
"zh": {
- "summary": "FreeVideo 的脚本在页面打开时偶尔加载失败,现在页面会自行恢复;看不到创作面板时,页面或节点会说明原因。",
+ "summary": "页面文件较小的 Windows 电脑上,生成过程中不再耗尽虚拟内存,权重预读也会一直开着。",
"changes": [
- "打开 ComfyUI 页面时,如果浏览器有一个 FreeVideo 脚本没能加载,页面会重新下载 FreeVideo 的文件并自动刷新一次,回到最初打开的地址。之前页面会一直不完整,直到手动强制刷新。如果你已经在页面上点击或输入过,就不会自动刷新。",
- "自动刷新后仍然失败时,提示会说明已经刷新过,并建议按 Ctrl+F5 或检查浏览器插件;复制的详情里还会列出每个失败文件在浏览器缓存中的情况。",
- "画布上有 FreeVideo 节点、却看不到创作面板和打开它的工具栏时,页面会提示并写明原因,例如某个样式文件没有加载。每次打开页面、切换工作流时都会检查,不再只在从启动器打开时检查。",
- "如果浏览器完全没有运行 FreeVideo 的页面脚本,页面本身无法提示,生成节点会在进度文字里说明原因和处理办法。"
+ "在 Windows 上把模型权重放进内存时,FreeVideo 现在会为本次请求之后还要分配的显存预留虚拟内存(提交内存)。之前页面文件较小的电脑可能在生成中途耗尽虚拟内存:剩下的步骤会关闭权重预读,或者请求中止后减少内存占用再重新开始。在固定页面文件、显存限制为 7 GB 的测试中,原来中途中止重来的请求(851 秒)现在一次完成(622 秒)。"
]
},
"history": [
+ {
+ "product_version": "0.3.14",
+ "en": {
+ "summary": "When a FreeVideo script fails to load once, the page now recovers by itself, and when the creative workspace cannot be seen, the page or the node says why.",
+ "changes": [
+ "If the browser fails to load one of FreeVideo's scripts while the ComfyUI page opens, the page refreshes its copies of FreeVideo's files and reloads itself once, returning to the address it was opened with. Before, the page stayed incomplete until a hard reload. The automatic reload is skipped once you have clicked or typed on the page.",
+ "If the scripts still fail after that reload, the message says so and suggests Ctrl+F5 or checking browser extensions, and the copied details include what the browser cache held for each failed file.",
+ "If a FreeVideo node is on the canvas but neither the creative workspace nor the toolbar that opens it can be seen, the page now says so and names the cause, such as a stylesheet that did not load. This is checked on every visit and whenever another workflow comes to the front, not only when the launcher opens the page.",
+ "If FreeVideo’s page scripts do not run in the browser at all, the generating node now shows the cause and what to do in its progress text, since the page itself cannot."
+ ]
+ },
+ "zh": {
+ "summary": "FreeVideo 的脚本在页面打开时偶尔加载失败,现在页面会自行恢复;看不到创作面板时,页面或节点会说明原因。",
+ "changes": [
+ "打开 ComfyUI 页面时,如果浏览器有一个 FreeVideo 脚本没能加载,页面会重新下载 FreeVideo 的文件并自动刷新一次,回到最初打开的地址。之前页面会一直不完整,直到手动强制刷新。如果你已经在页面上点击或输入过,就不会自动刷新。",
+ "自动刷新后仍然失败时,提示会说明已经刷新过,并建议按 Ctrl+F5 或检查浏览器插件;复制的详情里还会列出每个失败文件在浏览器缓存中的情况。",
+ "画布上有 FreeVideo 节点、却看不到创作面板和打开它的工具栏时,页面会提示并写明原因,例如某个样式文件没有加载。每次打开页面、切换工作流时都会检查,不再只在从启动器打开时检查。",
+ "如果浏览器完全没有运行 FreeVideo 的页面脚本,页面本身无法提示,生成节点会在进度文字里说明原因和处理办法。"
+ ]
+ }
+ },
{
"product_version": "0.3.13",
"en": {
@@ -244,33 +259,6 @@
"启动器支持导入新的 int8 离线包:视频模型、文本编码器、视频与音频解码器、采样缓存。"
]
}
- },
- {
- "product_version": "0.3.2",
- "en": {
- "summary": "Adds Preview first to two-pass sampling, deleting in Your creations and prompt box improvements (the example prompt as a placeholder, the last prompt restored on reopening), and fixes installing into folders with spaces.",
- "changes": [
- "Two-pass sampling can stop at a quick half-resolution preview: choose Two-pass: Preview first. When a preview looks right, choose Run second pass; the finished video is identical to generating it directly. Make several previews in a batch and pick one in Your creations.",
- "Your creations can delete videos you no longer need, after a confirmation.",
- "The example prompt is shown greyed out as a placeholder. Typing replaces it without clearing the box first, and a box that was never typed in generates the example. A box emptied after typing stays empty.",
- "Prompt enhancement rewrites the prompt that was typed. With an empty box, turning it on asks for a prompt first.",
- "Replacing or clearing all of the enhanced text starts a new prompt, which is enhanced before generating. Small edits still adjust the enhanced version.",
- "FreeVideo reopens with the last prompt, finished, unfinished or emptied, and its enhancement setting.",
- "Installing into a folder whose path contains a space, such as \"Comfy UI\", stopped at the PyTorch step with \"File not found\". It installs normally now."
- ]
- },
- "zh": {
- "summary": "二次采样新增「先出预览」,作品可以删除,提示词框改进(示例提示词以灰色占位显示,重新打开时恢复上次的提示词),并修复安装路径含空格时无法安装的问题。",
- "changes": [
- "二次采样新增「先出预览」:先用半分辨率快速出一版预览,满意后点「继续二采」,成片与直接生成完全一致。可以批量出几版预览,在「作品」里挑一版继续二采。",
- "「作品」里可以删除不需要的视频,删除前会确认。",
- "示例提示词以灰色占位显示,直接输入即可替换,无需先清空;未输入过时按示例生成,输入后再清空则保持为空。",
- "提示词增强改写已输入的提示词。提示词框为空时开启增强,会提示先输入提示词。",
- "在改写版中全选替换或清空后重新输入,会作为新的提示词,生成前自动改写;局部修改仍只调整改写版。",
- "重新打开 FreeVideo 时恢复上次编写的提示词(包括未写完或已清空的内容)及增强设置。",
- "安装位置的路径中有空格(例如「Comfy UI」)时,安装会停在 PyTorch 步骤并报「File not found」。现在可以正常安装。"
- ]
- }
}
]
}
diff --git a/freevideo_engine/runtime.py b/freevideo_engine/runtime.py
index 417ea8c..7e6be6f 100644
--- a/freevideo_engine/runtime.py
+++ b/freevideo_engine/runtime.py
@@ -56,8 +56,11 @@ class Engine:
window_batch=1, linear_compute='native-fp8', input_cache_dir=None,
fp8_gemm='auto', window_varlen=False, varlen_smooth_k=True,
task='t2va', stream_weights=False, canvas=None, head_parallelism=1,
- residual_offload=False, device_backend=None):
+ residual_offload=False, device_backend=None, gpu_allocation_bytes=None):
self.device_backend = device_backend if device_backend is not None else get_backend()
+ if gpu_allocation_bytes is not None and (type(gpu_allocation_bytes) is not int or gpu_allocation_bytes < 0):
+ raise ValueError('GPU allocation limit must be a nonnegative byte count')
+ self.gpu_allocation_bytes = gpu_allocation_bytes
if self.device_backend.capabilities.name != 'cuda':
raise NotImplementedError('Engine model execution currently requires the CUDA backend')
from .media_request import TASKS
@@ -199,7 +202,8 @@ class Engine:
logical, reserved = self.device_backend.prepare_streamed_layer(block, streamed_source, index,
pin_budget_bytes=max(0, int(pin_host_gb * 1e9) - prepared_pins['reserved']),
headroom_bytes=self.weight_cache_headroom_bytes,
- nonlocal_reserve_bytes=self.nonlocal_reserve_bytes)
+ nonlocal_reserve_bytes=self.nonlocal_reserve_bytes,
+ commit_reserve_bytes=self.gpu_commit_reserve())
prepared_pins['logical'] += logical
prepared_pins['reserved'] += reserved
prepared_pins['seconds'] += time.perf_counter() - tick
@@ -371,13 +375,15 @@ class Engine:
pin_order = 'interleaved'
self.pinned_model_bytes = self.device_backend.pin_layer_weights(pin_layers, max_bytes=int(pin_host_gb * 1e9) if pin_host_gb else None,
headroom_bytes=host_headroom,
- nonlocal_reserve_bytes=self.nonlocal_reserve_bytes)
+ nonlocal_reserve_bytes=self.nonlocal_reserve_bytes,
+ commit_reserve_bytes=self.gpu_commit_reserve())
pin_seconds = time.perf_counter() - pin_start
self.pinned_host_allocated_bytes = self.device_backend.host_memory_stats()['allocated_bytes.current']
print(json.dumps({'event': 'host_weights_pinned', 'seconds': pin_seconds,
'logical_bytes': self.pinned_model_bytes,
'working_headroom_bytes': host_headroom,
'nonlocal_reserve_bytes': self.nonlocal_reserve_bytes,
+ 'gpu_commit_reserve_bytes': self.gpu_commit_reserve(),
'pin_order': pin_order,
'host_allocator_bytes': self.pinned_host_allocated_bytes}), flush=True)
if preload_host:
@@ -450,6 +456,13 @@ class Engine:
'varlen_smooth_k': varlen_smooth_k if window_varlen else None,
'steps': steps, 'source_id': manifest['source_id']}
+ def gpu_commit_reserve(self):
+ """Allocator room this request may still reserve, which WDDM will charge to commit."""
+ from .system import windows
+ if self.gpu_allocation_bytes is None or not windows():
+ return 0
+ return max(0, self.gpu_allocation_bytes - torch.cuda.memory_reserved())
+
@torch.no_grad()
def sample(self, *args, compute_options=None, **kwargs):
from .pass_configuration import configuration
diff --git a/freevideo_engine/worker.py b/freevideo_engine/worker.py
index 46c3831..1db4750 100644
--- a/freevideo_engine/worker.py
+++ b/freevideo_engine/worker.py
@@ -146,7 +146,11 @@ def generate(request, resident=None):
metrics['transformer_released_before_decode'] = resident is None or 'engine' not in resident.entries
else:
tick = time.perf_counter()
+ # Windows charges the allocator room still to be reserved to commit;
+ # the engine keeps that room out of its locked weights.
+ allocation = metrics['device_memory'].get('effective_allocator_limit_bytes') or request['gpu_budget_bytes']
factory = lambda: Engine(request['cache'], input_cache_dir=request.get('input_cache_dir'),
+ gpu_allocation_bytes=int(allocation),
**dict(options, canvas=request.get('geometry')))
engine, reused = resident.engine(request, factory) if resident is not None else (factory(), False)
loaded_seconds = time.perf_counter() - tick