Skip to content
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

[Refactor] Refactor Mutables and Mutators #324

Merged
merged 17 commits into from
Nov 1, 2022
88 changes: 56 additions & 32 deletions configs/nas/mmcls/darts/DARTS_SUBNET_CIFAR_PAPER_ALIAS.yaml
Original file line number Diff line number Diff line change
@@ -1,56 +1,80 @@
normal_n2:
- normal_n2_p0
- normal_n2_p1
chosen:
- normal_n2_p0
- normal_n2_p1
normal_n2_p0:
- sep_conv_3x3
chosen:
- sep_conv_3x3
normal_n2_p1:
- sep_conv_3x3
chosen:
- sep_conv_3x3
normal_n3:
- normal_n3_p0
- normal_n3_p1
chosen:
- normal_n3_p0
- normal_n3_p1
normal_n3_p0:
- skip_connect
chosen:
- skip_connect
normal_n3_p1:
- sep_conv_5x5
chosen:
- sep_conv_5x5
normal_n4:
- normal_n4_p0
- normal_n4_p1
chosen:
- normal_n4_p0
- normal_n4_p1
normal_n4_p0:
- sep_conv_3x3
chosen:
- sep_conv_3x3
normal_n4_p1:
- skip_connect
chosen:
- skip_connect
normal_n5:
- normal_n5_p0
- normal_n5_p1
chosen:
- normal_n5_p0
- normal_n5_p1
normal_n5_p0:
- skip_connect
chosen:
- skip_connect
normal_n5_p1:
- skip_connect
chosen:
- skip_connect
reduce_n2:
- reduce_n2_p0
- reduce_n2_p1
chosen:
- reduce_n2_p0
- reduce_n2_p1
reduce_n2_p0:
- max_pool_3x3
chosen:
- max_pool_3x3
reduce_n2_p1:
- sep_conv_3x3
chosen:
- sep_conv_3x3
reduce_n3:
- reduce_n3_p0
- reduce_n3_p2
chosen:
- reduce_n3_p0
- reduce_n3_p2
reduce_n3_p0:
- max_pool_3x3
chosen:
- max_pool_3x3
reduce_n3_p2:
- dil_conv_5x5
chosen:
- dil_conv_5x5
reduce_n4:
- reduce_n4_p0
- reduce_n4_p2
chosen:
- reduce_n4_p0
- reduce_n4_p2
reduce_n4_p0:
- max_pool_3x3
chosen:
- max_pool_3x3
reduce_n4_p2:
- skip_connect
chosen:
- skip_connect
reduce_n5:
- reduce_n5_p0
- reduce_n5_p2
chosen:
- reduce_n5_p0
- reduce_n5_p2
reduce_n5_p0:
- max_pool_3x3
chosen:
- max_pool_3x3
reduce_n5_p2:
- skip_connect
chosen:
- skip_connect
60 changes: 40 additions & 20 deletions configs/nas/mmcls/dsnas/DSNAS_SUBNET_IMAGENET_PAPER_ALIAS.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,40 @@
backbone.layers.0.0: shuffle_3x3
backbone.layers.0.1: shuffle_3x3
backbone.layers.0.2: shuffle_xception
backbone.layers.0.3: shuffle_3x3
backbone.layers.1.0: shuffle_xception
backbone.layers.1.1: shuffle_7x7
backbone.layers.1.2: shuffle_3x3
backbone.layers.1.3: shuffle_3x3
backbone.layers.2.0: shuffle_xception
backbone.layers.2.1: shuffle_xception
backbone.layers.2.2: shuffle_7x7
backbone.layers.2.3: shuffle_xception
backbone.layers.2.4: shuffle_xception
backbone.layers.2.5: shuffle_xception
backbone.layers.2.6: shuffle_7x7
backbone.layers.2.7: shuffle_3x3
backbone.layers.3.0: shuffle_3x3
backbone.layers.3.1: shuffle_xception
backbone.layers.3.2: shuffle_xception
backbone.layers.3.3: shuffle_3x3
backbone.layers.0.0:
chosen: shuffle_3x3
backbone.layers.0.1:
chosen: shuffle_7x7
backbone.layers.0.2:
chosen: shuffle_3x3
backbone.layers.0.3:
chosen: shuffle_5x5
backbone.layers.1.0:
chosen: shuffle_3x3
backbone.layers.1.1:
chosen: shuffle_3x3
backbone.layers.1.2:
chosen: shuffle_3x3
backbone.layers.1.3:
chosen: shuffle_7x7
backbone.layers.2.0:
chosen: shuffle_xception
backbone.layers.2.1:
chosen: shuffle_3x3
backbone.layers.2.2:
chosen: shuffle_3x3
backbone.layers.2.3:
chosen: shuffle_5x5
backbone.layers.2.4:
chosen: shuffle_3x3
backbone.layers.2.5:
chosen: shuffle_5x5
backbone.layers.2.6:
chosen: shuffle_7x7
backbone.layers.2.7:
chosen: shuffle_7x7
backbone.layers.3.0:
chosen: shuffle_xception
backbone.layers.3.1:
chosen: shuffle_3x3
backbone.layers.3.2:
chosen: shuffle_7x7
backbone.layers.3.3:
chosen: shuffle_3x3
23 changes: 1 addition & 22 deletions configs/nas/mmcls/dsnas/dsnas_subnet_8xb128_in1k.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,7 @@
_base_ = ['./dsnas_supernet_8xb128_in1k.py']

