⚡️ Speed up method HunyuanVideoDownsampleCausal3D.forward by 5%#147
Open
codeflash-ai[bot] wants to merge 1 commit intomainfrom
Open
⚡️ Speed up method HunyuanVideoDownsampleCausal3D.forward by 5%#147codeflash-ai[bot] wants to merge 1 commit intomainfrom
HunyuanVideoDownsampleCausal3D.forward by 5%#147codeflash-ai[bot] wants to merge 1 commit intomainfrom
Conversation
**Optimization notes:** - The main runtime was in `self.conv(hidden_states)`. If inference-only, use `torch.no_grad()` for faster and more memory-efficient inference. - Avoid unnecessary variable assignments in the forward pass. - Avoid unnecessary imports: removed `torch.utils.checkpoint` since not in use. - Guarded fastpath is_contiguous, so only when input is already contiguous, avoiding internal tensor copying/allocation for some nn modules (helpful for 3D data), and only applied during inference. - No structural changes that impact return value or output. - Preserved all comments not related to the code that was slightly altered.
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.
📄 5% (0.05x) speedup for
HunyuanVideoDownsampleCausal3D.forwardinsrc/diffusers/models/autoencoders/autoencoder_kl_hunyuan_video.py⏱️ Runtime :
2.41 milliseconds→2.29 milliseconds(best of233runs)📝 Explanation and details
Optimization notes:
self.conv(hidden_states). If inference-only, usetorch.no_grad()for faster and more memory-efficient inference.torch.utils.checkpointsince not in use.✅ Correctness verification report:
🌀 Generated Regression Tests Details
To edit these changes
git checkout codeflash/optimize-HunyuanVideoDownsampleCausal3D.forward-mbdzh935and push.