Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
993cbbcd
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
993cbbcd
编写于
9月 13, 2018
作者:
D
Dang Qingqing
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move quantization transpiler to fluid/contrib/quantize path.
上级
8a850e21
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
50 addition
and
17 deletion
+50
-17
python/CMakeLists.txt
python/CMakeLists.txt
+1
-0
python/paddle/fluid/__init__.py
python/paddle/fluid/__init__.py
+1
-1
python/paddle/fluid/contrib/__init__.py
python/paddle/fluid/contrib/__init__.py
+2
-0
python/paddle/fluid/contrib/quantize/__init__.py
python/paddle/fluid/contrib/quantize/__init__.py
+19
-0
python/paddle/fluid/contrib/quantize/quantize_transpiler.py
python/paddle/fluid/contrib/quantize/quantize_transpiler.py
+6
-4
python/paddle/fluid/contrib/tests/CMakeLists.txt
python/paddle/fluid/contrib/tests/CMakeLists.txt
+0
-0
python/paddle/fluid/contrib/tests/test_quantize_transpiler.py
...on/paddle/fluid/contrib/tests/test_quantize_transpiler.py
+14
-7
python/paddle/fluid/tests/CMakeLists.txt
python/paddle/fluid/tests/CMakeLists.txt
+0
-1
python/paddle/fluid/transpiler/__init__.py
python/paddle/fluid/transpiler/__init__.py
+7
-4
未找到文件。
python/CMakeLists.txt
浏览文件 @
993cbbcd
...
@@ -87,6 +87,7 @@ if (WITH_TESTING)
...
@@ -87,6 +87,7 @@ if (WITH_TESTING)
endif
()
endif
()
endif
()
endif
()
add_subdirectory
(
paddle/fluid/tests
)
add_subdirectory
(
paddle/fluid/tests
)
add_subdirectory
(
paddle/fluid/contrib/tests
)
endif
()
endif
()
install
(
DIRECTORY
${
PADDLE_PYTHON_PACKAGE_DIR
}
install
(
DIRECTORY
${
PADDLE_PYTHON_PACKAGE_DIR
}
DESTINATION opt/paddle/share/wheels
DESTINATION opt/paddle/share/wheels
...
...
python/paddle/fluid/__init__.py
浏览文件 @
993cbbcd
...
@@ -47,7 +47,7 @@ from .param_attr import ParamAttr, WeightNormParamAttr
...
@@ -47,7 +47,7 @@ from .param_attr import ParamAttr, WeightNormParamAttr
from
.data_feeder
import
DataFeeder
from
.data_feeder
import
DataFeeder
from
.core
import
LoDTensor
,
LoDTensorArray
,
CPUPlace
,
CUDAPlace
,
CUDAPinnedPlace
,
Scope
from
.core
import
LoDTensor
,
LoDTensorArray
,
CPUPlace
,
CUDAPlace
,
CUDAPinnedPlace
,
Scope
from
.transpiler
import
DistributeTranspiler
,
InferenceTranspiler
,
\
from
.transpiler
import
DistributeTranspiler
,
InferenceTranspiler
,
\
memory_optimize
,
release_memory
,
DistributeTranspilerConfig
,
QuantizeTranspiler
memory_optimize
,
release_memory
,
DistributeTranspilerConfig
from
.lod_tensor
import
create_lod_tensor
,
create_random_int_lodtensor
from
.lod_tensor
import
create_lod_tensor
,
create_random_int_lodtensor
from
.
import
clip
from
.
import
clip
from
.
import
profiler
from
.
import
profiler
...
...
python/paddle/fluid/contrib/__init__.py
浏览文件 @
993cbbcd
...
@@ -18,5 +18,7 @@ from . import decoder
...
@@ -18,5 +18,7 @@ from . import decoder
from
.decoder
import
*
from
.decoder
import
*
from
.
import
memory_usage_calc
from
.
import
memory_usage_calc
from
.memory_usage_calc
import
*
from
.memory_usage_calc
import
*
from
.
import
quantize
__all__
=
decoder
.
__all__
+
memory_usage_calc
.
__all__
__all__
=
decoder
.
__all__
+
memory_usage_calc
.
__all__
__all__
+=
quantize
.
__all__
python/paddle/fluid/contrib/quantize/__init__.py
0 → 100644
浏览文件 @
993cbbcd
# Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserve.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from
__future__
import
print_function
from
.
import
quantize_transpiler
__all__
=
quantize_transpiler
.
__all__
python/paddle/fluid/
transpiler
/quantize_transpiler.py
→
python/paddle/fluid/
contrib/quantize
/quantize_transpiler.py
浏览文件 @
993cbbcd
...
@@ -18,14 +18,16 @@ import numpy as np
...
@@ -18,14 +18,16 @@ import numpy as np
from
paddle.fluid.framework
import
default_main_program
,
default_startup_program
,
program_guard
from
paddle.fluid.framework
import
default_main_program
,
default_startup_program
,
program_guard
from
paddle.fluid.layer_helper
import
LayerHelper
from
paddle.fluid.layer_helper
import
LayerHelper
from
paddle.fluid
import
unique_name
from
paddle.fluid
import
unique_name
from
paddle.fluid
import
core
from
paddle.fluid.initializer
import
Constant
from
paddle.fluid.initializer
import
Constant
from
paddle.fluid.param_attr
import
ParamAttr
from
paddle.fluid.param_attr
import
ParamAttr
from
paddle.fluid.layer_helper
import
LayerHelper
from
paddle.fluid.layer_helper
import
LayerHelper
from
paddle.fluid.layers.nn
import
autoincreased_step_counter
from
paddle.fluid.layers.nn
import
autoincreased_step_counter
from
..
import
core
from
paddle.fluid.framework
import
Variable
from
..framework
import
Variable
from
paddle.fluid.executor
import
global_scope
from
..executor
import
global_scope
from
paddle.fluid.transpiler.inference_transpiler
import
InferenceTranspiler
from
inference_transpiler
import
InferenceTranspiler
__all__
=
[
'QuantizeTranspiler'
]
_QUANTIZABLE_OP_TYPES
=
[
'conv2d'
,
'depthwise_conv2d'
,
'mul'
]
_QUANTIZABLE_OP_TYPES
=
[
'conv2d'
,
'depthwise_conv2d'
,
'mul'
]
...
...
python/paddle/fluid/
tests/transpiler
/CMakeLists.txt
→
python/paddle/fluid/
contrib/tests
/CMakeLists.txt
浏览文件 @
993cbbcd
文件已移动
python/paddle/fluid/
tests/transpiler
/test_quantize_transpiler.py
→
python/paddle/fluid/
contrib/tests
/test_quantize_transpiler.py
浏览文件 @
993cbbcd
...
@@ -13,17 +13,20 @@
...
@@ -13,17 +13,20 @@
# limitations under the license.
# limitations under the license.
import
numpy
as
np
import
numpy
as
np
import
six
import
unittest
import
unittest
import
paddle
import
paddle
import
paddle.fluid
as
fluid
import
paddle.fluid
as
fluid
from
paddle.fluid.transpiler.quantize_transpiler
import
_original_var_name
from
paddle.fluid.contrib.quantize.quantize_transpiler
import
_original_var_name
from
paddle.fluid.contrib.quantize.quantize_transpiler
import
QuantizeTranspiler
def
linear_fc
(
num
):
def
linear_fc
(
num
):
data
=
fluid
.
layers
.
data
(
name
=
'image'
,
shape
=
[
1
,
32
,
32
],
dtype
=
'float32'
)
data
=
fluid
.
layers
.
data
(
name
=
'image'
,
shape
=
[
1
,
32
,
32
],
dtype
=
'float32'
)
label
=
fluid
.
layers
.
data
(
name
=
'label'
,
shape
=
[
1
],
dtype
=
'int64'
)
label
=
fluid
.
layers
.
data
(
name
=
'label'
,
shape
=
[
1
],
dtype
=
'int64'
)
hidden
=
data
hidden
=
data
for
_
in
xrange
(
num
):
for
_
in
six
.
moves
.
xrange
(
num
):
hidden
=
fluid
.
layers
.
fc
(
hidden
,
size
=
128
,
act
=
'relu'
)
hidden
=
fluid
.
layers
.
fc
(
hidden
,
size
=
128
,
act
=
'relu'
)
loss
=
fluid
.
layers
.
cross_entropy
(
input
=
hidden
,
label
=
label
)
loss
=
fluid
.
layers
.
cross_entropy
(
input
=
hidden
,
label
=
label
)
loss
=
fluid
.
layers
.
mean
(
loss
)
loss
=
fluid
.
layers
.
mean
(
loss
)
...
@@ -51,7 +54,7 @@ def residual_block(num):
...
@@ -51,7 +54,7 @@ def residual_block(num):
data
=
fluid
.
layers
.
data
(
name
=
'image'
,
shape
=
[
1
,
32
,
32
],
dtype
=
'float32'
)
data
=
fluid
.
layers
.
data
(
name
=
'image'
,
shape
=
[
1
,
32
,
32
],
dtype
=
'float32'
)
label
=
fluid
.
layers
.
data
(
name
=
'label'
,
shape
=
[
1
],
dtype
=
'int64'
)
label
=
fluid
.
layers
.
data
(
name
=
'label'
,
shape
=
[
1
],
dtype
=
'int64'
)
hidden
=
data
hidden
=
data
for
_
in
xrange
(
num
):
for
_
in
six
.
moves
.
xrange
(
num
):
conv
=
conv_bn_layer
(
hidden
,
16
,
3
,
1
,
1
,
act
=
None
,
bias_attr
=
True
)
conv
=
conv_bn_layer
(
hidden
,
16
,
3
,
1
,
1
,
act
=
None
,
bias_attr
=
True
)
short
=
conv_bn_layer
(
hidden
,
16
,
1
,
1
,
0
,
act
=
None
)
short
=
conv_bn_layer
(
hidden
,
16
,
1
,
1
,
0
,
act
=
None
)
hidden
=
fluid
.
layers
.
elementwise_add
(
x
=
conv
,
y
=
short
,
act
=
'relu'
)
hidden
=
fluid
.
layers
.
elementwise_add
(
x
=
conv
,
y
=
short
,
act
=
'relu'
)
...
@@ -142,7 +145,7 @@ class TestQuantizeTranspiler(unittest.TestCase):
...
@@ -142,7 +145,7 @@ class TestQuantizeTranspiler(unittest.TestCase):
loss
=
linear_fc
(
3
)
loss
=
linear_fc
(
3
)
opt
=
fluid
.
optimizer
.
Adam
(
learning_rate
=
0.001
)
opt
=
fluid
.
optimizer
.
Adam
(
learning_rate
=
0.001
)
opt
.
minimize
(
loss
)
opt
.
minimize
(
loss
)
t
=
fluid
.
QuantizeTranspiler
(
activation_quantize_type
=
quant_type
)
t
=
QuantizeTranspiler
(
activation_quantize_type
=
quant_type
)
t
.
training_transpile
(
main
)
t
.
training_transpile
(
main
)
self
.
check_program
(
main
)
self
.
check_program
(
main
)
...
@@ -161,7 +164,7 @@ class TestQuantizeTranspiler(unittest.TestCase):
...
@@ -161,7 +164,7 @@ class TestQuantizeTranspiler(unittest.TestCase):
loss
=
residual_block
(
2
)
loss
=
residual_block
(
2
)
opt
=
fluid
.
optimizer
.
Adam
(
learning_rate
=
0.001
)
opt
=
fluid
.
optimizer
.
Adam
(
learning_rate
=
0.001
)
opt
.
minimize
(
loss
)
opt
.
minimize
(
loss
)
t
=
fluid
.
QuantizeTranspiler
(
activation_quantize_type
=
quant_type
)
t
=
QuantizeTranspiler
(
activation_quantize_type
=
quant_type
)
t
.
training_transpile
(
main
)
t
.
training_transpile
(
main
)
self
.
check_program
(
main
)
self
.
check_program
(
main
)
...
@@ -176,7 +179,7 @@ class TestQuantizeTranspiler(unittest.TestCase):
...
@@ -176,7 +179,7 @@ class TestQuantizeTranspiler(unittest.TestCase):
def
freeze_program
(
self
,
use_cuda
):
def
freeze_program
(
self
,
use_cuda
):
main
=
fluid
.
Program
()
main
=
fluid
.
Program
()
startup
=
fluid
.
Program
()
startup
=
fluid
.
Program
()
quant_transpiler
=
fluid
.
QuantizeTranspiler
()
quant_transpiler
=
QuantizeTranspiler
()
with
fluid
.
program_guard
(
main
,
startup
):
with
fluid
.
program_guard
(
main
,
startup
):
img
=
fluid
.
layers
.
data
(
img
=
fluid
.
layers
.
data
(
name
=
'image'
,
shape
=
[
1
,
28
,
28
],
dtype
=
'float32'
)
name
=
'image'
,
shape
=
[
1
,
28
,
28
],
dtype
=
'float32'
)
...
@@ -247,7 +250,11 @@ class TestQuantizeTranspiler(unittest.TestCase):
...
@@ -247,7 +250,11 @@ class TestQuantizeTranspiler(unittest.TestCase):
self
.
assertEqual
(
np
.
sum
(
w_8bit
),
np
.
sum
(
w_freeze
))
self
.
assertEqual
(
np
.
sum
(
w_8bit
),
np
.
sum
(
w_freeze
))
def
test_freeze_program_cuda
(
self
):
def
test_freeze_program_cuda
(
self
):
self
.
freeze_program
(
True
)
if
fluid
.
core
.
is_compiled_with_cuda
():
self
.
freeze_program
(
True
)
def
test_freeze_program_cpu
(
self
):
self
.
freeze_program
(
False
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
python/paddle/fluid/tests/CMakeLists.txt
浏览文件 @
993cbbcd
...
@@ -8,4 +8,3 @@ endforeach()
...
@@ -8,4 +8,3 @@ endforeach()
add_subdirectory
(
unittests
)
add_subdirectory
(
unittests
)
add_subdirectory
(
book
)
add_subdirectory
(
book
)
add_subdirectory
(
book_memory_optimization
)
add_subdirectory
(
book_memory_optimization
)
add_subdirectory
(
transpiler
)
python/paddle/fluid/transpiler/__init__.py
浏览文件 @
993cbbcd
...
@@ -16,12 +16,15 @@ from __future__ import print_function
...
@@ -16,12 +16,15 @@ from __future__ import print_function
from
.distribute_transpiler
import
DistributeTranspiler
,
DistributeTranspilerConfig
from
.distribute_transpiler
import
DistributeTranspiler
,
DistributeTranspilerConfig
from
.inference_transpiler
import
InferenceTranspiler
from
.inference_transpiler
import
InferenceTranspiler
from
.quantize_transpiler
import
QuantizeTranspiler
from
.memory_optimization_transpiler
import
memory_optimize
,
release_memory
from
.memory_optimization_transpiler
import
memory_optimize
,
release_memory
from
.ps_dispatcher
import
HashName
,
RoundRobin
from
.ps_dispatcher
import
HashName
,
RoundRobin
__all__
=
[
__all__
=
[
"DistributeTranspiler"
,
"InferenceTranspiler"
,
"memory_optimize"
,
"DistributeTranspiler"
,
"release_memory"
,
"HashName"
,
"RoundRobin"
,
"DistributeTranspilerConfig"
,
"InferenceTranspiler"
,
"QuantizeTranspiler"
"memory_optimize"
,
"release_memory"
,
"HashName"
,
"RoundRobin"
,
"DistributeTranspilerConfig"
,
]
]
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录