






'''simple docstring'''
import warnings
from typing import List, Optional, Union

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding, PaddingStrategy, PreTokenizedInput, TextInput, TruncationStrategy
from ...utils import TensorType






class      __SCREAMING_SNAKE_CASE      (			lowerCamelCase				):
 snake_case_  							=							["""image_processor""", """tokenizer"""]
 snake_case_  							=							"""LayoutLMv3ImageProcessor"""
 snake_case_  							=							("""LayoutLMv3Tokenizer""", """LayoutLMv3TokenizerFast""")




 def __init__(      self	:							int					,      __lowercase	:							Optional[Any]=None					,      __lowercase	:							Any=None					,      **__lowercase	:							Tuple      )	->						Tuple:
       SCREAMING_SNAKE_CASE__     :				Optional[Any]									=None
       if "feature_extractor" in kwargs:
             warnings.warn(
                 '''The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`'''
                 ''' instead.'''					,      __lowercase					,      )
             SCREAMING_SNAKE_CASE__     :				Dict									=kwargs.pop('''feature_extractor'''      )

       SCREAMING_SNAKE_CASE__     :				Tuple									=image_processor if image_processor is not None else feature_extractor
       if image_processor is None:
             raise ValueError('''You need to specify an `image_processor`.'''      )
       if tokenizer is None:
             raise ValueError('''You need to specify a `tokenizer`.'''      )

       super().__init__(__lowercase					,      __lowercase      )




 def __call__(      self	:							Union[str, Any]					,      __lowercase	:							Optional[Any]					,      __lowercase	:							Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]] = None					,      __lowercase	:							Optional[Union[PreTokenizedInput, List[PreTokenizedInput]]] = None					,      __lowercase	:							Union[List[List[int]], List[List[List[int]]]] = None					,      __lowercase	:							Optional[Union[List[int], List[List[int]]]] = None					,      __lowercase	:							bool = True					,      __lowercase	:							Union[bool, str, PaddingStrategy] = False					,      __lowercase	:							Union[bool, str, TruncationStrategy] = None					,      __lowercase	:							Optional[int] = None					,      __lowercase	:							int = 0					,      __lowercase	:							Optional[int] = None					,      __lowercase	:							Optional[bool] = None					,      __lowercase	:							Optional[bool] = None					,      __lowercase	:							bool = False					,      __lowercase	:							bool = False					,      __lowercase	:							bool = False					,      __lowercase	:							bool = False					,      __lowercase	:							bool = True					,      __lowercase	:							Optional[Union[str, TensorType]] = None					,      **__lowercase	:							str					,      )	->						BatchEncoding:
       # verify input
       if self.image_processor.apply_ocr and (boxes is not None):
             raise ValueError(
                 '''You cannot provide bounding boxes if you initialized the image processor with apply_ocr set to True.'''      )

       if self.image_processor.apply_ocr and (word_labels is not None):
             raise ValueError(
                 '''You cannot provide word labels if you initialized the image processor with apply_ocr set to True.'''      )

       # first, apply the image processor
       SCREAMING_SNAKE_CASE__     :				List[str]									=self.image_processor(images=__lowercase					,      return_tensors=__lowercase      )

       # second, apply the tokenizer
       if text is not None and self.image_processor.apply_ocr and text_pair is None:
             if isinstance(__lowercase					,      __lowercase      ):
                   SCREAMING_SNAKE_CASE__     :				Tuple									=[text]  # add batch dimension (as the image processor always adds a batch dimension)
             SCREAMING_SNAKE_CASE__     :				List[str]									=features['''words''']

       SCREAMING_SNAKE_CASE__     :				List[Any]									=self.tokenizer(
           text=text if text is not None else features['''words''']					,      text_pair=text_pair if text_pair is not None else None					,      boxes=boxes if boxes is not None else features['''boxes''']					,      word_labels=__lowercase					,      add_special_tokens=__lowercase					,      padding=__lowercase					,      truncation=__lowercase					,      max_length=__lowercase					,      stride=__lowercase					,      pad_to_multiple_of=__lowercase					,      return_token_type_ids=__lowercase					,      return_attention_mask=__lowercase					,      return_overflowing_tokens=__lowercase					,      return_special_tokens_mask=__lowercase					,      return_offsets_mapping=__lowercase					,      return_length=__lowercase					,      verbose=__lowercase					,      return_tensors=__lowercase					,      **__lowercase					,      )

       # add pixel values
       SCREAMING_SNAKE_CASE__     :				Union[str, Any]									=features.pop('''pixel_values'''      )
       if return_overflowing_tokens is True:
             SCREAMING_SNAKE_CASE__     :				int									=self.get_overflowing_images(__lowercase					,      encoded_inputs['''overflow_to_sample_mapping''']      )
       SCREAMING_SNAKE_CASE__     :				int									=images

       return encoded_inputs




 def      __magic_name__	(      self	:							List[str]					,      __lowercase	:							str					,      __lowercase	:							List[str]      )	->						List[Any]:
       # in case there's an overflow, ensure each `input_ids` sample is mapped to its corresponding image
       SCREAMING_SNAKE_CASE__     :				List[str]									=[]
       for sample_idx in overflow_to_sample_mapping:
             images_with_overflow.append(images[sample_idx]      )

       if len(__lowercase      ) != len(__lowercase      ):
             raise ValueError(
                 '''Expected length of images to be the same as the length of `overflow_to_sample_mapping`, but got'''
                 F" {len(__lowercase      )} and {len(__lowercase      )}"      )

       return images_with_overflow




 def      __magic_name__	(      self	:							int					,      *__lowercase	:							Dict					,      **__lowercase	:							Tuple      )	->						int:
       return self.tokenizer.batch_decode(*__lowercase					,      **__lowercase      )




 def      __magic_name__	(      self	:							int					,      *__lowercase	:							Optional[int]					,      **__lowercase	:							Optional[Any]      )	->						Optional[Any]:
       return self.tokenizer.decode(*__lowercase					,      **__lowercase      )




 @property
 def      __magic_name__	(      self	:							Optional[int]      )	->						Dict:
       return ["input_ids", "bbox", "attention_mask", "pixel_values"]




 @property
 def      __magic_name__	(      self	:							Optional[int]      )	->						Any:
       warnings.warn(
           '''`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead.'''					,      __lowercase					,      )
       return self.image_processor_class




 @property
 def      __magic_name__	(      self	:							Dict      )	->						Union[str, Any]:
       warnings.warn(
           '''`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead.'''					,      __lowercase					,      )
       return self.image_processor







'''simple docstring'''
from ...configuration_utils import PretrainedConfig
from ...utils import logging


a_					= logging.get_logger(__name__)

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






class      __SCREAMING_SNAKE_CASE      (			lowerCamelCase				):
 snake_case_  							=							"""gpt_bigcode"""
 snake_case_  							=							["""past_key_values"""]
 snake_case_  							=							{
     """hidden_size""": """n_embd""",
     """max_position_embeddings""": """n_positions""",
     """num_attention_heads""": """n_head""",
     """num_hidden_layers""": """n_layer""",
 }




 def __init__(      self	:							Any					,      __lowercase	:							Any=5_02_57					,      __lowercase	:							int=10_24					,      __lowercase	:							List[str]=7_68					,      __lowercase	:							Optional[int]=12					,      __lowercase	:							Dict=12					,      __lowercase	:							List[str]=None					,      __lowercase	:							int="gelu_pytorch_tanh"					,      __lowercase	:							Union[str, Any]=0.1					,      __lowercase	:							Optional[int]=0.1					,      __lowercase	:							Optional[int]=0.1					,      __lowercase	:							Optional[Any]=1e-5					,      __lowercase	:							List[str]=0.02					,      __lowercase	:							Tuple=True					,      __lowercase	:							Optional[Any]=True					,      __lowercase	:							Union[str, Any]=5_02_56					,      __lowercase	:							List[Any]=5_02_56					,      __lowercase	:							Union[str, Any]=True					,      __lowercase	:							List[str]=True					,      __lowercase	:							Dict=True					,      **__lowercase	:							List[Any]					,      )	->						Optional[int]:
       SCREAMING_SNAKE_CASE__     :				Union[str, Any]									=vocab_size
       SCREAMING_SNAKE_CASE__     :				Union[str, Any]									=n_positions
       SCREAMING_SNAKE_CASE__     :				Dict									=n_embd
       SCREAMING_SNAKE_CASE__     :				Dict									=n_layer
       SCREAMING_SNAKE_CASE__     :				Union[str, Any]									=n_head
       SCREAMING_SNAKE_CASE__     :				List[str]									=n_inner
       SCREAMING_SNAKE_CASE__     :				List[str]									=activation_function
       SCREAMING_SNAKE_CASE__     :				List[Any]									=resid_pdrop
       SCREAMING_SNAKE_CASE__     :				List[Any]									=embd_pdrop
       SCREAMING_SNAKE_CASE__     :				List[str]									=attn_pdrop
       SCREAMING_SNAKE_CASE__     :				Dict									=layer_norm_epsilon
       SCREAMING_SNAKE_CASE__     :				List[str]									=initializer_range
       SCREAMING_SNAKE_CASE__     :				List[Any]									=scale_attn_weights
       SCREAMING_SNAKE_CASE__     :				Union[str, Any]									=use_cache
       SCREAMING_SNAKE_CASE__     :				Dict									=attention_softmax_in_fpaa
       SCREAMING_SNAKE_CASE__     :				int									=scale_attention_softmax_in_fpaa
       SCREAMING_SNAKE_CASE__     :				Dict									=multi_query

       SCREAMING_SNAKE_CASE__     :				Optional[Any]									=bos_token_id
       SCREAMING_SNAKE_CASE__     :				Optional[Any]									=eos_token_id

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