o
    /ôj×  ã                   @   sª   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d„Zdejfdd	„Z	dej
jfd
d„Zdefdd„Zddd„Zdefdd„Zdae jddefdd„ƒZdS )é    N)Ú	Generator)Údefault_generatorÚ	new_stateÚreturnc                 C   s   t  | ¡ dS )zûSets the random number generator state.

    .. note:: This function only works for CPU. For CUDA, please use
        :func:`torch.manual_seed`, which works for both CPU and CUDA.

    Args:
        new_state (torch.ByteTensor): The desired state
    N)r   Ú	set_state)r   © r   ú]/var/www/html/academy/tools/voices/clone/sv-venv/lib/python3.10/site-packages/torch/random.pyÚset_rng_state
   s   	r	   c                   C   ó   t  ¡ S )zÁReturns the random number generator state as a `torch.ByteTensor`.

    .. note:: The returned state is for the default generator on CPU only.

    See also: :func:`torch.random.fork_rng`.
    )r   Ú	get_stater   r   r   r   Úget_rng_state   s   r   c                 C   st   t | ƒ} ddl}|j ¡ s|j | ¡ ddl}|j ¡ s"|j | ¡ ddl}|j	 ¡ s1|j	 | ¡ t
| ƒ t | ¡S )aŸ  Sets the seed for generating random numbers on all devices. 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)ÚintÚ
torch.cudaÚcudaÚ_is_in_bad_forkÚmanual_seed_allÚ	torch.mpsÚmpsÚmanual_seedÚ	torch.xpuÚxpuÚ_seed_custom_devicer   ©ÚseedÚtorchr   r   r   r       s   




r   c                  C   sn   t  ¡ } ddl}|j ¡ s|j | ¡ ddl}|j ¡ s"|j | ¡ ddl	}|j
 ¡ s1|j
 | ¡ t| ƒ | S )z—Sets the seed for generating random numbers to a non-deterministic
    random number on all devices. Returns a 64 bit number used to seed the RNG.
    r   N)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   =   s   


r   c                 C   s¤   t | ƒ} tj ¡ }tt|ƒrPtt|ƒ}d}d}t||ƒr2t||ƒr2t||ƒƒ s0t||ƒ| ƒ dS dS d|› d�}|d|› d|› d|› d�7 }tj|td	d
� dS dS )z­Sets 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_nameÚhasattrÚgetattrÚwarningsÚwarnÚUserWarning)r   Úcustom_backend_nameÚcustom_device_modZ_bad_fork_nameZ_seed_all_nameÚmessager   r   r   r   T   s   


ÿör   c                   C   r
   )zžReturns the initial seed for generating random numbers as a
    Python `long`.

    .. note:: The returned seed is for the default generator on CPU only.
    )r   Úinitial_seedr   r   r   r   r(   k   s   r(   FTÚfork_rngÚdevicesr   c                 #   sf  � t  |¡j}tt |dƒ‰ ˆ du rtd|› d�d ƒ‚|s"dV  dS | du rpˆ  ¡ }|dkritsi| ¡ › d|› d|› d| ¡ › d	| ¡ › d
| ¡ › d| ¡ › d|› d|› d| ¡ › d|› d|› d�}t 	|¡ dat
t|ƒƒ} nt
| ƒ} t  ¡ }‡ fdd„| D ƒ}zdV  W t  |¡ t| |ƒD ]
\}	}
ˆ  |
|	¡ q�dS t  |¡ t| |ƒD ]
\}	}
ˆ  |
|	¡ q§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.
        device_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())`.Tc                    s   g | ]}ˆ   |¡‘qS r   )r   )Ú.0Údevice©Z
device_modr   r   Ú
<listcomp>°   s    zfork_rng.<locals>.<listcomp>)r   r-   Útyper!   ÚRuntimeErrorÚdevice_countÚ_fork_rng_warned_alreadyÚupperr"   r#   ÚlistÚranger   r	   Úzip)r*   ÚenabledÚ_callerZ_devices_kwÚdevice_typeZnum_devicesr'   Zcpu_rng_stateZdevice_rng_statesr-   Zdevice_rng_stater   r.   r   r)   w   sd   €ÿÿþýüûûûø	÷
ö

ÿ
ÿÿ)r   N)NTr)   r*   r   )Ú
contextlibÚtypingr   r"   Útorch._Cr   r   ÚTensorr	   r   r   r   r   r   r   r(   r3   Úcontextmanagerr)   r   r   r   r   Ú<module>   s   

	