Skip to content

Commit 14e9619

Browse files
authored
Merge pull request #266 from microsoft/master
merge master
2 parents 68abe2f + 3fdbbdb commit 14e9619

File tree

130 files changed

+9459
-1370
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+9459
-1370
lines changed

azure-pipelines.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ jobs:
4949
sphinx-build -M html . _build -W
5050
displayName: 'Sphinx Documentation Build check'
5151
52-
- job: 'ubuntu_1604_python35_legacy_torch_tf'
52+
- job: 'ubuntu_1804_python36_legacy_torch_tf'
5353
pool:
54-
vmImage: 'Ubuntu 16.04'
54+
vmImage: 'Ubuntu 18.04'
5555

5656
steps:
5757
- script: |
@@ -141,7 +141,7 @@ jobs:
141141
powershell.exe -file install.ps1
142142
displayName: 'Install nni toolkit via source code'
143143
- script: |
144-
python -m pip install scikit-learn==0.20.0 --user
144+
python -m pip install scikit-learn==0.23.2 --user
145145
python -m pip install keras==2.1.6 --user
146146
python -m pip install torch==1.5.0+cpu torchvision==0.6.0+cpu -f https://download.pytorch.org/whl/torch_stable.html --user
147147
python -m pip install tensorflow==1.15.2 --user

deployment/docker/Dockerfile

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# Copyright (c) Microsoft Corporation.
22
# Licensed under the MIT license.
33

4-
FROM nvidia/cuda:9.0-cudnn7-runtime-ubuntu16.04
4+
FROM nvidia/cuda:9.2-cudnn7-runtime-ubuntu18.04
55

66
LABEL maintainer='Microsoft NNI Team<[email protected]>'
77

8-
RUN DEBIAN_FRONTEND=noninteractive && \
9-
apt-get -y update && \
8+
ENV DEBIAN_FRONTEND=noninteractive
9+
10+
RUN apt-get -y update && \
1011
apt-get -y install sudo \
1112
apt-utils \
1213
git \
@@ -21,7 +22,7 @@ RUN DEBIAN_FRONTEND=noninteractive && \
2122
openssh-client \
2223
openssh-server \
2324
lsof \
24-
python3.5 \
25+
python3.6 \
2526
python3-dev \
2627
python3-pip \
2728
python3-tk \
@@ -37,7 +38,7 @@ RUN cp /usr/bin/python3 /usr/bin/python
3738
#
3839
# update pip
3940
#
40-
RUN python3 -m pip install --upgrade pip setuptools==39.1.0
41+
RUN python3 -m pip install --upgrade pip==20.0.2 setuptools==39.1.0
4142

4243
# numpy 1.14.3 scipy 1.1.0
4344
RUN python3 -m pip --no-cache-dir install \
@@ -46,7 +47,7 @@ RUN python3 -m pip --no-cache-dir install \
4647
#
4748
# Tensorflow 1.15
4849
#
49-
RUN python3 -m pip --no-cache-dir install tensorflow-gpu==1.15
50+
RUN python3 -m pip --no-cache-dir install tensorflow-gpu==1.15.0
5051

5152
#
5253
# Keras 2.1.6
@@ -60,9 +61,9 @@ RUN python3 -m pip --no-cache-dir install torch==1.4.0
6061
RUN python3 -m pip install torchvision==0.5.0
6162

6263
#
63-
# sklearn 0.20.0
64+
# sklearn 0.23.2
6465
#
65-
RUN python3 -m pip --no-cache-dir install scikit-learn==0.20.0
66+
RUN python3 -m pip --no-cache-dir install scikit-learn==0.23.2
6667

6768
#
6869
# pandas==0.23.4 lightgbm==2.2.2

deployment/docker/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ scipy 1.1.0
1111
tensorflow-gpu 1.15.0
1212
keras 2.1.6
1313
torch 1.4.0
14-
scikit-learn 0.20.0
14+
scikit-learn 0.23.2
1515
pandas 0.23.4
1616
lightgbm 2.2.2
1717
nni

