a
    Ž¥»aÐÒ  ã                   @   s0  d dl Z d dlZd dlZd dlmZmZmZmZmZm	Z	 d dl
Z
d dl
mZ ddlmZ ddlmZ ddlmZ dd	lmZ d
dlmZ ejejdœZd eeeedœdd„ZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZ G dd„ deƒZ!dS )!é    N)ÚListÚTupleÚOptionalÚoverloadÚUnionÚcast)ÚTensoré   )ÚModuleé   )Ú	Parameter)ÚPackedSequence)Úinité   )Ú_VF)ÚRNN_TANHÚRNN_RELU)ÚtensorÚpermutationÚdimÚreturnc                 C   s   |   ||¡S ©N)Zindex_select)r   r   r   © r   úN/home/yuhw/wc/pochoir/venv/lib/python3.9/site-packages/torch/nn/modules/rnn.pyÚapply_permutation   s    r   c                       s²  e Zd ZU g d¢ZdgZeed< eed< eed< eed< eed< eed< e	ed	< eed
< eed< d8eeeeeee	eeddœ
‡ fdd„Z
‡ fdd„Zddœdd„Z‡ fdd„Zddœdd„Zeee ddœdd „Zeee eeeef dœd!d"„Zd9eeeeef edd$œd%d&„Zeeee d'œd(d)„Zeee d*œd+d,„Zd:eeef ee eeeef ef d-œd.d/„Zedœd0d1„Z‡ fd2d3„Zeeee  dœd4d5„ƒZ‡ fd6d7„Z ‡  Z!S );ÚRNNBase)	ÚmodeÚ
input_sizeÚhidden_sizeÚ
num_layersÚbiasÚbatch_firstÚdropoutÚbidirectionalÚ	proj_sizeÚall_weightsr   r   r   r   r    r!   r"   r#   r$   r	   TFç        r   N)
r   r   r   r   r    r!   r"   r#   r$   r   c                    s   |
|dœ}t tˆƒ ¡  |ˆ_|ˆ_|ˆ_|ˆ_|ˆ_|ˆ_t	|ƒˆ_
|ˆ_|	ˆ_|rZdnd}t|tjƒrŒd|  kr~dkrŒn n
t|tƒr”tdƒ‚|dkr¶|dkr¶t d ||¡¡ |	dk rÆtdƒ‚|	|krÖtdƒ‚|d	krèd
| }n>|dkrúd| }n,|dk�r
|}n|dk�r|}ntd| ƒ‚g ˆ_g ˆ_t|ƒD �]˜‰ t|ƒD �]†}|	dk�r\|	n|}ˆ dk�rn|n|| }ttj||ffi |¤Žƒ}ttj||ffi |¤Žƒ}ttj|fi |¤Žƒ}ttj|fi |¤Žƒ}d}ˆjdk�r|�rú||||f}n||f}n:ttj|	|ffi |¤Žƒ}|�r4|||||f}n
|||f}|dk�rLdnd‰ddg}|�rj|ddg7 }ˆjdk�r€|dg7 }‡ ‡fdd„|D ƒ}t||ƒD ]\}}tˆ||ƒ �qžˆj |¡ ˆj |¡ �qH�q:‡fdd„ˆjD ƒˆ_ˆ  ¡  ˆ !¡  d S )N©ÚdeviceÚdtyper   r	   r   zbdropout should be a number in range [0, 1] representing the probability of an element being zeroedz›dropout option adds dropout after all but last recurrent layer, so non-zero dropout expects num_layers greater than 1, but got dropout={} and num_layers={}zEproj_size should be a positive integer or zero to disable projectionsz,proj_size has to be smaller than hidden_sizeÚLSTMé   ÚGRUr   r   r   zUnrecognized RNN mode: r   Ú_reverseÚ úweight_ih_l{}{}úweight_hh_l{}{}úbias_ih_l{}{}úbias_hh_l{}{}úweight_hr_l{}{}c                    s   g | ]}|  ˆ ˆ¡‘qS r   ©Úformat©Ú.0Úx©ÚlayerÚsuffixr   r   Ú
<listcomp>r   ó    z$RNNBase.__init__.<locals>.<listcomp>c                    s   g | ]}‡ fd d„|ƒ‘qS )c                    s   t ˆ | ƒrtˆ | ƒS d S r   ©ÚhasattrÚgetattr©Úwn©Úselfr   r   Ú<lambda>y   r=   z-RNNBase.__init__.<locals>.<listcomp>.<lambda>r   ©r7   rB   rC   r   r   r<   y   r=   )"Úsuperr   Ú__init__r   r   r   r   r    r!   Úfloatr"   r#   r$   Ú
isinstanceÚnumbersÚNumberÚboolÚ
ValueErrorÚwarningsÚwarnr5   Ú_flat_weights_namesÚ_all_weightsÚranger   ÚtorchÚemptyÚzipÚsetattrÚextendÚappendÚ_flat_weightsÚflatten_parametersÚreset_parameters)rD   r   r   r   r   r    r!   r"   r#   r$   r(   r)   Úfactory_kwargsÚnum_directionsZ	gate_sizeÚ	directionÚreal_hidden_sizeZlayer_input_sizeZw_ihZw_hhZb_ihZb_hhZlayer_paramsZw_hrZparam_namesÚnameÚparam©Ú	__class__©r:   rD   r;   r   rH   '   s„    

$ÿý






zRNNBase.__init__c                    s@   t | dƒr*|| jv r*| j |¡}|| j|< tt| ƒ ||¡ d S )NrQ   )r?   rQ   ÚindexrZ   rG   r   Ú__setattr__)rD   ÚattrÚvalueÚidxrc   r   r   rg   ~   s    
zRNNBase.__setattr__©r   c                 C   s„  t | jƒt | jƒkrdS | jD ]}t|tƒs dS q| jd }|j}| jD ]:}t|jtƒr~|jj|kr~|jjr~tj	j
 |j¡sJ dS qJtdd„ | jD ƒƒ}t |ƒt | jƒkr°dS tj |¡�² ddlm	  m
  m} t ¡ �p t ¡ �r@| jrôdnd}| jdk�r|d7 }t | j|| j| | j¡| j| j| j| jt| jƒ¡	 W d  ƒ n1 �sV0    Y  W d  ƒ n1 �sv0    Y  dS )zÅResets parameter data pointer so that they can use faster code paths.

        Right now, this works only if the module is on the GPU and cuDNN is enabled.
        Otherwise, it's a no-op.
        Nr   c                 s   s   | ]}|  ¡ V  qd S r   )Zdata_ptr)r7   Úpr   r   r   Ú	<genexpr>¡   r=   z-RNNBase.flatten_parameters.<locals>.<genexpr>r+   r   r	   )ÚlenrZ   rQ   rJ   r   r)   ÚdataZis_cudarT   ÚbackendsZcudnnZis_acceptableÚsetZcudaZ	device_ofZtorch.backends.cudnn.rnnÚrnnZno_gradZ_use_cudnn_rnn_flatten_weightr    r$   Z_cudnn_rnn_flatten_weightr   Zget_cudnn_moder   r   r   r!   rM   r#   )rD   ÚwZfirst_fwr)   ÚfwZunique_data_ptrsrr   Znum_weightsr   r   r   r[   …   s<    



