This repository has been archived by the owner on Sep 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Fix Error in nas SPOS trainer, apply_fixed_architecture #3051
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -24,11 +24,14 @@ class FixedArchitecture(Mutator): | |
Preloaded architecture object. | ||
strict : bool | ||
Force everything that appears in ``fixed_arc`` to be used at least once. | ||
verbose : bool | ||
Print log messages if set to True | ||
""" | ||
|
||
def __init__(self, model, fixed_arc, strict=True): | ||
def __init__(self, model, fixed_arc, strict=True, verbose=True): | ||
super().__init__(model) | ||
self._fixed_arc = fixed_arc | ||
self.verbose = verbose | ||
|
||
mutable_keys = set([mutable.key for mutable in self.mutables if not isinstance(mutable, MutableScope)]) | ||
fixed_arc_keys = set(self._fixed_arc.keys()) | ||
|
@@ -99,10 +102,11 @@ def replace_layer_choice(self, module=None, prefix=""): | |
if sum(chosen) == 1 and max(chosen) == 1 and not mutable.return_mask: | ||
# sum is one, max is one, there has to be an only one | ||
# this is compatible with both integer arrays, boolean arrays and float arrays | ||
_logger.info("Replacing %s with candidate number %d.", global_name, chosen.index(1)) | ||
if self.verbose: | ||
_logger.info("Replacing %s with candidate number %d.", global_name, chosen.index(1)) | ||
setattr(module, name, mutable[chosen.index(1)]) | ||
else: | ||
if mutable.return_mask: | ||
if mutable.return_mask and self.verbose: | ||
_logger.info("`return_mask` flag of %s is true. As it relies on the behavior of LayerChoice, " \ | ||
"LayerChoice will not be replaced.") | ||
# remove unused parameters | ||
|
@@ -113,7 +117,7 @@ def replace_layer_choice(self, module=None, prefix=""): | |
self.replace_layer_choice(mutable, global_name) | ||
|
||
|
||
def apply_fixed_architecture(model, fixed_arc): | ||
def apply_fixed_architecture(model, fixed_arc, verbose=True): | ||
""" | ||
Load architecture from `fixed_arc` and apply to model. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
|
||
|
@@ -123,6 +127,8 @@ def apply_fixed_architecture(model, fixed_arc): | |
Model with mutables. | ||
fixed_arc : str or dict | ||
Path to the JSON that stores the architecture, or dict that stores the exported architecture. | ||
verbose : bool | ||
Print log messages if set to True | ||
|
||
Returns | ||
------- | ||
|
@@ -133,7 +139,7 @@ def apply_fixed_architecture(model, fixed_arc): | |
if isinstance(fixed_arc, str): | ||
with open(fixed_arc) as f: | ||
fixed_arc = json.load(f) | ||
architecture = FixedArchitecture(model, fixed_arc) | ||
architecture = FixedArchitecture(model, fixed_arc, verbose) | ||
architecture.reset() | ||
|
||
# for the convenience of parameters counting | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update the docstring accordingly.