






"""simple docstring"""






import unittest

import torch

from diffusers import VQModel
from diffusers.utils import floats_tensor, torch_device
from diffusers.utils.testing_utils import enable_full_determinism

from .test_modeling_common import ModelTesterMixin, UNetTesterMixin


enable_full_determinism()





class       snake_case_       (    _lowerCamelCase    ,							_lowerCamelCase    ,							unittest.TestCase       ):



	"""simple docstring"""

	SCREAMING_SNAKE_CASE_:							List[Any]   			=					VQModel
	SCREAMING_SNAKE_CASE_:							Optional[Any]   			=					"""sample"""


	@property
	def       _UpperCAmelCase						(      self  ,					__a=(32, 32)						):


					"""simple docstring"""

					A__							 =       4
					A__							 =       3

					A__							 =       floats_tensor((batch_size, num_channels) + sizes						).to(__a						)

					return {"sample": image}


	@property
	def       _UpperCAmelCase						(      self						):


					"""simple docstring"""

					return (3, 32, 32)


	@property
	def       _UpperCAmelCase						(      self						):


					"""simple docstring"""

					return (3, 32, 32)


	def       _UpperCAmelCase						(      self						):


					"""simple docstring"""

					A__							 =       {
					    'block_out_channels': [32, 64],
					    'in_channels': 3,
					    'out_channels': 3,
					    'down_block_types': ['DownEncoderBlock2D', 'DownEncoderBlock2D'],
					    'up_block_types': ['UpDecoderBlock2D', 'UpDecoderBlock2D'],
					    'latent_channels': 3,
					}
					A__							 =       self.dummy_input
					return init_dict, inputs_dict


	def       _UpperCAmelCase						(      self						):


					"""simple docstring"""

					pass


	def       _UpperCAmelCase						(      self						):


					"""simple docstring"""

					pass


	def       _UpperCAmelCase						(      self						):


					"""simple docstring"""

					A__ ,			A__							 =       VQModel.from_pretrained('fusing/vqgan-dummy'  ,					output_loading_info=__a						)
					self.assertIsNotNone(__a						)
					self.assertEqual(len(loading_info['missing_keys']						)  ,					0						)

					model.to(__a						)
					A__							 =       model(**self.dummy_input						)

					assert image is not None, "Make sure output is not None"






	def       _UpperCAmelCase						(      self						):


					"""simple docstring"""

					A__							 =       VQModel.from_pretrained('fusing/vqgan-dummy'						)
					model.to(__a						).eval()

					torch.manual_seed(0						)
					if torch.cuda.is_available():
									torch.cuda.manual_seed_all(0						)

					A__							 =       torch.randn(1  ,					model.config.in_channels  ,					model.config.sample_size  ,					model.config.sample_size						)
					A__							 =       image.to(__a						)
					with torch.no_grad():
									A__							 =       model(__a						).sample

					A__							 =       output[0, -1, -3:, -3:].flatten().cpu()
					# fmt: off
					A__							 =       torch.tensor([-0.0153, -0.4044, -0.1880, -0.5161, -0.2418, -0.4072, -0.1612, -0.0633, -0.0143]						)
					# fmt: on
					self.assertTrue(torch.allclose(__a  ,					__a  ,					atol=1E-3						)						)










"""simple docstring"""






from ...processing_utils import ProcessorMixin





class       snake_case_       (    _lowerCamelCase       ):



	"""simple docstring"""

	SCREAMING_SNAKE_CASE_:							List[str]   			=					"""WhisperFeatureExtractor"""
	SCREAMING_SNAKE_CASE_:							Union[str, Any]   			=					"""WhisperTokenizer"""


	def __init__(      self  ,					__a  ,					__a						):


					"""simple docstring"""

					super().__init__(__a  ,					__a						)
					A__							 =       self.feature_extractor
					A__							 =       False


	def       _UpperCAmelCase						(      self  ,					__a=None  ,					__a=None  ,					__a=True						):


					"""simple docstring"""

					return self.tokenizer.get_decoder_prompt_ids(task=__a  ,					language=__a  ,					no_timestamps=__a						)


	def __call__(      self  ,					*__a  ,					**__a						):


					"""simple docstring"""

					if self._in_target_context_manager:
									return self.current_processor(*__a  ,					**__a						)

					A__							 =       kwargs.pop('audio'  ,					__a						)
					A__							 =       kwargs.pop('sampling_rate'  ,					__a						)
					A__							 =       kwargs.pop('text'  ,					__a						)
					if len(__a						) > 0:
									A__							 =       args[0]
									A__							 =       args[1:]

					if audio is None and text is None:
									raise ValueError('You need to specify either an `audio` or `text` input to process.'						)

					if audio is not None:
									A__							 =       self.feature_extractor(__a  ,					*__a  ,					sampling_rate=__a  ,					**__a						)
					if text is not None:
									A__							 =       self.tokenizer(__a  ,					**__a						)

					if text is None:
									return inputs

					elif audio is None:
									return encodings
					else:
									A__							 =       encodings['input_ids']
									return inputs


	def       _UpperCAmelCase						(      self  ,					*__a  ,					**__a						):


					"""simple docstring"""

					return self.tokenizer.batch_decode(*__a  ,					**__a						)


	def       _UpperCAmelCase						(      self  ,					*__a  ,					**__a						):


					"""simple docstring"""

					return self.tokenizer.decode(*__a  ,					**__a						)






	def       _UpperCAmelCase						(      self  ,					__a  ,					__a="np"						):


					"""simple docstring"""

					return self.tokenizer.get_prompt_ids(__a  ,					return_tensors=__a						)


