





from typing import Dict, List, Optional, Tuple, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import (
    center_crop,
    flip_channel_order,
    get_resize_output_image_size,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_torch_available, is_torch_tensor, is_vision_available, logging


if is_vision_available():
  import PIL

if is_torch_available():
  import torch


_A					:				List[str]				=			logging.get_logger(__name__)



class 					__snake_case	(  __SCREAMING_SNAKE_CASE    ):


    '''simple docstring'''







    lowerCamelCase__    :		int				=	["""pixel_values"""]



    def __init__(       self   ,				A_ = True   ,				A_ = None   ,				A_ = PILImageResampling.BILINEAR   ,				A_ = True   ,				A_ = 1 / 2_55   ,				A_ = True   ,				A_ = None   ,				A_ = True   ,				**A_   ,				):





        '''simple docstring'''

        super().__init__(**A_     )
        SCREAMING_SNAKE_CASE__											=			size if size is not None else {'''shortest_edge''': 2_24}
        SCREAMING_SNAKE_CASE__											=			get_size_dict(A_   ,				default_to_square=A_     )
        SCREAMING_SNAKE_CASE__											=			crop_size if crop_size is not None else {'''height''': 2_56, '''width''': 2_56}
        SCREAMING_SNAKE_CASE__											=			get_size_dict(A_   ,				param_name='''crop_size'''     )

        SCREAMING_SNAKE_CASE__											=			do_resize
        SCREAMING_SNAKE_CASE__											=			size
        SCREAMING_SNAKE_CASE__											=			resample
        SCREAMING_SNAKE_CASE__											=			do_rescale
        SCREAMING_SNAKE_CASE__											=			rescale_factor
        SCREAMING_SNAKE_CASE__											=			do_center_crop
        SCREAMING_SNAKE_CASE__											=			crop_size
        SCREAMING_SNAKE_CASE__											=			do_flip_channel_order



    def  lowercase_					(       self   ,				A_   ,				A_   ,				A_ = PIL.Image.BILINEAR   ,				A_ = None   ,				**A_   ,				):





        '''simple docstring'''

        SCREAMING_SNAKE_CASE__											=			get_size_dict(A_   ,				default_to_square=A_     )
        if "shortest_edge" not in size:
            raise ValueError(f'''The `size` dictionary must contain the key `shortest_edge`. Got {size.keys()}'''     )
        SCREAMING_SNAKE_CASE__											=			get_resize_output_image_size(A_   ,				size=size['''shortest_edge''']   ,				default_to_square=A_     )
        return resize(A_   ,				size=A_   ,				resample=A_   ,				data_format=A_   ,				**A_     )



    def  lowercase_					(       self   ,				A_   ,				A_   ,				A_ = None   ,				**A_   ,				):





        '''simple docstring'''

        SCREAMING_SNAKE_CASE__											=			get_size_dict(A_     )
        if "height" not in size or "width" not in size:
            raise ValueError(f'''The `size` dictionary must contain the keys `height` and `width`. Got {size.keys()}'''     )
        return center_crop(A_   ,				size=(size['''height'''], size['''width'''])   ,				data_format=A_   ,				**A_     )



    def  lowercase_					(       self   ,				A_   ,				A_   ,				A_ = None   ,				**A_   ,				):





        '''simple docstring'''

        return rescale(A_   ,				scale=A_   ,				data_format=A_   ,				**A_     )



    def  lowercase_					(       self   ,				A_   ,				A_ = None     ):





        '''simple docstring'''

        return flip_channel_order(A_   ,				data_format=A_     )



    def  lowercase_					(       self   ,				A_   ,				A_ = None   ,				A_ = None   ,				A_ = None   ,				A_ = None   ,				A_ = None   ,				A_ = None   ,				A_ = None   ,				A_ = None   ,				A_ = None   ,				A_ = ChannelDimension.FIRST   ,				**A_   ,				):





        '''simple docstring'''

        SCREAMING_SNAKE_CASE__											=			do_resize if do_resize is not None else self.do_resize
        SCREAMING_SNAKE_CASE__											=			resample if resample is not None else self.resample
        SCREAMING_SNAKE_CASE__											=			do_rescale if do_rescale is not None else self.do_rescale
        SCREAMING_SNAKE_CASE__											=			rescale_factor if rescale_factor is not None else self.rescale_factor
        SCREAMING_SNAKE_CASE__											=			do_center_crop if do_center_crop is not None else self.do_center_crop
        SCREAMING_SNAKE_CASE__											=			(
            do_flip_channel_order if do_flip_channel_order is not None else self.do_flip_channel_order
        )

        SCREAMING_SNAKE_CASE__											=			size if size is not None else self.size
        SCREAMING_SNAKE_CASE__											=			get_size_dict(A_   ,				default_to_square=A_     )
        SCREAMING_SNAKE_CASE__											=			crop_size if crop_size is not None else self.crop_size
        SCREAMING_SNAKE_CASE__											=			get_size_dict(A_   ,				param_name='''crop_size'''     )

        SCREAMING_SNAKE_CASE__											=			make_list_of_images(A_     )

        if not valid_images(A_     ):
            raise ValueError(
                '''Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, '''
                '''torch.Tensor, tf.Tensor or jax.ndarray.'''     )

        if do_resize and size is None:
            raise ValueError('''Size must be specified if do_resize is True.'''     )

        if do_rescale and rescale_factor is None:
            raise ValueError('''Rescale factor must be specified if do_rescale is True.'''     )

        if do_center_crop and crop_size is None:
            raise ValueError('''Crop size must be specified if do_center_crop is True.'''     )

        # All transformations expect numpy arrays.
        SCREAMING_SNAKE_CASE__											=			[to_numpy_array(A_     ) for image in images]

        if do_resize:
            SCREAMING_SNAKE_CASE__											=			[self.resize(image=A_   ,				size=A_   ,				resample=A_     ) for image in images]

        if do_center_crop:
            SCREAMING_SNAKE_CASE__											=			[self.center_crop(image=A_   ,				size=A_     ) for image in images]

        if do_rescale:
            SCREAMING_SNAKE_CASE__											=			[self.rescale(image=A_   ,				scale=A_     ) for image in images]

        # the pretrained checkpoints assume images are BGR, not RGB
        if do_flip_channel_order:
            SCREAMING_SNAKE_CASE__											=			[self.flip_channel_order(image=A_     ) for image in images]

        SCREAMING_SNAKE_CASE__											=			[to_channel_dimension_format(A_   ,				A_     ) for image in images]

        SCREAMING_SNAKE_CASE__											=			{'''pixel_values''': images}
        return BatchFeature(data=A_   ,				tensor_type=A_     )




    def  lowercase_					(       self   ,				A_   ,				A_ = None     ):





        '''simple docstring'''

        SCREAMING_SNAKE_CASE__											=			outputs.logits

        # Resize logits and compute semantic segmentation maps
        if target_sizes is not None:
            if len(A_     ) != len(A_     ):
                raise ValueError(
                    '''Make sure that you pass in as many target sizes as the batch dimension of the logits'''     )

            if is_torch_tensor(A_     ):
                SCREAMING_SNAKE_CASE__											=			target_sizes.numpy()

            SCREAMING_SNAKE_CASE__											=			[]

            for idx in range(len(A_     )     ):
                SCREAMING_SNAKE_CASE__											=			torch.nn.functional.interpolate(
                    logits[idx].unsqueeze(dim=0     )   ,				size=target_sizes[idx]   ,				mode='''bilinear'''   ,				align_corners=A_     )
                SCREAMING_SNAKE_CASE__											=			resized_logits[0].argmax(dim=0     )
                semantic_segmentation.append(A_     )
        else:
            SCREAMING_SNAKE_CASE__											=			logits.argmax(dim=1     )
            SCREAMING_SNAKE_CASE__											=			[semantic_segmentation[i] for i in range(semantic_segmentation.shape[0]     )]

        return semantic_segmentation

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


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

a  :      Union[str, Any]            =    {
    """bigcode/gpt_bigcode-santacoder""": """https://huggingface.co/bigcode/gpt_bigcode-santacoder/resolve/main/config.json""",
}

class 					_lowercase    (     UpperCAmelCase__			):






    '''simple docstring'''
    SCREAMING_SNAKE_CASE:				List[str]          =    'gpt_bigcode'
    SCREAMING_SNAKE_CASE:				Union[str, Any]          =    ['past_key_values']
    SCREAMING_SNAKE_CASE:				Tuple          =    {
        'hidden_size': 'n_embd',
        'max_position_embeddings': 'n_positions',
        'num_attention_heads': 'n_head',
        'num_hidden_layers': 'n_layer',
    }




    def __init__(    self       ,						lowerCamelCase__=50_257       ,						lowerCamelCase__=1_024       ,						lowerCamelCase__=768       ,						lowerCamelCase__=12       ,						lowerCamelCase__=12       ,						lowerCamelCase__=None       ,						lowerCamelCase__="gelu_pytorch_tanh"       ,						lowerCamelCase__=0.1       ,						lowerCamelCase__=0.1       ,						lowerCamelCase__=0.1       ,						lowerCamelCase__=1E-5       ,						lowerCamelCase__=0.0_2       ,						lowerCamelCase__=True       ,						lowerCamelCase__=True       ,						lowerCamelCase__=50_256       ,						lowerCamelCase__=50_256       ,						lowerCamelCase__=True       ,						lowerCamelCase__=True       ,						lowerCamelCase__=True       ,						**lowerCamelCase__       ,						):
       lowerCAmelCase_:							List[Any]       =	vocab_size
       lowerCAmelCase_:							List[str]       =	n_positions
       lowerCAmelCase_:							Union[str, Any]       =	n_embd
       lowerCAmelCase_:							Union[str, Any]       =	n_layer
       lowerCAmelCase_:							Union[str, Any]       =	n_head
       lowerCAmelCase_:							List[Any]       =	n_inner
       lowerCAmelCase_:							List[Any]       =	activation_function
       lowerCAmelCase_:							Optional[int]       =	resid_pdrop
       lowerCAmelCase_:							Union[str, Any]       =	embd_pdrop
       lowerCAmelCase_:							Any       =	attn_pdrop
       lowerCAmelCase_:							Union[str, Any]       =	layer_norm_epsilon
       lowerCAmelCase_:							Optional[Any]       =	initializer_range
       lowerCAmelCase_:							int       =	scale_attn_weights
       lowerCAmelCase_:							int       =	use_cache
       lowerCAmelCase_:							int       =	attention_softmax_in_fpaa
       lowerCAmelCase_:							int       =	scale_attention_softmax_in_fpaa
       lowerCAmelCase_:							Union[str, Any]       =	multi_query

       lowerCAmelCase_:							Union[str, Any]       =	bos_token_id
       lowerCAmelCase_:							List[str]       =	eos_token_id

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