/usr/local/lib64/python3.6/site-packages/torch/nn/parallel/__pycache__
NameSizeModeActions
comm.cpython-36.pyc104660644editdlrm
data_parallel.cpython-36.pyc96340644editdlrm
distributed.cpython-36.pyc563480644editdlrm
parallel_apply.cpython-36.pyc29420644editdlrm
replicate.cpython-36.pyc45100644editdlrm
scatter_gather.cpython-36.pyc34900644editdlrm
_functions.cpython-36.pyc57950644editdlrm
__init__.cpython-36.pyc7760644editdlrm
Edit: /usr/local/lib64/python3.6/site-packages/torch/nn/parallel/__pycache__/comm.cpython-36.pyc (10466B)
3 Eg$*@sddlZddlZddlmZddlmZmZmZmZm Z m Z ddl m Z dddddZ dd d Zdd d Zdd dZdddddZdddddZdS)N)nccl) _take_tensors_flatten_dense_tensors_unflatten_dense_tensors_reorder_tensors_as_get_device_index_handle_complex)List)outcCs^t|}|dk|dkAs(tdj|||dk rLdd|D}tjj||Stjj||SdS)aBroadcasts a tensor to specified GPU devices. Args: tensor (Tensor): tensor to broadcast. Can be on CPU or GPU. devices (Iterable[torch.device, str or int], optional): an iterable of GPU devices, among which to broadcast. out (Sequence[Tensor], optional, keyword-only): the GPU tensors to store output results. .. note:: Exactly one of :attr:`devices` and :attr:`out` must be specified. Returns: - If :attr:`devices` is specified, a tuple containing copies of :attr:`tensor`, placed on :attr:`devices`. - If :attr:`out` is specified, a tuple containing :attr:`out` tensors, each containing a copy of :attr:`tensor`. NzSExactly one of 'devices' and 'out' must be specified, but got devices={} and out={}cSsg|] }t|qS)r).0dr r B/usr/local/lib64/python3.6/site-packages/torch/nn/parallel/comm.py #szbroadcast..)r RuntimeErrorformattorch_CZ _broadcastZ_broadcast_out)tensordevicesr r r r broadcasts rcCs,dd|D}dd|D}tjj|||S)a/Broadcasts a sequence tensors to the specified GPUs. Small tensors are first coalesced into a buffer to reduce the number of synchronizations. Args: tensors (sequence): tensors to broadcast. Must be on the same device, either CPU or GPU. devices (Iterable[torch.device, str or int]): an iterable of GPU devices, among which to broadcast. buffer_size (int): maximum size of the buffer used for coalescing Returns: A tuple containing copies of :attr:`tensor`, placed on :attr:`devices`. cSsg|] }t|qSr )r)r r r r rr8sz'broadcast_coalesced..cSsg|] }t|qSr )r)r tr r rr9s)rrZ_broadcast_coalesced)tensorsr buffer_sizer r rbroadcast_coalesced)src sbt|dd}|dj}dxt|D]v\}}|jjdksBtd|j|krR||j|kr&djdd |jD}djd d |D}td j |||q&Wdkrt d t |d kr|dSt j |rtj|}t j||dnptj|jj|}fddt|D} || dj|dd}x*| d dD]} |j| j|ddq@W|S)aSums tensors from multiple GPUs. All inputs should have matching shapes, dtype, and layout. The output tensor will be of the same shape, dtype, and layout. Args: inputs (Iterable[Tensor]): an iterable of tensors to add. destination (int, optional): a device on which the output will be placed (default: current device). Returns: A tensor containing an elementwise sum of all inputs, placed on the :attr:`destination` device. T)optionalrNcpuz+reduce_add expects all inputs to be on GPUsxcss|]}t|VqdS)N)str)r rr r r Tszreduce_add..css|]}t|VqdS)N)r)r rr r rr Usz2input {} has invalid size: got {}, but expected {}zLreduce_add expects destination to be on the same GPU with one of the tensors)outputrootcsg|]\}}|kr|qSr r )r ir) root_indexr rrcszreduce_add..)deviceZ non_blocking)rsize enumerater&typeAssertionErrorZ get_devicejoin ValueErrorrrlenrZ is_availablerZ empty_likereduceZtoZadd_) inputs destinationZ input_sizer$inpgotexpectedresultZdestination_deviceZnonroototherr )r%r reduce_add=s2      r6csdd|D}g}g}xt|D]|}tdd|DrZt||}|j||j|dq x.t||D] \}} |j| jr| jn| qfW|j|dd q Wfdd|D} xLt| D]@} dd| D} t| |} x"t| | dD]} |j| jqWqWtt ||S) a]Sums tensors from multiple GPUs. Small tensors are first coalesced into a buffer to reduce the number of synchronizations. Args: inputs (Iterable[Iterable[Tensor]]): iterable of iterables that contain tensors from a single device. destination (int, optional): a device on which the output will be placed (default: current device). buffer_size (int): maximum size of the buffer used for coalescing Returns: A tuple of tensors containing an elementwise sum of each group of inputs, placed on the ``destination`` device. cSsg|]}gqSr r )r _r r rr~sz(reduce_add_coalesced..css|] }|jVqdS)N) is_sparse)r rr r rr sz'reduce_add_coalesced..rr!csg|]}t|qSr )r)r r)rr rrscSsg|] }t|qSr )r)r chunkr r rrs) zipallr6appendr8Zto_denserdatatupler)r/r0rZ dense_tensorsr"Z ref_orderZtensor_at_gpusr4ZcollrZitrschunksZ flat_tensorsZ flat_resultr )rrreduce_add_coalescedks$   rAcCs|t|}|dkr6dd|D}ttjj|||||S|dk rLtdj||dk rbtdj|ttjj||||SdS)a1Scatters tensor across multiple GPUs. Args: tensor (Tensor): tensor to scatter. Can be on CPU or GPU. devices (Iterable[torch.device, str or int], optional): an iterable of GPU devices, among which to scatter. chunk_sizes (Iterable[int], optional): sizes of chunks to be placed on each device. It should match :attr:`devices` in length and sums to ``tensor.size(dim)``. If not specified, :attr:`tensor` will be divided into equal chunks. dim (int, optional): A dimension along which to chunk :attr:`tensor`. Default: ``0``. streams (Iterable[Stream], optional): an iterable of Streams, among which to execute the scatter. If not specified, the default stream will be utilized. out (Sequence[Tensor], optional, keyword-only): the GPU tensors to store output results. Sizes of these tensors must match that of :attr:`tensor`, except for :attr:`dim`, where the total size must sum to ``tensor.size(dim)``. .. note:: Exactly one of :attr:`devices` and :attr:`out` must be specified. When :attr:`out` is specified, :attr:`chunk_sizes` must not be specified and will be inferred from sizes of :attr:`out`. Returns: - If :attr:`devices` is specified, a tuple containing chunks of :attr:`tensor`, placed on :attr:`devices`. - If :attr:`out` is specified, a tuple containing :attr:`out` tensors, each containing a chunk of :attr:`tensor`. NcSsg|] }t|qSr )r)r r r r rrszscatter..zK'devices' must not be specified when 'out' is specified, but got devices={}zS'chunk_sizes' must not be specified when 'out' is specified, but got chunk_sizes={})rr?rrZ_scatterrrZ _scatter_out)rrZ chunk_sizesdimstreamsr r r rscatters"rDcCspdd|D}|dkrF|d kr(tjdt|ddd}tjj|||S|dk r\tdj|tjj|||SdS) aGathers tensors from multiple GPU devices. Args: tensors (Iterable[Tensor]): an iterable of tensors to gather. Tensor sizes in all dimensions other than :attr:`dim` have to match. dim (int, optional): a dimension along which the tensors will be concatenated. Default: ``0``. destination (torch.device, str, or int, optional): the output device. Can be CPU or CUDA. Default: the current CUDA device. out (Tensor, optional, keyword-only): the tensor to store gather result. Its sizes must match those of :attr:`tensors`, except for :attr:`dim`, where the size must equal ``sum(tensor.size(dim) for tensor in tensors)``. Can be on CPU or CUDA. .. note:: :attr:`destination` must not be specified when :attr:`out` is specified. Returns: - If :attr:`destination` is specified, a tensor located on :attr:`destination` device, that is a result of concatenating :attr:`tensors` along :attr:`dim`. - If :attr:`out` is specified, the :attr:`out` tensor, now containing results of concatenating :attr:`tensors` along :attr:`dim`. cSsg|] }t|qSr )r)r rr r rrszgather..Nr!zjUsing -1 to represent CPU tensor is deprecated. Please use a device object or string instead, e.g., "cpu".T)Z allow_cpurzS'destination' must not be specified when 'out' is specified, but got destination={}r:) warningswarnrrrZ_gatherrrZ _gather_out)rrBr0r r r rgathersrG)N)r)N)Nr)NNrN)rN)rErZ torch.cudarZ torch._utilsrrrrrrtypingr rrr6rArDrGr r r rs   !  . -2