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

Method _copy_data_info_from

python/paddle/base/framework.py:7384–7422  ·  view source on GitHub ↗

Copy the information of data variables from other program. Notes: This is a very low level API. Users should not invoke it directly. Args: other(Program): Other program pruned_origin_block_id_map(dict{int:int}): A dict which maps the block i

(self, other, pruned_origin_block_id_map=None)

Source from the content-addressed store, hash-verified

7382 self._distributed_lookup_table = other._distributed_lookup_table
7383
7384 def _copy_data_info_from(self, other, pruned_origin_block_id_map=None):
7385 """
7386 Copy the information of data variables from other program.
7387
7388 Notes: This is a very low level API. Users should not invoke it
7389 directly.
7390
7391 Args:
7392 other(Program): Other program
7393 pruned_origin_block_id_map(dict{int:int}): A dict which maps the block id in program
7394 self to the block id in program other. For example, {0:0, 1:1, 2:3} means block 0 in self is
7395 cloned from block 0 in other, etc. Default is None, which means default mapped,
7396 {0:0, 1:1,..., n:n}.
7397
7398 Returns:
7399 None
7400 """
7401 if not isinstance(other, Program):
7402 raise TypeError(
7403 f"Function Program._copy_param_info_from() needs to pass in a source Program, but received {type(other)}"
7404 )
7405
7406 if not pruned_origin_block_id_map:
7407 pruned_origin_block_id_map = {
7408 i: i for i in range(self.desc.num_blocks())
7409 }
7410
7411 # NOTE(zhiqiu): All vars in cloned program exist in original program.
7412 # The reverse is not true, due to backward pruning.
7413 for i, block in enumerate(self.blocks):
7414 other_block = other.blocks[pruned_origin_block_id_map[i]]
7415 for var in list(block.vars.values()):
7416 other_var = other_block.var(var.name)
7417 if other_var.is_data:
7418 var.is_data = True
7419 if other_var.desc.need_check_feed():
7420 var.desc.set_need_check_feed(True)
7421 if other_var.stop_gradient:
7422 var.stop_gradient = True
7423
7424 def _copy_operator_info_from(self, other: Program):
7425 """

Callers 2

cloneMethod · 0.95
_prune_with_inputMethod · 0.95

Calls 7

TypeErrorClass · 0.85
rangeFunction · 0.85
listFunction · 0.85
num_blocksMethod · 0.80
typeFunction · 0.50
valuesMethod · 0.45
varMethod · 0.45

Tested by

no test coverage detected