o
    +ôj‡  ã                   @   s   d dl mZmZmZ d dlZddlmZ ddlmZmZm	Z	m
Z
 g d¢Zdd	eeeejf d
efdd„Zd
ee fdd„Z	dded	eeeejf d
dfdd„Zdee d
dfdd„Zded
dfdd„Zded
dfdd„Zd dd„Zd dd„Zd
efdd„ZdS )!é    )Ú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ÚcudaÚdeviceÚreturnc                 C   sZ   t ƒ  t| tƒrt | ¡} nt| tƒrt d| ¡} | j}|du r#tƒ }tjj	| }| 
¡ S )aR  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.
    r   N)r	   Ú
isinstanceÚstrÚtorchr   ÚintÚindexr
   r   Údefault_generatorsÚ	get_state)r   ÚidxÚdefault_generator© r!   úd/var/www/html/academy/tools/voices/clone/cosy-venv/lib/python3.10/site-packages/torch/cuda/random.pyr      s   


r   c                  C   s&   g } t tƒ ƒD ]	}|  t|ƒ¡ q| S )zQReturn a list of ByteTensor representing the random number states of all devices.)Úranger   Úappendr   )ÚresultsÚir!   r!   r"   r   *   s   r   Ú	new_statec                    s~   t j ¡ � | jt jd�‰W d  ƒ n1 sw   Y  tˆ tƒr't  ˆ ¡‰ ntˆ tƒr2t  dˆ ¡‰ ‡ ‡fdd„}t	|ƒ dS )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                     s.   ˆ j } | d u r
tƒ } tjj|  }| ˆ¡ d S ©N)r   r
   r   r   r   Ú	set_state©r   r    ©r   Znew_state_copyr!   r"   ÚcbC   s
   zset_rng_state.<locals>.cb)
r   Ú_CÚ_DisableFuncTorchÚcloneÚcontiguous_formatr   r   r   r   r   )r'   r   r-   r!   r,   r"   r   2   s   
ÿ

r   Ú
new_statesc                 C   s    t | ƒD ]	\}}t||ƒ qdS )z›Set the random number generator state of all devices.

    Args:
        new_states (Iterable of torch.ByteTensor): The desired state for each device.
    N)Ú	enumerater   )r2   r&   Ústater!   r!   r"   r   M   s   ÿr   r   c                    ó$   t ˆ ƒ‰ ‡ fdd„}t|dd� dS )a�  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                     s    t ƒ } tjj|  }| ˆ ¡ d S r)   )r
   r   r   r   r   r+   ©r   r!   r"   r-   f   s   zmanual_seed.<locals>.cbTr6   N©r   r   ©r   r-   r!   r6   r"   r   W   s   r   c                    r5   )zÖSet 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                     s*   t tƒ ƒD ]} tjj|  }| ˆ ¡ qd S r)   )r#   r   r   r   r   r   )r&   r    r6   r!   r"   r-   y   s   þzmanual_seed_all.<locals>.cbT)r   Nr7   r8   r!   r6   r"   r   n   s   	r   c                  C   ó   dd„ } t | ƒ dS )at  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                  S   s   t ƒ } tjj|  }| ¡  d S r)   )r
   r   r   r   r   r+   r!   r!   r"   r-   Œ   s   zseed.<locals>.cbN©r   ©r-   r!   r!   r"   r   �   s   c                  C   r9   )z¸Set 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   sL   d} d}t tƒ ƒD ]}tjj| }|s| ¡  | ¡ } d}q	| | ¡ q	d S )Nr   FT)r#   r   r   r   r   r   r   r   )Zrandom_seedZseededr&   r    r!   r!   r"   r-   ›   s   ùzseed_all.<locals>.cbNr:   r;   r!   r!   r"   r   ”   s   r   c                  C   s    t ƒ  tƒ } tjj|  }| ¡ S )zyReturn the current random seed of the current GPU.

    .. warning::
        This function eagerly initializes CUDA.
    )r	   r
   r   r   r   r   r+   r!   r!   r"   r   ª   s   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!   r!   r"   Ú<module>   s*     	ÿÿÿ
þ


