§
    ŠŠtj‡P  ã            	       óÄ  — U d dl mZ d dlZd dlmc mZ d dlmZ d dlm	Z	 d dl
mZmZ d dlmZ d dlmZmZ d dlmZmZmZ d d	lmZmZ d
„ Zd"d„Zdej        fd„Zdej        fd„Zd„ Zd„ Zd„ Z d„ Z! e ¦   «         Z" e!¦   «         Z#ddœd„Z$d„ Z% e%¦   «         Z& e'¦   «         Z(e'd         e)d<   d#d„Z* e*e	j+        ¦  «         d dl,m-Z- ej.         /                    e-¦  «         ej0        j1         2                    ej.        j3        dd„ ej0        j1        j4        j5        ej0        j1        j4        j5        ej0        j1        j4        j5        dœ¬¦  «         d „ Z6 e6¦   «         Z7d!„ Z8dS )$é    )ÚcastN)Ú_prims)ÚDispatchKey)Úautograd_not_implementedÚregister_fake)ÚHigherOrderOperator)ÚCUDARngStateHelperÚmake_contiguous_strides_for)Údisable_proxy_modes_tracingÚProxyTorchDispatchModeÚtrack_tensor_tree)Ú_deviceÚ_dtypec           	      óR   — t          d| j        › d| j        › d| j        › d�¦  «        ‚)Nz"You are trying to functionalize a z RNG operator but zE does not use Philox/counter-based RNG. Therefore, functionalizing a zo RNG operator is not supported. We are discussing the possibility of a Philox-based RNG implementation for CPU.)ÚRuntimeErrorÚtype©Údevices    úT/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/torch/_prims/rng_prims.pyÚthrow_on_non_cudar      sQ   € Ý
ð	i¨V¬[ð 	ið 	iÈFÌKð 	ið 	iØFLÄkð	ið 	ið 	iñô ð ó    c                 óf  — t           j                             d| z   |d|¬¦  «        }|                     |¦  «         t	          t           j        j        j        | ¦  «        }|j        }|r||_	        ||fD ]<}	||	_
        t           j        j        j        |	_        | |z   |	_        ||	_        ||	_        Œ=d S )Nz
rngprims::© )Úmutates_argsÚschema)ÚtorchÚlibraryÚ	custom_opr   ÚgetattrÚ_opsÚopsÚrngprimsÚdefaultÚ_tagsÚ__doc__Ú_prims_commonÚRETURN_TYPEÚNEWÚreturn_typer   Ú	impl_atenÚprim_meta_impl)
Únamer   r*   Ú	impl_metaÚdocÚtagsÚrngprim_defÚprim_packetÚprimÚps
             r   Úregister_rng_primr4      sÁ   € Ý”-×)Ò)Ø�tÑ˜Y°RÀð *ñ ô €Kð ×Ò˜iÑ(Ô(Ð(å�%œ*œ.Ô1°4Ñ8Ô8€KØÔ€DØð ØˆŒ
à˜4Ð ð %ð %ˆØˆŒ	ÝÔ+Ô7Ô;ˆŒà˜&‘=ˆŒØˆŒØ$ˆÔÐð%ð %r   Úshapec                 óf   — t          j        t          j        dt          j        ¬¦  «        ¦  «        S )Nr   ©Údtype)r   Ú
TensorLiker   ÚtensorÚint64)r5   s    r   Úphilox_rand_offset_metar<   2   s&   € õ Ô�Uœ\¨!µ5´;Ð?Ñ?Ô?Ñ@Ô@Ð@r   c                 óˆ  — d}| D ]}||z  }Œt          j        |t           j        ¬¦  «        }d}d}d}t           j                             t           j                             ¦   «         ¦  «        }|j        |z  }t          t          |¦  «        }	|	|z   dz
  |z  }
t          |
|j
        |z  ¦  «        }
|	dz
  ||
z  |z  z  dz   |z  S )Né   r7   é   é   )r   Úscalar_tensorr;   ÚcudaÚget_device_propertiesÚcurrent_deviceÚmax_threads_per_multi_processorr   ÚintÚminÚmulti_processor_count)r5   Únumel_scalarÚdim_sizeÚnumelÚ
block_sizeÚunrollÚcurand4_engine_callsÚdevice_propertyÚblocks_per_smÚnumÚ	grid_sizes              r   Úphilox_rand_offsetrS   8   sÙ   € ð €LØð !ð !ˆØ˜Ñ ˆˆÝÔ µE´KÐ@Ñ@Ô@€Eà€JØ€FØÐÝ”j×6Ò6µu´z×7PÒ7PÑ7RÔ7RÑSÔS€OØ#ÔCÀzÑQ€MÝ
�s�EÑ
Ô
€CØ�zÑ! AÑ%¨*Ñ4€IÝ�I˜ÔDÀ}ÑTÑUÔU€IØ�1‰W˜* yÑ0°6Ñ9Ñ:¸QÑ>ÐBVÑVÐVr   c                  óŒ  — d} d}dt           j        dt           j        dt           j        dt          t          df         d z  dt
          d	t          fd
„}dt           j        dt           j        dt           j        dt          t          df         d z  dt
          d	t          fd„}t          | |||dt           j        j	        f¬¦  «         d S )NÚphilox_randz{(SymInt[] size, Tensor seed, Tensor offset, int[]? stride, Device? device=None, ScalarType? dtype=None) -> (Tensor, Tensor)r5   ÚseedÚoffsetÚstride.r   r8   c                 óž   — |�t          d|› �¦  «        ‚t          | ¦  «        }t          j        | |||¬¦  «        }t	          | ¦  «        }||fS )Nústride must be None, got )r5   Ústridesr8   r   )ÚAssertionErrorr
   r   Ú
