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.
Engine: per-card device index, PCI bus device order and card fields in the report
Bowen Xuec0617eae0026
diff --git a/freevideo_engine/bootstrap.py b/freevideo_engine/bootstrap.pyindex f2da233..8dba831 100644--- a/freevideo_engine/bootstrap.py+++ b/freevideo_engine/bootstrap.py@@ -1330,6 +1330,7 @@ class Installer:from .triton_compat import environmentreturn environment(self.root, dict(env,CUDA_VISIBLE_DEVICES=self.plan['inventory']['selected_gpu']['uuid'],+ CUDA_DEVICE_ORDER='PCI_BUS_ID',TRITON_CACHE_DIR=str(self.root / 'kernel-cache' / 'triton'),CUDA_CACHE_PATH=str(self.root / 'kernel-cache' / 'cuda'),TORCHINDUCTOR_CACHE_DIR=str(self.root / 'kernel-cache' / 'inductor')))diff --git a/freevideo_engine/device_index.py b/freevideo_engine/device_index.pynew file mode 100644index 0000000..d5a014c--- /dev/null+++ b/freevideo_engine/device_index.py@@ -0,0 +1,38 @@+"""The CUDA device this process works on, instead of an assumed device 0.++An engine child normally sees one card through CUDA_VISIBLE_DEVICES, where the+current device is 0, so these helpers return what the hardcoded 0 did. They keep+budgets, probes and workers on the card the process owns when more than one is visible.+"""+++def active_index(torch):+ try:+ return torch.cuda.current_device()+ except (AttributeError, RuntimeError, AssertionError):+ return 0 # No device context to ask: the first (only) visible card.+++def active_name(torch):+ return 'cuda:%d' % active_index(torch)+++def device_properties(torch):+ return torch.cuda.get_device_properties(active_index(torch))+++def card_report(hardware):+ """The card this request ran on, as report fields; never fails the request."""+ import os+ import sys+ result = dict(gpu_uuid=getattr(hardware, 'gpu_uuid', None), device_order=os.environ.get('CUDA_DEVICE_ORDER'))+ visible = [part for part in (os.environ.get('CUDA_VISIBLE_DEVICES') or '').split(',') if part.strip()]+ result['visible_device_count'] = len(visible) or None+ try:+ # The lightweight parent must not open a CUDA context; only read a context that already exists.+ torch = sys.modules.get('torch')+ if torch is not None and torch.cuda.is_initialized():+ result.update(device_index=active_index(torch), visible_device_count=torch.cuda.device_count())+ except Exception:+ pass+ return resultdiff --git a/freevideo_engine/generate.py b/freevideo_engine/generate.pyindex a2cac74..1e32088 100644--- a/freevideo_engine/generate.py+++ b/freevideo_engine/generate.py@@ -668,6 +668,8 @@ def _run(args):else canvas['frames'] - hide_tail_frames)from .support_report import code_identity, write as write_debugreport['runtime_hardware'] = hardware.to_dict()+ from .device_index import card_report+ report['gpu_card'] = card_report(hardware)report['runtime_code'] = code_identity()started = time.perf_counter()applied = Nonediff --git a/freevideo_engine/gpu_budget.py b/freevideo_engine/gpu_budget.pyindex e04733e..505db7c 100644--- a/freevideo_engine/gpu_budget.py+++ b/freevideo_engine/gpu_budget.py@@ -2,6 +2,7 @@import mathimport threadingimport time+from .device_index import device_propertiesfrom .system import windows_trial_allocator_owner = None@@ -14,7 +15,7 @@ def owned_pool_capacity(torch):of the resident worker's pool has already been included by the driver.Use the same owner/context and bounds as allocator admission instead."""- total = torch.cuda.get_device_properties(0).total_memory+ total = device_properties(torch).total_memoryfree, _ = torch.cuda.mem_get_info()reserved = torch.cuda.memory_reserved()local, reader = None, None@@ -71,7 +72,7 @@ def configure(torch, budget_bytes, explicit_limit=None, *, reserve_bytes=0, syst"""global _trial_allocator_ownerfrom .policy import memory_fraction- total = torch.cuda.get_device_properties(0).total_memory+ total = device_properties(torch).total_memoryplanned = memory_fraction(budget_bytes, total)if explicit_limit is not None and (type(explicit_limit) is not int or not 0 < explicit_limit <= total):raise ValueError('Benchmark allocator limit must be positive and no larger than physical VRAM')diff --git a/freevideo_engine/portable.py b/freevideo_engine/portable.pyindex f58309b..86381c6 100644--- a/freevideo_engine/portable.py+++ b/freevideo_engine/portable.py@@ -260,6 +260,7 @@ def connect(root, value, machine, progress=lambda **kw: None, cancelled=None, *,# CUDA UUIDs survive a Windows display-adapter order change. The host and# its engine children must see the same device that passed initialization.os.environ['CUDA_VISIBLE_DEVICES'] = machine['gpu_uuid']+ os.environ['CUDA_DEVICE_ORDER'] = 'PCI_BUS_ID'if cancelled is not None:controller.cancelled = cancelledif cancelled.is_set():diff --git a/freevideo_engine/prompt_vlm/worker.py b/freevideo_engine/prompt_vlm/worker.pyindex 90fe5d7..fe358a0 100644--- a/freevideo_engine/prompt_vlm/worker.py+++ b/freevideo_engine/prompt_vlm/worker.py@@ -301,12 +301,14 @@ def load_model(folder, torch, stats, checkpoint):available = stats['available_memory_at_start_bytes' if resident else 'available_memory_before_load_bytes']if available < stats['ram_required_bytes']:raise ValueError('ram_space')+ from ..device_index import active_index+ card = active_index(torch)checkpoint('load_weights')loading = time.monotonic()if resident:from .load import resident as load_resident- model = load_resident(folder, torch, 'cuda:0', resident, keep)- mapping, device = {'': 0}, 'cuda:0'+ model = load_resident(folder, torch, 'cuda:%d' % card, resident, keep)+ mapping, device = {'': card}, 'cuda:%d' % cardstats.update(weights=resident, kv_positions=kv_positions(reserved_tokens(stats)))else:import psutil@@ -317,17 +319,17 @@ def load_model(folder, torch, stats, checkpoint):mapping, device = {'': 'cpu'}, 'cpu'if weight_budget > 2 * 2**30:from accelerate import dispatch_model, infer_auto_device_map- mapping = infer_auto_device_map(model, max_memory={0: weight_budget,+ mapping = infer_auto_device_map(model, max_memory={card: weight_budget,'cpu': min(psutil.virtual_memory().total - 2 * 2**30, weights + available_memory() - 2 * 2**30)},no_split_module_classes=['Qwen3VLTextDecoderLayer', 'Qwen3VLVisionBlock'], dtype=torch.bfloat16)if 'disk' in mapping.values():raise ValueError('ram_space')model = dispatch_model(model, mapping)- device = 'cuda:0' if any(v == 0 for v in mapping.values()) else 'cpu'+ device = 'cuda:%d' % card if any(v == card for v in mapping.values()) else 'cpu'stats.update(load_seconds=time.monotonic() - loading, placement_seconds=time.monotonic() - placing,accelerations=['merged_gate_up', 'per_image_sdpa', 'chunked_vision_mlp', 'merged_qkv'],backend='freetoken-portable-ops+transformers',- cpu_offload=any(v == 'cpu' for v in mapping.values()) and any(v == 0 for v in mapping.values()),+ cpu_offload=any(v == 'cpu' for v in mapping.values()) and any(v == card for v in mapping.values()),execution_device=device, device_map=mapping)return model, devicediff --git a/freevideo_engine/resident_models.py b/freevideo_engine/resident_models.pyindex ebf82e4..b55c139 100644--- a/freevideo_engine/resident_models.py+++ b/freevideo_engine/resident_models.py@@ -7,6 +7,7 @@ import timeimport torchfrom .torch_compat import empty_host_cache, host_cache_release_supported+from .device_index import device_propertiesGiB = 1 << 30# Where a preview's sampling peak is kept, apart from its complete request's.@@ -506,7 +507,7 @@ class ModelBank:def snapshot(self):if not torch.cuda.is_initialized():return dict(reclaimable_gpu_bytes=0, reclaimable_ram_bytes=0, gpu_uuid=None, models=[])- uuid = str(getattr(torch.cuda.get_device_properties(0), 'uuid', ''))+ uuid = str(getattr(device_properties(torch), 'uuid', ''))if uuid and not uuid.startswith(('GPU-', 'MIG-')):uuid = 'GPU-' + uuidhost, committed = {}, {}diff --git a/freevideo_engine/sam2/utils/misc.py b/freevideo_engine/sam2/utils/misc.pyindex 08e6954..9768588 100644--- a/freevideo_engine/sam2/utils/misc.py+++ b/freevideo_engine/sam2/utils/misc.py@@ -11,14 +11,15 @@ from threading import Threadimport numpy as npimport torchfrom PIL import Image+from ...device_index import device_propertiesfrom tqdm import tqdmdef get_sdpa_settings():if torch.cuda.is_available():- old_gpu = torch.cuda.get_device_properties(0).major < 7+ old_gpu = device_properties(torch).major < 7# only use Flash Attention on Ampere (8.0) or newer GPUs- use_flash_attn = torch.cuda.get_device_properties(0).major >= 8+ use_flash_attn = device_properties(torch).major >= 8if not use_flash_attn:warnings.warn("Flash Attention is disabled as it requires a GPU with Ampere (8.0) CUDA capability.",