Skip to content

Commit

Permalink
修改COPY-FROM No.13 distributed
Browse files Browse the repository at this point in the history
Signed-off-by: jjyaoao <jjyaoao@126.com>
  • Loading branch information
jjyaoao committed Jul 21, 2023
1 parent 4384319 commit bac98db
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 13 deletions.
41 changes: 41 additions & 0 deletions python/paddle/distributed/fleet/base/role_maker.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,30 @@ def _barrier(self, comm_world):


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):
super().__init__()
self._is_collective = is_collective
Expand Down Expand Up @@ -1180,6 +1204,23 @@ def _generate_role(self):


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):
super().__init__(
is_collective=is_collective, init_gloo=init_gloo, **kwargs
Expand Down
8 changes: 5 additions & 3 deletions python/paddle/distributed/fleet/dataset/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1279,10 +1279,11 @@ class QueueDataset(DatasetBase):
QueueDataset, it will process data streamly.
Examples:
.. code-block:: python
import paddle
dataset = paddle.distributed.QueueDataset()
.. code-block:: python
import paddle
dataset = paddle.distributed.QueueDataset()
"""

Expand All @@ -1298,6 +1299,7 @@ def init(self, **kwargs):
:api_attr: Static Graph
should be called only once in user's python scripts to initialize setings of dataset instance
"""
super().init(**kwargs)

Expand Down
29 changes: 19 additions & 10 deletions python/paddle/distributed/fleet/fleet.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,11 @@ class Fleet:
Returns:
Fleet: A Fleet instance
Example for collective training:
.. code-block:: python
:name: code-example1
# Example1: for collective training
import paddle
paddle.enable_static()
import paddle.distributed.fleet as fleet
Expand All @@ -122,10 +123,11 @@ class Fleet:
# do distributed training
Example for parameter server training:
.. code-block:: python
:name: code-example2
# Example2: for parameter server training
import paddle
paddle.enable_static()
import paddle.distributed.fleet as fleet
Expand Down Expand Up @@ -195,40 +197,39 @@ def init(
Returns:
None
Examples1:
Examples:
.. code-block:: python
:name: code-example1
import paddle.distributed.fleet as fleet
fleet.init()
Examples2:
.. code-block:: python
:name: code-example2
import paddle.distributed.fleet as fleet
fleet.init(is_collective=True)
Examples3:
.. code-block:: python
:name: code-example3
import paddle.distributed.fleet as fleet
role = fleet.PaddleCloudRoleMaker()
fleet.init(role)
Examples4:
.. code-block:: python
:name: code-example4
import paddle.distributed.fleet as fleet
strategy = fleet.DistributedStrategy()
fleet.init(strategy=strategy)
Examples5:
.. code-block:: python
:name: code-example5
import paddle.distributed.fleet as fleet
strategy = fleet.DistributedStrategy()
fleet.init(log_level = "DEBUG")
Expand Down Expand Up @@ -627,6 +628,14 @@ def barrier_worker(self):
Returns:
None
Examples:
.. code-block:: python
import paddle.distributed.fleet as fleet
fleet.init()
fleet.barrier_worker()
"""
self._role_maker._barrier("worker")

Expand Down

0 comments on commit bac98db

Please sign in to comment.