ÿþ

üzRNNBase.flatten_parametersc                    s2   t tˆ ƒ |¡}‡ fdd„ˆ jD ƒˆ _ˆ  ¡  |S )Nc                    s   g | ]}‡ fd d„|ƒ‘qS )c                    s   t ˆ | ƒrtˆ | ƒS d S r   r>   rA   rC   r   r   rE   »   r=   z+RNNBase._apply.<locals>.<listcomp>.<lambda>r   rF   rC   r   r   r<   »   r=   z"RNNBase._apply.<locals>.<listcomp>)rG   r   Ú_applyrQ   rZ   r[   )rD   ÚfnÚretrc   rC   r   ru   µ   s    zRNNBase._applyc                 C   s2   dt  | j¡ }|  ¡ D ]}t || |¡ qd S ©Ng      ð?©ÚmathÚsqrtr   Ú
parametersr   Zuniform_©rD   ZstdvÚweightr   r   r   r\   Á   s    zRNNBase.reset_parameters©ÚinputÚbatch_sizesr   c                 C   s\   |d urdnd}|  ¡ |kr0td ||  ¡ ¡ƒ‚| j| d¡krXtd | j| d¡¡ƒ‚d S )Nr   r   z%input must have {} dimensions, got {}éÿÿÿÿz?input.size(-1) must be equal to input_size. Expected {}, got {})r   ÚRuntimeErrorr5   r   Úsize)rD   r€   r�   Zexpected_input_dimr   r   r   Úcheck_inputÆ   s    ÿÿÿÿzRNNBase.check_inputc                 C   sr   |d urt |d ƒ}n| jr&| d¡n| d¡}| jr:dnd}| jdkr\| j| || jf}n| j| || jf}|S ©Nr   r	   r   )Úintr!   r„   r#   r$   r   r   ©rD   r€   r�   Z
mini_batchr^   Úexpected_hidden_sizer   r   r   Úget_expected_hidden_sizeÑ   s    
ÿÿz RNNBase.get_expected_hidden_sizeúExpected hidden size {}, got {})Úhxr‰   Úmsgr   c                 C   s(   |  ¡ |kr$t| |t|  ¡ ƒ¡ƒ‚d S r   )r„   rƒ   r5   Úlist)rD   rŒ   r‰   r�   r   r   r   Úcheck_hidden_sizeß   s    zRNNBase.check_hidden_size©r€   Úhiddenr�   c                 C   s(   |   ||¡ |  ||¡}|  ||¡ d S r   )r…   rŠ   r�   )rD   r€   r‘   r�   r‰   r   r   r   Úcheck_forward_argsä   s    zRNNBase.check_forward_args)rŒ   r   c                 C   s   |d u r|S t ||ƒS r   ©r   ©rD   rŒ   r   r   r   r   Úpermute_hiddenê   s    zRNNBase.permute_hidden©r€   rŒ   r   c              
   C   s^  t |tƒ}|r(|\}}}}t|d ƒ}n0tt|ƒ}d }| jrF| d¡n| d¡}d }d }|d u rštt|ƒ}| jrtdnd}tj	| j
| || j|j|jd�}n|  ||¡}|d us²J ‚tt|ƒ}|  |||¡ t| j }	|d u �r|	||| j| j| j
| j| j| j| jƒ	}
n$|	|||| j| j| j
| j| j| jƒ	}
|
d }|
d }|�rNt||||ƒ}||  ||¡fS ©Nr   r	   r   ©r)   r(   )rJ   r   r‡   r   r   r!   r„   r#   rT   Úzerosr   r   r)   r(   r•   r’   Ú
_rnn_implsr   rZ   r    r"   Útraining)rD   r€   rŒ   Z	is_packedr�   Úsorted_indicesÚunsorted_indicesÚmax_batch_sizer^   Ú_implÚresultÚoutputr‘   r   r   r   Úforwardï   sB    


þ


ÿÿzRNNBase.forwardc                 C   s‚   d}| j dkr|d7 }| jdkr(|d7 }| jdur:|d7 }| jdurL|d	7 }| jdkr^|d
7 }| jdurp|d7 }|jf i | j¤ŽS )Nú{input_size}, {hidden_size}r   z, proj_size={proj_size}r	   z, num_layers={num_layers}Tú, bias={bias}Fz, batch_first={batch_first}z, dropout={dropout}z, bidirectional={bidirectional})r$   r   r    r!   r"   r#   r5   Ú__dict__©rD   Úsr   r   r   Ú
extra_repr  s    





zRNNBase.extra_reprc                    s®  t tˆƒ |¡ d|v r"|d ˆ_d|vr0dˆ_tˆjd d tƒrHd S ˆj}ˆjrXdnd}g ˆ_	g ˆ_t
|ƒD �] ‰ t
|ƒD �]}|dkr�dnd‰g d¢}‡ ‡fd	d
„|D ƒ}ˆj�rˆjdkràˆ j|g7  _ˆj	 |¡ n,ˆ j|d d… g7  _ˆj	 |d d… ¡ q~ˆjdk�rdˆ j|d d… g|dd … g 7  _ˆj	 |d d… |dd … g ¡ q~ˆ j|d d… g7  _ˆj	 |d d… ¡ q~qp‡fdd
„ˆj	D ƒˆ_d S )Nr%   r$   r   r   r	   r-   r.   )r/   r0   r1   r2   r3   c                    s   g | ]}|  ˆ ˆ¡‘qS r   r4   r6   r9   r   r   r<   ?  r=   z(RNNBase.__setstate__.<locals>.<listcomp>r+   r‚   c                    s   g | ]}‡ fd d„|ƒ‘qS )c                    s   t ˆ | ƒrtˆ | ƒS d S r   r>   rA   rC   r   r   rE   N  r=   z1RNNBase.__setstate__.<locals>.<listcomp>.<lambda>r   rF   rC   r   r   r<   N  r=   )rG   r   Ú__setstate__rR   r$   rJ   Ústrr   r#   rQ   rS   r    rX   rZ   )rD   Údr   r^   r_   Úweightsrc   re   r   r©   *  s8    

