Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Request for Integrating the new NAS algorithm: Cream #2705

Merged
merged 74 commits into from
Nov 27, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
a426e1a
integrate CREAM NAS algorithm
penghouwen Jul 20, 2020
57a2c40
Update README.md
penghouwen Jul 20, 2020
c15832f
Update Cream.md
penghouwen Jul 31, 2020
806937c
Update Cream.md
penghouwen Jul 31, 2020
b13fed0
Update Cream.md
penghouwen Jul 31, 2020
d7c3217
Update requirements.txt
penghouwen Jul 31, 2020
1951db0
Update Cream.md
penghouwen Jul 31, 2020
bce9cf2
Update requirements.txt
penghouwen Jul 31, 2020
cda252b
Update Cream.md
penghouwen Jul 31, 2020
29b6d5d
Update Cream.md
penghouwen Jul 31, 2020
e548cbc
Update Cream.md
penghouwen Jul 31, 2020
d5c95c6
Update Cream.md
penghouwen Jul 31, 2020
c73b95c
Update trainer.py
penghouwen Aug 1, 2020
0adaf7c
Update mutator.py
penghouwen Aug 1, 2020
85f01e9
Update Cream.md
penghouwen Aug 3, 2020
047fd86
Update Cream.md
penghouwen Aug 3, 2020
b22f92c
Update Cream.md
penghouwen Aug 3, 2020
3ee7591
Update Cream.md
penghouwen Aug 3, 2020
be81d53
Update Cream.md
penghouwen Aug 3, 2020
9535466
Fix pipeline for merging into NNI
ultmaster Aug 4, 2020
0892e66
Fix typo
ultmaster Aug 4, 2020
999d18c
Merge pull request #1 from ultmaster/fix-cream-before-merge
penghouwen Aug 4, 2020
2e13a23
Fix pipeline
ultmaster Aug 5, 2020
22a3f46
Add files via upload
penghouwen Aug 7, 2020
b1777f0
Update Cream.md
penghouwen Aug 7, 2020
4fcbaa9
Update CDARTS.md
penghouwen Aug 7, 2020
2205433
Update Cream.md
penghouwen Aug 7, 2020
b277b96
Update CDARTS.md
penghouwen Aug 7, 2020
8d413bf
Update CDARTS.md
penghouwen Aug 7, 2020
cc9f336
Update distributed_train.sh
penghouwen Sep 3, 2020
9494493
Update distributed_test.sh
penghouwen Sep 3, 2020
6a332ff
Update Cream.md
penghouwen Sep 3, 2020
b35ccac
init
Sep 27, 2020
c872739
Merge pull request #2 from mapleam/master
penghouwen Sep 27, 2020
9289614
Update supernet.py
Z7zuqer Sep 27, 2020
ab9d398
1)remove timm
Sep 27, 2020
82eee8d
Merge pull request #3 from mapleam/master
penghouwen Sep 27, 2020
2559697
Delete cream.jpg
penghouwen Oct 22, 2020
e48d293
Add files via upload
penghouwen Oct 22, 2020
a71563b
Update Cream.md
penghouwen Oct 22, 2020
c00c58e
version 1.0
Z7zuqer Nov 18, 2020
4d72a70
version 2.0
Z7zuqer Nov 21, 2020
60e5197
Merge pull request #4 from mapleam/master
penghouwen Nov 23, 2020
37518fa
Update Cream.md
penghouwen Nov 23, 2020
e04200c
Update Cream.md
penghouwen Nov 23, 2020
47dce8c
Update Cream.md
penghouwen Nov 23, 2020
5231d3b
Update Cream.md
penghouwen Nov 23, 2020
ce698c3
Update Cream.md
penghouwen Nov 23, 2020
0d63ceb
Update Cream.md
penghouwen Nov 23, 2020
274fb23
version 3.0
Z7zuqer Nov 23, 2020
931c47b
Merge branch 'master' into master
Z7zuqer Nov 23, 2020
59b1339
Merge pull request #5 from mapleam/master
penghouwen Nov 23, 2020
c162f39
Update Cream.md
penghouwen Nov 23, 2020
de8c261
Update Cream.md
penghouwen Nov 23, 2020
ae45787
Update Cream.md
Z7zuqer Nov 23, 2020
43101c1
Update retrain.py
Z7zuqer Nov 23, 2020
36ddeaf
Update test.py
Z7zuqer Nov 23, 2020
97451af
Update retrain.py
Z7zuqer Nov 23, 2020
96cfb17
Merge branch 'master' into master
Z7zuqer Nov 23, 2020
d735a25
Merge pull request #6 from mapleam/master
penghouwen Nov 23, 2020
8d24833
version 4.0
Z7zuqer Nov 23, 2020
a53cc5f
Merge remote-tracking branch 'origin/master'
Z7zuqer Nov 23, 2020
cce57e5
version 4.0
Z7zuqer Nov 23, 2020
d9cfd2f
Merge pull request #7 from mapleam/master
penghouwen Nov 24, 2020
0f8f8bf
Update Cream.md
penghouwen Nov 24, 2020
879bfeb
Update Cream.md
penghouwen Nov 24, 2020
85b17b4
Merge branch 'master' into master
penghouwen Nov 24, 2020
0cf817b
Move code dir
ultmaster Nov 24, 2020
fdeb0b9
Fix trainer and retrain optimizer
ultmaster Nov 25, 2020
d11e4cf
Update Cream.md
penghouwen Nov 25, 2020
06af2cb
Fix syntax warning
ultmaster Nov 26, 2020
6cb3b97
Fix syntax warning (again)
ultmaster Nov 26, 2020
9996098
Fix docs build warnings
ultmaster Nov 26, 2020
02b8e72
Merge branch 'master' of github.com:penghouwen/nni into cream-master
ultmaster Nov 26, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ Within the following table, we summarized the current NNI capabilities, we are g
<li><a href="docs/en_US/NAS/Proxylessnas.md">ProxylessNAS</a></li>
<li><a href="docs/en_US/Tuner/BuiltinTuner.md#NetworkMorphism">Network Morphism</a></li>
<li><a href="docs/en_US/NAS/TextNAS.md">TextNAS</a></li>
<li><a href="docs/en_US/NAS/Cream.md">Cream</a></li>
</ul>
</ul>
<a href="docs/en_US/Compressor/Overview.md">Model Compression</a>
Expand Down
79 changes: 79 additions & 0 deletions docs/en_US/NAS/Cream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Cream of the Crop: Distilling Prioritized Paths For One-Shot Neural Architecture Search

