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 the model warm only when the card's use can be read; drop the unused release parameter

Bowen Xueba3de55010d4
diff --git a/freevideo_engine/agent/guide.py b/freevideo_engine/agent/guide.py
index a61ea51..863c650 100644
--- a/freevideo_engine/agent/guide.py
+++ b/freevideo_engine/agent/guide.py
@@ -128,6 +128,10 @@ GUIDE = {
'without studio prompts. POST /jobs/{id}/cancel cancels only this job.',
'POST /jobs/{id}/resume continues failed, interrupted or cancelled generation; successful blocks stay. '
'refine_from is the separate preview second pass. Active or succeeded jobs cannot resume.',
+ 'After a video the model stays on the graphics card and in memory for up to ten minutes, so the next '
+ 'video starts quickly; it goes at once when another program needs the memory. An agent that runs its own '
+ 'model on the same card between videos (for example to check a result) calls POST /gpu/release (MCP freevideo_release_gpu) first '
+ '(it answers released=false while a video is running), or sets release_gpu_after=true on the generate job.',
'Results include the joined library_id and each block library_id/report_id. Fetch videos and thumbnails '
'with the token at /library/{day}/{run}/file and /thumbnail. MCP freevideo_asset and CLI agent asset use HTTP.',
],
@@ -309,6 +313,7 @@ CAPABILITIES_ZH = {
('GET', '/jobs/{id}'): '查看任务进度和结果',
('GET', '/jobs/{id}/events'): '持续接收任务进度',
('POST', '/jobs/{id}/cancel'): '取消任务',
+ ('POST', '/gpu/release'): '空闲时释放显存和内存里的视频模型',
('POST', '/jobs/{id}/resume'): '接着生成一条视频里还没完成的部分',
('POST', '/media'): '上传图片、视频或音频内容',
('POST', '/imports'): '导入视频或音频到剪辑时间线;轮询 GET /imports 等待就绪',
diff --git a/freevideo_engine/agent/jobs.py b/freevideo_engine/agent/jobs.py
index 80bd5db..46cae3b 100644
--- a/freevideo_engine/agent/jobs.py
+++ b/freevideo_engine/agent/jobs.py
@@ -714,6 +714,10 @@ class Jobs:
self.retry_pending()
return
row.update(status=status, finished_at=self.clock(), updated_at=self.clock())
+ if row['kind'] == 'generate' and row.get('spec', {}).get('release_gpu_after') is True:
+ # The agent runs another model on this card next. Off the lock: stopping the worker takes a moment.
+ from ..resident_process import OWNER
+ threading.Thread(target=OWNER.release_idle, args=('agent_requested',), name='freevideo-release-gpu', daemon=True).start()
if result is not None:
row['result'] = result
if error is not None:
diff --git a/freevideo_engine/agent/mcp.py b/freevideo_engine/agent/mcp.py
index 1b2ae34..13c6087 100644
--- a/freevideo_engine/agent/mcp.py
+++ b/freevideo_engine/agent/mcp.py
@@ -66,6 +66,7 @@ def tool_list():
dict(name='freevideo_ask', title='Ask the local VLM', description='Ask FreeVideo\'s local vision-language model about images or sampled frames of a video (e.g. "Does this shot match its description? Answer as JSON {score, issues}").', annotations=write),
dict(name='freevideo_enhance_prompt', title='Enhance a prompt', description='Rewrite a rough idea (any language) into a complete H3 prompt with the local VLM. Images become <Picture N> references.', annotations=write),
dict(name='freevideo_assemble', title='Assemble clips', description='Join finished clips (job ids, saved video ids or files) into one video with cuts or crossfades; trims with start/end.', annotations=write),
+ dict(name='freevideo_release_gpu', title='Release the card', description='Free the graphics card and memory the video model holds; call before running another model. released=false while a video runs.', annotations=write),
dict(name='freevideo_library', title='Saved videos', description='Saved FreeVideo videos, newest first, with prompts and the agent job that made them.', annotations=read)]
from .schema import DRAMA_OPERATIONS
rows.extend(dict(name='freevideo_drama_' + name, title='Film: ' + name, description=summary,
@@ -415,6 +416,8 @@ class Server:
if name == 'freevideo_edit_image':
made = c.edit(args['source'], args.get('recipe'), document=args.get('document'), target=args.get('target'))
return made, self.picture(made['view'])
+ if name == 'freevideo_release_gpu':
+ return c.post('/gpu/release', {}), []
if name == 'freevideo_library':
return c.library(**args), []
if name == 'freevideo_look':
diff --git a/freevideo_engine/agent/routes.py b/freevideo_engine/agent/routes.py
index 28ff660..3753ca7 100644
--- a/freevideo_engine/agent/routes.py
+++ b/freevideo_engine/agent/routes.py
@@ -178,7 +178,7 @@ def features(continuation, vlm):
return {'capabilities': True, 'plan': True, 'jobs.cancel': True, 'jobs.resume': True, 'takes': True,
'library.read': True, 'library.download': True, 'imports.create': True, 'imports.read': True,
'errors.validation': True, 'errors.missing_media': True,
- 'generate.text': True, 'generate.size': True, 'generate.first_frame': True, 'generate.seed': True,
+ 'gpu.release': True, 'generate.text': True, 'generate.size': True, 'generate.first_frame': True, 'generate.seed': True,
'queue.shared': True, 'queue.busy': True, 'chain.auto': bool(continuation),
'enhance': bool(vlm.get('ready')), 'drama.film': True, 'images.edit': rules,
'images.layers': rules, 'images.heal': rules, 'images.render': rules, 'projects.read': True,
@@ -1464,6 +1464,12 @@ def register():
row = await asyncio.to_thread(jobs.get, request.match_info['id'])
return reply(job_answer(await wait_for_job(jobs, row, float(request[query_key].get('wait', '0') or 0))))
+ @routes.post(PREFIX + '/gpu/release')
+ @guarded
+ async def gpu_release(request):
+ from ..resident_process import OWNER
+ return reply(await asyncio.to_thread(OWNER.release_idle, 'agent_requested'))
+
@routes.post(PREFIX + '/jobs/{id}/cancel')
@guarded
async def cancel(request):
diff --git a/freevideo_engine/agent/schema.py b/freevideo_engine/agent/schema.py
index 066a752..afafd0a 100644
--- a/freevideo_engine/agent/schema.py
+++ b/freevideo_engine/agent/schema.py
@@ -186,6 +186,7 @@ def generate(*, local=False):
obj(dict(name=string(512, pattern=r'^.+\.[sS][aA][fF][eE][tT][eE][nN][sS][oO][rR][sS]$'),
strength=number(-4, 4, default=1)), ('name',))]}, default=[]),
preview={'type': 'boolean', 'default': False},
+ release_gpu_after={'type': 'boolean', 'default': False},
refine_from=nullable({'oneOf': [JOB, SAVED]}), force_regenerate={'type': 'boolean', 'default': False},
continue_from={'oneOf': [obj({'from_job': JOB}, ('from_job',)), obj({'library': SAVED}, ('library',))]},
first_frame_reference={'type': 'boolean', 'default': False, 'description':
@@ -382,6 +383,8 @@ def contracts(*, local=False):
('GET', '/jobs/{id}'): route('Read job progress and result', query=obj({'wait': WAIT})),
('GET', '/jobs/{id}/events'): route('Watch job progress'),
('POST', '/jobs/{id}/cancel'): route('Cancel a job', body=EMPTY, optional_body=True),
+ ('POST', '/gpu/release'): route('Release the video model from the graphics card and memory when idle',
+ body=EMPTY, optional_body=True),
('POST', '/jobs/{id}/resume'): route('Resume unfinished generation blocks', body=obj({'ref': REF}),
optional_body=True, idempotent=True),
('POST', '/media'): route('Upload image, video or audio content',
@@ -1503,6 +1506,7 @@ TOOL_ENDPOINTS = {
'freevideo_resume': ('POST', '/jobs/{id}/resume'), 'freevideo_add_media': ('POST', '/media'),
'freevideo_import_media': ('POST', '/imports'), 'freevideo_imports': ('GET', '/imports'),
'freevideo_edit_image': ('POST', '/media/edit'), 'freevideo_library': ('GET', '/library'),
+ 'freevideo_release_gpu': ('POST', '/gpu/release'),
}
TOOL_ENDPOINTS.update({'freevideo_drama_' + name: (method, suffix)
for name, (method, suffix, _) in DRAMA_OPERATIONS.items()})
@@ -1521,7 +1525,7 @@ TOOL_KINDS = dict(freevideo_generate='generate', freevideo_assemble='assemble',
SESSION_ARGUMENT = dict(type='string', pattern='^s[0-9a-f]{12}$',
- description='Work session; omit for your latest.')
+ description='Work session; omit for latest.')
SHAPE_MIN_BYTES = 400
diff --git a/freevideo_engine/agent/spec.py b/freevideo_engine/agent/spec.py
index 76c7bf8..8fe24d3 100644
--- a/freevideo_engine/agent/spec.py
+++ b/freevideo_engine/agent/spec.py
@@ -226,6 +226,8 @@ def normalize(value, *, port=None):
result = dict(kind=kind, **_common(value))
if kind == 'generate':
result['force_regenerate'] = value['force_regenerate']
+ if value.get('release_gpu_after'):
+ result['release_gpu_after'] = True
if value.get('refine_from'):
ref = value['refine_from']
result['refine_from'] = {'from_job' if JOB_ID.fullmatch(ref) else 'library': ref}
diff --git a/freevideo_engine/comfy_nodes.py b/freevideo_engine/comfy_nodes.py
index 0f5dff6..3ee95e3 100644
--- a/freevideo_engine/comfy_nodes.py
+++ b/freevideo_engine/comfy_nodes.py
@@ -364,8 +364,8 @@ class FreeVideoGenerate(io.ComfyNode):
server = PromptServer.instance
def busy():
return server is not None and server.prompt_queue.get_tasks_remaining() > 0
- # Keep the models only while the next part is on its way; otherwise give
- # the memory back now and let the file cache make the next load quick.
+ # A finished request keeps the models for the next one while memory is ample;
+ # a failed one, a tight host or another program's growth gives it back at once.
try:
# The running prompt is this one; only prompts still waiting are a next part.
queued = server is not None and bool(server.prompt_queue.get_current_queue()[1])
@@ -383,7 +383,7 @@ class FreeVideoGenerate(io.ComfyNode):
gpu = comfy_bridge.installation()[1].get('gpu_uuid')
except (OSError, ValueError, KeyError, TypeError):
gpu = None
- OWNER.finished(next_part=next_part, gpu=gpu,
+ OWNER.finished(next_part=next_part, gpu=gpu, warm=True,
agent=server is not None and str(getattr(server, 'client_id', '') or '').startswith('agent:'))
if target and not result_reused[0]:
client = server.client_id if server is not None else None
diff --git a/freevideo_engine/resident_process.py b/freevideo_engine/resident_process.py
index cb21171..1720dd3 100644
--- a/freevideo_engine/resident_process.py
+++ b/freevideo_engine/resident_process.py
@@ -23,12 +23,16 @@ from .monitoring import save
ENV = 'FREEVIDEO_RESIDENT_SESSION'
GiB = 2**30
-# A finished request releases the worker unless its next part is already on the
-# way. Then it is kept briefly, and given up at once when anything else needs
-# the memory: another program's GPU use grows, host memory runs low, or an
-# image or prompt model starts (those release it themselves).
+# A finished request keeps the worker for the next one while host memory is ample
+# (KEEP_IDLE_SECONDS idle at most), and it is given up at once when anything else
+# needs the memory: another program's GPU use grows, host memory runs low, an
+# image or prompt model starts (those release it themselves), or the agent asks
+# for the card back. A request that is not followed by a queued part and fails,
+# or a machine without the room, releases it as before; a next part already on
+# its way is held for HOLD_SECONDS.
HOLD_SECONDS = 90.
AGENT_HOLD_SECONDS = 30.
+KEEP_IDLE_SECONDS = 600.
OTHER_GPU_GROWTH = 512 * 2**20
HOST_FLOOR = 4 * GiB
# Below this much host memory (free plus the idle worker's own), a kept worker's
@@ -377,12 +381,19 @@ class SessionOwner:
rows, self.decisions = self.decisions, []
return rows
- def finished(self, *, next_part=None, agent=False, gpu=None):
- """Release the idle worker now, or keep it while a next part is on its way."""
+ def finished(self, *, next_part=None, agent=False, gpu=None, warm=False):
+ """Release the idle worker now, or keep it for the next request.
+
+ A successful request (warm) keeps it while host memory is ample and the card's use can be read, so
+ another program's growth is seen; a next part on its way keeps it for a short hold. Anything else
+ gives the memory back now.
+ """
with self.mutex:
if self.active or self.process is None or self.process.poll() is not None:
return None
hold = min(HOLD_SECONDS, AGENT_HOLD_SECONDS) if agent else HOLD_SECONDS
+ if not next_part and warm and gpu_used(gpu) is not None:
+ hold, next_part = KEEP_IDLE_SECONDS, 'warm'
if not next_part or hold <= 0:
return self.release('finished' if not next_part else 'no_hold')
reason = pressure(gpu, None) or self._tight()
@@ -395,6 +406,17 @@ class SessionOwner:
name='freevideo-resident-hold', daemon=True).start()
return self.record(action='kept', reason=next_part, seconds=hold, pid=self.process.pid)
+ def release_idle(self, reason='requested'):
+ """Give the card and host memory back on a caller's request; never touches a running request."""
+ with self.mutex:
+ if self.active:
+ return dict(released=False, reason='busy')
+ if self.process is None or self.process.poll() is not None:
+ return dict(released=False, reason='nothing_held')
+ row = self.release(reason)
+ return dict(released=True, reason=reason, **{k: v for k, v in (row or {}).items()
+ if k in ('idle_seconds', 'worker_rss_bytes')})
+
def _tight(self):
from .system import windows
if windows():