





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


lowerCAmelCase :					Optional[Any] 							=logging.get_logger(__name__)

lowerCAmelCase :					str 							={
    '''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							):
     __A								=      "bloom"
     __A								=      ["past_key_values"]
     __A								=      {
         "num_hidden_layers": "n_layer",
         "num_attention_heads": "n_head",
     }





     def __init__(			self		: Tuple     ,				lowercase		: Union[str, Any]=250_880     ,				lowercase		: str=64     ,				lowercase		: Optional[Any]=2     ,				lowercase		: str=8     ,				lowercase		: Optional[int]=1e-5     ,				lowercase		: int=0.02     ,				lowercase		: str=True     ,				lowercase		: Optional[int]=1     ,				lowercase		: Tuple=2     ,				lowercase		: Any=False     ,				lowercase		: Dict=0.0     ,				lowercase		: int=0.0     ,				lowercase		: List[str]=1     ,				lowercase		: Optional[int]=False     ,				**lowercase		: Dict     ,				):





        """simple docstring"""




        lowercase_      :int         =			vocab_size
        # Backward compatibility with n_embed kwarg
        lowercase_      :Dict         =			kwargs.pop("n_embed"     ,				lowercase						)
        lowercase_      :Tuple         =			hidden_size if n_embed is None else n_embed
        lowercase_      :Optional[Any]         =			n_layer
        lowercase_      :Any         =			n_head
        lowercase_      :Any         =			layer_norm_epsilon
        lowercase_      :Dict         =			initializer_range
        lowercase_      :Optional[int]         =			use_cache
        lowercase_      :Dict         =			pretraining_tp
        lowercase_      :Dict         =			apply_residual_connection_post_layernorm
        lowercase_      :int         =			hidden_dropout
        lowercase_      :int         =			attention_dropout

        lowercase_      :Union[str, Any]         =			bos_token_id
        lowercase_      :Tuple         =			eos_token_id
        lowercase_      :Tuple         =			slow_but_exact

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







class 				a_       (    _lowerCAmelCase							):
     __A								=      version.parse("1.12"							)





     def __init__(			self		: Tuple     ,				lowercase		: PretrainedConfig     ,				lowercase		: str = "default"     ,				lowercase		: List[PatchingSpec] = None     ,				lowercase		: bool = False     ,				):





        """simple docstring"""




        super().__init__(lowercase     ,				task=lowercase     ,				patching_specs=lowercase     ,				use_past=lowercase						)
        if not getattr(self._config     ,				"pad_token_id"     ,				lowercase						):
           # TODO: how to do that better?
           lowercase_      :int         =			0





     @property
     def 							lowercase__				(			self		: Any						):





        """simple docstring"""




        lowercase_      :List[Any]         =			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_(lowercase     ,				direction="inputs"     ,				inverted_values_shape=lowercase						)
           lowercase_      :Any         =			{0: "batch", 1: "past_sequence + sequence"}
        else:
           lowercase_      :Any         =			{0: "batch", 1: "sequence"}

        return common_inputs





     @property
     def 							lowercase__				(			self		: str						):





        """simple docstring"""




        return self._config.n_layer





     @property
     def 							lowercase__				(			self		: Any						):





        """simple docstring"""




        return self._config.n_head





     @property
     def 							lowercase__				(			self		: int						):





        """simple docstring"""




        return 1e-3





     def 							lowercase__				(			self		: int     ,				lowercase		: "PreTrainedTokenizer"     ,				lowercase		: int = -1     ,				lowercase		: int = -1     ,				lowercase		: bool = False     ,				lowercase		: Optional["TensorType"] = None     ,				):





        """simple docstring"""




        lowercase_      :Tuple         =			super(lowercase     ,				self						).generate_dummy_inputs(
            lowercase     ,				batch_size=lowercase     ,				seq_length=lowercase     ,				is_pair=lowercase     ,				framework=lowercase						)

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

        lowercase_      :str         =			common_inputs["attention_mask"]
        if self.use_past:
           lowercase_      :Optional[int]         =			ordered_inputs["attention_mask"].dtype
           lowercase_      :Any         =			torch.cat(
               [ordered_inputs["attention_mask"], torch.ones(lowercase     ,				lowercase     ,				dtype=lowercase						)]     ,				dim=1						)

        return ordered_inputs







     @property
     def 							lowercase__				(			self		: Optional[Any]						):





        """simple docstring"""




        return 13









'''simple docstring'''


def 							UpperCAmelCase_  (						__lowerCamelCase : dict			):
   lowercase_      :set[int]         =			set()
   # To detect a back edge, keep track of vertices currently in the recursion stack
   lowercase_      :set[int]         =			set()
   return any(
       node not in visited and depth_first_search(__lowerCamelCase     ,__lowerCamelCase     ,__lowerCamelCase     ,__lowerCamelCase			)
       for node in graph			)
def 							UpperCAmelCase_  (						__lowerCamelCase : dict     ,__lowerCamelCase : int     ,__lowerCamelCase : set     ,__lowerCamelCase : set			):
   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()


