Skip to content

Commit 8aeac78

Browse files
committed
revert initializer.py
1 parent aa54638 commit 8aeac78

File tree

1 file changed

+0
-47
lines changed

1 file changed

+0
-47
lines changed

python/paddle/fluid/initializer.py

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -62,24 +62,6 @@ def init_on_cpu():
6262
_force_init_on_cpu_ = pre_state
6363

6464

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-
8365
class Initializer(object):
8466
"""Base class for variable initializers
8567
@@ -165,7 +147,6 @@ def __call__(self, var, block):
165147
"""
166148
assert isinstance(var, framework.Variable)
167149
assert isinstance(block, framework.Block)
168-
init_op = _is_inited_by(block, var, ['fill_constant'])
169150
# Initialization Ops should be prepended and not appended
170151
op = block._prepend_op(
171152
type="fill_constant",
@@ -176,9 +157,6 @@ def __call__(self, var, block):
176157
"value": float(self._value),
177158
'force_cpu': self._force_cpu or force_init_on_cpu()
178159
})
179-
if init_op is not None and _is_duplicated_init_op(init_op, op):
180-
block._remove_op(0)
181-
return init_op
182160
var.op = op
183161
return op
184162

@@ -221,7 +199,6 @@ def __call__(self, var, block):
221199
"""
222200
assert isinstance(var, framework.Variable)
223201
assert isinstance(block, framework.Block)
224-
init_op = _is_inited_by(block, var, ['uniform_random'])
225202
# Initialization Ops should be prepended and not appended
226203
if self._seed == 0:
227204
self._seed = block.program.random_seed
@@ -235,9 +212,6 @@ def __call__(self, var, block):
235212
"max": self._high,
236213
"seed": self._seed
237214
})
238-
if init_op is not None and _is_duplicated_init_op(init_op, op):
239-
block._remove_op(0)
240-
return init_op
241215
var.op = op
242216
return op
243217

@@ -279,7 +253,6 @@ def __call__(self, var, block):
279253
"""
280254
assert isinstance(var, framework.Variable)
281255
assert isinstance(block, framework.Block)
282-
init_op = _is_inited_by(block, var, ['gaussian_random'])
283256
# Initialization Ops should be prepended and not appended
284257
if self._seed == 0:
285258
self._seed = block.program.random_seed
@@ -293,9 +266,6 @@ def __call__(self, var, block):
293266
"std": self._std_dev,
294267
"seed": self._seed
295268
})
296-
if init_op is not None and _is_duplicated_init_op(init_op, op):
297-
block._remove_op(0)
298-
return init_op
299269
var.op = op
300270
return op
301271

@@ -365,9 +335,6 @@ def __call__(self, var, block):
365335
"""
366336
assert isinstance(var, framework.Variable)
367337
assert isinstance(block, framework.Block)
368-
init_op = _is_inited_by(block, var,
369-
['uniform_random', 'gaussian_random'])
370-
371338
f_in, f_out = self._compute_fans(var)
372339

373340
# If fan_in and fan_out are passed, use them
@@ -402,9 +369,6 @@ def __call__(self, var, block):
402369
"std": std,
403370
"seed": self._seed
404371
})
405-
if init_op is not None and _is_duplicated_init_op(init_op, op):
406-
block._remove_op(0)
407-
return init_op
408372
var.op = op
409373
return op
410374

@@ -470,9 +434,6 @@ def __call__(self, var, block):
470434
"""
471435
assert isinstance(var, framework.Variable)
472436
assert isinstance(block, framework.Block)
473-
init_op = _is_inited_by(block, var,
474-
['uniform_random', 'gaussian_random'])
475-
476437
f_in, f_out = self._compute_fans(var)
477438

478439
# If fan_in is passed, use it
@@ -506,9 +467,6 @@ def __call__(self, var, block):
506467
"std": std,
507468
"seed": self._seed
508469
})
509-
if init_op is not None and _is_duplicated_init_op(init_op, op):
510-
block._remove_op(0)
511-
return init_op
512470
var.op = op
513471
return op
514472

@@ -574,8 +532,6 @@ def __call__(self, var, block):
574532
if not isinstance(block, framework.Block):
575533
raise ValueError("block must be framework.Block.")
576534

577-
init_op = _is_inited_by(block, var, 'assign_value')
578-
579535
shape = var.shape
580536
if len(shape) != 4:
581537
raise ValueError("the length of shape must be 4.")
@@ -609,9 +565,6 @@ def __call__(self, var, block):
609565
'shape': list(shape),
610566
value_name: values
611567
})
612-
if init_op is not None and _is_duplicated_init_op(init_op, op):
613-
block._remove_op(0)
614-
return init_op
615568
var.op = op
616569
return op
617570

0 commit comments

Comments
 (0)