§
    ŠŠtjk&  ã                   ó<  — d dl Z d dlZd dlmZ d dlmZ d dlZg d¢Zerd dlm	Z	 d dl
mZ dej        ddfd	„Zdej        fd
„Zdej        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ej        dz  fd„ZdS )é    N)Ú	Generator)ÚTYPE_CHECKING)Úset_rng_stateÚget_rng_stateÚmanual_seedÚseedÚinitial_seedÚfork_rngÚthread_safe_generator)Ú
WorkerInfo)Údefault_generatorÚ	new_stateÚreturnc                 ó.   — t          j        | ¦  «         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   s    úJ/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/torch/random.pyr   r      s   € õ Ô 	Ñ*Ô*Ð*Ð*Ð*ó    c                  ó(   — t          j        ¦   «         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_state© r   r   r   r   '   s   € õ Ô&Ñ(Ô(Ð(r   c                 ó    — 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`.
    )Ú_manual_seed_impl)r   s    r   r   r   1   s   € õ ˜TÑ"Ô"Ð"r   c                 ó  — t          | ¦  «        } dd l}|j                             ¦   «         s|j                             | ¦  «         dd l}|j                             ¦   «         s|j                             | ¦  «         dd l}|j	                             ¦   «         s|j	                             | ¦  «         dd l
}|j                             ¦   «         s|j                             | ¦  «         t          | ¦  «         t          j        | ¦  «        S )Nr   )ÚintÚ
torch.cudaÚcudaÚ_is_in_bad_forkÚmanual_seed_allÚ	torch.mpsÚmpsr   Ú	torch.xpuÚxpuÚ
torch.mtiaÚmtiaÚ_seed_custom_devicer   ©r   Útorchs     r   r   r   >   s  € Ýˆt‰9Œ9€DØÐÐÐàŒ:×%Ò%Ñ'Ô'ð )ØŒ
×"Ò" 4Ñ(Ô(Ð(àÐÐÐàŒ9×$Ò$Ñ&Ô&ð $ØŒ	×Ò˜dÑ#Ô#Ð#àÐÐÐàŒ9×$Ò$Ñ&Ô&ð (ØŒ	×!Ò! $Ñ'Ô'Ð'àÐÐÐàŒ:×%Ò%Ñ'Ô'ð )ØŒ
×"Ò" 4Ñ(Ô(Ð(å˜ÑÔÐåÔ(¨Ñ.Ô.Ð.r   c                  ó  — t          j        ¦   «         } ddl}|j                             ¦   «         s|j                             | ¦  «         ddl}|j                             ¦   «         s|j                             | ¦  «         ddl	}|j
                             ¦   «         s|j
                             | ¦  «         ddl}|j                             ¦   «         s|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&   s     r   r   r   Y   s  € õ Ô!Ñ#Ô#€DØÐÐÐàŒ:×%Ò%Ñ'Ô'ð )ØŒ
×"Ò" 4Ñ(Ô(Ð(àÐÐÐàŒ9×$Ò$Ñ&Ô&ð $ØŒ	×Ò˜dÑ#Ô#Ð#àÐÐÐàŒ9×$Ò$Ñ&Ô&ð (ØŒ	×!Ò! $Ñ'Ô'Ð'àÐÐÐàŒ:×%Ò%Ñ'Ô'ð )ØŒ
×"Ò" 4Ñ(Ô(Ð(å˜ÑÔÐà€Kr   c                 óÌ  — t          | ¦  «        } t          j                             ¦   «         }t	          t          |¦  «        r¡t          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 )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_modÚ_bad_fork_nameÚ_seed_all_nameÚmessages         r   r%   r%   w   s'  € õ ˆt‰9Œ9€DÝœ(×@Ò@ÑBÔBÐÝ�uÐ)Ñ*Ô*ð >Ý#¥EÐ+>Ñ?Ô?ÐØ*ˆØ*ˆÝÐ$ nÑ5Ô5ð 	>½'Ø˜~ñ;
ô ;
ð 	>ð >•7Ð,¨nÑ=Ô=Ñ?Ô?ð AØ:•Ð)¨>Ñ:Ô:¸4Ñ@Ô@Ð@Ð@Ð@ðAð Að mÐ':ÐlÐlÐlˆGØÐm˜>ÐmÐm°.ÐmÐmÐH[ÐmÐmÐmÑmˆGÝŒM˜'¥;¸1Ð=Ñ=Ô=Ð=Ð=Ð=ð>ð >r   c                  ó(   — t          j        ¦   «         S )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   r	   r   r   r   r	   r	   �   s   € õ Ô)Ñ+Ô+Ð+r   FTr
   Údevicesc              #   ó*  ‡K  — |dk    rdV — dS t           j                             ¦   «         }|p
|�|j        nd}t          j        |¦  «        Š‰€t          d|› d�dz   ¦  «        ‚|sdV — dS | €è‰                     ¦   «         }|dk    r±t          sª|                     ¦   «         › d|› d	|› d
|                     ¦   «         › d|                     ¦   «         › d|                     ¦   «         › d|                     ¦   «         › d|› d|› d|                     ¦   «         › d|› d|› d�}t          j
        |d¬¦  «         dat          t          |¦  «        ¦  «        } nt          | ¦  «        } t          j        ¦   «         }ˆfd„| 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.
        device_type (str): device type str, default is ``None``, in which case the type
            is taken from :func:`torch.accelerator.current_accelerator`, falling back
            to ``"cuda"`` when the type cannot be determined. As for supported devices,
            see details in :ref:`accelerator<accelerators>`
    ÚmetaNr   z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())`.é   r,   Tc                 ó:   •— g | ]}‰                      |¦  «        ‘ŒS r   )r   )Ú.0ÚdeviceÚ
device_mods     €r   ú
<listcomp>zfork_rng.<locals>.<listcomp>è   s'   ø€ ÐPÐPÐP¸f˜×1Ò1°&Ñ9Ô9ÐPÐPÐPr   )r'   ÚacceleratorÚcurrent_acceleratorÚtypeÚget_device_moduleÚRuntimeErrorÚdevice_countÚ_fork_rng_warned_alreadyÚupperr2   r3   ÚlistÚranger   r   Úzip)r;   ÚenabledÚ_callerÚ_devices_kwÚdevice_typeÚaccÚnum_devicesr9   Úcpu_rng_stateÚdevice_rng_statesrB   Údevice_rng_staterC   s               @r   r
   r
   œ   s  øè è € ð6 �fÒÐØˆˆˆØˆå
Ô
×
/Ò
/Ñ
1Ô
1€CàÐJ¨c¨o #¤( (À6€KåÔ(¨Ñ5Ô5€JØÐÝØK {ÐKÐKÐKØ<ñ=ñ
ô 
ð 	
ð ð ØˆˆˆØˆà€Ø ×-Ò-Ñ/Ô/ˆØ˜Š?ˆ?Õ#;ˆ?à×$Ò$Ñ&Ô&ð 
@ð 
@¸{ð 
@ð 
@Ø!(ð
@ð 
@à5@×5FÒ5FÑ5HÔ5Hð
@ð 
@ð 7B×6GÒ6GÑ6IÔ6Ið
@ð 
@ð )4×(9Ò(9Ñ(;Ô(;ð	
@ð 
@ð
 ×$Ò$Ñ&Ô&ð
@ð 
@ð
 BMð
@ð 
@ð
 elð
@ð 
@ð #×(Ò(Ñ*Ô*ð
@ð 
@ð 8Cð
@ð 
@ð !,ð
@ð 
@ð 
@ð õ ŒM˜'¨aÐ0Ñ0Ô0Ð0Ø'+Ð$Ý•u˜[Ñ)Ô)Ñ*Ô*ˆˆõ �w‘-”-ˆåÔ'Ñ)Ô)€MØPÐPÐPÐPÈÐPÑPÔPÐð?ØˆˆˆåÔ˜MÑ*Ô*Ð*Ý(+¨GÐ5FÑ(GÔ(Gð 	?ð 	?Ñ$ˆFÐ$Ø×$Ò$Ð%5°vÑ>Ô>Ð>Ð>ð	?ð 	?øõ 	Ô˜MÑ*Ô*Ð*Ý(+¨GÐ5FÑ(GÔ(Gð 	?ð 	?Ñ$ˆFÐ$Ø×$Ò$Ð%5°vÑ>Ô>Ð>Ð>ð	?øøøs   Æ
G ÇAHc                  óf   — ddl m}   | ¦   «         }|�|j        dk    r|j        �|j        j        S dS )as  Returns a thread-safe random number generator for use in DataLoader workers.
    This function provides a convenient way for transforms and user code to use
    thread-safe random number generation without manually checking worker context.
    When called in a DataLoader thread worker, returns the worker's thread-local
    :class:`torch.Generator`. When called in the main process or process workers,
    returns ``None`` (which causes PyTorch functions to use the default global RNG).
    Returns:
        Optional[torch.Generator]: Thread-local generator in thread workers, None otherwise.
    Example::
        >>> from torch.random import thread_safe_generator
        >>> generator = thread_safe_generator()
        >>> torch.randint(0, 10, (5,), generator=generator)
    Example with transforms::
        >>> from torch.random import thread_safe_generator
        >>> class MyRandomTransform:
        ...     def __call__(self, img):
        ...         generator = thread_safe_generator()
        ...         offset = torch.randint(0, 10, (2,), generator=generator)
        ...         return img[..., offset[0]:, offset[1]:]
    r   )Úget_worker_infoNÚthread)Útorch.utils.datarZ   Úworker_methodÚrngÚtorch_generator)rZ   Úworker_infos     r   r   r   ò   sO   € ð0 1Ð0Ð0Ð0Ð0Ð0à%4 _Ñ%6Ô%6€KàÐØÔ%¨Ò1Ð1ØŒOÐ'àŒÔ.Ð.Øˆ4r   )r   N)NTr
   r;   N)Ú
contextlibr2   Úcollections.abcr   Útypingr   r'   Ú__all__Útorch.utils.data._utils.workerr   Útorch._Cr   ÚTensorr   r   r.   r   r   r   r   r%   r	   rK   Úcontextmanagerr
   r   r   r   r   ú<module>ri      sÎ  ðà Ð Ð Ð Ø €€€Ø %Ð %Ð %Ð %Ð %Ð %Ø  Ð  Ð  Ð  Ð  Ð  à €€€ðð ð €ð ð :Ø9Ð9Ð9Ð9Ð9Ð9à &Ð &Ð &Ð &Ð &Ð &ð	+˜Uœ\ð 	+¨dð 	+ð 	+ð 	+ð 	+ð)�u”|ð )ð )ð )ð )ð
#˜œÔ+ð 
#ð 
#ð 
#ð 
#ð/˜uœxÔ1ð /ð /ð /ð /ð6ˆcð ð ð ð ð<>ð >ð >ð >ð2,�cð ,ð ,ð ,ð ,ð !Ð ð ÔàØØØØðR?ð R?ð ðR?ð R?ð R?ñ ÔðR?ðj!˜uœ°Ñ5ð !ð !ð !ð !ð !ð !r   