



from ..utils import DummyObject, requires_backends


class 	a__       (       metaclass=_snake_case       ):


					"""simple docstring"""



					A__  :				Tuple					 =				['''torch''', '''transformers''', '''invisible_watermark''']

					def __init__(		self     :Any      ,  *lowercase__     :Any      ,  **lowercase__     :Union[str, Any]    ):
										requires_backends(self      ,  ['torch', 'transformers', 'invisible_watermark']    )

					@classmethod
					def 				__UpperCAmelCase		(		cls     :Any      ,  *lowercase__     :Union[str, Any]      ,  **lowercase__     :Any    ):
										requires_backends(cls      ,  ['torch', 'transformers', 'invisible_watermark']    )



					@classmethod
					def 				__UpperCAmelCase		(		cls     :int      ,  *lowercase__     :List[str]      ,  **lowercase__     :str    ):
										requires_backends(cls      ,  ['torch', 'transformers', 'invisible_watermark']    )




class 	a__       (       metaclass=_snake_case       ):


					"""simple docstring"""



					A__  :				int					 =				['''torch''', '''transformers''', '''invisible_watermark''']

					def __init__(		self     :List[str]      ,  *lowercase__     :Union[str, Any]      ,  **lowercase__     :Dict    ):
										requires_backends(self      ,  ['torch', 'transformers', 'invisible_watermark']    )

					@classmethod
					def 				__UpperCAmelCase		(		cls     :List[Any]      ,  *lowercase__     :int      ,  **lowercase__     :Optional[int]    ):
										requires_backends(cls      ,  ['torch', 'transformers', 'invisible_watermark']    )



					@classmethod
					def 				__UpperCAmelCase		(		cls     :int      ,  *lowercase__     :Tuple      ,  **lowercase__     :Dict    ):
										requires_backends(cls      ,  ['torch', 'transformers', 'invisible_watermark']    )











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

__magic_name__       =     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				):
							"""simple docstring"""






							return cls





def 		__snake_case						(    _UpperCAmelCase       ,			_UpperCAmelCase = None       ,			_UpperCAmelCase = None       ,			_UpperCAmelCase = None       ,			_UpperCAmelCase = None       ,			):
					"""simple docstring"""






					lowercase						   =       device
					lowercase						   =       shape[0]

					lowercase						   =       layout or torch.strided
					lowercase						   =       device or torch.device('cpu'				)

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

					return latents





def 		__snake_case						(    _UpperCAmelCase				):
					"""simple docstring"""






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






