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


UpperCAmelCase        =				logging.get_logger(__name__)

UpperCAmelCase        =				{
    """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					( lowercase__		):
			lowercase        =     '''bloom'''
			lowercase        =     ['''past_key_values''']
			lowercase        =     {
			    '''num_hidden_layers''': '''n_layer''',
			    '''num_attention_heads''': '''n_head''',
			}






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





				"""simple docstring"""


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





class 			lowercase					( lowercase__		):
			lowercase        =     version.parse('''1.12'''		)






			def __init__(self  :	Dict      ,SCREAMING_SNAKE_CASE_  :	PretrainedConfig      ,SCREAMING_SNAKE_CASE_  :	str = "default"      ,SCREAMING_SNAKE_CASE_  :	List[PatchingSpec] = None      ,SCREAMING_SNAKE_CASE_  :	bool = False      ,)       ->	Dict:





				"""simple docstring"""


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






			@property
			def 					UpperCAmelCase							(self  :	Optional[Any]			)       ->	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_(SCREAMING_SNAKE_CASE_      ,direction='''inputs'''      ,inverted_values_shape=SCREAMING_SNAKE_CASE_			)
					lowerCAmelCase												=  {0: '''batch''', 1: '''past_sequence + sequence'''}
				else:
					lowerCAmelCase												=  {0: '''batch''', 1: '''sequence'''}

				return common_inputs






			@property
			def 					UpperCAmelCase							(self  :	Optional[Any]			)       ->	int:





				"""simple docstring"""


				return self._config.n_layer






			@property
			def 					UpperCAmelCase							(self  :	Tuple			)       ->	int:





				"""simple docstring"""


				return self._config.n_head






			@property
			def 					UpperCAmelCase							(self  :	List[str]			)       ->	float:





				"""simple docstring"""


				return 1e-3






			def 					UpperCAmelCase							(self  :	Dict      ,SCREAMING_SNAKE_CASE_  :	"PreTrainedTokenizer"      ,SCREAMING_SNAKE_CASE_  :	int = -1      ,SCREAMING_SNAKE_CASE_  :	int = -1      ,SCREAMING_SNAKE_CASE_  :	bool = False      ,SCREAMING_SNAKE_CASE_  :	Optional["TensorType"] = None      ,)       ->	Mapping[str, Any]:





				"""simple docstring"""


				lowerCAmelCase												=  super(SCREAMING_SNAKE_CASE_      ,self			).generate_dummy_inputs(
				    SCREAMING_SNAKE_CASE_      ,batch_size=SCREAMING_SNAKE_CASE_      ,seq_length=SCREAMING_SNAKE_CASE_      ,is_pair=SCREAMING_SNAKE_CASE_      ,framework=SCREAMING_SNAKE_CASE_			)

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

				return ordered_inputs






			@property
			def 					UpperCAmelCase							(self  :	List[Any]			)       ->	int:





				"""simple docstring"""


				return 13




"""simple docstring"""






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		):






			def 					UpperCAmelCase							(self  :	Union[str, Any]			)       ->	Optional[Any]:





				"""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(SCREAMING_SNAKE_CASE_			)






			def 					UpperCAmelCase							(self  :	Union[str, Any]			)       ->	Optional[int]:





				"""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(SCREAMING_SNAKE_CASE_			) as cl:
						logger.warning(SCREAMING_SNAKE_CASE_			)
					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(SCREAMING_SNAKE_CASE_			) as cl:
					logger.warning(SCREAMING_SNAKE_CASE_			)
				self.assertEqual(cl.out      ,''''''			)

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

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






			@mockenv(TRANSFORMERS_VERBOSITY='''error'''			)
			def 					UpperCAmelCase							(self  :	Any			)       ->	str:





				"""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'''      ,SCREAMING_SNAKE_CASE_			)
				lowerCAmelCase												=  logging.log_levels[env_level_str]

				lowerCAmelCase												=  logging.get_verbosity()
				self.assertEqual(
				    SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_      ,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 					UpperCAmelCase							(self  :	List[Any]			)       ->	Tuple:





				"""simple docstring"""


				transformers.utils.logging._reset_library_root_logger()
				lowerCAmelCase												=  logging.logging.getLogger()
				with CaptureLogger(SCREAMING_SNAKE_CASE_			) 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 					UpperCAmelCase							(self  :	Dict			)       ->	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(SCREAMING_SNAKE_CASE_			) as cl:
						logger.warning_advice(SCREAMING_SNAKE_CASE_			)
					self.assertEqual(cl.out      ,''''''			)

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





def __magic_name__	(				)					->						List[Any]:

	'''simple docstring'''




	disable_progress_bar()
	assert are_progress_bars_disabled()

	enable_progress_bar()
	assert not are_progress_bars_disabled()


