




'''simple docstring'''





from collections import OrderedDict
from typing import TYPE_CHECKING, Any, List, Mapping, Optional

from packaging import version


if TYPE_CHECKING:
   from ... import PreTrainedTokenizer, TensorType

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfigWithPast, PatchingSpec
from ...utils import is_torch_available, logging


UpperCamelCase_						:      Any       =						logging.get_logger(__name__)

UpperCamelCase_						:      List[Any]       =						{
    '''bigscience/bloom''': '''https://huggingface.co/bigscience/bloom/resolve/main/config.json''',
    '''bigscience/bloom-560m''': '''https://huggingface.co/bigscience/bloom-560m/blob/main/config.json''',
    '''bigscience/bloom-1b1''': '''https://huggingface.co/bigscience/bloom-1b1/blob/main/config.json''',
    '''bigscience/bloom-1b7''': '''https://huggingface.co/bigscience/bloom-1b7/blob/main/config.json''',
    '''bigscience/bloom-3b''': '''https://huggingface.co/bigscience/bloom-3b/blob/main/config.json''',
    '''bigscience/bloom-7b1''': '''https://huggingface.co/bigscience/bloom-7b1/blob/main/config.json''',
}

class        _a    (						__lowerCAmelCase							):
     SCREAMING_SNAKE_CASE_							:   str       =						"""bloom"""
     SCREAMING_SNAKE_CASE_							:   Dict       =						["""past_key_values"""]
     SCREAMING_SNAKE_CASE_							:   int       =						{
         """num_hidden_layers""": """n_layer""",
         """num_attention_heads""": """n_head""",
     }






     def __init__(			self ,_SCREAMING_SNAKE_CASE=250_880 ,_SCREAMING_SNAKE_CASE=64 ,_SCREAMING_SNAKE_CASE=2 ,_SCREAMING_SNAKE_CASE=8 ,_SCREAMING_SNAKE_CASE=1e-5 ,_SCREAMING_SNAKE_CASE=0.0_2 ,_SCREAMING_SNAKE_CASE=True ,_SCREAMING_SNAKE_CASE=1 ,_SCREAMING_SNAKE_CASE=2 ,_SCREAMING_SNAKE_CASE=False ,_SCREAMING_SNAKE_CASE=0.0 ,_SCREAMING_SNAKE_CASE=0.0 ,_SCREAMING_SNAKE_CASE=1 ,_SCREAMING_SNAKE_CASE=False ,**_SCREAMING_SNAKE_CASE ,)							->      Any:
          _snake_case							=				vocab_size
          # Backward compatibility with n_embed kwarg
          _snake_case							=				kwargs.pop("n_embed" ,_SCREAMING_SNAKE_CASE   )
          _snake_case							=				hidden_size if n_embed is None else n_embed
          _snake_case							=				n_layer
          _snake_case							=				n_head
          _snake_case							=				layer_norm_epsilon
          _snake_case							=				initializer_range
          _snake_case							=				use_cache
          _snake_case							=				pretraining_tp
          _snake_case							=				apply_residual_connection_post_layernorm
          _snake_case							=				hidden_dropout
          _snake_case							=				attention_dropout

          _snake_case							=				bos_token_id
          _snake_case							=				eos_token_id
          _snake_case							=				slow_but_exact

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







