



from ...configuration_utils import PretrainedConfig
from ...utils import logging


__snake_case     :str			       =logging.get_logger(__name__)

__snake_case     :Tuple			       ={
    'facebook/s2t-wav2vec2-large-en-de': (
        'https://huggingface.co/facebook/s2t-wav2vec2-large-en-de/resolve/main/config.json'
    ),
    # See all Speech2Text models at https://huggingface.co/models?filter=speech2text2
}



class        lowerCAmelCase__					(  _lowerCamelCase       ):
				A_   :     Tuple								=     'speech_to_text_2'
				A_   :     Union[str, Any]								=     ['past_key_values']
				A_   :     Dict								=     {'num_attention_heads': 'decoder_attention_heads', 'hidden_size': 'd_model'}


				def __init__(							self      :  int						, __UpperCamelCase      :  Union[str, Any]=10_000						, __UpperCamelCase      :  List[Any]=6						, __UpperCamelCase      :  Any=2_048						, __UpperCamelCase      :  Optional[Any]=4						, __UpperCamelCase      :  Optional[Any]=0.0						, __UpperCamelCase      :  Any=True						, __UpperCamelCase      :  List[str]="relu"						, __UpperCamelCase      :  Optional[Any]=256						, __UpperCamelCase      :  Optional[Any]=0.1						, __UpperCamelCase      :  Dict=0.0						, __UpperCamelCase      :  int=0.0						, __UpperCamelCase      :  List[Any]=0.0_2						, __UpperCamelCase      :  List[Any]=2						, __UpperCamelCase      :  Optional[Any]=True						, __UpperCamelCase      :  Optional[Any]=1						, __UpperCamelCase      :  List[str]=0						, __UpperCamelCase      :  Tuple=2						, __UpperCamelCase      :  Dict=1_024						, **__UpperCamelCase      :  Any						, )		->     List[Any]:
											A      						=    vocab_size
											A      						=    d_model
											A      						=    decoder_ffn_dim
											A      						=    decoder_layers
											A      						=    decoder_attention_heads
											A      						=    dropout
											A      						=    attention_dropout
											A      						=    activation_dropout
											A      						=    activation_function
											A      						=    init_std
											A      						=    decoder_layerdrop
											A      						=    use_cache
											A      						=    decoder_layers
											A      						=    scale_embedding  # scale factor will be sqrt(d_model) if True
											A      						=    max_target_positions

											super().__init__(
											    pad_token_id=__UpperCamelCase						, bos_token_id=__UpperCamelCase						, eos_token_id=__UpperCamelCase						, decoder_start_token_id=__UpperCamelCase						, **__UpperCamelCase						, )

'''simple docstring'''
import unittest

import numpy as np

from transformers.testing_utils import is_flaky, require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
						import torch

if is_vision_available():
						from PIL import Image

						from transformers import DonutImageProcessor


class 			SCREAMING_SNAKE_CASE__      (     unittest.TestCase):







				def __init__(       self						,				A_						,				A_=7						,				A_=3						,				A_=18						,				A_=30						,				A_=400						,				A_=True						,				A_=None						,				A_=True						,				A_=False						,				A_=True						,				A_=True						,				A_=[0.5, 0.5, 0.5]						,				A_=[0.5, 0.5, 0.5]						,				)->		Dict:







											'''simple docstring'''






											UpperCamelCase   			=     parent
											UpperCamelCase   			=     batch_size
											UpperCamelCase   			=     num_channels
											UpperCamelCase   			=     image_size
											UpperCamelCase   			=     min_resolution
											UpperCamelCase   			=     max_resolution
											UpperCamelCase   			=     do_resize
											UpperCamelCase   			=     size if size is not None else {'height': 18, 'width': 20}
											UpperCamelCase   			=     do_thumbnail
											UpperCamelCase   			=     do_align_axis
											UpperCamelCase   			=     do_pad
											UpperCamelCase   			=     do_normalize
											UpperCamelCase   			=     image_mean
											UpperCamelCase   			=     image_std







				def 						UpperCAmelCase_    (       self     )->		List[Any]:







											'''simple docstring'''






											return {
											    "do_resize": self.do_resize,
											    "size": self.size,
											    "do_thumbnail": self.do_thumbnail,
											    "do_align_long_axis": self.do_align_axis,
											    "do_pad": self.do_pad,
											    "do_normalize": self.do_normalize,
											    "image_mean": self.image_mean,
											    "image_std": self.image_std,
											}


