






'''simple docstring'''



import json
import os
from pathlib import Path
from shutil import copyfile
from typing import Any, Dict, List, Optional, Tuple, Union

import sentencepiece

from ...tokenization_utils import PreTrainedTokenizer
from ...utils import logging


__UpperCamelCase   :							Optional[int]         =   logging.get_logger(__name__)

__UpperCamelCase   :							List[Any]         =   """▁"""

__UpperCamelCase   :							str         =   {
    """vocab_file""": """vocab.json""",
    """spm_file""": """sentencepiece.bpe.model""",
}

__UpperCamelCase   :							Optional[Any]         =   {
    """vocab_file""": {
        """facebook/s2t-small-librispeech-asr""": (
            """https://huggingface.co/facebook/s2t-small-librispeech-asr/resolve/main/vocab.json"""
        ),
    },
    """spm_file""": {
        """facebook/s2t-small-librispeech-asr""": (
            """https://huggingface.co/facebook/s2t-small-librispeech-asr/resolve/main/sentencepiece.bpe.model"""
        )
    },
}

__UpperCamelCase   :							Union[str, Any]         =   {
    """facebook/s2t-small-librispeech-asr""": 1024,
}

__UpperCamelCase   :							Optional[int]         =   ["""pt""", """fr""", """ru""", """nl""", """ro""", """it""", """es""", """de"""]

__UpperCamelCase   :							Tuple         =   {"""mustc""": MUSTC_LANGS}
class 				__SCREAMING_SNAKE_CASE							(				__SCREAMING_SNAKE_CASE  ):
      __a	       =VOCAB_FILES_NAMES
      __a	       =PRETRAINED_VOCAB_FILES_MAP
      __a	       =MAX_MODEL_INPUT_SIZES
      __a	       =["""input_ids""", """attention_mask"""]

      __a	       =[]




      def __init__(	self			, lowerCamelCase			, lowerCamelCase			, lowerCamelCase="<s>"			, lowerCamelCase="</s>"			, lowerCamelCase="<pad>"			, lowerCamelCase="<unk>"			, lowerCamelCase=False			, lowerCamelCase=False			, lowerCamelCase=None			, lowerCamelCase=None			, lowerCamelCase = None			, **lowerCamelCase			, )				->Tuple:



         '''simple docstring'''
         __a					  =     {} if sp_model_kwargs is None else sp_model_kwargs

         super().__init__(
             bos_token=_A			, eos_token=_A			, unk_token=_A			, pad_token=_A			, do_upper_case=_A			, do_lower_case=_A			, tgt_lang=_A			, lang_codes=_A			, sp_model_kwargs=self.sp_model_kwargs			, **_A			, )
         __a					  =     do_upper_case
         __a					  =     do_lower_case

         __a					  =     load_json(_A   )
         __a					  =     {v: k for k, v in self.encoder.items()}
         __a					  =     spm_file
         __a					  =     load_spm(_A			, self.sp_model_kwargs   )

         if lang_codes is not None:
            __a					  =     lang_codes
            __a					  =     LANGUAGES[lang_codes]
            __a					  =     [F"""<lang:{lang}>""" for lang in self.langs]
            __a					  =     {lang: self.sp_model.PieceToId(F"""<lang:{lang}>"""   ) for lang in self.langs}

            __a					  =     self.lang_tokens
            __a					  =     tgt_lang if tgt_lang is not None else self.langs[0]

            self.set_tgt_lang_special_tokens(self._tgt_lang   )
         else:
            __a					  =     {}




      @property
      def 			__UpperCamelCase				(	self   )				->Any:



         '''simple docstring'''
         return len(self.encoder   )




      @property
      def 			__UpperCamelCase				(	self   )				->List[Any]:



         '''simple docstring'''
         return self._tgt_lang




      @tgt_lang.setter
      def 			__UpperCamelCase				(	self			, lowerCamelCase   )				->List[Any]:



         '''simple docstring'''
         __a					  =     new_tgt_lang
         self.set_tgt_lang_special_tokens(_A   )




      def 			__UpperCamelCase				(	self			, lowerCamelCase   )				->List[Any]:



         '''simple docstring'''
         __a					  =     self.lang_code_to_id[tgt_lang]
         __a					  =     [lang_code_id]




      def 			__UpperCamelCase				(	self			, lowerCamelCase   )				->int:



         '''simple docstring'''
         return self.sp_model.encode(_A			, out_type=_A   )




      def 			__UpperCamelCase				(	self			, lowerCamelCase   )				->Optional[Any]:



         '''simple docstring'''
         return self.encoder.get(_A			, self.encoder[self.unk_token]   )




      def 			__UpperCamelCase				(	self			, lowerCamelCase   )				->str:



         '''simple docstring'''
         return self.decoder.get(_A			, self.unk_token   )




      def 			__UpperCamelCase				(	self			, lowerCamelCase   )				->List[Any]:



         '''simple docstring'''
         __a					  =     []
         __a					  =     """"""
         for token in tokens:
            # make sure that special tokens are not decoded using sentencepiece model
            if token in self.all_special_tokens:
               __a					  =     self.sp_model.decode(_A   )
               out_string += (decoded.upper() if self.do_upper_case else decoded) + token + " "
               __a					  =     []
            else:
               current_sub_tokens.append(_A   )
         __a					  =     self.sp_model.decode(_A   )
         out_string += decoded.upper() if self.do_upper_case else decoded
         return out_string.strip()




      def 			__UpperCamelCase				(	self			, lowerCamelCase			, lowerCamelCase=None   )				->Optional[Any]:



         '''simple docstring'''







         if token_ids_a is None:
            return self.prefix_tokens + token_ids_a + [self.eos_token_id]
         # 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.eos_token_id]




      def 			__UpperCamelCase				(	self			, lowerCamelCase			, lowerCamelCase = None			, lowerCamelCase = False   )				->List[Any]:



         '''simple docstring'''







         if already_has_special_tokens:
            return super().get_special_tokens_mask(
                token_ids_a=_A			, token_ids_a=_A			, already_has_special_tokens=_A   )

         __a					  =     [1] * len(self.prefix_tokens   )
         __a					  =     [1]
         if token_ids_a is None:
            return prefix_ones + ([0] * len(_A   )) + suffix_ones
         return prefix_ones + ([0] * len(_A   )) + ([0] * len(_A   )) + suffix_ones




      def 			__UpperCamelCase				(	self   )				->Any:



         '''simple docstring'''
         __a					  =     self.encoder.copy()
         vocab.update(self.added_tokens_encoder   )
         return vocab




      def __getstate__(	self   )				->Optional[int]:



         '''simple docstring'''
         __a					  =     self.__dict__.copy()
         __a					  =     None
         return state




      def __setstate__(	self			, lowerCamelCase   )				->Any:



         '''simple docstring'''
         __a					  =     d

         # for backward compatibility
         if not hasattr(self			, 'sp_model_kwargs'   ):
            __a					  =     {}

         __a					  =     load_spm(self.spm_file			, self.sp_model_kwargs   )






      def 			__UpperCamelCase				(	self			, lowerCamelCase			, lowerCamelCase = None   )				->Optional[Any]:



         '''simple docstring'''
         __a					  =     Path(_A   )
         assert save_dir.is_dir(), F"""{save_directory} should be a directory"""
         __a					  =     save_dir / (
             (filename_prefix + """-""" if filename_prefix else """""") + self.vocab_files_names["""vocab_file"""]
         )
         __a					  =     save_dir / (
             (filename_prefix + """-""" if filename_prefix else """""") + self.vocab_files_names["""spm_file"""]
         )

         save_json(self.encoder			, _A   )

         if os.path.abspath(self.spm_file   ) != os.path.abspath(_A   ) and os.path.isfile(self.spm_file   ):
            copyfile(self.spm_file			, _A   )
         elif not os.path.isfile(self.spm_file   ):
            with open(_A			, 'wb'   ) as fi:
               __a					  =     self.sp_model.serialized_model_proto()
               fi.write(_A   )

         return (str(_A   ), str(_A   ))