&$zRNNBase.__setstate__c                    s   ‡ fdd„ˆ j D ƒS )Nc                    s   g | ]}‡ fd d„|D ƒ‘qS )c                    s   g | ]}t ˆ |ƒ‘qS r   )r@   )r7   r~   rC   r   r   r<   R  r=   z2RNNBase.all_weights.<locals>.<listcomp>.<listcomp>r   )r7   r¬   rC   r   r   r<   R  r=   z'RNNBase.all_weights.<locals>.<listcomp>)rR   rC   r   rC   r   r%   P  s    zRNNBase.all_weightsc                    s2   t t| ƒ ¡ }|jd d … |_|jd d … |_|S r   )rG   r   Ú_replicate_for_data_parallelrZ   rQ   )rD   Zreplicarc   r   r   r­   T  s    z$RNNBase._replicate_for_data_parallel)r	   TFr&   Fr   NN)r‹   )N)"Ú__name__Ú
__module__Ú__qualname__Ú__constants__Z__jit_unused_properties__rª   Ú__annotations__r‡   rM   rI   rH   rg   r[   ru   r\   r   r   r…   r   rŠ   r�   r’   r•   r   r   r¢   r¨   r©   Úpropertyr   r   r%   r­   Ú__classcell__r   r   rc   r   r      sR   
   ýýW0  ÿÿ þ
þ+&r   c                       s    e Zd ZdZ‡ fdd„Z‡  ZS )ÚRNNaF  Applies a multi-layer Elman RNN with :math:`\tanh` or :math:`\text{ReLU}` non-linearity to an
    input sequence.


    For each element in the input sequence, each layer computes the following
    function:

    .. math::
        h_t = \tanh(W_{ih} x_t + b_{ih} + W_{hh} h_{(t-1)} + b_{hh})

    where :math:`h_t` is the hidden state at time `t`, :math:`x_t` is
    the input at time `t`, and :math:`h_{(t-1)}` is the hidden state of the
    previous layer at time `t-1` or the initial hidden state at time `0`.
    If :attr:`nonlinearity` is ``'relu'``, then :math:`\text{ReLU}` is used instead of :math:`\tanh`.

    Args:
        input_size: The number of expected features in the input `x`
        hidden_size: The number of features in the hidden state `h`
        num_layers: Number of recurrent layers. E.g., setting ``num_layers=2``
            would mean stacking two RNNs together to form a `stacked RNN`,
            with the second RNN taking in outputs of the first RNN and
            computing the final results. Default: 1
        nonlinearity: The non-linearity to use. Can be either ``'tanh'`` or ``'relu'``. Default: ``'tanh'``
        bias: If ``False``, then the layer does not use bias weights `b_ih` and `b_hh`.
            Default: ``True``
        batch_first: If ``True``, then the input and output tensors are provided
            as `(batch, seq, feature)` instead of `(seq, batch, feature)`.
            Note that this does not apply to hidden or cell states. See the
            Inputs/Outputs sections below for details.  Default: ``False``
        dropout: If non-zero, introduces a `Dropout` layer on the outputs of each
            RNN layer except the last layer, with dropout probability equal to
            :attr:`dropout`. Default: 0
        bidirectional: If ``True``, becomes a bidirectional RNN. Default: ``False``

    Inputs: input, h_0
        * **input**: tensor of shape :math:`(L, N, H_{in})` when ``batch_first=False`` or
          :math:`(N, L, H_{in})` when ``batch_first=True`` containing the features of
          the input sequence.  The input can also be a packed variable length sequence.
          See :func:`torch.nn.utils.rnn.pack_padded_sequence` or
          :func:`torch.nn.utils.rnn.pack_sequence` for details.
        * **h_0**: tensor of shape :math:`(D * \text{num\_layers}, N, H_{out})` containing the initial hidden
          state for each element in the batch. Defaults to zeros if not provided.

        where:

        .. math::
            \begin{aligned}
                N ={} & \text{batch size} \\
                L ={} & \text{sequence length} \\
                D ={} & 2 \text{ if bidirectional=True otherwise } 1 \\
                H_{in} ={} & \text{input\_size} \\
                H_{out} ={} & \text{hidden\_size}
            \end{aligned}

    Outputs: output, h_n
        * **output**: tensor of shape :math:`(L, N, D * H_{out})` when ``batch_first=False`` or
          :math:`(N, L, D * H_{out})` when ``batch_first=True`` containing the output features
          `(h_t)` from the last layer of the RNN, for each `t`. If a
          :class:`torch.nn.utils.rnn.PackedSequence` has been given as the input, the output
          will also be a packed sequence.
        * **h_n**: tensor of shape :math:`(D * \text{num\_layers}, N, H_{out})` containing the final hidden state
          for each element in the batch.

    Attributes:
        weight_ih_l[k]: the learnable input-hidden weights of the k-th layer,
            of shape `(hidden_size, input_size)` for `k = 0`. Otherwise, the shape is
            `(hidden_size, num_directions * hidden_size)`
        weight_hh_l[k]: the learnable hidden-hidden weights of the k-th layer,
            of shape `(hidden_size, hidden_size)`
        bias_ih_l[k]: the learnable input-hidden bias of the k-th layer,
            of shape `(hidden_size)`
        bias_hh_l[k]: the learnable hidden-hidden bias of the k-th layer,
            of shape `(hidden_size)`

    .. note::
        All the weights and biases are initialized from :math:`\mathcal{U}(-\sqrt{k}, \sqrt{k})`
        where :math:`k = \frac{1}{\text{hidden\_size}}`

    .. note::
        For bidirectional RNNs, forward and backward are directions 0 and 1 respectively.
        Example of splitting the output layers when ``batch_first=False``:
        ``output.view(seq_len, batch, num_directions, hidden_size)``.

    .. include:: ../cudnn_rnn_determinism.rst

    .. include:: ../cudnn_persistent_rnn.rst

    Examples::

        >>> rnn = nn.RNN(10, 20, 2)
        >>> input = torch.randn(5, 3, 10)
        >>> h0 = torch.randn(2, 3, 20)
        >>> output, hn = rnn(input, h0)
    c                    sp   d|v rt dƒ‚| dd¡| _| jdkr.d}n | jdkr>d}nt d | j¡ƒ‚tt| ƒj|g|¢R i |¤Ž d S )	Nr$   ú=proj_size argument is only supported for LSTM, not RNN or GRUÚnonlinearityÚtanhr   Úrelur   zUnknown nonlinearity '{}')rN   Úpopr·   r5   rG   rµ   rH   )rD   ÚargsÚkwargsr   rc   r   r   rH   ½  s    

