

from typing import List, Optional, Tuple, Union

from . import logging
from .import_utils import is_torch_available, is_torch_version


if is_torch_available():
     import torch

lowercase_									=    logging.get_logger(__name__)  # pylint: disable=invalid-name

try:
     from torch._dynamo import allow_in_graph as maybe_allow_in_graph
except (ImportError, ModuleNotFoundError):
     def 		_snake_case(       cls     :      List[str] )				-> Any:





         '''simple docstring'''






         return cls
def 		_snake_case(       SCREAMING_SNAKE_CASE__     :      Union[Tuple, List]       ,     SCREAMING_SNAKE_CASE__     :      Optional[Union[List["torch.Generator"], "torch.Generator"]] = None       ,     SCREAMING_SNAKE_CASE__     :      Optional["torch.device"] = None       ,     SCREAMING_SNAKE_CASE__     :      Optional["torch.dtype"] = None       ,     SCREAMING_SNAKE_CASE__     :      Optional["torch.layout"] = None       ,     )				-> List[Any]:





    '''simple docstring'''






    A__        =  device
    A__        =  shape[0]

    A__        =  layout or torch.strided
    A__        =  device or torch.device('cpu' )

    if generator is not None:
        A__        =  generator.device.type if not isinstance(SCREAMING_SNAKE_CASE__       ,     SCREAMING_SNAKE_CASE__ ) else generator[0].device.type
        if gen_device_type != device.type and gen_device_type == "cpu":
            A__        =  'cpu'
            if device != "mps":
                logger.info(
                    f'The passed generator was created on \'cpu\' even though a tensor on {device} was expected.'
                    f' Tensors will be created on \'cpu\' and then moved to {device}. Note that one can probably'
                    f' slighly speed up this function by passing a generator that was created on the {device} device.' )
        elif gen_device_type != device.type and gen_device_type == "cuda":
            raise ValueError(f'Cannot generate a {device} tensor from a generator of type {gen_device_type}.' )

    if isinstance(SCREAMING_SNAKE_CASE__       ,     SCREAMING_SNAKE_CASE__ ):
        A__        =  (1,) + shape[1:]
        A__        =  [
            torch.randn(SCREAMING_SNAKE_CASE__       ,     generator=generator[i]       ,     device=SCREAMING_SNAKE_CASE__       ,     dtype=SCREAMING_SNAKE_CASE__       ,     layout=SCREAMING_SNAKE_CASE__ )
            for i in range(SCREAMING_SNAKE_CASE__ )
        ]
        A__        =  torch.cat(SCREAMING_SNAKE_CASE__       ,     dim=0 ).to(SCREAMING_SNAKE_CASE__ )
    else:
        A__        =  torch.randn(SCREAMING_SNAKE_CASE__       ,     generator=SCREAMING_SNAKE_CASE__       ,     device=SCREAMING_SNAKE_CASE__       ,     dtype=SCREAMING_SNAKE_CASE__       ,     layout=SCREAMING_SNAKE_CASE__ ).to(SCREAMING_SNAKE_CASE__ )

    return latents

def 		_snake_case(       SCREAMING_SNAKE_CASE__     :      Tuple )				-> Optional[Any]:





    '''simple docstring'''






    if is_torch_version('<'       ,     '2.0.0' ) or not hasattr(SCREAMING_SNAKE_CASE__       ,     '_dynamo' ):
        return False
    return isinstance(SCREAMING_SNAKE_CASE__       ,     torch._dynamo.eval_frame.OptimizedModule )




import enum
import inspect
import warnings
from functools import wraps
from typing import Callable, Optional

from .logging import get_logger


lowercase_									=    set()
lowercase_									=    get_logger(__name__)
def 		_snake_case(       SCREAMING_SNAKE_CASE__     :      Optional[str] = None )				-> Optional[int]:





    '''simple docstring'''






    def decorator(SCREAMING_SNAKE_CASE__     :      Callable ):
        global _emitted_deprecation_warnings

        if inspect.isclass(SCREAMING_SNAKE_CASE__ ):
            A__        =  deprecated_class_or_function.__init__
            A__        =  deprecated_class_or_function.__name__
        else:
            A__        =  deprecated_class_or_function
            A__        =  deprecated_function.__name__
            # Support deprecating __init__ class method: class name instead
            A__        =  name if name != '__init__' else deprecated_function.__qualname__.split('.' )[-2]

        A__        =  (
            f'{name} is deprecated and will be removed in the next major version of datasets.' + f' {help_message}'
            if help_message
            else ''
        )

        @wraps(SCREAMING_SNAKE_CASE__ )
        def wrapper(*SCREAMING_SNAKE_CASE__     :      Tuple       ,     **SCREAMING_SNAKE_CASE__     :      Any ):
            A__        =  hash(SCREAMING_SNAKE_CASE__ )
            if func_hash not in _emitted_deprecation_warnings:
                warnings.warn(SCREAMING_SNAKE_CASE__       ,     category=SCREAMING_SNAKE_CASE__       ,     stacklevel=2 )
                _emitted_deprecation_warnings.add(SCREAMING_SNAKE_CASE__ )
            return deprecated_function(*SCREAMING_SNAKE_CASE__       ,     **SCREAMING_SNAKE_CASE__ )

        A__        =  'deprecated'

        if inspect.isclass(SCREAMING_SNAKE_CASE__ ):
            A__        =  wrapper
            return deprecated_class_or_function
        else:
            return wrapper

    return decorator


class 					A		(				enum.EnumMeta					):







    """simple docstring"""





    def __getattribute__( cls					:			Optional[Any],lowercase_					:			int						)->       Optional[Any]:





        '''simple docstring'''







        A__        =  super().__getattribute__(lowercase_						)
        if isinstance(lowercase_,enum.Enum						) and obj._on_access:
            obj._on_access()
        return obj


    def __getitem__( cls					:			int,lowercase_					:			Any						)->       Tuple:





        '''simple docstring'''







        A__        =  super().__getitem__(lowercase_						)
        if member._on_access:
            member._on_access()
        return member


    def __call__( cls					:			Optional[int],lowercase_					:			Tuple,lowercase_					:			List[Any]=None,*, lowercase_					:			Any=None,lowercase_					:			Optional[Any]=None,lowercase_					:			Any=None,lowercase_					:			Optional[int]=1						)->       List[str]:





        '''simple docstring'''







        A__        =  super().__call__(lowercase_,lowercase_,module=lowercase_,qualname=lowercase_,type=lowercase_,start=lowercase_						)
        if isinstance(lowercase_,enum.Enum						) and obj._on_access:
            obj._on_access()
        return obj




class 					A		(				enum.Enum       ,				metaclass=_UpperCAmelCase					):







    """simple docstring"""





    def __new__( cls					:			Any,lowercase_					:			str						)->       Any:





        '''simple docstring'''







        A__        =  object.__new__(cls						)
        A__        =  value
        A__        =  member.deprecate
        return member


    @property
    def 		snake_case__	( self					:			List[Any]						)->       List[Any]:





        '''simple docstring'''







        return ""


    def 		snake_case__	( self					:			List[str]						)->       Dict:





        '''simple docstring'''







        A__        =  F' {self.help_message}' if self.help_message else ''
        warnings.warn(
            F'\'{self.__objclass__.__name__}\' is deprecated and will be removed in the next major version of datasets.'
            + help_message,lowercase_,stacklevel=3,)

