未验证 提交 38fbbe6b 编写于 作者: J jjyaoao 提交者: GitHub

修改COPY-FROM No.13 distributed (#55236)

Signed-off-by: Njjyaoao <jjyaoao@126.com>
上级 0f0dfe9a
...@@ -546,6 +546,30 @@ class RoleMakerBase: ...@@ -546,6 +546,30 @@ class RoleMakerBase:
class PaddleCloudRoleMaker(RoleMakerBase): class PaddleCloudRoleMaker(RoleMakerBase):
"""
PaddleCloudRoleMaker is an interface for distributed configuration initialization based on obtaining distributed related information from environment variables.
Examples:
.. code-block:: python
import os
import paddle.distributed.fleet as fleet
os.environ["PADDLE_PSERVER_NUMS"] = "2"
os.environ["PADDLE_TRAINERS_NUM"] = "2"
os.environ["POD_IP"] = "127.0.0.1"
os.environ["PADDLE_PORT"] = "36001"
os.environ["TRAINING_ROLE"] = "PSERVER"
os.environ["PADDLE_PSERVERS_IP_PORT_LIST"] = "127.0.0.1:36001,127.0.0.2:36001"
os.environ["PADDLE_TRAINER_ID"] = "0"
fleet.PaddleCloudRoleMaker(is_collective=False)
"""
def __init__(self, is_collective=False, **kwargs): def __init__(self, is_collective=False, **kwargs):
super().__init__() super().__init__()
self._is_collective = is_collective self._is_collective = is_collective
...@@ -1184,6 +1208,23 @@ class PaddleCloudRoleMaker(RoleMakerBase): ...@@ -1184,6 +1208,23 @@ class PaddleCloudRoleMaker(RoleMakerBase):
class UserDefinedRoleMaker(PaddleCloudRoleMaker): class UserDefinedRoleMaker(PaddleCloudRoleMaker):
"""
UserDefinedRoleMaker is an interface for distributed configuration initialization based on obtaining distributed related information from user-defined parameters.
Examples:
.. code-block:: python
import paddle.distributed.fleet as fleet
from paddle.distributed.fleet.base.role_maker import Role
fleet.UserDefinedRoleMaker(
current_id=0,
role=Role.SERVER,
worker_num=2,
server_endpoints=["127.0.0.1:36011", "127.0.0.1:36012"])
"""
def __init__(self, is_collective=False, init_gloo=False, **kwargs): def __init__(self, is_collective=False, init_gloo=False, **kwargs):
super().__init__( super().__init__(
is_collective=is_collective, init_gloo=init_gloo, **kwargs is_collective=is_collective, init_gloo=init_gloo, **kwargs
......
...@@ -1279,10 +1279,11 @@ class QueueDataset(DatasetBase): ...@@ -1279,10 +1279,11 @@ class QueueDataset(DatasetBase):
QueueDataset, it will process data streamly. QueueDataset, it will process data streamly.
Examples: Examples:
.. code-block:: python
import paddle .. code-block:: python
dataset = paddle.distributed.QueueDataset()
import paddle
dataset = paddle.distributed.QueueDataset()
""" """
...@@ -1298,6 +1299,7 @@ class QueueDataset(DatasetBase): ...@@ -1298,6 +1299,7 @@ class QueueDataset(DatasetBase):
:api_attr: Static Graph :api_attr: Static Graph
should be called only once in user's python scripts to initialize setings of dataset instance should be called only once in user's python scripts to initialize setings of dataset instance
""" """
super().init(**kwargs) super().init(**kwargs)
......
...@@ -105,10 +105,11 @@ class Fleet: ...@@ -105,10 +105,11 @@ class Fleet:
Returns: Returns:
Fleet: A Fleet instance Fleet: A Fleet instance
Example for collective training:
.. code-block:: python .. code-block:: python
:name: code-example1
# Example1: for collective training
import paddle import paddle
paddle.enable_static() paddle.enable_static()
import paddle.distributed.fleet as fleet import paddle.distributed.fleet as fleet
...@@ -122,10 +123,11 @@ class Fleet: ...@@ -122,10 +123,11 @@ class Fleet:
# do distributed training # do distributed training
Example for parameter server training:
.. code-block:: python .. code-block:: python
:name: code-example2
# Example2: for parameter server training
import paddle import paddle
paddle.enable_static() paddle.enable_static()
import paddle.distributed.fleet as fleet import paddle.distributed.fleet as fleet
...@@ -195,40 +197,39 @@ class Fleet: ...@@ -195,40 +197,39 @@ class Fleet:
Returns: Returns:
None None
Examples1: Examples:
.. code-block:: python .. code-block:: python
:name: code-example1
import paddle.distributed.fleet as fleet import paddle.distributed.fleet as fleet
fleet.init() fleet.init()
Examples2:
.. code-block:: python .. code-block:: python
:name: code-example2
import paddle.distributed.fleet as fleet import paddle.distributed.fleet as fleet
fleet.init(is_collective=True) fleet.init(is_collective=True)
Examples3:
.. code-block:: python .. code-block:: python
:name: code-example3
import paddle.distributed.fleet as fleet import paddle.distributed.fleet as fleet
role = fleet.PaddleCloudRoleMaker() role = fleet.PaddleCloudRoleMaker()
fleet.init(role) fleet.init(role)
Examples4:
.. code-block:: python .. code-block:: python
:name: code-example4
import paddle.distributed.fleet as fleet import paddle.distributed.fleet as fleet
strategy = fleet.DistributedStrategy() strategy = fleet.DistributedStrategy()
fleet.init(strategy=strategy) fleet.init(strategy=strategy)
Examples5:
.. code-block:: python .. code-block:: python
:name: code-example5
import paddle.distributed.fleet as fleet import paddle.distributed.fleet as fleet
strategy = fleet.DistributedStrategy() strategy = fleet.DistributedStrategy()
fleet.init(log_level = "DEBUG") fleet.init(log_level = "DEBUG")
...@@ -627,6 +628,14 @@ class Fleet: ...@@ -627,6 +628,14 @@ class Fleet:
Returns: Returns:
None None
Examples:
.. code-block:: python
import paddle.distributed.fleet as fleet
fleet.init()
fleet.barrier_worker()
""" """
self._role_maker._barrier("worker") self._role_maker._barrier("worker")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册