Initialize parallel training environment in dynamic graph mode. Note: Now initialize both `NCCL` and `GLOO` contexts for communication. Args: backend (string): A string represents the backend used by DataParallel, should be one of 'gloo'(for cpu), 'nccl'(f
(nccl_config: NCCLConfig | None = None)
| 1001 | |
| 1002 | |
| 1003 | def init_parallel_env(nccl_config: NCCLConfig | None = None) -> Group: |
| 1004 | """ |
| 1005 | |
| 1006 | Initialize parallel training environment in dynamic graph mode. |
| 1007 | |
| 1008 | Note: |
| 1009 | Now initialize both `NCCL` and `GLOO` contexts for communication. |
| 1010 | |
| 1011 | Args: |
| 1012 | backend (string): A string represents the backend used by DataParallel, |
| 1013 | should be one of 'gloo'(for cpu), 'nccl'(for cuda), 'bkcl'(for xpu), 'auto'(auto detect). |
| 1014 | The auto detection prefer 'nccl', 'bkcl' than 'gloo'. |
| 1015 | |
| 1016 | Returns: |
| 1017 | None |
| 1018 | |
| 1019 | Examples: |
| 1020 | .. code-block:: pycon |
| 1021 | |
| 1022 | >>> # doctest: +REQUIRES(env:GPU, env:DISTRIBUTED) |
| 1023 | >>> import paddle |
| 1024 | >>> import paddle.nn as nn |
| 1025 | >>> import paddle.optimizer as opt |
| 1026 | >>> import paddle.distributed as dist |
| 1027 | |
| 1028 | >>> class LinearNet(nn.Layer): |
| 1029 | ... def __init__(self): |
| 1030 | ... super().__init__() |
| 1031 | ... self._linear1 = nn.Linear(10, 10) |
| 1032 | ... self._linear2 = nn.Linear(10, 1) |
| 1033 | ... |
| 1034 | ... def forward(self, x): |
| 1035 | ... return self._linear2(self._linear1(x)) |
| 1036 | |
| 1037 | >>> def train(): |
| 1038 | ... # 1. initialize parallel environment |
| 1039 | ... dist.init_parallel_env() |
| 1040 | ... # 2. create data parallel layer & optimizer |
| 1041 | ... layer = LinearNet() |
| 1042 | ... dp_layer = paddle.DataParallel(layer) |
| 1043 | ... loss_fn = nn.MSELoss() |
| 1044 | ... adam = opt.Adam(learning_rate=0.001, parameters=dp_layer.parameters()) |
| 1045 | ... # 3. run layer |
| 1046 | ... inputs = paddle.randn([10, 10], 'float32') |
| 1047 | ... outputs = dp_layer(inputs) |
| 1048 | ... labels = paddle.randn([10, 1], 'float32') |
| 1049 | ... loss = loss_fn(outputs, labels) |
| 1050 | ... loss.backward() |
| 1051 | ... adam.step() |
| 1052 | ... adam.clear_grad() |
| 1053 | |
| 1054 | >>> if __name__ == '__main__': |
| 1055 | ... dist.spawn(train) |
| 1056 | |
| 1057 | """ |
| 1058 | |
| 1059 | modified_flags = _get_modified_flags() |
| 1060 | _print_modified_flags(modified_flags) |
nothing calls this directly
no test coverage detected