mindspore.communication.get_group_rank_from_world_rank
- mindspore.communication.get_group_rank_from_world_rank(world_rank_id, group)[source]
Get the rank ID in the specified user communication group corresponding to the rank ID in the world communication group.
Note
This method isn't supported in GPU and CPU versions of MindSpore. The parameter group should not be "hccl_world_group". This method should be used after init().
- Parameters
- Returns
int, the rank ID in the user communication group.
- Raises
TypeError – If world_rank_id is not an integer or the group is not a string.
ValueError – If group is 'hccl_world_group' or backend is invalid.
RuntimeError – If HCCL is not available or MindSpore is GPU/CPU version.
- Supported Platforms:
Ascend
GPU
CPU
Examples
Note
Before running the following examples, you need to configure the communication environment variables.
For Ascend/GPU/CPU devices, it is recommended to use the msrun startup method without any third-party or configuration file dependencies. Please see the msrun start up for more details.
>>> import mindspore as ms >>> from mindspore import set_context >>> from mindspore.communication import init, create_group, get_group_rank_from_world_rank, get_rank >>> set_context(mode=ms.GRAPH_MODE) >>> ms.set_device(device_target="Ascend") >>> init() >>> group = "0-4" >>> rank_ids = [0,4] >>> if get_rank() in rank_ids: ... create_group(group, rank_ids) ... group_rank_id = get_group_rank_from_world_rank(4, group) ... print("group_rank_id is: ", group_rank_id) group_rank_id is: 1