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

Function create_parameter

python/paddle/pir/core.py:333–410  ·  view source on GitHub ↗
(
    dtype,
    shape,
    name=None,
    **kwargs,
)

Source from the content-addressed store, hash-verified

331
332
333def create_parameter(
334 dtype,
335 shape,
336 name=None,
337 **kwargs,
338):
339 if 'initializer' not in kwargs:
340 raise ValueError(
341 "initializer is None, if you want to create parameter, please pass its initializer."
342 )
343 if dtype is not None:
344 if not isinstance(dtype, DataType):
345 dtype = convert_np_dtype_to_dtype_(dtype)
346 value_name = name
347 if not value_name:
348 value_name = unique_name.generate('parameter')
349 startup_program = default_startup_program()
350 main_program = default_main_program()
351 parameter_meta = ParameterMeta(shape, dtype)
352
353 is_dist = False
354 if (
355 'placements' in kwargs
356 and kwargs['placements']
357 and 'process_mesh' in kwargs
358 and kwargs['process_mesh']
359 ):
360 is_dist = True
361
362 def to_dist(value):
363 import paddle
364 import paddle.distributed as dist
365
366 process_mesh = kwargs['process_mesh']
367 dim_map, partial_status = dist.auto_parallel.placement_type.to_dim_map(
368 kwargs['placements'], len(shape)
369 )
370 dist_attr = paddle.base.libpaddle.pir.create_tensor_dist_attribute(
371 process_mesh, dim_map, partial_status
372 )
373 dist_type = paddle.base.libpaddle.pir.cvt_to_dist_type(
374 value.type(), dist_attr
375 )
376 value.set_type(dist_type)
377 op_dist_attr = paddle.base.libpaddle.pir.create_op_dist_attribute(
378 process_mesh, [], [dist_attr]
379 )
380 value.get_defining_op().dist_attr = op_dist_attr
381
382 with program_guard(startup_program):
383 initializer = kwargs['initializer']
384 init_result = initializer(
385 parameter_meta, startup_program.global_block()
386 )
387 init_result.persistable = True
388 if is_dist:
389 to_dist(init_result)
390

Callers 15

_increment_global_varMethod · 0.90
_append_optimize_opMethod · 0.90
getMethod · 0.90
sample_programMethod · 0.90
sample_programMethod · 0.90
sample_programMethod · 0.90
sample_programMethod · 0.90
sample_programMethod · 0.90
sample_programMethod · 0.90
sample_programMethod · 0.90
build_ir_programMethod · 0.90
sample_programMethod · 0.90

Calls 12

ValueErrorClass · 0.85
ParameterMetaClass · 0.85
to_distFunction · 0.85
set_parameterFunction · 0.85
parameterFunction · 0.85
global_blockMethod · 0.80
default_startup_programFunction · 0.70
default_main_programFunction · 0.70
program_guardFunction · 0.70
generateMethod · 0.45
getMethod · 0.45

Tested by 15

sample_programMethod · 0.72
sample_programMethod · 0.72
sample_programMethod · 0.72
sample_programMethod · 0.72
sample_programMethod · 0.72
sample_programMethod · 0.72
sample_programMethod · 0.72
build_ir_programMethod · 0.72
sample_programMethod · 0.72
sample_programMethod · 0.72
sample_programMethod · 0.72
build_ir_programMethod · 0.72