Skip to content

Commit

Permalink
redesign candidate
Browse files Browse the repository at this point in the history
  • Loading branch information
aptsunny committed Oct 18, 2022
1 parent c314033 commit 6afafea
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 14 deletions.
5 changes: 0 additions & 5 deletions mmrazor/engine/runner/evolution_search_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,3 @@ def _check_constraints(
constraints_range=self.constraints_range)

return is_pass, results


if __name__ == '__main__':
import unittest
unittest.main()
2 changes: 1 addition & 1 deletion mmrazor/engine/runner/utils/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def check_subnet_resources(
"""Check whether is beyond resources constraints.
Returns:
bool: The result of checking.
bool, result: The result of checking.
"""
if constraints_range is None:
return True, dict()
Expand Down
10 changes: 7 additions & 3 deletions mmrazor/structures/subnet/candidate.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ def _format(self, data: _format_input) -> _format_return:
def _format_item(
cond: Union[Dict, Dict[str, Dict]]) -> Dict[str, Dict]:
"""Transform Dict to Dict[str, Dict]."""
if isinstance(list(cond.values())[0], str):
return {str(cond): {}.fromkeys(self._indicators, -1)}
else:
if isinstance(list(cond.values())[0], dict):
for value in list(cond.values()):
for key in list(self._indicators):
value.setdefault(key, 0.)
return cond
else:
return {str(cond): {}.fromkeys(self._indicators, -1)}

if isinstance(data, UserList):
return [_format_item(i) for i in data.data]
Expand Down Expand Up @@ -134,6 +134,10 @@ def extend(self, other: Any) -> None:
else:
self.data.extend([other])

def set_score(self, i: int, score: float) -> None:
"""Set score to the specified subnet by index."""
self.set_resource(i, score, 'score')

def set_resource(self,
i: int,
resources: float,
Expand Down
5 changes: 0 additions & 5 deletions tests/test_runners/test_utils/test_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,3 @@ def test_check_subnet_resources(mock_model, mock_estimator):
is_pass, _ = check_subnet_resources(mock_model, fake_subnet,
mock_estimator, constraints_range)
assert is_pass is False


if __name__ == '__main__':
import unittest
unittest.main()

0 comments on commit 6afafea

Please sign in to comment.