TensorMetar<   )r5   rV   rW   rX   r   r8   Úrandom_valuess          r   Ú_philox_rand_metaz/register_philox_rand.<locals>._philox_rand_metaR   sh   € ð ÐÝ Ð!E¸VÐ!EÐ!EÑFÔFÐFÝ,¨UÑ3Ô3ˆÝÔ)Ø ¨u¸Vð
ñ 
ô 
ˆõ )¨Ñ/Ô/ˆØ˜vÐ&Ð&r   c                 óh  — |�t          d|› �¦  «        ‚|j        dk    rg }n|g}|j        dk    rt          |¦  «        ‚t          j                             |¦  «        5  t          j        ||¦  «         t          j        | ||¬¦  «        }d d d ¦  «         n# 1 swxY w Y   |t          | ¦  «        fS )NrZ   ÚcpurB   )r   r8   )
r\   r   r   r   ÚrandomÚfork_rngr	   Úset_torch_state_tensorÚrandrS   )r5   rV   rW   rX   r   r8   Údevicesr^   s           r   Ú_philox_randz*register_philox_rand.<locals>._philox_randd   s  € ð ÐÝ Ð!E¸VÐ!EÐ!EÑFÔFÐFØŒ;˜%ÒÐØˆGˆGà�hˆGàŒ;˜&Ò Ð Ý# FÑ+Ô+Ð+åŒ\×"Ò" 7Ñ+Ô+ð 	Jð 	JÝÔ5°d¸FÑCÔCÐCÝ!œJ u°VÀ5ÐIÑIÔIˆMð	Jð 	Jð 	Jñ 	Jô 	Jð 	Jð 	Jð 	Jð 	Jð 	Jð 	Jøøøð 	Jð 	Jð 	Jð 	Jð Õ0°Ñ7Ô7Ð7Ð7s   Á-BÂBÂBz$Philox based stateless rand operator)r,   r   r*   r-   r.   r/   )
r   ÚSizeÚTensorÚtuplerF   r   r   r4   ÚTagÚnondeterministic_seeded)r,   r   r_   rg   s       r   Úregister_philox_randrm   N   s
  € Ø€Dð K€Fð'ÝŒzð'åŒlð'õ ”ð'õ •c˜3�h” $Ñ&ð	'õ
 ð'õ ð'ð 'ð 'ð 'ð$8ÝŒzð8åŒlð8õ ”ð8õ •c˜3�h” $Ñ&ð	8õ
 ð8õ ð8ð 8ð 8ð 8õ2 ØØØØ#Ø2ÝŒiÔ/Ð1ðñ ô ð ð ð r   c                 ó  — |                      d¦  «        rE|                      d¦  «        }t          |t          ¦  «        rt          j        |¦  «        }|j        S | D ]*}t          |t          j        ¦  «        r|j        j        c S Œ+d S )Nr   )ÚgetÚ
isinstanceÚstrr   r   r   ri   )ÚargsÚkwargsr   Úargs       r   Ú
get_deviceru   ‡   s�   € Ø‡z‚z�(ÑÔð Ø—’˜HÑ%Ô%ˆÝ�f�cÑ"Ô"ð 	*Ý”\ &Ñ)Ô)ˆFØŒ{Ðàð #ð #ˆÝ�c�5œ<Ñ(Ô(ð 	#Ø”:”?Ð"Ð"Ð"ð	#àˆ4r   c                  óØ  ‡‡‡‡‡‡—  G d„ dt           ¦  «        }  | ¦   «         Š ‰                     t          j        ¦  «        t	          ‰d¬¦  «        ¦  «         ‰                     t          j        ¦  «        d„ ¦   «         Š‰                     t          j        ¦  «        d„ ¦   «         Š‰                     t          j        ¦  «        d„ ¦   «         Š‰                     t          j        ¦  «        d„ ¦   «         Š‰                     t          j	        ¦  «        ˆˆˆˆfd	„¦   «         Št          ‰d¬
¦  «        ˆfd„¦   «         }‰                     t          ¦  «        ˆˆfd„¦   «         }‰S )Nc                   ó(   ‡ — e Zd Zˆ fd„Zˆ fd„Zˆ xZS )ú>register_run_and_save_rng_state_op.<locals>.RunAndSaveRngStatec                 óN   •— t          ¦   «                              dd¬¦  «         d S )NÚrun_and_save_rng_stateT©Ú	cacheable©ÚsuperÚ__init__©ÚselfÚ	__class__s    €r   r   zGregister_run_and_save_rng_state_op.<locals>.RunAndSaveRngState.__init__–   s'   ø€ Ý‰GŒG×ÒÐ5ÀÐÑFÔFÐFÐFÐFr   c                 ó>   •—  t          ¦   «         j        |g|¢R i |¤ŽS ©N©r~   Ú__call__)r�   Úoprr   rs   r‚   s       €r   r†   zGregister_run_and_save_rng_state_op.<locals>.RunAndSaveRngState.__call__™   s*   ø€ à#•5‘7”7Ô# BÐ8¨Ð8Ð8Ð8°Ð8Ð8Ð8r   ©Ú__name__Ú
__module__Ú__qualname__r   r†   Ú__classcell__©r‚   s   @r   ÚRunAndSaveRngStaterx   •   sV   ø€ € € € € ð	Gð 	Gð 	Gð 	Gð 	Gð	9ð 	9ð 	9ð 	9ð 	9ð 	9ð 	9ð 	9ð 	9r   rŽ   T©Údeferred_errorc                 óN   — t           j                             ¦   «          | |i |¤ŽfS r„   )r   rB   Úget_rng_state©r‡   rr   rs   s      r   Ú	impl_cudaz5register_run_and_save_rng_state_op.<locals>.impl_cuda£   s*   € åŒz×'Ò'Ñ)Ô)¨2¨2¨tÐ+>°vÐ+>Ð+>Ð>Ð>r   c                 ó8   — t          j        ¦   «          | |i |¤ŽfS r„   )r   r’   r“   s      r   Úimpl_cpuz4register_run_and_save_rng_state_op.<locals>.impl_cpu§   s%   € åÔ"Ñ$Ô$ b b¨$Ð&9°&Ð&9Ð&9Ð9Ð9r   c                 ó–   — t          t          d¦  «        r&t          j                             ¦   «          | |i |¤ŽfS t	          d¦  «        ‚©NÚhpuz2functionalize a hpu RNG operator is not supported.)Úhasattrr   r™   r’   r   r“   s      r   Úimpl_hpuz4register_run_and_save_rng_state_op.<locals>.impl_hpu«   sL   € å•5˜%Ñ Ô ð 	BÝ”9×*Ò*Ñ,Ô,¨b¨b°$Ð.A¸&Ð.AÐ.AÐAÐAÝÐOÑPÔPÐPr   c                 óN   — t           j                             ¦   «          | |i |¤ŽfS r„   )r   Úxpur’   r“   s      r   Úimpl_xpuz4register_run_and_save_rng_state_op.<locals>.impl_xpu±   s*   € åŒy×&Ò&Ñ(Ô(¨"¨"¨dÐ*=°fÐ*=Ð*=Ð=Ð=r   c                 ó†   •— ‰‰‰‰	dœ}t          ||¦  «        }||vrt          d|› �¦  «        ‚||         } || g|¢R i |¤ŽS ©N)rB   ra   r™   r�   zBackend not supported for ©ru   r\   )
r‡   rr   rs   Úimpl_mapr   Úimplr–   r”   r›   rž   s
         €€€€r   Úimpl_backend_selectz?register_run_and_save_rng_state_op.<locals>.impl_backend_selectµ   sz   ø€ ð ØØØð	
