





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  :    Tuple						    =  logging.get_logger(__name__)

_snake_case  :    Union[str, 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 				_UpperCAmelCase    (    _UpperCAmelCase    ):

  """simple docstring"""


  a_        = 'bloom'
  a_        = ['past_key_values']
  a_        = {
      'num_hidden_layers': 'n_layer',
      'num_attention_heads': 'n_head',
  }






  def __init__(				self :		List[Any]					,  lowerCAmelCase_ :		int=2_5_0_8_8_0					,  lowerCAmelCase_ :		Union[str, Any]=6_4					,  lowerCAmelCase_ :		Tuple=2					,  lowerCAmelCase_ :		List[Any]=8					,  lowerCAmelCase_ :		Any=1e-5					,  lowerCAmelCase_ :		int=0.02					,  lowerCAmelCase_ :		List[Any]=True					,  lowerCAmelCase_ :		Optional[int]=1					,  lowerCAmelCase_ :		List[Any]=2					,  lowerCAmelCase_ :		str=False					,  lowerCAmelCase_ :		Union[str, Any]=0.0					,  lowerCAmelCase_ :		Any=0.0					,  lowerCAmelCase_ :		Tuple=1					,  lowerCAmelCase_ :		Any=False					,  **lowerCAmelCase_ :		Union[str, Any]					,  )							->						Any:
     __lowerCAmelCase								=	vocab_size
     # Backward compatibility with n_embed kwarg
     __lowerCAmelCase								=	kwargs.pop('n_embed'					,  SCREAMING_SNAKE_CASE_     )
     __lowerCAmelCase								=	hidden_size if n_embed is None else n_embed
     __lowerCAmelCase								=	n_layer
     __lowerCAmelCase								=	n_head
     __lowerCAmelCase								=	layer_norm_epsilon
     __lowerCAmelCase								=	initializer_range
     __lowerCAmelCase								=	use_cache
     __lowerCAmelCase								=	pretraining_tp
     __lowerCAmelCase								=	apply_residual_connection_post_layernorm
     __lowerCAmelCase								=	hidden_dropout
     __lowerCAmelCase								=	attention_dropout

     __lowerCAmelCase								=	bos_token_id
     __lowerCAmelCase								=	eos_token_id
     __lowerCAmelCase								=	slow_but_exact

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





class 				_UpperCAmelCase    (    _UpperCAmelCase    ):

  """simple docstring"""


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






  def __init__(				self :		Tuple					,  lowerCAmelCase_ :		Any					,  lowerCAmelCase_ :		Tuple = "default"					,  lowerCAmelCase_ :		Optional[Any] = None					,  lowerCAmelCase_ :		Dict = 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?
        __lowerCAmelCase								=	0






  @property
  def 				lowercase		(				self :		List[Any]     )							->						Mapping[str, Mapping[int, str]]:
     __lowerCAmelCase								=	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_     )
        __lowerCAmelCase								=	{0: 'batch', 1: 'past_sequence + sequence'}
     else:
        __lowerCAmelCase								=	{0: 'batch', 1: 'sequence'}

     return common_inputs






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






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






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






  def 				lowercase		(				self :		Any					,  lowerCAmelCase_ :		int					,  lowerCAmelCase_ :		int = -1					,  lowerCAmelCase_ :		Optional[Any] = -1					,  lowerCAmelCase_ :		str = False					,  lowerCAmelCase_ :		Union[str, Any] = None					,  )							->						Mapping[str, Any]:
     __lowerCAmelCase								=	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()
     __lowerCAmelCase								=	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

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

     __lowerCAmelCase								=	common_inputs['attention_mask']
     if self.use_past:
        __lowerCAmelCase								=	ordered_inputs['attention_mask'].dtype
        __lowerCAmelCase								=	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 :		List[Any]     )							->						int:
     return 1_3





'''simple docstring'''



from . import (
    albert,
    align,
    altclip,
    audio_spectrogram_transformer,
    auto,
    autoformer,
    bark,
    bart,
    barthez,
    bartpho,
    beit,
    bert,
    bert_generation,
    bert_japanese,
    bertweet,
    big_bird,
    bigbird_pegasus,
    biogpt,
    bit,
    blenderbot,
    blenderbot_small,
    blip,
    blip_a,
    bloom,
    bridgetower,
    byta,
    camembert,
    canine,
    chinese_clip,
    clap,
    clip,
    clipseg,
    codegen,
    conditional_detr,
    convbert,
    convnext,
    convnextva,
    cpm,
    cpmant,
    ctrl,
    cvt,
    dataavec,
    deberta,
    deberta_va,
    decision_transformer,
    deformable_detr,
    deit,
    deprecated,
    deta,
    detr,
    dialogpt,
    dinat,
    distilbert,
    dit,
    donut,
    dpr,
    dpt,
    efficientformer,
    efficientnet,
    electra,
    encodec,
    encoder_decoder,
    ernie,
    ernie_m,
    esm,
    falcon,
    flaubert,
    flava,
    fnet,
    focalnet,
    fsmt,
    funnel,
    git,
    glpn,
    gpta,
    gpt_bigcode,
    gpt_neo,
    gpt_neox,
    gpt_neox_japanese,
    gpt_swa,
    gptj,
    gptsan_japanese,
    graphormer,
    groupvit,
    herbert,
    hubert,
    ibert,
    imagegpt,
    informer,
    instructblip,
    jukebox,
    layoutlm,
    layoutlmva,
    layoutlmva,
    layoutxlm,
    led,
    levit,
    lilt,
    llama,
    longformer,
    longta,
    luke,
    lxmert,
    mam_aaa,
    marian,
    markuplm,
    maskaformer,
    maskformer,
    mbart,
    mbartaa,
    mega,
    megatron_bert,
    megatron_gpta,
    mgp_str,
    mluke,
    mobilebert,
    mobilenet_va,
    mobilenet_va,
    mobilevit,
    mobilevitva,
    mpnet,
    mra,
    mta,
    musicgen,
    mvp,
    nat,
    nezha,
    nllb,
    nllb_moe,
    nystromformer,
    oneformer,
    open_llama,
    openai,
    opt,
    owlvit,
    pegasus,
    pegasus_x,
    perceiver,
    phobert,
    pixastruct,
    plbart,
    poolformer,
    prophetnet,
    qdqbert,
    rag,
    realm,
    reformer,
    regnet,
    rembert,
    resnet,
    roberta,
    roberta_prelayernorm,
    roc_bert,
    roformer,
    rwkv,
    sam,
    segformer,
    sew,
    sew_d,
    speech_encoder_decoder,
    speech_to_text,
    speech_to_text_a,
    speechta,
    splinter,
    squeezebert,
    swiftformer,
    swin,
    swinasr,
    swinva,
    switch_transformers,
    ta,
    table_transformer,
    tapas,
    time_series_transformer,
    timesformer,
    timm_backbone,
    transfo_xl,
    trocr,
    tvlt,
    umta,
    unispeech,
    unispeech_sat,
    upernet,
    videomae,
    vilt,
    vision_encoder_decoder,
    vision_text_dual_encoder,
    visual_bert,
    vit,
    vit_hybrid,
    vit_mae,
    vit_msn,
    vivit,
    wavaveca,
    wavaveca_conformer,
    wavaveca_phoneme,
    wavaveca_with_lm,
    wavlm,
    whisper,
    x_clip,
    xglm,
    xlm,
    xlm_prophetnet,
    xlm_roberta,
    xlm_roberta_xl,
    xlnet,
    xmod,
    yolos,
    yoso,
)






