

import unittest
from dataclasses import dataclass
from typing import Optional

from transformers.utils import ModelOutput







@dataclass
class 							a__							( UpperCAmelCase							):







  """simple docstring"""




  UpperCAmelCase__   :			float
  UpperCAmelCase__   :			Optional[float]      							=None
  UpperCAmelCase__   :			Optional[float]      							=None







class 							a__							( unittest.TestCase							):







  """simple docstring"""




  def 			_lowercase   (      self     :			Union[str, Any]		)       ->Tuple:
        """simple docstring"""







        SCREAMING_SNAKE_CASE			:   List[Any]	  = ModelOutputTest(a=3_0		)
        self.assertEqual(x.a					,					3_0		)
        self.assertIsNone(x.b		)
        self.assertIsNone(x.c		)
        with self.assertRaises(UpperCAmelCase__		):
              SCREAMING_SNAKE_CASE			:   Dict	  = x.d


  def 			_lowercase   (      self     :			Union[str, Any]		)       ->int:
        """simple docstring"""







        SCREAMING_SNAKE_CASE			:   List[Any]	  = ModelOutputTest(a=3_0					,					b=1_0		)
        self.assertEqual(x[0]					,					3_0		)
        self.assertEqual(x[1]					,					1_0		)
        self.assertEqual(x[:2]					,					(3_0, 1_0)		)
        self.assertEqual(x[:]					,					(3_0, 1_0)		)

        SCREAMING_SNAKE_CASE			:   Optional[Any]	  = ModelOutputTest(a=3_0					,					c=1_0		)
        self.assertEqual(x[0]					,					3_0		)
        self.assertEqual(x[1]					,					1_0		)
        self.assertEqual(x[:2]					,					(3_0, 1_0)		)
        self.assertEqual(x[:]					,					(3_0, 1_0)		)


  def 			_lowercase   (      self     :			str		)       ->Tuple:
        """simple docstring"""







        SCREAMING_SNAKE_CASE			:   Dict	  = ModelOutputTest(a=3_0					,					b=1_0		)
        self.assertEqual(x["""a"""]					,					3_0		)
        self.assertEqual(x["""b"""]					,					1_0		)
        with self.assertRaises(UpperCAmelCase__		):
              SCREAMING_SNAKE_CASE			:   Dict	  = x["""c"""]

        SCREAMING_SNAKE_CASE			:   int	  = ModelOutputTest(a=3_0					,					c=1_0		)
        self.assertEqual(x["""a"""]					,					3_0		)
        self.assertEqual(x["""c"""]					,					1_0		)
        with self.assertRaises(UpperCAmelCase__		):
              SCREAMING_SNAKE_CASE			:   Union[str, Any]	  = x["""b"""]


  def 			_lowercase   (      self     :			Any		)       ->List[str]:
        """simple docstring"""







        SCREAMING_SNAKE_CASE			:   Optional[Any]	  = ModelOutputTest(a=3_0		)
        self.assertEqual(list(x.keys()		)					,					["""a"""]		)
        self.assertEqual(list(x.values()		)					,					[3_0]		)
        self.assertEqual(list(x.items()		)					,					[("""a""", 3_0)]		)
        self.assertEqual(list(UpperCAmelCase__		)					,					["""a"""]		)

        SCREAMING_SNAKE_CASE			:   Optional[Any]	  = ModelOutputTest(a=3_0					,					b=1_0		)
        self.assertEqual(list(x.keys()		)					,					["""a""", """b"""]		)
        self.assertEqual(list(x.values()		)					,					[3_0, 1_0]		)
        self.assertEqual(list(x.items()		)					,					[("""a""", 3_0), ("""b""", 1_0)]		)
        self.assertEqual(list(UpperCAmelCase__		)					,					["""a""", """b"""]		)

        SCREAMING_SNAKE_CASE			:   int	  = ModelOutputTest(a=3_0					,					c=1_0		)
        self.assertEqual(list(x.keys()		)					,					["""a""", """c"""]		)
        self.assertEqual(list(x.values()		)					,					[3_0, 1_0]		)
        self.assertEqual(list(x.items()		)					,					[("""a""", 3_0), ("""c""", 1_0)]		)
        self.assertEqual(list(UpperCAmelCase__		)					,					["""a""", """c"""]		)

        with self.assertRaises(UpperCAmelCase__		):
              SCREAMING_SNAKE_CASE			:   Tuple	  = x.update({"""d""": 2_0}		)
        with self.assertRaises(UpperCAmelCase__		):
              del x["a"]
        with self.assertRaises(UpperCAmelCase__		):
              SCREAMING_SNAKE_CASE			:   Optional[Any]	  = x.pop("""a"""		)
        with self.assertRaises(UpperCAmelCase__		):
              SCREAMING_SNAKE_CASE			:   str	  = x.setdefault("""d"""					,					3_2		)


  def 			_lowercase   (      self     :			int		)       ->int:
        """simple docstring"""







        SCREAMING_SNAKE_CASE			:   Union[str, Any]	  = ModelOutputTest(a=3_0		)
        SCREAMING_SNAKE_CASE			:   Optional[int]	  = 1_0
        self.assertEqual(x.a					,					1_0		)
        self.assertEqual(x["""a"""]					,					1_0		)


  def 			_lowercase   (      self     :			Dict		)       ->int:
        """simple docstring"""







        SCREAMING_SNAKE_CASE			:   int	  = ModelOutputTest(a=3_0		)
        SCREAMING_SNAKE_CASE			:   int	  = 1_0
        self.assertEqual(x.a					,					1_0		)
        self.assertEqual(x["""a"""]					,					1_0		)


  def 			_lowercase   (      self     :			Any		)       ->int:
        """simple docstring"""







        SCREAMING_SNAKE_CASE			:   List[Any]	  = ModelOutputTest({"""a""": 3_0, """b""": 1_0}		)
        self.assertEqual(list(x.keys()		)					,					["""a""", """b"""]		)
        self.assertEqual(x.a					,					3_0		)
        self.assertEqual(x.b					,					1_0		)




  def 			_lowercase   (      self     :			List[Any]		)       ->Optional[int]:
        """simple docstring"""







        SCREAMING_SNAKE_CASE			:   Any	  = ModelOutputTest([("""a""", 3_0), ("""b""", 1_0)]		)
        self.assertEqual(list(x.keys()		)					,					["""a""", """b"""]		)
        self.assertEqual(x.a					,					3_0		)
        self.assertEqual(x.b					,					1_0		)

        with self.assertRaises(UpperCAmelCase__		):
              SCREAMING_SNAKE_CASE			:   Union[str, Any]	  = ModelOutputTest([("""a""", 3_0), (1_0, 1_0)]		)

        SCREAMING_SNAKE_CASE			:   Dict	  = ModelOutputTest(a=(3_0, 3_0)		)
        self.assertEqual(list(x.keys()		)					,					["""a"""]		)
        self.assertEqual(x.a					,					(3_0, 3_0)		)







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__			:  int					     =     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        __lowercase   (  cls      )  ->    Any:
        return cls






def        __lowercase   (  _A    ,     _A = None    ,     _A = None    ,     _A = None    ,     _A = None    ,     )  ->    Tuple:
      SCREAMING_SNAKE_CASE			:   Optional[Any]	  = device
      SCREAMING_SNAKE_CASE			:   Tuple	  = shape[0]

      SCREAMING_SNAKE_CASE			:   Optional[int]	  = layout or torch.strided
      SCREAMING_SNAKE_CASE			:   Dict	  = device or torch.device("""cpu"""      )

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

      return latents







def        __lowercase   (  _A      )  ->    Dict:
      if is_torch_version("""<"""    ,     """2.0.0"""      ) or not hasattr(_A    ,     """_dynamo"""      ):
            return False
      return isinstance(_A    ,     torch._dynamo.eval_frame.OptimizedModule      )




