'''simple docstring'''


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

snake_case__	:     Union[str, Any]      =    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    _lowerCamelCase       ( cls   :				Dict  ):



      """simple docstring"""





      return cls


def    _lowerCamelCase       ( lowerCamelCase_   :				Union[Tuple, List]      ,	lowerCamelCase_   :				Optional[Union[List["torch.Generator"], "torch.Generator"]] = None      ,	lowerCamelCase_   :				Optional["torch.device"] = None      ,	lowerCamelCase_   :				Optional["torch.dtype"] = None      ,	lowerCamelCase_   :				Optional["torch.layout"] = None      ,	):



     """simple docstring"""





     UpperCAmelCase_				:  Optional[Any]  = device
     UpperCAmelCase_				:  Union[str, Any]  = shape[0]

     UpperCAmelCase_				:  str  = layout or torch.strided
     UpperCAmelCase_				:  Tuple  = device or torch.device('cpu'  )

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

     return latents





def    _lowerCamelCase       ( lowerCamelCase_   :				Any  ):



     """simple docstring"""





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







def      lowercase_							(     _lowerCamelCase				:			str):
    lowercase__					:  Union[str, Any]          =							0
    for plain_chr in plain_text:
        lowercase__					:  Union[str, Any]          =							(
            ord(_lowerCamelCase) + (hash_value << 6) + (hash_value << 16) - hash_value
        )
    return hash_value