ð 
ˆõ ˜D &Ñ)Ô)ˆØ˜Ð!Ð!Ý Ð!F¸fÐ!FÐ!FÑGÔGÐGØ˜ÔˆØˆt�BÐ(˜Ð(Ð(Ð( Ð(Ð(Ð(r   ©Ú
skip_cachec                 ó   •—  ‰| g|¢R i |¤ŽS r„   r   )r‡   rr   rs   r¤   s      €r   Úimpl_fake_tensor_modezAregister_run_and_save_rng_state_op.<locals>.impl_fake_tensor_modeÃ   s&   ø€ ð #Ð" 2Ð7¨Ð7Ð7Ð7°Ð7Ð7Ð7r   c                 ó
  •—  ‰|g|¢R i |¤Ž}t          j        | j        j        |g|¢R ¦  «        }t          j        | j        j        |¦  «        }| j                             d‰	||¦  «        }t          ||d | j        ¬¦  «        S ©NÚcall_function©ÚconstantÚtracer)ÚpytreeÚtree_mapr®   Úunwrap_proxyÚcreate_proxyr   )
Úmoder‡   rr   rs   ÚoutÚ
proxy_argsÚproxy_kwargsÚ	out_proxyr¤   rz   s
           €€r   Úimpl_proxy_dispatch_modezDregister_run_and_save_rng_state_op.<locals>.impl_proxy_dispatch_modeÈ   s“   ø€ à!Ð! "Ð6 tÐ6Ð6Ð6¨vÐ6Ð6ˆÝ”_ T¤[Ô%=À¸{ÀT¸{¸{ÑKÔKˆ
Ý” t¤{Ô'?ÀÑHÔHˆØ”K×,Ò,ØÐ3°ZÀñ
ô 
ˆ	õ !  i¸$ÀtÄ{ÐSÑSÔSÐSr   )r   Úpy_implr   ÚAutogradr   ÚCUDAÚCPUÚHPUÚXPUÚBackendSelectr   r   )	rŽ   r¨   r¸   r¤   r–   r”   r›   rž   rz   s	      @@@@@@r   Ú"register_run_and_save_rng_state_oprÀ   ”   sñ  øøøøøø€ ð9ð 9ð 9ð 9ð 9Õ0ñ 9ô 9ð 9ð 0Ð/Ñ1Ô1Ðà8Ð×"Ò"¥;Ô#7Ñ8Ô8Ý Ð!7ÈÐMÑMÔMñô ð ð ×#Ò#¥KÔ$4Ñ5Ô5ð?ð ?ñ 6Ô5ð?ð ×#Ò#¥K¤OÑ4Ô4ð:ð :ñ 5Ô4ð:ð ×#Ò#¥K¤OÑ4Ô4ðQð Qñ 5Ô4ðQð
 ×#Ò#¥K¤OÑ4Ô4ð>ð >ñ 5Ô4ð>ð ×#Ò#¥KÔ$=Ñ>Ô>ð)ð )ð )ð )ð )ð )ð )ñ ?Ô>ð)õ Ð)°dÐ;Ñ;Ô;ð8ð 8ð 8ð 8ñ <Ô;ð8ð ×#Ò#Õ$:Ñ;Ô;ðTð Tð Tð Tð Tñ <Ô;ðTð "Ð!r   c                  óô  ‡‡‡‡‡	—  G d„ dt           ¦  «        }  | ¦   «         Š	 ‰	                     t          j        ¦  «        t	          ‰	d¬¦  «        ¦  «         ‰	                     t          j        ¦  «        d„ ¦   «         Š‰	                     t          j        ¦  «        d„ ¦   «         Š‰	                     t          j        ¦  «        d„ ¦   «         Š‰	                     t          j        ¦  «        d„ ¦   «         Š‰	                     t          ¦  «        ˆ	fd	„¦   «         }‰	                     t          j
        ¦  «        ˆˆˆˆfd
