


'''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, prepare_image_inputs


if is_torch_available():
				import torch

if is_vision_available():
				from PIL import Image

				from transformers import MobileNetVaImageProcessor





class        lowercase__    (		unittest.TestCase   ):





							'''simple docstring'''


							def __init__(       self       ,   __snake_case       ,   __snake_case=7       ,   __snake_case=3       ,   __snake_case=18       ,   __snake_case=30       ,   __snake_case=400       ,   __snake_case=True       ,   __snake_case=None       ,   __snake_case=True       ,   __snake_case=None       ,   ):
											_SCREAMING_SNAKE_CASE					:			List[str]							= size if size is not None else {"""shortest_edge""": 20}
											_SCREAMING_SNAKE_CASE					:			Optional[Any]							= crop_size if crop_size is not None else {"""height""": 18, """width""": 18}
											_SCREAMING_SNAKE_CASE					:			Any							= parent
											_SCREAMING_SNAKE_CASE					:			int							= batch_size
											_SCREAMING_SNAKE_CASE					:			Any							= num_channels
											_SCREAMING_SNAKE_CASE					:			str							= image_size
											_SCREAMING_SNAKE_CASE					:			Any							= min_resolution
											_SCREAMING_SNAKE_CASE					:			Any							= max_resolution
											_SCREAMING_SNAKE_CASE					:			Dict							= do_resize
											_SCREAMING_SNAKE_CASE					:			List[Any]							= size
											_SCREAMING_SNAKE_CASE					:			List[Any]							= do_center_crop
											_SCREAMING_SNAKE_CASE					:			Any							= crop_size






							def UpperCAmelCase_      (       self    ):
											return {
											    "do_resize": self.do_resize,
											    "size": self.size,
											    "do_center_crop": self.do_center_crop,
											    "crop_size": self.crop_size,
											}





@require_torch
@require_vision
class        lowercase__    (		_snake_case	,	unittest.TestCase   ):





							'''simple docstring'''


							A_				: str       =    MobileNetVaImageProcessor if is_vision_available() else None






							def UpperCAmelCase_      (       self    ):
											_SCREAMING_SNAKE_CASE					:			Union[str, Any]							= MobileNetVaImageProcessingTester(self    )






							@property
							def UpperCAmelCase_      (       self    ):
											return self.image_processor_tester.prepare_image_processor_dict()






							def UpperCAmelCase_      (       self    ):
											_SCREAMING_SNAKE_CASE					:			Tuple							= self.image_processing_class(**self.image_processor_dict    )
											self.assertTrue(hasattr(__snake_case       ,   """do_resize"""    )    )
											self.assertTrue(hasattr(__snake_case       ,   """size"""    )    )
											self.assertTrue(hasattr(__snake_case       ,   """do_center_crop"""    )    )
											self.assertTrue(hasattr(__snake_case       ,   """crop_size"""    )    )






							def UpperCAmelCase_      (       self    ):
											_SCREAMING_SNAKE_CASE					:			str							= self.image_processing_class.from_dict(self.image_processor_dict    )
											self.assertEqual(image_processor.size       ,   {"""shortest_edge""": 20}    )
											self.assertEqual(image_processor.crop_size       ,   {"""height""": 18, """width""": 18}    )

											_SCREAMING_SNAKE_CASE					:			Optional[Any]							= self.image_processing_class.from_dict(self.image_processor_dict       ,   size=42       ,   crop_size=84    )
											self.assertEqual(image_processor.size       ,   {"""shortest_edge""": 42}    )
											self.assertEqual(image_processor.crop_size       ,   {"""height""": 84, """width""": 84}    )






							def UpperCAmelCase_      (       self    ):
											pass






							def UpperCAmelCase_      (       self    ):
											# Initialize image_processing
											_SCREAMING_SNAKE_CASE					:			Optional[int]							= self.image_processing_class(**self.image_processor_dict    )
											# create random PIL images
											_SCREAMING_SNAKE_CASE					:			str							= prepare_image_inputs(self.image_processor_tester       ,   equal_resolution=__snake_case    )
											for image in image_inputs:
															self.assertIsInstance(__snake_case       ,   Image.Image    )

											# Test not batched input
											_SCREAMING_SNAKE_CASE					:			int							= 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.crop_size["""height"""],
											        self.image_processor_tester.crop_size["""width"""],
											    )       ,   )

											# Test batched
											_SCREAMING_SNAKE_CASE					:			Union[str, Any]							= image_processing(__snake_case       ,   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.crop_size["""height"""],
											        self.image_processor_tester.crop_size["""width"""],
											    )       ,   )






							def UpperCAmelCase_      (       self    ):
											# Initialize image_processing
											_SCREAMING_SNAKE_CASE					:			List[Any]							= self.image_processing_class(**self.image_processor_dict    )
											# create random numpy tensors
											_SCREAMING_SNAKE_CASE					:			Tuple							= prepare_image_inputs(self.image_processor_tester       ,   equal_resolution=__snake_case       ,   numpify=__snake_case    )
											for image in image_inputs:
															self.assertIsInstance(__snake_case       ,   np.ndarray    )

											# Test not batched input
											_SCREAMING_SNAKE_CASE					:			Union[str, Any]							= 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.crop_size["""height"""],
											        self.image_processor_tester.crop_size["""width"""],
											    )       ,   )

											# Test batched
											_SCREAMING_SNAKE_CASE					:			Union[str, Any]							= image_processing(__snake_case       ,   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.crop_size["""height"""],
											        self.image_processor_tester.crop_size["""width"""],
											    )       ,   )






							def UpperCAmelCase_      (       self    ):
											# Initialize image_processing
											_SCREAMING_SNAKE_CASE					:			str							= self.image_processing_class(**self.image_processor_dict    )
											# create random PyTorch tensors
											_SCREAMING_SNAKE_CASE					:			Any							= prepare_image_inputs(self.image_processor_tester       ,   equal_resolution=__snake_case       ,   torchify=__snake_case    )
											for image in image_inputs:
															self.assertIsInstance(__snake_case       ,   torch.Tensor    )

											# Test not batched input
											_SCREAMING_SNAKE_CASE					:			Optional[int]							= 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.crop_size["""height"""],
											        self.image_processor_tester.crop_size["""width"""],
											    )       ,   )

											# Test batched
											_SCREAMING_SNAKE_CASE					:			int							= image_processing(__snake_case       ,   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.crop_size["""height"""],
											        self.image_processor_tester.crop_size["""width"""],
											    )       ,   )








'''simple docstring'''


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


UpperCAmelCase_						:  List[Any]				  =						logging.get_logger(__name__)

UpperCAmelCase_						:  Any				  =						{
    'bigcode/gpt_bigcode-santacoder': 'https://huggingface.co/bigcode/gpt_bigcode-santacoder/resolve/main/config.json',
}





class        lowercase__    (		_snake_case   ):





							'''simple docstring'''


							A_				: Dict       =    """gpt_bigcode"""
							A_				: str       =    ["""past_key_values"""]
							A_				: Tuple       =    {
							    """hidden_size""": """n_embd""",
							    """max_position_embeddings""": """n_positions""",
							    """num_attention_heads""": """n_head""",
							    """num_hidden_layers""": """n_layer""",
							}






							def __init__(       self       ,   __snake_case=5_0257       ,   __snake_case=1024       ,   __snake_case=768       ,   __snake_case=12       ,   __snake_case=12       ,   __snake_case=None       ,   __snake_case="gelu_pytorch_tanh"       ,   __snake_case=0.1       ,   __snake_case=0.1       ,   __snake_case=0.1       ,   __snake_case=1e-5       ,   __snake_case=0.02       ,   __snake_case=True       ,   __snake_case=True       ,   __snake_case=5_0256       ,   __snake_case=5_0256       ,   __snake_case=True       ,   __snake_case=True       ,   __snake_case=True       ,   **__snake_case       ,   ):
											_SCREAMING_SNAKE_CASE					:			Optional[Any]							= vocab_size
											_SCREAMING_SNAKE_CASE					:			Optional[Any]							= n_positions
											_SCREAMING_SNAKE_CASE					:			List[Any]							= n_embd
											_SCREAMING_SNAKE_CASE					:			Union[str, Any]							= n_layer
											_SCREAMING_SNAKE_CASE					:			Union[str, Any]							= n_head
											_SCREAMING_SNAKE_CASE					:			Optional[int]							= n_inner
											_SCREAMING_SNAKE_CASE					:			Optional[Any]							= activation_function
											_SCREAMING_SNAKE_CASE					:			Union[str, Any]							= resid_pdrop
											_SCREAMING_SNAKE_CASE					:			Union[str, Any]							= embd_pdrop
											_SCREAMING_SNAKE_CASE					:			List[Any]							= attn_pdrop
											_SCREAMING_SNAKE_CASE					:			Optional[int]							= layer_norm_epsilon
											_SCREAMING_SNAKE_CASE					:			Any							= initializer_range
											_SCREAMING_SNAKE_CASE					:			str							= scale_attn_weights
											_SCREAMING_SNAKE_CASE					:			Tuple							= use_cache
											_SCREAMING_SNAKE_CASE					:			Optional[int]							= attention_softmax_in_fpaa
											_SCREAMING_SNAKE_CASE					:			List[Any]							= scale_attention_softmax_in_fpaa
											_SCREAMING_SNAKE_CASE					:			Any							= multi_query

											_SCREAMING_SNAKE_CASE					:			Optional[int]							= bos_token_id
											_SCREAMING_SNAKE_CASE					:			Optional[int]							= eos_token_id

											super().__init__(bos_token_id=__snake_case       ,   eos_token_id=__snake_case       ,   **__snake_case    )




