



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


_lowerCamelCase	:       Tuple      	=	logging.get_logger(__name__)

_lowerCamelCase	:       str      	=	{
    "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  SCREAMING_SNAKE_CASE (  a__		):






    """simple docstring"""





    _SCREAMING_SNAKE_CASE	  =  "bloom"
    _SCREAMING_SNAKE_CASE	  =  ["past_key_values"]
    _SCREAMING_SNAKE_CASE	  =  {
        "num_hidden_layers": "n_layer",
        "num_attention_heads": "n_head",
    }






    def __init__(  self      :					int  ,						UpperCamelCase__      :					List[str]=2_5_0_8_8_0  ,						UpperCamelCase__      :					int=6_4  ,						UpperCamelCase__      :					Optional[Any]=2  ,						UpperCamelCase__      :					Optional[int]=8  ,						UpperCamelCase__      :					List[Any]=1E-5  ,						UpperCamelCase__      :					Any=0.0_2  ,						UpperCamelCase__      :					str=True  ,						UpperCamelCase__      :					int=1  ,						UpperCamelCase__      :					Any=2  ,						UpperCamelCase__      :					Union[str, Any]=False  ,						UpperCamelCase__      :					Optional[Any]=0.0  ,						UpperCamelCase__      :					Optional[Any]=0.0  ,						UpperCamelCase__      :					Any=1  ,						UpperCamelCase__      :					Tuple=False  ,						**UpperCamelCase__      :					int  ,						):


       """simple docstring"""







       UpperCamelCase					=  vocab_size
       # Backward compatibility with n_embed kwarg
       UpperCamelCase					=  kwargs.pop('n_embed'  ,						SCREAMING_SNAKE_CASE_ )
       UpperCamelCase					=  hidden_size if n_embed is None else n_embed
       UpperCamelCase					=  n_layer
       UpperCamelCase					=  n_head
       UpperCamelCase					=  layer_norm_epsilon
       UpperCamelCase					=  initializer_range
       UpperCamelCase					=  use_cache
       UpperCamelCase					=  pretraining_tp
       UpperCamelCase					=  apply_residual_connection_post_layernorm
       UpperCamelCase					=  hidden_dropout
       UpperCamelCase					=  attention_dropout

       UpperCamelCase					=  bos_token_id
       UpperCamelCase					=  eos_token_id
       UpperCamelCase					=  slow_but_exact

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

class  SCREAMING_SNAKE_CASE (  a__		):






    """simple docstring"""





    _SCREAMING_SNAKE_CASE	  =  version.parse("""1.12"""		)






    def __init__(  self      :					Tuple  ,						UpperCamelCase__      :					int  ,						UpperCamelCase__      :					Optional[int] = "default"  ,						UpperCamelCase__      :					List[str] = None  ,						UpperCamelCase__      :					List[str] = False  ,						):


       """simple docstring"""







       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?
          UpperCamelCase					=  0






    @property
    def  A       (  self      :					str ):


       """simple docstring"""







       UpperCamelCase					=  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_ )
          UpperCamelCase					=  {0: 'batch', 1: 'past_sequence + sequence'}
       else:
          UpperCamelCase					=  {0: 'batch', 1: 'sequence'}

       return common_inputs






    @property
    def  A       (  self      :					Union[str, Any] ):


       """simple docstring"""







       return self._config.n_layer






    @property
    def  A       (  self      :					int ):


       """simple docstring"""







       return self._config.n_head






    @property
    def  A       (  self      :					Optional[int] ):


       """simple docstring"""







       return 1E-3






    def  A       (  self      :					List[Any]  ,						UpperCamelCase__      :					Union[str, Any]  ,						UpperCamelCase__      :					int = -1  ,						UpperCamelCase__      :					List[Any] = -1  ,						UpperCamelCase__      :					str = False  ,						UpperCamelCase__      :					Tuple = None  ,						):


       """simple docstring"""







       UpperCamelCase					=  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()
       UpperCamelCase					=  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

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

       UpperCamelCase					=  common_inputs['attention_mask']
       if self.use_past:
          UpperCamelCase					=  ordered_inputs['attention_mask'].dtype
          UpperCamelCase					=  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  A       (  self      :					Union[str, Any] ):


       """simple docstring"""







       return 1_3






from typing import Optional

import pyspark

from .. import Features, NamedSplit
from ..download import DownloadMode
from ..packaged_modules.spark.spark import Spark
from .abc import AbstractDatasetReader



class 				lowerCAmelCase_		(  a__							):
       def __init__(			self,			SCREAMING_SNAKE_CASE_,			SCREAMING_SNAKE_CASE_ = None,			SCREAMING_SNAKE_CASE_ = None,			SCREAMING_SNAKE_CASE_ = True,			SCREAMING_SNAKE_CASE_ = None,			SCREAMING_SNAKE_CASE_ = False,			SCREAMING_SNAKE_CASE_ = None,			SCREAMING_SNAKE_CASE_ = True,			SCREAMING_SNAKE_CASE_ = "arrow",			**SCREAMING_SNAKE_CASE_,			)     ->		Optional[int]:
          super().__init__(
              split=SCREAMING_SNAKE_CASE_,			features=SCREAMING_SNAKE_CASE_,			cache_dir=SCREAMING_SNAKE_CASE_,			keep_in_memory=SCREAMING_SNAKE_CASE_,			streaming=SCREAMING_SNAKE_CASE_,			**SCREAMING_SNAKE_CASE_,			)
          UpperCamelCase    :  List[str]							=	load_from_cache_file
          UpperCamelCase    :  List[str]							=	file_format
          UpperCamelCase    :  Optional[int]							=	Spark(
              df=SCREAMING_SNAKE_CASE_,			features=SCREAMING_SNAKE_CASE_,			cache_dir=SCREAMING_SNAKE_CASE_,			working_dir=SCREAMING_SNAKE_CASE_,			**SCREAMING_SNAKE_CASE_,			)






       def 					snake_case_       (			self       )     ->		int:
          if self.streaming:
             return self.builder.as_streaming_dataset(split=self.split       )
          UpperCamelCase    :  Union[str, Any]							=	None if self._load_from_cache_file else DownloadMode.FORCE_REDOWNLOAD
          self.builder.download_and_prepare(
              download_mode=SCREAMING_SNAKE_CASE_,			file_format=self._file_format,			)
          return self.builder.as_dataset(split=self.split       )



