Bug fixes and performance improvements for ComfyUI-WanVideoWrapper #844
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.
Bug fixes and performance improvements for ComfyUI-WanVideoWrapper
This PR addresses several bugs and performance issues in the ComfyUI-WanVideoWrapper project:
Bug Fixes
1. Fixed cache state management
Added proper checks to ensure pred_id exists in cache state before accessing it, preventing potential KeyError exceptions.
2. Fixed RoPE implementation
Added dimension checks in apply_rope_comfy_chunked to prevent index errors when freqs_cis dimensions are smaller than seq_dim.
3. Fixed index handling in multitalk audio processing
Added length checks to prevent index errors when processing audio embeddings of different lengths.
Performance Improvements
1. Optimized memory usage in sampling process
Added explicit tensor cleanup and torch.no_grad() contexts to reduce memory usage during sampling.
2. Improved VAE encoding/decoding performance
Optimized tile processing in VAE encoding and decoding to reduce memory overhead and improve speed.
3. Added memory-efficient RoPE computation
Implemented a more memory-efficient version of RoPE computation that reduces peak memory usage.
4. Optimized context window processing
Improved memory efficiency in context window processing by reusing tensors and reducing unnecessary allocations.
Testing
All changes have been tested with various video generation workflows to ensure they don't introduce new issues.