mindspore.mint.distributed.get_group_rank
- mindspore.mint.distributed.get_group_rank(group, global_rank)[source]
Get the rank ID in the specified user communication group corresponding to the rank ID in the world communication group.
Note
This method should be used after mindspore.mint.distributed.init_process_group.
- Parameters
- Returns
int, the rank ID in the user communication group.
- Raises
TypeError – If global_rank is not an integer or the group is not a string.
RuntimeError – If device target is invalid, or backend is invalid, or distributed initialization fails.
- Supported Platforms:
Ascend
Examples
Note
Before running the following examples, you need to configure the communication environment variables.
For Ascend 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.
This example should be run with 8 devices.
>>> from mindspore import set_context >>> from mindspore.mint.distributed import init_process_group, new_group, get_group_rank, get_rank >>> set_context(device_target="Ascend") >>> # Launch 8 processes. >>> init_process_group() >>> rank_ids = [0,4] >>> if get_rank() in rank_ids: ... group = new_group(rank_ids) ... group_rank_id = get_group_rank(group, 4) ... print("group_rank_id is: ", group_rank_id) #rank 0 and 4: group_rank_id is: 1