# NOTE: Replace this with the mutable_cfg searched by yourself.
fix_subnet = {
'backbone.layers.0.0': 'shuffle_3x3',
'backbone.layers.0.1': 'shuffle_7x7',
'backbone.layers.0.2': 'shuffle_3x3',
'backbone.layers.0.3': 'shuffle_5x5',
'backbone.layers.1.0': 'shuffle_3x3',
'backbone.layers.1.1': 'shuffle_3x3',
'backbone.layers.1.2': 'shuffle_3x3',
'backbone.layers.1.3': 'shuffle_7x7',
'backbone.layers.2.0': 'shuffle_xception',
'backbone.layers.2.1': 'shuffle_3x3',
'backbone.layers.2.2': 'shuffle_3x3',
'backbone.layers.2.3': 'shuffle_5x5',
'backbone.layers.2.4': 'shuffle_3x3',
'backbone.layers.2.5': 'shuffle_5x5',
'backbone.layers.2.6': 'shuffle_7x7',
'backbone.layers.2.7': 'shuffle_7x7',
'backbone.layers.3.0': 'shuffle_xception',
'backbone.layers.3.1': 'shuffle_3x3',
'backbone.layers.3.2': 'shuffle_7x7',
'backbone.layers.3.3': 'shuffle_3x3',
}
fix_subnet = 'configs/nas/mmcls/dsnas/DSNAS_SUBNET_IMAGENET_PAPER_ALIAS.yaml'

model = dict(fix_subnet=fix_subnet)

