Skip to content

Studio video: stream the Wan encode under model / sequential offload too - #15173

Merged
danielhanchen merged 3 commits into
mainfrom
studio-video-decode-export-overlap
Oct 25, 2026
Merged

danielhanchen merged 3 commits into
mainfrom
studio-video-decode-export-overlap

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

#14405 encodes a Wan clip while the VAE decodes it. A forward hook on the decoder turns each finished chunk into frames, and a libx264 thread encodes them during the decode. open_stream_encode only accepted a decoder whose weights were already on CUDA when the render started. Model and sequential offload keep the VAE on the host between renders, so every offloaded Wan render (low_vram, the 14B / A14B models on smaller cards, T4) never streamed and paid the whole encode after the decode.

Changes

  • The gate also accepts a VAE parked on the host when the pipeline executes on CUDA. The offload hooks bring it onto the card for the decode, the same way the MiniMax-H3 session already handles it.
  • Unchanged:
    • the per-frame check (the streamed mp4 is used only when every frame matches the final export);
    • every fallback;
    • the kill switch UNSLOTH_STUDIO_VIDEO_STREAM_ENCODE=0.

Results

Exclusive B200, real weights, default size, frames and steps. One warm-up, then off / on / on / off / off / on in one process. Medians of 3, seconds.

config post-sampling, off -> on encode tail, off -> on peak VRAM
Wan2.2-TI2V-5B 1280x704x121, low_vram (newly streams) 3.568 -> 2.740 (-23%), every on run below every off run 0.899 -> 0.363 10019 MiB both
Wan2.1-1.3B 832x480x33, low_vram (newly streams) 0.863 -> 0.762 (inside the off spread) 0.551 -> 0.374 4223 MiB both
  • Base check: on the base tree the low_vram VAE sits on cpu with the execution device cuda:0, and the render reports streamed: false.
  • Host RAM: rises by the pinned chunk copies, about 300 MB at 1280x704x121.

Output identity

  • Frames: the frames fed to the encoder are identical, and so are the x264 settings string, SPS / PPS, frame rate, time base, and frame and packet counts.
  • Same mp4 bytes: TI2V-5B low_vram and Wan2.1-1.3B low_vram produced the same mp4 bytes in every run of both arms.
  • Bitstreams can still differ: libx264 frame threads, which the stock export also uses, are timing dependent. The stock path alone, under heavy host load, produced 3 different files from identical frames. PSNR against the input frames is identical in both arms (39.8655 dB on every TI2V low_vram file).

Tests

  • New test in tests/test_video_stream_encode.py: a host-parked decoder opens a session only when the pipeline executes on CUDA (not with no execution device or a CPU one), and the kill switch still turns it off.
  • tests/test_video_*.py: 2611 passed, 105 skipped.

Limits

  • Sequential offload and A14B / I2V-14B were not run end to end. They use the same gate and VAE class.
  • No T4 numbers. There the saving is capped at about 0.4-1 s per render, against decodes of tens of seconds.

open_stream_encode refused any Wan VAE whose decoder parameters sat on the
host when the render began. Model and sequential offload park the VAE there
between renders and onload it for the decode, so every offloaded Wan render
(low_vram, A14B / 14B on smaller cards) encoded only after the decode. The
gate now also accepts a host-parked decoder when the pipeline executes on
CUDA, as the MiniMax-H3 session already does. The frame identity check and
every fallback are unchanged.
@danielhanchen danielhanchen self-assigned this Oct 24, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-24T23:56:59.583605Z 425b367 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 425b367f69

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit 43b83d5 into main Oct 25, 2026
@danielhanchen
danielhanchen deleted the studio-video-decode-export-overlap branch October 25, 2026 00:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant