
"""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

lowercase		:    Dict			=       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			)  ->      int:


								'''simple docstring'''
								return cls


def      lowerCamelCase_     (						lowerCamelCase_						,					lowerCamelCase_ = None						,					lowerCamelCase_ = None						,					lowerCamelCase_ = None						,					lowerCamelCase_ = None						,					)  ->      int:


					'''simple docstring'''
					__a:    Any		     =       device
					__a:    Dict		     =       shape[0]

					__a:    List[str]		     =       layout or torch.strided
					__a:    Any		     =       device or torch.device("""cpu"""			)

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

					return latents




def      lowerCamelCase_     (						lowerCamelCase_			)  ->      str:


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


"""simple docstring"""
import unittest
from dataclasses import dataclass
from typing import Optional

from transformers.utils import ModelOutput




@dataclass
class  _snake_case	(    _lowercase							):
							SCREAMING_SNAKE_CASE		  =    42
							SCREAMING_SNAKE_CASE		  =    None
							SCREAMING_SNAKE_CASE		  =    None






class  _snake_case	(    unittest.TestCase							):






							def 				__lowercase	(       self    :      Optional[Any]     ):






												"""simple docstring"""



												__a:    Dict		     =       ModelOutputTest(a=3_0     )
												self.assertEqual(x.a    ,			3_0     )
												self.assertIsNone(x.b     )
												self.assertIsNone(x.c     )
												with self.assertRaises(snake_case__     ):
																	__a:    int		     =       x.d






							def 				__lowercase	(       self    :      int     ):






												"""simple docstring"""



												__a:    Tuple		     =       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)     )

												__a:    Tuple		     =       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    :      Tuple     ):






												"""simple docstring"""



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

												__a:    str		     =       ModelOutputTest(a=3_0    ,			c=1_0     )
												self.assertEqual(x["""a"""]    ,			3_0     )
												self.assertEqual(x["""c"""]    ,			1_0     )
												with self.assertRaises(snake_case__     ):
																	__a:    List[str]		     =       x["""b"""]






							def 				__lowercase	(       self    :      List[str]     ):






												"""simple docstring"""



												__a:    str		     =       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(snake_case__     )    ,			["""a"""]     )

												__a:    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(snake_case__     )    ,			["""a""", """b"""]     )

												__a:    Union[str, Any]		     =       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(snake_case__     )    ,			["""a""", """c"""]     )

												with self.assertRaises(snake_case__     ):
																	__a:    List[Any]		     =       x.update({"""d""": 2_0}     )
												with self.assertRaises(snake_case__     ):
																	del x["a"]
												with self.assertRaises(snake_case__     ):
																	__a:    Union[str, Any]		     =       x.pop("""a"""     )
												with self.assertRaises(snake_case__     ):
																	__a:    List[Any]		     =       x.setdefault("""d"""    ,			3_2     )






							def 				__lowercase	(       self    :      Any     ):






												"""simple docstring"""



												__a:    List[str]		     =       ModelOutputTest(a=3_0     )
												__a:    str		     =       1_0
												self.assertEqual(x.a    ,			1_0     )
												self.assertEqual(x["""a"""]    ,			1_0     )






							def 				__lowercase	(       self    :      Dict     ):






												"""simple docstring"""



												__a:    List[str]		     =       ModelOutputTest(a=3_0     )
												__a:    Any		     =       1_0
												self.assertEqual(x.a    ,			1_0     )
												self.assertEqual(x["""a"""]    ,			1_0     )






							def 				__lowercase	(       self    :      int     ):






												"""simple docstring"""



												__a:    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[str]     ):






												"""simple docstring"""



												__a:    Union[str, 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(snake_case__     ):
																	__a:    str		     =       ModelOutputTest([("""a""", 3_0), (1_0, 1_0)]     )

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