


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




											'''simple docstring'''
											return cls
def 							UpperCamelCase_  (				__snake_case			:						Union[Tuple, List]	,			__snake_case			:						Optional[Union[List["torch.Generator"], "torch.Generator"]] = None	,			__snake_case			:						Optional["torch.device"] = None	,			__snake_case			:						Optional["torch.dtype"] = None	,			__snake_case			:						Optional["torch.layout"] = None	,			)->      int:




						'''simple docstring'''
						__magic_name__ 		=			device
						__magic_name__ 		=			shape[0]

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

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

						return latents




def 							UpperCamelCase_  (				__snake_case			:						List[str]     )->      List[Any]:




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





import warnings

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding

class     __snake_case							(      _UpperCAmelCase):
					SCREAMING_SNAKE_CASE_		:					Union[str, Any] 				= ["image_processor", "tokenizer"]
					SCREAMING_SNAKE_CASE_		:					Tuple 				= "AutoImageProcessor"
					SCREAMING_SNAKE_CASE_		:					Dict 				= "AutoTokenizer"
					def __init__(	self					:	List[str]  ,			_lowerCAmelCase					:	str=None  ,			_lowerCAmelCase					:	Dict=None  ,			**_lowerCAmelCase					:	List[str]     )       ->				Optional[int]:



											'''simple docstring'''





											__magic_name__ 		=			None
											if "feature_extractor" in kwargs:
																	warnings.warn(
																	    'The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`'
																	    ' instead.'  ,			_lowerCAmelCase  ,			)
																	__magic_name__ 		=			kwargs.pop('feature_extractor'     )

											__magic_name__ 		=			image_processor if image_processor is not None else feature_extractor
											if image_processor is None:
																	raise ValueError('You have to specify an image_processor.'     )
											if tokenizer is None:
																	raise ValueError('You have to specify a tokenizer.'     )

											super().__init__(_lowerCAmelCase  ,			_lowerCAmelCase     )
											__magic_name__ 		=			self.image_processor
					def __call__(	self					:	str  ,			_lowerCAmelCase					:	Any=None  ,			_lowerCAmelCase					:	int=None  ,			_lowerCAmelCase					:	List[str]=None  ,			**_lowerCAmelCase					:	int     )       ->				int:



											'''simple docstring'''





											if text is None and images is None:
																	raise ValueError('You have to specify either text or images. Both cannot be none.'     )

											if text is not None:
																	__magic_name__ 		=			self.tokenizer(_lowerCAmelCase  ,			return_tensors=_lowerCAmelCase  ,			**_lowerCAmelCase     )

											if images is not None:
																	__magic_name__ 		=			self.image_processor(_lowerCAmelCase  ,			return_tensors=_lowerCAmelCase  ,			**_lowerCAmelCase     )

											if text is not None and images is not None:
																	__magic_name__ 		=			image_features.pixel_values
																	return encoding
											elif text is not None:
																	return encoding
											else:
																	return BatchEncoding(data=dict(**_lowerCAmelCase     )  ,			tensor_type=_lowerCAmelCase     )
					def   a (	self					:	Optional[int]  ,			*_lowerCAmelCase					:	Optional[int]  ,			**_lowerCAmelCase					:	Optional[Any]     )       ->				Optional[int]:



											'''simple docstring'''





											return self.tokenizer.batch_decode(*_lowerCAmelCase  ,			**_lowerCAmelCase     )
					def   a (	self					:	Union[str, Any]  ,			*_lowerCAmelCase					:	str  ,			**_lowerCAmelCase					:	Tuple     )       ->				int:



											'''simple docstring'''





											return self.tokenizer.decode(*_lowerCAmelCase  ,			**_lowerCAmelCase     )
					@property
					def   a (	self					:	List[Any]     )       ->				Tuple:



											'''simple docstring'''





											__magic_name__ 		=			self.tokenizer.model_input_names
											__magic_name__ 		=			self.image_processor.model_input_names
											return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names     )     )
					@property
					def   a (	self					:	Optional[Any]     )       ->				Dict:



											'''simple docstring'''





											warnings.warn(
											    '`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead.'  ,			_lowerCAmelCase  ,			)
											return self.image_processor_class







					@property
					def   a (	self					:	Dict     )       ->				Tuple:



											'''simple docstring'''





											warnings.warn(
											    '`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead.'  ,			_lowerCAmelCase  ,			)
											return self.image_processor

