parameters: (self, block=None, rank=None, name=None)
return_statement: return local_tensor
docstring: Create a new local tensor of serial tensor corresponding to rank.
  
          Args:
              block (Block): The block contains the new tensor. Default value is recommend and it will be created in the block of dist main program corresponding to the serial tensor block id. Default: None.
              rank (int): The rank id. Default value is recommend and it will be the current rank. Default: None.
docstring_summary: Create a new local tensor of serial tensor corresponding to rank.
docstring_tokens: Create a new local tensor of serial tensor corresponding to rank .
function: def new_local_tensor(self, block=None, rank=None, name=None):
          """
          Create a new local tensor of serial tensor corresponding to rank.
  
          Args:
              block (Block): The block contains the new tensor. Default value is recommend and it will be created in the block of dist main program corresponding to the serial tensor block id. Default: None.
              rank (int): The rank id. Default value is recommend and it will be the current rank. Default: None.
          """
  
          def _copy_kwargs(serial_tensor):
              kwargs = {}
              no_need_copy_args = ["self", "block", "shape", "name"]
              arg_spec = inspect.getargspec(Variable.__init__)
  
              for key in arg_spec.args:
                  # TODO: Check the copied attribute from serial tensor whether valid
                  if key in no_need_copy_args:
                      continue
                  elif key not in kwargs:
                      if key == "type":
                          kwargs[key] = serial_tensor.desc.type()
                      elif key == "dtype":
                          kwargs[key] = serial_tensor.desc.dtype()
                      elif key == "lod_level":
                          kwargs[key] = serial_tensor.desc.lod_level()
                      elif key == "persistable":
                          kwargs[key] = serial_tensor.desc.persistable()
                      elif key == "stop_gradient":
                          kwargs[key] = serial_tensor.desc.stop_gradient()
                      elif key == "need_check_feed":
                          kwargs[key] = serial_tensor.desc.need_check_feed()
                      # TODO: Get capacity by framework
                      elif key == "capacity":
                          continue
                      else:
                          kwargs[key] = self.serial_tensor.__dict__[key]
  
              if isinstance(serial_tensor, Parameter):
                  kwargs["trainable"] = serial_tensor.trainable
                  kwargs["optimize_attr"] = serial_tensor.trainable
                  kwargs["regularizer"] = serial_tensor.regularizer
                  kwargs["do_model_average"] = serial_tensor.do_model_average
                  kwargs["need_clip"] = serial_tensor.need_clip
                  kwargs["is_distributed"] = serial_tensor.is_distributed
                  kwargs["is_parameter"] = serial_tensor.is_parameter
  
              return kwargs
  
          if rank is not None and not (isinstance(rank, int) and rank >= 0):
              raise ValueError("The rank must >= 0, but got {}".format(rank))
          if block is not None and not isinstance(block, Block):
              raise TypeError("The block must be Block, but got {}.".format(
                  type(block)))
          rank = paddle.distributed.get_rank() if rank is None else rank
  
          if block is None:
              block_id = self.serial_tensor.block.idx
              block = self.dist_context.dist_main_programs[rank].block(block_id)
  
          # copy serial tensor attribute
          kwargs = _copy_kwargs(self.serial_tensor)
          kwargs["name"] = name
          kwargs["shape"] = self.local_sizes(rank)
  
          if isinstance(self.serial_tensor, Parameter):
              kwargs.pop("persistable")
              local_tensor = Parameter(block=block, **kwargs)
          else:
              local_tensor = block.create_var(**kwargs)
  
          # TODO: Set original id when set original_id is approved
          local_tensor.desc.set_original_id(self.serial_tensor.desc.id())
          self._local_tensor_map[rank] = local_tensor
          return local_tensor
function_tokens: def new_local_tensor ( self , block = None , rank = None , name = None ) : def _copy_kwargs ( serial_tensor ) : kwargs = { } no_need_copy_args = [ "self" , "block" , "shape" , "name" ] arg_spec = inspect . getargspec ( Variable . __init__ ) for key in arg_spec . args : # TODO: Check the copied attribute from serial tensor whether valid if key in no_need_copy_args : continue elif key not in kwargs : if key == "type" : kwargs [ key ] = serial_tensor . desc . type ( ) elif key == "dtype" : kwargs [ key ] = serial_tensor . desc . dtype ( ) elif key == "lod_level" : kwargs [ key ] = serial_tensor . desc . lod_level ( ) elif key == "persistable" : kwargs [ key ] = serial_tensor . desc . persistable ( ) elif key == "stop_gradient" : kwargs [ key ] = serial_tensor . desc . stop_gradient ( ) elif key == "need_check_feed" : kwargs [ key ] = serial_tensor . desc . need_check_feed ( ) # TODO: Get capacity by framework elif key == "capacity" : continue else : kwargs [ key ] = self . serial_tensor . __dict__ [ key ] if isinstance ( serial_tensor , Parameter ) : kwargs [ "trainable" ] = serial_tensor . trainable kwargs [ "optimize_attr" ] = serial_tensor . trainable kwargs [ "regularizer" ] = serial_tensor . regularizer kwargs [ "do_model_average" ] = serial_tensor . do_model_average kwargs [ "need_clip" ] = serial_tensor . need_clip kwargs [ "is_distributed" ] = serial_tensor . is_distributed kwargs [ "is_parameter" ] = serial_tensor . is_parameter return kwargs if rank is not None and not ( isinstance ( rank , int ) and rank >= 0 ) : raise ValueError ( "The rank must >= 0, but got {}" . format ( rank ) ) if block is not None and not isinstance ( block , Block ) : raise TypeError ( "The block must be Block, but got {}." . format ( type ( block ) ) ) rank = paddle . distributed . get_rank ( ) if rank is None else rank if block is None : block_id = self . serial_tensor . block . idx block = self . dist_context . dist_main_programs [ rank ] . block ( block_id ) # copy serial tensor attribute kwargs = _copy_kwargs ( self . serial_tensor ) kwargs [ "name" ] = name kwargs [ "shape" ] = self . local_sizes ( rank ) if isinstance ( self . serial_tensor , Parameter ) : kwargs . pop ( "persistable" ) local_tensor = Parameter ( block = block , * * kwargs ) else : local_tensor = block . create_var ( * * kwargs ) # TODO: Set original id when set original_id is approved local_tensor . desc . set_original_id ( self . serial_tensor . desc . id ( ) ) self . _local_tensor_map [ rank ] = local_tensor return local_tensor