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.
"""Disk estimates and live guards for the automatic Windows space saver."""
from pathlib import Path
import hashlib
import json
from .long_paths import io_path, resolved
from . import disk_space
GiB = 1 << 30
SPACE_FLOOR = 2 * GiB
def existing(path):
path = Path(path)
while not path.exists() and path != path.parent:
path = path.parent
return path
def add(disks, path, amount):
parent = existing(path)
# Volumes of one APFS container share their free space.
key = disk_space.disk_key(parent)
if key not in disks:
disks[key] = dict(paths=[], needed_bytes=0, free_bytes=disk_space.free_bytes(parent))
disk = disks[key]
if str(parent) not in disk['paths']:
disk['paths'].append(str(parent))
disk['needed_bytes'] += amount
def errors(disks):
return [('Insufficient disk space: need %.2f GiB, available %.2f GiB, short %.2f GiB · %s' %
(d['needed_bytes'] / GiB, d['free_bytes'] / GiB,
(d['needed_bytes'] - d['free_bytes']) / GiB, ', '.join(d['paths'])))
for d in disks if d['needed_bytes'] > d['free_bytes']]
def frontend_ready(root, frontend):
"""An interrupted engine install can already have a completed frontend."""
try:
root, comfy = Path(root), Path(frontend['root'])
record = json.loads((root / 'launcher' / 'comfy-host.json').read_text(encoding='utf-8'))
identity = record['identity']
env_root = Path(record['environment'])
return (env_root.resolve().parent == (root / 'envs').resolve()
and Path(record['python']).is_file()
and Path(record['python']).resolve().is_relative_to(env_root.resolve())
and Path(identity['engine_python']).resolve() == (root / 'envs/unified/Scripts/python.exe').resolve()
and Path(identity['comfy']).resolve() == comfy.resolve()
and identity['requirements'] == hashlib.sha256((comfy / 'requirements.txt').read_bytes()).hexdigest()
and json.loads((env_root / 'freevideo-host.json').read_text(encoding='utf-8')) == identity)
except (OSError, ValueError, KeyError, TypeError):
return False
# Adding missing packages to the launcher's existing ComfyUI environment: at
# most a whole Windows PyTorch reinstalled as a copy, a 1.78 GiB wheel plus
# about 4.5 GB installed (the cuDNN repair).
FRONTEND_IN_PLACE_GIB = 5
def frontend_in_place(root, comfy):
"""The launcher's ComfyUI environment for this ComfyUI exists: setup repairs or updates it in place."""
try:
root, comfy = io_path(root), io_path(comfy)
record = json.loads((root / 'launcher' / 'comfy-host.json').read_text(encoding='utf-8'))
environment = io_path(record['environment'])
identity = json.loads((environment / 'freevideo-host.json').read_text(encoding='utf-8'))
return (environment.resolve().parent == (root / 'envs').resolve() and io_path(record['python']).is_file()
and resolved(identity['comfy']) == comfy.resolve())
except (OSError, ValueError, KeyError, TypeError):
return False
def frontend_gib(root, comfy, mac):
"""Disk for a separate ComfyUI environment: a new one, or packages added to the existing one."""
gib = disk_space.frontend_gib(mac)
return min(gib, FRONTEND_IN_PLACE_GIB) if frontend_in_place(root, comfy) else gib
def budget(groups, root, normal_extra, *, eligible, environments_ready, frontend=None, keep_extreme=False,
frontend_gib=12):
"""Estimate each volume for the selected installation strategy."""
frontend = frontend or {}
def estimate(extreme):
disks = {}
for group in groups.values():
add(disks, group['path'], group['needed_bytes'] - (group.get('resume_bytes', 0) if extreme else 0))
extra = (1 if environments_ready else 6) if extreme else normal_extra
add(disks, root, extra * GiB)
if frontend.get('separate') and not (extreme and frontend_ready(root, frontend)):
add(disks, root, (3 if extreme else frontend_gib) * GiB)
if frontend.get('download') and not Path(frontend['root']).exists():
add(disks, frontend['root'], GiB)
if extreme:
for disk in disks.values():
disk['needed_bytes'] += SPACE_FLOOR
return list(disks.values()), extra + (2 if extreme else 0)
normal, extra = estimate(False)
extreme = eligible and (keep_extreme or bool(errors(normal)))
disks, extra = estimate(True) if extreme else (normal, extra)
return dict(mode='extreme' if extreme else 'normal', disks=disks,
environment_cache_safety_gib=extra, errors=errors(disks),
ordinary_needed_bytes=sum(d['needed_bytes'] for d in normal),
safety_bytes_per_volume=SPACE_FLOOR if extreme else 0)
def environment(root, env):
"""Bound package expansion and keep its temporary files on the chosen disk."""
temporary = Path(root) / 'downloads' / 'install-temp'
temporary.mkdir(parents=True, exist_ok=True)
return dict(env, UV_CONCURRENT_DOWNLOADS='1', UV_CONCURRENT_INSTALLS='1',
UV_CONCURRENT_BUILDS='1', UV_LINK_MODE='hardlink',
TMP=str(temporary), TEMP=str(temporary), TMPDIR=str(temporary))
def check_floor(paths):
seen = set()
for path in paths:
parent = existing(path)
device = disk_space.disk_key(parent)
if device in seen:
continue
seen.add(device)
free = disk_space.free_bytes(parent)
if free < SPACE_FLOOR:
raise RuntimeError('Space-saving installation paused: less than 2 GiB free on %s '
'(%.2f GiB available). Free space and resume; downloaded files are retained.' %
(parent, free / GiB))
def check_models(entries, replacements=()):
"""Recheck actual free disk AFTER package cleanup, before writing any models."""
disks = {}
for row, path, _, local in entries:
remaining = row['bytes']
if str(path) in replacements:
pass # The approved original stays on disk; budget a full new download.
elif path.is_file() and path.stat().st_size == remaining:
remaining = 0 # provision still verifies its pinned content.
elif local and local.get('method') == 'hardlink':
remaining = 0
else:
partial = path.with_suffix(path.suffix + '.partial')
if partial.is_file() and partial.stat().st_size <= remaining:
remaining -= partial.stat().st_size
add(disks, path.parent, remaining)
for disk in disks.values():
disk['needed_bytes'] += SPACE_FLOOR
problems = errors(disks.values())
if problems:
raise RuntimeError('\n'.join(problems) + '\nFree space and resume; installed components and downloaded files are retained.')