zRNN.__init__)r®   r¯   r°   Ú__doc__rH   r´   r   r   rc   r   rµ   ]  s   _rµ   c                
       s  e Zd ZdZ‡ fdd„Zeee eeeef dœdd„Z	eeeef ee dœdd	„Z
eeef ee eeef d
œdd„Zeejjdeeeeef  eeeeef f dœdd„ƒƒZeejjdeeeeef  eeeeef f dœdd„ƒƒZddd„Z‡  ZS )r*   a•  Applies a multi-layer long short-term memory (LSTM) RNN to an input
    sequence.


    For each element in the input sequence, each layer computes the following
    function:

    .. math::
        \begin{array}{ll} \\
            i_t = \sigma(W_{ii} x_t + b_{ii} + W_{hi} h_{t-1} + b_{hi}) \\
            f_t = \sigma(W_{if} x_t + b_{if} + W_{hf} h_{t-1} + b_{hf}) \\
            g_t = \tanh(W_{ig} x_t + b_{ig} + W_{hg} h_{t-1} + b_{hg}) \\
            o_t = \sigma(W_{io} x_t + b_{io} + W_{ho} h_{t-1} + b_{ho}) \\
            c_t = f_t \odot c_{t-1} + i_t \odot g_t \\
            h_t = o_t \odot \tanh(c_t) \\
        \end{array}

    where :math:`h_t` is the hidden state at time `t`, :math:`c_t` is the cell
    state at time `t`, :math:`x_t` is the input at time `t`, :math:`h_{t-1}`
    is the hidden state of the layer at time `t-1` or the initial hidden
    state at time `0`, and :math:`i_t`, :math:`f_t`, :math:`g_t`,
    :math:`o_t` are the input, forget, cell, and output gates, respectively.
    :math:`\sigma` is the sigmoid function, and :math:`\odot` is the Hadamard product.

    In a multilayer LSTM, the input :math:`x^{(l)}_t` of the :math:`l` -th layer
    (:math:`l >= 2`) is the hidden state :math:`h^{(l-1)}_t` of the previous layer multiplied by
    dropout :math:`\delta^{(l-1)}_t` where each :math:`\delta^{(l-1)}_t` is a Bernoulli random
    variable which is :math:`0` with probability :attr:`dropout`.

    If ``proj_size > 0`` is specified, LSTM with projections will be used. This changes
    the LSTM cell in the following way. First, the dimension of :math:`h_t` will be changed from
    ``hidden_size`` to ``proj_size`` (dimensions of :math:`W_{hi}` will be changed accordingly).
    Second, the output hidden state of each layer will be multiplied by a learnable projection
    matrix: :math:`h_t = W_{hr}h_t`. Note that as a consequence of this, the output
    of LSTM network will be of different shape as well. See Inputs/Outputs sections below for exact
    dimensions of all variables. You can find more details in https://arxiv.org/abs/1402.1128.

    Args:
        input_size: The number of expected features in the input `x`
        hidden_size: The number of features in the hidden state `h`
        num_layers: Number of recurrent layers. E.g., setting ``num_layers=2``
            would mean stacking two LSTMs together to form a `stacked LSTM`,
            with the second LSTM taking in outputs of the first LSTM and
            computing the final results. Default: 1
        bias: If ``False``, then the layer does not use bias weights `b_ih` and `b_hh`.
            Default: ``True``
        batch_first: If ``True``, then the input and output tensors are provided
            as `(batch, seq, feature)` instead of `(seq, batch, feature)`.
            Note that this does not apply to hidden or cell states. See the
            Inputs/Outputs sections below for details.  Default: ``False``
        dropout: If non-zero, introduces a `Dropout` layer on the outputs of each
            LSTM layer except the last layer, with dropout probability equal to
            :attr:`dropout`. Default: 0
        bidirectional: If ``True``, becomes a bidirectional LSTM. Default: ``False``
        proj_size: If ``> 0``, will use LSTM with projections of corresponding size. Default: 0

    Inputs: input, (h_0, c_0)
        * **input**: tensor of shape :math:`(L, N, H_{in})` when ``batch_first=False`` or
          :math:`(N, L, H_{in})` when ``batch_first=True`` containing the features of
          the input sequence.  The input can also be a packed variable length sequence.
          See :func:`torch.nn.utils.rnn.pack_padded_sequence` or
          :func:`torch.nn.utils.rnn.pack_sequence` for details.
        * **h_0**: tensor of shape :math:`(D * \text{num\_layers}, N, H_{out})` containing the
          initial hidden state for each element in the batch.
          Defaults to zeros if (h_0, c_0) is not provided.
        * **c_0**: tensor of shape :math:`(D * \text{num\_layers}, N, H_{cell})` containing the
          initial cell state for each element in the batch.
          Defaults to zeros if (h_0, c_0) is not provided.

        where:

        .. math::
            \begin{aligned}
                N ={} & \text{batch size} \\
                L ={} & \text{sequence length} \\
                D ={} & 2 \text{ if bidirectional=True otherwise } 1 \\
                H_{in} ={} & \text{input\_size} \\
                H_{cell} ={} & \text{hidden\_size} \\
                H_{out} ={} & \text{proj\_size if } \text{proj\_size}>0 \text{ otherwise hidden\_size} \\
            \end{aligned}

    Outputs: output, (h_n, c_n)
        * **output**: tensor of shape :math:`(L, N, D * H_{out})` when ``batch_first=False`` or
          :math:`(N, L, D * H_{out})` when ``batch_first=True`` containing the output features
          `(h_t)` from the last layer of the LSTM, for each `t`. If a
          :class:`torch.nn.utils.rnn.PackedSequence` has been given as the input, the output
          will also be a packed sequence.
        * **h_n**: tensor of shape :math:`(D * \text{num\_layers}, N, H_{out})` containing the
          final hidden state for each element in the batch.
        * **c_n**: tensor of shape :math:`(D * \text{num\_layers}, N, H_{cell})` containing the
          final cell state for each element in the batch.

    Attributes:
        weight_ih_l[k] : the learnable input-hidden weights of the :math:`\text{k}^{th}` layer
            `(W_ii|W_if|W_ig|W_io)`, of shape `(4*hidden_size, input_size)` for `k = 0`.
            Otherwise, the shape is `(4*hidden_size, num_directions * hidden_size)`. If
            ``proj_size > 0`` was specified, the shape will be
            `(4*hidden_size, num_directions * proj_size)` for `k > 0`
        weight_hh_l[k] : the learnable hidden-hidden weights of the :math:`\text{k}^{th}` layer
            `(W_hi|W_hf|W_hg|W_ho)`, of shape `(4*hidden_size, hidden_size)`. If ``proj_size > 0``
            was specified, the shape will be `(4*hidden_size, proj_size)`.
        bias_ih_l[k] : the learnable input-hidden bias of the :math:`\text{k}^{th}` layer
            `(b_ii|b_if|b_ig|b_io)`, of shape `(4*hidden_size)`
        bias_hh_l[k] : the learnable hidden-hidden bias of the :math:`\text{k}^{th}` layer
            `(b_hi|b_hf|b_hg|b_ho)`, of shape `(4*hidden_size)`
        weight_hr_l[k] : the learnable projection weights of the :math:`\text{k}^{th}` layer
            of shape `(proj_size, hidden_size)`. Only present when ``proj_size > 0`` was
            specified.
        weight_ih_l[k]_reverse: Analogous to `weight_ih_l[k]` for the reverse direction.
            Only present when ``bidirectional=True``.
        weight_hh_l[k]_reverse:  Analogous to `weight_hh_l[k]` for the reverse direction.
            Only present when ``bidirectional=True``.
        bias_ih_l[k]_reverse:  Analogous to `bias_ih_l[k]` for the reverse direction.
            Only present when ``bidirectional=True``.
        bias_hh_l[k]_reverse:  Analogous to `bias_hh_l[k]` for the reverse direction.
            Only present when ``bidirectional=True``.
        weight_hr_l[k]_reverse:  Analogous to `weight_hr_l[k]` for the reverse direction.
            Only present when ``bidirectional=True`` and ``proj_size > 0`` was specified.

    .. note::
        All the weights and biases are initialized from :math:`\mathcal{U}(-\sqrt{k}, \sqrt{k})`
        where :math:`k = \frac{1}{\text{hidden\_size}}`

    .. note::
        For bidirectional LSTMs, forward and backward are directions 0 and 1 respectively.
        Example of splitting the output layers when ``batch_first=False``:
        ``output.view(seq_len, batch, num_directions, hidden_size)``.

    .. include:: ../cudnn_rnn_determinism.rst

    .. include:: ../cudnn_persistent_rnn.rst

    Examples::

        >>> rnn = nn.LSTM(10, 20, 2)
        >>> input = torch.randn(5, 3, 10)
        >>> h0 = torch.randn(2, 3, 20)
        >>> c0 = torch.randn(2, 3, 20)
        >>> output, (hn, cn) = rnn(input, (h0, c0))
    c                    s"   t t| ƒjdg|¢R i |¤Ž d S )Nr*   )rG   r*   rH   ©rD   r»   r¼   rc   r   r   rH   d  s    zLSTM.__init__r   c                 C   sT   |d urt |d ƒ}n| jr&| d¡n| d¡}| jr:dnd}| j| || jf}|S r†   )r‡   r!   r„   r#   r   r   rˆ   r   r   r   Úget_expected_cell_sizeg  s    ÿzLSTM.get_expected_cell_sizer�   c                 C   sD   |   ||¡ |  |d |  ||¡d¡ |  |d |  ||¡d¡ d S )Nr   z"Expected hidden[0] size {}, got {}r	   z"Expected hidden[1] size {}, got {})r…   r�   rŠ   r¿   )rD   r€   r‘   r�   r   r   r   r’   s  s    ÿÿzLSTM.check_forward_args)rŒ   r   r   c                 C   s(   |d u r|S t |d |ƒt |d |ƒfS )Nr   r	   r“   r”   r   r   r   r•     s    zLSTM.permute_hiddenNr–   c                 C   s   d S r   r   ©rD   r€   rŒ   r   r   r   r¢   ˆ  s    zLSTM.forwardc                 C   s   d S r   r   rÀ   r   r   r   r¢   �  s    c                 C   sŒ  |}t |tƒr,|\}}}}|d }t|ƒ}n&d }| jr@| d¡n| d¡}d }d }|d u rÆ| jrddnd}| jdkrx| jn| j}	tj	| j
