parameters: (sliced_parameters, strategy=None)
return_statement: return merged_parameter
docstring: Merge parameter slices into one parameter. Used in the case of distributed inference.
      For details of it, please check:
      `<https://www.mindspore.cn/docs/programming_guide/en/master/save_load_model_hybrid_parallel.html>`_.
  
      Args:
          sliced_parameters (list[Parameter]): Parameter slices in order of rank id.
          strategy (Optional[dict]): Parameter slice strategy, whose key is parameter name and
              value is slice strategy of this parameter. If strategy is None, just merge
              parameter slices in 0 axis order. Default: None.
  
      Returns:
          Parameter, the merged parameter which has the whole data.
  
      Raises:
          ValueError: Failed to merge.
          TypeError: The sliced_parameters is incorrect or strategy is not dict.
          KeyError: The parameter name is not in keys of strategy.
  
      Examples:
          >>> import numpy as np
          >>> from mindspore import Tensor, merge_sliced_parameter, Parameter
          >>>
          >>> sliced_parameters = [
          ...                      Parameter(Tensor(np.array([0.00023915, 0.00013939, -0.00098059])),
          ...                                "network.embedding_table"),
          ...                      Parameter(Tensor(np.array([0.00015815, 0.00015458, -0.00012125])),
          ...                                "network.embedding_table"),
          ...                      Parameter(Tensor(np.array([0.00042165, 0.00029692, -0.00007941])),
          ...                                "network.embedding_table"),
          ...                      Parameter(Tensor(np.array([0.00084451, 0.00089960, -0.00010431])),
          ...                                "network.embedding_table")]
          >>> merged_parameter = merge_sliced_parameter(sliced_parameters)
          >>> print(merged_parameter)
          Parameter (name=network.embedding_table, shape=(12,), dtype=Float64, requires_grad=True)
docstring_summary: Merge parameter slices into one parameter. Used in the case of distributed inference.
      For details of it, please check:
      `<https://www.mindspore.cn/docs/programming_guide/en/master/save_load_model_hybrid_parallel.html>`_.
docstring_tokens: Merge parameter slices into one parameter . Used in the case of distributed inference . For details of it please check : <https : // www . mindspore . cn / docs / programming_guide / en / master / save_load_model_hybrid_parallel . html > _ .
function: def merge_sliced_parameter(sliced_parameters, strategy=None):
      """
      Merge parameter slices into one parameter. Used in the case of distributed inference.
      For details of it, please check:
      `<https://www.mindspore.cn/docs/programming_guide/en/master/save_load_model_hybrid_parallel.html>`_.
  
      Args:
          sliced_parameters (list[Parameter]): Parameter slices in order of rank id.
          strategy (Optional[dict]): Parameter slice strategy, whose key is parameter name and
              value is slice strategy of this parameter. If strategy is None, just merge
              parameter slices in 0 axis order. Default: None.
  
      Returns:
          Parameter, the merged parameter which has the whole data.
  
      Raises:
          ValueError: Failed to merge.
          TypeError: The sliced_parameters is incorrect or strategy is not dict.
          KeyError: The parameter name is not in keys of strategy.
  
      Examples:
          >>> import numpy as np
          >>> from mindspore import Tensor, merge_sliced_parameter, Parameter
          >>>
          >>> sliced_parameters = [
          ...                      Parameter(Tensor(np.array([0.00023915, 0.00013939, -0.00098059])),
          ...                                "network.embedding_table"),
          ...                      Parameter(Tensor(np.array([0.00015815, 0.00015458, -0.00012125])),
          ...                                "network.embedding_table"),
          ...                      Parameter(Tensor(np.array([0.00042165, 0.00029692, -0.00007941])),
          ...                                "network.embedding_table"),
          ...                      Parameter(Tensor(np.array([0.00084451, 0.00089960, -0.00010431])),
          ...                                "network.embedding_table")]
          >>> merged_parameter = merge_sliced_parameter(sliced_parameters)
          >>> print(merged_parameter)
          Parameter (name=network.embedding_table, shape=(12,), dtype=Float64, requires_grad=True)
      """
      if not isinstance(sliced_parameters, list):
          raise TypeError(f"For 'merge_sliced_parameter', the 'sliced_parameters' should be list, "
                          f"but got {type(sliced_parameters)}.")
  
      if not sliced_parameters:
          raise ValueError("For 'merge_sliced_parameter', the 'sliced_parameters' should not be empty.")
  
      if strategy and not isinstance(strategy, dict):
          raise TypeError(f"For 'merge_sliced_parameter', the 'strategy' should be dict, but got {type(strategy)}.")
  
      try:
          parameter_name = sliced_parameters[0].name
          parameter_shape = sliced_parameters[0].data.shape
          parameter_shape_length = len(parameter_shape)
      except BaseException as e:
          raise TypeError(e.__str__() + f" For 'merge_sliced_parameter', the element in 'sliced_parameters' should be "
                                        f"'Parameter', but got {type(sliced_parameters[0])} at index 0.")
  
      is_even = True
      for index, parameter in enumerate(sliced_parameters):
          if not isinstance(parameter, Parameter):
              raise TypeError(f"For 'merge_sliced_parameter', the element in 'sliced_parameters' should be 'Parameter', "
                              f"but got {type(parameter)} at index {index}.")
  
          if parameter.name != parameter_name \
                  or len(parameter.data.shape) != parameter_shape_length \
                  or parameter.data.shape[1:] != parameter_shape[1:]:
              raise ValueError(f"For 'merge_sliced_parameter', please make sure that the elements in 'slice_parameters'"
                               f" have the same name, dimension length and shape except 0 axis. The name, dimension "
                               f"length, shape except 0 axis should be {parameter_name}, {parameter_shape_length}, "
                               f"{parameter_shape[1:]}, but got name: {parameter.name}, dimension length: "
                               f"{len(parameter.data.shape)}, shape except 0 axis: {parameter.data.shape[1:]} "
                               f"at index {index}.")
  
          if parameter.data.shape != parameter_shape:
              is_even = False
  
      layerwise_parallel = sliced_parameters[0].layerwise_parallel
      requires_grad = sliced_parameters[0].requires_grad
      sliced_data = [parameter.data.asnumpy() for parameter in sliced_parameters]
  
      if not strategy:
          merged_tensor = Tensor(np.concatenate(sliced_data))
          merged_parameter = Parameter(merged_tensor, parameter_name, requires_grad, layerwise_parallel)
  
      else:
          if parameter_name not in strategy.keys():
              raise KeyError(f"For 'merge_sliced_parameter', the parameter name {parameter_name} should be a key in "
                             f"the 'strategy'. Please check 'sliced_parameter' and 'strategy'.")
          merged_tensor = _merge_param_with_strategy(sliced_data, parameter_name, strategy, is_even)
          merged_parameter = Parameter(merged_tensor, parameter_name, requires_grad, layerwise_parallel)
  
      return merged_parameter
