-
Notifications
You must be signed in to change notification settings - Fork 227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Improvement] Update estimator with api revision #277
Merged
sunnyxiaohu
merged 7 commits into
open-mmlab:dev-1.x
from
gaoyang07:gy/estimator_update
Sep 14, 2022
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1ae7f5d
update estimator usage and fix bugs
bbbb675
refactor api of estimator & add inner check methods
2992afb
fix docstrings
e67e611
update search loop and config
3e6146c
fix lint
6b16de4
update unittest
1fafeb1
decouple mmdet dependency and fix lint
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
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
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# Copyright (c) OpenMMLab. All rights reserved. | ||
from .check import check_subnet_flops | ||
from .genetic import crossover | ||
|
||
__all__ = ['crossover'] | ||
__all__ = ['crossover', 'check_subnet_flops'] |
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,43 @@ | ||
# Copyright (c) OpenMMLab. All rights reserved. | ||
import copy | ||
from typing import Optional, Tuple | ||
|
||
import torch.nn as nn | ||
from mmdet.models.detectors import BaseDetector | ||
|
||
from mmrazor.models import ResourceEstimator | ||
from mmrazor.structures import export_fix_subnet, load_fix_subnet | ||
from mmrazor.utils import SupportRandomSubnet | ||
|
||
|
||
def check_subnet_flops( | ||
model: nn.Module, | ||
subnet: SupportRandomSubnet, | ||
estimator: ResourceEstimator, | ||
flops_range: Optional[Tuple[float, float]] = None) -> bool: | ||
"""Check whether is beyond flops constraints. | ||
|
||
Returns: | ||
bool: The result of checking. | ||
""" | ||
if flops_range is None: | ||
return True | ||
|
||
assert hasattr(model, 'set_subnet') and hasattr(model, 'architecture') | ||
model.set_subnet(subnet) | ||
fix_mutable = export_fix_subnet(model) | ||
copied_model = copy.deepcopy(model) | ||
load_fix_subnet(copied_model, fix_mutable) | ||
|
||
model_to_check = model.architecture | ||
if isinstance(model_to_check, BaseDetector): | ||
results = estimator.estimate(model=model_to_check.backbone) | ||
else: | ||
results = estimator.estimate(model=model_to_check) | ||
|
||
flops = results['flops'] | ||
flops_mix, flops_max = flops_range | ||
if flops_mix <= flops <= flops_max: # type: ignore | ||
return True | ||
else: | ||
return False |
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
10 changes: 3 additions & 7 deletions
10
mmrazor/models/task_modules/estimators/counters/__init__.py
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 |
---|---|---|
@@ -1,10 +1,6 @@ | ||
# Copyright (c) OpenMMLab. All rights reserved. | ||
from .flops_params_counter import (get_model_complexity_info, | ||
params_units_convert) | ||
from .latency_counter import repeat_measure_inference_speed | ||
from .flops_params_counter import get_model_flops_params | ||
from .latency_counter import get_model_latency | ||
from .op_counters import * # noqa: F401,F403 | ||
|
||
__all__ = [ | ||
'get_model_complexity_info', 'params_units_convert', | ||
'repeat_measure_inference_speed' | ||
] | ||
__all__ = ['get_model_flops_params', 'get_model_latency'] |
Oops, something went wrong.
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.
Try to use PlaceHolder for downstream repos.
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.
Done.