„¦   «         }t          ‰	d¬¦  «        d„ ¦   «         }‰	j        ˆ	fd„¦   «         }‰	S )Nc                   ó(   ‡ — e Zd Zˆ fd„Zˆ fd„Zˆ xZS )ú7register_run_with_rng_state_op.<locals>.RunWithRngStatec                 óN   •— t          ¦   «                              dd¬¦  «         d S )NÚrun_with_rng_stateTr{   r}   r€   s    €r   r   z@register_run_with_rng_state_op.<locals>.RunWithRngState.__init__×   s'   ø€ Ý‰GŒG×ÒÐ1¸TÐÑBÔBÐBÐBÐBr   c                 ó@   •—  t          ¦   «         j        ||g|¢R i |¤ŽS r„   r…   )r�   Ú	rng_stater‡   rr   rs   r‚   s        €r   r†   z@register_run_with_rng_state_op.<locals>.RunWithRngState.__call__Ú   s,   ø€ à#•5‘7”7Ô# I¨rÐC°DÐCÐCÐC¸FÐCÐCÐCr   rˆ   r�   s   @r   ÚRunWithRngStaterÃ   Ö   s_   ø€ € € € € ð	Cð 	Cð 	Cð 	Cð 	Cð	Dð 	Dð 	Dð 	Dð 	Dð 	Dð 	Dð 	Dð 	Dr   rÈ   Tr�   c                 óò   — t           j                             ¦   «         }t           j                             |                      ¦   «         ¦  «          ||i |¤Ž}t           j                             |¦  «         |S r„   )r   rB   r’   Úset_rng_statera   ©rÇ   r‡   rr   rs   Úcurrent_stater´   s         r   r”   z1register_run_with_rng_state_op.<locals>.impl_cudaä   sb   € åœ
×0Ò0Ñ2Ô2ˆÝŒ
× Ò  §¢¡¤Ñ1Ô1Ð1Øˆb�$Ð!˜&Ð!Ð!ˆÝŒ
× Ò  Ñ/Ô/Ð/Øˆ
r   c                 óŒ   — t          j        ¦   «         }t          j        | ¦  «          ||i |¤Ž}t          j        |¦  «         |S r„   )r   r’   rÊ   rË   s         r   r–   z0register_run_with_rng_state_op.<locals>.impl_cpuì   sK   € åÔ+Ñ-Ô-ˆÝÔ˜IÑ&Ô&Ð&Øˆb�$Ð!˜&Ð!Ð!ˆÝÔ˜MÑ*Ô*Ð*Øˆ
r   c                 ó  — t          t          d¦  «        rft          j                             ¦   «         }t          j                             | ¦  «          ||i |¤Ž}t          j                             |¦  «         |S t          d¦  «        ‚r˜   )rš   r   r™   r’   rÊ   r   rË   s         r   r›   z0register_run_with_rng_state_op.<locals>.impl_hpuô   s{   € å•5˜%Ñ Ô ð 	Ý!œI×3Ò3Ñ5Ô5ˆMÝŒI×#Ò# IÑ.Ô.Ð.Ø�"�dÐ%˜fÐ%Ð%ˆCÝŒI×#Ò# MÑ2Ô2Ð2ØˆJÝÐOÑPÔPÐPr   c                 óÎ   — t           j                             ¦   «         }t           j                             | ¦  «          ||i |¤Ž}t           j                             |¦  «         |S r„   )r   r�   r’   rÊ   rË   s         r   rž   z0register_run_with_rng_state_op.<locals>.impl_xpuþ   sZ   € åœ	×/Ò/Ñ1Ô1ˆÝŒ	×Ò 	Ñ*Ô*Ð*Øˆb�$Ð!˜&Ð!Ð!ˆÝŒ	×Ò Ñ.Ô.Ð.Øˆ
r   c                 óZ  •— t          ¦   «         5   ‰	||g|¢R i |¤Ž}d d d ¦  «         n# 1 swxY w Y   t          j        | j        j        ||g|¢R ¦  «        }t          j        | j        j        |¦  «        }| j                             d‰	||¦  «        }t          ||d | j        ¬¦  «        S rª   ©r   r¯   r°   r®   r±   r²   r   )
r³   rÇ   r‡   rr   rs   r´   rµ   r¶   r·   rÅ   s
            €r   r¸   z@register_run_with_rng_state_op.<locals>.impl_proxy_dispatch_mode  s  ø€ õ )Ñ*Ô*ð 	Eð 	EØ$Ð$ Y°ÐD°TÐDÐDÐD¸VÐDÐDˆCð	Eð 	Eð 	Eñ 	Eô 	Eð 	Eð 	Eð 	Eð 	Eð 	Eð 	Eøøøð 	Eð 	Eð 	Eð 	Eå”_ T¤[Ô%=À	È2Ð?UÐPTÐ?UÐ?UÑVÔVˆ
Ý” t¤{Ô'?ÀÑHÔHˆØ”K×,Ò,ØÐ/°¸\ñ
ô 
ˆ	õ !  i¸$ÀtÄ{ÐSÑSÔSÐSs   �*ª.±.c                 óˆ   •— ‰‰‰	‰
dœ}t          ||¦  «        }||vrt          d|› �¦  «        ‚||         } || |g|¢R i |¤ŽS r    r¡   )rÇ   r‡   rr   rs   r¢   r   r£   r–   r”   r›   rž   s          €€€€r   r¤   z;register_run_with_rng_state_op.<locals>.impl_backend_select  s|   ø€ ð ØØØð	
ð 
ˆõ ˜D &Ñ)Ô)ˆØ˜Ð!Ð!Ý Ð!F¸fÐ!FÐ!FÑGÔGÐGØ˜ÔˆØˆt�I˜rÐ3 DÐ3Ð3Ð3¨FÐ3Ð3Ð3r   r¥   c                 ó   —  ||i |¤ŽS r„   r   )rÇ   r‡   rr   rs   s       r   r¨   z=register_run_with_rng_state_op.<locals>.impl_fake_tensor_mode!  s   € ð ˆr�4Ð"˜6Ð"Ð"Ð"r   c                 ó"  •— |                       |¦  «        }|                       |¦  «        }|                       |¦  «        }|                      ¦   «         5   ‰	||g|¢R i |¤Ž}|                      |¦  «        cd d d ¦  «         S # 1 swxY w Y   d S r„   ©Úunwrap_tensorsÚredispatch_to_nextÚwrap_tensors)
ÚctxrÇ   r‡   rr   rs   Úunwrapped_rng_stateÚunwrapped_argsÚunwrapped_kwargsr´   rÅ   s
            €r   Úimpl_functionalz7register_run_with_rng_state_op.<locals>.impl_functional'  sø   ø€ à!×0Ò0°Ñ;Ô;ÐØ×+Ò+¨DÑ1Ô1ˆØ×-Ò-¨fÑ5Ô5Ðà×#Ò#Ñ%Ô%ð 	)ð 	)Ø$Ð$Ø# RðØ*8ðð ð Ø<Lðð ˆCð ×#Ò# CÑ(Ô(ð		)ð 	)ð 	)ð 	)ñ 	)ô 	)ð 	)ð 	)ð 	)ð 	)ð 	)ð 	)øøøð 	)ð 	)ð 	)ð 	)ð 	)ð 	)s   Á"BÂBÂB)r   r¹   r   rº   r   r»   r¼   r½   r¾   r   r¿   r   Úpy_functionalize_impl)
