


'''simple docstring'''





from typing import Dict, List, Optional, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import (
    center_crop,
    convert_to_rgb,
    get_resize_output_image_size,
    normalize,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    OPENAI_CLIP_MEAN,
    OPENAI_CLIP_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_vision_available, logging


__a     =			logging.get_logger(__name__)


if is_vision_available():
 import PIL






class   __lowercase				(  __snake_case  ):
      UpperCamelCase								=       ['''pixel_values''']





      def __init__(		self						:					List[str]					,       __lowerCamelCase						:					bool = True					,       __lowerCamelCase						:					Dict[str, int] = None					,       __lowerCamelCase						:					PILImageResampling = PILImageResampling.BICUBIC					,       __lowerCamelCase						:					bool = True					,       __lowerCamelCase						:					Dict[str, int] = None					,       __lowerCamelCase						:					bool = True					,       __lowerCamelCase						:					Union[int, float] = 1 / 2_5_5					,       __lowerCamelCase						:					bool = True					,       __lowerCamelCase						:					Optional[Union[float, List[float]]] = None					,       __lowerCamelCase						:					Optional[Union[float, List[float]]] = None					,       __lowerCamelCase						:					bool = True					,       **__lowerCamelCase						:					Optional[Any]					,       )    ->   None:






         """simple docstring"""







         super().__init__(**__lowerCamelCase       )
         UpperCAmelCase							=     size if size is not None else {"""shortest_edge""": 2_2_4}
         UpperCAmelCase							=     get_size_dict(__lowerCamelCase					,       default_to_square=__lowerCamelCase       )
         UpperCAmelCase							=     crop_size if crop_size is not None else {"""height""": 2_2_4, """width""": 2_2_4}
         UpperCAmelCase							=     get_size_dict(__lowerCamelCase					,       default_to_square=__lowerCamelCase					,       param_name="""crop_size"""       )

         UpperCAmelCase							=     do_resize
         UpperCAmelCase							=     size
         UpperCAmelCase							=     resample
         UpperCAmelCase							=     do_center_crop
         UpperCAmelCase							=     crop_size
         UpperCAmelCase							=     do_rescale
         UpperCAmelCase							=     rescale_factor
         UpperCAmelCase							=     do_normalize
         UpperCAmelCase							=     image_mean if image_mean is not None else OPENAI_CLIP_MEAN
         UpperCAmelCase							=     image_std if image_std is not None else OPENAI_CLIP_STD
         UpperCAmelCase							=     do_convert_rgb





      def        _lowercase				(		self						:					Dict					,       __lowerCamelCase						:					np.ndarray					,       __lowerCamelCase						:					Dict[str, int]					,       __lowerCamelCase						:					PILImageResampling = PILImageResampling.BICUBIC					,       __lowerCamelCase						:					Optional[Union[str, ChannelDimension]] = None					,       **__lowerCamelCase						:					Tuple					,       )    ->   np.ndarray:






         """simple docstring"""







         UpperCAmelCase							=     get_size_dict(__lowerCamelCase					,       default_to_square=__lowerCamelCase       )
         if "shortest_edge" not in size:
            raise ValueError(F"""The `size` parameter must contain the key `shortest_edge`. Got {size.keys()}"""       )
         UpperCAmelCase							=     get_resize_output_image_size(__lowerCamelCase					,       size=size["""shortest_edge"""]					,       default_to_square=__lowerCamelCase       )
         return resize(__lowerCamelCase					,       size=__lowerCamelCase					,       resample=__lowerCamelCase					,       data_format=__lowerCamelCase					,       **__lowerCamelCase       )





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






         """simple docstring"""







         UpperCAmelCase							=     get_size_dict(__lowerCamelCase       )
         if "height" not in size or "width" not in size:
            raise ValueError(F"""The `size` parameter must contain the keys (height, width). Got {size.keys()}"""       )
         return center_crop(__lowerCamelCase					,       size=(size["""height"""], size["""width"""])					,       data_format=__lowerCamelCase					,       **__lowerCamelCase       )





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






         """simple docstring"""







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





      def        _lowercase				(		self						:					Optional[Any]					,       __lowerCamelCase						:					np.ndarray					,       __lowerCamelCase						:					Union[float, List[float]]					,       __lowerCamelCase						:					Union[float, List[float]]					,       __lowerCamelCase						:					Optional[Union[str, ChannelDimension]] = None					,       **__lowerCamelCase						:					Dict					,       )    ->   np.ndarray:






         """simple docstring"""







         return normalize(__lowerCamelCase					,       mean=__lowerCamelCase					,       std=__lowerCamelCase					,       data_format=__lowerCamelCase					,       **__lowerCamelCase       )





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






         """simple docstring"""







         UpperCAmelCase							=     do_resize if do_resize is not None else self.do_resize
         UpperCAmelCase							=     size if size is not None else self.size
         UpperCAmelCase							=     get_size_dict(__lowerCamelCase					,       param_name="""size"""					,       default_to_square=__lowerCamelCase       )
         UpperCAmelCase							=     resample if resample is not None else self.resample
         UpperCAmelCase							=     do_center_crop if do_center_crop is not None else self.do_center_crop
         UpperCAmelCase							=     crop_size if crop_size is not None else self.crop_size
         UpperCAmelCase							=     get_size_dict(__lowerCamelCase					,       param_name="""crop_size"""					,       default_to_square=__lowerCamelCase       )
         UpperCAmelCase							=     do_rescale if do_rescale is not None else self.do_rescale
         UpperCAmelCase							=     rescale_factor if rescale_factor is not None else self.rescale_factor
         UpperCAmelCase							=     do_normalize if do_normalize is not None else self.do_normalize
         UpperCAmelCase							=     image_mean if image_mean is not None else self.image_mean
         UpperCAmelCase							=     image_std if image_std is not None else self.image_std
         UpperCAmelCase							=     do_convert_rgb if do_convert_rgb is not None else self.do_convert_rgb

         UpperCAmelCase							=     make_list_of_images(__lowerCamelCase       )

         if not valid_images(__lowerCamelCase       ):
            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_center_crop and crop_size is None:
            raise ValueError("""Crop size must be specified if do_center_crop is True."""       )

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

         if do_normalize and (image_mean is None or image_std is None):
            raise ValueError("""Image mean and std must be specified if do_normalize is True."""       )

         # PIL RGBA images are converted to RGB
         if do_convert_rgb:
            UpperCAmelCase							=     [convert_to_rgb(__lowerCamelCase       ) for image in images]

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

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

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

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

         if do_normalize:
            UpperCAmelCase							=     [self.normalize(image=__lowerCamelCase					,       mean=__lowerCamelCase					,       std=__lowerCamelCase       ) for image in images]

         UpperCAmelCase							=     [to_channel_dimension_format(__lowerCamelCase					,       __lowerCamelCase       ) for image in images]

         UpperCAmelCase							=     {"""pixel_values""": images}
         return BatchFeature(data=__lowerCamelCase					,       tensor_type=__lowerCamelCase       )







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


__a     =			logging.get_logger(__name__)

__a     =			{
    """facebook/nllb-moe-54B""": """https://huggingface.co/facebook/nllb-moe-54b/resolve/main/config.json""",
}






class   __lowercase				(  __snake_case  ):
      UpperCamelCase								=       '''nllb-moe'''
      UpperCamelCase								=       ['''past_key_values''']
      UpperCamelCase								=       {'''num_attention_heads''': '''encoder_attention_heads''', '''hidden_size''': '''d_model'''}





      def __init__(		self						:					Optional[int]					,       __lowerCamelCase						:					Optional[Any]=1_2_8_1_1_2					,       __lowerCamelCase						:					Dict=1_0_2_4					,       __lowerCamelCase						:					Optional[int]=1_2					,       __lowerCamelCase						:					Union[str, Any]=4_0_9_6					,       __lowerCamelCase						:					List[str]=1_6					,       __lowerCamelCase						:					List[str]=1_2					,       __lowerCamelCase						:					int=4_0_9_6					,       __lowerCamelCase						:					Tuple=1_6					,       __lowerCamelCase						:					str=0.05					,       __lowerCamelCase						:					List[str]=0.05					,       __lowerCamelCase						:					List[Any]=True					,       __lowerCamelCase						:					Tuple=True					,       __lowerCamelCase						:					str="relu"					,       __lowerCamelCase						:					Dict=1_0_2_4					,       __lowerCamelCase						:					List[str]=0.1					,       __lowerCamelCase						:					Optional[int]=0.1					,       __lowerCamelCase						:					List[Any]=0.0					,       __lowerCamelCase						:					Optional[Any]=0.02					,       __lowerCamelCase						:					Dict=2					,       __lowerCamelCase						:					Union[str, Any]=True					,       __lowerCamelCase						:					Any=False					,       __lowerCamelCase						:					Tuple="float32"					,       __lowerCamelCase						:					Any=False					,       __lowerCamelCase						:					Optional[int]=1_2_8					,       __lowerCamelCase						:					List[str]=6_4					,       __lowerCamelCase						:					List[Any]=4					,       __lowerCamelCase						:					Tuple=4					,       __lowerCamelCase						:					str=0.001					,       __lowerCamelCase						:					Optional[int]=0.001					,       __lowerCamelCase						:					Tuple="all"					,       __lowerCamelCase						:					Any=False					,       __lowerCamelCase						:					Optional[int]=False					,       __lowerCamelCase						:					List[str]=1.0					,       __lowerCamelCase						:					Dict=0.2					,       __lowerCamelCase						:					Union[str, Any]=1					,       __lowerCamelCase						:					int=0					,       __lowerCamelCase						:					Dict=2					,       __lowerCamelCase						:					int=False					,       **__lowerCamelCase						:					str					,       )    ->   int:






         """simple docstring"""







         UpperCAmelCase							=     vocab_size
         UpperCAmelCase							=     max_position_embeddings
         UpperCAmelCase							=     d_model
         UpperCAmelCase							=     encoder_ffn_dim
         UpperCAmelCase							=     encoder_layers
         UpperCAmelCase							=     encoder_attention_heads
         UpperCAmelCase							=     decoder_ffn_dim
         UpperCAmelCase							=     decoder_layers
         UpperCAmelCase							=     decoder_attention_heads
         UpperCAmelCase							=     dropout
         UpperCAmelCase							=     attention_dropout
         UpperCAmelCase							=     activation_dropout
         UpperCAmelCase							=     activation_function
         UpperCAmelCase							=     init_std
         UpperCAmelCase							=     encoder_layerdrop
         UpperCAmelCase							=     decoder_layerdrop
         UpperCAmelCase							=     use_cache
         UpperCAmelCase							=     encoder_layers
         UpperCAmelCase							=     scale_embedding  # scale factor will be sqrt(d_model) if True
         UpperCAmelCase							=     router_z_loss_coef
         UpperCAmelCase							=     router_aux_loss_coef
         UpperCAmelCase							=     decoder_sparse_step
         UpperCAmelCase							=     encoder_sparse_step
         UpperCAmelCase							=     num_experts
         UpperCAmelCase							=     expert_capacity
         UpperCAmelCase							=     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							=     router_dtype

         UpperCAmelCase							=     router_ignore_padding_tokens
         UpperCAmelCase							=     batch_prioritized_routing
         UpperCAmelCase							=     second_expert_policy
         UpperCAmelCase							=     normalize_router_prob_before_dropping
         UpperCAmelCase							=     moe_eval_capacity_token_fraction
         UpperCAmelCase							=     moe_token_dropout
         UpperCAmelCase							=     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					,       )



