





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     :     Optional[Any]							=	logging.get_logger(__name__)

UpperCAmelCase     :     Dict							=	{
    """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     __lowerCAmelCase	(   UpperCamelCase__):






      """simple docstring"""




      _lowercase    : List[str]            =      '''bloom'''
      _lowercase    : Tuple            =      ['''past_key_values''']
      _lowercase    : Tuple            =      {
          '''num_hidden_layers''': '''n_layer''',
          '''num_attention_heads''': '''n_head''',
      }







      def __init__(   self		,				lowerCAmelCase__=2_5_0_8_8_0		,				lowerCAmelCase__=6_4		,				lowerCAmelCase__=2		,				lowerCAmelCase__=8		,				lowerCAmelCase__=1E-5		,				lowerCAmelCase__=0.02		,				lowerCAmelCase__=True		,				lowerCAmelCase__=1		,				lowerCAmelCase__=2		,				lowerCAmelCase__=False		,				lowerCAmelCase__=0.0		,				lowerCAmelCase__=0.0		,				lowerCAmelCase__=1		,				lowerCAmelCase__=False		,				**lowerCAmelCase__		,				)       ->						List[Any]:



        '''simple docstring'''




        a__     : List[str]  =vocab_size
        # Backward compatibility with n_embed kwarg
        a__     : Any  =kwargs.pop("n_embed"		,				UpperCamelCase_							)
        a__     : Optional[Any]  =hidden_size if n_embed is None else n_embed
        a__     : List[str]  =n_layer
        a__     : Dict  =n_head
        a__     : Any  =layer_norm_epsilon
        a__     : Tuple  =initializer_range
        a__     : List[Any]  =use_cache
        a__     : List[Any]  =pretraining_tp
        a__     : str  =apply_residual_connection_post_layernorm
        a__     : str  =hidden_dropout
        a__     : int  =attention_dropout

        a__     : Optional[Any]  =bos_token_id
        a__     : int  =eos_token_id
        a__     : Optional[Any]  =slow_but_exact

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







class     __lowerCAmelCase	(   UpperCamelCase__):






      """simple docstring"""




      _lowercase    : List[Any]            =      version.parse("""1.12""")







      def __init__(   self		,				lowerCAmelCase__		,				lowerCAmelCase__ = "default"		,				lowerCAmelCase__ = None		,				lowerCAmelCase__ = False		,				)       ->						Union[str, Any]:



        '''simple docstring'''




        super().__init__(UpperCamelCase_		,				task=UpperCamelCase_		,				patching_specs=UpperCamelCase_		,				use_past=UpperCamelCase_							)
        if not getattr(self._config		,				"pad_token_id"		,				UpperCamelCase_							):
          # TODO: how to do that better?
          a__     : Union[str, Any]  =0







      @property
      def        _lowercase  (   self							)       ->						Mapping[str, Mapping[int, str]]:



        '''simple docstring'''




        a__     : Optional[Any]  =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_(UpperCamelCase_		,				direction="inputs"		,				inverted_values_shape=UpperCamelCase_							)
          a__     : Optional[Any]  ={0: "batch", 1: "past_sequence + sequence"}
        else:
          a__     : Any  ={0: "batch", 1: "sequence"}

        return common_inputs







      @property
      def        _lowercase  (   self							)       ->						int:



        '''simple docstring'''




        return self._config.n_layer







      @property
      def        _lowercase  (   self							)       ->						int:



        '''simple docstring'''




        return self._config.n_head







      @property
      def        _lowercase  (   self							)       ->						float:



        '''simple docstring'''




        return 1E-3







      def        _lowercase  (   self		,				lowerCAmelCase__		,				lowerCAmelCase__ = -1		,				lowerCAmelCase__ = -1		,				lowerCAmelCase__ = False		,				lowerCAmelCase__ = None		,				)       ->						Mapping[str, Any]:



        '''simple docstring'''




        a__     : List[str]  =super(UpperCamelCase_		,				self							).generate_dummy_inputs(
            UpperCamelCase_		,				batch_size=UpperCamelCase_		,				seq_length=UpperCamelCase_		,				is_pair=UpperCamelCase_		,				framework=UpperCamelCase_							)

        # We need to order the input in the way they appears in the forward()
        a__     : Dict  =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

            a__ ,							a__     : List[str]  =common_inputs["input_ids"].shape
            # Not using the same length for past_key_values
            a__     : Tuple  =seqlen + 2
            a__     : str  =self._config.hidden_size // self.num_attention_heads
            a__     : Any  =(
                batch * self.num_attention_heads,
                head_dim,
                past_key_values_length,
            )
            a__     : Union[str, Any]  =(
                batch * self.num_attention_heads,
                past_key_values_length,
                head_dim,
            )
            a__     : Optional[Any]  =[
                (torch.zeros(UpperCamelCase_							), torch.zeros(UpperCamelCase_							)) for _ in range(self.num_layers							)
            ]

        a__     : int  =common_inputs["attention_mask"]
        if self.use_past:
          a__     : List[Any]  =ordered_inputs["attention_mask"].dtype
          a__     : int  =torch.cat(
              [ordered_inputs["attention_mask"], torch.ones(UpperCamelCase_		,				UpperCamelCase_		,				dtype=UpperCamelCase_							)]		,				dim=1							)

        return ordered_inputs







      @property
      def        _lowercase  (   self							)       ->						int:



        '''simple docstring'''




        return 1_3













from typing import Optional

from .. import Features, NamedSplit
from ..packaged_modules.text.text import Text
from ..utils.typing import NestedDataStructureLike, PathLike
from .abc import AbstractDatasetReader







class     __lowerCAmelCase	(   UpperCamelCase__):







      def __init__(   self		,				lowerCAmelCase__		,				lowerCAmelCase__ = None		,				lowerCAmelCase__ = None		,				lowerCAmelCase__ = None		,				lowerCAmelCase__ = False		,				lowerCAmelCase__ = False		,				lowerCAmelCase__ = None		,				**lowerCAmelCase__		,				)       ->						int:



        '''simple docstring'''




        super().__init__(
            lowerCAmelCase__		,				split=lowerCAmelCase__		,				features=lowerCAmelCase__		,				cache_dir=lowerCAmelCase__		,				keep_in_memory=lowerCAmelCase__		,				streaming=lowerCAmelCase__		,				num_proc=lowerCAmelCase__		,				**lowerCAmelCase__		,				)
        a__     : Tuple  =path_or_paths if isinstance(lowerCAmelCase__		,				lowerCAmelCase__							) else {self.split: path_or_paths}
        a__     : List[str]  =Text(
            cache_dir=lowerCAmelCase__		,				data_files=lowerCAmelCase__		,				features=lowerCAmelCase__		,				**lowerCAmelCase__		,				)







      def        _lowercase  (   self							)       ->						List[Any]:



        '''simple docstring'''




        if self.streaming:
          a__     : str  =self.builder.as_streaming_dataset(split=self.split							)
        # Build regular (map-style) dataset
        else:
          a__     : Dict  =None
          a__     : Optional[Any]  =None
          a__     : Union[str, Any]  =None
          a__     : Tuple  =None

          self.builder.download_and_prepare(
              download_config=lowerCAmelCase__		,				download_mode=lowerCAmelCase__		,				verification_mode=lowerCAmelCase__		,				base_path=lowerCAmelCase__		,				num_proc=self.num_proc		,				)
          a__     : Tuple  =self.builder.as_dataset(
              split=self.split		,				verification_mode=lowerCAmelCase__		,				in_memory=self.keep_in_memory							)
        return dataset






