[Fix] Correctly process compile.disable in config#1674
[Fix] Correctly process compile.disable in config#1674HAOCHENYE merged 2 commits intoopen-mmlab:mainfrom
compile.disable in config#1674Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR fixes the logic for determining when torch.compile should be disabled by checking the disable flag within compile configuration dictionaries. Previously, the code only checked for boolean False values, missing cases where users explicitly set disable=True in their compile config.
Key changes:
- Enhanced the early-return condition in
compile_model()to handle thedisableflag in dict-type compile configurations
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
mmengine/_strategy/base.py
Outdated
| """ | ||
| if isinstance(compile, bool) and not compile: | ||
| if isinstance(compile, bool) and not compile or \ | ||
| isinstance(compile, dict) and not compile.get('disable', False): |
There was a problem hiding this comment.
The condition logic is inverted. When disable=True, not compile.get('disable', False) evaluates to False, preventing the early return. The condition should be compile.get('disable', False) (without not) to return the model when disable is True.
| isinstance(compile, dict) and not compile.get('disable', False): | |
| isinstance(compile, dict) and compile.get('disable', False): |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
@HAOCHENYE This one is ready to be reviewed. |
compile.disable in configcompile.disable in config
compile.disable in configcompile.disable in config
This is a sub-PR of #1665
Motivation
The
torch.compilereceives a lot args. And in mmengine, all contents incompilefrom any config file will be transferred totorch.compile.The mmengine checks several dependencies when user specifies
compilein their config file, and makinghasattr(config, compile)as the flag of enablingtorch.compile.However this is not exact. The compile config can include an arg
disableto state if the compiler is actually working. So the mmengine needs to carefully determine if the user is actually enabling thetorch.compile. This caused a small modification inmmengine/_strategy/base.pyModification
When user specified
compilewith a dict type, thecompile_modelfunc will check ifdisableis set toTrue, and can directly return the model just likecompileis set toNone