Expand Down
4 changes: 2 additions & 2 deletions configs/nas/mmcls/dsnas/dsnas_supernet_8xb128_in1k.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# model
model = dict(
type='mmrazor.Dsnas',
type='mmrazor.DSNAS',
architecture=dict(
type='ImageClassifier',
data_preprocessor=_base_.data_preprocessor,
Expand All @@ -29,7 +29,7 @@
)

model_wrapper_cfg = dict(
type='mmrazor.DsnasDDP',
type='mmrazor.DSNASDDP',
broadcast_buffers=False,
find_unused_parameters=True)

Expand Down
40 changes: 40 additions & 0 deletions configs/nas/mmcls/spos/SPOS_SUBNET.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
backbone.layers.0.0:
chosen: shuffle_7x7
backbone.layers.0.1:
chosen: shuffle_3x3
backbone.layers.0.2:
chosen: shuffle_7x7
backbone.layers.0.3:
chosen: shuffle_3x3
backbone.layers.1.0:
chosen: shuffle_xception
backbone.layers.1.1:
chosen: shuffle_5x5
backbone.layers.1.2:
chosen: shuffle_5x5
backbone.layers.1.3:
chosen: shuffle_3x3
backbone.layers.2.0:
chosen: shuffle_3x3
backbone.layers.2.1:
chosen: shuffle_5x5
backbone.layers.2.2:
chosen: shuffle_3x3
backbone.layers.2.3:
chosen: shuffle_5x5
backbone.layers.2.4:
chosen: shuffle_3x3
backbone.layers.2.5:
chosen: shuffle_xception
backbone.layers.2.6:
chosen: shuffle_5x5
backbone.layers.2.7:
chosen: shuffle_7x7
backbone.layers.3.0:
chosen: shuffle_7x7
backbone.layers.3.1:
chosen: shuffle_3x3
backbone.layers.3.2:
chosen: shuffle_5x5
backbone.layers.3.3:
chosen: shuffle_xception
4 changes: 2 additions & 2 deletions configs/nas/mmcls/spos/spos_shufflenet_subnet_8xb128_in1k.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
_base_ = ['./spos_shufflenet_supernet_8xb128_in1k.py']

# FIXME: you may replace this with the mutable_cfg searched by yourself
fix_subnet = 'https://download.openmmlab.com/mmrazor/v1/spos/spos_shufflenetv2_subnet_8xb128_in1k_flops_0.33M_acc_73.87_20220715-aa94d5ef_subnet_cfg_v1.yaml' # noqa: E501
# FIXME: you may replace this with the searched by yourself
fix_subnet = 'configs/nas/mmcls/spos/SPOS_SUBNET.yaml'

model = dict(fix_subnet=fix_subnet)

Expand Down
40 changes: 40 additions & 0 deletions configs/nas/mmdet/detnas/DETNAS_SUBNET.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
backbone.layers.0.0:
chosen: shuffle_5x5
backbone.layers.0.1:
chosen: shuffle_3x3
backbone.layers.0.2:
chosen: shuffle_3x3
backbone.layers.0.3:
chosen: shuffle_3x3
backbone.layers.1.0:
chosen: shuffle_xception
backbone.layers.1.1:
chosen: shuffle_3x3
backbone.layers.1.2:
chosen: shuffle_xception
backbone.layers.1.3:
chosen: shuffle_7x7
backbone.layers.2.0:
chosen: shuffle_7x7
backbone.layers.2.1:
chosen: shuffle_7x7
backbone.layers.2.2:
chosen: shuffle_xception
backbone.layers.2.3:
chosen: shuffle_xception
backbone.layers.2.4:
chosen: shuffle_3x3
backbone.layers.2.5:
chosen: shuffle_7x7
backbone.layers.2.6:
chosen: shuffle_5x5
backbone.layers.2.7:
chosen: shuffle_xception
backbone.layers.3.0:
chosen: shuffle_7x7
backbone.layers.3.1:
chosen: shuffle_7x7
backbone.layers.3.2:
chosen: shuffle_7x7
backbone.layers.3.3:
chosen: shuffle_5x5
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
_base_ = ['./detnas_frcnn_shufflenet_supernet_coco_1x.py']

# FIXME: you may replace this with the searched by yourself
fix_subnet = 'https://download.openmmlab.com/mmrazor/v1/detnas/detnas_subnet_frcnn_shufflenetv2_fpn_1x_coco_bbox_backbone_flops-0.34M_mAP-37.5_20220715-61d2e900_subnet_cfg_v1.yaml' # noqa: E501
fix_subnet = 'configs/nas/mmdet/detnas/DETNAS_SUBNET.yaml'

model = dict(fix_subnet=fix_subnet)

Expand Down
6 changes: 3 additions & 3 deletions mmrazor/models/algorithms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .distill import (DAFLDataFreeDistillation, DataFreeDistillation,
FpnTeacherDistill, OverhaulFeatureDistillation,
SelfDistill, SingleTeacherDistill)
from .nas import SPOS, AutoSlim, AutoSlimDDP, Darts, DartsDDP, Dsnas, DsnasDDP
from .nas import DSNAS, DSNASDDP, SPOS, AutoSlim, AutoSlimDDP, Darts, DartsDDP
from .pruning import SlimmableNetwork, SlimmableNetworkDDP
from .pruning.ite_prune_algorithm import ItePruneAlgorithm

Expand All @@ -23,6 +23,6 @@
'DAFLDataFreeDistillation',
'OverhaulFeatureDistillation',
'ItePruneAlgorithm',
'Dsnas',
'DsnasDDP',
'DSNAS',
'DSNASDDP',
]
4 changes: 2 additions & 2 deletions mmrazor/models/algorithms/nas/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Copyright (c) OpenMMLab. All rights reserved.
from .autoslim import AutoSlim, AutoSlimDDP
from .darts import Darts, DartsDDP
from .dsnas import Dsnas, DsnasDDP
from .dsnas import DSNAS, DSNASDDP
from .spos import SPOS

__all__ = [
'SPOS', 'AutoSlim', 'AutoSlimDDP', 'Darts', 'DartsDDP', 'Dsnas', 'DsnasDDP'
'SPOS', 'AutoSlim', 'AutoSlimDDP', 'Darts', 'DartsDDP', 'DSNAS', 'DSNASDDP'
]
4 changes: 2 additions & 2 deletions mmrazor/models/algorithms/nas/dsnas.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


@MODELS.register_module()
class Dsnas(BaseAlgorithm):
class DSNAS(BaseAlgorithm):
"""Implementation of `DSNAS <https://arxiv.org/abs/2002.09128>`_

Args:
Expand Down Expand Up @@ -272,7 +272,7 @@ def handle_grads(self):


@MODEL_WRAPPERS.register_module()
class DsnasDDP(MMDistributedDataParallel):
class DSNASDDP(MMDistributedDataParallel):

def __init__(self,
*,
Expand Down
Loading