
    &Vf(                         d dl Zd dlmZ 	 	 	 	 	 	 	 	 ddZ	 	 	 	 	 ddZd Zd Zd	 Zd
 Z	ddZ
d Zd Zd Zd Z	 ddZ	 	 	 	 ddZd ZdS )    N)treeFTc           	      6   	
*+,-./01234 pj         d         d }|st          j        |          t          j                  }|d         j         d         }| t	          j         |d                   d         n|4|D ]}|j                             d           |o|j        t          j        k    rt	          j        |t          j                  }t          |j                   dk    rt	          j
        |d          }|s ||          }g d(d	*|r|st          d
          t                    }g }g }fd}t          j                  rt          j        |          2n |          f22fd}|t	          j        |          }r|                                 t!          |          D ]8} ||          }||         .  |t          |          t                    z             \  }} *.|          }|st	          j        |          }n|d         }t	          j        |||          }t          j        |          }t          j        |          }t          *.fd|D                       }t          d t'          |||          D                       }t          j        ||          }
r,|                    |           |                    |           2|g}|g}:|d         }|d         }t	          j        |          }	rlt	          j         *|d         |          |t	          j        |                    }t	          j         *||d          |t	          j        |                    }nmt!          |          D ]l} ||          }  |t          |          t                    z             \  }}
r+|                    |           |                    |           f|g}|g}m|d         }|d         }t	          j        |          }nt                    }t          4fdt/          |          D                       -t          fdt'          -|          D                       -t          j        d |D                       }   | t                    t                    z             \  }!}"
r4nd1t          1fdt/          t          j        |!                    D                       }#t	          j        ddd          }$4}%nt	          j                  }%4fd|%ddd}&|Yrt	          j        |dg          }t	          j        t          j        4d          //                    |          //fd0*fd+n[t7          t          j                  r?r4t	          j        d          }'t	          j        |'dz
            33fd0nfd 0d! +nd00]t          d" t          j        |!          D                       ,+,-0
 	f	d#}(t	          j        d)|(|$|#,f|z   d$|&})|)dd         }n--
 fd%}(t	          j        d)|(|$|#f|z   d$|&})|)dd         }|)d         }#t          d& |#D                       }t          d' |D                       }t          j        |!|          }t          j        |!|          }|st          j        ||          }|||fS )*aS  Iterates over the time dimension of a tensor.

    Args:
        step_function: RNN step function.
            Args;
                `input`; Tensor with shape `(samples, ...)` (no time dimension),
                    representing input for the batch of samples at a certain
                    time step.
                `states`; List of tensors.
            Returns;
                `output`; Tensor with shape `(samples, output_dim)`
                    (no time dimension).
                `new_states`; List of tensors, same length and shapes
                    as 'states'. The first state in the list must be the
                    output tensor at the previous timestep.
        inputs: Tensor of temporal data of shape `(samples, time, ...)`
            (at least 3D), or nested tensors, and each of which has shape
            `(samples, time, ...)`.
        initial_states: Tensor with shape `(samples, state_size)`
            (no time dimension), containing the initial values for the states
            used in the step function. In the case that state_size is in a
            nested shape, the shape of initial_states will also follow the
            nested structure.
        go_backwards: Boolean. If `True`, do the iteration over the time
            dimension in reverse order and return the reversed sequence.
        mask: Binary tensor with shape `(samples, time, 1)`,
            with a zero for every element that is masked.
        constants: List of constant values passed at each step.
        unroll: Whether to unroll the RNN or to use a symbolic `while_loop`.
        input_length: An integer or a 1-D Tensor, depending on whether
            the time dimension is fixed-length or not. In case of variable
            length input, it is used for masking in case there's no mask
            specified.
        time_major: Boolean. If `True`, the inputs and outputs will be in shape
            `(timesteps, batch, ...)`, whereas in the False case, it will be
            `(batch, timesteps, ...)`. Using `time_major = True` is a bit more
            efficient because it avoids transposes at the beginning and end of
            the RNN calculation. However, most TensorFlow data is batch-major,
            so by default this function accepts input and emits output in
            batch-major form.
        zero_output_for_mask: Boolean. If `True`, the output for masked timestep
            will be zeros, whereas in the `False` case, output from previous
            timestep is returned.
        return_all_outputs: Boolean. If `True`, return the recurrent outputs for
            all timesteps in the sequence. If `False`, only return the output
            for the last timestep (which consumes less memory).

    Returns:
        A tuple, `(last_output, outputs, new_states)`.
            - `last_output`: the latest output of the rnn,
                with shape `(samples, ...)`.
            - `outputs`:
                - If `return_all_outputs=True`: a tensor with shape
                  `(samples, time, ...)` where each entry `outputs[s, t]` is the
                  output of the step function at time `t` for sample `s`
                - Else, a tensor equal to `last_output` with shape
                  `(samples, 1, ...)`
            - `new_states`: list of tensors, latest states returned by
                the step function, of shape `(samples, ...)`.
       c                     t          t          t          | j                                      }d\  |d<   |d<   t	          j        | |          S )Nr   r   r   r   )listrangelenshapetf	transpose)input_taxess     ]/var/www/html/software/conda/lib/python3.11/site-packages/keras/src/backend/tensorflow/rnn.pyswap_batch_timestepz rnn.<locals>.swap_batch_timestepQ   sE    E#gm,,--..Qa|GT***    r   N      axisc                    t          j        |           rt          d|            t          j        |          rt          d|           t          |j                  t          | j                  z
  }t          |          D ]}t          j        | d          } dg|z  |j                                        |d          z   }t          j	        | |          S )Nz)mask_t is expected to be tensor, but got z*input_t is expected to be tensor, but got r   r   )
