






from typing import Optional

import torch
import torch.utils.checkpoint
from torch import Tensor, nn
from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss

from ...activations import ACTaFN
from ...modeling_outputs import (
    BackboneOutput,
    BaseModelOutputWithNoAttention,
    BaseModelOutputWithPoolingAndNoAttention,
    ImageClassifierOutputWithNoAttention,
)
from ...modeling_utils import PreTrainedModel
from ...utils import (
    add_code_sample_docstrings,
    add_start_docstrings,
    add_start_docstrings_to_model_forward,
    logging,
    replace_return_docstrings,
)
from ...utils.backbone_utils import BackboneMixin
from .configuration_resnet import ResNetConfig


UpperCAmelCase__      			=						logging.get_logger(__name__)

# General docstring
UpperCAmelCase__      			=						'''ResNetConfig'''

# Base docstring
UpperCAmelCase__      			=						'''microsoft/resnet-50'''
UpperCAmelCase__      			=						[1, 2048, 7, 7]

# Image classification docstring
UpperCAmelCase__      			=						'''microsoft/resnet-50'''
UpperCAmelCase__      			=						'''tiger cat'''

UpperCAmelCase__      			=						[
    '''microsoft/resnet-50''',
    # See all resnet models at https://huggingface.co/models?filter=resnet
]




