
    #h                         d dl Z d dlmZ d dlZd dlmZ d dlZdej        ddfdZdej        fdZ	dej
        j        fdZdefd	Zdd
ZdefdZdae j        ddefd            ZdS )    N)	Generator)default_generator	new_statereturnc                 .    t          j        |            dS )zSets the random number generator state.

    .. note: This function only works for CPU. For CUDA, please use
             torch.manual_seed(seed), which works for both CPU and CUDA.

    Args:
        new_state (torch.ByteTensor): The desired state
    N)r   	set_state)r   s    L/var/www/html/auto_sub_bot/venv/lib/python3.11/site-packages/torch/random.pyset_rng_stater
   	   s     	*****    c                  (    t          j                    S )zBReturns the random number generator state as a `torch.ByteTensor`.)r   	get_state r   r	   get_rng_stater      s    &(((r   c                    t          |           } ddl}|j                                        s|j                            |            ddl}|j                                        s|j                            |            t          |d          r3|j	                                        s|j	                            |            t          |            t          j        |           S )a  Sets the seed for generating random numbers. Returns a
    `torch.Generator` object.

    Args:
        seed (int): The desired seed. Value must be within the inclusive range
            `[-0x8000_0000_0000_0000, 0xffff_ffff_ffff_ffff]`. Otherwise, a RuntimeError
            is raised. Negative inputs are remapped to positive values with the formula
            `0xffff_ffff_ffff_ffff + seed`.
    r   Nxpu)int
torch.cudacuda_is_in_bad_forkmanual_seed_all	torch.mpsmpsmanual_seedhasattrr   _seed_custom_devicer   seedtorchs     r	   r   r      s     t99D:%%'' )
""4(((9$$&& $	d###ue (UY%>%>%@%@ (	!!$'''(...r   c                     t          j                    } ddl}|j                                        s|j                            |            ddl}|j                                        s|j                            |            t          |d          r3|j
                                        s|j
                            |            t          |            | S )zSets the seed for generating random numbers to a non-deterministic
    random number. Returns a 64 bit number used to seed the RNG.
    r   Nr   )r   r   r   r   r   r   r   r   r   r   r   r   r   s     r	   r   r   6   s     !##D:%%'' )
""4(((9$$&& $	d###ue (UY%>%>%@%@ (	!!$'''Kr   c                    t          |           } t          j                                        }t	          t          |          rt          t          |          }d}d}t	          ||          rEt	          ||          r5 t          ||                      s t          ||          |            dS dS d| d}|d| d| d| dz  }t          j        |t          d	
           dS dS )zSets the seed to generate random numbers for custom device.

    Args:
        seed (int): The desired seed.

    See [Note: support the custom device with privateuse1]
    r   r   zSet seed for `z0` device does not take effect, please add API's `z` and `z` to `z` device module.   )
stacklevelN)	r   r   _C_get_privateuse1_backend_namer   getattrwarningswarnUserWarning)r   custom_backend_namecustom_device_mod_bad_fork_name_seed_all_namemessages         r	   r   r   L   s"    t99D(@@BBu)** 
>#E+>??**$n55 	>'BSUc:d:d 	>=7,n==?? A:)>::4@@@@@A A m':lllGm>mm.mmH[mmmmGM';1======
> 
>r   c                  (    t          j                    S )zSReturns the initial seed for generating random numbers as a
    Python `long`.
    )r   initial_seedr   r   r	   r0   r0   c   s     )+++r   FTfork_rngdevicesr   c              #   .  K   t          j        |          j        }t          t           |d          }|t	          d| ddz             |sdV  dS | |                                }|dk    rt          s|                                 d| d| d|                                 d	|                                 d
|                                 d|                                 d| d| d|                                 d| d| d}t          j	        |           dat          t          |                    } nt          |           } t          j                    }g }	| D ]*}
|	                    |                    |
                     +	 dV  t          j        |           t          | |	          D ]\  }
}|                    ||
           dS # t          j        |           t          | |	          D ]\  }
}|                    ||
           w xY w)a  
    Forks the RNG, so that when you return, the RNG is reset
    to the state that it was previously in.

    Args:
        devices (iterable of Device IDs): devices for which to fork
            the RNG. CPU RNG state is always forked. By default, :meth:`fork_rng` operates
            on all devices, but will emit a warning if your machine has a lot
            of devices, since this function will run very slowly in that case.
            If you explicitly specify devices, this warning will be suppressed
        enabled (bool): if ``False``, the RNG is not forked.  This is a convenience
            argument for easily disabling the context manager without having
            to delete it and unindent your Python code under it.
        deivce_type (str): device type str, default is `cuda`. As for custom device,
            see details in [Note: support the custom device with privateuse1]
    Nztorch has no module of `z`, you should register z,a module by `torch._register_device_module`.   z reports that you have z& available devices, and you have used z_ without explicitly specifying which devices are being used. For safety, we initialize *every* zA device by default, which can be quite slow if you have a lot of z5s. If you know that you are only making use of a few z' devices, set the environment variable z_VISIBLE_DEVICES or the 'z' keyword argument of z with the set of devices you are actually using. For example, if you are using CPU only, set device.upper()_VISIBLE_DEVICES= or devices=[]; if you are using device 0 only, set zb_VISIBLE_DEVICES=0 or devices=[0].  To initialize all devices and suppress this warning, set the 'z#' keyword argument to `range(torch.z.device_count())`.T)r   devicetyper&   RuntimeErrordevice_count_fork_rng_warned_alreadyupperr'   r(   listranger   appendr
   zip)r2   enabled_caller_devices_kwdevice_type
device_modnum_devicesr.   cpu_rng_statedevice_rng_statesr5   device_rng_states               r	   r1   r1   m   s     & ,{++0KT22JZkZZZIJ K K 	K   --//??#;?%++-- 
G 
Gk 
G 
G(/
G 
G<G<M<M<O<O
G 
G >I=N=N=P=P
G 
G 0;/@/@/B/B	
G 
G
 &++--
G 
G
 IT
G 
G
 ls
G 
G *//11
G 
G ?J
G 
G (3
G 
G 
GG M'"""'+$u[))** w--'))M C C  !9!9&!A!ABBBB?M***(+G5F(G(G 	? 	?$F$$$%5v>>>>	? 	? 	M***(+G5F(G(G 	? 	?$F$$$%5v>>>>	?s   G AH)r   N)NTr1   r2   r   )
contextlibtypingr   r'   torch._Cr   r   Tensorr
   r   r$   r   r   r   r   r0   r9   contextmanagerr1   r   r   r	   <module>rM      s=              & & & & & & 	+U\ 	+d 	+ 	+ 	+ 	+)u| ) ) ) )
/+ / / / /8c    ,> > > >.,c , , , , !  A? A?kt A? A? A? A? A? A?r   