'''simple docstring'''




import unittest

import numpy as np

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

from ...test_image_processing_common import ImageProcessingSavingTestMixin


if is_torch_available():
			import torch

if is_vision_available():
			from PIL import Image

			from transformers import BlipImageProcessor






class     a__( unittest.TestCase     ):


			'''simple docstring'''






			def __init__(       self	,   __lowerCAmelCase	,   __lowerCAmelCase=7	,   __lowerCAmelCase=3	,   __lowerCAmelCase=18	,   __lowerCAmelCase=30	,   __lowerCAmelCase=400	,   __lowerCAmelCase=True	,   __lowerCAmelCase=None	,   __lowerCAmelCase=True	,   __lowerCAmelCase=False	,   __lowerCAmelCase=[0.48145466, 0.4578275, 0.40821073]	,   __lowerCAmelCase=[0.26862954, 0.26130258, 0.27577711]	,   __lowerCAmelCase=True	,   ):




					"""simple docstring"""


					lowerCAmelCase        =  size if size is not None else {"height": 20, "width": 20}
					lowerCAmelCase        =  parent
					lowerCAmelCase        =  batch_size
					lowerCAmelCase        =  num_channels
					lowerCAmelCase        =  image_size
					lowerCAmelCase        =  min_resolution
					lowerCAmelCase        =  max_resolution
					lowerCAmelCase        =  do_resize
					lowerCAmelCase        =  size
					lowerCAmelCase        =  do_normalize
					lowerCAmelCase        =  image_mean
					lowerCAmelCase        =  image_std
					lowerCAmelCase        =  do_pad
					lowerCAmelCase        =  do_convert_rgb



			def 							a_	(       self):




					"""simple docstring"""


					return {
					    "do_resize": self.do_resize,
					    "size": self.size,
					    "do_normalize": self.do_normalize,
					    "image_mean": self.image_mean,
					    "image_std": self.image_std,
					    "do_convert_rgb": self.do_convert_rgb,
					    "do_pad": self.do_pad,
					}







			def 							a_	(       self	,   __lowerCAmelCase=False	,   __lowerCAmelCase=False	,   __lowerCAmelCase=False):




					"""simple docstring"""


					assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

					if equal_resolution:
							lowerCAmelCase        =  []
							for i in range(self.batch_size):
									image_inputs.append(
									    np.random.randint(
									        255	,   size=(self.num_channels, self.max_resolution, self.max_resolution)	,   dtype=np.uinta))
					else:
							lowerCAmelCase        =  []
							for i in range(self.batch_size):
									lowerCAmelCase        =  np.random.choice(np.arange(self.min_resolution	,   self.max_resolution)	,   2)
									image_inputs.append(np.random.randint(255	,   size=(self.num_channels, width, height)	,   dtype=np.uinta))

					if not numpify and not torchify:
							# PIL expects the channel dimension as last dimension
							lowerCAmelCase        =  [Image.fromarray(np.moveaxis(UpperCamelCase__	,   0	,   -1)) for x in image_inputs]

					if torchify:
							lowerCAmelCase        =  [torch.from_numpy(UpperCamelCase__) for x in image_inputs]

					return image_inputs