rÈ   r¸   r¤   r¨   rÝ   r–   r”   r›   rž   rÅ   s
        @@@@@r   Úregister_run_with_rng_state_oprß   Õ   s  øøøøø€ ðDð Dð Dð Dð DÕ-ñ Dô Dð Dð )˜Ñ*Ô*Ðà4Ð×Ò�{Ô3Ñ4Ô4Ý Ð!3ÀDÐIÑIÔIñô ð ð ×Ò¥Ô 0Ñ1Ô1ðð ñ 2Ô1ðð ×Ò¥¤Ñ0Ô0ðð ñ 1Ô0ðð ×Ò¥¤Ñ0Ô0ðQð Qñ 1Ô0ðQð ×Ò¥¤Ñ0Ô0ðð ñ 1Ô0ðð ×ÒÕ 6Ñ7Ô7ð
Tð 
Tð 
Tð 
Tñ 8Ô7ð
Tð ×Ò¥Ô 9Ñ:Ô:ð4ð 4ð 4ð 4ð 4ð 4ð 4ñ ;Ô:ð4õ Ð%°$Ð7Ñ7Ô7ð#ð #ñ 8Ô7ð#ð
 Ô-ð	)ð 	)ð 	)ð 	)ñ .Ô-ð	)ð Ðr   ©rÇ   c                óX  — |j         j        }|j         j        }t          t          |d ¦  «        }|�t          |d¦  «        st          d|› d|› d�¦  «        ‚|j        |         }|                     ¦   «         }| 	                    |¦  «          | |i |¤Ž}	| 	                    |¦  «         |	S )NÚdefault_generatorsú3GraphSafe RNG operations not supported for device 'z' (no torch.z.default_generators))
r   Úindexr   r   r   rš   r\   râ   Úgraphsafe_get_stateÚgraphsafe_set_state)
r‡   rÇ   rr   rs   Ú
device_idxÚdevice_typeÚ
device_modÚ	generatorrÌ   r´   s
             r   Ú_impl_graphsafe_rngrë   :  sÕ   € àÔ!Ô'€JØÔ"Ô'€KÝ� ¨TÑ2Ô2€JØÐ¥¨Ð5IÑ!JÔ!JÐÝð;À+ð ;ð ;Ø$ð;ð ;ð ;ñ
