|
|
|
@@ -86,8 +86,8 @@ def init(backend_name=None): |
|
|
|
This method should be used after set_context. |
|
|
|
|
|
|
|
Args: |
|
|
|
backend_name (str): Backend, using HCCL/NCCL. If the `backend_name` is None, system will |
|
|
|
recognize `device_target` by devices. Default: None. |
|
|
|
backend_name (str): Backend, using HCCL/NCCL. If the `backend_name` is None, system will recognize |
|
|
|
`device_target` by devices. Default: None. |
|
|
|
|
|
|
|
Raises: |
|
|
|
TypeError: If `backend_name` is not a string. |
|
|
|
@@ -176,7 +176,7 @@ def get_rank(group=GlobalComm.WORLD_COMM_GROUP): |
|
|
|
ValueError: If backend is invalid. |
|
|
|
RuntimeError: If HCCL/NCCL is not available. |
|
|
|
|
|
|
|
>>> from mindspore.communication import init, get_rank() |
|
|
|
>>> from mindspore.communication import init, get_rank |
|
|
|
>>> init() |
|
|
|
>>> rank_id = get_rank() |
|
|
|
>>> print(rank_id) |
|
|
|
@@ -208,11 +208,12 @@ def get_local_rank(group=GlobalComm.WORLD_COMM_GROUP): |
|
|
|
RuntimeError: If HCCL is not available or MindSpore is GPU version. |
|
|
|
Examples: |
|
|
|
>>> from mindspore.context import set_context |
|
|
|
>>> from mindspore.communication.management import init, get_rank, get_local_rank |
|
|
|
>>> set_context(device_target="Ascend", device_num=16) # 2 server, each server with 8 NPU. |
|
|
|
>>> init() |
|
|
|
>>> world_rank = get_rank() # rank_id is 9. |
|
|
|
>>> local_rank = get_local_rank() |
|
|
|
>>> print("local_rank is: {}, world_rank is {}"%(local_rank, world_rank)) |
|
|
|
>>> print("local_rank is: {}, world_rank is {}".format(local_rank, world_rank)) |
|
|
|
local_rank is: 1, world_rank is 9 |
|
|
|
""" |
|
|
|
if not isinstance(group, str): |
|
|
|
@@ -238,6 +239,15 @@ def get_group_size(group=GlobalComm.WORLD_COMM_GROUP): |
|
|
|
TypeError: If group is not a string. |
|
|
|
ValueError: If backend is invalid. |
|
|
|
RuntimeError: If HCCL/NCCL is not available. |
|
|
|
|
|
|
|
Examples: |
|
|
|
>>> from mindspore.context import set_context |
|
|
|
>>> from mindspore.communication.management import init, get_group_size |
|
|
|
>>> set_context(device_target="Ascend", device_num=8) |
|
|
|
>>> init() |
|
|
|
>>> group_size = get_group_size() |
|
|
|
>>> print("group_size is: ", group_size) |
|
|
|
group_size is: 8 |
|
|
|
""" |
|
|
|
if not isinstance(group, str): |
|
|
|
raise TypeError("Group name must be a string, but got {}".format(type(group))) |
|
|
|
@@ -265,6 +275,7 @@ def get_local_rank_size(group=GlobalComm.WORLD_COMM_GROUP): |
|
|
|
RuntimeError: If HCCL is not available or MindSpore is GPU version. |
|
|
|
Examples: |
|
|
|
>>> from mindspore.context import set_context |
|
|
|
>>> from mindspore.communication.management import init, get_local_rank_size |
|
|
|
>>> set_context(device_target="Ascend", device_num=16) # 2 server, each server with 8 NPU. |
|
|
|
>>> init() |
|
|
|
>>> local_rank_size = get_local_rank_size() |
|
|
|
@@ -300,6 +311,7 @@ def get_world_rank_from_group_rank(group, group_rank_id): |
|
|
|
|
|
|
|
Examples: |
|
|
|
>>> from mindspore.context import set_context |
|
|
|
>>> from mindspore.communication.management import init, create_group, get_world_rank_from_group_rank |
|
|
|
>>> set_context(device_target="Ascend") |
|
|
|
>>> init() |
|
|
|
>>> group = "0-4" |
|
|
|
@@ -338,6 +350,7 @@ def get_group_rank_from_world_rank(world_rank_id, group): |
|
|
|
|
|
|
|
Examples: |
|
|
|
>>> from mindspore.context import set_context |
|
|
|
>>> from mindspore.communication.management import init, create_group, get_group_rank_from_world_rank |
|
|
|
>>> set_context(device_target="Ascend") |
|
|
|
>>> init() |
|
|
|
>>> group = "0-4" |
|
|
|
@@ -377,6 +390,7 @@ def create_group(group, rank_ids): |
|
|
|
Examples: |
|
|
|
>>> from mindspore.context import set_context |
|
|
|
>>> from mindspore.ops import operations as ops |
|
|
|
>>> from mindspore.communication.management import init, create_group |
|
|
|
>>> set_context(device_target="Ascend") |
|
|
|
>>> init() |
|
|
|
>>> group = "0-8" |
|
|
|
|