@require_torch
@require_vision
class     a__( lowerCAmelCase__			,						unittest.TestCase     ):


			'''simple docstring'''






			UpperCAmelCase_      :					Union[str, Any]								=	BlipImageProcessor if is_vision_available() else None



			def 							a_	(       self):




					"""simple docstring"""


					lowerCAmelCase        =  BlipImageProcessingTester(self)



			@property
			def 							a_	(       self):




					"""simple docstring"""


					return self.image_processor_tester.prepare_image_processor_dict()



			def 							a_	(       self):




					"""simple docstring"""


					lowerCAmelCase        =  self.image_processing_class(**self.image_processor_dict)
					self.assertTrue(hasattr(UpperCamelCase__	,   """do_resize"""))
					self.assertTrue(hasattr(UpperCamelCase__	,   """size"""))
					self.assertTrue(hasattr(UpperCamelCase__	,   """do_normalize"""))
					self.assertTrue(hasattr(UpperCamelCase__	,   """image_mean"""))
					self.assertTrue(hasattr(UpperCamelCase__	,   """image_std"""))
					self.assertTrue(hasattr(UpperCamelCase__	,   """do_convert_rgb"""))



			def 							a_	(       self):




					"""simple docstring"""


					pass



			def 							a_	(       self):




					"""simple docstring"""


					lowerCAmelCase        =  self.image_processing_class(**self.image_processor_dict)
					# create random PIL images
					lowerCAmelCase        =  self.image_processor_tester.prepare_inputs(equal_resolution=UpperCamelCase__)
					for image in image_inputs:
							self.assertIsInstance(UpperCamelCase__	,   Image.Image)

					# Test not batched input
					lowerCAmelCase        =  image_processor(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
					lowerCAmelCase        =  image_processor(UpperCamelCase__	,   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"""],
					    )	,   )



			def 							a_	(       self):




					"""simple docstring"""


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

					# Test not batched input
					lowerCAmelCase        =  image_processor(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
					lowerCAmelCase        =  image_processor(UpperCamelCase__	,   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"""],
					    )	,   )







			def 							a_	(       self):




					"""simple docstring"""


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

					# Test not batched input
					lowerCAmelCase        =  image_processor(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
					lowerCAmelCase        =  image_processor(UpperCamelCase__	,   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"""],
					    )	,   )







@require_torch
@require_vision
class     a__( lowerCAmelCase__			,						unittest.TestCase     ):


			'''simple docstring'''






			UpperCAmelCase_      :					List[Any]								=	BlipImageProcessor if is_vision_available() else None



			def 							a_	(       self):




					"""simple docstring"""


					lowerCAmelCase        =  BlipImageProcessingTester(self	,   num_channels=4)
					lowerCAmelCase        =  3



			@property
			def 							a_	(       self):




					"""simple docstring"""


					return self.image_processor_tester.prepare_image_processor_dict()



			def 							a_	(       self):




					"""simple docstring"""


					lowerCAmelCase        =  self.image_processing_class(**self.image_processor_dict)
					self.assertTrue(hasattr(UpperCamelCase__	,   """do_resize"""))
					self.assertTrue(hasattr(UpperCamelCase__	,   """size"""))
					self.assertTrue(hasattr(UpperCamelCase__	,   """do_normalize"""))
					self.assertTrue(hasattr(UpperCamelCase__	,   """image_mean"""))
					self.assertTrue(hasattr(UpperCamelCase__	,   """image_std"""))
					self.assertTrue(hasattr(UpperCamelCase__	,   """do_convert_rgb"""))



			def 							a_	(       self):




					"""simple docstring"""


					pass







			def 							a_	(       self):




					"""simple docstring"""


					lowerCAmelCase        =  self.image_processing_class(**self.image_processor_dict)
					# create random PIL images
					lowerCAmelCase        =  self.image_processor_tester.prepare_inputs(equal_resolution=UpperCamelCase__)
					for image in image_inputs:
							self.assertIsInstance(UpperCamelCase__	,   Image.Image)

					# Test not batched input
					lowerCAmelCase        =  image_processor(image_inputs[0]	,   return_tensors="""pt""").pixel_values
					self.assertEqual(
					    encoded_images.shape	,   (
					        1,
					        self.expected_encoded_image_num_channels,
					        self.image_processor_tester.size["""height"""],
					        self.image_processor_tester.size["""width"""],
					    )	,   )

					# Test batched
					lowerCAmelCase        =  image_processor(UpperCamelCase__	,   return_tensors="""pt""").pixel_values
					self.assertEqual(
					    encoded_images.shape	,   (
					        self.image_processor_tester.batch_size,
					        self.expected_encoded_image_num_channels,
					        self.image_processor_tester.size["""height"""],
					        self.image_processor_tester.size["""width"""],
					    )	,   )





'''simple docstring'''




from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


__lowercase				   =  logging.get_logger(__name__)

__lowercase				   =  {
    '''flaubert/flaubert_small_cased''': '''https://huggingface.co/flaubert/flaubert_small_cased/resolve/main/config.json''',
    '''flaubert/flaubert_base_uncased''': '''https://huggingface.co/flaubert/flaubert_base_uncased/resolve/main/config.json''',
    '''flaubert/flaubert_base_cased''': '''https://huggingface.co/flaubert/flaubert_base_cased/resolve/main/config.json''',
    '''flaubert/flaubert_large_cased''': '''https://huggingface.co/flaubert/flaubert_large_cased/resolve/main/config.json''',
}






class     a__( lowerCAmelCase__     ):


			'''simple docstring'''






			UpperCAmelCase_      :					int								=	'''flaubert'''
			UpperCAmelCase_      :					Optional[Any]								=	{
			    '''hidden_size''': '''emb_dim''',
			    '''num_attention_heads''': '''n_heads''',
			    '''num_hidden_layers''': '''n_layers''',
			    '''n_words''': '''vocab_size''',  # For backward compatibility
			}



			def __init__(       self	,   __lowerCAmelCase=False	,   __lowerCAmelCase=0.0	,   __lowerCAmelCase=30145	,   __lowerCAmelCase=2048	,   __lowerCAmelCase=12	,   __lowerCAmelCase=16	,   __lowerCAmelCase=0.1	,   __lowerCAmelCase=0.1	,   __lowerCAmelCase=True	,   __lowerCAmelCase=False	,   __lowerCAmelCase=False	,   __lowerCAmelCase=False	,   __lowerCAmelCase=1	,   __lowerCAmelCase=True	,   __lowerCAmelCase=512	,   __lowerCAmelCase=2048**-0.5	,   __lowerCAmelCase=1E-1_2	,   __lowerCAmelCase=0.02	,   __lowerCAmelCase=0	,   __lowerCAmelCase=1	,   __lowerCAmelCase=2	,   __lowerCAmelCase=3	,   __lowerCAmelCase=5	,   __lowerCAmelCase=True	,   __lowerCAmelCase="first"	,   __lowerCAmelCase=True	,   __lowerCAmelCase=None	,   __lowerCAmelCase=True	,   __lowerCAmelCase=0.1	,   __lowerCAmelCase=5	,   __lowerCAmelCase=5	,   __lowerCAmelCase=0	,   __lowerCAmelCase=0	,   __lowerCAmelCase=2	,   __lowerCAmelCase=0	,   **__lowerCAmelCase	,   ):




					"""simple docstring"""


					lowerCAmelCase        =  pre_norm
					lowerCAmelCase        =  layerdrop
					lowerCAmelCase        =  vocab_size
					lowerCAmelCase        =  emb_dim
					lowerCAmelCase        =  n_layers
					lowerCAmelCase        =  n_heads
					lowerCAmelCase        =  dropout
					lowerCAmelCase        =  attention_dropout
					lowerCAmelCase        =  gelu_activation
					lowerCAmelCase        =  sinusoidal_embeddings
					lowerCAmelCase        =  causal
					lowerCAmelCase        =  asm
					lowerCAmelCase        =  n_langs
					lowerCAmelCase        =  use_lang_emb
					lowerCAmelCase        =  layer_norm_eps
					lowerCAmelCase        =  bos_index
					lowerCAmelCase        =  eos_index
					lowerCAmelCase        =  pad_index
					lowerCAmelCase        =  unk_index
					lowerCAmelCase        =  mask_index
					lowerCAmelCase        =  is_encoder
					lowerCAmelCase        =  max_position_embeddings
					lowerCAmelCase        =  embed_init_std
					lowerCAmelCase        =  init_std
					lowerCAmelCase        =  summary_type
					lowerCAmelCase        =  summary_use_proj
					lowerCAmelCase        =  summary_activation
					lowerCAmelCase        =  summary_proj_to_labels
					lowerCAmelCase        =  summary_first_dropout
					lowerCAmelCase        =  start_n_top
					lowerCAmelCase        =  end_n_top
					lowerCAmelCase        =  mask_token_id
					lowerCAmelCase        =  lang_id

					if "n_words" in kwargs:
							lowerCAmelCase        =  kwargs["""n_words"""]

					super().__init__(pad_token_id=__lowerCAmelCase	,   bos_token_id=__lowerCAmelCase	,   **__lowerCAmelCase)







class     a__( lowerCAmelCase__     ):


			'''simple docstring'''






			@property
			def 							a_	(       self):




					"""simple docstring"""


					if self.task == "multiple-choice":
							lowerCAmelCase        =  {0: """batch""", 1: """choice""", 2: """sequence"""}
					else:
							lowerCAmelCase        =  {0: """batch""", 1: """sequence"""}
					return OrderedDict(
					    [
					        ("""input_ids""", dynamic_axis),
					        ("""attention_mask""", dynamic_axis),
					    ])