ô 
ð 	
ð Ô-¨jÔ9€IØ×1Ò1Ñ3Ô3€Mà×!Ò! )Ñ,Ô,Ð,Ø
ˆ"ˆdÐ
�fÐ
Ð
€CØ×!Ò! -Ñ0Ô0Ð0Ø€Jr   c                  óº  ‡—  G d„ dt           ¦  «        }  | ¦   «         Š ‰                     t          j        ¦  «        t	          ‰d¬¦  «        ¦  «         ‰                     t          j        ¦  «        d dœd„¦   «         }t          ‰d¬¦  «        d dœd„¦   «         }‰                     t          ¦  «        d dœˆfd	„
¦   «         }‰j        d dœˆfd
„
¦   «         }‰S )Nc                   ó.   ‡ — e Zd Zˆ fd„Zddœˆ fd„
Zˆ xZS )úJregister_graphsafe_run_with_rng_state_op.<locals>.GraphSafeRunWithRngStatec                 óN   •— t          ¦   «                              dd¬¦  «         d S )NÚgraphsafe_run_with_rng_stateTr{   r}   r€   s    €r   r   zSregister_graphsafe_run_with_rng_state_op.<locals>.GraphSafeRunWithRngState.__init__O  s'   ø€ Ý‰GŒG×ÒÐ;ÀtÐÑLÔLÐLÐLÐLr   Nrà   c                óB   •—  t          ¦   «         j        |g|¢R d|i|¤ŽS ©NrÇ   r…   )r�   r‡   rÇ   rr   rs   r‚   s        €r   r†   zSregister_graphsafe_run_with_rng_state_op.<locals>.GraphSafeRunWithRngState.__call__R  s/   ø€ à#•5‘7”7Ô# BÐM¨ÐMÐMÐM¸ÐMÀfÐMÐMÐMr   rˆ   r�   s   @r   ÚGraphSafeRunWithRngStaterî   N  sp   ø€ € € € € ð	Mð 	Mð 	Mð 	Mð 	Mð 15ð 	Nð 	Nð 	Nð 	Nð 	Nð 	Nð 	Nð 	Nð 	Nð 	Nð 	Nr   ró   Tr�   rà   c                ó¼   — ddl m} t          ||¦  «        }|� |t          j        |¦  «        ¦  «        st          d|› d|› d�¦  «        ‚t          | g|¢R d|i|¤ŽS )Nr   )Úsupports_graphsafe_rngrã   z,'. Call register_graphsafe_rng_device_type('z') to register.rÇ   )Ú$torch._functorch._aot_autograd.utilsrõ   ru   r   r   r\   rë   )r‡   rÇ   rr   rs   rõ   r   s         r   r¤   zEregister_graphsafe_run_with_rng_state_op.<locals>.impl_backend_select\  s¢   € àOÐOÐOÐOÐOÐOå˜D &Ñ)Ô)ˆØˆ>Ð!7Ð!7½¼ÀVÑ8LÔ8LÑ!MÔ!Mˆ>Ý ðTÀfð Tð TØ<BðTð Tð Tñô ð õ # 2ÐL¨ÐLÐLÐL¸	ÐLÀVÐLÐLÐLr   r¥   c                ó   —  | |i |¤ŽS r„   r   )r‡   rÇ   rr   rs   s       r   r¨   zGregister_graphsafe_run_with_rng_state_op.<locals>.impl_fake_tensor_modeh  ó   € àˆr�4Ð"˜6Ð"Ð"Ð"r   c                ób  •— t          ¦   «         5   ‰	|g|¢R d|i|¤Ž}d d d ¦  «         n# 1 swxY w Y   t          j        | j        j        |g|¢R ¦  «        }t          j        | j        j        d|i|¥¦  «        }| j                             d‰	||¦  «        }t          ||d | j        ¬¦  «        S )NrÇ   r«   r¬   rÑ   )
r³   r‡   rÇ   rr   rs   r´   rµ   r¶   r·   rð   s
            €r   r¸   zJregister_graphsafe_run_with_rng_state_op.<locals>.impl_proxy_dispatch_model  s  ø€ å(Ñ*Ô*ð 	Yð 	YØ.Ð.¨rÐX°DÐXÐXÐXÀIÐXÐQWÐXÐXˆCð	Yð 	Yð 	Yñ 	Yô 	Yð 	Yð 	Yð 	Yð 	Yð 	Yð 	Yøøøð 	Yð 	Yð 	Yð 	Yå”_ T¤[Ô%=À¸{ÀT¸{¸{ÑKÔKˆ
Ý”ØŒKÔ$ {°IÐ&HÀÐ&Hñ
ô 
ˆð ”K×,Ò,ØÐ9¸:À|ñ
ô 
ˆ	õ !  i¸$ÀtÄ{ÐSÑSÔSÐSó   �+«/²/c                ó,  •— |�|                       |¦  «        nd }|                       |¦  «        }|                       |¦  «        }|                      ¦   «         5   ‰	|g|¢R d|i|¤Ž}|                      |¦  «        cd d d ¦  «         S # 1 swxY w Y   d S rò   rÕ   )
rÙ   r‡   rÇ   rr   rs   rÚ   rÛ   rÜ   r´   rð   s
            €r   rÝ   zAregister_graphsafe_run_with_rng_state_op.<locals>.impl_functionaly  s  ø€ ð .7Ð-BˆC×Ò˜yÑ)Ô)Ð)Èð 	ð ×+Ò+¨DÑ1Ô1ˆØ×-Ò-¨fÑ5Ô5Ðà×#Ò#Ñ%Ô%ð 	)ð 	)Ø.Ð.ØðØ#ðð ð Ø/BðØFVðð ˆCð ×#Ò# CÑ(Ô(ð		)ð 	)ð 	)ð 	)ñ 	)ô 	)ð 	)ð 	)ð 	)ð 	)ð 	)ð 	)øøøð 	)ð 	)ð 	)ð 	)ð 	)ð 	)s   Á#B	Â	BÂB)	r   r¹   r   rº   r   r¿   r   r   rÞ   )ró   r¤   r¨   r¸   rÝ   rð   s        @r   Ú(register_graphsafe_run_with_rng_state_oprü   M  s~  ø€ ðNð Nð Nð Nð NÕ#6ñ Nô Nð Nð $<Ð#;Ñ#=Ô#=Ð à>Ð ×(Ò(­Ô)=Ñ>Ô>Ý Ð!=ÈdÐSÑSÔSñô ð ð "×)Ò)­+Ô*CÑDÔDØ15ð 	Mð 	Mð 	Mð 	Mñ EÔDð	Mõ Ð/¸DÐAÑAÔAØ37ð #ð #ð #ð #ñ BÔAð#ð "×)Ò)Õ*@ÑAÔAØ<@ð 