r   	is_nested
ValueErrorr
   r   r	   r   expand_dimsas_listtile)mask_tr   	fixed_dim	rank_diff_	multipless         r   _expand_maskzrnn.<locals>._expand_maskt   s    >&!! 	DFDD   >'"" 	FWFF   &&V\):)::	y!! 	0 	0A^FB//FFC)Ogm&;&;&=&=ijj&II	wvy)))r   z/Unrolling requires a fixed number of timesteps.c                 \    t          j        |           } r|                                  | S N)r   unstackreverse)r   go_backwardss    r   _process_single_input_tz$rnn.<locals>._process_single_input_t   s/    j))G "!!!Nr   c                 L      fdD             }t          j        |          S )Nc                      g | ]
}|         S  r,   ).0t_times     r   
<listcomp>z2rnn.<locals>._get_input_tensor.<locals>.<listcomp>   s    6662d8666r   )r   pack_sequence_as)r/   inpinputsprocessed_inputs   ` r   _get_input_tensorzrnn.<locals>._get_input_tensor   s0    6666o666C(555r   c              3   0   K   | ]} |          V  d S r%   r,   )r-   sr#   r   s     r   	<genexpr>zrnn.<locals>.<genexpr>   s@       % %01LL++% % % % % %r   c              3   J   K   | ]\  }}}t          j        |||          V  d S r%   r   where)r-   mr7   pss       r   r8   zrnn.<locals>.<genexpr>   sJ       * * 1b HQ2&&* * * * * *r   r   c              3   \   K   | ]&\  }}t          j        |j        d |           V  'dS )	input_ta_dtypesizetensor_array_nameN)r   TensorArrayrB   )r-   ir2   time_steps_ts      r   r8   zrnn.<locals>.<genexpr>   s_       
 
 3 Ni!"1a//  
 
 
 
 
 
r   c              3      K   | ]G\  }}s|                     |          n(|                     t          j        |d g                    V  HdS )r   N)r&   r   r'   )r-   tainput_r(   s      r   r8   zrnn.<locals>.<genexpr>   sp       
 
 F $9

6"""ZZ
6A3 7 788	
 
 
 
 
 
r   c                     g | ]
}|d          S )r   r,   )r-   r2   s     r   r0   zrnn.<locals>.<listcomp>  s    888SV888r   c              3   h   K   | ],\  }}t          j        |j        |j        d |           V  -dS )
output_ta_)rB   rC   element_shaperD   N)r   rE   rB   r   )r-   rF   outoutput_ta_sizes      r   r8   zrnn.<locals>.<genexpr>  sf       
 
 3 Ni#!i"2q"2"2	  
 
 
 
 
 
r   int32r/   )rB   namec                     | k     S r%   r,   )r/   r!   rG   s     r   <lambda>zrnn.<locals>.<lambda>  s    TL%8 r       T)condmaximum_iterationsparallel_iterationsswap_memorymask_tarA   c                 .                         |           S r%   read)r/   rZ   s    r   
masking_fnzrnn.<locals>.masking_fn+  s    ||D)))r   c                      t           fd|D                       }t          d t          |||          D                       S )Nc              3   X   K   | ]$} |t          j                             V  %dS )r>   N)r
   r   )r-   or#   r   s     r   r8   z5rnn.<locals>.compute_masked_output.<locals>.<genexpr>/  sR       % % !Lc&,6G6GHHH% % % % % %r   c              3   J   K   | ]\  }}}t          j        |||          V  d S r%   r:   )r-   r<   ra   fms       r   r8   z5rnn.<locals>.compute_masked_output.<locals>.<genexpr>3  sJ         1b HQ2&&     r   tuplezip)r   flat_out	flat_masktiled_mask_tr#   s   `   r   compute_masked_outputz"rnn.<locals>.compute_masked_output.  sz    $ % % % % %%% % %       $'h	$J$J     r   c                 .    t          j        |           S r%   )r   less)r/   rev_input_lengths    r   r^   zrnn.<locals>.masking_fn=  s    7#3T:::r   c                 .    t          j        |           S r%   )r   greater)r/   input_lengths    r   r^   zrnn.<locals>.masking_fnB  s    :lD999r   c                 V     t           fdt          ||          D                       S )Nc              3   J   K   | ]\  }}t          j        ||          V  d S r%   r:   )r-   ra   zor   s      r   r8   z5rnn.<locals>.compute_masked_output.<locals>.<genexpr>F  sI        B HVQ++     r   rd   )r   rg   rh   s   `  r   rj   z"rnn.<locals>.compute_masked_outputE  sE        #&x#;#;     r   c              3   >   K   | ]}t          j        |          V  d S r%   )r   