| ||	|j|jd�}
tj	| j
| || j|j|jd�}|
|f}n|  ||¡}|  |||¡ |d u �rt ||| j| j| j
| j| j| j| j¡	}n&t |||| j| j| j
| j| j| j¡	}|d }|dd … }t |tƒ�rxt||||ƒ}||  ||¡fS ||  ||¡fS d S r—   )rJ   r   r‡   r!   r„   r#   r$   r   rT   r™   r   r)   r(   r•   r’   r   ZlstmrZ   r    r"   r›   )rD   r€   rŒ   Ú
orig_inputr�   rœ   r�   rž   r^   r`   Zh_zerosZc_zerosr    r¡   r‘   Úoutput_packedr   r   r   r¢   •  sH    

þþ

ÿÿ)N)N)N)r®   r¯   r°   r½   rH   r   r   r   r‡   r¿   r’   r•   r   rT   Ú_jit_internalÚ_overload_methodr¢   r   r´   r   r   rc   r   r*   Ö  s.     
ý

ý	ÿÿr*   c                       s‚   e Zd ZdZ‡ fdd„Zeejjd
e	e
e	 ee	e	f dœdd„ƒƒZeejjdee
e	 eee	f dœdd„ƒƒZdd	d„Z‡  ZS )r,   a¹  Applies a multi-layer gated recurrent unit (GRU) RNN to an input sequence.


    For each element in the input sequence, each layer computes the following
    function:

    .. math::
        \begin{array}{ll}
            r_t = \sigma(W_{ir} x_t + b_{ir} + W_{hr} h_{(t-1)} + b_{hr}) \\
            z_t = \sigma(W_{iz} x_t + b_{iz} + W_{hz} h_{(t-1)} + b_{hz}) \\
            n_t = \tanh(W_{in} x_t + b_{in} + r_t * (W_{hn} h_{(t-1)}+ b_{hn})) \\
            h_t = (1 - z_t) * n_t + z_t * h_{(t-1)}
        \end{array}

    where :math:`h_t` is the hidden state at time `t`, :math:`x_t` is the input
    at time `t`, :math:`h_{(t-1)}` is the hidden state of the layer
    at time `t-1` or the initial hidden state at time `0`, and :math:`r_t`,
    :math:`z_t`, :math:`n_t` are the reset, update, and new gates, respectively.
    :math:`\sigma` is the sigmoid function, and :math:`*` is the Hadamard product.

    In a multilayer GRU, the input :math:`x^{(l)}_t` of the :math:`l` -th layer
    (:math:`l >= 2`) is the hidden state :math:`h^{(l-1)}_t` of the previous layer multiplied by
    dropout :math:`\delta^{(l-1)}_t` where each :math:`\delta^{(l-1)}_t` is a Bernoulli random
    variable which is :math:`0` with probability :attr:`dropout`.

    Args:
        input_size: The number of expected features in the input `x`
        hidden_size: The number of features in the hidden state `h`
        num_layers: Number of recurrent layers. E.g., setting ``num_layers=2``
            would mean stacking two GRUs together to form a `stacked GRU`,
            with the second GRU taking in outputs of the first GRU and
            computing the final results. Default: 1
        bias: If ``False``, then the layer does not use bias weights `b_ih` and `b_hh`.
            Default: ``True``
        batch_first: If ``True``, then the input and output tensors are provided
            as `(batch, seq, feature)` instead of `(seq, batch, feature)`.
            Note that this does not apply to hidden or cell states. See the
            Inputs/Outputs sections below for details.  Default: ``False``
        dropout: If non-zero, introduces a `Dropout` layer on the outputs of each
            GRU layer except the last layer, with dropout probability equal to
            :attr:`dropout`. Default: 0
        bidirectional: If ``True``, becomes a bidirectional GRU. Default: ``False``

    Inputs: input, h_0
        * **input**: tensor of shape :math:`(L, N, H_{in})` when ``batch_first=False`` or
          :math:`(N, L, H_{in})` when ``batch_first=True`` containing the features of
          the input sequence.  The input can also be a packed variable length sequence.
          See :func:`torch.nn.utils.rnn.pack_padded_sequence` or
          :func:`torch.nn.utils.rnn.pack_sequence` for details.
        * **h_0**: tensor of shape :math:`(D * \text{num\_layers}, N, H_{out})` containing the initial hidden
          state for each element in the batch. Defaults to zeros if not provided.

        where:

        .. math::
            \begin{aligned}
                N ={} & \text{batch size} \\
                L ={} & \text{sequence length} \\
                D ={} & 2 \text{ if bidirectional=True otherwise } 1 \\
                H_{in} ={} & \text{input\_size} \\
                H_{out} ={} & \text{hidden\_size}
            \end{aligned}

    Outputs: output, h_n
        * **output**: tensor of shape :math:`(L, N, D * H_{out})` when ``batch_first=False`` or
          :math:`(N, L, D * H_{out})` when ``batch_first=True`` containing the output features
          `(h_t)` from the last layer of the GRU, for each `t`. If a
          :class:`torch.nn.utils.rnn.PackedSequence` has been given as the input, the output
          will also be a packed sequence.
        * **h_n**: tensor of shape :math:`(D * \text{num\_layers}, N, H_{out})` containing the final hidden state
          for each element in the batch.

    Attributes:
        weight_ih_l[k] : the learnable input-hidden weights of the :math:`\text{k}^{th}` layer
            (W_ir|W_iz|W_in), of shape `(3*hidden_size, input_size)` for `k = 0`.
            Otherwise, the shape is `(3*hidden_size, num_directions * hidden_size)`
        weight_hh_l[k] : the learnable hidden-hidden weights of the :math:`\text{k}^{th}` layer
            (W_hr|W_hz|W_hn), of shape `(3*hidden_size, hidden_size)`
        bias_ih_l[k] : the learnable input-hidden bias of the :math:`\text{k}^{th}` layer
            (b_ir|b_iz|b_in), of shape `(3*hidden_size)`
        bias_hh_l[k] : the learnable hidden-hidden bias of the :math:`\text{k}^{th}` layer
            (b_hr|b_hz|b_hn), of shape `(3*hidden_size)`

    .. note::
        All the weights and biases are initialized from :math:`\mathcal{U}(-\sqrt{k}, \sqrt{k})`
        where :math:`k = \frac{1}{\text{hidden\_size}}`

    .. note::
        For bidirectional GRUs, forward and backward are directions 0 and 1 respectively.
        Example of splitting the output layers when ``batch_first=False``:
        ``output.view(seq_len, batch, num_directions, hidden_size)``.

    .. include:: ../cudnn_persistent_rnn.rst

    Examples::

        >>> rnn = nn.GRU(10, 20, 2)
        >>> input = torch.randn(5, 3, 10)
        >>> h0 = torch.randn(2, 3, 20)
        >>> output, hn = rnn(input, h0)
    c                    s2   d|v rt dƒ‚tt| ƒjdg|¢R i |¤Ž d S )Nr$   r¶   r,   )rN   rG   r,   rH   r¾   rc   r   r   rH   )  s    zGRU.__init__Nr–   c                 C   s   d S r   r   rÀ   r   r   r   r¢   .  s    zGRU.forwardc                 C   s   d S r   r   rÀ   r   r   r   r¢   3  s    c                 C   sJ  |}t |tƒr,|\}}}}|d }t|ƒ}n&d }| jr@| d¡n| d¡}d }d }|d u rŠ| jrddnd}tj| j| || j	|j
|jd�}n|  ||¡}|  |||¡ |d u rÖt ||| j| j| j| j| j| j| j¡	}	n&t |||| j| j| j| j| j| j¡	}	|	d }
|	d }t |tƒ�r6t|
|||ƒ}||  ||¡fS |
|  ||¡fS d S r—   )rJ   r   r‡   r!   r„   r#   rT   r™   r   r   r)   r(   r•   r’   r   ZgrurZ   r    r"   r›   )rD   r€   rŒ   rÁ   r�   rœ   r�   rž   r^   r    r¡   r‘   rÂ   r   r   r   r¢   8  s<    

þÿÿ)N)N)N)r®   r¯   r°   r½   rH   r   rT   rÃ   rÄ   r   r   r   r¢   r   r´   r   r   rc   r   r,   Â  s   f$$r,   c                       sz   e Zd ZU g d¢Zeed< eed< eed< eed< eed< deeeeddœ‡ fd	d
„Ze	dœdd„Z
ddœdd„Z‡  ZS )ÚRNNCellBase)r   r   r    r   r   r    Ú	weight_ihÚ	weight_hhN)r   r   r    Ú
num_chunksr   c                    sÌ   ||dœ}t t| ƒ ¡  || _|| _|| _ttj|| |ffi |¤Žƒ| _	ttj|| |ffi |¤Žƒ| _
|r¨ttj|| fi |¤Žƒ| _ttj|| fi |¤Žƒ| _n|  dd ¡ |  dd ¡ |  ¡  d S )Nr'   Úbias_ihÚbias_hh)rG   rÅ   rH   r   r   r    r   rT   rU   rÆ   rÇ   rÉ   rÊ   Zregister_parameterr\   )rD   r   r   r    rÈ   r(   r)   r]   rc   r   r   rH   l  s    
  zRNNCellBase.__init__rk   c                 C   sN   d}d| j v r | jdur |d7 }d| j v r<| jdkr<|d7 }|jf i | j ¤ŽS )Nr£   r    Tr¤   r·   r¸   z, nonlinearity={nonlinearity})r¥   r    r·   r5   r¦   r   r   r   r¨   ~  s    zRNNCellBase.extra_reprc                 C   s2   dt  | j¡ }|  ¡ D ]}t || |¡ qd S rx   ry   r}   r   r   r   r\   †  s    zRNNCellBase.reset_parameters)NN)r®   r¯   r°   r±   r‡   r²   rM   r   rH   rª   r¨   r\   r´   r   r   rc   r   rÅ   a  s   
 ÿ
ÿrÅ   c                       sZ   e Zd ZU dZg d¢Zeed< deeeeddœ‡ fdd	„Z	de
ee
 e
d
œdd„Z‡  ZS )ÚRNNCellaê  An Elman RNN cell with tanh or ReLU non-linearity.

    .. math::

        h' = \tanh(W_{ih} x + b_{ih}  +  W_{hh} h + b_{hh})

    If :attr:`nonlinearity` is `'relu'`, then ReLU is used in place of tanh.

    Args:
        input_size: The number of expected features in the input `x`
        hidden_size: The number of features in the hidden state `h`
        bias: If ``False``, then the layer does not use bias weights `b_ih` and `b_hh`.
            Default: ``True``
        nonlinearity: The non-linearity to use. Can be either ``'tanh'`` or ``'relu'``. Default: ``'tanh'``

    Inputs: input, hidden
        - **input** of shape `(batch, input_size)`: tensor containing input features
        - **hidden** of shape `(batch, hidden_size)`: tensor containing the initial hidden
          state for each element in the batch.
          Defaults to zero if not provided.

    Outputs: h'
        - **h'** of shape `(batch, hidden_size)`: tensor containing the next hidden state
          for each element in the batch

    Shape:
        - Input1: :math:`(N, H_{in})` tensor containing input features where
          :math:`H_{in}` = `input_size`
        - Input2: :math:`(N, H_{out})` tensor containing the initial hidden
          state for each element in the batch where :math:`H_{out}` = `hidden_size`
          Defaults to zero if not provided.
        - Output: :math:`(N, H_{out})` tensor containing the next hidden state
          for each element in the batch

    Attributes:
        weight_ih: the learnable input-hidden weights, of shape
            `(hidden_size, input_size)`
        weight_hh: the learnable hidden-hidden weights, of shape
            `(hidden_size, hidden_size)`
        bias_ih: the learnable input-hidden bias, of shape `(hidden_size)`
        bias_hh: the learnable hidden-hidden bias, of shape `(hidden_size)`

    .. note::
        All the weights and biases are initialized from :math:`\mathcal{U}(-\sqrt{k}, \sqrt{k})`
        where :math:`k = \frac{1}{\text{hidden\_size}}`

    Examples::

        >>> rnn = nn.RNNCell(10, 20)
        >>> input = torch.randn(6, 3, 10)
        >>> hx = torch.randn(3, 20)
        >>> output = []
        >>> for i in range(6):
                hx = rnn(input[i], hx)
                output.append(hx)
    )r   r   r    r·   r·   Tr¸   N)r   r   r    r·   r   c                    s4   ||dœ}t t| ƒj|||fddi|¤Ž || _d S )Nr'   rÈ   r	   )rG   rË   rH   r·   )rD   r   r   r    r·   r(   r)   r]   rc   r   r   rH   È  s    
 zRNNCell.__init__r–   c                 C   sŽ   |d u r&t j| d¡| j|j|jd�}| jdkrNt ||| j	| j
| j| j¡}n<| jdkrvt ||| j	| j
| j| j¡}n|}td | j¡ƒ‚|S )Nr   r˜   r¸   r¹   zUnknown nonlinearity: {})rT   r™   r„   r   r)   r(   r·   r   Zrnn_tanh_cellrÆ   rÇ   rÉ   rÊ   Zrnn_relu_cellrƒ   r5   )rD   r€   rŒ   rw   r   r   r   r¢   Î  s&    
ý
ý
ÿzRNNCell.forward)Tr¸   NN)N)r®   r¯   r°   r½   r±   rª   r²   r‡   rM   rH   r   r   r¢   r´   r   r   rc   r   rË   Œ  s   
8  ÿ
ÿrË   c                       sV   e Zd ZdZd
eeeddœ‡ fdd„Zdeee	eef  e	eef dœdd	„Z
‡  ZS )ÚLSTMCellaÞ	  A long short-term memory (LSTM) cell.

    .. math::

        \begin{array}{ll}
        i = \sigma(W_{ii} x + b_{ii} + W_{hi} h + b_{hi}) \\
        f = \sigma(W_{if} x + b_{if} + W_{hf} h + b_{hf}) \\
        g = \tanh(W_{ig} x + b_{ig} + W_{hg} h + b_{hg}) \\
        o = \sigma(W_{io} x + b_{io} + W_{ho} h + b_{ho}) \\
        c' = f * c + i * g \\
        h' = o * \tanh(c') \\
        \end{array}

    where :math:`\sigma` is the sigmoid function, and :math:`*` is the Hadamard product.

    Args:
        input_size: The number of expected features in the input `x`
        hidden_size: The number of features in the hidden state `h`
        bias: If ``False``, then the layer does not use bias weights `b_ih` and
            `b_hh`. Default: ``True``

    Inputs: input, (h_0, c_0)
        - **input** of shape `(batch, input_size)`: tensor containing input features
        - **h_0** of shape `(batch, hidden_size)`: tensor containing the initial hidden
          state for each element in the batch.
        - **c_0** of shape `(batch, hidden_size)`: tensor containing the initial cell state
          for each element in the batch.

          If `(h_0, c_0)` is not provided, both **h_0** and **c_0** default to zero.

    Outputs: (h_1, c_1)
        - **h_1** of shape `(batch, hidden_size)`: tensor containing the next hidden state
          for each element in the batch
        - **c_1** of shape `(batch, hidden_size)`: tensor containing the next cell state
          for each element in the batch

    Attributes:
        weight_ih: the learnable input-hidden weights, of shape
            `(4*hidden_size, input_size)`
        weight_hh: the learnable hidden-hidden weights, of shape
            `(4*hidden_size, hidden_size)`
        bias_ih: the learnable input-hidden bias, of shape `(4*hidden_size)`
        bias_hh: the learnable hidden-hidden bias, of shape `(4*hidden_size)`

    .. note::
        All the weights and biases are initialized from :math:`\mathcal{U}(-\sqrt{k}, \sqrt{k})`
        where :math:`k = \frac{1}{\text{hidden\_size}}`

    Examples::

        >>> rnn = nn.LSTMCell(10, 20) # (input_size, hidden_size)
        >>> input = torch.randn(2, 3, 10) # (time_steps, batch, input_size)
        >>> hx = torch.randn(3, 20) # (batch, hidden_size)
        >>> cx = torch.randn(3, 20)
        >>> output = []
        >>> for i in range(input.size()[0]):
                hx, cx = rnn(input[i], (hx, cx))
                output.append(hx)
        >>> output = torch.stack(output, dim=0)
    TN©r   r   r    r   c                    s.   ||dœ}t t| ƒj|||fddi|¤Ž d S )Nr'   rÈ   r+   )rG   rÌ   rH   ©rD   r   r   r    r(   r)   r]   rc   r   r   rH   "  s    
zLSTMCell.__init__r–   c                 C   sJ   |d u r.t j| d¡| j|j|jd�}||f}t ||| j| j	| j
| j¡S ©Nr   r˜   )rT   r™   r„   r   r)   r(   r   Z	lstm_cellrÆ   rÇ   rÉ   rÊ   )rD   r€   rŒ   r™   r   r   r   r¢   '  s    ýzLSTMCell.forward)TNN)N)r®   r¯   r°   r½   r‡   rM   rH   r   r   r   r¢   r´   r   r   rc   r   rÌ   ä  s   =  ÿÿrÌ   c                       sF   e Zd ZdZd
eeeddœ‡ fdd„Zdeee edœdd	„Z	‡  Z
S )ÚGRUCellaP	  A gated recurrent unit (GRU) cell

    .. math::

        \begin{array}{ll}
        r = \sigma(W_{ir} x + b_{ir} + W_{hr} h + b_{hr}) \\
        z = \sigma(W_{iz} x + b_{iz} + W_{hz} h + b_{hz}) \\
        n = \tanh(W_{in} x + b_{in} + r * (W_{hn} h + b_{hn})) \\
        h' = (1 - z) * n + z * h
        \end{array}

    where :math:`\sigma` is the sigmoid function, and :math:`*` is the Hadamard product.

    Args:
        input_size: The number of expected features in the input `x`
        hidden_size: The number of features in the hidden state `h`
        bias: If ``False``, then the layer does not use bias weights `b_ih` and
            `b_hh`. Default: ``True``

    Inputs: input, hidden
        - **input** of shape `(batch, input_size)`: tensor containing input features
        - **hidden** of shape `(batch, hidden_size)`: tensor containing the initial hidden
          state for each element in the batch.
          Defaults to zero if not provided.

    Outputs: h'
        - **h'** of shape `(batch, hidden_size)`: tensor containing the next hidden state
          for each element in the batch

    Shape:
        - Input1: :math:`(N, H_{in})` tensor containing input features where
          :math:`H_{in}` = `input_size`
        - Input2: :math:`(N, H_{out})` tensor containing the initial hidden
          state for each element in the batch where :math:`H_{out}` = `hidden_size`
          Defaults to zero if not provided.
        - Output: :math:`(N, H_{out})` tensor containing the next hidden state
          for each element in the batch

    Attributes:
        weight_ih: the learnable input-hidden weights, of shape
            `(3*hidden_size, input_size)`
        weight_hh: the learnable hidden-hidden weights, of shape
            `(3*hidden_size, hidden_size)`
        bias_ih: the learnable input-hidden bias, of shape `(3*hidden_size)`
        bias_hh: the learnable hidden-hidden bias, of shape `(3*hidden_size)`

    .. note::
        All the weights and biases are initialized from :math:`\mathcal{U}(-\sqrt{k}, \sqrt{k})`
        where :math:`k = \frac{1}{\text{hidden\_size}}`

    Examples::

        >>> rnn = nn.GRUCell(10, 20)
        >>> input = torch.randn(6, 3, 10)
        >>> hx = torch.randn(3, 20)
        >>> output = []
        >>> for i in range(6):
                hx = rnn(input[i], hx)
                output.append(hx)
    TNrÍ   c                    s.   ||dœ}t t| ƒj|||fddi|¤Ž d S )Nr'   rÈ   r   )rG   rÐ   rH   rÎ   rc   r   r   rH   p  s    
zGRUCell.__init__r–   c                 C   sB   |d u r&t j| d¡| j|j|jd�}t ||| j| j	| j
| j¡S rÏ   )rT   r™   r„   r   r)   r(   r   Zgru_cellrÆ   rÇ   rÉ   rÊ   rÀ   r   r   r   r¢   u  s    ýzGRUCell.forward)TNN)N)r®   r¯   r°   r½   r‡   rM   rH   r   r   r¢   r´   r   r   rc   r   rÐ   2  s   =  ÿÿrÐ   )r	   )"rz   rO   rK   Útypingr   r   r   r   r   r   rT   r   Úmoduler
   Z	parameterr   Z	utils.rnnr   r.   r   r   Zrnn_tanhZrnn_relurš   r‡   r   r   rµ   r*   r,   rÅ   rË   rÌ   rÐ   r   r   r   r   Ú<module>   s4    þ  Gy m  +XN