@require_torch
@require_vision
class 			SCREAMING_SNAKE_CASE__      (     snake_case_							,       unittest.TestCase):
				lowerCAmelCase_     			=							DonutImageProcessor if is_vision_available() else None







				def 						UpperCAmelCase_    (       self     )->		str:







											'''simple docstring'''






											UpperCamelCase   			=     DonutImageProcessingTester(self     )







				@property
				def 						UpperCAmelCase_    (       self     )->		str:







											'''simple docstring'''






											return self.image_processor_tester.prepare_image_processor_dict()







				def 						UpperCAmelCase_    (       self     )->		Optional[int]:







											'''simple docstring'''






											UpperCamelCase   			=     self.image_processing_class(**self.image_processor_dict     )
											self.assertTrue(hasattr(A_						,				'do_resize'     )     )
											self.assertTrue(hasattr(A_						,				'size'     )     )
											self.assertTrue(hasattr(A_						,				'do_thumbnail'     )     )
											self.assertTrue(hasattr(A_						,				'do_align_long_axis'     )     )
											self.assertTrue(hasattr(A_						,				'do_pad'     )     )
											self.assertTrue(hasattr(A_						,				'do_normalize'     )     )
											self.assertTrue(hasattr(A_						,				'image_mean'     )     )
											self.assertTrue(hasattr(A_						,				'image_std'     )     )







				def 						UpperCAmelCase_    (       self     )->		Optional[int]:







											'''simple docstring'''






											UpperCamelCase   			=     self.image_processing_class.from_dict(self.image_processor_dict     )
											self.assertEqual(image_processor.size						,				{'height': 18, 'width': 20}     )

											UpperCamelCase   			=     self.image_processing_class.from_dict(self.image_processor_dict						,				size=42     )
											self.assertEqual(image_processor.size						,				{'height': 42, 'width': 42}     )

											# Previous config had dimensions in (width, height) order
											UpperCamelCase   			=     self.image_processing_class.from_dict(self.image_processor_dict						,				size=(42, 84)     )
											self.assertEqual(image_processor.size						,				{'height': 84, 'width': 42}     )







				def 						UpperCAmelCase_    (       self     )->		Tuple:







											'''simple docstring'''






											pass







				@is_flaky()
				def 						UpperCAmelCase_    (       self     )->		Any:







											'''simple docstring'''






											UpperCamelCase   			=     self.image_processing_class(**self.image_processor_dict     )
											# create random PIL images
											UpperCamelCase   			=     prepare_image_inputs(self.image_processor_tester						,				equal_resolution=A_     )
											for image in image_inputs:
																		self.assertIsInstance(A_						,				Image.Image     )

											# Test not batched input
											UpperCamelCase   			=     image_processing(image_inputs[0]						,				return_tensors='pt'     ).pixel_values
											self.assertEqual(
											    encoded_images.shape						,				(
											        1,
											        self.image_processor_tester.num_channels,
											        self.image_processor_tester.size['height'],
											        self.image_processor_tester.size['width'],
											    )						,				)

											# Test batched
											UpperCamelCase   			=     image_processing(A_						,				return_tensors='pt'     ).pixel_values
											self.assertEqual(
											    encoded_images.shape						,				(
											        self.image_processor_tester.batch_size,
											        self.image_processor_tester.num_channels,
											        self.image_processor_tester.size['height'],
											        self.image_processor_tester.size['width'],
											    )						,				)







				@is_flaky()
				def 						UpperCAmelCase_    (       self     )->		Optional[int]:







											'''simple docstring'''






											UpperCamelCase   			=     self.image_processing_class(**self.image_processor_dict     )
											# create random numpy tensors
											UpperCamelCase   			=     prepare_image_inputs(self.image_processor_tester						,				equal_resolution=A_						,				numpify=A_     )
											for image in image_inputs:
																		self.assertIsInstance(A_						,				np.ndarray     )

											# Test not batched input
											UpperCamelCase   			=     image_processing(image_inputs[0]						,				return_tensors='pt'     ).pixel_values
											self.assertEqual(
											    encoded_images.shape						,				(
											        1,
											        self.image_processor_tester.num_channels,
											        self.image_processor_tester.size['height'],
											        self.image_processor_tester.size['width'],
											    )						,				)

											# Test batched
											UpperCamelCase   			=     image_processing(A_						,				return_tensors='pt'     ).pixel_values
											self.assertEqual(
											    encoded_images.shape						,				(
											        self.image_processor_tester.batch_size,
											        self.image_processor_tester.num_channels,
											        self.image_processor_tester.size['height'],
											        self.image_processor_tester.size['width'],
											    )						,				)







				@is_flaky()
				def 						UpperCAmelCase_    (       self     )->		Dict:







											'''simple docstring'''






											UpperCamelCase   			=     self.image_processing_class(**self.image_processor_dict     )
											# create random PyTorch tensors
											UpperCamelCase   			=     prepare_image_inputs(self.image_processor_tester						,				equal_resolution=A_						,				torchify=A_     )
											for image in image_inputs:
																		self.assertIsInstance(A_						,				torch.Tensor     )

											# Test not batched input
											UpperCamelCase   			=     image_processing(image_inputs[0]						,				return_tensors='pt'     ).pixel_values
											self.assertEqual(
											    encoded_images.shape						,				(
											        1,
											        self.image_processor_tester.num_channels,
											        self.image_processor_tester.size['height'],
											        self.image_processor_tester.size['width'],
											    )						,				)

											# Test batched
											UpperCamelCase   			=     image_processing(A_						,				return_tensors='pt'     ).pixel_values
											self.assertEqual(
											    encoded_images.shape						,				(
											        self.image_processor_tester.batch_size,
											        self.image_processor_tester.num_channels,
											        self.image_processor_tester.size['height'],
											        self.image_processor_tester.size['width'],
											    )						,				)




