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

Change Doc #1510

Merged
merged 40 commits into from
Sep 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
a3ea2cb
fix negative time number in local mode when trial time is short
LeonardoWang Jun 20, 2019
01c60bd
fix bug of duration<0
Jun 21, 2019
ace5132
fix windows version and readme
LeonardoWang Jun 21, 2019
48d3e4d
change tab
LeonardoWang Jun 21, 2019
61dbdca
change line
Jun 21, 2019
38e683a
Merge branch 'fix-bug-ui' of github.com:LeonardoWang/nni
Jun 21, 2019
f2e6d16
add compressor
LeonardoWang Aug 1, 2019
c6e6b75
add __init__
LeonardoWang Aug 1, 2019
d9897c2
Merge branch 'master' of github.com:microsoft/nni
Aug 2, 2019
2979de3
compressor
Aug 2, 2019
365585f
new framework
Aug 13, 2019
1f92408
change import
LeonardoWang Aug 13, 2019
f925075
change import error
Aug 13, 2019
a1e36c3
Merge branch 'master' of https://github.com/microsoft/nni
Aug 14, 2019
7672887
add doc and change files
Aug 14, 2019
17a20fc
add test function in pynni/test
Aug 15, 2019
9ab12f3
fix bug F
Aug 15, 2019
491ef33
test
Aug 15, 2019
02877ed
add requirment
Aug 15, 2019
fe46e9f
change setup
Aug 15, 2019
2b5114b
change dependencies to zaure-piplines.yml
Aug 15, 2019
a68d911
change
Aug 15, 2019
555cbb8
add mac
Aug 15, 2019
6badf9e
add macos
Aug 15, 2019
6f3f1ff
change compressor with __call__(), add frame method
Aug 19, 2019
41751de
add configure without doc
Aug 20, 2019
baffb8d
update doc and test unit
Aug 21, 2019
2213dfa
add configure parser change doc and test
Aug 23, 2019
0538d30
test commit
Aug 23, 2019
3b02ef6
move example
Aug 26, 2019
3a94357
add user hint
Aug 26, 2019
8eff37e
add doc and change example name
Aug 27, 2019
b8c674d
change for PR
Aug 27, 2019
1cbab82
This is a combination of 9 commits
Aug 19, 2019
3c12db8
Merge branch 'master' of github.com:LeonardoWang/nni
LeonardoWang Aug 30, 2019
3c7d6bf
change doc and bind_model()
LeonardoWang Aug 30, 2019
f96d110
Merge branch 'dev-mc' of https://github.com/microsoft/nni
LeonardoWang Aug 30, 2019
2e7de79
change prepeocess_model() to bind_model()
LeonardoWang Aug 30, 2019
3cb6800
Merge branch 'dev-mc' of https://github.com/microsoft/nni
LeonardoWang Sep 2, 2019
420294b
move function
LeonardoWang Sep 5, 2019
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
13 changes: 11 additions & 2 deletions docs/en_US/Compressor/Overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ class YourPruner(nni.compressors.tf_compressor.TfPruner):
def update_epoch(self, epoch_num, sess):
pass

def step(self):
# note for pytorch version, there is no sess in input arguments
def step(self, sess):
# can do some processing based on the model or weights binded
# in the func bind_model
pass
Expand Down Expand Up @@ -159,10 +160,18 @@ class YourPruner(nni.compressors.tf_compressor.TfQuantizer):
def update_epoch(self, epoch_num, sess):
pass

def step(self):
# note for pytorch version, there is no sess in input arguments
def step(self, sess):
# can do some processing based on the model or weights binded
# in the func bind_model
pass

# you can also design your method
def your_method(self, your_input):
#your code

def bind_model(self, model):
#preprocess model
```

__[TODO]__ Will add another member function `quantize_layer_output`, as some quantization algorithms also quantize layers' output.
Expand Down
49 changes: 41 additions & 8 deletions docs/en_US/Compressor/Pruner.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,21 @@ We first sort the weights in the specified layer by their absolute values. And t

Tensorflow code
```
pruner = nni.compressors.tf_compressor.LevelPruner([{'sparsity':0.8,'support_type': 'default'}])
configure_list = [{'sparsity':0.8,'support_type': 'default'}]
pruner = nni.compressors.tf_compressor.LevelPruner(configure_list)
pruner(model_graph)
```

Pytorch code
```
pruner = nni.compressors.torch_compressor.LevelPruner([{'sparsity':0.8,'support_type': 'default'}])
configure_list = [{'sparsity':0.8,'support_type': 'default'}]
pruner = nni.compressors.torch_compressor.LevelPruner(configure_list)
pruner(model)
```

#### User configuration for LevelPruner
* **sparsity:** This is to specify the sparsity operations to be compressed to

***
<a name="AGPruner"></a>

Expand All @@ -41,13 +46,29 @@ First, you should import pruner and add mask to model.
Tensorflow code
```
from nni.compressors.tfCompressor import AGPruner
pruner = AGPruner(initial_sparsity=0, final_sparsity=0.8, start_epoch=1, end_epoch=10, frequency=1)
configure_list = [{
'initial_sparsity': 0,
'final_sparsity': 0.8,
'start_epoch': 1,
'end_epoch': 10,
'frequency': 1,
'support_type': 'default'
}]
pruner = AGPruner(configure_list)
pruner(tf.get_default_graph())
```
Pytorch code
```
from nni.compressors.torchCompressor import AGPruner
pruner = AGPruner(initial_sparsity=0, final_sparsity=0.8, start_epoch=1, end_epoch=10, frequency=1)
configure_list = [{
'initial_sparsity': 0,
'final_sparsity': 0.8,
'start_epoch': 1,
'end_epoch': 10,
'frequency': 1,
'support_type': 'default'
}]
pruner = AGPruner(configure_list)
pruner(model)
```

Expand All @@ -62,6 +83,14 @@ Pytorch code
pruner.update_epoch(epoch)
```
You can view example for more information

