r"""Broadcast tensor data from root process to others. Args: inp: Input tensor. group: The process group to work on. The default group is WORLD which means all processes available. You can use a list of process ranks to create new group to work on it, e.g
(
inp: Tensor, group: Optional[Group] = WORLD, device: Optional[str] = None,
)
| 199 | |
| 200 | |
| 201 | def broadcast( |
| 202 | inp: Tensor, group: Optional[Group] = WORLD, device: Optional[str] = None, |
| 203 | ) -> Tensor: |
| 204 | r"""Broadcast tensor data from root process to others. |
| 205 | |
| 206 | Args: |
| 207 | inp: Input tensor. |
| 208 | group: The process group to work on. |
| 209 | The default group is WORLD which means all processes available. |
| 210 | You can use a list of process ranks to create new group to work on it, e.g. [1, 3, 5]. |
| 211 | device: The specific device to execute this operator. |
| 212 | None default device means the device of inp will be used. |
| 213 | Specify "gpu0:1" to execute this operator on diffrent cuda stream, |
| 214 | 1 is stream id, and default stream id is 0. |
| 215 | |
| 216 | Returns: |
| 217 | Result tensor. |
| 218 | |
| 219 | Examples: |
| 220 | |
| 221 | .. code-block:: |
| 222 | |
| 223 | input = Tensor([rank]) |
| 224 | # Rank 0 # input: Tensor([0]) |
| 225 | # Rank 1 # input: Tensor([1]) |
| 226 | output = broadcast(input) |
| 227 | # Rank 0 # output: Tensor([0]) |
| 228 | # Rank 1 # output: Tensor([0]) |
| 229 | |
| 230 | input = Tensor([rank]) |
| 231 | group = Group([1, 0]) # first rank is root |
| 232 | output = broadcast(input, group) |
| 233 | # Rank 0 # output: Tensor([1]) |
| 234 | # Rank 1 # output: Tensor([1]) |
| 235 | """ |
| 236 | shape, dtype = _bcast_shape_dtype(group, inp) |
| 237 | if group.rank != 0: |
| 238 | # dummy input to infer shape |
| 239 | inp = _dummy_input(shape, dtype, device) |
| 240 | |
| 241 | _bcast_tracer_state(group, inp) |
| 242 | |
| 243 | out = _Broadcast(group, device)(inp) |
| 244 | return out |
| 245 | |
| 246 | |
| 247 | def _bcast_param( |