MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / create_parameter

Method create_parameter

python/paddle/base/framework.py:4696–4742  ·  view source on GitHub ↗
(self, *args, **kwargs)

Source from the content-addressed store, hash-verified

4694 del self.vars[name]
4695
4696 def create_parameter(self, *args, **kwargs):
4697 global_block = self.program.global_block()
4698 param = None
4699 if in_dygraph_mode():
4700 param = EagerParamBase(*args, **kwargs)
4701 else:
4702 param = Parameter(global_block, *args, **kwargs)
4703 # NOTE(Aurelius84): we deliver stop_gradient in append_op, so we
4704 # need record it state and reset it back after calling this API
4705 stop_gradient = param.stop_gradient
4706
4707 if "initializer" in kwargs:
4708
4709 def _is_inited_by(block, var):
4710 init_ops = []
4711 for op in block.ops:
4712 if var.name in op.output_arg_names:
4713 # In startup_program, "broadcast" and "c_sync_comm_stream"
4714 # are treated as initialization ops that cause error.
4715 # Think of "broadcast" and "c_sync_comm_stream" as a special case here.
4716 # NOTE: "coalesce_tensor" is a special case for rnn with cudnn support
4717 if op.type in [
4718 "broadcast",
4719 "c_sync_comm_stream",
4720 "coalesce_tensor",
4721 ]:
4722 continue
4723 init_ops.append(op)
4724 return init_ops
4725
4726 initializer = kwargs["initializer"]
4727 init_ops = _is_inited_by(global_block, param)
4728 init_ops_len = len(init_ops)
4729 if init_ops_len > 1:
4730 raise RuntimeError(
4731 "param "
4732 + param.name
4733 + " is inited by multiple init ops "
4734 + str(init_ops)
4735 )
4736 elif init_ops_len == 1:
4737 # TODO already inited, do nothing, should log a warning
4738 pass
4739 else:
4740 initializer(param, self)
4741 param.stop_gradient = stop_gradient
4742 return param
4743
4744 def append_op(self, *args, **kwargs):
4745 """

Callers 15

_sync_with_cppMethod · 0.95
__init__Method · 0.45
__init__Method · 0.45
_simple_networkFunction · 0.45
__init__Method · 0.45
__init__Method · 0.45
initialize_alphaMethod · 0.45
nceFunction · 0.45
_init_by_numpy_arrayFunction · 0.45
sequence_convFunction · 0.45
fc_baseFunction · 0.45
instance_normFunction · 0.45

Calls 6

in_dygraph_modeFunction · 0.85
EagerParamBaseClass · 0.85
RuntimeErrorClass · 0.85
strFunction · 0.85
global_blockMethod · 0.80
ParameterClass · 0.70

Tested by 15

test_dist_parameterMethod · 0.36
__init__Method · 0.36
test_build_apiMethod · 0.36
test_build_apiMethod · 0.36
__init__Method · 0.36
__init__Method · 0.36
len_with_selected_rowsFunction · 0.36