zeros_liker-   ra   s     r   r8   zrnn.<locals>.<genexpr>Q  s=       % %%&a  % % % % % %r   c                   	  t           fdD                       }t          j        |          }            } |t          |          t                    z             \  }}t          j        |          }rnt          j        |          }	 |||	          }
t          j        |          }t          j        |          } |||          }t          j        ||          }r ndt          fdt	          ||
          D                       } dz   |t          |
          ft          |          z   S )as  RNN step function.

                Args:
                    time: Current timestep value.
                    output_ta_t: TensorArray.
                    prev_output: tuple of outputs from time - 1.
                    *states: List of states.

                Returns:
                    Tuple: `(time + 1, output_ta_t, output) + tuple(new_states)`
                c              3   B   K   | ]}|                               V  d S r%   r\   r-   rI   r/   s     r   r8   z%rnn.<locals>._step.<locals>.<genexpr>a  -      %G%Gbggdmm%G%G%G%G%G%Gr   r   c              3   J   K   | ]\  }}|                     |          V  d S r%   writer-   rI   rO   ta_index_to_writes      r   r8   z%rnn.<locals>._step.<locals>.<genexpr>|  J       $ $C HH.44$ $ $ $ $ $r   r   re   r   r1   flattenrf   )r/   output_ta_tprev_outputstatescurrent_inputr   output
