o
    zi                     @   sL   d Z ddlmZ ddlmZ ddlmZmZ eddeded fd	d
Z	dS )z1Utilities to help with reproducibility of models.    )contextmanager)	Generator_collect_rng_states_set_rng_statesTinclude_cudareturn)NNNc                 c   s    t | }dV  t| dS )a  A context manager that resets the global random state on exit to what it was before entering.

    It supports isolating the states for PyTorch, Numpy, and Python built-in random number generators.

    Args:
        include_cuda: Whether to allow this function to also control the `torch.cuda` random number generator.
            Set this to ``False`` when using the function in a forked process where CUDA re-initialization is
            prohibited.

    Example:
        >>> import torch
        >>> torch.manual_seed(1)  # doctest: +ELLIPSIS
        <torch._C.Generator object at ...>
        >>> with isolate_rng():
        ...     [torch.rand(1) for _ in range(3)]
        [tensor([0.7576]), tensor([0.2793]), tensor([0.4031])]
        >>> torch.rand(1)
        tensor([0.7576])

    Nr   )r   states r
   T/home/ubuntu/.local/lib/python3.10/site-packages/pytorch_lightning/utilities/seed.pyisolate_rng   s   r   N)T)
__doc__
contextlibr   typingr   lightning_fabric.utilities.seedr   r   boolr   r
   r
   r
   r   <module>   s   