
    <Цi+                         % S r SSKrSSKrSSKJrJrJrJrJrJ	r	J
r
  SSKrSSKJrJr  SSKJrJrJr  SSKJr  SSKJr  \
\\\4   r\R4                  r\R6                  rS	q/ q\\	\/ S4   \\   4      \S
'   \R>                  " 5       r \RB                  " 5       r"\" 5       r#S r$S r%S\&4S jr'S)S jr( " S S\)5      r*S\&4S jr+S\&4S jr,S*S\\   SS4S jjr-S\4S jr.S\4S jr/S*S\\   S\4S jjr0S*S\\   S\4S jjr1S*S\\   S\	\\4   4S jjr2S)S jr3S\4S jr4S\SS4S jr5 " S S5      r " S  S!5      r6S\S"   S\64S# jr7S+S\
\\\R                  4   S\4S$ jjr8 S+S%\S\
\\\R                  4   SS4S& jjr9SS'K:7  / S(Qr;g),zH
This package enables an interface for accessing MTIA backend in python
    N)AnyCallableDictListOptionalTupleUnion)deviceTensor)_dummy_type_LazySeedTrackerclassproperty)Device   )_get_device_indexF_queued_callsc                      [        5         g N)
_lazy_init     R/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/torch/mtia/__init__.pyinitr   !   s    Lr   c                  :    [         =(       a    [        5       (       + $ )z9Return whether PyTorch's MTIA state has been initialized.)_initialized_is_in_bad_forkr   r   r   is_initializedr   %   s    1 111r   returnc                  >    [         R                  R                  5       $ r   )torch_C_mtia_isInBadForkr   r   r   r   r   *   s    88%%''r   c            	         [        5       (       d  [        [        S5      (       a  g [           [        5       (       a
   S S S 5        g [	        5       (       a  [        S5      e[        5       (       d  [        S5      e[        R                  R                  5         S[        l        [        R                  S [        R                  5        5       5         [         H  u  p U " 5         M     [)        [        S5        SqS S S 5        g ! [          a1  nS[#        U5       SSR%                  U5       3n['        U5      UeS nAff = f! [)        [        S5        f = f! , (       d  f       g = f)	Nis_initializingzwCannot re-initialize MTIA in forked subprocess. To use MTIA with multiprocessing, you must use the 'spawn' start methodzTorch not compiled with MTIA enabled. Ensure you have `import mtia.host_runtime.torch_mtia` in your python src file and include `//mtia/host_runtime/torch_mtia:torch_mtia` as your target dependency!Tc              3   6   #    U  H  o(       d  M  Uv   M     g 7fr   r   ).0callss     r   	<genexpr>_lazy_init.<locals>.<genexpr>P   s     X0NuRWUU0Ns   
	z6MTIA call failed lazily at initialization with error: z(

MTIA call was originally invoked at:

 )r   hasattr_tls_initialization_lockr   RuntimeError_is_compiledAssertionErrorr    r!   
_mtia_initr$   r   extend_lazy_seed_tracker	get_calls	ExceptionstrjoinDeferredMtiaCallErrordelattrr   )queued_callorig_tracebackemsgs       r   r   r   .   sH   74):;;	  
	 I  ~~ *  	  $X0B0L0L0NXX	-/<+<M 0= D+,Y 
	H ! <PQTUVQWPX YCCE77>CZB[]  04!;< D+,W 
	sN   EBEED%E)E
D?,D::D??EEE
E%c                       \ rS rSrSrg)r8   a   r   N)__name__
__module____qualname____firstlineno____static_attributes__r   r   r   r8   r8   a   s    r   r8   c                  >    [         R                  R                  5       $ )z*Return true if compiled with MTIA support.)r    r!   _mtia_isBuiltr   r   r   r/   r/   e   s    88!!##r   c                  <    [        5       (       d  g[        5       S:  $ )z'Return true if MTIA device is availableFr   )r/   device_countr   r   r   is_availablerI   j   s    >>>Ar   r
   c                     [         R                  R                  U 5         [         R                  R	                  5       sSSS5        $ ! , (       d  f       g= f)z?Waits for all jobs in all streams on a MTIA device to complete.N)r    mtiar
   r!   _mtia_deviceSynchronizer
   s    r   synchronizerN   r   s0    			6	"xx//1 
#	"	"s   A
Ac                  >    [         R                  R                  5       $ )z,Return the number of MTIA devices available.)r    r!   _accelerator_hooks_device_countr   r   r   rH   rH   x   s    883355r   c                  >    [         R                  R                  5       $ )z0Return the index of a currently selected device.)r    r!   %_accelerator_hooks_get_current_devicer   r   r   current_devicerS   }   s    8899;;r   c                 P    [         R                  R                  [        U SS95      $ )a;  Return the currently selected :class:`Stream` for a given device.

Args:
    device (torch.device or int, optional): selected device. Returns
        the currently selected :class:`Stream` for the current device, given
        by :func:`~torch.mtia.current_device`, if :attr:`device` is ``None``
        (default).
Toptional)r    r!   _mtia_getCurrentStreamr   rM   s    r   current_streamrX      !     88**+<Vd+STTr   c                 P    [         R                  R                  [        U SS95      $ )a%  Return the default :class:`Stream` for a given device.

Args:
    device (torch.device or int, optional): selected device. Returns
        the default :class:`Stream` for the current device, given by
        :func:`~torch.mtia.current_device`, if :attr:`device` is ``None``
        (default).
TrU   )r    r!   _mtia_getDefaultStreamr   rM   s    r   default_streamr\      rY   r   c                 P    [         R                  R                  [        U SS95      $ )a  Return capability of a given device as a tuple of (major version, minor version).

Args:
    device (torch.device or int, optional) selected device. Returns
        statistics for the current device, given by current_device(),
        if device is None (default).
TrU   )r    r!   _mtia_getDeviceCapabilityr   rM   s    r   get_device_capabilityr_      s"     88--.?QU.VWWr   c                  >    [         R                  R                  5       $ )zEmpty the MTIA device cache.)r    r!   _mtia_emptyCacher   r   r   empty_cacherb      s    88$$&&r   streamc                 J    U c  g[         R                  R                  U 5        g)a  Set the current stream.This is a wrapper API to set the stream.
    Usage of this function is discouraged in favor of the ``stream``
    context manager.

Args:
    stream (Stream): selected stream. This function is a no-op
        if this argument is ``None``.
N)r    r!   _mtia_setCurrentStreamrc   s    r   
set_streamrg      s     ~	HH##F+r   c                 f    [        U 5      n U S:  a   [        R                  R                  U 5        gg)zSet the current device.

Args:
    device (torch.device or int): selected device. This function is a no-op
        if this argument is negative.
r   N)r   r    r!   %_accelerator_hooks_set_current_devicerM   s    r   
set_devicerj      s,     v&F{66v> r   c                   B    \ rS rSrSrS \4S jrS rS\S\S\4S jrS	r	g
)r
      zContext-manager that changes the selected device.

Args:
    device (torch.device or int): device index to select. It's a no-op if
        this argument is a negative integer or ``None``.
c                 0    [        USS9U l        SU l        g )NTrU   )r   idxprev_idx)selfr
   s     r   __init__device.__init__   s    $Vd;r   c                 `    [         R                  R                  U R                  5      U l        g r   )r    r!   (_accelerator_hooks_maybe_exchange_devicero   rp   )rq   s    r   	__enter__device.__enter__   s    II$((Sr   typevalue	tracebackc                 `    [         R                  R                  U R                  5      U l        g)NF)r    r!   ru   rp   ro   )rq   rx   ry   rz   s       r   __exit__device.__exit__   s    88DDT]]Sr   )ro   rp   N)