new_statesflat_outputflat_mask_outputflat_new_output
flat_stateflat_new_stateflat_final_stater   rj   	constantsflat_zero_outputinput_tar3   r^   return_all_outputsstep_functionzero_output_for_masks   `             @r   _stepzrnn.<locals>._stepU  s    !&%G%G%G%Gh%G%G%G G G $ 5fm L L#D))%2]!5==53C3C#C& &"
 #l622 ,3$$k22 !
 #8"7K)9# #
 "\&11
!%j!9!9#8#8NJ$ $  "2:?OPP
,>$EDDA!# $ $ $ $#&{O#D#D$ $ $  
 q+u_/E/EFJ J  r   )body	loop_varsc                     t           fdD                       }t          j        |          } |t          |          t          	          z             \  }}t          j        |          }t          j        |          }r ndt          fdt	          ||          D                       }t          j        
|          } dz   |ft          |          z   S )a)  RNN step function.

                Args:
                    time: Current timestep value.
                    output_ta_t: TensorArray.
                    *states: List of states.

                Returns:
                    Tuple: `(time + 1,output_ta_t) + tuple(new_states)`
                c              3   B   K   | ]}|                               V  d S r%   r\   ry   s     r   r8   z%rnn.<locals>._step.<locals>.<genexpr>  rz   r   r   c              3   J   K   | ]\  }}|                     |          V  d S r%   r|   r~   s      r   r8   z%rnn.<locals>._step.<locals>.<genexpr>  r   r   r   r   )r/   r   r   r   r   r   r   r   r   r   initial_statesr   r3   r   r   s   `       @r   r   zrnn.<locals>._step  s    !&%G%G%G%Gh%G%G%G G G $ 5fm L L%2]!5==53C3C#C& &"
 "&j!9!9"l622,>$EDDA!# $ $ $ $#&{K#@#@$ $ $  
 "2"N 
 q+.z1B1BBBr   c              3   >   K   | ]}|                                 V  d S r%   )stackrv   s     r   r8   zrnn.<locals>.<genexpr>  s*      55a		555555r   c              3   &   K   | ]}|d          V  dS )r   Nr,   rv   s     r   r8   zrnn.<locals>.<genexpr>  s&      33aAbE333333r   )r   r,   )r   r   map_structurer   r   with_rank_at_leastrB   boolcastr
   r   r   re   r   r&   r'   r	   ru   r;   rf   r1   appendr   	enumerateconstant
reduce_maxrE   
isinstanceTensorsubtract
while_loop)5r   r3   r   r(   maskr   unrollrp   
time_majorr   r   r   flattened_inputs
time_stepsrJ   r   successive_statessuccessive_outputsr)   r5   	mask_listrF   r2   r   r   ri   r   flat_statesflat_new_statesflat_final_stateslast_outputoutputsinput_time_zerooutput_time_zeror!   	output_tar/   max_iterationswhile_loop_kwargsmax_lenr   final_outputsr#   rj   r   r   r   rZ   r^   rP   r4   rm   rG   s5   ```` ` ` ``                               @@@@@@@@@@@r   rnnr      s	   R  26<?L+ + +  A#$7@@|F++!!$*1-J,6,>!!$%%a((J  # + +''****:  74))Dtz??a>$R000D 	-&&t,,D	* * * *  vK 	PNOOO~&&	 	 	 	 	 >&!! 	A"0' OO  76v>>@O	6 	6 	6 	6 	6 	6 
4((I $!!###:&& !1 !1''**"1%2]vy)9)99& &"
  ,|FF;;) 9"$-"7"7KK"4R"8K,DD"l622"&,z":":$ % % % % %5@% % %     %* * *$'$o{% %* * * % %! .v7HII% 1&--f555%,,V4444*0&)/%%,R0K*2.Jh122G# 
 h L2<<M+.. 
 ( Lw!<<<M'**  :&& 
1 
1''**!.vy)9)99" " & 1&--f555%,,V4444*0&)/%%,R0K*2.Jh122GG ~&&
  
 
 
 
 $$455
 
 
 
 
  
 
 
 
 "(,<==
 
 
 
 
 /88'7888
 

 ,mU>22U95E5EE
 
! *<B 
 
 
 
 $DL1A$B$BCC
 
 
 
 
	 {1G&999)NN]<88N 9888"0#%	
 
  -z$,,ngLI  G ood++G* * * * *      bi00 	 
