+
    –°³jÊ,  ã                   óö   € ^ RI t ^ RIHt ^ RIt^ RIHt ^ RIHtHtH	t	H
t
 ^ RIHt R tRR ltR tRR	 ltR
 t] P$                  R R l4       t] P$                  R R l4       t] P$                  R R l4       tR# )é    N©Ú	Generator)Úglobal_decomposition_table)Ú_rnn_helperÚgather_paramsÚgru_cellÚ	lstm_cell)Ú
while_loopc                 ó,  a€ . p. pV  F  oSeQ   \         ;QJ d    V3R lV 4       F  '       g   K   RM	  RM! V3R lV 4       4      '       d   SP                  4       oVP                  S4       Sf   Kn  VP                  S4       K�  	  \        V4      # )Nc              3   ód   <"  € T F%  p\         P                  P                  SV4      x € K'  	  R # 5i)N)ÚtorchÚ_CÚ	_overlaps)Ú.0Úseen_tensorÚtensors   & €ÚV/home/luca/screen-checking/.venv/lib/python3.14/site-packages/torch/export/_patches.pyÚ	<genexpr>Ú,_clone_tensors_that_alias.<locals>.<genexpr>   s(   øé € ð &
ÙGS¸ŒE�H‰H×Ñ˜v {×3Ð3Ã|ùs   ƒ-0TF)ÚanyÚcloneÚappendÚtuple)ÚtensorsÚcloned_tensorsÚseen_tensorsr   s   &  @r   Ú_clone_tensors_that_aliasr   
   s‰   ø€ ð €NØ€LÛˆØÒ§#£#ô &
ÙGSó&
§#§#¢#ô &
ÙGSó&
÷ #
ò #
ð —\‘\“^ˆFØ×Ñ˜fÔ%ØÔØ×Ñ Ö'ñ ô �Ó Ð ó    c                ó¨  aaaa€ V^ ,          pV^,          oV'       d
   V^,          MRpV'       d
   V^,          MRo\        V4      ^8X  d
   V^,          M\        V4      ^8X  d
   V^,          MRoV^ ,          P                  ^ 4      pV^,          P                  ^ 4      p\        P                  P                  P                  WV4      oV'       d   SP                  ^ 4      MSo\        SSS34      w  ooo\        P                  ! SP                  ^ 4      .\        VP                  R,          4      O5RVP                  RVP                  / p	V3R lp
VVVV3R lp\        P                  ! ^ \        P                  R7      p\!        W«WÉWx.4      w  rÞppV'       d   VP                  ^ 4      pWïP#                  ^ 4      VP#                  ^ 4      33# )aQ  
1 layer fn for while loop LSTM

Args:
    inp: Input tensor of shape (seq_len, batch, input_size)
    hidden: Tuple of (hx, cx) hidden states
    params: List of weight and bias tensors
    has_biases: Whether biases are included
    reverse: Whether to process sequence in reverse

Returns:
    Tuple of (output, (final_hx, final_cx))
Nºé   NNÚdtypeÚdevicec                 ó,   <€ V SP                  ^ 4      8  # ©r   ©Úsize)ÚiÚoutÚhxÚcxÚprecomputed_inputs   &&&&€r   Úcond_fnÚ*one_layer_while_loop_lstm.<locals>.cond_fnA   ó   ø€ ØÐ$×)Ñ)¨!Ó,Ñ,Ð,r   c           
      ó>  <€ V P                  4       p\        P                  ! V4       \        P                  ! VSP                  ^ 4      ^,
          R7       \	        SV,          W#SSS^R7      w  r#VP                  4       pVP                  ^ 4      W&   V ^,           WV3# )r   ©Úmax)Ú	chunk_dim)Úitemr   Ú_check_is_sizer'   r	   r   Úsqueeze)	Úidxr)   r*   r+   r(   Úhh_biasÚ	hh_weightÚ	hr_weightr,   s	   &&&& €€€€r   Úbody_fnÚ*one_layer_while_loop_lstm.<locals>.body_fnD   s‰   ø€ à�H‰H‹JˆÜ×Ò˜QÔÜ×Ò˜QÐ$5×$:Ñ$:¸1Ó$=ÀÕ$AÕBÜØ˜aÕ  "¨)°W¸iÐSTô
‰ˆð �i‰i‹kˆà—‘˜A“ˆ‰Ø�Q�w˜ Ð#Ð#r   ©r"   )ÚlenÚ	unsqueezer   ÚnnÚ
functionalÚlinearÚflipr   Úemptyr'   r   Úshaper"   r#   r   Úint64r
   r6   )ÚinpÚhiddenÚparamsÚ
