/usr/local/lib64/python3.6/site-packages/torch/nn/utils/__pycache__
NameSizeModeActions
clip_grad.cpython-36.pyc39470644editdlrm
convert_parameters.cpython-36.pyc23450644editdlrm
fusion.cpython-36.pyc15280644editdlrm
init.cpython-36.pyc22840644editdlrm
memory_format.cpython-36.pyc37630644editdlrm
parametrizations.cpython-36.pyc149990644editdlrm
parametrize.cpython-36.pyc198700644editdlrm
prune.cpython-36.pyc455570644editdlrm
rnn.cpython-36.pyc159340644editdlrm
spectral_norm.cpython-36.pyc96420644editdlrm
weight_norm.cpython-36.pyc46070644editdlrm
__init__.cpython-36.pyc7320644editdlrm
Edit: /usr/local/lib64/python3.6/site-packages/torch/nn/utils/__pycache__/rnn.cpython-36.pyc (15934B)
3 EgBD@sddlmZddlZddlZddlmZddlmZddlmZddl m Z m Z edd d d d gZ ejejeejeejd e _ ddZGddde Zd#ddZd$ddZddZd%ddZd&ddZd'dd Zd(d!d"ZdS))) namedtupleN)Tensor)_VF)Optional)ListTuplePackedSequence_data batch_sizessorted_indicesunsorted_indices)r r r r cCs|dkr dS||S)N)optionalfnrr>/usr/local/lib64/python3.6/site-packages/torch/nn/utils/rnn.pybindsrcseZdZdZd!fdd ZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZeddZdd ZZS)"PackedSequenceaqHolds the data and list of :attr:`batch_sizes` of a packed sequence. All RNN modules accept packed sequences as inputs. Note: Instances of this class should never be created manually. They are meant to be instantiated by functions like :func:`pack_padded_sequence`. Batch sizes represent the number elements at each sequence step in the batch, not the varying sequence lengths passed to :func:`pack_padded_sequence`. For instance, given data ``abc`` and ``x`` the :class:`PackedSequence` would contain data ``axbc`` with ``batch_sizes=[2,1,1]``. Attributes: data (Tensor): Tensor containing packed sequence batch_sizes (Tensor): Tensor of integers holding information about the batch size at each sequence step sorted_indices (Tensor, optional): Tensor of integers holding how this :class:`PackedSequence` is constructed from sequences. unsorted_indices (Tensor, optional): Tensor of integers holding how this to recover the original sequences with correct order. .. note:: :attr:`data` can be on arbitrary device and of arbitrary dtype. :attr:`sorted_indices` and :attr:`unsorted_indices` must be ``torch.int64`` tensors on the same device as :attr:`data`. However, :attr:`batch_sizes` should always be a CPU ``torch.int64`` tensor. This invariant is maintained throughout :class:`PackedSequence` class, and all functions that construct a `:class:PackedSequence` in PyTorch (i.e., they only pass in tensors conforming to this constraint). Ncs tt|j|ft||||S)N)superr__new___packed_sequence_init_args)clsr r r r ) __class__rrr?s zPackedSequence.__new__cCs2t||jj|jt|jddt|jddS)NcSs|jS)N) pin_memory)trrrMsz+PackedSequence.pin_memory..cSs|jS)N)r)rrrrrNs)typer rr rr r )selfrrrrIszPackedSequence.pin_memorycOsFtjf|jj|jjdj||}|jr2|j||S|j|ddi|S)N)dtypedevicercuda)torchtensorr rrtois_cuda)rargskwargsexrrrr Ps  zPackedSequence.cudacOsLtjf|jj|jjdj||}|jjdkr8|j||S|j|ddi|S)N)rrcpur)r!r"r rrr#r)rr%r&r'rrrr(Ws   zPackedSequence.cpucCs|jtjdS)N)r)r#r!double)rrrrr)^szPackedSequence.doublecCs|jtjdS)N)r)r#r!float)rrrrr*aszPackedSequence.floatcCs|jtjdS)N)r)r#r!half)rrrrr+dszPackedSequence.halfcCs|jtjdS)N)r)r#r!long)rrrrr,gszPackedSequence.longcCs|jtjdS)N)r)r#r!int)rrrrr-jszPackedSequence.intcCs|jtjdS)N)r)r#r!short)rrrrr.mszPackedSequence.shortcCs|jtjdS)N)r)r#r!Zint8)rrrrcharpszPackedSequence.charcCs|jtjdS)N)r)r#r!Zuint8)rrrrbytesszPackedSequence.bytecs||jj||jkr|SddtddjDt|jfdd}t|jfdd}t||j||SdS)a Performs dtype and/or device conversion on `self.data`. It has similar signature as :meth:`torch.Tensor.to`, except optional arguments like `non_blocking` and `copy` should be passed as kwargs, not args, or they will not apply to the index tensors. .. note:: If the ``self.data`` Tensor already has the correct :class:`torch.dtype` and :class:`torch.device`, then ``self`` is returned. Otherwise, returns a copy with the desired configuration. cSsi|]\}}||qSrr).0kvrrr sz%PackedSequence.to..cSs|ddko|ddkS)Nrrrr)rrrrrsz#PackedSequence.to..cs|jjfS)N)r#r)r)r r&rrrscs|jjfS)N)r#r)r)r r&rrrsN) r r#filteritemsrr r rr )rr%r&r r r)r r&rr#vs zPackedSequence.tocCs|jjS)z+Returns true if `self.data` stored on a gpu)r r$)rrrrr$szPackedSequence.is_cudacCs |jjS)z6Returns true if `self.data` stored on in pinned memory)r is_pinned)rrrrr7szPackedSequence.is_pinned)NNN)__name__ __module__ __qualname____doc__rrr r(r)r*r+r,r-r.r/r0r#propertyr$r7 __classcell__rr)rrrs #  rcCsn|dkrt|}|dk r8|jjdkr,td||||fSt|ttfrRt|dksVt|d|d||fSdS)Nr(abatch_sizes should always be on CPU. Instances of PackedSequence should never be created manually. They should be instantiated by functions like pack_sequence and pack_padded_sequences in nn.utils.rnn. https://pytorch.org/docs/stable/nn.html#torch.nn.utils.rnn.pack_sequencer) invert_permutationrr ValueError isinstancelisttuplelenAssertionError)r r r r rrrrs  rcCs$t||||\}}}}t||||S)N)rr)r r r r rrr_packed_sequence_initsrGcCs@|dkr dStj|tjd}|jd|tjd|j|jd|S)N)Z memory_formatr)r)r!Z empty_likeZlegacy_contiguous_formatZscatter_ZarangeZnumelr)Z permutationoutputrrrr@s r@FTcCstjjr&t|tj r&tjdddtj|tjd}|r@d}n6tj |dd\}}|j |j }|rfdnd }|j ||}t j|||\}}t|||dS) aSPacks a Tensor containing padded sequences of variable length. :attr:`input` can be of size ``T x B x *`` where `T` is the length of the longest sequence (equal to ``lengths[0]``), ``B`` is the batch size, and ``*`` is any number of dimensions (including 0). If ``batch_first`` is ``True``, ``B x T x *`` :attr:`input` is expected. For unsorted sequences, use `enforce_sorted = False`. If :attr:`enforce_sorted` is ``True``, the sequences should be sorted by length in a decreasing order, i.e. ``input[:,0]`` should be the longest sequence, and ``input[:,B-1]`` the shortest one. `enforce_sorted = True` is only necessary for ONNX export. Note: This function accepts any input that has at least two dimensions. You can apply it to pack the labels, and use the output of the RNN with them to compute the loss directly. A Tensor can be retrieved from a :class:`PackedSequence` object by accessing its ``.data`` attribute. Args: input (Tensor): padded batch of variable length sequences. lengths (Tensor or list(int)): list of sequence lengths of each batch element (must be on the CPU if provided as a tensor). batch_first (bool, optional): if ``True``, the input is expected in ``B x T x *`` format. enforce_sorted (bool, optional): if ``True``, the input is expected to contain sequences sorted by length in a decreasing order. If ``False``, the input will get sorted unconditionally. Default: ``True``. Returns: a :class:`PackedSequence` object zpack_padded_sequence has been called with a Python list of sequence lengths. The tracer cannot track the data flow of Python values, and it will treat them as constants, likely rendering the trace incorrect for any other combination of lengths.r>) stacklevel)rNT)Z descendingrr?)r!_CZ_get_tracing_staterBrwarningswarn as_tensorZint64sortr#r index_selectrZ_pack_padded_sequencerG)inputlengths batch_firstenforce_sortedr batch_dimr r rrrpack_padded_sequences!   rUc Cs|jjd}|dk r0||kr,tdj|||}tj|j|j|||\}}|j}|dk rx|r`dnd}|j||||fS||fS)aPads a packed batch of variable length sequences. It is an inverse operation to :func:`pack_padded_sequence`. The returned Tensor's data will be of size ``T x B x *``, where `T` is the length of the longest sequence and `B` is the batch size. If ``batch_first`` is True, the data will be transposed into ``B x T x *`` format. Example: >>> from torch.nn.utils.rnn import pack_padded_sequence, pad_packed_sequence >>> seq = torch.tensor([[1,2,0], [3,0,0], [4,5,6]]) >>> lens = [2, 1, 3] >>> packed = pack_padded_sequence(seq, lens, batch_first=True, enforce_sorted=False) >>> packed PackedSequence(data=tensor([4, 1, 3, 5, 2, 6]), batch_sizes=tensor([3, 2, 1]), sorted_indices=tensor([2, 0, 1]), unsorted_indices=tensor([1, 2, 0])) >>> seq_unpacked, lens_unpacked = pad_packed_sequence(packed, batch_first=True) >>> seq_unpacked tensor([[1, 2, 0], [3, 0, 0], [4, 5, 6]]) >>> lens_unpacked tensor([2, 1, 3]) .. note:: :attr:`total_length` is useful to implement the ``pack sequence -> recurrent network -> unpack sequence`` pattern in a :class:`~torch.nn.Module` wrapped in :class:`~torch.nn.DataParallel`. See :ref:`this FAQ section ` for details. Args: sequence (PackedSequence): batch to pad batch_first (bool, optional): if ``True``, the output will be in ``B x T x *`` format. padding_value (float, optional): values for padded elements. total_length (int, optional): if not ``None``, the output will be padded to have length :attr:`total_length`. This method will throw :class:`ValueError` if :attr:`total_length` is less than the max sequence length in :attr:`sequence`. Returns: Tuple of Tensor containing the padded sequence, and a Tensor containing the list of lengths of each sequence in the batch. Batch elements will be re-ordered as they were ordered originally when the batch was passed to ``pack_padded_sequence`` or ``pack_sequence``. rNzExpected total_length to be at least the length of the longest sequence in input, but got total_length={} and max sequence length being {}r?) r sizerAformatrZ_pad_packed_sequencer r rO) sequencerR padding_value total_lengthZmax_seq_lengthZ padded_outputrQr rTrrrpad_packed_sequences5   r\cCstjjj|||S)aPad a list of variable length Tensors with ``padding_value`` ``pad_sequence`` stacks a list of Tensors along a new dimension, and pads them to equal length. For example, if the input is list of sequences with size ``L x *`` and if batch_first is False, and ``T x B x *`` otherwise. `B` is batch size. It is equal to the number of elements in ``sequences``. `T` is length of the longest sequence. `L` is length of the sequence. `*` is any number of trailing dimensions, including none. Example: >>> from torch.nn.utils.rnn import pad_sequence >>> a = torch.ones(25, 300) >>> b = torch.ones(22, 300) >>> c = torch.ones(15, 300) >>> pad_sequence([a, b, c]).size() torch.Size([25, 3, 300]) Note: This function returns a Tensor of size ``T x B x *`` or ``B x T x *`` where `T` is the length of the longest sequence. This function assumes trailing dimensions and type of all the Tensors in sequences are same. Args: sequences (list[Tensor]): list of variable length sequences. batch_first (bool, optional): output will be in ``B x T x *`` if True, or in ``T x B x *`` otherwise padding_value (float, optional): value for padded elements. Default: 0. Returns: Tensor of size ``T x B x *`` if :attr:`batch_first` is ``False``. Tensor of size ``B x T x *`` otherwise )r!rJZ_nn pad_sequence) sequencesrRrZrrrr]Cs(r]cCs&tjdd|D}tt|||dS)afPacks a list of variable length Tensors ``sequences`` should be a list of Tensors of size ``L x *``, where `L` is the length of a sequence and `*` is any number of trailing dimensions, including zero. For unsorted sequences, use `enforce_sorted = False`. If ``enforce_sorted`` is ``True``, the sequences should be sorted in the order of decreasing length. ``enforce_sorted = True`` is only necessary for ONNX export. Example: >>> from torch.nn.utils.rnn import pack_sequence >>> a = torch.tensor([1,2,3]) >>> b = torch.tensor([4,5]) >>> c = torch.tensor([6]) >>> pack_sequence([a, b, c]) PackedSequence(data=tensor([ 1, 4, 6, 2, 5, 3]), batch_sizes=tensor([ 3, 2, 1])) Args: sequences (list[Tensor]): A list of sequences of decreasing length. enforce_sorted (bool, optional): if ``True``, checks that the input contains sequences sorted by length in a decreasing order. If ``False``, this condition is not checked. Default: ``True``. Returns: a :class:`PackedSequence` object cSsg|]}|jdqS)r)rW)r1r3rrr sz!pack_sequence..)rS)r!rMrUr])r^rSrQrrr pack_sequencensr`)NNN)NNN)FT)FrVN)FrV)T) collectionsrrKr!rrZ _jit_internalrtypingrrr __annotations__rrrrGr@rUr\r]r`rrrrs*       5 F +