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.

Image generation: falling back to streaming no longer stops half-way when locking pages fails

Bowen Xueaea443e0f52d
diff --git a/freevideo_engine/image_gen/image_runner.py b/freevideo_engine/image_gen/image_runner.py
index 2c66df2..c90e914 100644
--- a/freevideo_engine/image_gen/image_runner.py
+++ b/freevideo_engine/image_gen/image_runner.py
@@ -233,11 +233,14 @@ class ImageRunner:
def _to_streamed(self):
"""A request no longer fits the whole model on the card: put the host copy back and stream."""
- with torch.no_grad():
- self.dit_stack = self.dit_stack.to_streamed()
- self.te_stack = self.te_stack.to_streamed()
- self.full_card = False
- torch.cuda.empty_cache()
+ try:
+ with torch.no_grad():
+ self.dit_stack = self.dit_stack.to_streamed()
+ self.te_stack = self.te_stack.to_streamed()
+ finally:
+ # Each stack is usable on its own whichever one stopped, so the next request plans from stacks as they are.
+ self.full_card = False
+ torch.cuda.empty_cache()
def budget(self):
if self.gpu_budget_bytes is not None:
diff --git a/freevideo_engine/image_gen/image_stream.py b/freevideo_engine/image_gen/image_stream.py
index b08b6c8..9a9da26 100644
--- a/freevideo_engine/image_gen/image_stream.py
+++ b/freevideo_engine/image_gen/image_stream.py
@@ -99,9 +99,20 @@ class ResidentStack:
def to_streamed(self, **options):
"""Copy the layers back to the host and return a ``StreamedStack`` over them."""
- for layer in self.layers:
- layer.to('cpu')
- return StreamedStack(self.layers, name=self.name, device=self.device, **options)
+ moved = []
+ try:
+ for layer in self.layers:
+ layer.to('cpu')
+ moved.append(layer)
+ except BaseException:
+ for layer in moved:
+ layer.to(self.device)
+ raise
+ try:
+ return StreamedStack(self.layers, name=self.name, device=self.device, **options)
+ except Exception:
+ # Locking pages failed: stream from ordinary memory instead.
+ return StreamedStack(self.layers, name=self.name, device=self.device, **{**options, 'pin': False})
def close(self):
pass