class        _a    (						__lowerCAmelCase							):
     SCREAMING_SNAKE_CASE_							:   List[Any]       =						version.parse("""1.12"""							)






     def __init__(			self ,_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE = "default" ,_SCREAMING_SNAKE_CASE = None ,_SCREAMING_SNAKE_CASE = False ,)							->      int:
          super().__init__(_SCREAMING_SNAKE_CASE ,task=_SCREAMING_SNAKE_CASE ,patching_specs=_SCREAMING_SNAKE_CASE ,use_past=_SCREAMING_SNAKE_CASE   )
          if not getattr(self._config ,"pad_token_id" ,_SCREAMING_SNAKE_CASE   ):
               # TODO: how to do that better?
               _snake_case							=				0






     @property
     def     _lowercase     (			self   )							->      Mapping[str, Mapping[int, str]]:
          _snake_case							=				OrderedDict({"input_ids": {0: "batch", 1: "sequence"}}   )
          if self.use_past:
               # BLOOM stores values on dynamic axis 2. For more details see: https://github.com/huggingface/transformers/pull/18344
               self.fill_with_past_key_values_(_SCREAMING_SNAKE_CASE ,direction="inputs" ,inverted_values_shape=_SCREAMING_SNAKE_CASE   )
               _snake_case							=				{0: "batch", 1: "past_sequence + sequence"}
          else:
               _snake_case							=				{0: "batch", 1: "sequence"}

          return common_inputs






     @property
     def     _lowercase     (			self   )							->      int:
          return self._config.n_layer






     @property
     def     _lowercase     (			self   )							->      int:
          return self._config.n_head






     @property
     def     _lowercase     (			self   )							->      float:
          return 1e-3






     def     _lowercase     (			self ,_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE = -1 ,_SCREAMING_SNAKE_CASE = -1 ,_SCREAMING_SNAKE_CASE = False ,_SCREAMING_SNAKE_CASE = None ,)							->      Mapping[str, Any]:
          _snake_case							=				super(_SCREAMING_SNAKE_CASE ,self   ).generate_dummy_inputs(
              _SCREAMING_SNAKE_CASE ,batch_size=_SCREAMING_SNAKE_CASE ,seq_length=_SCREAMING_SNAKE_CASE ,is_pair=_SCREAMING_SNAKE_CASE ,framework=_SCREAMING_SNAKE_CASE   )

          # We need to order the input in the way they appears in the forward()
          _snake_case							=				OrderedDict({"input_ids": common_inputs["input_ids"]}   )

          # Need to add the past_keys
          if self.use_past:
               if not is_torch_available():
                    raise ValueError("Cannot generate dummy past_keys inputs without PyTorch installed."   )
               else:
                    import torch

                    _snake_case							, _snake_case							=				common_inputs["input_ids"].shape
                    # Not using the same length for past_key_values
                    _snake_case							=				seqlen + 2
                    _snake_case							=				self._config.hidden_size // self.num_attention_heads
                    _snake_case							=				(
                        batch * self.num_attention_heads,
                        head_dim,
                        past_key_values_length,
                    )
                    _snake_case							=				(
                        batch * self.num_attention_heads,
                        past_key_values_length,
                        head_dim,
                    )
                    _snake_case							=				[
                        (torch.zeros(_SCREAMING_SNAKE_CASE   ), torch.zeros(_SCREAMING_SNAKE_CASE   )) for _ in range(self.num_layers   )
                    ]

          _snake_case							=				common_inputs["attention_mask"]
          if self.use_past:
               _snake_case							=				ordered_inputs["attention_mask"].dtype
               _snake_case							=				torch.cat(
                   [ordered_inputs["attention_mask"], torch.ones(_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE ,dtype=_SCREAMING_SNAKE_CASE   )] ,dim=1   )

          return ordered_inputs






     @property
     def     _lowercase     (			self   )							->      int:
          return 13








'''simple docstring'''





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

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


if is_sentencepiece_available():
   from .tokenization_big_bird import BigBirdTokenizer
else:
   UpperCamelCase_						:      List[Any]       =						None

UpperCamelCase_						:      Tuple       =						logging.get_logger(__name__)
UpperCamelCase_						:      Any       =						{'''vocab_file''': '''spiece.model''', '''tokenizer_file''': '''tokenizer.json'''}

UpperCamelCase_						:      Any       =						{
    '''vocab_file''': {
        '''google/bigbird-roberta-base''': '''https://huggingface.co/google/bigbird-roberta-base/resolve/main/spiece.model''',
        '''google/bigbird-roberta-large''': (
            '''https://huggingface.co/google/bigbird-roberta-large/resolve/main/spiece.model'''
        ),
        '''google/bigbird-base-trivia-itc''': (
            '''https://huggingface.co/google/bigbird-base-trivia-itc/resolve/main/spiece.model'''
        ),
    },
    '''tokenizer_file''': {
        '''google/bigbird-roberta-base''': (
            '''https://huggingface.co/google/bigbird-roberta-base/resolve/main/tokenizer.json'''
        ),
        '''google/bigbird-roberta-large''': (
            '''https://huggingface.co/google/bigbird-roberta-large/resolve/main/tokenizer.json'''
        ),
        '''google/bigbird-base-trivia-itc''': (
            '''https://huggingface.co/google/bigbird-base-trivia-itc/resolve/main/tokenizer.json'''
        ),
    },
}

UpperCamelCase_						:      Optional[int]       =						{
    '''google/bigbird-roberta-base''': 4096,
    '''google/bigbird-roberta-large''': 4096,
    '''google/bigbird-base-trivia-itc''': 4096,
}


UpperCamelCase_						:      List[str]       =						'''▁'''

