


class      lowerCamelCase	:

       class      lowerCamelCase	:
              _UpperCamelCase    		=      """_prev""", """_data""", """_next"""

              def __init__(			self	,						a__	,						a__	,						a__					):






               '''simple docstring'''






               snake_case   : Tuple	  =      link_p
               snake_case   : Union[str, Any]	  =      element
               snake_case   : Tuple	  =      link_n



              def 				UpperCAmelCase				(			self					):






               '''simple docstring'''






               return (
                   f''' Prev -> {self._prev is not None}, Next -> {self._next is not None}'''
               )







       def __init__(			self					):






        '''simple docstring'''






        snake_case   : Optional[Any]	  =      self._Node(a__	,						a__	,						a__					)
        snake_case   : Union[str, Any]	  =      self._Node(a__	,						a__	,						a__					)
        snake_case   : Union[str, Any]	  =      self._trailer
        snake_case   : Union[str, Any]	  =      self._header
        snake_case   : Optional[Any]	  =      0

       def __len__(			self					):






        '''simple docstring'''






        return self._size

       def 				UpperCAmelCase				(			self					):






        '''simple docstring'''






        return self.__len__() == 0

       def 				UpperCAmelCase				(			self	,						a__	,						a__	,						a__					):






        '''simple docstring'''






        snake_case   : str	  =      self._Node(a__	,						a__	,						a__					)
        snake_case   : int	  =      new_node
        snake_case   : Union[str, Any]	  =      new_node
        self._size += 1
        return self



       def 				UpperCAmelCase				(			self	,						a__					):






        '''simple docstring'''






        snake_case   : Dict	  =      node._prev
        snake_case   : Dict	  =      node._next

        snake_case   : Tuple	  =      successor
        snake_case   : List[Any]	  =      predecessor
        self._size -= 1
        snake_case   : int	  =      node._data
        snake_case   : Any	  =      None
        del node
        return temp







class      lowerCamelCase	(  _DoublyLinkedBase     ):

       def 				UpperCAmelCase				(			self					):






        '''simple docstring'''






        if self.is_empty():
         raise Exception('''List is empty'''					)
        return self._header._next._data

       def 				UpperCAmelCase				(			self					):






        '''simple docstring'''






        if self.is_empty():
         raise Exception('''List is empty'''					)
        return self._trailer._prev._data

       def 				UpperCAmelCase				(			self	,						a__					):






        '''simple docstring'''






        return self._insert(self._header	,						a__	,						self._header._next					)

       def 				UpperCAmelCase				(			self	,						a__					):






        '''simple docstring'''






        return self._insert(self._trailer._prev	,						a__	,						self._trailer					)

       def 				UpperCAmelCase				(			self					):






        '''simple docstring'''






        if self.is_empty():
         raise IndexError('''remove_first from empty list'''					)
        return self._delete(self._header._next					)



       def 				UpperCAmelCase				(			self					):






        '''simple docstring'''






        if self.is_empty():
         raise IndexError('''remove_first from empty list'''					)
        return self._delete(self._trailer._prev					)










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

a				:							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    _UpperCAmelCase	(   cls       )		->str:


   '''simple docstring'''
   return cls






def    _UpperCAmelCase	(   __lowerCamelCase ,     __lowerCamelCase = None ,     __lowerCamelCase = None ,     __lowerCamelCase = None ,     __lowerCamelCase = None ,     )		->Union[str, Any]:


 '''simple docstring'''
 snake_case   : Union[str, Any]	  =      device
 snake_case   : Any	  =      shape[0]

 snake_case   : Any	  =      layout or torch.strided
 snake_case   : Union[str, Any]	  =      device or torch.device('''cpu'''       )

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

 return latents






def    _UpperCAmelCase	(   __lowerCamelCase       )		->Tuple:


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