has_biasesÚreverseÚ	ih_weightÚih_biasr*   r+   Ústep_outputr-   r;   ÚcntÚ_r)   Úfinal_hxÚfinal_cxr8   r9   r:   r,   s   &&&&&            @@@@r   Úone_layer_while_loop_lstmrS      s™  û€ ð �q•	€IØ�q•	€Iß%ˆf�QŽi¨4€Gß%ˆf�QŽi¨4€Gä˜“[ AÔ%ˆˆqŽ	¼¸F»ÀqÔ8H¨6°!®9Èdð ð 
��×	Ñ	˜QÓ	€BØ	��×	Ñ	˜QÓ	€BäŸ™×+Ñ+×2Ñ2°3À7ÓKÐß5<Ð)×.Ñ.¨qÔ1ÐBSÐÜ$=Ø	�G˜YÐ'ó%Ñ!€Iˆw˜	ô
 —+’+Ø×Ñ˜qÓ!ðä	ˆr�x‰x˜�|Ó	òð �h‰hðð �y‰yñ	€Kõ-÷$ð $ô �,Š,�q¤§¡Ô
,€CÜ!+Ø˜3¨RÐ4ó"Ñ€AˆH�h÷ Ø�h‰h�q‹kˆà×!Ñ! !Ó$ h×&6Ñ&6°qÓ&9Ð:Ð:Ð:r   c	                óÊ  € \        V4      ^8w  d   \        R4      h\        W#V^ ,          P                  ^4      V^,          P                  ^4      8g  4      p\	        \        V^ ,          V^,          4      4      p	\        p
\        V V	VVVVVVVV
4
      w  r¼\	        \        V!  4      pV\        P                  ! V^ ,          ^ 4      \        P                  ! V^,          ^ 4      3# )aj  
LSTM implementation using while_loop for export compatibility.

This is a drop-in replacement for the default LSTM decomposition that uses
while_loop instead of Python loops, making it more suitable for torch.export.

Args:
    input: Input tensor
    hx: Tuple of (h0, c0) hidden states
    params: List of weight and bias tensors
    has_biases: Whether biases are included
    num_layers: Number of LSTM layers
    dropout: Dropout probability
    train: Training mode
    bidirectional: Whether to use bidirectional LSTM
    batch_first: Whether batch dimension is first

Returns:
    Tuple of (output, h_n, c_n)
zlstm expects two hidden states)
r>   ÚAssertionErrorr   r'   ÚlistÚziprS   r   r   Ústack©Úinputr*   rI   rJ   Ú
num_layersÚdropoutÚtrainÚbidirectionalÚbatch_firstrH   Úlayer_fnr)   Úfinal_hiddenss   &&&&&&&&&    r   Úlstm_while_loop_implrb   [   sÌ   € ô> ˆ2ƒw�!„|ÜÐ=Ó>Ð>Ü˜6¨r°!­u¯z©z¸!«}ÀÀ1ÅÇ
Á
È1ÃÑ/MÓN€FÜ”#�b˜•e˜R �UÓ#Ó$€FÜ(€HÜ$ØØØØØØØØØØóÑ€Cô œ˜mÑ,Ó-€MØ”—’˜M¨!Õ,¨aÓ0´%·+²+¸mÈAÕ>NÐPQÓ2RÐRÐRr   c                óÖ  aaa€ V^ ,          pV^,          oV'       d
   V^,          MRpV'       d
   V^,          MRo\         P                  P                  P                  WV4      oV'       d   SP	                  ^ 4      MSo\        SS34      w  ooVP                  ^ 4      p\         P                  ! SP                  ^ 4      .\        VP                  R,          4      O5RVP                  RVP                  / pV3R lp	VVV3R lp
\         P                  ! ^ \         P                  R7      p\        WšW¸V.4      w  rÍpV'       d   VP	                  ^ 4      pWÞP!                  ^ 4      3# )a<  
1 layer fn for while loop GRU

Args:
    inp: Input tensor of shape (seq_len, batch, input_size)
    hidden: Hidden state tensor
    params: List of weight and bias tensors
    has_biases: Whether biases are included
    reverse: Whether to process sequence in reverse

Returns:
    Tuple of (output, final_hidden)
