mindspore.merge_sliced_parameter
- mindspore.merge_sliced_parameter(sliced_parameters, strategy=None)[source]
Merge parameter slices into one parameter. Used in the case of distributed inference. For details of it, please check: https://www.mindspore.cn/tutorials/experts/en/r1.9/parallel/save_load.html.
- Parameters
- 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 >>> import mindspore as ms >>> from mindspore import Tensor, 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 = ms.merge_sliced_parameter(sliced_parameters) >>> print(merged_parameter) Parameter (name=network.embedding_table, shape=(12,), dtype=Float64, requires_grad=True)