
    JThw                     4   S SK Jr  S SKJr  S SKrS SKJr  SSKJrJrJ	r	J
r
  SS\\\\R                  4   S\4S	 jjrS\\   4S
 jr SS\S\\\\R                  4   SS4S jjrS\\   SS4S jrS\SS4S jrS\SS4S jrSS jrSS jrS\4S jr/ SQrg)    )Iterable)UnionN)Tensor   )
_lazy_call
_lazy_initcurrent_devicedevice_countdevicereturnc                 R   [        5         [        U [        5      (       a  [        R                  " U 5      n O,[        U [
        5      (       a  [        R                  " SU 5      n U R                  nUc
  [        5       n[        R                  R                  U   nUR                  5       $ )a6  Return the random number generator state of the specified GPU as a ByteTensor.

Args:
    device (torch.device or int, optional): The device to return the RNG state of.
        Default: ``'xpu'`` (i.e., ``torch.device('xpu')``, the current XPU device).

.. warning::
    This function eagerly initializes XPU.
xpu)r   
isinstancestrtorchr   intindexr	   r   default_generators	get_state)r   idxdefault_generators      H/var/www/auris/envauris/lib/python3.13/site-packages/torch/xpu/random.pyget_rng_stater      s{     L&#f%	FC	 	 eV,
,,C
{		44S9&&((    c                  h    [        [        5       5       V s/ s H  n [        U 5      PM     nn U$ s  sn f )zQReturn a list of ByteTensor representing the random number states of all devices.)ranger
   r   )iresultss     r   get_rng_state_allr   !   s/    ).|~)>?)>A}Q)>G?N @s   /	new_statec                   ^^ [         R                  R                  5          U R                  [         R                  S9mSSS5        [        T[        5      (       a  [         R                  " T5      mO,[        T[        5      (       a  [         R                  " ST5      mUU4S jn[        U5        g! , (       d  f       Ny= f)a  Set the random number generator state of the specified GPU.

Args:
    new_state (torch.ByteTensor): The desired state
    device (torch.device or int, optional): The device to set the RNG state.
        Default: ``'xpu'`` (i.e., ``torch.device('xpu')``, the current XPU device).
)memory_formatNr   c                     > TR                   n U c
  [        5       n [        R                  R                  U    nUR                  T5        g N)r   r	   r   r   r   	set_state)r   r   r   new_state_copys     r   cbset_rng_state.<locals>.cb8   s<    ll; "C!II88=##N3r   )
r   _C_DisableFuncTorchclonecontiguous_formatr   r   r   r   r   )r    r   r'   r&   s    ` @r   set_rng_stater-   '   s     
	#	#	%"u7N7NO 
&&#f%	FC	 	 eV,4 rN 
&	%s   B22
C 
new_statesc                 B    [        U 5       H  u  p[        X!5        M     g)zSet the random number generator state of all devices.

Args:
    new_states (Iterable of torch.ByteTensor): The desired state for each device.
N)	enumerater-   )r.   r   states      r   set_rng_state_allr2   B   s     j)e *r   seedc                 <   ^  [        T 5      m U 4S jn[        USS9  g)al  Set the seed for generating random numbers for the current GPU.

It's safe to call this function if XPU is not available; in that case, it is silently ignored.

Args:
    seed (int): The desired seed.

.. warning::
    If you are working with a multi-GPU model, this function is insufficient
    to get determinism.  To seed all GPUs, use :func:`manual_seed_all`.
c                  v   > [        5       n [        R                  R                  U    nUR	                  T5        g r$   )r	   r   r   r   manual_seed)r   r   r3   s     r   r'   manual_seed.<locals>.cbZ   s.    !II88=%%d+r   T)r3   Nr   r   r3   r'   s   ` r   r6   r6   L   s     t9D,
 rr   c                 <   ^  [        T 5      m U 4S jn[        USS9  g)zSet the seed for generating random numbers on all GPUs.

It's safe to call this function if XPU is not available; in that case, it is silently ignored.

Args:
    seed (int): The desired seed.
c                     > [        [        5       5       H1  n [        R                  R                  U    nUR                  T5        M3     g r$   )r   r
   r   r   r   r6   )r   r   r3   s     r   r'   manual_seed_all.<locals>.cbl   s7    |~&A %		 < <Q ?))$/ 'r   T)seed_allNr8   r9   s   ` r   manual_seed_allr>   b   s     t9D0
 rD!r   c                       S n [        U 5        g)a[  Set the seed for generating random numbers to a random number for the current GPU.

It's safe to call this function if XPU is not available; in that case, it is silently ignored.

.. warning::
    If you are working with a multi-GPU model, this function will only initialize
    the seed on one GPU.  To initialize all GPUs, use :func:`seed_all`.
c                  r    [        5       n [        R                  R                  U    nUR	                  5         g r$   )r	   r   r   r   r3   r   r   s     r   r'   seed.<locals>.cb~   s+    !II88= r   Nr   r'   s    r   r3   r3   t   s    !
 rNr   c                       S n [        U 5        g)zSet the seed for generating random numbers to a random number on all GPUs.

It's safe to call this function if XPU is not available; in that case, it is silently ignored.
c                      Sn Sn[        [        5       5       H\  n[        R                  R                  U   nU(       d$  UR                  5         UR                  5       n SnMK  UR                  U 5        M^     g )Nr   FT)r   r
   r   r   r   r3   initial_seedr6   )random_seedseededr   r   s       r   r'   seed_all.<locals>.cb   sb    |~&A %		 < <Q ?!&&(/<<>!--k: 'r   NrC   rD   s    r   r=   r=      s    
; rNr   c                      [        5         [        5       n [        R                  R                  U    nUR                  5       $ )zlReturn the current random seed of the current GPU.

.. warning::
    This function eagerly initializes XPU.
)r   r	   r   r   r   rG   rA   s     r   rG   rG      s5     L

C		44S9))++r   )	r   r   r-   r2   r6   r>   r3   r=   rG   )r   )r   N)collections.abcr   typingr   r   r    r   r   r	   r
   r   r   r   r   listr   r-   r2   r6   r>   r3   r=   rG   __all__ r   r   <module>rR      s    $    B B)%S%,, 67 )F ),4<  @E$S#u||%;<	6 (6"2  t  c d ,"# "$ "$$*	,c 	,
r   