
    IЦi                     0   S SK JrJrJr  S SKrS SKJr  SSKJrJrJ	r	J
r
  / SQ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g)    )IterableListUnionN)Tensor   )
_lazy_call
_lazy_initcurrent_devicedevice_count)	get_rng_stateget_rng_state_allset_rng_stateset_rng_state_allmanual_seedmanual_seed_allseedseed_allinitial_seed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       $ )a:  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: ``'cuda'`` (i.e., ``torch.device('cuda')``, the current CUDA device).

.. warning::
    This function eagerly initializes CUDA.
cuda)r	   
isinstancestrtorchr   intindexr
   r   default_generators	get_state)r   idxdefault_generators      P/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/torch/cuda/random.pyr   r      s{     L&#f%	FC	 	 ff-
,,C
{

55c:&&((    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"   r   r   -   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: ``'cuda'`` (i.e., ``torch.device('cuda')``, the current CUDA 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>.cbD   s<    ll; "C!JJ99#>##N3r#   )
r   _C_DisableFuncTorchclonecontiguous_formatr   r   r   r   r   )r(   r   r/   r.   s    ` @r"   r   r   3   s     
	#	#	%"u7N7NO 
&&#f%	FC	 	 ff-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   )r5   r&   states      r"   r   r   N   s     j)e *r#   r   c                 <   ^  [        T 5      m U 4S jn[        USS9  g)am  Set the seed for generating random numbers for the current GPU.

It's safe to call this function if CUDA 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   r   )r    r!   r   s     r"   r/   manual_seed.<locals>.cbg   s.    !JJ99#>%%d+r#   T)r   Nr   r   r   r/   s   ` r"   r   r   X   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 CUDA 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   r   )r&   r!   r   s     r"   r/   manual_seed_all.<locals>.cbz   s7    |~&A %

 = =a @))$/ 'r#   T)r   Nr<   r=   s   ` r"   r   r   o   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 CUDA 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   r   r    r!   s     r"   r/   seed.<locals>.cb   s+    !JJ99#> r#   Nr   r/   s    r"   r   r      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 CUDA 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   r   r   r   )random_seedseededr&   r!   s       r"   r/   seed_all.<locals>.cb   sb    |~&A %

 = =a @!&&(/<<>!--k: 'r#   NrE   rF   s    r"   r   r      s    
; rNr#   c                      [        5         [        5       n [        R                  R                  U    nUR                  5       $ )zmReturn the current random seed of the current GPU.

.. warning::
    This function eagerly initializes CUDA.
)r	   r
   r   r   r   r   rC   s     r"   r   r      s5     L

C

55c:))++r#   )r   )r   N)typingr   r   r   r   r    r   r	   r
   r   __all__r   r   r   r   r   r   r   r   r   r   r   r    r#   r"   <module>rQ      s    ( (   B B
)%S%,, 67 )V ),4<  @F$S#u||%;<	6 (6"2  t  c d ."# "$ "&&,	,c 	,r#   