Tð 
Tð 
Tð 
Tð 
Tð 
Tñ BÔAð
Tð "Ô7Ø26ð )ð )ð )ð )ð )ð )ñ 8Ô7ð)ð (Ð'r   r   Ú#_registered_graphsafe_dispatch_keysÚdispatch_keyÚreturnc                 óž   — | t           v rdS t                                | ¦  «         t                               | ¦  «        t          ¦  «         dS )zARegister graphsafe_run_with_rng_state py_impl for a dispatch key.N)rý   Úaddrð   r¹   rë   )rþ   s    r   Úregister_graphsafe_rng_dispatchr  �  sJ   € àÕ:Ð:Ð:ØˆÝ'×+Ò+¨LÑ9Ô9Ð9Ý ×(Ò(¨Ñ6Ô6Õ7JÑKÔKÐKÐKÐKr   )ÚOpaqueBaseMetaÚ	referencec                 ó   — | j         gS r„   r   )Úgens    r   ú<lambda>r  ¦  s
   € ˜#œ*˜€ r   )r   Ú__eq__Ú__ne__)ÚtypÚguard_fnÚmembersc                  óø  ‡‡—  G d„ dt           ¦  «        }  | ¦   «         Š ‰                     t          j        ¦  «        t	          ‰d¬¦  «        ¦  «         ‰                     t          j        ¦  «        d„ ¦   «         Š‰                     t          j        ¦  «        ˆfd„¦   «         }t          ‰d¬¦  «        d„ ¦   «         }‰                     t          ¦  «        ˆfd	„¦   «         }‰j	        ˆfd
„¦   «         }‰S )u®  
    Register a higher-order operator for DTensor distributed random operations.
    Takes pre-computed integer offsets (start_offset_incr, end_offset_incr), an op,
    and args. Internally adjusts the RNG state using the offsets before/after
    running the op.

    The offsets are computed at trace time from the DTensorSpec, so the compiled graph
    contains only plain integers â€” no DTensorSpec or DeviceMesh objects.
    c                   ó(   ‡ — e Zd Zˆ fd„Zˆ fd„Zˆ xZS )ú4register_run_dtensor_rng_op.<locals>.RunDTensorRngOpc                 óN   •— t          ¦   «                              dd¬¦  «         d S )NÚrun_dtensor_rng_opFr{   r}   r€   s    €r   r   z=register_run_dtensor_rng_op.<locals>.RunDTensorRngOp.__init__»  s)   ø€ õ ‰GŒG×ÒÐ1¸UÐÑCÔCÐCÐCÐCr   c                 óB   •—  t          ¦   «         j        |||g|¢R i |¤ŽS r„   r…   )r�   Ústart_offset_incrÚend_offset_incrr‡   rr   rs   r‚   s         €r   r†   z=register_run_dtensor_rng_op.<locals>.RunDTensorRngOp.__call__Ã  s?   ø€ à#•5‘7”7Ô#Ø! ?°BðØ9=ðð ð ØAGðð ð r   rˆ   r�   s   @r   ÚRunDTensorRngOpr  º  sV   ø€ € € € € ð	Dð 	Dð 	Dð 	Dð 	Dð	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	r   r  Tr�   c                 ó¢  — ddl m}  |t          j                             ¦   «         ¦  «        }|j                             ¦   «         }|| z   |_        |r#t          |d         d¦  «        r|d         j        n2t          j        dt          j         	                    ¦   «         › �¦  «        }t          j
                             |gd¬¦  «        5  t          j                             |j        ¦  «         	  ||i |¤Ž}	||z   |_        n# ||z   |_        w xY w	 d d d ¦  «         n# 1 swxY w Y   t          j                             |j        ¦  «         |	S )Nr   )Ú_PhiloxStater   zcuda:rB   )rf   rè   )Ú torch.distributed.tensor._randomr  r   rB   r’   rW   Úclonerš   r   rD   rb   rc   rÊ   Ústate)
r  r  r‡   rr   rs   r  r  Ú
old_offsetr   r´   s
             r   r”   z.register_run_dtensor_rng_op.<locals>.impl_cudaÏ  s’  € àAÐAÐAÐAÐAÐAà��UœZ×5Ò5Ñ7Ô7Ñ8Ô8ˆØ”\×'Ò'Ñ)Ô)ˆ
Ø!Ð$5Ñ5ˆŒð ðEÝ  Q¤¨Ñ2Ô2ðEˆD�ŒGŒNˆNå”ÐC¥e¤j×&?Ò&?Ñ&AÔ&AÐCÐCÑDÔDð 	õ
 Œ\×"Ò"¨F¨8ÀÐ"ÑHÔHð 	<ð 	<ÝŒJ×$Ò$ U¤[Ñ1Ô1Ð1ð<Ø�b˜$Ð) &Ð)Ð)�à)¨OÑ;�”�ø˜z¨OÑ;�”Ð;Ð;Ð;Ð;�ð	<ð 	<ð 	<ñ 	<ô 	<ð 	<ð 	<ð 	<ð 	<ð 	<ð 	<øøøð 	<ð 	<ð 	<ð 	<õ 	Œ
