Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add warnings when using replicate_in_memory=True and MCCachingModule (#…
…273)
- Loading branch information
Showing
4 changed files
with
38 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import warnings | ||
|
||
from torch import nn | ||
|
||
from baal.bayesian.caching_utils import LRUCacheModule | ||
|
||
WARNING_CACHE_REPLICATED = """ | ||
To use MCCachingModule at maximum effiency, we recommend using | ||
`replicate_in_memory=False`, but it is `True`. | ||
""" | ||
|
||
|
||
def raise_warnings_cache_replicated(module, replicate_in_memory): | ||
if ( | ||
isinstance(module, nn.Module) | ||
and replicate_in_memory | ||
and any(isinstance(m, LRUCacheModule) for m in module.modules()) | ||
): | ||
warnings.warn(WARNING_CACHE_REPLICATED, UserWarning) |
This file contains 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
This file contains 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