:-1===#%;w{L#I#I ; ; ; ; ; ;
: : : : :    J!  % % %*.,7G*H*H% % %    . . . . . . . . . . . . .` M ,<=F  $ M 'qrr*JJC C C C C C C C C C< M +f4  $ M
 'qrr*J!!$	5595555533733333'(8'BB+,<kJJ C$%8'BB++r   c                 x   t          |||
|d u|          }|st          ddlm} t	          ||          r|j        }t	          ||          r|j        }t	          ||          r|j        }	 t          | |||||||	|	  	        S # t          j        j	        $ r t          t          j        j
        $ r t          w xY w)N)use_biasreset_afterr   Variable)cudnn_okNotImplementedErrorkeras.src.backend.tensorflowr   r   value
_cudnn_grur   errorsInvalidArgumentErrorNotFoundError)r3   initial_stater   kernelrecurrent_kernelbias
activationrecurrent_activationreturn_sequencesr(   r   r   r   cudnn_supportedr   s                  r   grur     s    T!  O  "!!555555&(## "H-- 2+1$!! z"

 

 
	
 9) " " "!!9" " " "!!"s   ,B 6B9c                     ddl m} ddl m} | |j        t          j        |j        fv o!||j        t          j        |j        fv o| o|o|S Nr   )activations)ops	keras.srcr   r   tanhr   sigmoid)r   r   r   r   r   r   r   s          r   _do_gru_arguments_support_cudnnr     s     &%%%%% 	{'#(;; 	 S[9:	 J	 		
 r   c                     ddl m} ddl m} | |j        t          j        |j        fv o||j        t          j        |j        fv o| o|S r   r   )r   r   r   r   r   r   s         r    _do_lstm_arguments_support_cudnnr     sy     &%%%%% 	{'#(;; 	 S[9:	 J	 r   c           
          t          j        t          j        t          j        t          j        | d                    d                    S )Nr   rB   r   r   )r   
reduce_any
reduce_alllogical_notr   )r   s    r   _has_fully_masked_sequencer     sC     =
bnRWT%@%@%@AAJJJ  r   c                     t          j        t          j        t          |                     t	          |                     }t          j        |dg           d S )Na  You are passing a RNN mask that does not correspond to right-padded sequences, while using cuDNN, which is not supported. With cuDNN, RNN masks can only be used for right-padding, e.g. `[[True, True, False, False]]` would be a valid mask, but any mask that isn't just contiguous `True`'s on the left and contiguous `False`'s on the right would be invalid. You can pass `use_cudnn=False` to your RNN layer to stop using cuDNN (this may be slower).)r   logical_andr   r   _is_sequence_right_paddedAssert)r   valids     r   _assert_valid_maskr   (  sb    N
1$7788!$'' E IF	
    r   c                 ~    fdfd| D             } fd|D             }t          j        | |z   d          S )a  Utility function convert variable to cuDNN compatible parameter.

    Note that Keras weights for kernels are different from the cuDNN format.
    Eg.:

    ```
      Keras                 cuDNN
      [[0, 1, 2],  <--->  [[0, 2, 4],
       [3, 4, 5]]          [1, 3, 5]]
    ```

    If the input weights need to be in a unified format, then set
    `transpose_weights=True` to convert the weights.

    Args:
        weights: list of weights for the kernels and recurrent kernels.
        biases: list of biases for individual gate.
        shape: the shape for the converted variables that will be feed to cuDNN.
        transpose_weights: boolean, whether to transpose the weights.

    Returns:
        The converted weights that can be feed to cuDNN ops as param.
    c                 4    rt          j        |           n| S r%   )r   r   )wtranspose_weightss    r   convertz+_standardize_cudnn_weights.<locals>.convertW  s    "3:r|A:r   c                 L    g | ] }t          j         |                    !S r,   r   reshape)r-   xr   r   s     r   r0   z._standardize_cudnn_weights.<locals>.<listcomp>Z  s-    >>>rz''!**e,,>>>r   c                 :    g | ]}t          j        |          S r,   r   )r-   r   r   s     r   r0   z._standardize_cudnn_weights.<locals>.<listcomp>[  s%    333qbjE""333r   r   r   )r   concat)weightsbiasesr   r   r   s     ``@r   _standardize_cudnn_weightsr   >  so    2; ; ; ; ; ?>>>>g>>>G3333F333F9Wv%A....r   c           	      f   t          j        |           d         }t          j        t          j        | t           j                  d          }t          j        ||          }t          j        t          j        t          j        | d          t          j        |d                              S )aJ  Check the mask tensor and see if it right padded.

    cuDNN uses the sequence length param to skip the tailing
    timestep. If the data is left padded, or not a strict right padding (has
    masked value in the middle of the sequence), then cuDNN won't work
    properly in those cases.

    Left padded data: [[False, False, True, True, True]].
    Right padded data: [[True, True, True, False, False]].
    Mixture of mask/unmasked data: [[True, False, True, False, False]].

    Note that for the mixed data example above, the actually data RNN should see
    are those 2 Trues (index 0 and 2), the index 1 False should be ignored and
    not pollute the internal states.

    Args:
        mask: the Boolean tensor with shape [batch, timestep]

    Returns:
        boolean scalar tensor, whether the mask is strictly right padded.
    r   r   )maxlenr   r   )r   r   
reduce_sumr   rQ   sequence_maskr   equal)r   max_seq_lengthcount_of_trueright_padded_masks       r   r   r   _  s    , Xd^^A&NM"'$"9"9BBBM(~NNN=
GD'''G%V444	
 	
  r   c                 t    |rdnd}t          j        t          j        | t           j                  |          S )a^  Calculate the sequence length tensor (1-D) based on the masking tensor.

    The masking tensor is a 2D boolean tensor with shape [batch, timestep]. For
    any timestep that should be masked, the corresponding field will be False.
    Consider the following example:
      a = [[True, True, False, False],
           [True, True, True, False]]
    It is a (2, 4) tensor, and the corresponding sequence length result should
    be 1D tensor with value [2, 3]. Note that the masking tensor must be right
    padded that could be checked by, e.g., `is_sequence_right_padded()`.

    Args:
        mask: Boolean tensor with shape [batch, timestep] or [timestep, batch]
            if time_major=True.
        time_major: Boolean, which indicates whether the mask is time major or
            batch major.

    Returns:
        sequence_length: 1D int32 tensor.
    r   r   r   )r   r   r   rQ   )r   r   timestep_indexs      r   "_compute_sequence_length_from_maskr    s5    * %+QQ!N=rx00~FFFFr   c                  Z    t          t          j                            d                    S )NGPU)r   r   configlist_logical_devicesr,   r   r   _is_gpu_availabler
    s     	..u55666r   c	           
      x   | t          |           t          ||          }	n|r5t          j        |           d         }
t          j        |           d         }n4t          j        |           d         }
t          j        |           d         }t          j        |
g|          }	|s|	t          j        | d          } d\  }}n	|rdnd\  }}t          j        ||          }t          j        |d	d          }|t          j        |d	d          z  }t          j        t          j        |d
g          d          }t          j	        
                                d         r\|d         |d         c|d<   |d<   |d         |d	         c|d	<   |d<   |d         |d         c|d<   |d<   |d         |d	         c|d	<   |d<   t          ||t          j        d
g          d          }|rt          j        | |	||          } t          j                            | |d|dd|	|          \  }}}}}|r/t          j        ||	||          }t          j        ||g          }|d
         }|s|	|rt          j        |g d          }t          j        ||          }|	|}|st          j        ||rdnd          }|||fS )z>GRU with cuDNN implementation which is only available for GPU.Nr   r   r   r   r   permr   r   r   r   r   r      is_cuda_build   Tr   r   r   r   seq_axis
batch_axisr   inputinput_hinput_cparamsis_trainingrnn_modesequence_lengthsr   )r   r  r   r   fillr   r   splitr   	sysconfigget_build_infor   r   reverse_sequenceraw_ops
CudnnRNNV3r'   squeeze)r3   r   r   r   r   r   r   r(   r   r  	batch_dimmax_sequence_lengthr  r  init_hr   r  r   hr!   r   states                         r   r   r     sI    4   =dJOO 	6((+I"$(6"2"21"5((+I"$(6"2"21"57I;0CDD @*2f9555%**)3?vv* ^M999Fhvqq)))Grx(!!4444G 8BJtbT**A..D	|""$$_5 , ")WQZ
GAJ!(WQZ
GAJ7DGQa7DGQa'k2$	  F  
 $!	
 
 
 *//) 0 	 	GQ1a  7%!	
 
 
 *WH:666"+K 8*27G2,wYYY777Jqx(((E #  K.
3I11JJJ 	 r   c                 v    |t          | |||          }nt          | ||||          }|ot                      S )N)r   r   r   r   )r   r   r   r   r   )r   r   r
  )r   r   r   r   r   args_supporteds         r   r   r     se     9!!5	
 
 
 9!!5#
 
 
 1/111r   c                 x   t          ||||d u          }|st          ddlm} t	          ||          r|j        }t	          ||          r|j        }t	          ||          r|j        }	 t          | ||||||||
|	
  
        S # t          j        j	        $ r t          t          j        j
        $ r t          w xY w)N)r   r   r   )r   r   r   r   r   r   _cudnn_lstmr   r   r   r   )r3   initial_state_hinitial_state_cr   r   r   r   r   r   r   r(   r   r   r   r   s                  r   lstmr2  *  s    (&4t;K  O  "!!555555&(## "H-- 2+1$!! z"
 
 	
 9) " " "!!9" " " "!!"s   +B 6B9c
           
         | t          |           t          ||          }
n|r5t          j        |           d         }t          j        |           d         }n4t          j        |           d         }t          j        |           d         }t          j        |g|          }
|s|
t          j        | d          } d\  }}n	|rdnd\  }}t          j        ||          }t          j        ||          }t          j        |dd          t          j        |dd          z  t          j        t          j	        |          |fd          t          j
                                        d	         r3fd
dD             t          j        dd          fddD             t          t          j        d          t          j        dg          d          }|rt          j        | |
||          } t          j                            | |||dd|
|          \  }}}}}|r/t          j        ||
||          }t          j        ||g          }|d         }|s|
|	rt          j        |g d          }t          j        ||          }t          j        ||          }|
|}|	st          j        ||rdnd          }||||gfS )Nr   r   r  r  r  r   r   r  is_rocm_buildc                      g | ]
}|         S r,   r,   )r-   r   r   s     r   r0   z_cudnn_lstm.<locals>.<listcomp>  s    @@@!71:@@@r   )r   r   r   r   r        r     c                      g | ]
}|         S r,   r,   )r-   r   	full_biass     r   r0   z_cudnn_lstm.<locals>.<listcomp>  s    DDDaYq\DDDr   r   Tr  r  r2  r  )r   r  r   r   r  r   r   r   r   ru   r!  r"  r   r   r#  r$  r%  r'   r&  )r3   r0  r1  r   r   r   r   r   r(   r   r  r'  r(  r  r  r)  init_cr  r   r*  cr!   r   r:  r   s                          @@r   r/  r/  ]  sX    4   =dJOO 	6((+I"$(6"2"21"5((+I"$(6"2"21"57I;0CDD @*2f9555%**)3?vv* ^O(;;;F^O(;;;Fhvqq)))Grx(!!4444G 	2=..5q99I	|""$$_5 E A@@@'?@@@HY222	DDDD+CDDD	'x	1%%k2$	  F  
 $!	
 
 
 *//) 0 	 	GQ1a  7%!	
 
 
 *WH:666"+K 8*27G2,wYYY777

18$$$A

18$$$A #  K.
3I11JJJ1a&))r   )FNNFNFFT)FFFFT)Fr%   )FFFF)
tensorflowr   r   r   r   r   r   r   r   r   r   r   r  r
  r   r   r2  r/  r,   r   r   <module>r>     sl             	x, x, x, x,H 3" 3" 3" 3"l  (  $    ,/ / / /B  BG G G27 7 7q q qr 2 2 2 2F 0" 0" 0" 0"fn* n* n* n* n*r   