Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenDAS
nni
Commits
e779d7f3
Unverified
Commit
e779d7f3
authored
Oct 28, 2021
by
lin bin
Committed by
GitHub
Oct 28, 2021
Browse files
[quantization] Fix quantize config setting in speedup example (#4276)
parent
78ea3767
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
20 deletions
+21
-20
examples/model_compress/quantization/mixed_precision_speedup_mnist.py
...el_compress/quantization/mixed_precision_speedup_mnist.py
+4
-4
test/nni_test/nnitest/test_quantize_model_speedup.py
test/nni_test/nnitest/test_quantize_model_speedup.py
+17
-16
No files found.
examples/model_compress/quantization/mixed_precision_speedup_mnist.py
View file @
e779d7f3
...
@@ -83,16 +83,16 @@ def quantization_aware_training_example(train_loader, test_loader, device):
...
@@ -83,16 +83,16 @@ def quantization_aware_training_example(train_loader, test_loader, device):
model
=
NaiveModel
()
model
=
NaiveModel
()
configure_list
=
[{
configure_list
=
[{
'quant_types'
:
[
'
weight'
,
'outpu
t'
],
'quant_types'
:
[
'
input'
,
'weigh
t'
],
'quant_bits'
:
{
'
weigh
t'
:
8
,
'
outpu
t'
:
8
},
'quant_bits'
:
{
'
inpu
t'
:
8
,
'
weigh
t'
:
8
},
'op_names'
:
[
'conv1'
]
'op_names'
:
[
'conv1'
]
},
{
},
{
'quant_types'
:
[
'output'
],
'quant_types'
:
[
'output'
],
'quant_bits'
:
{
'output'
:
8
},
'quant_bits'
:
{
'output'
:
8
},
'op_names'
:
[
'relu1'
]
'op_names'
:
[
'relu1'
]
},
{
},
{
'quant_types'
:
[
'
weight'
,
'outpu
t'
],
'quant_types'
:
[
'
input'
,
'weigh
t'
],
'quant_bits'
:
{
'
weigh
t'
:
8
,
'
outpu
t'
:
8
},
'quant_bits'
:
{
'
inpu
t'
:
8
,
'
weigh
t'
:
8
},
'op_names'
:
[
'conv2'
]
'op_names'
:
[
'conv2'
]
},
{
},
{
'quant_types'
:
[
'output'
],
'quant_types'
:
[
'output'
],
...
...
test/nni_test/nnitest/test_quantize_model_speedup.py
View file @
e779d7f3
...
@@ -97,10 +97,10 @@ class QuantizationSpeedupTestCase(TestCase):
...
@@ -97,10 +97,10 @@ class QuantizationSpeedupTestCase(TestCase):
model
=
BackboneModel
()
model
=
BackboneModel
()
configure_list
=
{
configure_list
=
{
'conv1'
:{
'weight_bit'
:
8
,
'
activation
_bit'
:
8
},
'conv1'
:{
'weight_bit
s
'
:
8
,
'
output
_bit
s
'
:
8
},
'conv2'
:{
'weight_bit'
:
32
,
'
activation
_bit'
:
32
},
'conv2'
:{
'weight_bit
s
'
:
32
,
'
output
_bit
s
'
:
32
},
'fc1'
:{
'weight_bit'
:
16
,
'
activation
_bit'
:
16
},
'fc1'
:{
'weight_bit
s
'
:
16
,
'
output
_bit
s
'
:
16
},
'fc2'
:{
'weight_bit'
:
8
,
'
activation
_bit'
:
8
}
'fc2'
:{
'weight_bit
s
'
:
8
,
'
output
_bit
s
'
:
8
}
}
}
optimizer
=
torch
.
optim
.
SGD
(
model
.
parameters
(),
lr
=
0.01
,
momentum
=
0.5
)
optimizer
=
torch
.
optim
.
SGD
(
model
.
parameters
(),
lr
=
0.01
,
momentum
=
0.5
)
...
@@ -126,16 +126,16 @@ class QuantizationSpeedupTestCase(TestCase):
...
@@ -126,16 +126,16 @@ class QuantizationSpeedupTestCase(TestCase):
model
=
BackboneModel
()
model
=
BackboneModel
()
configure_list
=
[{
configure_list
=
[{
'quant_types'
:
[
'
weight'
,
'outpu
t'
],
'quant_types'
:
[
'
input'
,
'weigh
t'
],
'quant_bits'
:
{
'
weigh
t'
:
8
,
'
outpu
t'
:
8
},
'quant_bits'
:
{
'
inpu
t'
:
8
,
'
weigh
t'
:
8
},
'op_names'
:
[
'conv1'
]
'op_names'
:
[
'conv1'
]
},
{
},
{
'quant_types'
:
[
'output'
],
'quant_types'
:
[
'output'
],
'quant_bits'
:
{
'output'
:
8
},
'quant_bits'
:
{
'output'
:
8
},
'op_names'
:
[
'relu1'
]
'op_names'
:
[
'relu1'
]
},
{
},
{
'quant_types'
:
[
'
weight'
,
'outpu
t'
],
'quant_types'
:
[
'
input'
,
'weigh
t'
],
'quant_bits'
:
{
'
weigh
t'
:
8
,
'
outpu
t'
:
8
},
'quant_bits'
:
{
'
inpu
t'
:
8
,
'
weigh
t'
:
8
},
'op_names'
:
[
'conv2'
]
'op_names'
:
[
'conv2'
]
},
{
},
{
'quant_types'
:
[
'output'
],
'quant_types'
:
[
'output'
],
...
@@ -145,8 +145,9 @@ class QuantizationSpeedupTestCase(TestCase):
...
@@ -145,8 +145,9 @@ class QuantizationSpeedupTestCase(TestCase):
]
]
# finetune the model by using QAT
# finetune the model by using QAT
dummy_input
=
torch
.
randn
(
1
,
1
,
28
,
28
)
optimizer
=
torch
.
optim
.
SGD
(
model
.
parameters
(),
lr
=
0.01
,
momentum
=
0.5
)
optimizer
=
torch
.
optim
.
SGD
(
model
.
parameters
(),
lr
=
0.01
,
momentum
=
0.5
)
quantizer
=
QAT_Quantizer
(
model
,
configure_list
,
optimizer
)
quantizer
=
QAT_Quantizer
(
model
,
configure_list
,
optimizer
,
dummy_input
)
quantizer
.
compress
()
quantizer
.
compress
()
model
.
to
(
self
.
device
)
model
.
to
(
self
.
device
)
...
@@ -178,13 +179,13 @@ class QuantizationSpeedupTestCase(TestCase):
...
@@ -178,13 +179,13 @@ class QuantizationSpeedupTestCase(TestCase):
model
=
vgg16
()
model
=
vgg16
()
configure_list
=
{
configure_list
=
{
'features.0'
:{
'weight_bit'
:
8
,
'
activation
_bit'
:
8
},
'features.0'
:{
'weight_bit
s
'
:
8
,
'
output
_bit
s
'
:
8
},
'features.1'
:{
'weight_bit'
:
32
,
'
activation
_bit'
:
32
},
'features.1'
:{
'weight_bit
s
'
:
32
,
'
output
_bit
s
'
:
32
},
'features.2'
:{
'weight_bit'
:
16
,
'
activation
_bit'
:
16
},
'features.2'
:{
'weight_bit
s
'
:
16
,
'
output
_bit
s
'
:
16
},
'features.4'
:{
'weight_bit'
:
8
,
'
activation
_bit'
:
8
},
'features.4'
:{
'weight_bit
s
'
:
8
,
'
output
_bit
s
'
:
8
},
'features.7'
:{
'weight_bit'
:
8
,
'
activation
_bit'
:
8
},
'features.7'
:{
'weight_bit
s
'
:
8
,
'
output
_bit
s
'
:
8
},
'features.8'
:{
'weight_bit'
:
8
,
'
activation
_bit'
:
8
},
'features.8'
:{
'weight_bit
s
'
:
8
,
'
output
_bit
s
'
:
8
},
'features.11'
:{
'weight_bit'
:
8
,
'
activation
_bit'
:
8
}
'features.11'
:{
'weight_bit
s
'
:
8
,
'
output
_bit
s
'
:
8
}
}
}
model
.
to
(
self
.
device
)
model
.
to
(
self
.
device
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment