





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

snake_case__					:							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 A_					(			_lowerCamelCase   ):
   lowerCAmelCase__        = """bloom"""
   lowerCAmelCase__        = ["""past_key_values"""]
   lowerCAmelCase__        = {
       """num_hidden_layers""": """n_layer""",
       """num_attention_heads""": """n_head""",
   }




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

         __A          =				bos_token_id
         __A          =				eos_token_id
         __A          =				slow_but_exact

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





class A_					(			_lowerCamelCase   ):
   lowerCAmelCase__        = version.parse("""1.12"""   )




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




   @property
   def _lowerCAmelCase      (self	:Tuple )->					Mapping[str, Mapping[int, str]]:
         __A          =				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_(_UpperCamelCase    ,   direction='''inputs'''    ,   inverted_values_shape=_UpperCamelCase )
               __A          =				{0: '''batch''', 1: '''past_sequence + sequence'''}
         else:
               __A          =				{0: '''batch''', 1: '''sequence'''}

         return common_inputs




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




   @property
   def _lowerCAmelCase      (self	:Optional[Any] )->					int:
         return self._config.n_head




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




   def _lowerCAmelCase      (self	:Optional[int]    ,   _UpperCamelCase	:"PreTrainedTokenizer"    ,   _UpperCamelCase	:int = -1    ,   _UpperCamelCase	:int = -1    ,   _UpperCamelCase	:bool = False    ,   _UpperCamelCase	:Optional["TensorType"] = None    ,   )->					Mapping[str, Any]:
         __A          =				super(_UpperCamelCase    ,   self ).generate_dummy_inputs(
             _UpperCamelCase    ,   batch_size=_UpperCamelCase    ,   seq_length=_UpperCamelCase    ,   is_pair=_UpperCamelCase    ,   framework=_UpperCamelCase )

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

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

         return ordered_inputs






   @property
   def _lowerCAmelCase      (self	:Optional[int] )->					int:
         return 13












def _a				(	lowerCamelCase:   dict )	->						bool:







      '''simple docstring'''






      __A          =				set()
      # To detect a back edge, keep track of vertices currently in the recursion stack
      __A          =				set()
      return any(
          node not in visited and depth_first_search(lowerCamelCase					,				lowerCamelCase					,				lowerCamelCase					,				lowerCamelCase )
          for node in graph )



def _a				(	lowerCamelCase:   dict					,				lowerCamelCase:   int					,				lowerCamelCase:   set					,				lowerCamelCase:   set )	->						bool:







      '''simple docstring'''






      visited.add(lowerCamelCase )
      rec_stk.add(lowerCamelCase )

      for node in graph[vertex]:
            if node not in visited:
                  if depth_first_search(lowerCamelCase					,				lowerCamelCase					,				lowerCamelCase					,				lowerCamelCase ):
                        return True
            elif node in rec_stk:
                  return True

    # The node needs to be removed from recursion stack before function ends
      rec_stk.remove(lowerCamelCase )
      return False


if __name__ == "__main__":
       from doctest import testmod

       testmod()