deployment/docker/README_zh_CN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@
4747

4848
使用下列命令从 docker Hub 中拉取 NNI docker 映像。
4949

50-
docker pull msranni/nni:latest
50+
docker pull msranni/nni:latest

deployment/pypi/setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
'scipy',
6464
'coverage',
6565
'colorama',
66-
'scikit-learn>=0.20,<0.22',
66+
'scikit-learn>=0.23.2',
6767
'pkginfo',
6868
'websockets'
6969
],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Comparison of Filter Pruning Algorithms
2+
3+
To provide an initial insight into the performance of various filter pruning algorithms,
4+
we conduct extensive experiments with various pruning algorithms on some benchmark models and datasets.
5+
We present the experiment result in this document.
6+
In addition, we provide friendly instructions on the re-implementation of these experiments to facilitate further contributions to this effort.
7+
8+
## Experiment Setting
9+
10+
The experiments are performed with the following pruners/datasets/models:
11+
12+
* Models: [VGG16, ResNet18, ResNet50](https://github.com/microsoft/nni/tree/master/examples/model_compress/models/cifar10)
13+
14+
* Datasets: CIFAR-10
15+
16+
* Pruners:
17+
- These pruners are included:
18+
- Pruners with scheduling : `SimulatedAnnealing Pruner`, `NetAdapt Pruner`, `AutoCompress Pruner`.
19+
Given the overal sparsity requirement, these pruners can automatically generate a sparsity distribution among different layers.
20+
- One-shot pruners: `L1Filter Pruner`, `L2Filter Pruner`, `FPGM Pruner`.
21+
The sparsity of each layer is set the same as the overall sparsity in this experiment.
22+
- Only **filter pruning** performances are compared here.
23+
24+
For the pruners with scheduling, `L1Filter Pruner` is used as the base algorithm. That is to say, after the sparsities distribution is decided by the scheduling algorithm, `L1Filter Pruner` is used to performn real pruning.
25+
26+
- All the pruners listed above are implemented in [nni](https://github.com/microsoft/nni/tree/master/docs/en_US/Compressor/Overview.md).
27+
28+
## Experiment Result
29+
30+
For each dataset/model/pruner combination, we prune the model to different levels by setting a series of target sparsities for the pruner.
31+
32+
Here we plot both **Number of Weights - Performances** curve and **FLOPs - Performance** curve.
33+
As a reference, we also plot the result declared in the paper [AutoCompress: An Automatic DNN Structured Pruning Framework for Ultra-High Compression Rates](http://arxiv.org/abs/1907.03141) for models VGG16 and ResNet18 on CIFAR-10.
34+
35+
The experiment result are shown in the following figures:
36+
37+
CIFAR-10, VGG16:
38+
39+
![](../../../examples/model_compress/comparison_of_pruners/img/performance_comparison_vgg16.png)
40+
41+
CIFAR-10, ResNet18:
42+
43+
![](../../../examples/model_compress/comparison_of_pruners/img/performance_comparison_resnet18.png)
44+
45+
CIFAR-10, ResNet50:
46+
47+
![](../../../examples/model_compress/comparison_of_pruners/img/performance_comparison_resnet50.png)
48+
49+
## Analysis
50+
51+
From the experiment result, we get the following conclusions:
52+
53+
* Given the constraint on the number of parameters, the pruners with scheduling ( `AutoCompress Pruner` , `SimualatedAnnealing Pruner` ) performs better than the others when the constraint is strict. However, they have no such advantage in FLOPs/Performances comparison since only number of parameters constraint is considered in the optimization process;
54+
* The basic algorithms `L1Filter Pruner` , `L2Filter Pruner` , `FPGM Pruner` performs very similarly in these experiments;
55+
* `NetAdapt Pruner` can not achieve very high compression rate. This is caused by its mechanism that it prunes only one layer each pruning iteration. This leads to un-acceptable complexity if the sparsity per iteration is much lower than the overall sparisity constraint.
56+
57+
## Experiments Reproduction
58+
59+
### Implementation Details
60+
61+
* The experiment results are all collected with the default configuration of the pruners in nni, which means that when we call a pruner class in nni, we don't change any default class arguments.
62+
63+
* Both FLOPs and the number of parameters are counted with [Model FLOPs/Parameters Counter](https://github.com/microsoft/nni/blob/master/docs/en_US/Compressor/CompressionUtils.md#model-flopsparameters-counter) after [model speed up](https://github.com/microsoft/nni/blob/master/docs/en_US/Compressor/ModelSpeedup.md). This avoids potential issues of counting them of masked models.
64+
65+
* The experiment code can be found [here]( https://github.com/microsoft/nni/tree/master/examples/model_compress/auto_pruners_torch.py).
66+
67+
### Experiment Result Rendering
68+
69+
* If you follow the practice in the [example]( https://github.com/microsoft/nni/tree/master/examples/model_compress/auto_pruners_torch.py), for every single pruning experiment, the experiment result will be saved in JSON format as follows:
70+
``` json
71+
{
72+
"performance": {"original": 0.9298, "pruned": 0.1, "speedup": 0.1, "finetuned": 0.7746},
73+
"params": {"original": 14987722.0, "speedup": 167089.0},
74+
"flops": {"original": 314018314.0, "speedup": 38589922.0}
75+
}
76+
```
77+
78+
* The experiment results are saved [here](https://github.com/microsoft/nni/tree/master/examples/model_compress/experiment_data).
79+
You can refer to [analyze](https://github.com/microsoft/nni/tree/master/examples/model_compress/experiment_data/analyze.py) to plot new performance comparison figures.
80+
81+
## Contribution
82+
83+
### TODO Items
84+
85+
* Pruners constrained by FLOPS/latency
86+
* More pruning algorithms/datasets/models
87+
88+
### Issues
89+
For algorithm implementation & experiment issues, please [create an issue](https://github.com/microsoft/nni/issues/new/).

docs/en_US/CommunitySharings/perf_compare.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ Performance comparison and analysis can help users decide a proper algorithm (e.
88
:maxdepth: 1
99

1010
Neural Architecture Search Comparison <NasComparison>
11-
Hyper-parameter Tuning Algorithm Comparsion <HpoComparison>
11+
Hyper-parameter Tuning Algorithm Comparsion <HpoComparison>
12+
Model Compression Algorithm Comparsion <ModelCompressionComparison>

docs/en_US/Compressor/Overview.md

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Pruning algorithms compress the original network by removing redundant weights o
4242
| [SimulatedAnnealing Pruner](https://nni.readthedocs.io/en/latest/Compressor/Pruner.html#simulatedannealing-pruner) | Automatic pruning with a guided heuristic search method, Simulated Annealing algorithm [Reference Paper](https://arxiv.org/abs/1907.03141) |
4343
| [AutoCompress Pruner](https://nni.readthedocs.io/en/latest/Compressor/Pruner.html#autocompress-pruner) | Automatic pruning by iteratively call SimulatedAnnealing Pruner and ADMM Pruner [Reference Paper](https://arxiv.org/abs/1907.03141) |
4444

45+
You can refer to this [benchmark](https://github.com/microsoft/nni/tree/master/docs/en_US/Benchmark.md) for the performance of these pruners on some benchmark problems.
4546

4647
### Quantization Algorithms
4748

docs/en_US/Compressor/Pruner.md

+68-23
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ We provide several pruning algorithms that support fine-grained weight pruning a
2020
* [NetAdapt Pruner](#netadapt-pruner)
2121
* [SimulatedAnnealing Pruner](#simulatedannealing-pruner)
2222
* [AutoCompress Pruner](#autocompress-pruner)
23+
* [AutoML for Model Compression Pruner](#automl-for-model-compression-pruner)
24+
* [Sensitivity Pruner](#sensitivity-pruner)
2325

2426
**Others**
2527
* [ADMM Pruner](#admm-pruner)
@@ -37,7 +39,7 @@ Tensorflow code
3739
```python
3840
from nni.compression.tensorflow import LevelPruner
3941
config_list = [{ 'sparsity': 0.8, 'op_types': ['default'] }]
40-
pruner = LevelPruner(model_graph, config_list)
42+
pruner = LevelPruner(model, config_list)
4143
pruner.compress()
4244
```
4345

@@ -116,17 +118,6 @@ FPGMPruner prune filters with the smallest geometric median.
116118
117119
### Usage
118120

119-
Tensorflow code
120-
```python
121-
from nni.compression.tensorflow import FPGMPruner
122-
config_list = [{
123-
'sparsity': 0.5,
124-
'op_types': ['Conv2D']
125-
}]
126-
pruner = FPGMPruner(model, config_list)
127-
pruner.compress()
128-
```
129-
130121
PyTorch code
131122
```python
132123
from nni.compression.torch import FPGMPruner
@@ -145,11 +136,6 @@ pruner.compress()
145136
.. autoclass:: nni.compression.torch.FPGMPruner
146137
```
147138

148-
##### Tensorflow
149-
```eval_rst
150-
.. autoclass:: nni.compression.tensorflow.FPGMPruner
151-
```
152-
153139
## L1Filter Pruner
154140

155141
This is an one-shot pruner, In ['PRUNING FILTERS FOR EFFICIENT CONVNETS'](https://arxiv.org/abs/1608.08710), authors Hao Li, Asim Kadav, Igor Durdanovic, Hanan Samet and Hans Peter Graf.
@@ -382,12 +368,6 @@ You can view [example](https://github.com/microsoft/nni/blob/master/examples/mod
382368
.. autoclass:: nni.compression.torch.AGPPruner
383369
```
384370

385-
##### Tensorflow
386-
387-
```eval_rst
388-
.. autoclass:: nni.compression.tensorflow.AGPPruner
389-
```
390-
391371
***
392372

393373
## NetAdapt Pruner
@@ -497,6 +477,39 @@ You can view [example](https://github.com/microsoft/nni/blob/master/examples/mod
497477
.. autoclass:: nni.compression.torch.AutoCompressPruner
498478
```
499479

480+
## AutoML for Model Compression Pruner
481+
482+
AutoML for Model Compression Pruner (AMCPruner) leverages reinforcement learning to provide the model compression policy.
483+
This learning-based compression policy outperforms conventional rule-based compression policy by having higher compression ratio,
484+
better preserving the accuracy and freeing human labor.
485+
486+
![](../../img/amc_pruner.jpg)
487+
488+
For more details, please refer to [AMC: AutoML for Model Compression and Acceleration on Mobile Devices](https://arxiv.org/pdf/1802.03494.pdf).
489+
490+
491+
#### Usage
492+
493+
PyTorch code
494+
495+
```python
496+
from nni.compression.torch import AMCPruner
497+
config_list = [{
498+
'op_types': ['Conv2d', 'Linear']
499+
}]
500+
pruner = AMCPruner(model, config_list, evaluator, val_loader, flops_ratio=0.5)
501+
pruner.compress()
502+
```
503+
504+
You can view [example](https://github.com/microsoft/nni/blob/master/examples/model_compress/amc/) for more information.
505+
506+
#### User configuration for AutoCompress Pruner
507+
508+
##### PyTorch
509+
510+
```eval_rst
511+
.. autoclass:: nni.compression.torch.AMCPruner
512+
```
500513

501514
## ADMM Pruner
502515
Alternating Direction Method of Multipliers (ADMM) is a mathematical optimization technique,
@@ -588,3 +601,35 @@ We try to reproduce the experiment result of the fully connected network on MNIS
588601
![](../../img/lottery_ticket_mnist_fc.png)
589602

590603
The above figure shows the result of the fully connected network. `round0-sparsity-0.0` is the performance without pruning. Consistent with the paper, pruning around 80% also obtain similar performance compared to non-pruning, and converges a little faster. If pruning too much, e.g., larger than 94%, the accuracy becomes lower and convergence becomes a little slower. A little different from the paper, the trend of the data in the paper is relatively more clear.
604+
605+
606+
## Sensitivity Pruner
607+
For each round, SensitivityPruner prunes the model based on the sensitivity to the accuracy of each layer until meeting the final configured sparsity of the whole model:
608+
1. Analyze the sensitivity of each layer in the current state of the model.
609+
2. Prune each layer according to the sensitivity.
610+
611+
For more details, please refer to [Learning both Weights and Connections for Efficient Neural Networks ](https://arxiv.org/abs/1506.02626).
612+
613+
#### Usage
614+
615+
PyTorch code
616+
617+
```python
618+
from nni.compression.torch import SensitivityPruner
619+
config_list = [{
620+
'sparsity': 0.5,
621+
'op_types': ['Conv2d']
622+
}]
623+
pruner = SensitivityPruner(model, config_list, finetuner=fine_tuner, evaluator=evaluator)
624+
# eval_args and finetune_args are the parameters passed to the evaluator and finetuner respectively
625+
pruner.compress(eval_args=[model], finetune_args=[model])
626+
```
627+
628+
629+
#### User configuration for Sensitivity Pruner
630+
631+
##### PyTorch
632+
633+
```eval_rst
634+
.. autoclass:: nni.compression.torch.SensitivityPruner
635+
```

docs/en_US/TrainingService/AMLMode.md

+11-7
Original file line numberDiff line numberDiff line change
@@ -49,30 +49,34 @@ tuner:
4949
trial:
5050
command: python3 mnist.py
5151
codeDir: .
52-
computeTarget: ${replace_to_your_computeTarget}
5352
image: msranni/nni
53+
gpuNum: 1
5454
amlConfig:
5555
subscriptionId: ${replace_to_your_subscriptionId}
5656
resourceGroup: ${replace_to_your_resourceGroup}
5757
workspaceName: ${replace_to_your_workspaceName}
58-
58+
computeTarget: ${replace_to_your_computeTarget}
5959
```
6060
6161
Note: You should set `trainingServicePlatform: aml` in NNI config YAML file if you want to start experiment in aml mode.
6262

6363
Compared with [LocalMode](LocalMode.md) trial configuration in aml mode have these additional keys:
64-
* computeTarget
65-
* required key. The compute cluster name you want to use in your AML workspace. See Step 6.
6664
* image
6765
* required key. The docker image name used in job. The image `msranni/nni` of this example only support GPU computeTargets.
6866

6967
amlConfig:
7068
* subscriptionId
71-
* the subscriptionId of your account
69+
* required key, the subscriptionId of your account
7270
* resourceGroup
73-
* the resourceGroup of your account
71+
* required key, the resourceGroup of your account
7472
* workspaceName
75-
* the workspaceName of your account
73+
* required key, the workspaceName of your account
74+
* computeTarget
75+
* required key, the compute cluster name you want to use in your AML workspace. See Step 6.
76+
* maxTrialNumPerGpu
77+
* optional key, used to specify the max concurrency trial number on a GPU device.
78+
* useActiveGpu
79+
* optional key, used to specify whether to use a GPU if there is another process. By default, NNI will use the GPU only if there is no other active process in the GPU.
7680

7781
The required information of amlConfig could be found in the downloaded `config.json` in Step 5.
7882

0 commit comments

Comments
 (0)