Skip to content

Commit ca988bd

Browse files
authored
Merge pull request #1 from PaddlePaddle/develop
update from origin
2 parents e745bcf + f07a226 commit ca988bd

File tree

362 files changed

+15411
-3383
lines changed

Some content is hidden

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

362 files changed

+15411
-3383
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ include(external/swig) # download, build, install swig
126126
include(external/warpctc) # download, build, install warpctc
127127
include(external/any) # download libn::any
128128
include(external/eigen) # download eigen3
129-
include(external/pybind11) # download pybind11
129+
include(external/pybind11) # download pybind11
130130
include(external/nccl)
131131

132132
include(cudnn) # set cudnn libraries, must before configure

benchmark/paddle/image/resnet.py

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
#!/usr/bin/env python
2+
from paddle.trainer_config_helpers import *
3+
4+
height = 224
5+
width = 224
6+
num_class = 1000
7+
batch_size = get_config_arg('batch_size', int, 64)
8+
layer_num = get_config_arg("layer_num", int, 50)
9+
is_test = get_config_arg("is_test", bool, False)
10+
11+
args = {'height': height, 'width': width, 'color': True, 'num_class': num_class}
12+
define_py_data_sources2(
13+
"train.list", None, module="provider", obj="process", args=args)
14+
15+
settings(
16+
batch_size=batch_size,
17+
learning_rate=0.01 / batch_size,
18+
learning_method=MomentumOptimizer(0.9),
19+
regularization=L2Regularization(0.0005 * batch_size))
20+
21+
22+
#######################Network Configuration #############
23+
def conv_bn_layer(name,
24+
input,
25+
filter_size,
26+
num_filters,
27+
stride,
28+
padding,
29+
channels=None,
30+
active_type=ReluActivation()):
31+
"""
32+
A wrapper for conv layer with batch normalization layers.
33+
Note:
34+
conv layer has no activation.
35+
"""
36+
37+
tmp = img_conv_layer(
38+
name=name + "_conv",
39+
input=input,
40+
filter_size=filter_size,
41+
num_channels=channels,
42+
num_filters=num_filters,
43+
stride=stride,
44+
padding=padding,
45+
act=LinearActivation(),
46+
bias_attr=False)
47+
return batch_norm_layer(
48+
name=name + "_bn", input=tmp, act=active_type, use_global_stats=is_test)
49+
50+
51+
def bottleneck_block(name, input, num_filters1, num_filters2):
52+
"""
53+
A wrapper for bottlenect building block in ResNet.
54+
Last conv_bn_layer has no activation.
55+
Addto layer has activation of relu.
56+
"""
57+
last_name = conv_bn_layer(
58+
name=name + '_branch2a',
59+
input=input,
60+
filter_size=1,
61+
num_filters=num_filters1,
62+
stride=1,
63+
padding=0)
64+
last_name = conv_bn_layer(
65+
name=name + '_branch2b',
66+
input=last_name,
67+
filter_size=3,
68+
num_filters=num_filters1,
69+
stride=1,
70+
padding=1)
71+
last_name = conv_bn_layer(
72+
name=name + '_branch2c',
73+
input=last_name,
74+
filter_size=1,
75+
num_filters=num_filters2,
76+
stride=1,
77+
padding=0,
78+
active_type=LinearActivation())
79+
80+
return addto_layer(
81+
name=name + "_addto", input=[input, last_name], act=ReluActivation())
82+
83+
84+
def mid_projection(name, input, num_filters1, num_filters2, stride=2):
85+
"""
86+
A wrapper for middile projection in ResNet.
87+
projection shortcuts are used for increasing dimensions,
88+
and other shortcuts are identity
89+
branch1: projection shortcuts are used for increasing
90+
dimensions, has no activation.
91+
branch2x: bottleneck building block, shortcuts are identity.
92+
"""
93+
# stride = 2
94+
branch1 = conv_bn_layer(
95+
name=name + '_branch1',
96+
input=input,
97+
filter_size=1,
98+
num_filters=num_filters2,
99+
stride=stride,
100+
padding=0,
101+
active_type=LinearActivation())
102+
103+
last_name = conv_bn_layer(
104+
name=name + '_branch2a',
105+
input=input,
106+
filter_size=1,
107+
num_filters=num_filters1,
108+
stride=stride,
109+
padding=0)
110+
last_name = conv_bn_layer(
111+
name=name + '_branch2b',
112+
input=last_name,
113+
filter_size=3,
114+
num_filters=num_filters1,
115+
stride=1,
116+
padding=1)
117+
118+
last_name = conv_bn_layer(
119+
name=name + '_branch2c',
120+
input=last_name,
121+
filter_size=1,
122+
num_filters=num_filters2,
123+
stride=1,
124+
padding=0,
125+
active_type=LinearActivation())
126+
127+
return addto_layer(
128+
name=name + "_addto", input=[branch1, last_name], act=ReluActivation())
129+
130+
131+
img = data_layer(name='image', size=height * width * 3)
132+
133+
134+
def deep_res_net(res2_num=3, res3_num=4, res4_num=6, res5_num=3):
135+
"""
136+
A wrapper for 50,101,152 layers of ResNet.
137+
res2_num: number of blocks stacked in conv2_x
138+
res3_num: number of blocks stacked in conv3_x
139+
res4_num: number of blocks stacked in conv4_x
140+
res5_num: number of blocks stacked in conv5_x
141+
"""
142+
# For ImageNet
143+
# conv1: 112x112
144+
tmp = conv_bn_layer(
145+
"conv1",
146+
input=img,
147+
filter_size=7,
148+
channels=3,
149+
num_filters=64,
150+
stride=2,
151+
padding=3)
152+
tmp = img_pool_layer(name="pool1", input=tmp, pool_size=3, stride=2)
153+
154+
# conv2_x: 56x56
155+
tmp = mid_projection(
156+
name="res2_1", input=tmp, num_filters1=64, num_filters2=256, stride=1)
157+
for i in xrange(2, res2_num + 1, 1):
158+
tmp = bottleneck_block(
159+
name="res2_" + str(i), input=tmp, num_filters1=64, num_filters2=256)
160+
161+
# conv3_x: 28x28
162+
tmp = mid_projection(
163+
name="res3_1", input=tmp, num_filters1=128, num_filters2=512)
164+
for i in xrange(2, res3_num + 1, 1):
165+
tmp = bottleneck_block(
166+
name="res3_" + str(i),
167+
input=tmp,
168+
num_filters1=128,
169+
num_filters2=512)
170+
171+
# conv4_x: 14x14
172+
tmp = mid_projection(
173+
name="res4_1", input=tmp, num_filters1=256, num_filters2=1024)
174+
for i in xrange(2, res4_num + 1, 1):
175+
tmp = bottleneck_block(
176+
name="res4_" + str(i),
177+
input=tmp,
178+
num_filters1=256,
179+
num_filters2=1024)
180+
181+
# conv5_x: 7x7
182+
tmp = mid_projection(
183+
name="res5_1", input=tmp, num_filters1=512, num_filters2=2048)
184+
for i in xrange(2, res5_num + 1, 1):
185+
tmp = bottleneck_block(
186+
name="res5_" + str(i),
187+
input=tmp,
188+
num_filters1=512,
189+
num_filters2=2048)
190+
191+
tmp = img_pool_layer(
192+
name='avgpool',
193+
input=tmp,
194+
pool_size=7,
195+
stride=1,
196+
pool_type=AvgPooling())
197+
198+
return fc_layer(input=tmp, size=num_class, act=SoftmaxActivation())
199+
200+
201+
if layer_num == 50:
202+
resnet = deep_res_net(3, 4, 6, 3)
203+
elif layer_num == 101:
204+
resnet = deep_res_net(3, 4, 23, 3)
205+
elif layer_num == 152:
206+
resnet = deep_res_net(3, 8, 36, 3)
207+
else:
208+
print("Wrong layer number.")
209+
210+
lbl = data_layer(name="label", size=num_class)
211+
loss = cross_entropy(name='loss', input=resnet, label=lbl)
212+
inputs(img, lbl)
213+
outputs(loss)

