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

A_     :						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       ( __a		):
  __A :				Tuple											= 'bloom'
  __A :				List[Any]											= ['past_key_values']
  __A :				Optional[int]											= {
      '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.02    ,     _lowerCamelCase=True    ,     _lowerCamelCase=1    ,     _lowerCamelCase=2    ,     _lowerCamelCase=False    ,     _lowerCamelCase=0.0    ,     _lowerCamelCase=0.0    ,     _lowerCamelCase=1    ,     _lowerCamelCase=False    ,     **_lowerCamelCase    ,     ):
     lowerCAmelCase_			=      vocab_size
     # Backward compatibility with n_embed kwarg
     lowerCAmelCase_			=      kwargs.pop('''n_embed'''    ,     _lowerCamelCase )
     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=_lowerCamelCase    ,     eos_token_id=_lowerCamelCase    ,     **_lowerCamelCase )






class     __UpperCAmelCase       ( __a		):
  __A :				Optional[int]											= version.parse('1.12'		)





  def __init__(	self    ,     _lowerCamelCase    ,     _lowerCamelCase = "default"    ,     _lowerCamelCase = None    ,     _lowerCamelCase = False    ,     ):
     super().__init__(_lowerCamelCase    ,     task=_lowerCamelCase    ,     patching_specs=_lowerCamelCase    ,     use_past=_lowerCamelCase )
     if not getattr(self._config    ,     '''pad_token_id'''    ,     _lowerCamelCase ):
        # TODO: how to do that better?
        lowerCAmelCase_			=      0





  @property
  def 						UpperCAmelCase_	(	self ):
     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_(_lowerCamelCase    ,     direction='''inputs'''    ,     inverted_values_shape=_lowerCamelCase )
        lowerCAmelCase_			=      {0: '''batch''', 1: '''past_sequence + sequence'''}
     else:
        lowerCAmelCase_			=      {0: '''batch''', 1: '''sequence'''}

     return common_inputs





  @property
  def 						UpperCAmelCase_	(	self ):
     return self._config.n_layer





  @property
  def 						UpperCAmelCase_	(	self ):
     return self._config.n_head





  @property
  def 						UpperCAmelCase_	(	self ):
     return 1E-3





  def 						UpperCAmelCase_	(	self    ,     _lowerCamelCase    ,     _lowerCamelCase = -1    ,     _lowerCamelCase = -1    ,     _lowerCamelCase = False    ,     _lowerCamelCase = None    ,     ):
     lowerCAmelCase_			=      super(_lowerCamelCase    ,     self ).generate_dummy_inputs(
         _lowerCamelCase    ,     batch_size=_lowerCamelCase    ,     seq_length=_lowerCamelCase    ,     is_pair=_lowerCamelCase    ,     framework=_lowerCamelCase )

     # 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_	,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(_lowerCamelCase ), torch.zeros(_lowerCamelCase )) 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(_lowerCamelCase    ,     _lowerCamelCase    ,     dtype=_lowerCamelCase )]    ,     dim=1 )

     return ordered_inputs







  @property
  def 						UpperCAmelCase_	(	self ):
     return 13






'''simple docstring'''

import contextlib
import importlib
import io
import unittest

import transformers

# Try to import everything from transformers to ensure every object can be loaded.
from transformers import *  # noqa F406
from transformers.testing_utils import DUMMY_UNKNOWN_IDENTIFIER, require_flax, require_tf, require_torch
from transformers.utils import ContextManagers, find_labels, is_flax_available, is_tf_available, is_torch_available


if is_torch_available():
 from transformers import BertForPreTraining, BertForQuestionAnswering, BertForSequenceClassification

if is_tf_available():
 from transformers import TFBertForPreTraining, TFBertForQuestionAnswering, TFBertForSequenceClassification

if is_flax_available():
 from transformers import FlaxBertForPreTraining, FlaxBertForQuestionAnswering, FlaxBertForSequenceClassification


A_     :						Optional[Any]    							=DUMMY_UNKNOWN_IDENTIFIER
# An actual model hosted on huggingface.co

