





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


a_ =			logging.get_logger(__name__)

a_ =			{
    """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 		__snake_case					(		_UpperCAmelCase     ):





 """simple docstring"""


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

 def __init__(    self					,						__lowerCamelCase=25_0880					,						__lowerCamelCase=64					,						__lowerCamelCase=2					,						__lowerCamelCase=8					,						__lowerCamelCase=1e-5					,						__lowerCamelCase=0.0_2					,						__lowerCamelCase=True					,						__lowerCamelCase=1					,						__lowerCamelCase=2					,						__lowerCamelCase=False					,						__lowerCamelCase=0.0					,						__lowerCamelCase=0.0					,						__lowerCamelCase=1					,						__lowerCamelCase=False					,						**__lowerCamelCase					,						):



     '''simple docstring'''




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

     __A    :						Tuple						 =     bos_token_id
     __A    :						List[Any]						 =     eos_token_id
     __A    :						int						 =     slow_but_exact

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






class 		__snake_case					(		_UpperCAmelCase     ):





 """simple docstring"""


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

 def __init__(    self					,						__lowerCamelCase					,						__lowerCamelCase = "default"					,						__lowerCamelCase = None					,						__lowerCamelCase = False					,						):



     '''simple docstring'''




     super().__init__(lowercase_					,						task=lowercase_					,						patching_specs=lowercase_					,						use_past=lowercase_  )
     if not getattr(self._config					,						'''pad_token_id'''					,						lowercase_  ):
         # TODO: how to do that better?
         __A    :						str						 =     0

 @property
 def 					UpperCamelCase__(    self  ):



     '''simple docstring'''




     __A    :						Union[str, 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_(lowercase_					,						direction='''inputs'''					,						inverted_values_shape=lowercase_  )
         __A    :						Union[str, Any]						 =     {0: '''batch''', 1: '''past_sequence + sequence'''}
     else:
         __A    :						Tuple						 =     {0: '''batch''', 1: '''sequence'''}

     return common_inputs

 @property
 def 					UpperCamelCase__(    self  ):



     '''simple docstring'''




     return self._config.n_layer

 @property
 def 					UpperCamelCase__(    self  ):



     '''simple docstring'''




     return self._config.n_head

 @property
 def 					UpperCamelCase__(    self  ):



     '''simple docstring'''




     return 1e-3

 def 					UpperCamelCase__(    self					,						__lowerCamelCase					,						__lowerCamelCase = -1					,						__lowerCamelCase = -1					,						__lowerCamelCase = False					,						__lowerCamelCase = None					,						):



     '''simple docstring'''




     __A    :						str						 =     super(lowercase_					,						self  ).generate_dummy_inputs(
         lowercase_					,						batch_size=lowercase_					,						seq_length=lowercase_					,						is_pair=lowercase_					,						framework=lowercase_  )

     # We need to order the input in the way they appears in the forward()
     __A    :						str						 =     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    :						int						 =     common_inputs['''input_ids'''].shape
             # Not using the same length for past_key_values
             __A    :						List[Any]						 =     seqlen + 2
             __A    :						List[str]						 =     self._config.hidden_size // self.num_attention_heads
             __A    :						Union[str, Any]						 =     (
                 batch * self.num_attention_heads,
                 head_dim,
                 past_key_values_length,
             )
             __A    :						str						 =     (
                 batch * self.num_attention_heads,
                 past_key_values_length,
                 head_dim,
             )
             __A    :						Optional[int]						 =     [
                 (torch.zeros(lowercase_  ), torch.zeros(lowercase_  )) for _ in range(self.num_layers  )
             ]

     __A    :						Tuple						 =     common_inputs['''attention_mask''']
     if self.use_past:
         __A    :						Optional[int]						 =     ordered_inputs['''attention_mask'''].dtype
         __A    :						Dict						 =     torch.cat(
             [ordered_inputs['''attention_mask'''], torch.ones(lowercase_					,						lowercase_					,						dtype=lowercase_  )]					,						dim=1  )

     return ordered_inputs







 @property
 def 					UpperCamelCase__(    self  ):



     '''simple docstring'''




     return 13







from argparse import ArgumentParser

from datasets.commands.convert import ConvertCommand
from datasets.commands.dummy_data import DummyDataCommand
from datasets.commands.env import EnvironmentCommand
from datasets.commands.run_beam import RunBeamCommand
from datasets.commands.test import TestCommand
from datasets.utils.logging import set_verbosity_info
def 						_snake_case(    SCREAMING_SNAKE_CASE__			:	Tuple      )							->      Tuple:





    '''simple docstring'''






    return {key.lstrip('-'      ): value for key, value in zip(unknown_args[::2]    ,			unknown_args[1::2]      )}
def 						_snake_case(    )							->      Dict:





    '''simple docstring'''






    A__          =   ArgumentParser(
        'HuggingFace Datasets CLI tool'    ,			usage='datasets-cli <command> [<args>]'    ,			allow_abbrev=SCREAMING_SNAKE_CASE__      )
    A__          =   parser.add_subparsers(help='datasets-cli command helpers'      )
    set_verbosity_info()

    # Register commands
    ConvertCommand.register_subcommand(SCREAMING_SNAKE_CASE__      )
    EnvironmentCommand.register_subcommand(SCREAMING_SNAKE_CASE__      )
    TestCommand.register_subcommand(SCREAMING_SNAKE_CASE__      )
    RunBeamCommand.register_subcommand(SCREAMING_SNAKE_CASE__      )
    DummyDataCommand.register_subcommand(SCREAMING_SNAKE_CASE__      )

    # Parse args
    A__      ,						A__          =   parser.parse_known_args()
    if not hasattr(SCREAMING_SNAKE_CASE__    ,			'func'      ):
        parser.print_help()
        exit(1      )
    A__          =   parse_unknown_args(SCREAMING_SNAKE_CASE__      )

    # Run
    A__          =   args.func(SCREAMING_SNAKE_CASE__    ,			**SCREAMING_SNAKE_CASE__      )
    service.run()


if __name__ == "__main__":
     main()