class 							snake_case_       (    nn.Module      ):

						"""simple docstring"""



						def __init__(self:					Dict ,					__UpperCAmelCase:					int ,					__UpperCAmelCase:					int ,					__UpperCAmelCase:					int = 3 ,					__UpperCAmelCase:					int = 1 ,					__UpperCAmelCase:					str = "relu"   )    ->     Any:




											'''simple docstring'''



											super().__init__()
											__a					:						List[str]      =					nn.Convad(
											    __UpperCAmelCase ,					__UpperCAmelCase ,					kernel_size=__UpperCAmelCase ,					stride=__UpperCAmelCase ,					padding=kernel_size // 2 ,					bias=__UpperCAmelCase   )
											__a					:						str      =					nn.BatchNormad(__UpperCAmelCase   )
											__a					:						Optional[int]      =					ACTaFN[activation] if activation is not None else nn.Identity()



						def        UpperCAmelCase__					(self:					List[str] ,					__UpperCAmelCase:					Tensor   )    ->     Tensor:




											'''simple docstring'''



											__a					:						int      =					self.convolution(__UpperCAmelCase   )
											__a					:						int      =					self.normalization(__UpperCAmelCase   )
											__a					:						Optional[int]      =					self.activation(__UpperCAmelCase   )
											return hidden_state




class 							snake_case_       (    nn.Module      ):

						"""simple docstring"""



						def __init__(self:					int ,					__UpperCAmelCase:					ResNetConfig   )    ->     List[str]:




											'''simple docstring'''



											super().__init__()
											__a					:						List[str]      =					ResNetConvLayer(
											    config.num_channels ,					config.embedding_size ,					kernel_size=7 ,					stride=2 ,					activation=config.hidden_act   )
											__a					:						Tuple      =					nn.MaxPoolad(kernel_size=3 ,					stride=2 ,					padding=1   )
											__a					:						List[Any]      =					config.num_channels



						def        UpperCAmelCase__					(self:					str ,					__UpperCAmelCase:					Tensor   )    ->     Tensor:




											'''simple docstring'''



											__a					:						Union[str, Any]      =					pixel_values.shape[1]
											if num_channels != self.num_channels:
																raise ValueError(
																    "Make sure that the channel dimension of the pixel values match with the one set in the configuration."   )
											__a					:						Dict      =					self.embedder(__UpperCAmelCase   )
											__a					:						Optional[int]      =					self.pooler(__UpperCAmelCase   )
											return embedding




class 							snake_case_       (    nn.Module      ):

						"""simple docstring"""



						def __init__(self:					List[Any] ,					__UpperCAmelCase:					int ,					__UpperCAmelCase:					int ,					__UpperCAmelCase:					int = 2   )    ->     str:




											'''simple docstring'''



											super().__init__()
											__a					:						Union[str, Any]      =					nn.Convad(__UpperCAmelCase ,					__UpperCAmelCase ,					kernel_size=1 ,					stride=__UpperCAmelCase ,					bias=__UpperCAmelCase   )
											__a					:						Tuple      =					nn.BatchNormad(__UpperCAmelCase   )



						def        UpperCAmelCase__					(self:					List[Any] ,					__UpperCAmelCase:					Tensor   )    ->     Tensor:




											'''simple docstring'''



											__a					:						str      =					self.convolution(__UpperCAmelCase   )
											__a					:						Optional[int]      =					self.normalization(__UpperCAmelCase   )
											return hidden_state




class 							snake_case_       (    nn.Module      ):

						"""simple docstring"""



						def __init__(self:					int ,					__UpperCAmelCase:					int ,					__UpperCAmelCase:					int ,					__UpperCAmelCase:					int = 1 ,					__UpperCAmelCase:					str = "relu"   )    ->     str:




											'''simple docstring'''



											super().__init__()
											__a					:						List[Any]      =					in_channels != out_channels or stride != 1
											__a					:						Tuple      =					(
											    ResNetShortCut(__UpperCAmelCase ,					__UpperCAmelCase ,					stride=__UpperCAmelCase   ) if should_apply_shortcut else nn.Identity()
											)
											__a					:						Optional[int]      =					nn.Sequential(
											    ResNetConvLayer(__UpperCAmelCase ,					__UpperCAmelCase ,					stride=__UpperCAmelCase   ) ,					ResNetConvLayer(__UpperCAmelCase ,					__UpperCAmelCase ,					activation=__UpperCAmelCase   ) ,					)
											__a					:						List[Any]      =					ACTaFN[activation]



						def        UpperCAmelCase__					(self:					Any ,					__UpperCAmelCase:					str   )    ->     int:




											'''simple docstring'''



											__a					:						str      =					hidden_state
											__a					:						Any      =					self.layer(__UpperCAmelCase   )
											__a					:						Union[str, Any]      =					self.shortcut(__UpperCAmelCase   )
											hidden_state += residual
											__a					:						int      =					self.activation(__UpperCAmelCase   )
											return hidden_state




class 							snake_case_       (    nn.Module      ):

						"""simple docstring"""



						def __init__(self:					Dict ,					__UpperCAmelCase:					int ,					__UpperCAmelCase:					int ,					__UpperCAmelCase:					int = 1 ,					__UpperCAmelCase:					str = "relu" ,					__UpperCAmelCase:					int = 4   )    ->     Optional[Any]:




											'''simple docstring'''



											super().__init__()
											__a					:						Any      =					in_channels != out_channels or stride != 1
											__a					:						Optional[Any]      =					out_channels // reduction
											__a					:						int      =					(
											    ResNetShortCut(__UpperCAmelCase ,					__UpperCAmelCase ,					stride=__UpperCAmelCase   ) if should_apply_shortcut else nn.Identity()
											)
											__a					:						Any      =					nn.Sequential(
											    ResNetConvLayer(__UpperCAmelCase ,					__UpperCAmelCase ,					kernel_size=1   ) ,					ResNetConvLayer(__UpperCAmelCase ,					__UpperCAmelCase ,					stride=__UpperCAmelCase   ) ,					ResNetConvLayer(__UpperCAmelCase ,					__UpperCAmelCase ,					kernel_size=1 ,					activation=__UpperCAmelCase   ) ,					)
											__a					:						Any      =					ACTaFN[activation]



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




											'''simple docstring'''



											__a					:						List[Any]      =					hidden_state
											__a					:						List[Any]      =					self.layer(__UpperCAmelCase   )
											__a					:						List[str]      =					self.shortcut(__UpperCAmelCase   )
											hidden_state += residual
											__a					:						List[Any]      =					self.activation(__UpperCAmelCase   )
											return hidden_state




class 							snake_case_       (    nn.Module      ):

						"""simple docstring"""



						def __init__(self:					Tuple ,					__UpperCAmelCase:					ResNetConfig ,					__UpperCAmelCase:					int ,					__UpperCAmelCase:					int ,					__UpperCAmelCase:					int = 2 ,					__UpperCAmelCase:					int = 2 ,					)    ->     Union[str, Any]:




											'''simple docstring'''



											super().__init__()

											__a					:						int      =					ResNetBottleNeckLayer if config.layer_type == "bottleneck" else ResNetBasicLayer

											__a					:						Optional[Any]      =					nn.Sequential(
											    # downsampling is done in the first layer with stride of 2
											    layer(__UpperCAmelCase ,					__UpperCAmelCase ,					stride=__UpperCAmelCase ,					activation=config.hidden_act   ) ,					*[layer(__UpperCAmelCase ,					__UpperCAmelCase ,					activation=config.hidden_act   ) for _ in range(depth - 1   )] ,					)



						def        UpperCAmelCase__					(self:					List[Any] ,					__UpperCAmelCase:					Tensor   )    ->     Tensor:




											'''simple docstring'''



											__a					:						Union[str, Any]      =					input
											for layer in self.layers:
																__a					:						Tuple      =					layer(__UpperCAmelCase   )
											return hidden_state




class 							snake_case_       (    nn.Module      ):

						"""simple docstring"""



						def __init__(self:					Union[str, Any] ,					__UpperCAmelCase:					ResNetConfig   )    ->     Dict:




											'''simple docstring'''



											super().__init__()
											__a					:						int      =					nn.ModuleList([]   )
											# based on `downsample_in_first_stage` the first layer of the first stage may or may not downsample the input
											self.stages.append(
											    ResNetStage(
											        __UpperCAmelCase ,					config.embedding_size ,					config.hidden_sizes[0] ,					stride=2 if config.downsample_in_first_stage else 1 ,					depth=config.depths[0] ,					)   )
											__a					:						int      =					zip(config.hidden_sizes ,					config.hidden_sizes[1:]   )
											for (in_channels, out_channels), depth in zip(__UpperCAmelCase ,					config.depths[1:]   ):
																self.stages.append(ResNetStage(__UpperCAmelCase ,					__UpperCAmelCase ,					__UpperCAmelCase ,					depth=__UpperCAmelCase   )   )



						def        UpperCAmelCase__					(self:					Optional[int] ,					__UpperCAmelCase:					Tensor ,					__UpperCAmelCase:					bool = False ,					__UpperCAmelCase:					bool = True   )    ->     BaseModelOutputWithNoAttention:




											'''simple docstring'''



											__a					:						str      =					() if output_hidden_states else None

											for stage_module in self.stages:
																if output_hidden_states:
																					__a					:						Any      =					hidden_states + (hidden_state,)

																__a					:						List[str]      =					stage_module(__UpperCAmelCase   )

											if output_hidden_states:
																__a					:						int      =					hidden_states + (hidden_state,)

											if not return_dict:
																return tuple(v for v in [hidden_state, hidden_states] if v is not None   )

											return BaseModelOutputWithNoAttention(
											    last_hidden_state=__UpperCAmelCase ,					hidden_states=__UpperCAmelCase ,					)




class 							snake_case_       (    __UpperCamelCase      ):

						"""simple docstring"""



						snake_case__        =      ResNetConfig
						snake_case__        =      """resnet"""
						snake_case__        =      """pixel_values"""
						snake_case__        =      True



						def        UpperCAmelCase__					(self:					Any ,					__UpperCAmelCase:					List[Any]   )    ->     List[Any]:




											'''simple docstring'''



											if isinstance(__UpperCAmelCase ,					nn.Convad   ):
																nn.init.kaiming_normal_(module.weight ,					mode="fan_out" ,					nonlinearity="relu"   )
											elif isinstance(__UpperCAmelCase ,					(nn.BatchNormad, nn.GroupNorm)   ):
																nn.init.constant_(module.weight ,					1   )
																nn.init.constant_(module.bias ,					0   )



						def        UpperCAmelCase__					(self:					Optional[Any] ,					__UpperCAmelCase:					Union[str, Any] ,					__UpperCAmelCase:					Optional[Any]=False   )    ->     Union[str, Any]:




											'''simple docstring'''



											if isinstance(__UpperCAmelCase ,					__UpperCAmelCase   ):
																__a					:						Optional[int]      =					value


UpperCAmelCase__      			=						r'''
    This model is a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass. Use it
    as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and
    behavior.

    Parameters:
        config ([`ResNetConfig`]): Model configuration class with all the parameters of the model.
            Initializing with a config file does not load the weights associated with the model, only the
            configuration. Check out the [`~PreTrainedModel.from_pretrained`] method to load the model weights.
'''

UpperCAmelCase__      			=						r'''
    Args:
        pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, height, width)`):
            Pixel values. Pixel values can be obtained using [`AutoImageProcessor`]. See
            [`ConvNextImageProcessor.__call__`] for details.

        output_hidden_states (`bool`, *optional*):
            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
            more detail.
        return_dict (`bool`, *optional*):
            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
'''




@add_start_docstrings(
    """The bare ResNet model outputting raw features without any specific head on top."""		,							__UpperCamelCase		,							)
class 							snake_case_       (    __UpperCamelCase      ):

						"""simple docstring"""



						def __init__(self:					Tuple ,					__UpperCAmelCase:					List[Any]   )    ->     Dict:




											'''simple docstring'''



											super().__init__(__UpperCAmelCase   )
											__a					:						List[Any]      =					config
											__a					:						Dict      =					ResNetEmbeddings(__UpperCAmelCase   )
											__a					:						Dict      =					ResNetEncoder(__UpperCAmelCase   )
											__a					:						Any      =					nn.AdaptiveAvgPoolad((1, 1)   )
											# Initialize weights and apply final processing
											self.post_init()



						@add_start_docstrings_to_model_forward(__UpperCAmelCase   )
						@add_code_sample_docstrings(
						    checkpoint=_CHECKPOINT_FOR_DOC ,					output_type=__UpperCAmelCase ,					config_class=_CONFIG_FOR_DOC ,					modality="vision" ,					expected_output=_EXPECTED_OUTPUT_SHAPE ,					)
						def        UpperCAmelCase__					(self:					List[Any] ,					__UpperCAmelCase:					Tensor ,					__UpperCAmelCase:					Optional[bool] = None ,					__UpperCAmelCase:					Optional[bool] = None   )    ->     BaseModelOutputWithPoolingAndNoAttention:




											'''simple docstring'''



											__a					:						Any      =					(
											    output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
											)
											__a					:						Optional[Any]      =					return_dict if return_dict is not None else self.config.use_return_dict

											__a					:						str      =					self.embedder(__UpperCAmelCase   )

											__a					:						Optional[Any]      =					self.encoder(
											    __UpperCAmelCase ,					output_hidden_states=__UpperCAmelCase ,					return_dict=__UpperCAmelCase   )

											__a					:						List[Any]      =					encoder_outputs[0]

											__a					:						Dict      =					self.pooler(__UpperCAmelCase   )

											if not return_dict:
																return (last_hidden_state, pooled_output) + encoder_outputs[1:]

											return BaseModelOutputWithPoolingAndNoAttention(
											    last_hidden_state=__UpperCAmelCase ,					pooler_output=__UpperCAmelCase ,					hidden_states=encoder_outputs.hidden_states ,					)




@add_start_docstrings(
    """
    ResNet Model with an image classification head on top (a linear layer on top of the pooled features), e.g. for
    ImageNet.
    """		,							__UpperCamelCase		,							)
class 							snake_case_       (    __UpperCamelCase      ):

						"""simple docstring"""



						def __init__(self:					List[Any] ,					__UpperCAmelCase:					Union[str, Any]   )    ->     Optional[Any]:




											'''simple docstring'''



											super().__init__(__UpperCAmelCase   )
											__a					:						str      =					config.num_labels
											__a					:						str      =					ResNetModel(__UpperCAmelCase   )
											# classification head
											__a					:						int      =					nn.Sequential(
											    nn.Flatten() ,					nn.Linear(config.hidden_sizes[-1] ,					config.num_labels   ) if config.num_labels > 0 else nn.Identity() ,					)
											# initialize weights and apply final processing
											self.post_init()



						@add_start_docstrings_to_model_forward(__UpperCAmelCase   )
						@add_code_sample_docstrings(
						    checkpoint=_IMAGE_CLASS_CHECKPOINT ,					output_type=__UpperCAmelCase ,					config_class=_CONFIG_FOR_DOC ,					expected_output=_IMAGE_CLASS_EXPECTED_OUTPUT ,					)
						def        UpperCAmelCase__					(self:					int ,					__UpperCAmelCase:					Optional[torch.FloatTensor] = None ,					__UpperCAmelCase:					Optional[torch.LongTensor] = None ,					__UpperCAmelCase:					Optional[bool] = None ,					__UpperCAmelCase:					Optional[bool] = None ,					)    ->     ImageClassifierOutputWithNoAttention:




											'''simple docstring'''



											__a					:						Optional[int]      =					return_dict if return_dict is not None else self.config.use_return_dict

											__a					:						Any      =					self.resnet(__UpperCAmelCase ,					output_hidden_states=__UpperCAmelCase ,					return_dict=__UpperCAmelCase   )

											__a					:						Optional[Any]      =					outputs.pooler_output if return_dict else outputs[1]

											__a					:						Tuple      =					self.classifier(__UpperCAmelCase   )

											__a					:						str      =					None

											if labels is not None:
																if self.config.problem_type is None:
																					if self.num_labels == 1:
																										__a					:						str      =					"regression"
																					elif self.num_labels > 1 and (labels.dtype == torch.long or labels.dtype == torch.int):
																										__a					:						Dict      =					"single_label_classification"
																					else:
																										__a					:						Optional[int]      =					"multi_label_classification"
																if self.config.problem_type == "regression":
																					__a					:						Optional[int]      =					MSELoss()
																					if self.num_labels == 1:
																										__a					:						Any      =					loss_fct(logits.squeeze() ,					labels.squeeze()   )
																					else:
																										__a					:						Union[str, Any]      =					loss_fct(__UpperCAmelCase ,					__UpperCAmelCase   )
																elif self.config.problem_type == "single_label_classification":
																					__a					:						str      =					CrossEntropyLoss()
																					__a					:						int      =					loss_fct(logits.view(-1 ,					self.num_labels   ) ,					labels.view(-1   )   )
																elif self.config.problem_type == "multi_label_classification":
																					__a					:						Optional[Any]      =					BCEWithLogitsLoss()
																					__a					:						str      =					loss_fct(__UpperCAmelCase ,					__UpperCAmelCase   )

											if not return_dict:
																__a					:						Any      =					(logits,) + outputs[2:]
																return (loss,) + output if loss is not None else output

											return ImageClassifierOutputWithNoAttention(loss=__UpperCAmelCase ,					logits=__UpperCAmelCase ,					hidden_states=outputs.hidden_states   )




@add_start_docstrings(
    """
    ResNet backbone, to be used with frameworks like DETR and MaskFormer.
    """		,							__UpperCamelCase		,							)
class 							snake_case_       (    __UpperCamelCase		,							__UpperCamelCase      ):

						"""simple docstring"""



						def __init__(self:					List[str] ,					__UpperCAmelCase:					Tuple   )    ->     Optional[Any]:




											'''simple docstring'''



											super().__init__(__UpperCAmelCase   )
											super()._init_backbone(__UpperCAmelCase   )

											__a					:						Any      =					[config.embedding_size] + config.hidden_sizes
											__a					:						int      =					ResNetEmbeddings(__UpperCAmelCase   )
											__a					:						Any      =					ResNetEncoder(__UpperCAmelCase   )

											# initialize weights and apply final processing
											self.post_init()



						@add_start_docstrings_to_model_forward(__UpperCAmelCase   )
						@replace_return_docstrings(output_type=__UpperCAmelCase ,					config_class=_CONFIG_FOR_DOC   )
						def        UpperCAmelCase__					(self:					Any ,					__UpperCAmelCase:					Tensor ,					__UpperCAmelCase:					Optional[bool] = None ,					__UpperCAmelCase:					Optional[bool] = None   )    ->     BackboneOutput:




											'''simple docstring'''



											__a					:						Optional[Any]      =					return_dict if return_dict is not None else self.config.use_return_dict
											__a					:						List[Any]      =					(
											    output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
											)

											__a					:						Dict      =					self.embedder(__UpperCAmelCase   )

											__a					:						Optional[int]      =					self.encoder(__UpperCAmelCase ,					output_hidden_states=__UpperCAmelCase ,					return_dict=__UpperCAmelCase   )

											__a					:						List[str]      =					outputs.hidden_states

											__a					:						Any      =					()
											for idx, stage in enumerate(self.stage_names   ):
																if stage in self.out_features:
																					feature_maps += (hidden_states[idx],)

											if not return_dict:
																__a					:						str      =					(feature_maps,)
																if output_hidden_states:
																					output += (outputs.hidden_states,)
																return output

											return BackboneOutput(
											    feature_maps=__UpperCAmelCase ,					hidden_states=outputs.hidden_states if output_hidden_states else None ,					attentions=__UpperCAmelCase ,					)













import os
from shutil import copyfile
from typing import List, Optional, Tuple

from tokenizers import processors

from ...tokenization_utils import AddedToken, BatchEncoding
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import is_sentencepiece_available, logging


if is_sentencepiece_available():
			from .tokenization_nllb import NllbTokenizer
else:
			UpperCAmelCase__      			=						None


UpperCAmelCase__      			=						logging.get_logger(__name__)


UpperCAmelCase__      			=						{'''vocab_file''': '''sentencepiece.bpe.model''', '''tokenizer_file''': '''tokenizer.json'''}

UpperCAmelCase__      			=						{
    '''vocab_file''': {
        '''facebook/nllb-200-distilled-600M''': (
            '''https://huggingface.co/facebook/nllb-200-distilled-600M/resolve/main/sentencepiece.bpe.model'''
        ),
    },
    '''tokenizer_file''': {
        '''facebook/nllb-200-distilled-600M''': (
            '''https://huggingface.co/facebook/nllb-200-distilled-600M/resolve/main/tokenizer.json'''
        ),
    },
}

UpperCAmelCase__      			=						{
    '''facebook/nllb-large-en-ro''': 1024,
    '''facebook/nllb-200-distilled-600M''': 1024,
}

# fmt: off
UpperCAmelCase__      			=						['''ace_Arab''', '''ace_Latn''', '''acm_Arab''', '''acq_Arab''', '''aeb_Arab''', '''afr_Latn''', '''ajp_Arab''', '''aka_Latn''', '''amh_Ethi''', '''apc_Arab''', '''arb_Arab''', '''ars_Arab''', '''ary_Arab''', '''arz_Arab''', '''asm_Beng''', '''ast_Latn''', '''awa_Deva''', '''ayr_Latn''', '''azb_Arab''', '''azj_Latn''', '''bak_Cyrl''', '''bam_Latn''', '''ban_Latn''', '''bel_Cyrl''', '''bem_Latn''', '''ben_Beng''', '''bho_Deva''', '''bjn_Arab''', '''bjn_Latn''', '''bod_Tibt''', '''bos_Latn''', '''bug_Latn''', '''bul_Cyrl''', '''cat_Latn''', '''ceb_Latn''', '''ces_Latn''', '''cjk_Latn''', '''ckb_Arab''', '''crh_Latn''', '''cym_Latn''', '''dan_Latn''', '''deu_Latn''', '''dik_Latn''', '''dyu_Latn''', '''dzo_Tibt''', '''ell_Grek''', '''eng_Latn''', '''epo_Latn''', '''est_Latn''', '''eus_Latn''', '''ewe_Latn''', '''fao_Latn''', '''pes_Arab''', '''fij_Latn''', '''fin_Latn''', '''fon_Latn''', '''fra_Latn''', '''fur_Latn''', '''fuv_Latn''', '''gla_Latn''', '''gle_Latn''', '''glg_Latn''', '''grn_Latn''', '''guj_Gujr''', '''hat_Latn''', '''hau_Latn''', '''heb_Hebr''', '''hin_Deva''', '''hne_Deva''', '''hrv_Latn''', '''hun_Latn''', '''hye_Armn''', '''ibo_Latn''', '''ilo_Latn''', '''ind_Latn''', '''isl_Latn''', '''ita_Latn''', '''jav_Latn''', '''jpn_Jpan''', '''kab_Latn''', '''kac_Latn''', '''kam_Latn''', '''kan_Knda''', '''kas_Arab''', '''kas_Deva''', '''kat_Geor''', '''knc_Arab''', '''knc_Latn''', '''kaz_Cyrl''', '''kbp_Latn''', '''kea_Latn''', '''khm_Khmr''', '''kik_Latn''', '''kin_Latn''', '''kir_Cyrl''', '''kmb_Latn''', '''kon_Latn''', '''kor_Hang''', '''kmr_Latn''', '''lao_Laoo''', '''lvs_Latn''', '''lij_Latn''', '''lim_Latn''', '''lin_Latn''', '''lit_Latn''', '''lmo_Latn''', '''ltg_Latn''', '''ltz_Latn''', '''lua_Latn''', '''lug_Latn''', '''luo_Latn''', '''lus_Latn''', '''mag_Deva''', '''mai_Deva''', '''mal_Mlym''', '''mar_Deva''', '''min_Latn''', '''mkd_Cyrl''', '''plt_Latn''', '''mlt_Latn''', '''mni_Beng''', '''khk_Cyrl''', '''mos_Latn''', '''mri_Latn''', '''zsm_Latn''', '''mya_Mymr''', '''nld_Latn''', '''nno_Latn''', '''nob_Latn''', '''npi_Deva''', '''nso_Latn''', '''nus_Latn''', '''nya_Latn''', '''oci_Latn''', '''gaz_Latn''', '''ory_Orya''', '''pag_Latn''', '''pan_Guru''', '''pap_Latn''', '''pol_Latn''', '''por_Latn''', '''prs_Arab''', '''pbt_Arab''', '''quy_Latn''', '''ron_Latn''', '''run_Latn''', '''rus_Cyrl''', '''sag_Latn''', '''san_Deva''', '''sat_Beng''', '''scn_Latn''', '''shn_Mymr''', '''sin_Sinh''', '''slk_Latn''', '''slv_Latn''', '''smo_Latn''', '''sna_Latn''', '''snd_Arab''', '''som_Latn''', '''sot_Latn''', '''spa_Latn''', '''als_Latn''', '''srd_Latn''', '''srp_Cyrl''', '''ssw_Latn''', '''sun_Latn''', '''swe_Latn''', '''swh_Latn''', '''szl_Latn''', '''tam_Taml''', '''tat_Cyrl''', '''tel_Telu''', '''tgk_Cyrl''', '''tgl_Latn''', '''tha_Thai''', '''tir_Ethi''', '''taq_Latn''', '''taq_Tfng''', '''tpi_Latn''', '''tsn_Latn''', '''tso_Latn''', '''tuk_Latn''', '''tum_Latn''', '''tur_Latn''', '''twi_Latn''', '''tzm_Tfng''', '''uig_Arab''', '''ukr_Cyrl''', '''umb_Latn''', '''urd_Arab''', '''uzn_Latn''', '''vec_Latn''', '''vie_Latn''', '''war_Latn''', '''wol_Latn''', '''xho_Latn''', '''ydd_Hebr''', '''yor_Latn''', '''yue_Hant''', '''zho_Hans''', '''zho_Hant''', '''zul_Latn''']




class 							snake_case_       (    __UpperCamelCase      ):

						"""simple docstring"""



						snake_case__        =      VOCAB_FILES_NAMES
						snake_case__        =      PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
						snake_case__        =      PRETRAINED_VOCAB_FILES_MAP
						snake_case__        =      ["""input_ids""", """attention_mask"""]
						snake_case__        =      NllbTokenizer

						snake_case__        =      []
						snake_case__        =      []



						def __init__(self:					Optional[Any] ,					__UpperCAmelCase:					Union[str, Any]=None ,					__UpperCAmelCase:					List[Any]=None ,					__UpperCAmelCase:					Union[str, Any]="<s>" ,					__UpperCAmelCase:					Tuple="</s>" ,					__UpperCAmelCase:					Optional[Any]="</s>" ,					__UpperCAmelCase:					Tuple="<s>" ,					__UpperCAmelCase:					Optional[Any]="<unk>" ,					__UpperCAmelCase:					Dict="<pad>" ,					__UpperCAmelCase:					Any="<mask>" ,					__UpperCAmelCase:					Dict=None ,					__UpperCAmelCase:					Optional[Any]=None ,					__UpperCAmelCase:					List[str]=None ,					__UpperCAmelCase:					List[str]=False ,					**__UpperCAmelCase:					Tuple ,					)    ->     Tuple:




											'''simple docstring'''



											__a					:						Dict      =					AddedToken(__UpperCAmelCase ,					lstrip=__UpperCAmelCase ,					rstrip=__UpperCAmelCase   ) if isinstance(__UpperCAmelCase ,					__UpperCAmelCase   ) else mask_token
											__a					:						List[str]      =					legacy_behaviour
											super().__init__(
											    vocab_file=__UpperCAmelCase ,					tokenizer_file=__UpperCAmelCase ,					bos_token=__UpperCAmelCase ,					eos_token=__UpperCAmelCase ,					sep_token=__UpperCAmelCase ,					cls_token=__UpperCAmelCase ,					unk_token=__UpperCAmelCase ,					pad_token=__UpperCAmelCase ,					mask_token=__UpperCAmelCase ,					src_lang=__UpperCAmelCase ,					tgt_lang=__UpperCAmelCase ,					additional_special_tokens=__UpperCAmelCase ,					legacy_behaviour=__UpperCAmelCase ,					**__UpperCAmelCase ,					)

											__a					:						Union[str, Any]      =					vocab_file
											__a					:						str      =					False if not self.vocab_file else True

											__a					:						Dict      =					FAIRSEQ_LANGUAGE_CODES.copy()

											if additional_special_tokens is not None:
																# Only add those special tokens if they are not already there.
																_additional_special_tokens.extend(
																    [t for t in additional_special_tokens if t not in _additional_special_tokens]   )

											self.add_special_tokens({"additional_special_tokens": _additional_special_tokens}   )
											__a					:						Optional[Any]      =					{
											    lang_code: self.convert_tokens_to_ids(__UpperCAmelCase   ) for lang_code in FAIRSEQ_LANGUAGE_CODES
											}

											__a					:						Dict      =					src_lang if src_lang is not None else "eng_Latn"
											__a					:						str      =					self.convert_tokens_to_ids(self._src_lang   )
											__a					:						Any      =					tgt_lang
											self.set_src_lang_special_tokens(self._src_lang   )



						@property
						def        UpperCAmelCase__					(self:					List[str]   )    ->     str:




											'''simple docstring'''



											return self._src_lang



						@src_lang.setter
						def        UpperCAmelCase__					(self:					List[str] ,					__UpperCAmelCase:					str   )    ->     None:




											'''simple docstring'''



											__a					:						Dict      =					new_src_lang
											self.set_src_lang_special_tokens(self._src_lang   )



						def        UpperCAmelCase__					(self:					Any ,					__UpperCAmelCase:					List[int] ,					__UpperCAmelCase:					Optional[List[int]] = None   )    ->     List[int]:




											'''simple docstring'''



											if token_ids_a is None:
																return self.prefix_tokens + token_ids_a + self.suffix_tokens
											# We don't expect to process pairs, but leave the pair logic for API consistency
											return self.prefix_tokens + token_ids_a + token_ids_a + self.suffix_tokens



						def        UpperCAmelCase__					(self:					List[str] ,					__UpperCAmelCase:					List[int] ,					__UpperCAmelCase:					Optional[List[int]] = None   )    ->     List[int]:




											'''simple docstring'''



											__a					:						int      =					[self.sep_token_id]
											__a					:						str      =					[self.cls_token_id]

											if token_ids_a is None:
																return len(cls + token_ids_a + sep   ) * [0]
											return len(cls + token_ids_a + sep + sep + token_ids_a + sep   ) * [0]



						def        UpperCAmelCase__					(self:					str ,					__UpperCAmelCase:					Dict ,					__UpperCAmelCase:					str ,					__UpperCAmelCase:					Optional[str] ,					__UpperCAmelCase:					Optional[str] ,					**__UpperCAmelCase:					Optional[int]   )    ->     int:




											'''simple docstring'''



											if src_lang is None or tgt_lang is None:
																raise ValueError("Translation requires a `src_lang` and a `tgt_lang` for this model"   )
											__a					:						Tuple      =					src_lang
											__a					:						Optional[Any]      =					self(__UpperCAmelCase ,					add_special_tokens=__UpperCAmelCase ,					return_tensors=__UpperCAmelCase ,					**__UpperCAmelCase   )
											__a					:						List[Any]      =					self.convert_tokens_to_ids(__UpperCAmelCase   )
											__a					:						List[Any]      =					tgt_lang_id
											return inputs



						def        UpperCAmelCase__					(self:					Optional[int] ,					__UpperCAmelCase:					List[str] ,					__UpperCAmelCase:					str = "eng_Latn" ,					__UpperCAmelCase:					Optional[List[str]] = None ,					__UpperCAmelCase:					str = "fra_Latn" ,					**__UpperCAmelCase:					Dict ,					)    ->     BatchEncoding:




											'''simple docstring'''



											__a					:						Optional[int]      =					src_lang
											__a					:						List[str]      =					tgt_lang
											return super().prepare_seqaseq_batch(__UpperCAmelCase ,					__UpperCAmelCase ,					**__UpperCAmelCase   )



						def        UpperCAmelCase__					(self:					List[Any]   )    ->     int:




											'''simple docstring'''



											return self.set_src_lang_special_tokens(self.src_lang   )



						def        UpperCAmelCase__					(self:					Union[str, Any]   )    ->     Union[str, Any]:




											'''simple docstring'''



											return self.set_tgt_lang_special_tokens(self.tgt_lang   )



						def        UpperCAmelCase__					(self:					Optional[int] ,					__UpperCAmelCase:					Union[str, Any]   )    ->     None:




											'''simple docstring'''



											__a					:						Optional[Any]      =					self.convert_tokens_to_ids(__UpperCAmelCase   )

											if self.legacy_behaviour:
																__a					:						Dict      =					[]
																__a					:						str      =					[self.eos_token_id, self.cur_lang_code]
											else:
																__a					:						Optional[Any]      =					[self.cur_lang_code]
																__a					:						Optional[int]      =					[self.eos_token_id]

											__a					:						Dict      =					self.convert_ids_to_tokens(self.prefix_tokens   )
											__a					:						List[Any]      =					self.convert_ids_to_tokens(self.suffix_tokens   )

											__a					:						int      =					processors.TemplateProcessing(
											    single=prefix_tokens_str + ["$A"] + suffix_tokens_str ,					pair=prefix_tokens_str + ["$A", "$B"] + suffix_tokens_str ,					special_tokens=list(zip(prefix_tokens_str + suffix_tokens_str ,					self.prefix_tokens + self.suffix_tokens   )   ) ,					)



						def        UpperCAmelCase__					(self:					str ,					__UpperCAmelCase:					str   )    ->     None:




											'''simple docstring'''



											__a					:						List[Any]      =					self.convert_tokens_to_ids(__UpperCAmelCase   )
											if self.legacy_behaviour:
																__a					:						Any      =					[]
																__a					:						Union[str, Any]      =					[self.eos_token_id, self.cur_lang_code]
											else:
																__a					:						Union[str, Any]      =					[self.cur_lang_code]
																__a					:						List[str]      =					[self.eos_token_id]

											__a					:						str      =					self.convert_ids_to_tokens(self.prefix_tokens   )
											__a					:						str      =					self.convert_ids_to_tokens(self.suffix_tokens   )

											__a					:						int      =					processors.TemplateProcessing(
											    single=prefix_tokens_str + ["$A"] + suffix_tokens_str ,					pair=prefix_tokens_str + ["$A", "$B"] + suffix_tokens_str ,					special_tokens=list(zip(prefix_tokens_str + suffix_tokens_str ,					self.prefix_tokens + self.suffix_tokens   )   ) ,					)



						def        UpperCAmelCase__					(self:					str ,					__UpperCAmelCase:					str ,					__UpperCAmelCase:					Optional[str] = None   )    ->     Tuple[str]:




											'''simple docstring'''



											if not self.can_save_slow_tokenizer:
																raise ValueError(
																    "Your fast tokenizer does not have the necessary information to save the vocabulary for a slow "
																    "tokenizer."   )

											if not os.path.isdir(__UpperCAmelCase   ):
																logger.error(f'Vocabulary path ({save_directory}) should be a directory.'   )
																return
											__a					:						Tuple      =					os.path.join(
											    __UpperCAmelCase ,					(filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["vocab_file"]   )

											if os.path.abspath(self.vocab_file   ) != os.path.abspath(__UpperCAmelCase   ):
																copyfile(self.vocab_file ,					__UpperCAmelCase   )

											return (out_vocab_file,)





