


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


__UpperCamelCase       :       Dict						       =				logging.get_logger(__name__)

__UpperCamelCase       :       Optional[Any]						       =				{
    "facebook/nllb-moe-54B": "https://huggingface.co/facebook/nllb-moe-54b/resolve/main/config.json",
}

class       __magic_name__	(     __lowerCAmelCase):
     A:		Dict			=      "nllb-moe"
     A:		Any			=      ["past_key_values"]
     A:		Optional[int]			=      {"num_attention_heads": "encoder_attention_heads", "hidden_size": "d_model"}


     def __init__(      self							:     Optional[int]							,	lowerCamelCase__							:     Union[str, Any]=128112							,	lowerCamelCase__							:     Any=1024							,	lowerCamelCase__							:     Optional[Any]=12							,	lowerCamelCase__							:     str=4096							,	lowerCamelCase__							:     List[Any]=16							,	lowerCamelCase__							:     Dict=12							,	lowerCamelCase__							:     Optional[Any]=4096							,	lowerCamelCase__							:     int=16							,	lowerCamelCase__							:     Dict=0.05							,	lowerCamelCase__							:     Dict=0.05							,	lowerCamelCase__							:     Optional[int]=True							,	lowerCamelCase__							:     List[Any]=True							,	lowerCamelCase__							:     Tuple="relu"							,	lowerCamelCase__							:     Any=1024							,	lowerCamelCase__							:     Any=0.1							,	lowerCamelCase__							:     Tuple=0.1							,	lowerCamelCase__							:     Optional[Any]=0.0							,	lowerCamelCase__							:     Dict=0.02							,	lowerCamelCase__							:     int=2							,	lowerCamelCase__							:     Optional[int]=True							,	lowerCamelCase__							:     str=False							,	lowerCamelCase__							:     Dict="float32"							,	lowerCamelCase__							:     Dict=False							,	lowerCamelCase__							:     List[str]=128							,	lowerCamelCase__							:     Any=64							,	lowerCamelCase__							:     Union[str, Any]=4							,	lowerCamelCase__							:     List[Any]=4							,	lowerCamelCase__							:     str=0.001							,	lowerCamelCase__							:     List[Any]=0.001							,	lowerCamelCase__							:     Union[str, Any]="all"							,	lowerCamelCase__							:     List[Any]=False							,	lowerCamelCase__							:     Tuple=False							,	lowerCamelCase__							:     Tuple=1.0							,	lowerCamelCase__							:     List[str]=0.2							,	lowerCamelCase__							:     str=1							,	lowerCamelCase__							:     Any=0							,	lowerCamelCase__							:     int=2							,	lowerCamelCase__							:     Any=False							,	**lowerCamelCase__							:     Any							,	)  ->      Tuple:





      '''simple docstring'''






      UpperCamelCase__					:    Optional[int]          =   vocab_size
      UpperCamelCase__					:    List[Any]          =   max_position_embeddings
      UpperCamelCase__					:    str          =   d_model
      UpperCamelCase__					:    Union[str, Any]          =   encoder_ffn_dim
      UpperCamelCase__					:    Optional[int]          =   encoder_layers
      UpperCamelCase__					:    Tuple          =   encoder_attention_heads
      UpperCamelCase__					:    Union[str, Any]          =   decoder_ffn_dim
      UpperCamelCase__					:    Optional[int]          =   decoder_layers
      UpperCamelCase__					:    List[str]          =   decoder_attention_heads
      UpperCamelCase__					:    Union[str, Any]          =   dropout
      UpperCamelCase__					:    Union[str, Any]          =   attention_dropout
      UpperCamelCase__					:    Tuple          =   activation_dropout
      UpperCamelCase__					:    List[str]          =   activation_function
      UpperCamelCase__					:    int          =   init_std
      UpperCamelCase__					:    str          =   encoder_layerdrop
      UpperCamelCase__					:    Any          =   decoder_layerdrop
      UpperCamelCase__					:    str          =   use_cache
      UpperCamelCase__					:    str          =   encoder_layers
      UpperCamelCase__					:    List[Any]          =   scale_embedding  # scale factor will be sqrt(d_model) if True
      UpperCamelCase__					:    Optional[Any]          =   router_z_loss_coef
      UpperCamelCase__					:    List[str]          =   router_aux_loss_coef
      UpperCamelCase__					:    Optional[int]          =   decoder_sparse_step
      UpperCamelCase__					:    List[str]          =   encoder_sparse_step
      UpperCamelCase__					:    Any          =   num_experts
      UpperCamelCase__					:    int          =   expert_capacity
      UpperCamelCase__					:    Optional[int]          =   router_bias
      if router_dtype not in ["float32", "float16", "bfloat16"]:
       raise ValueError(F"`router_dtype` must be one of 'float32', 'float16' or 'bfloat16', got {router_dtype}"			)
      UpperCamelCase__					:    Tuple          =   router_dtype

      UpperCamelCase__					:    Optional[Any]          =   router_ignore_padding_tokens
      UpperCamelCase__					:    Dict          =   batch_prioritized_routing
      UpperCamelCase__					:    Union[str, Any]          =   second_expert_policy
      UpperCamelCase__					:    Dict          =   normalize_router_prob_before_dropping
      UpperCamelCase__					:    List[str]          =   moe_eval_capacity_token_fraction
      UpperCamelCase__					:    Dict          =   moe_token_dropout
      UpperCamelCase__					:    Any          =   output_router_logits
      super().__init__(
          pad_token_id=lowerCamelCase__							,	bos_token_id=lowerCamelCase__							,	eos_token_id=lowerCamelCase__							,	is_encoder_decoder=lowerCamelCase__							,	decoder_start_token_id=lowerCamelCase__							,	**lowerCamelCase__							,	)






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       __magic_name__	(     __lowerCAmelCase):
     A:		Optional[Any]			=      ["image_processor", "tokenizer"]
     A:		Optional[Any]			=      "LayoutLMv2ImageProcessor"
     A:		List[str]			=      ("LayoutXLMTokenizer", "LayoutXLMTokenizerFast")


     def __init__(      self							:     Dict							,	lowerCamelCase__							:     Union[str, Any]=None							,	lowerCamelCase__							:     List[str]=None							,	**lowerCamelCase__							:     Any			)  ->      Optional[Any]:





      '''simple docstring'''






      if "feature_extractor" in kwargs:
       warnings.warn(
           '''The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`'''
           ''' instead.'''							,	lowerCamelCase__							,	)
       UpperCamelCase__					:    str          =   kwargs.pop('''feature_extractor'''			)

      UpperCamelCase__					:    List[Any]          =   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__(lowerCamelCase__							,	lowerCamelCase__			)


     def __call__(      self							:     Optional[Any]							,	lowerCamelCase__							:     Union[str, Any]							,	lowerCamelCase__							:     Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]] = None							,	lowerCamelCase__							:     Optional[Union[PreTokenizedInput, List[PreTokenizedInput]]] = None							,	lowerCamelCase__							:     Union[List[List[int]], List[List[List[int]]]] = None							,	lowerCamelCase__							:     Optional[Union[List[int], List[List[int]]]] = None							,	lowerCamelCase__							:     bool = True							,	lowerCamelCase__							:     Union[bool, str, PaddingStrategy] = False							,	lowerCamelCase__							:     Union[bool, str, TruncationStrategy] = None							,	lowerCamelCase__							:     Optional[int] = None							,	lowerCamelCase__							:     int = 0							,	lowerCamelCase__							:     Optional[int] = None							,	lowerCamelCase__							:     Optional[bool] = None							,	lowerCamelCase__							:     Optional[bool] = None							,	lowerCamelCase__							:     bool = False							,	lowerCamelCase__							:     bool = False							,	lowerCamelCase__							:     bool = False							,	lowerCamelCase__							:     bool = False							,	lowerCamelCase__							:     bool = True							,	lowerCamelCase__							:     Optional[Union[str, TensorType]] = None							,	**lowerCamelCase__							:     Any							,	)  ->      BatchEncoding:





      '''simple docstring'''






      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.'''			)

      if return_overflowing_tokens is True and return_offsets_mapping is False:
       raise ValueError('''You cannot return overflowing tokens without returning the offsets mapping.'''			)

      # first, apply the image processor
      UpperCamelCase__					:    Optional[Any]          =   self.image_processor(images=lowerCamelCase__							,	return_tensors=lowerCamelCase__			)

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

      UpperCamelCase__					:    Optional[int]          =   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=lowerCamelCase__							,	add_special_tokens=lowerCamelCase__							,	padding=lowerCamelCase__							,	truncation=lowerCamelCase__							,	max_length=lowerCamelCase__							,	stride=lowerCamelCase__							,	pad_to_multiple_of=lowerCamelCase__							,	return_token_type_ids=lowerCamelCase__							,	return_attention_mask=lowerCamelCase__							,	return_overflowing_tokens=lowerCamelCase__							,	return_special_tokens_mask=lowerCamelCase__							,	return_offsets_mapping=lowerCamelCase__							,	return_length=lowerCamelCase__							,	verbose=lowerCamelCase__							,	return_tensors=lowerCamelCase__							,	**lowerCamelCase__							,	)

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

      return encoded_inputs


     def      UpperCAmelCase__	(      self							:     Optional[int]							,	lowerCamelCase__							:     Any							,	lowerCamelCase__							:     List[Any]			)  ->      str:





      '''simple docstring'''






      UpperCamelCase__					:    int          =   []
      for sample_idx in overflow_to_sample_mapping:
       images_with_overflow.append(images[sample_idx]			)

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

      return images_with_overflow


     def      UpperCAmelCase__	(      self							:     int							,	*lowerCamelCase__							:     Dict							,	**lowerCamelCase__							:     str			)  ->      str:





      '''simple docstring'''






      return self.tokenizer.batch_decode(*lowerCamelCase__							,	**lowerCamelCase__			)


     def      UpperCAmelCase__	(      self							:     List[str]							,	*lowerCamelCase__							:     int							,	**lowerCamelCase__							:     str			)  ->      Tuple:





      '''simple docstring'''






      return self.tokenizer.decode(*lowerCamelCase__							,	**lowerCamelCase__			)


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





      '''simple docstring'''






      return ["input_ids", "bbox", "attention_mask", "image"]


     @property
     def      UpperCAmelCase__	(      self							:     Dict			)  ->      Tuple:





      '''simple docstring'''






      warnings.warn(
          '''`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead.'''							,	lowerCamelCase__							,	)
      return self.image_processor_class


     @property
     def      UpperCAmelCase__	(      self							:     Optional[Any]			)  ->      Optional[int]:





      '''simple docstring'''






      warnings.warn(
          '''`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead.'''							,	lowerCamelCase__							,	)
      return self.image_processor


