Skip to content

[Improvement] Support for candidate multiple dimensional search constraints.#316

Merged
aptsunny merged 9 commits intoopen-mmlab:autoformer_algo_devfrom
aptsunny:autoformer_algo_candidate
Oct 14, 2022
Merged

[Improvement] Support for candidate multiple dimensional search constraints.#316
aptsunny merged 9 commits intoopen-mmlab:autoformer_algo_devfrom
aptsunny:autoformer_algo_candidate

Conversation

@aptsunny
Copy link
Copy Markdown
Contributor

Part of Autoformer algo

Motivation

Continued improvements of EvolutionSearchLoop throught multi-resources constraints.

Use cases (Optional)

Modify the search configs file as follow.

flops_range=(0., 330.) ->  constraints_range=dict(flops=(0., 330.)),
train_cfg = dict(
    _delete_=True,
    type='mmrazor.EvolutionSearchLoop',
    dataloader=_base_.val_dataloader,
    evaluator=_base_.val_evaluator,
    max_epochs=20,
    num_candidates=20,
    top_k=10,
    num_mutation=5,
    num_crossover=5,
    mutate_prob=0.2,
    constraints_range=dict(params=(0, 55), flops=(0., 330.)),
    dump_derived_mutable=True,
    score_key='accuracy/top1')

Checklist

After PR:

  • The search configuration file for the search algorithm needs to be changed. Please fix it


self.top_k_candidates = Candidates()
if resource_estimator_cfg is None:
if resource_estimator_cfg:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be if resource_estimator_cfg is None?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default resource_estimator_cfg is dict.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then directly use self.estimator = ResourceEstimator(**resource_estimator_cfg)

crossover_candidate = self._crossover()

if self._check_constraints(random_subnet=crossover_candidate):
flag = False
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reify the flag here as it suits the particular judgment of model constraints.

any to tuple(any, float, float)."""

def _format_item(item: Any):
"""Transform any to tuple(any, float)."""
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modify docstring here.

@aptsunny aptsunny force-pushed the autoformer_algo_candidate branch from 4fdfa3a to a1fa920 Compare October 13, 2022 03:09
assert hasattr(model, 'set_subnet') and hasattr(model, 'architecture')
model.set_subnet(subnet)
fix_mutable = export_fix_subnet(model)
fix_mutable = export_fix_subnet(model, dump_derived)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove dump_derived

crossover_candidate = self._crossover()

if self._check_constraints(random_subnet=crossover_candidate):
flag = False
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename flag

@sunnyxiaohu
Copy link
Copy Markdown
Contributor

update type-hint for Candidate::append, extend, insert. It seems that they must accept Dict as input.

return subnet

def _check_constraints(self, random_subnet: SupportRandomSubnet) -> bool:
def _check_constraints(self,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update docstring

constraints_range (Dict[str, Any]): Constraints to be used for
screening candidates. Defaults to dict(flops=(0, 330)).
resource_estimator_cfg (Dict[str, Any]): Used for building a
resource estimator. Default to dict().
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type: Default -> Defaults

"""The data structure of sampled candidate. The format is [(any, float),
(any, float), ...].
"""The data structure of sampled candidate. The format is Union[Dict[Any,
Dict], List[Dict[Any, Dict]]].
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The format is List[Dict[Any, Dict]]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@codecov
Copy link
Copy Markdown

codecov bot commented Oct 13, 2022

Codecov Report

❗ No coverage uploaded for pull request base (autoformer_algo_dev@b4b7e24). Click here to learn what that means.
Patch has no changes to coverable lines.

Additional details and impacted files
@@                  Coverage Diff                   @@
##             autoformer_algo_dev     #316   +/-   ##
======================================================
  Coverage                       ?   82.84%           
======================================================
  Files                          ?      190           
  Lines                          ?     8375           
  Branches                       ?     1307           
======================================================
  Hits                           ?     6938           
  Misses                         ?     1175           
  Partials                       ?      262           
Flag Coverage Δ
unittests 82.84% <0.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@aptsunny aptsunny merged commit 325dd32 into open-mmlab:autoformer_algo_dev Oct 14, 2022
humu789 pushed a commit to humu789/mmrazor that referenced this pull request Feb 13, 2023
* Update mmcls pplnn benchmark

* Update supported model list
humu789 pushed a commit to humu789/mmrazor that referenced this pull request Feb 13, 2023
* support for litehrnet

* support ncnn vulkan

* update supported models

* add docstring

* add one ut and fix wrapper

* add test_shuffleunit

* add test_stem_forward

* add last ut

* fix flake8

* fix yapf

* fix lint

* fix yapf

* fix comments

* unified chunk

* mv adaptive_avg_pool

* fix lint

* move adaptive_avg_pool_ncnn

* fix lint

* symbolic rewriter of adaptive_avg_pool2d

* fix lint

* fix yapf

* fix ci
@openmmlab-bot
Copy link
Copy Markdown
Collaborator

openmmlab-bot commented Mar 28, 2023

aptsunny,您好!您在MMRazor项目中给我们提的PR非常重要,感谢您付出私人时间帮助改进开源项目,相信很多开发者会从你的PR中受益。
我们非常期待与您继续合作,OpenMMLab专门成立了贡献者组织MMSIG,为贡献者们提供开源证书、荣誉体系和专享好礼,可通过添加微信:openmmlabwx 联系我们(请备注mmsig+GitHub id),由衷希望您能加入!
Dear aptsunny,
First of all, we want to express our gratitude for your significant PR in the MMXXX project. Your contribution is highly appreciated, and we are grateful for your efforts in helping improve this open-source project during your personal time. We believe that many developers will benefit from your PR.
We are looking forward to continuing our collaboration with you. OpenMMLab has established a special contributors' organization called MMSIG, which provides contributors with open-source certificates, a recognition system, and exclusive rewards. You can contact us by adding our WeChat(if you have WeChat): openmmlab_wx, or join in our discord: https://discord.gg/raweFPmdzG. We sincerely hope you will join us!
Best regards! @aptsunny

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants