Skip to content

Conversation

@programming-pupil
Copy link

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.

@kabachuha
Copy link
Contributor

"torch no_grad"s are not needed because ComfyUI sets torch no grad inference mode for the workflow globally

@programming-pupil
Copy link
Author

Referen

Okay, I understand. I have restored the code I will be working on. Thank you very much for taking the time to review it again and see if it needs to be merged. I am very grateful for your tremendous contribution to the open source community!

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.

2 participants