Nr    r"   r#   c                 ó,   <€ V SP                  ^ 4      8  # r%   r&   )r(   r)   Ú
cur_hiddenr,   s   &&&€r   r-   Ú)one_layer_while_loop_gru.<locals>.cond_fn¯   r/   r   c                 ó6  <€ V P                  4       p\        P                  ! V4       \        P                  ! VSP                  ^ 4      ^,
          R7       \	        SV,          VRRSS4      pVP                  4       pVP                  ^ 4      W&   V ^,           W3# )r   r1   N)r4   r   r5   r'   r   r   r6   )r7   r)   re   r(   r8   r9   r,   s   &&& €€€r   r;   Ú)one_layer_while_loop_gru.<locals>.body_fn²   s‡   ø€ à�H‰H‹JˆÜ×Ò˜QÔÜ×Ò˜QÐ$5×$:Ñ$:¸1Ó$=ÀÕ$AÕBÜØ˜aÕ  *¨d°D¸)ÀWó
ˆ
ð �i‰i‹kˆØ×#Ñ# AÓ&ˆ‰Ø�Q�w˜Ð'Ð'r   r=   )r   r@   rA   rB   rC   r   r?   rD   r'   r   rE   r"   r#   r   rF   r
   r6   )rG   rH   rI   rJ   rK   rL   rM   re   rN   r-   r;   rO   rP   r)   Úfinal_hiddenr8   r9   r,   s   &&&&&          @@@r   Úone_layer_while_loop_grurj   �   s9  ú€ ð �q•	€IØ�q•	€Iß%ˆf�QŽi¨4€Gß%ˆf�QŽi¨4€GäŸ™×+Ñ+×2Ñ2°3À7ÓKÐß5<Ð)×.Ñ.¨qÔ1ÐBSÐÜ2°I¸wÐ3GÓHÑ€IˆwØ×!Ñ! !Ó$€Jô —+’+Ø×Ñ˜qÓ!ðä	ˆz×Ñ Õ#Ó	$òð ×Ñðð × Ñ ñ	€Kõ-÷
(ô �,Š,�q¤§¡Ô
,€CÜ% g¸È:Ð8VÓWÑ€AˆLßØ�h‰h�q‹kˆà×$Ñ$ QÓ'Ð'Ð'r   c	                ó¸   € \        W#R4      p\        VP                  ^ 4      4      p	\        p
\	        V V	VVVVVVVV
4
      w  r¼V\
        P                  ! V^ 4      3# )aU  
GRU implementation using while_loop for export compatibility.

This is a drop-in replacement for the default GRU decomposition that uses
while_loop instead of Python loops, making it more suitable for torch.export.

Args:
    input: Input tensor
    hx: Hidden state tensor
    params: List of weight and bias tensors
    has_biases: Whether biases are included
    num_layers: Number of GRU layers
    dropout: Dropout probability
    train: Training mode
    bidirectional: Whether to use bidirectional GRU
    batch_first: Whether batch dimension is first

Returns:
    Tuple of (output, h_n)
F)r   rV   Úunbindrj   r   r   rX   rY   s   &&&&&&&&&    r   Úgru_while_loop_implrm   Æ   sj   € ô> ˜6¨uÓ5€FÜ�"—)‘)˜A“,Ó€FÜ'€HÜ$ØØØØØØØØØØóÑ€Cð ”—’˜M¨1Ó-Ð-Ð-r   c                ó2   € V ^8„  d   QhR\         R,          /# ©é   Úreturn)NNNr   )Úformats   "r   Ú__annotate__rs   ø   s   € ÷ ,Xñ ,XäÐÕ ñ,Xr   c              #  ó‚  "  € \         R,          pVP                  V R4      pV P                  P                  \        P                  P
                  P                  R4      p WV &   WP                  \        P                  P
                  P                  &   Rx € Ve   W2V &   MVP                  V R4       Ve4   VV P                  \        P                  P
                  P                  &   R# V P                  P                  \        P                  P
                  P                  R4       R#   Te   Y2T &   MTP                  T R4       Te3   TT P                  \        P                  P
                  P                  &   i T P                  P                  \        P                  P
                  P                  R4       i ; i5i)af  
Generic context manager for registering while_loop-based RNN decompositions.

Args:
    rnn_op: The aten operation to patch (e.g., torch.ops.aten.lstm.input)
    rnn_impl: The while_loop-based implementation function

Note:
    This is an internal helper. Use register_lstm_while_loop_decomposition()
    or register_gru_while_loop_decomposition() instead.
