Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Typing][C-16] Add type annotations for python/paddle/distributed/communication/broadcast.py #66575

Merged
merged 2 commits into from
Jul 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions python/paddle/distributed/communication/broadcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations

from typing import TYPE_CHECKING, Any

import paddle
import paddle.distributed as dist
Expand All @@ -22,8 +25,15 @@
convert_tensor_to_object,
)

if TYPE_CHECKING:
from paddle import Tensor
from paddle.base.core import task
from paddle.distributed.communication.group import Group


def broadcast(tensor, src, group=None, sync_op=True):
def broadcast(
tensor: Tensor, src: int, group: Group | None = None, sync_op: bool = True
) -> task:
"""

Broadcast a tensor from the source to all others.
Expand Down Expand Up @@ -70,10 +80,12 @@ def broadcast(tensor, src, group=None, sync_op=True):
)


def broadcast_object_list(object_list, src, group=None):
def broadcast_object_list(
object_list: list[Any], src: int, group: Group | None = None
) -> None:
"""

Broadcast picklable objects from the source to all others. Similiar to broadcast(), but python object can be passed in.
Broadcast picklable objects from the source to all others. Similar to broadcast(), but python object can be passed in.

Args:
object_list (list): The list of objects to send if current rank is the source, or the list of objects to receive otherwise.
Expand Down