





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


snake_case								=							logging.get_logger(__name__)

snake_case								=							{
    """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_					(   A__						):







       """simple docstring"""





       SCREAMING_SNAKE_CASE_   :			List[Any]  			=	'''bloom'''
       SCREAMING_SNAKE_CASE_   :			Any  			=	['''past_key_values''']
       SCREAMING_SNAKE_CASE_   :			Optional[Any]  			=	{
           '''num_hidden_layers''': '''n_layer''',
           '''num_attention_heads''': '''n_head''',
       }







       def __init__(     self						:						Optional[Any]    ,__A						:						Any=25_0880    ,__A						:						Any=64    ,__A						:						Optional[int]=2    ,__A						:						int=8    ,__A						:						Tuple=1e-5    ,__A						:						Optional[Any]=0.02    ,__A						:						Optional[Any]=True    ,__A						:						int=1    ,__A						:						str=2    ,__A						:						Tuple=False    ,__A						:						Dict=0.0    ,__A						:						Optional[int]=0.0    ,__A						:						Optional[int]=1    ,__A						:						str=False    ,**__A						:						str    ,)    ->       Optional[int]:
         _lowercase						    =			vocab_size
         # Backward compatibility with n_embed kwarg
         _lowercase						    =			kwargs.pop('n_embed'    ,a__	)
         _lowercase						    =			hidden_size if n_embed is None else n_embed
         _lowercase						    =			n_layer
         _lowercase						    =			n_head
         _lowercase						    =			layer_norm_epsilon
         _lowercase						    =			initializer_range
         _lowercase						    =			use_cache
         _lowercase						    =			pretraining_tp
         _lowercase						    =			apply_residual_connection_post_layernorm
         _lowercase						    =			hidden_dropout
         _lowercase						    =			attention_dropout

         _lowercase						    =			bos_token_id
         _lowercase						    =			eos_token_id
         _lowercase						    =			slow_but_exact

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





class 					A_					(   A__						):







       """simple docstring"""





       SCREAMING_SNAKE_CASE_   :			str  			=	version.parse('''1.12'''						)







       def __init__(     self						:						Tuple    ,__A						:						List[str]    ,__A						:						Dict = "default"    ,__A						:						Optional[int] = None    ,__A						:						Dict = False    ,)    ->       str:
         super().__init__(a__    ,task=a__    ,patching_specs=a__    ,use_past=a__	)
         if not getattr(self._config    ,'pad_token_id'    ,a__	):
           # TODO: how to do that better?
           _lowercase						    =			0







       @property
       def  __UpperCAmelCase			(     self						:						Union[str, Any]	)    ->       Optional[Any]:
         _lowercase						    =			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_(a__    ,direction='inputs'    ,inverted_values_shape=a__	)
           _lowercase						    =			{0: 'batch', 1: 'past_sequence + sequence'}
         else:
           _lowercase						    =			{0: 'batch', 1: 'sequence'}

         return common_inputs







       @property
       def  __UpperCAmelCase			(     self						:						Union[str, Any]	)    ->       List[Any]:
         return self._config.n_layer







       @property
       def  __UpperCAmelCase			(     self						:						List[Any]	)    ->       List[str]:
         return self._config.n_head







       @property
       def  __UpperCAmelCase			(     self						:						List[Any]	)    ->       int:
         return 1e-3







       def  __UpperCAmelCase			(     self						:						Any    ,__A						:						str    ,__A						:						Any = -1    ,__A						:						Dict = -1    ,__A						:						str = False    ,__A						:						Union[str, Any] = None    ,)    ->       List[Any]:
         _lowercase						    =			super(a__    ,self	).generate_dummy_inputs(
             a__    ,batch_size=a__    ,seq_length=a__    ,is_pair=a__    ,framework=a__	)

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

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

         _lowercase						    =			common_inputs['attention_mask']
         if self.use_past:
           _lowercase						    =			ordered_inputs['attention_mask'].dtype
           _lowercase						    =			torch.cat(
               [ordered_inputs['attention_mask'], torch.ones(a__    ,a__    ,dtype=a__	)]    ,dim=1	)

         return ordered_inputs







       @property
       def  __UpperCAmelCase			(     self						:						List[str]	)    ->       Optional[Any]:
         return 13




from ...configuration_utils import PretrainedConfig
from ...utils import logging


_lowercase    	=		logging.get_logger(__name__)



class      _UpperCAmelCase      (							A__  ):
     UpperCamelCase__		     =					'''timm_backbone'''




     def __init__(					self			,    a__=None			,    a__=3			,    a__=True			,    a__=True			,    a__=None			,    **a__			,    ):
         super().__init__(**a__)
         A__					=       backbone
         A__					=       num_channels
         A__					=       features_only
         A__					=       use_pretrained_backbone
         A__					=       True
         A__					=       out_indices if out_indices is not None else (-1,)