def  __UpperCAmelCase						(					SCREAMING_SNAKE_CASE__:						Any,       SCREAMING_SNAKE_CASE__:						int     )	->      Union[str, Any]:

   """simple docstring"""
   __a					  =     sentencepiece.SentencePieceProcessor(**SCREAMING_SNAKE_CASE__     )
   spm.Load(str(SCREAMING_SNAKE_CASE__     )     )
   return spm



def  __UpperCAmelCase						(					SCREAMING_SNAKE_CASE__:						Optional[Any]     )	->      List[str]:

   """simple docstring"""
   with open(SCREAMING_SNAKE_CASE__,       'r'     ) as f:
      return json.load(SCREAMING_SNAKE_CASE__     )



def  __UpperCAmelCase						(					SCREAMING_SNAKE_CASE__:						Tuple,       SCREAMING_SNAKE_CASE__:						Union[str, Any]     )	->      int:

   """simple docstring"""
   with open(SCREAMING_SNAKE_CASE__,       'w'     ) as f:
      json.dump(SCREAMING_SNAKE_CASE__,       SCREAMING_SNAKE_CASE__,       indent=2     )






"""simple docstring"""


from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


__magic_name__       :					Any						=			logging.get_logger(__name__)

__magic_name__       :					int						=			{
    """facebook/convnextv2-tiny-1k-224""": """https://huggingface.co/facebook/convnextv2-tiny-1k-224/resolve/main/config.json""",
}






class 							lowercase__			(   __SCREAMING_SNAKE_CASE					,     __SCREAMING_SNAKE_CASE	):

			"""simple docstring"""
			__lowerCAmelCase     :				str										=  """convnextv2"""







			def __init__(      self						,   _A=3						,   _A=4						,   _A=4						,   _A=None						,   _A=None						,   _A="gelu"						,   _A=0.02						,   _A=1e-1_2						,   _A=0.0						,   _A=2_2_4						,   _A=None						,   _A=None						,   **_A						,   ):






									'''simple docstring'''







									super().__init__(**_A    )

									UpperCamelCase				:		Optional[Any]				   =			num_channels
									UpperCamelCase				:		int				   =			patch_size
									UpperCamelCase				:		Dict				   =			num_stages
									UpperCamelCase				:		Tuple				   =			[9_6, 1_9_2, 3_8_4, 7_6_8] if hidden_sizes is None else hidden_sizes
									UpperCamelCase				:		str				   =			[3, 3, 9, 3] if depths is None else depths
									UpperCamelCase				:		List[str]				   =			hidden_act
									UpperCamelCase				:		List[str]				   =			initializer_range
									UpperCamelCase				:		List[Any]				   =			layer_norm_eps
									UpperCamelCase				:		Any				   =			drop_path_rate
									UpperCamelCase				:		Any				   =			image_size
									UpperCamelCase				:		Union[str, Any]				   =			["""stem"""] + [f"""stage{idx}""" for idx in range(1						,   len(self.depths    ) + 1    )]
									UpperCamelCase   ,						UpperCamelCase				:		Optional[int]				   =			get_aligned_output_features_output_indices(
									    out_features=_A						,   out_indices=_A						,   stage_names=self.stage_names    )