## Introduction
One-shot weight sharing methods have recently drawn great attention in neural architecture search due to high efficiency and competitive performance. However, weight sharing across models has an inherent deficiency, i.e., insufficient training
of subnetworks in the hypernetwork. To alleviate this problem, we present a simple yet effective architecture distillation method. The central idea is that subnetworks can learn collaboratively and teach each other throughout the training
process, aiming to boost the convergence of individual models. We introduce the concept of prioritized path, which refers to the architecture candidates exhibiting superior performance during training. Distilling knowledge from the prioritized
paths is able to boost the training of subnetworks. Since the prioritized paths are changed on the fly depending on their performance and complexity, the final obtained paths are the cream of the crop. We directly select the most promising
one from the prioritized paths as the final architecture, without using other complex search methods, such as reinforcement learning or evolution algorithms. The experiments on ImageNet verify such path distillation method can improve the
convergence ratio and performance of the hypernetwork, as well as boosting the training of subnetworks. The discovered architectures achieve superior performance compared to the recent MobileNetV3 and EfficientNet families under aligned
penghouwen marked this conversation as resolved.
Show resolved Hide resolved
settings. Moreover, the experiments on object detection and more challenging search space show the generality and robustness of the proposed method.

## Reproduction Results

## Examples

[Example code](https://github.com/microsoft/nni/tree/master/examples/nas/cream)

## Requirements
* python >= 3.6
* torch >= 1.2
* torchscope
* apex (not necessary, please make sure your nvcc CUDA version is the same with pytorch CUDA verision)
penghouwen marked this conversation as resolved.
Show resolved Hide resolved

## Data Preparation
You need to first download the [ImageNet-2012](http://www.image-net.org/) to the folder `./data/imagenet` and move the validation set to the subfolder `./data/imagenet/val`. To move the validation set, you cloud use the following script: <https://raw.githubusercontent.com/soumith/imagenetloader.torch/master/valprep.sh>

Put the imagenet data in ${Root}/data. It should be like following:
```buildoutcfg
${Root}/data/imagenet/train
penghouwen marked this conversation as resolved.
Show resolved Hide resolved
${Root}/data/imagenet/val
...
```


## Quick Start

### I. Search

First, build environments for searching.
```
pip install -r ./examples/nas/cream/requirements.txt
```

To search for an architecture, you need to configure the parameters `flops_minimum` and `flops_maximum` to specify the desired model flops, such as [0,600]MB flops. You can specify the flops interval by changing these two parameters in `./examples/nas/cream/supernet.sh`
penghouwen marked this conversation as resolved.
Show resolved Hide resolved
penghouwen marked this conversation as resolved.
Show resolved Hide resolved
```buildoutcfg
--flops_minimum 0 # Minimum Flops of Architecture
--flops_maximum 600 # Maximum Flops of Architecture
```

After you specify the flops of the architectures you would like to search, you can search an architecture now by running:
penghouwen marked this conversation as resolved.
Show resolved Hide resolved
```buildoutcfg
sh ./experiments/scripts/supernet.sh

```

### II. Test
To test our trained of models, you need to use `model_selection` in `./examples/nas/cream/test.sh` to specify which model to test.
penghouwen marked this conversation as resolved.
Show resolved Hide resolved
```buildoutcfg
--model_selection 42 # test 42m model
--model_selection 470 # test 470m model
......
```

After specifying the flops of the model, you need to write the path to the resume model in `./examples/nas/cream/test.sh`.
```buildoutcfg
--resume './experiments/ckps/42.pth.tar'
--resume './experiments/ckps/470.pth.tar'
......
```

We provide 14M/42M/114M/285M/470M/600M pretrained models in [google drive](https://drive.google.com/drive/folders/1CQjyBryZ4F20Rutj7coF8HWFcedApUn2).
After downloading the pretrained models and adding `--model_selection` and `--resume` in './experiments/scripts/test.sh', you need to use the following command to test the model.
```buildoutcfg
sh ./experiments/scripts/test.sh
```

The test result will be saved in `./retrain`. You can configure the `--ouput` in `./examples/nas/cream/test.sh` to specify a path for it.


94 changes: 94 additions & 0 deletions examples/nas/cream/Cream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Cream of the Crop: Distilling Prioritized Paths For One-Shot Neural Architecture Search
penghouwen marked this conversation as resolved.
Show resolved Hide resolved

## Introduction
One-shot weight sharing methods have recently drawn great attention in neural architecture search due to high efficiency and competitive performance. However, weight sharing across models has an inherent deficiency, i.e., insufficient training
of subnetworks in the hypernetwork. To alleviate this problem, we present a simple yet effective architecture distillation method. The central idea is that subnetworks can learn collaboratively and teach each other throughout the training
process, aiming to boost the convergence of individual models. We introduce the concept of prioritized path, which refers to the architecture candidates exhibiting superior performance during training. Distilling knowledge from the prioritized
paths is able to boost the training of subnetworks. Since the prioritized paths are changed on the fly depending on their performance and complexity, the final obtained paths are the cream of the crop. We directly select the most promising
one from the prioritized paths as the final architecture, without using other complex search methods, such as reinforcement learning or evolution algorithms. The experiments on ImageNet verify such path distillation method can improve the
convergence ratio and performance of the hypernetwork, as well as boosting the training of subnetworks. The discovered architectures achieve superior performance compared to the recent MobileNetV3 and EfficientNet families under aligned
settings. Moreover, the experiments on object detection and more challenging search space show the generality and robustness of the proposed method.

## Reproduction Results

## Examples

[Example code](https://github.com/microsoft/nni/tree/master/examples/nas/cream)

## Requirements
* python >= 3.6
* torch >= 1.2
* torchscope
* apex (not necessary, please make sure your nvcc CUDA version is the same with pytorch CUDA verision)

## Data Preparation
You need to first download the [ImageNet-2012](http://www.image-net.org/) to the folder `./data/imagenet` and move the validation set to the subfolder `./data/imagenet/val`. To move the validation set, you cloud use the following script: <https://raw.githubusercontent.com/soumith/imagenetloader.torch/master/valprep.sh>

Put the imagenet data in ${Root}/data. It should be like following:
```buildoutcfg
${Root}/data/imagenet/train
${Root}/data/imagenet/val
...
```


## Quick Start

### I. Search

First, build environments for searching.
```
pip install -r ./examples/nas/cream/requirements.txt
```

To search for an architecture, you need to configure the parameters `flops_minimum` and `flops_maximum` to specify the desired model flops, such as [0,600]MB flops. You can specify the flops interval by changing these two parameters in `./examples/nas/cream/supernet.sh`
```buildoutcfg
--flops_minimum 0 # Minimum Flops of Architecture
--flops_maximum 600 # Maximum Flops of Architecture
```

After you specify the flops of the architectures you would like to search, you can search an architecture now by running:
```buildoutcfg
sh ./experiments/scripts/supernet.sh

```

### II. Test
To test our trained of models, you need to use `model_selection` in `./examples/nas/cream/test.sh` to specify which model to test.
```buildoutcfg
--model_selection 42 # test 42m model
--model_selection 470 # test 470m model
......
```

After specifying the flops of the model, you need to write the path to the resume model in `./examples/nas/cream/test.sh`.
```buildoutcfg
--resume './experiments/ckps/42.pth.tar'
--resume './experiments/ckps/470.pth.tar'
......
```

We provide 14M/42M/114M/285M/470M/600M pretrained models in [google drive](https://drive.google.com/drive/folders/1CQjyBryZ4F20Rutj7coF8HWFcedApUn2).
After downloading the pretrained models and adding `--model_selection` and `--resume` in './experiments/scripts/test.sh', you need to use the following command to test the model.
```buildoutcfg
sh ./experiments/scripts/test.sh
```

The test result will be saved in `./retrain`. You can configure the `--ouput` in `./examples/nas/cream/test.sh` to specify a path for it.


### PyTorch

```eval_rst
.. autoclass:: nni.nas.pytorch.cdarts.CdartsTrainer
:members:

.. autoclass:: nni.nas.pytorch.cdarts.RegularizedDartsMutator
:members:

.. autoclass:: nni.nas.pytorch.cdarts.DartsDiscreteMutator
:members:

.. autoclass:: nni.nas.pytorch.cdarts.RegularizedMutatorParallel
:members:
```
Empty file added examples/nas/cream/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions examples/nas/cream/dataset/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from dataset.loader import create_loader
from dataset.base_dataset import Dataset, AugMixDataset
from dataset.utils import resolve_data_config
Loading