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


_lowercase							=				logging.get_logger(__name__)

_lowercase							=				{
    '''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'''







							_lowerCamelCase					:			Tuple          =   'bloom'
							_lowerCamelCase					:			List[Any]          =   ['past_key_values']
							_lowerCamelCase					:			Optional[int]          =   {
							    'num_hidden_layers': 'n_layer',
							    'num_attention_heads': 'n_head',
							}
							def __init__(     self  ,    _lowerCamelCase=250_880  ,    _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  ,    )			->							Any:




										'''simple docstring'''
										__lowercase       =       vocab_size
										# Backward compatibility with n_embed kwarg
										__lowercase       =       kwargs.pop("n_embed"  ,    _lowerCamelCase       )
										__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=_lowerCamelCase  ,    eos_token_id=_lowerCamelCase  ,    **_lowerCamelCase       )





class 					__a     ( __a       ):



							'''simple docstring'''







							_lowerCamelCase					:			Optional[int]          =   version.parse("""1.12"""       )
							def __init__(     self  ,    _lowerCamelCase  ,    _lowerCamelCase = "default"  ,    _lowerCamelCase = None  ,    _lowerCamelCase = False  ,    )			->							Union[str, Any]:




										'''simple docstring'''
										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?
													__lowercase       =       0
							@property
							def   SCREAMING_SNAKE_CASE						(     self       )			->							str:




										'''simple docstring'''
										__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_(_lowerCamelCase  ,    direction="inputs"  ,    inverted_values_shape=_lowerCamelCase       )
													__lowercase       =       {0: "batch", 1: "past_sequence + sequence"}
										else:
													__lowercase       =       {0: "batch", 1: "sequence"}

										return common_inputs
							@property
							def   SCREAMING_SNAKE_CASE						(     self       )			->							List[Any]:




										'''simple docstring'''
										return self._config.n_layer
							@property
							def   SCREAMING_SNAKE_CASE						(     self       )			->							Optional[Any]:




										'''simple docstring'''
										return self._config.n_head
							@property
							def   SCREAMING_SNAKE_CASE						(     self       )			->							Optional[Any]:




										'''simple docstring'''
										return 1e-3
							def   SCREAMING_SNAKE_CASE						(     self  ,    _lowerCamelCase  ,    _lowerCamelCase = -1  ,    _lowerCamelCase = -1  ,    _lowerCamelCase = False  ,    _lowerCamelCase = None  ,    )			->							Union[str, Any]:




										'''simple docstring'''
										__lowercase       =       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()
										__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(_lowerCamelCase       ), torch.zeros(_lowerCamelCase       )) 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(_lowerCamelCase  ,    _lowerCamelCase  ,    dtype=_lowerCamelCase       )]  ,    dim=1       )

										return ordered_inputs





							@property
							def   SCREAMING_SNAKE_CASE						(     self       )			->							Tuple:




										'''simple docstring'''
										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 )    ,     [] )





