Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

perf(video): avoid full-clip decoding for H3 live previews (#8868)

[._.]/1a2ba01448f1
diff --git a/scripts/generate_minimax_h3.py b/scripts/generate_minimax_h3.py
index 4e85faee9f..0921e08c93 100644
--- a/scripts/generate_minimax_h3.py
+++ b/scripts/generate_minimax_h3.py
@@ -879,6 +879,20 @@ class _H3StepwisePreview:
* (self.latent_height // patch_h)
* (self.latent_width // patch_w)
)
+ # The preview publishes one frame, not a clip. Decode just one VAE
+ # window around the midpoint instead of decoding the entire video on
+ # every diffusion step. Respect the decoder's lead-in/token-drop floor
+ # and slice on temporal patch boundaries so unpatchify stays valid.
+ chunk = pipe.video_vae.tokens_chunk_size
+ drop = pipe.video_vae.config.token_drop
+ minimum = 2 * chunk - drop if drop > 0 else chunk
+ self.preview_latent_frames = min(
+ self.num_latent_frames, ((minimum + patch_t - 1) // patch_t) * patch_t
+ )
+ rows_per_patch_frame = self.target_rows // (self.num_latent_frames // patch_t)
+ start = ((self.num_latent_frames - self.preview_latent_frames) // (2 * patch_t))
+ self.preview_row_start = start * rows_per_patch_frame
+ self.preview_row_end = self.preview_row_start + (self.preview_latent_frames // patch_t) * rows_per_patch_frame
self._latest_rows = None
self.saved = 0
@@ -894,9 +908,10 @@ class _H3StepwisePreview:
return
try:
rows = self._latest_rows[-self.target_rows:]
+ rows = rows[self.preview_row_start:self.preview_row_end]
frames = self.pipe._decode_video(
rows,
- self.num_latent_frames,
+ self.preview_latent_frames,
self.latent_height,
self.latent_width,
)
diff --git a/scripts/generate_minimax_h3.test.js b/scripts/generate_minimax_h3.test.js
index d17ad0aef0..3817cabc0b 100644
--- a/scripts/generate_minimax_h3.test.js
+++ b/scripts/generate_minimax_h3.test.js
@@ -183,27 +183,31 @@ describe.skipIf(!pyBin)('generate_minimax_h3.py', () => {
expect(output.trim()).toBe('/tmp/previews');
});
- it('projects the DiT batch rows to the generated video rows before decoding', () => {
+ it('decodes only a bounded midpoint window of generated rows for the stepwise preview', () => {
const output = runPython(`${importRunner}\n${[
'import json, sys, types',
'packing = types.ModuleType("minimax_h3_mlx.packing")',
'packing.align_num_frames = lambda value: value',
- 'packing.video_latent_num_frames = lambda value: 2',
+ 'packing.video_latent_num_frames = lambda value: 37',
'sys.modules["minimax_h3_mlx"] = types.ModuleType("minimax_h3_mlx")',
'sys.modules["minimax_h3_mlx.packing"] = packing',
'class Config:',
' spatial_compression_ratio = 2',
+ ' token_drop = 3',
'class DitConfig:',
' patch_size = (1, 2, 2)',
'class VideoVae:',
' config = Config()',
+ ' tokens_chunk_size = 5',
'class Dit:',
' config = DitConfig()',
'class Rows:',
- ' def __init__(self, shape): self.shape = shape',
+ ' def __init__(self, shape, start=0): self.shape, self.start = shape, start',
' def __getitem__(self, key):',
- ' if key == 0: return Rows((10, 4))',
- ' if isinstance(key, slice): return Rows((8, 4))',
+ ' if key == 0: return Rows((152, 4))',
+ ' if isinstance(key, slice):',
+ ' start, stop, _ = key.indices(self.shape[0])',
+ ' return Rows((stop - start, 4), self.start + start)',
' raise AssertionError(f"unexpected row key: {key!r}")',
'class Frame:',
' shape = (4, 4, 3)',
@@ -214,19 +218,19 @@ describe.skipIf(!pyBin)('generate_minimax_h3.py', () => {
' video_vae = VideoVae()',
' dit = Dit()',
' def _decode_video(self, rows, *shape):',
- ' print(json.dumps({"rows": list(rows.shape), "shape": list(shape)}))',
+ ' print(json.dumps({"rows": list(rows.shape), "start": rows.start, "shape": list(shape)}))',
' return Frames()',
'seen = []',
'runner.write_stepwise_preview = lambda directory, frame: seen.append((directory, list(frame.shape))) or True',
- 'preview = runner._H3StepwisePreview(Pipe(), "/tmp/previews", 17, 8, 8)',
- 'rows = Rows((1, 10, 4))',
+ 'preview = runner._H3StepwisePreview(Pipe(), "/tmp/previews", 124, 8, 8)',
+ 'rows = Rows((1, 152, 4))',
'proxy = runner._PreviewingDiT(lambda *args: "ok", preview)',
'proxy(rows)',
'preview.publish(1, 2)',
'print(json.dumps({"seen": seen, "saved": preview.saved}))',
].join('\n')}`);
const lines = output.trim().split('\n').map((line) => JSON.parse(line));
- expect(lines[0]).toMatchObject({ rows: [8, 4], shape: [2, 4, 4] });
+ expect(lines[0]).toMatchObject({ rows: [28, 4], start: 64, shape: [7, 4, 4] });
expect(lines[1]).toEqual({ seen: [['/tmp/previews', [4, 4, 3]]], saved: 1 });
});
diff --git a/server/lib/videoDraftDecoders.js b/server/lib/videoDraftDecoders.js
index 4b8bcd52ef..a4e0b54f53 100644
--- a/server/lib/videoDraftDecoders.js
+++ b/server/lib/videoDraftDecoders.js
@@ -4,8 +4,8 @@
* A diffusion video model produces a latent sequence; a VAE decoder turns that
* sequence into pixels. On MiniMax H3 the decode is not a rounding error on the
* render — it is a full-sequence pass over every latent frame at the output
- * canvas, and it happens twice over: once at the end of the render, and once
- * per denoise step for the stepwise preview PortOS publishes to the Video Gen
+ * canvas at the end of the render. Each denoise step also decodes a bounded
+ * temporal window for the stepwise preview PortOS publishes to the Video Gen
* stage. Most of the time a user spends looking at an H3 render is spent
* deciding whether the PROMPT and the COMPOSITION are right, which a
* lower-fidelity decode answers just as well as the shipped one.