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.

Load the image model from read-only mappings when a Windows machine has too little commit for...

Bowen Xuee2a00dd0ef8a
diff --git a/freevideo_engine/image_gen/image_runner.py b/freevideo_engine/image_gen/image_runner.py
index 8957c7d..1f8649e 100644
--- a/freevideo_engine/image_gen/image_runner.py
+++ b/freevideo_engine/image_gen/image_runner.py
@@ -17,6 +17,7 @@ from . import image_policy
from .image_stream import ResidentStack, StreamedStack
GiB = 2**30
+COMMIT_FLOOR = 2 * GiB # commit that must remain after private copies of the weights
_DIT_FILE = 'diffusion_models/qwen_image_2.1_turbo_int8_convrot.safetensors'
_TE_FILE = 'text_encoders/qwen3vl_8b_int8_convrot.safetensors'
_VAE_FILE = 'vae/qwen_image_2.1_vae_bf16.safetensors'
@@ -141,9 +142,15 @@ class ImageRunner:
# An Apple GPU shares the host's memory: its layers stay views of the mapped files (mapped.py).
self.mapped = self.device.type == 'mps'
self.full_card = not self.mapped and self._fits_whole_model()
+ # The weights are read from read-only mappings of the files, not copied into private memory,
+ # on a Mac and on a Windows machine whose commit cannot hold the copies. Such a machine pins
+ # nothing: the commit left after the weights is what the card's own allocations are charged to.
+ low_commit = not self.mapped and self._copies_exceed_commit()
+ mapped_files = {'mapped': True} if self.mapped or low_commit else {}
+ self.low_commit = low_commit
self.transformer = load_dit(self.pack_dir / _DIT_FILE, device=self.device if self.full_card else 'cpu',
progress=lambda done, total: loading.report('dit', done, total),
- **({'mapped': True} if self.mapped else {}))
+ **mapped_files)
self.load_seconds['dit'] = time.monotonic() - started
loading.complete('dit')
started = time.monotonic()
@@ -156,7 +163,7 @@ class ImageRunner:
processor_dir = self.pack_dir / 'processor'
text = load_text_encoder(self.pack_dir / _TE_FILE, config_path=config_dir / 'config.json', device='cpu',
progress=lambda done, total: loading.report('text', done, total),
- **({'mapped': True} if self.mapped else {}))
+ **mapped_files)
from transformers import Qwen3VLProcessor
processor = Qwen3VLProcessor.from_pretrained(str(processor_dir), local_files_only=True)
self.load_seconds['text'] = time.monotonic() - started
@@ -206,10 +213,10 @@ class ImageRunner:
else:
with torch.no_grad(): # LayerOffloader refuses to be built with autograd on
self.dit_stack = StreamedStack(stacks[0], name='dit', device=self.device,
- progress=pin_progress(0))
+ pin=not low_commit, progress=pin_progress(0))
loading.report('pin', stack_bytes[0], pin_total)
self.te_stack = StreamedStack(stacks[1], name='text_encoder', device=self.device,
- progress=pin_progress(1))
+ pin=not low_commit, progress=pin_progress(1))
self.load_seconds['pin'] = time.monotonic() - started
loading.complete('pin')
@@ -224,6 +231,25 @@ class ImageRunner:
self.last_plan = None
loading.finish()
+ def _copies_exceed_commit(self):
+ """True on Windows when private copies of the DiT and encoder would leave too little commit.
+
+ System commit is charged for every private byte: with 15.8 GB of RAM, 11.7 GB of commit free
+ and 16.5 GB of weights, the encoder's read failed with an access violation. A read-only
+ mapping costs no commit; the pages are re-read from the file when the system needs the
+ memory, and pinning (which checks live commit itself) still locks what fits.
+ """
+ from ..system import windows
+ if not windows():
+ return False
+ try:
+ from ..system import system_memory
+ commit = system_memory().get('commit_available_bytes')
+ copies = sum((self.pack_dir / name).stat().st_size for name in (_DIT_FILE, _TE_FILE, _VAE_FILE))
+ except Exception:
+ return False
+ return commit is not None and commit < copies + COMMIT_FLOOR
+
def _lookup_on_host(self, embedding):
device = self.device
@@ -320,7 +346,8 @@ class ImageRunner:
def stats(self):
return dict(dit=self.dit_stack.stats(), text_encoder=self.te_stack.stats(),
- plan=self.last_plan.to_dict() if self.last_plan else None, load_seconds=self.load_seconds)
+ plan=self.last_plan.to_dict() if self.last_plan else None, load_seconds=self.load_seconds,
+ low_commit_load=self.low_commit)
def close(self):
for hook in self._embed_hooks:
diff --git a/freevideo_engine/image_gen/qwen_te_weights.py b/freevideo_engine/image_gen/qwen_te_weights.py
index 7765a9f..7d4a4d1 100644
--- a/freevideo_engine/image_gen/qwen_te_weights.py
+++ b/freevideo_engine/image_gen/qwen_te_weights.py
@@ -20,6 +20,16 @@ from .load_progress import TensorProgress
_CONVROT = {"format": "int8_tensorwise", "convrot": True, "convrot_groupsize": 256}
+def _open(path):
+ """The encoder file, opened like the DiT and VAE (streamed_weights._open_safetensors).
+
+ Windows charges a copy-on-write mapping of a whole file to system commit, 9.35 GB for this
+ one, however little of it is read; the pread backend reads only the requested tensors.
+ """
+ from ..system import windows
+ return safe_open(str(path), framework="pt", device="cpu", **({"backend": "pread"} if windows() else {}))
+
+
def _quant_metadata(st, name):
value = st.get_tensor(name + ".comfy_quant")
if value.dtype != torch.uint8 or value.ndim != 1:
@@ -168,6 +178,7 @@ def load_text_encoder(path, *, config=None, config_path=None, device="cpu", dtyp
``load_vision(device='cpu')`` method installs only BF16 visual tensors and
returns that module, allowing the caller's placement policy to own moves.
CPU supports loading/inspection; Int8Linear execution requires CUDA.
+ ``mapped`` leaves tensors stored as they are on disk as views of a read-only mapping of the file.
``progress(done_bytes, total_bytes)`` counts language source bytes, including
vocabulary chunks, and excludes the deferred vision tensors and logits head.
"""
@@ -194,7 +205,7 @@ def load_text_encoder(path, *, config=None, config_path=None, device="cpu", dtyp
vision_type = type(model.model.visual)
model.model.visual = None
model.lm_head = torch.nn.Identity()
- with safe_open(str(path), framework="pt", device="cpu") as st:
+ with _open(path) as st:
reads = (TensorProgress(st, progress, (key for key in st.keys()
if not key.startswith(("model.visual.", "lm_head.")))) if progress is not None else None)
if mapped: # CPU only: tensors stored as they are on disk stay views of the mapped file
@@ -212,7 +223,7 @@ def load_text_encoder(path, *, config=None, config_path=None, device="cpu", dtyp
return owner.model.visual
with init_empty_weights():
visual = vision_type(config.vision_config)
- with safe_open(str(path), framework="pt", device="cpu") as st:
+ with _open(path) as st:
visual_keys = [key for key in st.keys() if key.startswith("model.visual.")]
for key in sorted(visual_keys):
value = st.get_tensor(key)