/usr/local/lib64/python3.6/site-packages/torch/distributed/nn/__pycache__
NameSizeModeActions
functional.cpython-36.pyc91660644editdlrm
__init__.cpython-36.pyc2370644editdlrm
Edit: /usr/local/lib64/python3.6/site-packages/torch/distributed/nn/__pycache__/functional.cpython-36.pyc (9166B)
3 Eg@sddlZddlmZddljZejjfddZdejjfddZ dejjfddZ ej j ejjfd d Z ejjfd d Zejjfd dZej j ejjfddZGdddeZGdddeZGdddeZGdddeZGdddeZGdddeZGdddeZdS)N)FunctioncCstj|||S)a Broadcasts the tensor to the whole group. ``tensor`` must have the same number of elements in all processes participating in the collective. Arguments: tensor (Tensor): Data to be sent if ``src`` is the rank of current process. src (int): Source rank. group (ProcessGroup, optional): The process group to work on. Returns: Tensor: Received tensor from the broadcast op. ) _Broadcastapply)tensorsrcgrouprK/usr/local/lib64/python3.6/site-packages/torch/distributed/nn/functional.py broadcastsr cCstj|||S)aT Gathers a list of tensors in a single process. Arguments: tensor (Tensor): Input tensor. dst (int, optional): Destination rank (default is 0). group (ProcessGroup, optional): The process group to work on. Returns: tuple[Tensor]: List of appropriately-sized tensors with the gathered data. )_Gatherr)rdstrrrr gathers r cCstj||f|S)a Scatters a list of tensors to all processes in a group. Each process will receive exactly one tensor and store its data in the ``tensor`` argument. Arguments: tensors (list[Tensor]): List of tensors to scatter on the source rank. Receivers must pass ``None`. src (int, optional): Source rank (default is 0). group (ProcessGroup, optional): The process group to work on. Returns: Tensor: Output tensor from the scatter operation. )_Scatterr)tensorsrrrrr scatter)srcCstj||||S)a Reduces the tensor data across all machines. Only the process with rank ``dst`` is going to receive the final result. Arguments: tensor (Tensor): Input of the collective. dst (int): Destination rank. op (optional): One of the values from ``torch.distributed.ReduceOp`` enum. Specifies an operation used for element-wise reductions. group (ProcessGroup, optional): The process group to work on. Returns: Tensor: Output of the collective. )_Reducer)rr oprrrr reduce=srcCs tj||S)a Gathers tensors from the whole group in a list. Arguments: tensor (Tensor): Tensor to be broadcast from current process. group (ProcessGroup, optional): The process group to work on. Returns: tuple[Tensor]): Output of the collective. ) _AllGatherr)rrrrr all_gatherRs rcCstj|f|S)ai Each process scatters list of input tensors to all processes in a group and return gathered list of tensors in output list. Arguments: tensors (list[Tensor]): List of tensors to scatter one per rank. group (ProcessGroup, optional): The process group to work on. Returns: tuple[Tensor]): Output of the collective. ) _AlltoAllr)rrrrr all_to_allas rcCstj|||S)a* Reduces the tensor data across all machines in such a way that all get the final result. After the call the returned tensor is going to be bitwise identical in all processes. Arguments: tensor (Tensor): Input of the collective. op (optional): One of the values from ``torch.distributed.ReduceOp`` enum. Specifies an operation used for element-wise reductions. group (ProcessGroup, optional): The process group to work on. Returns: Tensor: Output of the collective ) _AllReducer)rrrrrr all_reduceqsrc@s$eZdZeddZeddZdS)rcCs2||_||_tj|_|j}tj|||d|S)N)r)rrdistget_rankrankcloner )ctxrrrrrr forwards  z_Broadcast.forwardcCs6tj|jtjj|j|}|j|jkr,|jdd|fS)N) rrrrReduceOpSUMrrZzero_)r grad_outputgxrrr backwards z_Broadcast.backwardN)__name__ __module__ __qualname__ staticmethodrr$rrrr rs rc@s$eZdZeddZeddZdS)r csh||_||_fddttj|dD}tj|d|krNtj|||dntjd||dt|S)Ncsg|]}tjqSr)torch zeros_like).0i)rrr sz#_Gather.forward..)r)r rrangerget_world_sizerr tuple)rr rrZ tensor_listr)rr rsz_Gather.forwardcGsdtj|j|jf|fS)N)NN)rrr r)r grad_outputsrrr r$sz_Gather.backwardN)r%r&r'r(rr$rrrr r s r c@s$eZdZeddZeddZdS)rcsr||_||_tfddDs&ttjd}tj|d|kr\tj|t ||dntj|d||d|S)Nc3s"|]}|jdjkVqdS)rN)size)r+t)rrr sz#_Scatter.forward..r)r) rrallAssertionErrorr)r*rrrlist)rrrroutputr)rr rsz_Scatter.forwardcCsdtj|j|j|S)N)NN)r rrr)rr"rrr r$sz_Scatter.backwardN)r%r&r'r(rr$rrrr rs rc@s$eZdZeddZeddZdS)rcCs*||_||_|j}tj||||d|S)N)rr)rrrrr)rrrrrrrr rs z_Reduce.forwardcCsdtj|j|j|fS)N)NNN)rrrr)rr"rrr r$sz_Reduce.backwardN)r%r&r'r(rr$rrrr rs rc@s$eZdZeddZeddZdS)rcs<||_fddttj|dD}tj||dt|S)Ncsg|]}tjqSr)r) empty_like)r+r,)rrr r-sz&_AllGather.forward..)r)rr.rr/rr0)rrrout_tensor_listr)rr rsz_AllGather.forwardcGs.tj|jf|}tjtj|dd}d|fS)Nr)Zdim)rrrr)sumstack)rr1Zgxsr#rrr r$sz_AllGather.backwardN)r%r&r'r(rr$rrrr rs rc@s$eZdZeddZeddZdS)rcs||_fddttj|dD}dgtj|d}tj|d}tj|dtjjkrxXttj|dD].}d}||krt}tj |||||dqhWntj |t|dt |S)Ncsg|]}tj|qSr)r)r9)r+r,)rrr r-sz%_AlltoAll.forward..)r) rr.rr/r get_backendZBackendZGLOOr7rrr0)rrrr:reqsZmy_rankr,to_sendr)rr rs z_AlltoAll.forwardcGsdtj|jf|S)N)N)rrr)rr1rrr r$sz_AlltoAll.backwardN)r%r&r'r(rr$rrrr rs rc@s$eZdZeddZeddZdS)rcCs(||_||_|j}tj|||d|S)N)rr)rrrrr)rrrrrrr rs z_AllReduce.forwardcCsdtj|j|j|fS)N)NN)rrrr)rr"rrr r$sz_AllReduce.backwardN)r%r&r'r(rr$rrrr rs r)r)Ztorch.autogradrZtorch.distributedZ distributedrrZWORLDr r rr r!rrrrrr rrrrrrrrr s