


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


UpperCAmelCase   :    Dict     =		logging.get_logger(__name__)

UpperCAmelCase   :    Dict     =		{
    "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        __lowercase       (							a_  ):



		"""simple docstring"""

		UpperCamelCase     :					Any			       =		"bloom"
		UpperCamelCase     :					Union[str, Any]			       =		["past_key_values"]
		UpperCamelCase     :					Any			       =		{
		    "num_hidden_layers": "n_layer",
		    "num_attention_heads": "n_head",
		}







		def __init__( self		,      A=25_08_80		,      A=64		,      A=2		,      A=8		,      A=1e-5		,      A=0.02		,      A=True		,      A=1		,      A=2		,      A=False		,      A=0.0		,      A=0.0		,      A=1		,      A=False		,      **A		,      )  -> str:







					'''simple docstring'''







					lowerCamelCase    		=  vocab_size
					# Backward compatibility with n_embed kwarg
					lowerCamelCase    		=  kwargs.pop("""n_embed"""		,      A	)
					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=A		,      eos_token_id=A		,      **A	)







class        __lowercase       (							a_  ):



		"""simple docstring"""

		UpperCamelCase     :					List[str]			       =		version.parse("1.12"  )







		def __init__( self		,      A		,      A = "default"		,      A = None		,      A = False		,      )  -> Optional[Any]:







					'''simple docstring'''







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







		@property
		def 					__A   ( self	)  -> Mapping[str, Mapping[int, str]]:







					'''simple docstring'''







					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_(A		,      direction="""inputs"""		,      inverted_values_shape=A	)
								lowerCamelCase    		=  {0: """batch""", 1: """past_sequence + sequence"""}
					else:
								lowerCamelCase    		=  {0: """batch""", 1: """sequence"""}

					return common_inputs







		@property
		def 					__A   ( self	)  -> int:







					'''simple docstring'''







					return self._config.n_layer







		@property
		def 					__A   ( self	)  -> int:







					'''simple docstring'''







					return self._config.n_head







		@property
		def 					__A   ( self	)  -> float:







					'''simple docstring'''







					return 1e-3







		def 					__A   ( self		,      A		,      A = -1		,      A = -1		,      A = False		,      A = None		,      )  -> Mapping[str, Any]:







					'''simple docstring'''







					lowerCamelCase    		=  super(A		,      self	).generate_dummy_inputs(
					    A		,      batch_size=A		,      seq_length=A		,      is_pair=A		,      framework=A	)

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

					return ordered_inputs







		@property
		def 					__A   ( self	)  -> int:







					'''simple docstring'''







					return 13





import os
import unittest

from huggingface_hub.utils import are_progress_bars_disabled

import transformers.models.bart.tokenization_bart
from transformers import logging
from transformers.testing_utils import CaptureLogger, mockenv, mockenv_context
from transformers.utils.logging import disable_progress_bar, enable_progress_bar







class        __lowercase       (							unittest.TestCase  ):



		"""simple docstring"""

		def 					__A   ( self	)  -> Dict:







					'''simple docstring'''







					lowerCamelCase    		=  logging.get_logger()

					# the current default level is logging.WARNING
					lowerCamelCase    		=  logging.get_verbosity()

					logging.set_verbosity_error()
					self.assertEqual(logger.getEffectiveLevel()		,      logging.get_verbosity()	)

					logging.set_verbosity_warning()
					self.assertEqual(logger.getEffectiveLevel()		,      logging.get_verbosity()	)

					logging.set_verbosity_info()
					self.assertEqual(logger.getEffectiveLevel()		,      logging.get_verbosity()	)

					logging.set_verbosity_debug()
					self.assertEqual(logger.getEffectiveLevel()		,      logging.get_verbosity()	)

					# restore to the original level
					logging.set_verbosity(A	)







		def 					__A   ( self	)  -> Tuple:







					'''simple docstring'''







					lowerCamelCase    		=  logging.get_verbosity()

					lowerCamelCase    		=  logging.get_logger("""transformers.models.bart.tokenization_bart"""	)
					lowerCamelCase    		=  """Testing 1, 2, 3"""

					# should be able to log warnings (if default settings weren't overridden by `pytest --log-level-all`)
					if level_origin <= logging.WARNING:
								with CaptureLogger(A	) as cl:
											logger.warning(A	)
								self.assertEqual(cl.out		,      msg + """\n"""	)

					# this is setting the level for all of `transformers.*` loggers
					logging.set_verbosity_error()

					# should not be able to log warnings
					with CaptureLogger(A	) as cl:
								logger.warning(A	)
					self.assertEqual(cl.out		,      """"""	)

					# should be able to log warnings again
					logging.set_verbosity_warning()
					with CaptureLogger(A	) as cl:
								logger.warning(A	)
					self.assertEqual(cl.out		,      msg + """\n"""	)

					# restore to the original level
					logging.set_verbosity(A	)







		@mockenv(TRANSFORMERS_VERBOSITY="""error"""	)
		def 					__A   ( self	)  -> Union[str, Any]:







					'''simple docstring'''







					transformers.utils.logging._reset_library_root_logger()
					# this action activates the env var
					lowerCamelCase    		=  logging.get_logger("""transformers.models.bart.tokenization_bart"""	)

					lowerCamelCase    		=  os.getenv("""TRANSFORMERS_VERBOSITY"""		,      A	)
					lowerCamelCase    		=  logging.log_levels[env_level_str]

					lowerCamelCase    		=  logging.get_verbosity()
					self.assertEqual(
					    A		,      A		,      F'TRANSFORMERS_VERBOSITY={env_level_str}/{env_level}, but internal verbosity is {current_level}'		,      )

					# restore to the original level
					lowerCamelCase    		=  """"""
					transformers.utils.logging._reset_library_root_logger()







		@mockenv(TRANSFORMERS_VERBOSITY="""super-error"""	)
		def 					__A   ( self	)  -> Union[str, Any]:







					'''simple docstring'''







					transformers.utils.logging._reset_library_root_logger()
					lowerCamelCase    		=  logging.logging.getLogger()
					with CaptureLogger(A	) as cl:
								# this action activates the env var
								logging.get_logger("""transformers.models.bart.tokenization_bart"""	)
					self.assertIn("""Unknown option TRANSFORMERS_VERBOSITY=super-error"""		,      cl.out	)

					# no need to restore as nothing was changed







		def 					__A   ( self	)  -> Optional[Any]:







					'''simple docstring'''







					transformers.utils.logging._reset_library_root_logger()

					lowerCamelCase    		=  logging.get_logger("""transformers.models.bart.tokenization_bart"""	)
					lowerCamelCase    		=  """Testing 1, 2, 3"""

					with mockenv_context(TRANSFORMERS_NO_ADVISORY_WARNINGS="""1"""	):
								# nothing should be logged as env var disables this method
								with CaptureLogger(A	) as cl:
											logger.warning_advice(A	)
								self.assertEqual(cl.out		,      """"""	)

					with mockenv_context(TRANSFORMERS_NO_ADVISORY_WARNINGS=""""""	):
								# should log normally as TRANSFORMERS_NO_ADVISORY_WARNINGS is unset
								with CaptureLogger(A	) as cl:
											logger.warning_advice(A	)
								self.assertEqual(cl.out		,      msg + """\n"""	)






def 	__lowerCamelCase						(							):





			'''simple docstring'''




			disable_progress_bar()
			assert are_progress_bars_disabled()

			enable_progress_bar()
			assert not are_progress_bars_disabled()