× Ò  ¤Ñ-Ô-Ð-Øˆ
s*   Ã%D Ã1DÃ9D ÄDÄD Ä D$Ä'D$c                 ór   •— t          ||¦  «        }|dk    rt          d|› d�¦  «        ‚ ‰| ||g|¢R i |¤ŽS )NrB   z2run_dtensor_rng_op only supports CUDA device, got zF. This operator is designed for distributed random operations on CUDA.)ru   r   )r  r  r‡   rr   rs   r   r”   s         €r   r¤   z8register_run_dtensor_rng_op.<locals>.impl_backend_selectæ  sp   ø€ å˜D &Ñ)Ô)ˆØ�VÒÐÝðXÀVð Xð Xð Xñô ð ð ˆyÐ*¨O¸RÐQÀ$ÐQÐQÐQÈ&ÐQÐQÐQr   r¥   c                 ó   —  ||i |¤ŽS r„   r   )r  r  r‡   rr   rs   s        r   r¨   z:register_run_dtensor_rng_op.<locals>.impl_fake_tensor_modeð  rø   r   c                 ó^  •— t          ¦   «         5   ‰
|||g|¢R i |¤Ž}d d d ¦  «         n# 1 swxY w Y   t          j        | j        j        |||g|¢R ¦  «        }t          j        | j        j        |¦  «        }| j                             d‰
||¦  «        }	t          ||	d | j        ¬¦  «        S rª   rÑ   )r³   r  r  r‡   rr   rs   r´   rµ   r¶   r·   r  s             €r   r¸   z=register_run_dtensor_rng_op.<locals>.impl_proxy_dispatch_modeô  s  ø€ õ )Ñ*Ô*ð 	ð 	Ø$Ð$Ø! ?°BðØ9=ðð ð ØAGðð ˆCð	ð 	ð 	ñ 	ô 	ð 	ð 	ð 	ð 	ð 	ð 	øøøð 	ð 	ð 	ð 	õ ”_ØŒKÔ$Ð'8¸/È2Ð&UÐPTÐ&UÐ&Uñ
ô 
ˆ
õ ” t¤{Ô'?ÀÑHÔHˆØ”K×,Ò,ØÐ/°¸\ñ
ô 
ˆ	õ !  i¸$ÀtÄ{ÐSÑSÔSÐSrú   c                 óú   •— |                       |¦  «        }|                       |¦  «        }|                      ¦   «         5   ‰	|||g|¢R i |¤Ž}|                      |¦  «        cd d d ¦  «         S # 1 swxY w Y   d S r„   rÕ   )
rÙ   r  r  r‡   rr   rs   rÛ   rÜ   r´   r  s
            €r   rÝ   z4register_run_dtensor_rng_op.<locals>.impl_functional  sì   ø€ à×+Ò+¨DÑ1Ô1ˆØ×-Ò-¨fÑ5Ô5Ðà×#Ò#Ñ%Ô%ð 	)ð 	)Ø$Ð$Ø!ØØðð  ð	ð ð ð
 #ðð ˆCð ×#Ò# CÑ(Ô(ð	)ð 	)ð 	)ð 	)ñ 	)ô 	)ð 	)ð 	)ð 	)ð 	)ð 	)ð 	)øøøð 	)ð 	)ð 	)ð 	)ð 	)ð 	)s   Á #A0Á0A4Á7A4)
r   r¹   r   rº   r   r»   r¿   r   r   rÞ   )r  r¤   r¨   r¸   rÝ   r”   r  s        @@r   Úregister_run_dtensor_rng_opr   ¯  st  øø€ ðð ð ð ð Õ-ñ ô ð ð )˜Ñ*Ô*Ðà4Ð×Ò�{Ô3Ñ4Ô4Ý Ð!3ÀDÐIÑIÔIñô ð ð ×Ò¥Ô 0Ñ1Ô1ðð ñ 2Ô1ðð, ×Ò¥Ô 9Ñ:Ô:ðRð Rð Rð Rñ ;Ô:ðRõ Ð%°$Ð7Ñ7Ô7ð#ð #ñ 8Ô7ð#ð ×ÒÕ 6Ñ7Ô7ðTð Tð Tð Tñ 8Ô7ðTð  Ô-ð)ð )ð )ð )ñ .Ô-ð)ð Ðr   c                  ó"   — t          ¦   «          d S r„   )rm   r   r   r   Úregister_rng_primsr"    s   € ÝÑÔÐÐÐr   r„   )rþ   r   rÿ   N)9Útypingr   r   Útorch.utils._pytreeÚutilsÚ_pytreer¯   r   Útorch._Cr   Útorch._higher_order_ops.utilsr   r   Ú
torch._opsr   Útorch._prims_commonr	   r
   Ú"torch.fx.experimental.proxy_tensorr   r   r   Útorch.typesr   r   r   r4   rh   r<   rS   rm   ru   rÀ   rß   rz   rÅ   rë   rü   rð   Úsetrý   Ú__annotations__r  r»   Útorch._opaque_baser  Ú_CÚ_set_generator_metaclassÚ_libraryÚopaque_objectÚregister_opaque_typeÚ	GeneratorÚ
MemberTypeÚUSE_REALr   r  r"  r   r   r   ú<module>r8     s  ðà Ð Ð Ð Ð Ð Ð à €€€Ø $Ð $Ð $Ð $Ð $Ð $Ð $Ð $Ð $Ø Ð Ð Ð Ð Ð Ø  Ð  Ð  Ð  Ð  Ð  Ø QÐ QÐ QÐ QÐ QÐ QÐ QÐ QØ *Ð *Ð *Ð *Ð *Ð *Ø OÐ OÐ OÐ OÐ OÐ OÐ OÐ Oðð ð ð ð ð ð ð ð ð ð
 (Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'ðð ð ð%ð %ð %ð %ð.AØŒ:ðAð Að Að AðWØŒ:ðWð Wð Wð Wð,6ð 6ð 6ðr
ð 
ð 
ð>"ð >"ð >"ðB^ð ^ð ^ðB <Ð;Ñ=Ô=Ð Ø3Ð3Ñ5Ô5Ð ð .2ð ð ð ð ð ð&:(ð :(ð :(ðz  HÐGÑIÔIÐ à:=¸#¹%¼%Ð # S¨Ô%7Ð ?Ð ?Ñ ?ðLð Lð Lð Lð  Ð  Ô 0Ñ 1Ô 1Ð 1ð .Ð -Ð -Ð -Ð -Ð -ð „× !Ò ! .Ñ 1Ô 1Ð 1à „Ô × 1Ò 1Ø	„HÔØØ%Ð%à”.Ô.Ô9ÔBØ”.Ô.Ô9ÔBØ”.Ô.Ô9ÔBðð ð	 2ñ 	ô 	ð 	ðeð eð eðP 1Ð0Ñ2Ô2Ð ðð ð ð ð r   