Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the Flash Attention 2 availability check in diffsynth_engine/utils/flag.py to target the specific flash_attn.flash_attn_func module. A review comment suggests implementing a more robust try-except block to ensure the check accurately reflects how the module is imported elsewhere in the codebase, preventing potential runtime errors.
| FLASH_ATTN_4_AVAILABLE = check_module_available("flash_attn.cute.interface", "Flash attention 4") | ||
| FLASH_ATTN_3_AVAILABLE = check_module_available("flash_attn_interface", "Flash attention 3") | ||
| FLASH_ATTN_2_AVAILABLE = check_module_available("flash_attn", "Flash attention 2") | ||
| FLASH_ATTN_2_AVAILABLE = check_module_available("flash_attn.flash_attn_func", "Flash attention 2") |
There was a problem hiding this comment.
The check for Flash Attention 2 availability is not fully robust. It verifies that the flash_attn.flash_attn_func module can be imported, but the code in diffsynth_engine/models/basic/attention.py uses from flash_attn import flash_attn_func. This requires flash_attn_func to be an attribute of the top-level flash_attn package.
These two conditions are not always equivalent. A more robust approach would be to verify the attribute's existence directly by attempting the import. This prevents potential ImportError at runtime if the flash-attn package structure changes.
| FLASH_ATTN_2_AVAILABLE = check_module_available("flash_attn.flash_attn_func", "Flash attention 2") | |
| try: | |
| from flash_attn import flash_attn_func | |
| logger.info("Flash attention 2 is available") | |
| FLASH_ATTN_2_AVAILABLE = True | |
| except (ImportError, AttributeError): | |
| logger.info("Flash attention 2 is not available") | |
| FLASH_ATTN_2_AVAILABLE = False |
No description provided.