Skip to content

Commit 090c974

Browse files
author
wangyang59
committed
completed implementation of cudnn_convt convTransProjection and convTransOperator
1 parent 07c1ea2 commit 090c974

File tree

4 files changed

+148
-22
lines changed

4 files changed

+148
-22
lines changed

python/paddle/trainer/config_parser.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ def __init__(self,
726726
**xargs):
727727
super(ConvProjection, self).__init__(input_layer_name, **xargs)
728728

729-
parse_conv(conv_conf, input_layer_name, self.proj_conf.conv_conf,
729+
parse_conv(conv_conf, self.input_layer_name, self.proj_conf.conv_conf,
730730
num_filters)
731731
self.proj_conf.output_size = self.proj_conf.conv_conf.output_x * \
732732
self.proj_conf.conv_conf.output_y * \
@@ -746,7 +746,7 @@ def __init__(self,
746746

747747
parse_conv(
748748
conv_conf,
749-
input_layer_name,
749+
self.input_layer_name,
750750
self.proj_conf.conv_conf,
751751
num_filters,
752752
trans=True)
@@ -1834,8 +1834,17 @@ def __init__(self,
18341834
use_gpu = int(g_command_config_args.get("use_gpu", 0))
18351835
parallel_nn = int(g_command_config_args.get("parallel_nn", 0))
18361836

1837-
# cudnn_convt has not been implemented so use exconvt only
1838-
self.layer_type = "exconvt"
1837+
# Automatically select cudnn_type for GPU and exconvt for CPU
1838+
# if set type=exconvt, but still reserve the way user specify
1839+
# exconvt or cudnn_convt manually.
1840+
if self.layer_type == "cudnn_convt":
1841+
config_assert(use_gpu, "cudnn_convt only support GPU")
1842+
1843+
if (use_gpu == 1 and self.layer_type != "exconvt" and
1844+
(parallel_nn == 0 or self.config.device > -1)):
1845+
self.layer_type = "cudnn_convt"
1846+
else:
1847+
self.layer_type = "exconvt"
18391848
# need to specify layer in config
18401849
self.config.type = self.layer_type
18411850

@@ -1852,10 +1861,9 @@ def __init__(self,
18521861
trans=True)
18531862
conv_conf = self.config.inputs[input_index].conv_conf
18541863
psize = self.calc_parameter_size(conv_conf)
1855-
print("output size for %s is %d " % (name, conv_conf.output_x))
18561864
self.create_input_parameter(input_index, psize)
1857-
self.set_layer_size(
1858-
(conv_conf.img_size**2) * self.config.num_filters)
1865+
self.set_cnn_layer(name, conv_conf.img_size_y, conv_conf.img_size,
1866+
self.config.num_filters)
18591867

18601868
psize = self.config.size
18611869
if shared_biases:
@@ -1872,6 +1880,11 @@ class ConvTransLayer(ConvTransLayerBase):
18721880
layer_type = 'exconvt'
18731881

18741882

1883+
@config_layer('cudnn_convt')
1884+
class ConvTransLayer(ConvTransLayerBase):
1885+
layer_type = 'cudnn_convt'
1886+
1887+
18751888
@config_layer('norm')
18761889
class NormLayer(LayerBase):
18771890
def __init__(self, name, inputs, **xargs):

python/paddle/trainer_config_helpers/layers.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2046,8 +2046,9 @@ def img_conv_layer(input,
20462046
:param trans: true if it is a convTransLayer, false if it is a convLayer
20472047
:type trans: bool
20482048
:param layer_type: specify the layer_type, default is None. If trans=True,
2049-
layer_type has to be "exconvt", otherwise layer_type
2050-
has to be either "exconv" or "cudnn_conv"
2049+
layer_type has to be "exconvt" or "cudnn_convt",
2050+
otherwise layer_type has to be either "exconv" or
2051+
"cudnn_conv"
20512052
:type layer_type: String
20522053
:return: LayerOutput object.
20532054
:rtype: LayerOutput
@@ -2087,7 +2088,7 @@ def img_conv_layer(input,
20872088

20882089
if layer_type:
20892090
if trans:
2090-
assert layer_type in ["exconvt"]
2091+
assert layer_type in ["exconvt", "cudnn_convt"]
20912092
else:
20922093
assert layer_type in ["exconv", "cudnn_conv"]
20932094
lt = layer_type

python/paddle/trainer_config_helpers/tests/configs/protostr/img_trans_layers.protostr

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ layers {
3333
bias_parameter_name: "___conv_0__.wbias"
3434
num_filters: 64
3535
shared_biases: true
36+
height: 256
37+
width: 256
3638
}
3739
layers {
3840
name: "__batch_norm_0__"
@@ -58,6 +60,8 @@ layers {
5860
}
5961
bias_parameter_name: "___batch_norm_0__.wbias"
6062
moving_average_fraction: 0.9
63+
height: 256
64+
width: 256
6165
}
6266
layers {
6367
name: "__crmnorm_0__"

python/paddle/trainer_config_helpers/tests/configs/protostr/projections.protostr

Lines changed: 120 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,38 @@ layers {
154154
inputs {
155155
input_layer_name: "img"
156156
}
157+
inputs {
158+
input_layer_name: "img"
159+
proj_conf {
160+
type: "conv"
161+
name: "___mixed_6__.w1"
162+
input_size: 1024
163+
output_size: 57600
164+
conv_conf {
165+
filter_size: 3
166+
channels: 1
167+
stride: 1
168+
padding: 0
169+
groups: 1
170+
filter_channels: 1
171+
output_x: 30
172+
img_size: 32
173+
caffe_mode: true
174+
filter_size_y: 3
175+
padding_y: 0
176+
stride_y: 1
177+
output_y: 30
178+
img_size_y: 32
179+
}
180+
}
181+
}
157182
inputs {
158183
input_layer_name: "filter"
159184
}
160185
operator_confs {
161186
type: "conv"
162187
input_indices: 0
163-
input_indices: 1
188+
input_indices: 2
164189
input_sizes: 1024
165190
input_sizes: 576
166191
output_size: 57600
@@ -186,38 +211,110 @@ layers {
186211
layers {
187212
name: "__mixed_7__"
188213
type: "mixed"
214+
size: 254016
215+
active_type: ""
216+
inputs {
217+
input_layer_name: "img"
218+
}
219+
inputs {
220+
input_layer_name: "img"
221+
proj_conf {
222+
type: "convt"
223+
name: "___mixed_7__.w1"
224+
input_size: 1024
225+
output_size: 254016
226+
conv_conf {
227+
filter_size: 3
228+
channels: 1
229+
stride: 2
230+
padding: 1
231+
groups: 1
232+
filter_channels: 64
233+
output_x: 32
234+
img_size: 63
235+
caffe_mode: true
236+
filter_size_y: 3
237+
padding_y: 1
238+
stride_y: 2
239+
output_y: 32
240+
img_size_y: 63
241+
}
242+
}
243+
}
244+
inputs {
245+
input_layer_name: "filter"
246+
}
247+
operator_confs {
248+
type: "convt"
249+
input_indices: 0
250+
input_indices: 2
251+
input_sizes: 1024
252+
input_sizes: 576
253+
output_size: 254016
254+
conv_conf {
255+
filter_size: 3
256+
channels: 1
257+
stride: 2
258+
padding: 1
259+
groups: 1
260+
filter_channels: 64
261+
output_x: 32
262+
img_size: 63
263+
caffe_mode: true
264+
filter_size_y: 3
265+
padding_y: 1
266+
stride_y: 2
267+
output_y: 32
268+
img_size_y: 63
269+
}
270+
num_filters: 64
271+
}
272+
}
273+
layers {
274+
name: "__mixed_8__"
275+
type: "mixed"
189276
size: 100
190277
active_type: ""
191278
inputs {
192279
input_layer_name: "__mixed_4__"
193-
input_parameter_name: "___mixed_7__.w0"
280+
input_parameter_name: "___mixed_8__.w0"
194281
proj_conf {
195282
type: "fc"
196-
name: "___mixed_7__.w0"
283+
name: "___mixed_8__.w0"
197284
input_size: 300
198285
output_size: 100
199286
}
200287
}
201288
inputs {
202289
input_layer_name: "__mixed_5__"
203-
input_parameter_name: "___mixed_7__.w1"
290+
input_parameter_name: "___mixed_8__.w1"
204291
proj_conf {
205292
type: "trans_fc"
206-
name: "___mixed_7__.w1"
293+
name: "___mixed_8__.w1"
207294
input_size: 100
208295
output_size: 100
209296
}
210297
}
211298
inputs {
212299
input_layer_name: "__mixed_6__"
213-
input_parameter_name: "___mixed_7__.w2"
300+
input_parameter_name: "___mixed_8__.w2"
214301
proj_conf {
215302
type: "fc"
216-
name: "___mixed_7__.w2"
303+
name: "___mixed_8__.w2"
217304
input_size: 57600
218305
output_size: 100
219306
}
220307
}
308+
inputs {
309+
input_layer_name: "__mixed_7__"
310+
input_parameter_name: "___mixed_8__.w3"
311+
proj_conf {
312+
type: "fc"
313+
name: "___mixed_8__.w3"
314+
input_size: 254016
315+
output_size: 100
316+
}
317+
}
221318
drop_rate: 0.5
222319
}
223320
parameters {
@@ -281,7 +378,7 @@ parameters {
281378
initial_smart: true
282379
}
283380
parameters {
284-
name: "___mixed_7__.w0"
381+
name: "___mixed_8__.w0"
285382
size: 30000
286383
initial_mean: 0.0
287384
initial_std: 0.057735026919
@@ -291,7 +388,7 @@ parameters {
291388
initial_smart: true
292389
}
293390
parameters {
294-
name: "___mixed_7__.w1"
391+
name: "___mixed_8__.w1"
295392
size: 10000
296393
initial_mean: 0.0
297394
initial_std: 0.1
@@ -301,7 +398,7 @@ parameters {
301398
initial_smart: true
302399
}
303400
parameters {
304-
name: "___mixed_7__.w2"
401+
name: "___mixed_8__.w2"
305402
size: 5760000
306403
initial_mean: 0.0
307404
initial_std: 0.00416666666667
@@ -310,10 +407,20 @@ parameters {
310407
initial_strategy: 0
311408
initial_smart: true
312409
}
410+
parameters {
411+
name: "___mixed_8__.w3"
412+
size: 25401600
413+
initial_mean: 0.0
414+
initial_std: 0.00198412698413
415+
dims: 254016
416+
dims: 100
417+
initial_strategy: 0
418+
initial_smart: true
419+
}
313420
input_layer_names: "test"
314421
input_layer_names: "img"
315422
input_layer_names: "filter"
316-
output_layer_names: "__mixed_7__"
423+
output_layer_names: "__mixed_8__"
317424
sub_models {
318425
name: "root"
319426
layer_names: "test"
@@ -328,10 +435,11 @@ sub_models {
328435
layer_names: "filter"
329436
layer_names: "__mixed_6__"
330437
layer_names: "__mixed_7__"
438+
layer_names: "__mixed_8__"
331439
input_layer_names: "test"
332440
input_layer_names: "img"
333441
input_layer_names: "filter"
334-
output_layer_names: "__mixed_7__"
442+
output_layer_names: "__mixed_8__"
335443
is_recurrent_layer_group: false
336444
}
337445

0 commit comments

Comments
 (0)