Úpost_autogradN)r   ÚgetÚ
py_kernelsr   r   ÚDispatchKeyÚCompositeImplicitAutogradÚpop)Úrnn_opÚrnn_implÚregistryÚoriginal_decompÚoriginal_py_kernels   &&   r   Ú&_register_rnn_while_loop_decompositionr€   ÷   si  é € ô *¨/Õ:€Hð —l‘l 6¨4Ó0€Oð  ×*Ñ*×.Ñ.Ü�‰×Ñ×6Ñ6¸óÐðXà#�ÑØLT×Ñœ%Ÿ(™(×.Ñ.×HÑHÑIÛð Ò&Ø.�VÒð �L‰L˜ Ô&ð Ò)à"ð ×ÑœeŸh™h×2Ñ2×LÑLÓMð
 ×Ñ×!Ñ!¤%§(¡(×"6Ñ"6×"PÑ"PÐRVÖWøð Ò&Ø.�VÒð �L‰L˜ Ô&ð Ò)à"ð ×ÑœeŸh™h×2Ñ2×LÑLÒMð
 ×Ñ×!Ñ!¤%§(¡(×"6Ñ"6×"PÑ"PÐRVÕWüs    ‚AF?Á!8D+ ÂBF?Ä+BF<Æ<F?c                ó2   € V ^8„  d   QhR\         R,          /# ro   r   )rr   s   "r   rs   rs   (  s   € ÷ ñ ´	Ð:JÕ0Kñ r   c               #  óØ   "  € \        \        P                  P                  P                  P
                  \        4      ;_uu_ 4        Rx € RRR4       R#   + '       g   i     R# ; i5i)aN  
Context manager that temporarily registers the while_loop-based LSTM decomposition.

The while_loop-based decomposition is more suitable for export and graph-based
execution, as it avoids Python control flow that cannot be captured in the graph.
This should support dynamic sequence lengths, however as while_loop does not
support Autograd yet, an ExportedProgram created with this will not be trainable.

Usage::

    from torch.export._patches import register_lstm_while_loop_decomposition
    from torch.export import export

    with register_lstm_while_loop_decomposition():
        # Export your model with LSTM
        ep = export(model, (x, h0, c0))

Note:
    This context manager temporarily modifies the global decomposition table
    and py_kernels registration. The original registrations are restored when
    exiting the context.
N)r€   r   ÚopsÚatenÚlstmrZ   rb   © r   r   Ú&register_lstm_while_loop_decompositionr‡   '  sG   é € ô0 
0Ü�	‰	�‰×Ñ×!Ñ!Ô#7÷
õ 
ó 	÷
÷ 
÷ 
ò 
üó   ‚AA*ÁAÁ
A*ÁA'	Á!	A*c                ó2   € V ^8„  d   QhR\         R,          /# ro   r   )rr   s   "r   rs   rs   F  s   € ÷ ñ ¬yÐ9IÕ/Jñ r   c               #  óØ   "  € \        \        P                  P                  P                  P
                  \        4      ;_uu_ 4        Rx € RRR4       R#   + '       g   i     R# ; i5i)aF  
Context manager that temporarily registers the while_loop-based GRU decomposition.

The while_loop-based decomposition is more suitable for export and graph-based
execution, as it avoids Python control flow that cannot be captured in the graph.
This should support dynamic sequence lengths, however as while_loop does not
support Autograd yet, an ExportedProgram created with this will not be trainable.

Usage::

    from torch.export._patches import register_gru_while_loop_decomposition
    from torch.export import export

    with register_gru_while_loop_decomposition():
        # Export your model with GRU
        ep = export(model, (x, h0))

Note:
    This context manager temporarily modifies the global decomposition table
    and py_kernels registration. The original registrations are restored when
    exiting the context.
N)r€   r   rƒ   r„   ÚgrurZ   rm   r†   r   r   Ú%register_gru_while_loop_decompositionrŒ   E  sG   é € ô0 
0Ü�	‰	�‰×Ñ× Ñ Ô"5÷
õ 
ó 	÷
÷ 
÷ 
ò 
ürˆ   )F)Ú
contextlibÚcollections.abcr   r   Útorch._decompr   Útorch._decomp.decompositionsr   r   r   r	   Ú"torch._higher_order_ops.while_loopr
   r   rS   rb   rj   rm   Úcontextmanagerr€   r‡   rŒ   r†   r   r   Ú<module>r“      s‰   ðÛ Ý %ã Ý 4ß XÓ XÝ 9ò!ô >;òB1Sôh4(òn..ðb ×Ñô,Xó ð,Xð^ ×Ñôó ðð: ×Ñôó òr   