#### User configuration for AGPruner
* **initial_sparsity:** This is to specify the sparsity when compressor starts to compress
* **final_sparsity:** This is to specify the sparsity when compressor finishes to compress
* **start_epoch:** This is to specify the epoch number when compressor starts to compress
* **end_epoch:** This is to specify the epoch number when compressor finishes to compress
* **frequency:** This is to specify every *frequency* number epochs compressor compress once

***
<a name="SensitivityPruner"></a>

Expand All @@ -76,15 +105,15 @@ You can prune weight step by step and reach one target sparsity by SensitivityPr
Tensorflow code
```
from nni.compressors.tfCompressor import SensitivityPruner

pruner = SensitivityPruner(sparsity = 0.8)
configure_list = [{'sparsity':0.8,'support_type': 'default'}]
pruner = SensitivityPruner(configure_list)
pruner(tf.get_default_graph())
```
Pytorch code
```
from nni.compressors.torchCompressor import SensitivityPruner

pruner = SensitivityPruner(sparsity = 0.8)
configure_list = [{'sparsity':0.8,'support_type': 'default'}]
pruner = SensitivityPruner(configure_list)
pruner(model)
```
Like AGPruner, you should update mask information every epoch by adding code below
Expand All @@ -98,4 +127,8 @@ Pytorch code
pruner.update_epoch(epoch)
```
You can view example for more information

#### User configuration for SensitivityPruner
* **sparsity:** This is to specify the sparsity operations to be compressed to

***
22 changes: 17 additions & 5 deletions docs/en_US/Compressor/Quantizer.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Quantizer on NNI Compressor

## NaiveQuantizer

We provide NaiveQuantizer to quantizer weight to default 8 bits, you can use it to test quantize algorithm.
We provide NaiveQuantizer to quantizer weight to default 8 bits, you can use it to test quantize algorithm without any configure.

### Usage
tensorflow
Expand All @@ -16,6 +16,7 @@ pytorch
```
nni.compressors.torch_compressor.NaiveQuantizer()(model)
```

***
<a name="QATquantizer"></a>

Expand All @@ -34,18 +35,24 @@ You can quantize your model to 8 bits with the code below before your training c
Tensorflow code
```
from nni.compressors.tfCompressor import QATquantizer
quantizer = QATquantizer(q_bits = 8)
configure_list = [{'q_bits':8, 'support_type':'default'}]
quantizer = QATquantizer(configure_list)
quantizer(tf.get_default_graph())
```
Pytorch code
```
from nni.compressors.torchCompressor import QATquantizer
quantizer = QATquantizer(q_bits = 8)
configure_list = [{'q_bits':8, 'support_type':'default'}]
quantizer = QATquantizer(configure_list)
quantizer(model)
```

You can view example for more information

#### User configuration for QATquantizer
* **q_bits:** This is to specify the q_bits operations to be quantized to


***
<a name="DoReFaQuantizer"></a>

Expand All @@ -58,14 +65,19 @@ To implement DoReFaQuantizer, you can add code below before your training code
Tensorflow code
```
from nni.compressors.tfCompressor import DoReFaQuantizer
quantizer = DoReFaQuantizer(q_bits = 8)
configure_list = [{'q_bits':8, 'support_type':'default'}]
quantizer = DoReFaQuantizer(configure_list)
quantizer(tf.get_default_graph())
```
Pytorch code
```
from nni.compressors.torchCompressor import DoReFaQuantizer
quantizer = DoReFaQuantizer(q_bits = 8)
configure_list = [{'q_bits':8, 'support_type':'default'}]
quantizer = DoReFaQuantizer(configure_list)
quantizer(model)
```

You can view example for more information

#### User configuration for QATquantizer
* **q_bits:** This is to specify the q_bits operations to be quantized to
4 changes: 2 additions & 2 deletions src/sdk/pynni/nni/compressors/tf_compressor/_nnimc_tf.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def compress(self, model):
"""
assert self._bound_model is None, "Each NNI compressor instance can only compress one model"
self._bound_model = model
self.preprocess_model(model)
self.bind_model(model)

def compress_default_graph(self):
"""
Expand All @@ -42,7 +42,7 @@ def compress_default_graph(self):
self.compress(tf.get_default_graph())


def preprocess_model(self, model):
def bind_model(self, model):
"""
This method is called when a model is bound to the compressor.
Users can optionally overload this method to do model-specific initialization.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ def compress(self, model):
"""
assert self._bound_model is None, "Each NNI compressor instance can only compress one model"
self._bound_model = model
self.preprocess_model(model)
self.bind_model(model)


def preprocess_model(self, model):
def bind_model(self, model):
"""
This method is called when a model is bound to the compressor.
Users can optionally overload this method to do model-specific initialization.
Expand Down