Repository navigation
Studio video: stream-encode Wan clips under the ROCm bf16 VAE decode - #14653
Merged
Merged
Conversation
The ROCm gfx11 / gfx12 default decodes the Wan VAE in bf16 and widens the result to fp32 before the pipeline postprocesses it, while the stream encode hook postprocessed the raw bf16 chunks. The rounding differed, so every clip fell back (frames differ) after doing the streamed work. The hook now widens chunks to fp32 when the observed decode is that wrapper; NVIDIA's fp16 decode returns fp16 and keeps the current path.
…ecode Studio's default video load wraps the bf16 decode again (untiled when it fits), so the outermost vae.decode never carries the bf16 marker and the stream encode still fell back on gfx1151. Read the mode the bf16 install records on the VAE; the test now stacks an outer decode layer too.
Member
Author
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On ROCm gfx11 / gfx12 (Strix Halo, RDNA3, RDNA4), Studio decodes the Wan VAE in bf16 by default (
install_rocm_vae_bf16_decode, 6x faster per clip than fp32 on gfx1151). The wrapper runs the decoder in bf16 and hands the pipeline the fp32 widening of its output, so diffusers' postprocess runs in fp32.The overlapped video encode (#14405) converts each decoder chunk to uint8 inside a forward hook, from the raw chunk. On this path the raw chunk is bf16, so the hook postprocessed in bf16 while the exported frames were postprocessed in fp32. The rounding differed,
_matchesnever passed, and every clip did all of the streamed work and then encoded again. A gfx1151 default Wan render logs:on every clip.
Change
StreamEncodechecks whether the VAE carries the ROCm bf16 decode (vae._unsloth_bf16_decode_mode, set by the installer, so it survives the untiled-when-fits layer Studio puts on top). When it is, the hook widens each chunk to fp32 before the clamp and postprocess, which is what the pipeline does with the widened output. Unpatchify and clamp are exact in either dtype, so the chunks now equal the exported frames bit for bit.Paths left as they are:
Results
AMD CI, Radeon 8060S (gfx1151), Linux, torch 2.11.0+rocm7.13.0. Base and head ran in the same job on the same machine, run 39753304821:
7fd4988b11;wan_stream_offsetsUNSLOTH_STUDIO_VIDEO_STREAM_ENCODE=0, and every arm ran twice in fresh processes (A/A).wan_autowan_auto_repeatwan_stream_offwan_stream_off_repeatVerdict CONFIRMED: the base reproduces the fallback, and the head streams on every default clip.
The first version of this change keyed the widen on the outermost
vae.decode. Its gfx1151 run (39743742573) still fell back, because Studio's untiled-when-fits decode wraps the bf16 decode from outside. The final version reads the mode the bf16 install records on the VAE.Tests
New
test_rocm_bf16_decode_streams_the_exported_framesintests/test_video_stream_encode.py. It installs the realinstall_rocm_vae_bf16_decode(forced mode) on a tinyAutoencoderKLWan, with and without patchify, with and without an outer decode layer like Studio's untiled-when-fits wrapper, and requires the session to stream:tests/test_video_stream_encode.pyframes differ), 10 passedframes differ)Not covered