benchmark/paddle/image/run_mkldnn.sh

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,23 @@ function train() {
55
export OMP_DYNAMIC="FALSE"
66
export KMP_AFFINITY="granularity=fine,compact,0,0"
77
topology=$1
8-
bs=$2
9-
use_mkldnn=$3
10-
if [ $3 == "True" ]; then
8+
layer_num=$2
9+
bs=$3
10+
use_mkldnn=$4
11+
if [ $4 == "True" ]; then
1112
thread=1
12-
log="logs/${topology}-mkldnn-${bs}.log"
13-
elif [ $3 == "False" ]; then
13+
log="logs/${topology}-${layer_num}-mkldnn-${bs}.log"
14+
elif [ $4 == "False" ]; then
1415
thread=`nproc`
1516
# each trainer_count use only 1 core to avoid conflict
1617
export OMP_NUM_THREADS=1
1718
export MKL_NUM_THREADS=1
18-
log="logs/${topology}-${thread}mklml-${bs}.log"
19+
log="logs/${topology}-${layer_num}-${thread}mklml-${bs}.log"
1920
else
2021
echo "Wrong input $3, use True or False."
2122
exit 0
2223
fi
23-
args="batch_size=${bs}"
24+
args="batch_size=${bs},layer_num=${layer_num}"
2425
config="${topology}.py"
2526
paddle train --job=time \
2627
--config=$config \
@@ -40,12 +41,9 @@ if [ ! -d "logs" ]; then
4041
mkdir logs
4142
fi
4243

43-
#========== mkldnn ==========#
44-
train vgg 64 True
45-
train vgg 128 True
46-
train vgg 256 True
47-
48-
#========== mklml ===========#
49-
train vgg 64 False
50-
train vgg 128 False
51-
train vgg 256 False
44+
for use_mkldnn in True False; do
45+
for batchsize in 64 128 256; do
46+
train vgg 19 $batchsize $use_mkldnn
47+
train resnet 50 $batchsize $use_mkldnn
48+
done
49+
done

benchmark/paddle/image/vgg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
settings(
1515
batch_size=batch_size,
16-
learning_rate=0.01 / batch_size,
16+
learning_rate=0.001 / batch_size,
1717
learning_method=MomentumOptimizer(0.9),
1818
regularization=L2Regularization(0.0005 * batch_size))
1919

cmake/cblas.cmake

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
# Find the CBlas and lapack libraries
22
#
3-
# It will search MKL, atlas, OpenBlas, reference-cblas in order.
3+
# It will search MKLML, atlas, OpenBlas, reference-cblas in order.
44
#
55
# If any cblas implementation found, the following variable will be set.
6-
# CBLAS_PROVIDER # one of MKL, ATLAS, OPENBLAS, REFERENCE
6+
# CBLAS_PROVIDER # one of MKLML, ATLAS, OPENBLAS, REFERENCE
77
# CBLAS_INC_DIR # the include directory for cblas.
88
# CBLAS_LIBS # a list of libraries should be linked by paddle.
99
# # Each library should be full path to object file.
10-
#
11-
# User should set one of MKL_ROOT, ATLAS_ROOT, OPENBLAS_ROOT, REFERENCE_CBLAS_ROOT
12-
# during cmake. If none of them set, it will try to find cblas implementation in
13-
# system paths.
14-
#
1510

1611
set(CBLAS_FOUND OFF)
1712

@@ -30,44 +25,6 @@ if(WITH_MKLML AND MKLML_INC_DIR AND MKLML_LIB)
3025
return()
3126
endif()
3227

33-
## Then find MKL.
34-
set(INTEL_MKL_ROOT "/opt/intel/mkl" CACHE PATH "Folder contains intel mkl libs")
35-
set(MKL_ROOT $ENV{MKL_ROOT} CACHE PATH "Folder contains env MKL")
36-
37-
set(MKL_INCLUDE_SEARCH_PATHS
38-
${MKL_ROOT}/include
39-
${INTEL_MKL_ROOT}/include)
40-
set(MKL_LIB_SEARCH_PATHS
41-
${MKL_ROOT}/lib
42-
${MKL_ROOT}/lib/intel64
43-
${INTEL_MKL_ROOT}/lib
44-
${INTEL_MKL_ROOT}/lib/intel64)
45-
46-
find_path(MKL_INC_DIR mkl.h PATHS
47-
${MKL_INCLUDE_SEARCH_PATHS})
48-
find_path(MKL_LAPACK_INC_DIR mkl_lapacke.h PATHS
49-
${MKL_INCLUDE_SEARCH_PATHS})
50-
find_library(MKL_CORE_LIB NAMES mkl_core PATHS
51-
${MKL_LIB_SEARCH_PATHS})
52-
find_library(MKL_SEQUENTIAL_LIB NAMES mkl_sequential PATHS
53-
${MKL_LIB_SEARCH_PATHS})
54-
find_library(MKL_INTEL_LP64 NAMES mkl_intel_lp64 PATHS
55-
${MKL_LIB_SEARCH_PATHS})
56-
57-
if(MKL_LAPACK_INC_DIR AND MKL_INC_DIR AND MKL_CORE_LIB AND MKL_SEQUENTIAL_LIB AND MKL_INTEL_LP64)
58-
set(CBLAS_FOUND ON)
59-
set(CBLAS_PROVIDER MKL)
60-
set(CBLAS_INC_DIR ${MKL_INC_DIR} ${MKL_LAPACK_INC_DIR})
61-
set(CBLAS_LIBRARIES ${MKL_INTEL_LP64} ${MKL_SEQUENTIAL_LIB} ${MKL_CORE_LIB})
62-
63-
add_definitions(-DPADDLE_USE_MKL)
64-
add_definitions(-DLAPACK_FOUND)
65-
66-
message(STATUS "Found MKL (include: ${MKL_INC_DIR}, library: ${CBLAS_LIBRARIES})")
67-
message(STATUS "Found lapack in MKL (include: ${MKL_LAPACK_INC_DIR})")
68-
return()
69-
endif()
70-
7128
## Then find atlas.
7229
set(ATLAS_ROOT $ENV{ATLAS_ROOT} CACHE PATH "Folder contains Atlas")
7330
set(ATLAS_INCLUDE_SEARCH_PATHS

cmake/cross_compiling/ios.cmake

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,8 @@ if(NOT DEFINED IOS_ARCH)
7979
# FIXME(liuyiqun): support "armv7;armv7s;arm64" future
8080
set(IOS_ARCH "arm64")
8181
elseif(IOS_PLATFORM STREQUAL "SIMULATOR")
82-
set(IOS_ARCH "i386;x86_64")
83-
elseif(IOS_PLATFORM STREQUAL "WATCHOS")
84-
set(IOS_ARCH armv7k)
82+
# FIXME(liuyiqun): support "i386;x86_64" future
83+
set(IOS_ARCH "x86_64")
8584
endif()
8685
endif()
8786
set(CMAKE_OSX_ARCHITECTURES ${IOS_ARCH} CACHE string "Build architecture for iOS")

cmake/external/mkldnn.cmake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,20 @@ IF(${CBLAS_PROVIDER} STREQUAL "MKLML")
4646
MESSAGE(STATUS "Build MKLDNN with ${MKLDNN_MKLROOT}")
4747
ENDIF()
4848

49+
SET(MKLDNN_CFLAG "${CMAKE_C_FLAGS} -Wno-error=strict-overflow")
50+
SET(MKLDNN_CXXFLAG "${CMAKE_CXX_FLAGS} -Wno-error=strict-overflow")
4951
ExternalProject_Add(
5052
${MKLDNN_PROJECT}
5153
${EXTERNAL_PROJECT_LOG_ARGS}
5254
DEPENDS ${MKLDNN_DEPENDS}
5355
GIT_REPOSITORY "https://github.com/01org/mkl-dnn.git"
54-
GIT_TAG "v0.10"
56+
GIT_TAG "v0.11"
5557
PREFIX ${MKLDNN_SOURCES_DIR}
5658
UPDATE_COMMAND ""
5759
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${MKLDNN_INSTALL_DIR}
5860
CMAKE_ARGS -DMKLROOT=${MKLDNN_MKLROOT}
61+
CMAKE_ARGS -DCMAKE_C_FLAGS=${MKLDNN_CFLAG}
62+
CMAKE_ARGS -DCMAKE_CXX_FLAGS=${MKLDNN_CXXFLAG}
5963
CMAKE_CACHE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${MKLDNN_INSTALL_DIR}
6064
-DMKLROOT:PATH=${MKLDNN_MKLROOT}
6165
)

cmake/external/mklml.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ ENDIF()
2727
INCLUDE(ExternalProject)
2828

2929
SET(MKLML_PROJECT "extern_mklml")
30-
SET(MKLML_VER "mklml_lnx_2018.0.20170720")
31-
SET(MKLML_URL "https://github.com/01org/mkl-dnn/releases/download/v0.10/${MKLML_VER}.tgz")
30+
SET(MKLML_VER "mklml_lnx_2018.0.1.20171007")
31+
SET(MKLML_URL "https://github.com/01org/mkl-dnn/releases/download/v0.11/${MKLML_VER}.tgz")
3232
SET(MKLML_SOURCE_DIR "${THIRD_PARTY_PATH}/mklml")
3333
SET(MKLML_DOWNLOAD_DIR "${MKLML_SOURCE_DIR}/src/${MKLML_PROJECT}")
3434
SET(MKLML_DST_DIR "mklml")

0 commit comments

Comments
 (0)