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.
Compile the video decoder block once and share it across blocks (#33)
Bowen Xue3d614e314c6d
diff --git a/freevideo_engine/decode.py b/freevideo_engine/decode.pyindex 5dd1651..a23fe35 100644--- a/freevideo_engine/decode.py+++ b/freevideo_engine/decode.py@@ -7,7 +7,7 @@ import timeimport torchfrom .offload import LayerOffloader, pin_layer_weights-from .vae_tiles import TileDecoder+from .vae_tiles import TileDecoder, compile_blocks@torch.no_grad()@@ -110,6 +110,7 @@ def decode_to_file(latents, audio_latents, out_path, *, base, offload=False, prepassdel bufferpreload_seconds = time.perf_counter() - read_started+ compiled_blocks = compile_blocks(vae.decoder)mean = torch.tensor(vae.config.latents_mean, device='cuda').view(1, -1, 1, 1, 1)std = torch.tensor(vae.config.latents_std, device='cuda').view(1, -1, 1, 1, 1)torch.cuda.synchronize()@@ -229,6 +230,7 @@ def decode_to_file(latents, audio_latents, out_path, *, base, offload=False, pre'decoded_artifact_save_seconds': artifact_seconds,'streamed_video_output': stream_output, 'streamed_vae_weights': stream_weights,'vae_resident_blocks': resident_blocks,+ 'vae_compiled_blocks': compiled_blocks,'video_postprocess_seconds': streamed_timings.get('video_postprocess_seconds'),'vae_pinned_weight_bytes': pinned_bytes,'decode_save_seconds': time.perf_counter() - started,diff --git a/freevideo_engine/vae_tiles.py b/freevideo_engine/vae_tiles.pyindex 97ae65a..37f12e3 100644--- a/freevideo_engine/vae_tiles.py+++ b/freevideo_engine/vae_tiles.py@@ -13,6 +13,7 @@ Prologue/epilogue adapted from diffusers' MiniMaxH3VideoViTDecoder3d, pinned atVDN 30b6b380c2482f3519469350810c2955d8847fd9. Spatial tile geometry, per-tileGEMM shapes, temporal chunking and stitching remain those of the original VAE."""+import osimport typesfrom contextlib import nullcontextimport torch@@ -20,6 +21,24 @@ import torchfrom .offload import LayerOffloader+def compile_blocks(decoder):+ """Compile the decoder block once; all blocks share the graph, their weights are inputs.++ Decoding 1344x768x243 on Windows with an RTX 5060 Ti took 114.9 s eager. Compiled, it+ took 100.6 s in a fresh process that loaded the graph from the disk cache, and 105.4 s+ in one that compiled it first. On an RTX PRO 6000 it took 18.1 s and 14.6 s. The+ rounding of fused RMSNorm, rotary and residual work moves 0.7% of output values by+ one or two 8-bit levels. FREEVIDEO_VAE_COMPILE=0 keeps the eager blocks.+ """+ if os.environ.get('FREEVIDEO_VAE_COMPILE', '1').lower() in ('0', 'off', 'false'):+ return False+ for block in decoder.transformer_blocks:+ if not getattr(block, 'freevideo_compiled', False):+ block.forward = torch.compile(block.forward, dynamic=False)+ block.freevideo_compiled = True+ return True++class TileDecoder:def __init__(self, decoder, prefetch=True, weight_source=None, resident_blocks=0):self.decoder = decoder