




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


_lowerCamelCase			:	Optional[Any]			 =     logging.get_logger(__name__)


class        UpperCamelCase_					(				__UpperCAmelCase  ):

    '''simple docstring'''






    UpperCAmelCase__													=   ['''pixel_values''']


    def __init__(    self   :			Any      ,				UpperCAmelCase__   :			bool = True      ,				UpperCAmelCase__   :			Dict[str, int] = None      ,				UpperCAmelCase__   :			PILImageResampling = PILImageResampling.BILINEAR      ,				UpperCAmelCase__   :			bool = True      ,				UpperCAmelCase__   :			Union[int, float] = 1 / 255      ,				UpperCAmelCase__   :			bool = True      ,				UpperCAmelCase__   :			Dict[str, int] = None      ,				UpperCAmelCase__   :			bool = True      ,				**UpperCAmelCase__   :			List[Any]      ,				)		->int:





           '''simple docstring'''

           super().__init__(**__SCREAMING_SNAKE_CASE)
           A__   				=					size if size is not None else {'''shortest_edge''': 224}
           A__   				=					get_size_dict(__SCREAMING_SNAKE_CASE      ,				default_to_square=__SCREAMING_SNAKE_CASE)
           A__   				=					crop_size if crop_size is not None else {'''height''': 256, '''width''': 256}
           A__   				=					get_size_dict(__SCREAMING_SNAKE_CASE      ,				param_name='''crop_size''')

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


    def  SCREAMING_SNAKE_CASE							(    self   :			str      ,				UpperCAmelCase__   :			np.ndarray      ,				UpperCAmelCase__   :			Dict[str, int]      ,				UpperCAmelCase__   :			PILImageResampling = PIL.Image.BILINEAR      ,				UpperCAmelCase__   :			Optional[Union[str, ChannelDimension]] = None      ,				**UpperCAmelCase__   :			Tuple      ,				)		->Optional[Any]:





           '''simple docstring'''

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


    def  SCREAMING_SNAKE_CASE							(    self   :			Dict      ,				UpperCAmelCase__   :			np.ndarray      ,				UpperCAmelCase__   :			Dict[str, int]      ,				UpperCAmelCase__   :			Optional[Union[str, ChannelDimension]] = None      ,				**UpperCAmelCase__   :			Any      ,				)		->List[Any]:





           '''simple docstring'''

           A__   				=					get_size_dict(__SCREAMING_SNAKE_CASE)
           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(__SCREAMING_SNAKE_CASE      ,				size=(size['''height'''], size['''width'''])      ,				data_format=__SCREAMING_SNAKE_CASE      ,				**__SCREAMING_SNAKE_CASE)


    def  SCREAMING_SNAKE_CASE							(    self   :			List[str]      ,				UpperCAmelCase__   :			np.ndarray      ,				UpperCAmelCase__   :			Union[int, float]      ,				UpperCAmelCase__   :			Optional[Union[str, ChannelDimension]] = None      ,				**UpperCAmelCase__   :			List[Any]      ,				)		->Optional[int]:





           '''simple docstring'''

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


    def  SCREAMING_SNAKE_CASE							(    self   :			List[str]      ,				UpperCAmelCase__   :			np.ndarray      ,				UpperCAmelCase__   :			Optional[Union[str, ChannelDimension]] = None)		->Any:





           '''simple docstring'''

           return flip_channel_order(__SCREAMING_SNAKE_CASE      ,				data_format=__SCREAMING_SNAKE_CASE)


    def  SCREAMING_SNAKE_CASE							(    self   :			int      ,				UpperCAmelCase__   :			ImageInput      ,				UpperCAmelCase__   :			bool = None      ,				UpperCAmelCase__   :			Dict[str, int] = None      ,				UpperCAmelCase__   :			PILImageResampling = None      ,				UpperCAmelCase__   :			bool = None      ,				UpperCAmelCase__   :			float = None      ,				UpperCAmelCase__   :			bool = None      ,				UpperCAmelCase__   :			Dict[str, int] = None      ,				UpperCAmelCase__   :			bool = None      ,				UpperCAmelCase__   :			Optional[Union[str, TensorType]] = None      ,				UpperCAmelCase__   :			ChannelDimension = ChannelDimension.FIRST      ,				**UpperCAmelCase__   :			Dict      ,				)		->List[str]:





           '''simple docstring'''

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

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

           A__   				=					make_list_of_images(__SCREAMING_SNAKE_CASE)

           if not valid_images(__SCREAMING_SNAKE_CASE):
                  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.
           A__   				=					[to_numpy_array(__SCREAMING_SNAKE_CASE) for image in images]

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

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

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

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

           A__   				=					[to_channel_dimension_format(__SCREAMING_SNAKE_CASE      ,				__SCREAMING_SNAKE_CASE) for image in images]

           A__   				=					{'''pixel_values''': images}
           return BatchFeature(data=__SCREAMING_SNAKE_CASE      ,				tensor_type=__SCREAMING_SNAKE_CASE)





    def  SCREAMING_SNAKE_CASE							(    self   :			Optional[Any]      ,				UpperCAmelCase__   :			Dict      ,				UpperCAmelCase__   :			List[Tuple] = None)		->str:





           '''simple docstring'''

           A__   				=					outputs.logits

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

                  if is_torch_tensor(__SCREAMING_SNAKE_CASE):
                         A__   				=					target_sizes.numpy()

                  A__   				=					[]

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

           return semantic_segmentation








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