class        _a    (						__lowerCAmelCase							):
     SCREAMING_SNAKE_CASE_							:   List[Any]       =						VOCAB_FILES_NAMES
     SCREAMING_SNAKE_CASE_							:   List[Any]       =						PRETRAINED_VOCAB_FILES_MAP
     SCREAMING_SNAKE_CASE_							:   Any       =						PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
     SCREAMING_SNAKE_CASE_							:   str       =						BigBirdTokenizer
     SCREAMING_SNAKE_CASE_							:   Tuple       =						["""input_ids""", """attention_mask"""]
     SCREAMING_SNAKE_CASE_							:   List[int]       =						[]






     def __init__(			self ,_SCREAMING_SNAKE_CASE=None ,_SCREAMING_SNAKE_CASE=None ,_SCREAMING_SNAKE_CASE="<unk>" ,_SCREAMING_SNAKE_CASE="<s>" ,_SCREAMING_SNAKE_CASE="</s>" ,_SCREAMING_SNAKE_CASE="<pad>" ,_SCREAMING_SNAKE_CASE="[SEP]" ,_SCREAMING_SNAKE_CASE="[MASK]" ,_SCREAMING_SNAKE_CASE="[CLS]" ,**_SCREAMING_SNAKE_CASE ,)							->      Dict:
          _snake_case							=				AddedToken(_SCREAMING_SNAKE_CASE ,lstrip=_SCREAMING_SNAKE_CASE ,rstrip=_SCREAMING_SNAKE_CASE   ) if isinstance(_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE   ) else bos_token
          _snake_case							=				AddedToken(_SCREAMING_SNAKE_CASE ,lstrip=_SCREAMING_SNAKE_CASE ,rstrip=_SCREAMING_SNAKE_CASE   ) if isinstance(_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE   ) else eos_token
          _snake_case							=				AddedToken(_SCREAMING_SNAKE_CASE ,lstrip=_SCREAMING_SNAKE_CASE ,rstrip=_SCREAMING_SNAKE_CASE   ) if isinstance(_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE   ) else unk_token
          _snake_case							=				AddedToken(_SCREAMING_SNAKE_CASE ,lstrip=_SCREAMING_SNAKE_CASE ,rstrip=_SCREAMING_SNAKE_CASE   ) if isinstance(_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE   ) else pad_token
          _snake_case							=				AddedToken(_SCREAMING_SNAKE_CASE ,lstrip=_SCREAMING_SNAKE_CASE ,rstrip=_SCREAMING_SNAKE_CASE   ) if isinstance(_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE   ) else cls_token
          _snake_case							=				AddedToken(_SCREAMING_SNAKE_CASE ,lstrip=_SCREAMING_SNAKE_CASE ,rstrip=_SCREAMING_SNAKE_CASE   ) if isinstance(_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE   ) else sep_token

          # Mask token behave like a normal word, i.e. include the space before it
          _snake_case							=				AddedToken(_SCREAMING_SNAKE_CASE ,lstrip=_SCREAMING_SNAKE_CASE ,rstrip=_SCREAMING_SNAKE_CASE   ) if isinstance(_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE   ) else mask_token

          super().__init__(
              _SCREAMING_SNAKE_CASE ,tokenizer_file=_SCREAMING_SNAKE_CASE ,bos_token=_SCREAMING_SNAKE_CASE ,eos_token=_SCREAMING_SNAKE_CASE ,unk_token=_SCREAMING_SNAKE_CASE ,sep_token=_SCREAMING_SNAKE_CASE ,pad_token=_SCREAMING_SNAKE_CASE ,cls_token=_SCREAMING_SNAKE_CASE ,mask_token=_SCREAMING_SNAKE_CASE ,**_SCREAMING_SNAKE_CASE ,)

          _snake_case							=				vocab_file
          _snake_case							=				False if not self.vocab_file else True






     def     _lowercase     (			self ,_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE = None   )							->      List[int]:
          _snake_case							=				[self.sep_token_id]
          _snake_case							=				[self.cls_token_id]
          if token_ids_a is None:
               return cls + token_ids_a + sep
          return cls + token_ids_a + sep + token_ids_a + sep






     def     _lowercase     (			self ,_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE = None ,_SCREAMING_SNAKE_CASE = False   )							->      List[int]:

          if already_has_special_tokens:
               if token_ids_a is not None:
                    raise ValueError(
                        "You should not supply a second sequence if the provided sequence of "
                        "ids is already formatted with special tokens for the model."   )
               return [1 if x in [self.sep_token_id, self.cls_token_id] else 0 for x in token_ids_a]

          if token_ids_a is None:
               return [1] + ([0] * len(_SCREAMING_SNAKE_CASE   )) + [1]
          return [1] + ([0] * len(_SCREAMING_SNAKE_CASE   )) + [1] + ([0] * len(_SCREAMING_SNAKE_CASE   )) + [1]






     def     _lowercase     (			self ,_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE = None   )							->      List[int]:
          _snake_case							=				[self.sep_token_id]
          _snake_case							=				[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   ) * [0] + len(token_ids_a + sep   ) * [1]






     def     _lowercase     (			self ,_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE = None   )							->      Tuple[str]:
          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(_SCREAMING_SNAKE_CASE   ):
               logger.error(f"""Vocabulary path ({save_directory}) should be a directory"""   )
               return
          _snake_case							=				os.path.join(
              _SCREAMING_SNAKE_CASE ,(filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["vocab_file"]   )

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

          return (out_vocab_file,)