r@   rA   rB   rC   __doc__r   rr   rv   r|   rD   r   r   r   r
   r
      s3    s TS   r   c                   Z    \ rS rSr% Sr\S   \S'   S\S   4S jrS rS\	S	\	S
\	4S jr
Srg)StreamContext   a  Context-manager that selects a given stream.

All MTIA kernels queued within its context will be enqueued on a selected
stream.

Args:
    Stream (Stream): selected stream. This manager is a no-op if it's
        ``None``.
.. note:: Streams are per-device.
torch.mtia.Stream
cur_streamrc   c                    S U l         Xl        [        S S5      U l        [        R
                  R                  5       (       d  U R                  c  SU l        [        R
                  R                  5       (       d  S O[        R                  R                  S 5      U l	        [        R
                  R                  5       (       d  S U l
        g [        R                  R                  S 5      U l
        g )NTrn   )r   rc   r   ro   r    jitis_scriptingrK   r\   src_prev_streamdst_prev_stream)rq   rc   s     r   rr   StreamContext.__init__   s    $T40yy%%''xx 		..00Dejj6O6OPT6U 	 		..00D 	6;jj6O6OPT6U 	r   c                    U R                   nUb  U R                  S:X  a  g [        R                  R	                  S 5      U l        U R
                  R                  UR                  :w  aL  [        UR                  5         [        R                  R	                  UR                  5      U l        S S S 5        [        R                  R                  U5        g ! , (       d  f       N.= fNrn   )	rc   ro   r    rK   rX   r   r
   r   rg   )rq   r   s     r   rv   StreamContext.__enter__   s    [[
R$zz88> &&**;*;;
))*',zz'@'@ARAR'S$ +

j) +*s   >/C
C#rx   ry   rz   c                 0   U R                   nUb  U R                  S:X  a  g U R                  R                  UR                  :w  a)  [        R
                  R                  U R                  5        [        R
                  R                  U R                  5        g r   )rc   ro   r   r
   r    rK   rg   r   )rq   rx   ry   rz   r   s        r   r|   StreamContext.__exit__  sj    [[
R &&**;*;;JJ!!$"6"67

d223r   )r   r   ro   r   rc   N)r@   rA   rB   rC   r~   r   __annotations__rr   rv   r   r|   rD   r   r   r   r   r      sF    	 ,--
x(;< 
*4S 4 4 4r   r   r   c                     [        U 5      $ )a  Wrap around the Context-manager StreamContext that selects a given stream.

Arguments:
    stream (Stream): selected stream. This manager is a no-op if it's
        ``None``.
..Note:: In eager mode stream is of type Stream class while in JIT it doesn't support torch.mtia.stream
)r   rf   s    r   rc   rc     s       r   c                     [         R                  " S[        SS9  [        R                  " S/[        R
                  U S9$ )zReturns the random number generator state as a ByteTensor.

Args:
    device (torch.device or int, optional): The device to return the RNG state of.
        Default: ``'mtia'`` (i.e., ``torch.device('mtia')``, the current mtia device).
z.get_rng_state is not implemented in torch.mtia   
stacklevelr   )dtyper
   )warningswarnUserWarningr    zerosuint8rM   s    r   get_rng_stater     s4     MM8
 ;;s%++f==r   	new_statec                 8    [         R                  " S[        SS9  g)a  Sets the random number generator state.

Args:
    new_state (torch.ByteTensor): The desired state
    device (torch.device or int, optional): The device to set the RNG state.
        Default: ``'mtia'`` (i.e., ``torch.device('mtia')``, the current mtia device).
z.set_rng_state is not implemented in torch.mtiar   r   N)r   r   r   )r   r
   s     r   set_rng_stater   ,  s     MM8r   )*)r   rI   r   rN   rH   rS   rX   r\   memory_statsmax_memory_allocatedr_   rb   rj   rg   rc   r
   r   r   )r   Nr   )rK   )<r~   	threadingr   typingr   r   r   r   r   r   r	   r    r
   _devicer   torch._utilsr   r   r   torch.typesr   _utilsr   r6   int	_device_tEventStreamr   r   r   localr,   Lockr-   r3   r   r   boolr   r   r5   r8   r/   rI   rN   rH   rS   rX   r\   r_   rb   rg   rj   r   rc   r   r   memory__all__r   r   r   <module>r      s+     D D D  + E E  % '3#$	 		  t	(2t8
d3i
'(   ~~' %' 2
( (0f	I 	$d $
d 2+ 2t 26c 6
< <
	U8I. 	U& 	U	U8I. 	U& 	UX(9"5 XsCx X'
,v ,	?y 	?T 	? (74 74t!8/0 !] !>%S%,, 67 >V >  @F$S#u||%;<	" r   