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: retry one size down when graphics memory runs out, down to the smallest size...
Bowen Xuef285e7653ee5
diff --git a/freevideo_engine/agent/errors.py b/freevideo_engine/agent/errors.pyindex 8ec96ea..4acf7bf 100644--- a/freevideo_engine/agent/errors.py+++ b/freevideo_engine/agent/errors.py@@ -118,8 +118,8 @@ ERRORS.update({# Static bilingual image reasons; backend exception strings never enter the API.IMAGE_REASONS = {- 'no_memory': ('Not enough GPU memory. Make the picture smaller in "Image size…" and try again.',- '显存不足。在“图像大小…”里缩小后再试。'),+ 'no_memory': ('Not enough GPU memory, even at the smallest size. Close other apps using the GPU, then try again.',+ '显存不够,最小尺寸也没能生成。关掉其他占用显卡的程序后再试。'),'busy_video': ('A video is generating. Try again when it finishes.', '视频正在生成,完成后再试。'),'pack_missing': ('Download "Image generation models" in the launcher first.','请先在启动器里下载“图像生成模型”。'),diff --git a/freevideo_engine/image_gen/failure.py b/freevideo_engine/image_gen/failure.pyindex 891498a..700c05c 100644--- a/freevideo_engine/image_gen/failure.py+++ b/freevideo_engine/image_gen/failure.py@@ -19,7 +19,7 @@ NO_REPORT = frozenset(('busy', 'invalid_request', 'cancelled'))STAGES = ('start', 'load', 'text', 'encode', 'denoise', 'decode')KINDS = ('generate', 'edit', 'cast', 'compose', 'download', 'install')MESSAGE_ZH = {- 'no_memory': '显存不足。在“图像大小…”里缩小后再试。',+ 'no_memory': '显存不够,最小尺寸也没能生成。关掉其他占用显卡的程序后再试。','busy_video': '视频正在生成,完成后再试。','busy': '已有一张图在生成,请等它完成。','pack_missing': '请先在启动器里下载“图像生成模型”。',diff --git a/freevideo_engine/image_gen/image_runner.py b/freevideo_engine/image_gen/image_runner.pyindex 563f296..e96c800 100644--- a/freevideo_engine/image_gen/image_runner.py+++ b/freevideo_engine/image_gen/image_runner.py@@ -235,6 +235,10 @@ class ImageRunner:return self.generator.generate(prompt, width=width, height=height, seed=seed,reference_images=reference_images, progress=progress, cancel=cancel)+ def at_boundary(self):+ """False when a failure left a weights streamer inside a layer pass; the next request cannot use it."""+ return self.dit_stack.offloader.at_boundary and self.te_stack.offloader.at_boundary+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)diff --git a/freevideo_engine/image_gen/service.py b/freevideo_engine/image_gen/service.pyindex 965d0d0..84997cf 100644--- a/freevideo_engine/image_gen/service.py+++ b/freevideo_engine/image_gen/service.py@@ -588,6 +588,38 @@ class Service:self.context = Noneself.queue_wake.set()+ def shrink(self, value, row, context):+ """After a memory error while working on the picture, step the size down for one more try.++ The ladder is the one start-up fitting uses (32-pixel grid, 512 pixels at the least);+ the step grows with the size so a big canvas needs few tries. False at the smallest size.+ """+ if (row.get('code') != 'no_memory' or row.get('stage') in ('load', 'text', 'encode')+ or self.stop.is_set() or self.session_stop.is_set()):+ return False+ width, height = value['width'], value['height']+ long, short = max(width, height), min(width, height)+ # A worker that had to load the model again costs seconds per try; take bigger steps then.+ side = long - max(32, long // (8 if row.get('reloaded') else 16) // 32 * 32)++ def fitted(length):+ return (short * length + long * 16) // (long * 32) * 32++ if side < 512 or fitted(side) < 512:+ # The step would jump past the least size: try that size itself before giving up.+ side = next((n for n in range(512, long, 32) if fitted(n) >= 512), None)+ if side is None:+ return False+ other = fitted(side)+ value['width'], value['height'] = (side, other) if width >= height else (other, side)+ with self.mutex:+ fitted = self.state.get('fitted') or {}+ requested = fitted.get('requested') or dict(width=width, height=height)+ self.state['fitted'] = dict(width=value['width'], height=value['height'], requested=requested)+ self.state.update(phase='progress', stage='start', fraction=0)+ context.update_request(value)+ return True+def infer(self, session, value):context = self.context or Context('generate', value)session.send(action='generate', **value)@@ -625,6 +657,11 @@ class Service:elif phase in ('result', 'error'):if self.stop.is_set() or row.get('code') == 'cancelled':result = dict(phase='cancelled')+ elif phase == 'error' and self.shrink(value, row, context):+ # The memory estimate was optimistic for this machine: same worker, next size down.+ session.send(action='generate', **value)+ deadline = time.monotonic() + INFERENCE_TIMEOUT+ continueelif phase == 'error':code = row.get('code')result = self.failed(code, context, row=row)diff --git a/freevideo_engine/image_gen/worker.py b/freevideo_engine/image_gen/worker.pyindex 4d9afce..3ca7012 100644--- a/freevideo_engine/image_gen/worker.py+++ b/freevideo_engine/image_gen/worker.py@@ -142,10 +142,25 @@ def serve(pack_dir, *, device='cuda', idle_seconds=45., stream=None, output=Noneexcept Exception:# Diagnostics must not replace the inference exception.pass- result = dict(phase='error', code=code, stage=context.timing.stage,+ reload = not getattr(runner, 'at_boundary', lambda: True)()+ result = dict(phase='error', code=code, stage=context.timing.stage, reloaded=reload,seconds=context.timing.seconds(), stages=context.timing.snapshot(), plan=plan,error=exception_details(error, context.redactor, code))finally:+ if result is not None and result.get('reloaded'):+ # A failure inside a layer pass leaves the weights streamer part-way through it and the+ # next request would be refused; the model is loaded again for that one.+ with redirect_stdout(sys.stderr):+ try:+ runner.close()+ except Exception as error:+ print('image runner close failed: %s' % type(error).__name__, file=sys.stderr, flush=True)+ runner = None+ import gc+ gc.collect()+ torch = sys.modules.get('torch')+ if torch is not None and torch.cuda.is_available():+ torch.cuda.empty_cache()with inbox.mutex:inbox.busy = Falseif result is not None:diff --git a/freevideo_engine/offload.py b/freevideo_engine/offload.pyindex 19e4353..123217f 100644--- a/freevideo_engine/offload.py+++ b/freevideo_engine/offload.py@@ -514,6 +514,11 @@ class LayerOffloader:self.hooks.append(layer.register_forward_hook(lambda module, args, result, index=index: self._after(index), always_call=True))+ @property+ def at_boundary(self):+ """No layer pass is open, so the next pass can start; False after a failure inside one."""+ return not (self.expected or self.pending or self.host_pending)+def cache_between_steps(self, max_bytes, *, max_layers=None, allow_growth=True):"""Retain affordable device planes until this sampling pass closes.diff --git a/web/image_generation.js b/web/image_generation.jsindex 7f1acdb..6279cea 100644--- a/web/image_generation.js+++ b/web/image_generation.js@@ -107,8 +107,8 @@ export function imagePackMessage(info, t) {}export function imageGenError(code, info, t) {const reasons = {- no_memory: ['Not enough GPU memory. Make the picture smaller in "Image size…" and try again.',- '显存不足。在“图像大小…”里缩小后再试。'],+ no_memory: ['Not enough GPU memory, even at the smallest size. Close other apps using the GPU, then try again.',+ '显存不够,最小尺寸也没能生成。关掉其他占用显卡的程序后再试。'],busy_video: ['A video is generating. Try again when it finishes.', '视频正在生成,完成后再试。'],busy: ['An image is already being generated. Try again when it finishes.', '已有一张图在生成,完成后再试。'],model_unreadable: ['The image generation model files could not be read. Repair them in the launcher and try again.',