feat: add compiled_region option to torch.compile the VAE encoder/decoder#120
Open
xbcReal wants to merge 1 commit into
Open
feat: add compiled_region option to torch.compile the VAE encoder/decoder#120xbcReal wants to merge 1 commit into
xbcReal wants to merge 1 commit into
Conversation
…oder
Add a 'compiled_region' knob to CompileConfig ('language' | 'all').
'language' keeps the existing behavior (compile only the MoT
TransformerBlocks); 'all' additionally applies torch.compile to the
WanVAE_ Encoder3d/Decoder3d (CausalConv3d layers), which the existing
apply_compile path never touches since it only wraps the
_encode_vision/_decode_vision post-processing functions.
The VAE is compiled with the torch.compile defaults (fullgraph=False,
dynamic=None): the causal-conv feat_cache list mutation creates graph
breaks, so fullgraph must stay off; and with automatic dynamic shapes
the chunk temporal size only takes two values (1 frame for prime,
temporal_window frames for steady state), so compilation stabilizes
after at most a couple of recompiles without forcing dynamic=True.
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.
What does this PR do?
Adds a
compiled_regionknob toCompileConfig('language'|'all'):'language'(default) keeps the existing behavior: compile only the MoT TransformerBlocks.'all'additionally appliestorch.compileto the WanVAE_Encoder3d/Decoder3d(theCausalConv3dlayers). The existingapply_compilepath never touches these, since it only wraps the_encode_vision/_decode_visionpost-processing functions (patchify + Linear + pos_embed, no 3D Conv).Implementation notes
The VAE is compiled with the
torch.compiledefaults (fullgraph=False,dynamic=None):feat_cache[idx] = cache_x), which creates graph breaks, sofullgraphmust stay off; dynamo compiles the sub-graphs between breaks.dynamic=None), the first call compiles a static kernel and dynamo recompiles once with dynamic shapes when a different temporal size shows up. The chunk temporal size only takes two values (1 frame for prime,temporal_windowframes for steady state), so compilation stabilizes after at most a couple of recompiles without forcingdynamic=True.@torch.no_grad()withrequires_grad_(False), so no backward graph is involved.Changes
cosmos_framework/configs/toml_config/sft_config.py: newcompiled_regionfield onCompileConfigcosmos_framework/model/generator/omni_mot_model.py: new_compile_vae()method, invoked whencompile.enabledandcompiled_region == 'all'examples/toml/sft_config/vision_sft_nano.toml: enablecompiled_region = 'all'in the nano SFT example