

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

__UpperCAmelCase      = 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[Any]     )			->	Tuple:
      return cls





def 	snake_case_      (__A     :						Union[Tuple, List]					,   __A     :						Optional[Union[List["torch.Generator"], "torch.Generator"]] = None					,   __A     :						Optional["torch.device"] = None					,   __A     :						Optional["torch.dtype"] = None					,   __A     :						Optional["torch.layout"] = None					,   )			->	Union[str, Any]:
   __lowerCAmelCase  :			int					    =						device
   __lowerCAmelCase  :			List[str]					    =						shape[0]

   __lowerCAmelCase  :			Dict					    =						layout or torch.strided
   __lowerCAmelCase  :			int					    =						device or torch.device("""cpu"""     )

   if generator is not None:
      __lowerCAmelCase  :			str					    =						generator.device.type if not isinstance(__UpperCamelCase					,   __UpperCamelCase     ) else generator[0].device.type
      if gen_device_type != device.type and gen_device_type == "cpu":
         __lowerCAmelCase  :			Tuple					    =						"""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(__UpperCamelCase					,   __UpperCamelCase     ):
      __lowerCAmelCase  :			Union[str, Any]					    =						(1,) + shape[1:]
      __lowerCAmelCase  :			int					    =						[
          torch.randn(__UpperCamelCase					,   generator=generator[i]					,   device=__UpperCamelCase					,   dtype=__UpperCamelCase					,   layout=__UpperCamelCase     )
          for i in range(__UpperCamelCase     )
      ]
      __lowerCAmelCase  :			Any					    =						torch.cat(__UpperCamelCase					,   dim=0     ).to(__UpperCamelCase     )
   else:
      __lowerCAmelCase  :			List[str]					    =						torch.randn(__UpperCamelCase					,   generator=__UpperCamelCase					,   device=__UpperCamelCase					,   dtype=__UpperCamelCase					,   layout=__UpperCamelCase     ).to(__UpperCamelCase     )

   return latents





def 	snake_case_      (__A     :						Union[str, Any]     )			->	str:
   if is_torch_version("""<"""					,   """2.0.0"""     ) or not hasattr(__UpperCamelCase					,   """_dynamo"""     ):
      return False
   return isinstance(__UpperCamelCase					,   torch._dynamo.eval_frame.OptimizedModule     )








def 					SCREAMING_SNAKE_CASE	(       __UpperCamelCase			:						str      )  ->							int:
    UpperCAmelCase_							 =     5381
    for x in s:
        UpperCAmelCase_							 =     ((hash_value << 5) + hash_value) + ord(__UpperCamelCase      )
    return hash_value & 0xffff_ffff





