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.

Record the RAM FreeVideo itself holds in resource refusals and feedback

Bowen Xued25e2288acd5
diff --git a/freevideo_engine/diagnostic_resources.py b/freevideo_engine/diagnostic_resources.py
index a461459..c53a765 100644
--- a/freevideo_engine/diagnostic_resources.py
+++ b/freevideo_engine/diagnostic_resources.py
@@ -751,6 +751,10 @@ def planning(rows):
item[key] = numbers(row.get(key), HARDWARE_MEMORY)
item['system_memory'] = numbers(row.get('system_memory'),
('total_bytes', 'available_bytes', 'physical_available_bytes', 'commit_available_bytes'))
+ from .exit_diagnostics import OWN_MEMORY_KEYS
+ own = numbers(row.get('own_memory'), OWN_MEMORY_KEYS)
+ if own:
+ item['own_memory'] = own
for key in ('budget_bytes', 'reserve_bytes'):
item[key] = numbers(row.get(key), ('gpu', 'ram'))
item['resource_error'] = numbers(row.get('resource_error'), tuple(resource + '_' + field
diff --git a/freevideo_engine/exit_diagnostics.py b/freevideo_engine/exit_diagnostics.py
index a7be152..644582b 100644
--- a/freevideo_engine/exit_diagnostics.py
+++ b/freevideo_engine/exit_diagnostics.py
@@ -19,6 +19,8 @@ _SYSTEM_STATUS = {
}
_CRASH_PREFIXES = (0xC0000000, 0x80000000)
_FIELDS = ('physical_available_bytes', 'commit_available_bytes', 'commit_limit_bytes', 'total_bytes')
+OWN_MEMORY_KEYS = ('own_private_working_set_bytes', 'own_processes', 'own_unreadable_processes',
+ 'host_private_working_set_bytes', 'resident_private_working_set_bytes')
def _count(value):
@@ -58,6 +60,56 @@ def memory_sample(pid=None):
return {key: sample[key] for key in sample if sample[key] is not None}
+def own_memory(pid=None):
+ """Physical RAM held by this process tree and by the largest process above it (Windows).
+
+ A refusal says how much memory the system had left; this says how much of
+ what was taken is FreeVideo's. The numbers are private working sets, which
+ exclude mapped files, so they can be compared with free physical RAM. The
+ tree is the generation process and its children; the resident worker is
+ started by the host and is added by the caller from its own status. The
+ host figure is the largest of up to four ancestors (a launcher gate is
+ small, the program that started it is not). Processes that cannot be read
+ are counted, never taken as zero; if the process itself cannot be read
+ nothing is returned. Other platforms give nothing; the function never raises.
+ """
+ if not windows():
+ return {}
+ pid = os.getpid() if pid is None else pid
+ result = {}
+ try:
+ from .win32 import ProcessMemory, processes, process_memory
+ reading = ProcessMemory().sample(pid)
+ unreadable = reading.get('unreadable_memory_pids') or []
+ if not reading.get('processes') or pid in unreadable:
+ return {}
+ result.update(own_private_working_set_bytes=reading['private_working_set_bytes'],
+ own_processes=reading['processes'])
+ if unreadable:
+ result['own_unreadable_processes'] = len(unreadable)
+ except Exception:
+ return {}
+ try:
+ parents = processes()
+ seen, node, largest = {pid}, parents.get(pid), None
+ for _ in range(4):
+ if not node or node in seen:
+ break
+ seen.add(node)
+ try:
+ row = process_memory(node)
+ except Exception:
+ row = None
+ if row and _count(row.get('private_working_set_bytes')) is not None:
+ largest = max(largest or 0, row['private_working_set_bytes'])
+ node = parents.get(node)
+ if largest is not None:
+ result['host_private_working_set_bytes'] = largest
+ except Exception:
+ pass
+ return {key: value for key, value in result.items() if _count(value) is not None}
+
+
def exit_reading(code, *, requested_stop=False, system=None):
"""The exit code as given, a fixed-word class and whether the system probably ended it.
diff --git a/freevideo_engine/feedback.py b/freevideo_engine/feedback.py
index d34d065..6acb6b6 100644
--- a/freevideo_engine/feedback.py
+++ b/freevideo_engine/feedback.py
@@ -6,6 +6,8 @@ settings and timings. No prompt, reference or picture is read here.
import json
import re
+from .exit_diagnostics import OWN_MEMORY_KEYS
+
# The summary travels in a GitHub page address, which has to stay short.
MAX_DIAGNOSTICS = 3000
# Anything that looks like a file location or a long secret-like token is replaced.
@@ -45,6 +47,9 @@ def summary(report, machine=None):
memory = planning[-1].get('system_memory') if isinstance(planning, list) and planning and isinstance(planning[-1], dict) else None
if isinstance(memory, dict):
memory = {k: memory[k] for k in MEMORY_KEYS if type(memory.get(k)) is int}
+ own = planning[-1].get('own_memory')
+ if isinstance(own, dict):
+ memory.update({k: own[k] for k in OWN_MEMORY_KEYS if type(own.get(k)) is int})
if memory:
out['memory'] = memory
errors = analysis.get('errors')
diff --git a/freevideo_engine/generate.py b/freevideo_engine/generate.py
index ff599ce..3355497 100644
--- a/freevideo_engine/generate.py
+++ b/freevideo_engine/generate.py
@@ -287,6 +287,15 @@ def automatic_profile(args, canvas, *, stage, evidence, descriptor=None, environ
mapped_bytes=mapped if type(mapped) is int else None,
commit_available_bytes=commit if type(commit) is int else None)
except ResourceBudgetError as error:
+ from .exit_diagnostics import own_memory
+ own = dict(own_memory())
+ resident = ((state or {}).get('memory') or {})
+ if (resident.get('guard_metric') == 'tree private working set'
+ and type(resident.get('guard_bytes')) is int and resident['guard_bytes'] >= 0):
+ own['resident_private_working_set_bytes'] = resident['guard_bytes']
+ if own:
+ error.add_own_memory(own)
+ row['own_memory'] = own
row.update(status='rejected', resource_error=error.details)
error.resource_planning = evidence
impossible_capacity = any(error.details[name+'_capacity_bytes'] - error.details[name+'_reserve_bytes']
diff --git a/freevideo_engine/policy.py b/freevideo_engine/policy.py
index 01d4b23..d7ea624 100644
--- a/freevideo_engine/policy.py
+++ b/freevideo_engine/policy.py
@@ -622,6 +622,22 @@ class ResourceBudgetError(ValueError):
lines.append('Available memory includes validated idle-cache credit, if present. Resolution, frames and steps were not reduced.')
super().__init__('\n'.join(lines))
+ def add_own_memory(self, own):
+ """Say how much of the physical RAM already taken is FreeVideo's own."""
+ self.details.update(own)
+ parts = []
+ if 'own_private_working_set_bytes' in own:
+ partial = own.get('own_unreadable_processes', 0)
+ parts.append('FreeVideo\'s generation processes hold %s%.2f GiB of private physical RAM (%d processes%s)' %
+ ('at least ' if partial else '', own['own_private_working_set_bytes'] / GiB,
+ own.get('own_processes', 0), ', %d unreadable' % partial if partial else ''))
+ if 'resident_private_working_set_bytes' in own:
+ parts.append('FreeVideo\'s resident worker holds %.2f GiB' % (own['resident_private_working_set_bytes'] / GiB))
+ if 'host_private_working_set_bytes' in own:
+ parts.append('the largest process above the generation process holds %.2f GiB' % (own['host_private_working_set_bytes'] / GiB))
+ if parts:
+ parts[0] = parts[0][0].upper() + parts[0][1:]
+ self.args = ('%s\n%s.' % (self.args[0], '; '.join(parts)),)
def feasible_alternatives(hardware, canvas, **options):