A_     :						Tuple    							='''main'''
# Default branch name
A_     :						Dict    							='''f2c752cfc5c0ab6f4bdec59acea69eefbee381c2'''
# One particular commit (not the top of `main`)
A_     :						int    							='''aaaaaaa'''
# This commit does not exist, so we should 404.

A_     :						List[str]    							='''d9e9f15bc825e4b2c9249e9578f884bbcb5e3684'''
# Sha-1 of config.json on the top of `main`, for checking purposes
A_     :						List[str]    							='''4b243c475af8d0a7754e87d7d096c92e5199ec2fe168a2ee7998e3b8e9bcb1d3'''



@contextlib.contextmanager
def snake_case_      (					)			->					Tuple:
   print('''Welcome!''')
   yield
   print('''Bye!''')



@contextlib.contextmanager
def snake_case_      (					)			->					str:
   print('''Bonjour!''')
   yield
   print('''Au revoir!''')


class     __UpperCAmelCase       ( unittest.TestCase		):





  def 						UpperCAmelCase_	(	self ):
     # If the spec is missing, importlib would not be able to import the module dynamically.
     assert transformers.__spec__ is not None
     assert importlib.util.find_spec('''transformers''' ) is not None






class     __UpperCAmelCase       ( unittest.TestCase		):





  @unittest.mock.patch('''sys.stdout'''    ,     new_callable=io.StringIO )
  def 						UpperCAmelCase_	(	self    ,     _lowerCamelCase ):
     with ContextManagers([] ):
        print('''Transformers are awesome!''' )
     # The print statement adds a new line at the end of the output
     self.assertEqual(mock_stdout.getvalue()    ,     '''Transformers are awesome!\n''' )





  @unittest.mock.patch('''sys.stdout'''    ,     new_callable=io.StringIO )
  def 						UpperCAmelCase_	(	self    ,     _lowerCamelCase ):
     with ContextManagers([context_en()] ):
        print('''Transformers are awesome!''' )
     # The output should be wrapped with an English welcome and goodbye
     self.assertEqual(mock_stdout.getvalue()    ,     '''Welcome!\nTransformers are awesome!\nBye!\n''' )





  @unittest.mock.patch('''sys.stdout'''    ,     new_callable=io.StringIO )
  def 						UpperCAmelCase_	(	self    ,     _lowerCamelCase ):
     with ContextManagers([context_fr(), context_en()] ):
        print('''Transformers are awesome!''' )
     # The output should be wrapped with an English and French welcome and goodbye
     self.assertEqual(mock_stdout.getvalue()    ,     '''Bonjour!\nWelcome!\nTransformers are awesome!\nBye!\nAu revoir!\n''' )





  @require_torch
  def 						UpperCAmelCase_	(	self ):
     self.assertEqual(find_labels(_lowerCamelCase )    ,     ['''labels'''] )
     self.assertEqual(find_labels(_lowerCamelCase )    ,     ['''labels''', '''next_sentence_label'''] )
     self.assertEqual(find_labels(_lowerCamelCase )    ,     ['''start_positions''', '''end_positions'''] )


     class     __UpperCAmelCase       ( __a		):
       pass






     self.assertEqual(find_labels(_lowerCamelCase )    ,     ['''labels'''] )





  @require_tf
  def 						UpperCAmelCase_	(	self ):
     self.assertEqual(find_labels(_lowerCamelCase )    ,     ['''labels'''] )
     self.assertEqual(find_labels(_lowerCamelCase )    ,     ['''labels''', '''next_sentence_label'''] )
     self.assertEqual(find_labels(_lowerCamelCase )    ,     ['''start_positions''', '''end_positions'''] )


     class     __UpperCAmelCase       ( __a		):
       pass






     self.assertEqual(find_labels(_lowerCamelCase )    ,     ['''labels'''] )







  @require_flax
  def 						UpperCAmelCase_	(	self ):
     # Flax models don't have labels
     self.assertEqual(find_labels(_lowerCamelCase )    ,     [] )
     self.assertEqual(find_labels(_lowerCamelCase )    ,     [] )
     self.assertEqual(find_labels(_lowerCamelCase )    ,     [] )


     class     __UpperCAmelCase       ( __a		):
       pass






     self.assertEqual(find_labels(_lowerCamelCase )    ,     [] )