_lowerCamelCase			:	Tuple							 =     logging.get_logger(__name__)

_lowerCamelCase			:	Tuple							 =     {
    """tiiuae/falcon-40b""": """https://huggingface.co/tiiuae/falcon-40b/resolve/main/config.json""",
    """tiiuae/falcon-7b""": """https://huggingface.co/tiiuae/falcon-7b/resolve/main/config.json""",
}


class        UpperCamelCase_					(				UpperCAmelCase__  ):

    '''simple docstring'''






    UpperCAmelCase__													=   '''falcon'''
    UpperCAmelCase__													=   ['''past_key_values''']


    def __init__(    self   :			Optional[Any]      ,				UpperCAmelCase__   :			str=65_024      ,				UpperCAmelCase__   :			List[Any]=4_544      ,				UpperCAmelCase__   :			Optional[Any]=32      ,				UpperCAmelCase__   :			Dict=71      ,				UpperCAmelCase__   :			Any=1e-5      ,				UpperCAmelCase__   :			Optional[int]=0.02      ,				UpperCAmelCase__   :			Optional[int]=True      ,				UpperCAmelCase__   :			Union[str, Any]=0.0      ,				UpperCAmelCase__   :			List[str]=0.0      ,				UpperCAmelCase__   :			str=None      ,				UpperCAmelCase__   :			Dict=False      ,				UpperCAmelCase__   :			List[str]=False      ,				UpperCAmelCase__   :			Optional[Any]=True      ,				UpperCAmelCase__   :			Optional[Any]=True      ,				UpperCAmelCase__   :			Optional[Any]=False      ,				UpperCAmelCase__   :			Dict=11      ,				UpperCAmelCase__   :			str=11      ,				**UpperCAmelCase__   :			Dict      ,				)		->Any:





           '''simple docstring'''

           A__   				=					vocab_size
           # Backward compatibility with n_embed kwarg
           A__   				=					kwargs.pop('''n_embed'''      ,				UpperCAmelCase__)
           A__   				=					hidden_size if n_embed is None else n_embed
           A__   				=					num_hidden_layers
           A__   				=					num_attention_heads
           A__   				=					layer_norm_epsilon
           A__   				=					initializer_range
           A__   				=					use_cache
           A__   				=					hidden_dropout
           A__   				=					attention_dropout

           A__   				=					bos_token_id
           A__   				=					eos_token_id
           A__   				=					num_attention_heads if num_kv_heads is None else num_kv_heads
           A__   				=					alibi
           A__   				=					new_decoder_architecture
           A__   				=					multi_query  # Ignored when new_decoder_architecture is True
           A__   				=					parallel_attn
           A__   				=					bias

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


    @property
    def  SCREAMING_SNAKE_CASE							(    self   :			str)		->int:





           '''simple docstring'''

           return self.hidden_size // self.num_attention_heads





    @property
    def  SCREAMING_SNAKE_CASE							(    self   :			str)		->Dict:





           '''simple docstring'''

           return not self.alibi