function_tokens: def merge_sliced_parameter ( sliced_parameters , strategy = None ) : if not isinstance ( sliced_parameters , list ) : raise TypeError ( f"For 'merge_sliced_parameter', the 'sliced_parameters' should be list, " f"but got {type(sliced_parameters)}." ) if not sliced_parameters : raise ValueError ( "For 'merge_sliced_parameter', the 'sliced_parameters' should not be empty." ) if strategy and not isinstance ( strategy , dict ) : raise TypeError ( f"For 'merge_sliced_parameter', the 'strategy' should be dict, but got {type(strategy)}." ) try : parameter_name = sliced_parameters [ 0 ] . name parameter_shape = sliced_parameters [ 0 ] . data . shape parameter_shape_length = len ( parameter_shape ) except BaseException as e : raise TypeError ( e . __str__ ( ) + f" For 'merge_sliced_parameter', the element in 'sliced_parameters' should be " f"'Parameter', but got {type(sliced_parameters[0])} at index 0." ) is_even = True for index , parameter in enumerate ( sliced_parameters ) : if not isinstance ( parameter , Parameter ) : raise TypeError ( f"For 'merge_sliced_parameter', the element in 'sliced_parameters' should be 'Parameter', " f"but got {type(parameter)} at index {index}." ) if parameter . name != parameter_name or len ( parameter . data . shape ) != parameter_shape_length or parameter . data . shape [ 1 : ] != parameter_shape [ 1 : ] : raise ValueError ( f"For 'merge_sliced_parameter', please make sure that the elements in 'slice_parameters'" f" have the same name, dimension length and shape except 0 axis. The name, dimension " f"length, shape except 0 axis should be {parameter_name}, {parameter_shape_length}, " f"{parameter_shape[1:]}, but got name: {parameter.name}, dimension length: " f"{len(parameter.data.shape)}, shape except 0 axis: {parameter.data.shape[1:]} " f"at index {index}." ) if parameter . data . shape != parameter_shape : is_even = False layerwise_parallel = sliced_parameters [ 0 ] . layerwise_parallel requires_grad = sliced_parameters [ 0 ] . requires_grad sliced_data = [ parameter . data . asnumpy ( ) for parameter in sliced_parameters ] if not strategy : merged_tensor = Tensor ( np . concatenate ( sliced_data ) ) merged_parameter = Parameter ( merged_tensor , parameter_name , requires_grad , layerwise_parallel ) else : if parameter_name not in strategy . keys ( ) : raise KeyError ( f"For 'merge_sliced_parameter', the parameter name {parameter_name} should be a key in " f"the 'strategy'. Please check 'sliced_parameter' and 'strategy'." ) merged_tensor = _merge_param_with_strategy ( sliced_data , parameter_name , strategy , is_even ) merged_parameter = Parameter ( merged_tensor , parameter_name , requires_grad , layerwise_parallel ) return merged_parameter