@@ -62,24 +62,6 @@ def init_on_cpu():
62
62
_force_init_on_cpu_ = pre_state
63
63
64
64
65
- def _is_inited_by (block , var , init_op_types ):
66
- for op in block .ops :
67
- if var .name in op .output_arg_names and op .type in init_op_types :
68
- return op
69
- return None
70
-
71
-
72
- def _is_duplicated_init_op (op1 , op2 ):
73
- if op1 .block == op2 .block and \
74
- op1 .type == op2 .type and \
75
- op1 .input_arg_names == op2 .input_arg_names and \
76
- op1 .output_arg_names == op2 .output_arg_names and \
77
- op1 .idx != op2 .idx and \
78
- op1 .all_attrs () == op2 .all_attrs ():
79
- return True
80
- return False
81
-
82
-
83
65
class Initializer (object ):
84
66
"""Base class for variable initializers
85
67
@@ -165,7 +147,6 @@ def __call__(self, var, block):
165
147
"""
166
148
assert isinstance (var , framework .Variable )
167
149
assert isinstance (block , framework .Block )
168
- init_op = _is_inited_by (block , var , ['fill_constant' ])
169
150
# Initialization Ops should be prepended and not appended
170
151
op = block ._prepend_op (
171
152
type = "fill_constant" ,
@@ -176,9 +157,6 @@ def __call__(self, var, block):
176
157
"value" : float (self ._value ),
177
158
'force_cpu' : self ._force_cpu or force_init_on_cpu ()
178
159
})
179
- if init_op is not None and _is_duplicated_init_op (init_op , op ):
180
- block ._remove_op (0 )
181
- return init_op
182
160
var .op = op
183
161
return op
184
162
@@ -221,7 +199,6 @@ def __call__(self, var, block):
221
199
"""
222
200
assert isinstance (var , framework .Variable )
223
201
assert isinstance (block , framework .Block )
224
- init_op = _is_inited_by (block , var , ['uniform_random' ])
225
202
# Initialization Ops should be prepended and not appended
226
203
if self ._seed == 0 :
227
204
self ._seed = block .program .random_seed
@@ -235,9 +212,6 @@ def __call__(self, var, block):
235
212
"max" : self ._high ,
236
213
"seed" : self ._seed
237
214
})
238
- if init_op is not None and _is_duplicated_init_op (init_op , op ):
239
- block ._remove_op (0 )
240
- return init_op
241
215
var .op = op
242
216
return op
243
217
@@ -279,7 +253,6 @@ def __call__(self, var, block):
279
253
"""
280
254
assert isinstance (var , framework .Variable )
281
255
assert isinstance (block , framework .Block )
282
- init_op = _is_inited_by (block , var , ['gaussian_random' ])
283
256
# Initialization Ops should be prepended and not appended
284
257
if self ._seed == 0 :
285
258
self ._seed = block .program .random_seed
@@ -293,9 +266,6 @@ def __call__(self, var, block):
293
266
"std" : self ._std_dev ,
294
267
"seed" : self ._seed
295
268
})
296
- if init_op is not None and _is_duplicated_init_op (init_op , op ):
297
- block ._remove_op (0 )
298
- return init_op
299
269
var .op = op
300
270
return op
301
271
@@ -365,9 +335,6 @@ def __call__(self, var, block):
365
335
"""
366
336
assert isinstance (var , framework .Variable )
367
337
assert isinstance (block , framework .Block )
368
- init_op = _is_inited_by (block , var ,
369
- ['uniform_random' , 'gaussian_random' ])
370
-
371
338
f_in , f_out = self ._compute_fans (var )
372
339
373
340
# If fan_in and fan_out are passed, use them
@@ -402,9 +369,6 @@ def __call__(self, var, block):
402
369
"std" : std ,
403
370
"seed" : self ._seed
404
371
})
405
- if init_op is not None and _is_duplicated_init_op (init_op , op ):
406
- block ._remove_op (0 )
407
- return init_op
408
372
var .op = op
409
373
return op
410
374
@@ -470,9 +434,6 @@ def __call__(self, var, block):
470
434
"""
471
435
assert isinstance (var , framework .Variable )
472
436
assert isinstance (block , framework .Block )
473
- init_op = _is_inited_by (block , var ,
474
- ['uniform_random' , 'gaussian_random' ])
475
-
476
437
f_in , f_out = self ._compute_fans (var )
477
438
478
439
# If fan_in is passed, use it
@@ -506,9 +467,6 @@ def __call__(self, var, block):
506
467
"std" : std ,
507
468
"seed" : self ._seed
508
469
})
509
- if init_op is not None and _is_duplicated_init_op (init_op , op ):
510
- block ._remove_op (0 )
511
- return init_op
512
470
var .op = op
513
471
return op
514
472
@@ -574,8 +532,6 @@ def __call__(self, var, block):
574
532
if not isinstance (block , framework .Block ):
575
533
raise ValueError ("block must be framework.Block." )
576
534
577
- init_op = _is_inited_by (block , var , 'assign_value' )
578
-
579
535
shape = var .shape
580
536
if len (shape ) != 4 :
581
537
raise ValueError ("the length of shape must be 4." )
@@ -609,9 +565,6 @@ def __call__(self, var, block):
609
565
'shape' : list (shape ),
610
566
value_name : values
611
567
})
612
- if init_op is not None and _is_duplicated_init_op (init_op , op ):
613
- block ._remove_op (0 )
614
- return init_op
615
568
var .op = op
616
569
return op
617
570
0 commit comments