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.

Report the text-encode room readings and resident models

Bowen Xue287c70c7c1e1
diff --git a/freevideo_engine/diagnostic_resources.py b/freevideo_engine/diagnostic_resources.py
index 6738492..a461459 100644
--- a/freevideo_engine/diagnostic_resources.py
+++ b/freevideo_engine/diagnostic_resources.py
@@ -342,6 +342,49 @@ def encoder_discard(value):
return {'encoder_discarded_without_cpu_copy': all(modes)} if modes else {}
+ROOM_READINGS = ('cuda_free_bytes', 'local_budget_bytes', 'local_usage_bytes', 'process_budget_bytes',
+ 'allocated_bytes', 'reserved_bytes')
+RESIDENT_ACTIONS = ('admit', 'reuse', 'evict', 'park', 'unpark', 'keep_declined')
+RESIDENT_ROLES = ('encoder', 'engine', 'video_vae', 'audio_vae', 'input_video_vae', 'input_audio_vae', 'latent_upscaler')
+RESIDENT_BYTES = ('gpu_bytes', 'estimated_peak_bytes', 'released_gpu_bytes', 'parked_bytes', 'moved_bytes',
+ 'device_ceiling_bytes')
+
+
+def room_readings(value):
+ value = mapping(value)
+ result = numbers(value, ROOM_READINGS)
+ if value.get('bound') in ('cuda_free', 'local_budget', 'process_budget'):
+ result['bound'] = value['bound']
+ return result
+
+
+def encoder_workspace(value):
+ """Text-encode room before and after making space: each reading and the bound that decided."""
+ rows = []
+ for raw in sequence(value)[:6]:
+ raw = mapping(raw)
+ row = numbers(raw, ('whole_need_bytes', 'blocks_need_bytes', 'capacity_bytes', 'need_bytes',
+ 'room_before_bytes', 'room_after_bytes', 'loaded_before_bytes', 'loaded_after_bytes',
+ 'unloaded_bytes'))
+ if raw.get('mode') in ('whole', 'blocks'):
+ row['mode'] = raw['mode']
+ for key in ('readings', 'readings_after'):
+ if isinstance(raw.get(key), dict):
+ row[key] = room_readings(raw[key])
+ rows.append(row)
+ return rows
+
+
+def resident_decisions(value):
+ """Which models were resident, admitted, kept or released around this request."""
+ rows = []
+ for raw in sequence(value)[-24:]:
+ raw = mapping(raw)
+ if raw.get('action') in RESIDENT_ACTIONS and raw.get('role') in RESIDENT_ROLES:
+ rows.append(dict(numbers(raw, RESIDENT_BYTES), action=raw['action'], role=raw['role']))
+ return rows
+
+
def sampling_checkpoint(value):
"""Keep completion and cleanup evidence without paths or free-form text."""
value = mapping(value)
diff --git a/freevideo_engine/diagnostic_summary.py b/freevideo_engine/diagnostic_summary.py
index dd9b232..cac5df2 100644
--- a/freevideo_engine/diagnostic_summary.py
+++ b/freevideo_engine/diagnostic_summary.py
@@ -202,6 +202,8 @@ def summary_report(report):
retry = diagnostic.mapping(encoding.get('diagnostic_retry'))
if type(retry.get('index')) is int and 1 <= retry['index'] <= 3:
result['encoder_resources']['retry'] = dict(index=retry['index'], final_attempt=retry.get('final_attempt') is True)
+ result['encoder_resources']['workspace'] = diagnostic.encoder_workspace(encoding.get('encoder_workspace'))
+ result['encoder_resources']['resident_models'] = diagnostic.resident_decisions(encoding.get('resident_admission'))
result['encoder_resources']['oom_attempts'] = []
for row in diagnostic.sequence(encoding.get('encoder_attempts'))[:3]:
row = diagnostic.mapping(row)
@@ -220,6 +222,7 @@ def summary_report(report):
result['worker_resources'] = diagnostic.resources(diagnostic.mapping(report.get('memory')).get('video'))
result['worker_resources'].update(diagnostic.encoder_discard(engine))
result['worker_resources'].update(diagnostic.sampling_checkpoint(engine))
+ result['worker_resources']['resident_models'] = diagnostic.resident_decisions(engine.get('resident_admission'))
if 'failure_cleanup' in engine:
result['worker_resources']['failure_cleanup'] = diagnostic.failure_cleanup(engine['failure_cleanup'])
# Keep the driver activity next to the kernel/backend receipt so a
diff --git a/freevideo_engine/encode_worker.py b/freevideo_engine/encode_worker.py
index 6704639..af34634 100644
--- a/freevideo_engine/encode_worker.py
+++ b/freevideo_engine/encode_worker.py
@@ -514,7 +514,7 @@ def _encode(args, request, resident, trace):
guard.arm()
from .encoder_memory import snapshot
phase('encoder_compute', load_seconds=load_seconds, device_load_seconds=transfer_seconds[0],
- gpu=snapshot(torch, clip, memory))
+ gpu=snapshot(torch, clip, memory, windows_memory=True))
print(json.dumps({'event': 'encoder_compute_start'}), flush=True)
if not encoder_cache_hit:
start_layer_window(trace, clip, path)
@@ -580,7 +580,7 @@ def _encode(args, request, resident, trace):
torch.cuda.synchronize()
from .encoder_memory import release_cast_buffers, snapshot
loading['cast_buffers'] = release_cast_buffers(memory, torch)
- phase('encoder_conditioning_pack', gpu=snapshot(torch, clip, memory))
+ phase('encoder_conditioning_pack', gpu=snapshot(torch, clip, memory, windows_memory=True))
finally:
del clip.load_model
stop_layer_window(trace)
diff --git a/freevideo_engine/encoder_workspace.py b/freevideo_engine/encoder_workspace.py
index 4589494..31e5392 100644
--- a/freevideo_engine/encoder_workspace.py
+++ b/freevideo_engine/encoder_workspace.py
@@ -152,24 +152,38 @@ class Workspace:
pass # Learning only refines the bound; the encode itself does not depend on it.
-def dedicated_room(torch, reader=None, budget=None):
+def dedicated_room(torch, reader=None, budget=None, detail=None):
"""Bytes a new allocation can use without leaving dedicated VRAM or this request's budget.
PyTorch's cached free blocks count. cudaMemGetInfo is not the WDDM budget:
after a load that left 1.9 GiB by its count, the 4060 Ti above reported no
free memory at all, so on Windows the DXGI budget bounds it as well.
`budget` is what this process may hold in total under FreeVideo's plan.
+ `detail`, when given, receives each reading and which bound decided.
"""
free = torch.cuda.mem_get_info()[0]
+ bound = 'cuda_free'
+ if detail is not None:
+ detail['cuda_free_bytes'] = int(free)
if reader is not None:
try:
local = reader.sample()['local']
- free = min(free, max(0, local['budget_bytes'] - local['usage_bytes']))
+ window = max(0, local['budget_bytes'] - local['usage_bytes'])
+ if detail is not None:
+ detail.update(local_budget_bytes=int(local['budget_bytes']), local_usage_bytes=int(local['usage_bytes']))
+ if window < free:
+ free, bound = window, 'local_budget'
except (OSError, KeyError):
pass
- room = free + torch.cuda.memory_reserved() - torch.cuda.memory_allocated()
+ allocated, reserved = torch.cuda.memory_allocated(), torch.cuda.memory_reserved()
+ room = free + reserved - allocated
if budget is not None:
- room = min(room, budget - torch.cuda.memory_allocated())
+ if budget - allocated < room:
+ room, bound = budget - allocated, 'process_budget'
+ if detail is not None:
+ detail['process_budget_bytes'] = int(budget)
+ if detail is not None:
+ detail.update(allocated_bytes=int(allocated), reserved_bytes=int(reserved), bound=bound)
return int(max(0, room))
@@ -185,12 +199,15 @@ def adapter_reader():
def make_room(patcher, torch, need, reader=None, budget=None):
"""Move loaded weights back to host memory until `need` bytes of dedicated VRAM are free."""
- before = dedicated_room(torch, reader, budget)
- result = dict(need_bytes=int(need), room_before_bytes=before, loaded_before_bytes=int(patcher.loaded_size()))
+ readings = {}
+ before = dedicated_room(torch, reader, budget, readings)
+ result = dict(need_bytes=int(need), room_before_bytes=before, loaded_before_bytes=int(patcher.loaded_size()),
+ readings=readings)
if before < need:
unloaded = patcher.partially_unload(patcher.offload_device, need - before)
- result.update(unloaded_bytes=int(unloaded or 0), room_after_bytes=dedicated_room(torch, reader, budget),
- loaded_after_bytes=int(patcher.loaded_size()))
+ after = {}
+ result.update(unloaded_bytes=int(unloaded or 0), room_after_bytes=dedicated_room(torch, reader, budget, after),
+ loaded_after_bytes=int(patcher.loaded_size()), readings_after=after)
return result