


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


__snake_case											=					logging.get_logger(__name__)

__snake_case											=					{
    '''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"""

		_a   			=    'bloom'
		_a   			=    ['past_key_values']
		_a   			=    {
		    'num_hidden_layers': 'n_layer',
		    'num_attention_heads': 'n_head',
		}




		def __init__(		self   ,       UpperCamelCase_=250880   ,       UpperCamelCase_=64   ,       UpperCamelCase_=2   ,       UpperCamelCase_=8   ,       UpperCamelCase_=1e-5   ,       UpperCamelCase_=0.02   ,       UpperCamelCase_=True   ,       UpperCamelCase_=1   ,       UpperCamelCase_=2   ,       UpperCamelCase_=False   ,       UpperCamelCase_=0.0   ,       UpperCamelCase_=0.0   ,       UpperCamelCase_=1   ,       UpperCamelCase_=False   ,       **UpperCamelCase_   ,       ):

							'''simple docstring'''


							UpperCamelCase__       :Optional[Any]							 =			vocab_size
							# Backward compatibility with n_embed kwarg
							UpperCamelCase__       :List[Any]							 =			kwargs.pop('''n_embed'''   ,       UpperCamelCase_							)
							UpperCamelCase__       :Dict							 =			hidden_size if n_embed is None else n_embed
							UpperCamelCase__       :str							 =			n_layer
							UpperCamelCase__       :str							 =			n_head
							UpperCamelCase__       :List[str]							 =			layer_norm_epsilon
							UpperCamelCase__       :Dict							 =			initializer_range
							UpperCamelCase__       :List[Any]							 =			use_cache
							UpperCamelCase__       :int							 =			pretraining_tp
							UpperCamelCase__       :str							 =			apply_residual_connection_post_layernorm
							UpperCamelCase__       :List[str]							 =			hidden_dropout
							UpperCamelCase__       :List[str]							 =			attention_dropout

							UpperCamelCase__       :List[Any]							 =			bos_token_id
							UpperCamelCase__       :Optional[int]							 =			eos_token_id
							UpperCamelCase__       :List[Any]							 =			slow_but_exact

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



class        lowercase     (							A__ ):

		"""simple docstring"""

		_a   			=    version.parse('1.12' )




		def __init__(		self   ,       UpperCamelCase_   ,       UpperCamelCase_ = "default"   ,       UpperCamelCase_ = None   ,       UpperCamelCase_ = False   ,       ):

							'''simple docstring'''


							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?
												UpperCamelCase__       :List[str]							 =			0




		@property
		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							UpperCamelCase__       :Union[str, 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_(UpperCamelCase_   ,       direction='''inputs'''   ,       inverted_values_shape=UpperCamelCase_							)
												UpperCamelCase__       :Dict							 =			{0: '''batch''', 1: '''past_sequence + sequence'''}
							else:
												UpperCamelCase__       :str							 =			{0: '''batch''', 1: '''sequence'''}

							return common_inputs




		@property
		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							return self._config.n_layer




		@property
		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							return self._config.n_head




		@property
		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							return 1e-3




		def    lowerCAmelCase__    (		self   ,       UpperCamelCase_   ,       UpperCamelCase_ = -1   ,       UpperCamelCase_ = -1   ,       UpperCamelCase_ = False   ,       UpperCamelCase_ = None   ,       ):

							'''simple docstring'''


							UpperCamelCase__       :List[Any]							 =			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()
							UpperCamelCase__       :str							 =			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

																	UpperCamelCase__       :int							 =			common_inputs['''input_ids'''].shape
																	# Not using the same length for past_key_values
																	UpperCamelCase__       :int							 =			seqlen + 2
																	UpperCamelCase__       :Any							 =			self._config.hidden_size // self.num_attention_heads
																	UpperCamelCase__       :str							 =			(
																	    batch * self.num_attention_heads,
																	    head_dim,
																	    past_key_values_length,
																	)
																	UpperCamelCase__       :Tuple							 =			(
																	    batch * self.num_attention_heads,
																	    past_key_values_length,
																	    head_dim,
																	)
																	UpperCamelCase__       :Union[str, Any]							 =			[
																	    (torch.zeros(UpperCamelCase_							), torch.zeros(UpperCamelCase_							)) for _ in range(self.num_layers							)
																	]

							UpperCamelCase__       :Optional[int]							 =			common_inputs['''attention_mask''']
							if self.use_past:
												UpperCamelCase__       :List[str]							 =			ordered_inputs['''attention_mask'''].dtype
												UpperCamelCase__       :Tuple							 =			torch.cat(
												    [ordered_inputs['''attention_mask'''], torch.ones(UpperCamelCase_   ,       UpperCamelCase_   ,       dtype=UpperCamelCase_							)]   ,       dim=1							)

							return ordered_inputs




		@property
		def    lowerCAmelCase__    (		self							):

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

		"""simple docstring"""

		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							UpperCamelCase__       :int							 =			logging.get_logger()

							# the current default level is logging.WARNING
							UpperCamelCase__       :List[Any]							 =			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(UpperCamelCase_							)




		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							UpperCamelCase__       :Union[str, Any]							 =			logging.get_verbosity()

							UpperCamelCase__       :Union[str, Any]							 =			logging.get_logger('''transformers.models.bart.tokenization_bart'''							)
							UpperCamelCase__       :Optional[Any]							 =			'''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(UpperCamelCase_							) as cl:
																	logger.warning(UpperCamelCase_							)
												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(UpperCamelCase_							) as cl:
												logger.warning(UpperCamelCase_							)
							self.assertEqual(cl.out   ,       ''''''							)

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

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




		@mockenv(TRANSFORMERS_VERBOSITY='''error'''							)
		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							transformers.utils.logging._reset_library_root_logger()
							# this action activates the env var
							UpperCamelCase__       :Tuple							 =			logging.get_logger('''transformers.models.bart.tokenization_bart'''							)

							UpperCamelCase__       :Any							 =			os.getenv('''TRANSFORMERS_VERBOSITY'''   ,       UpperCamelCase_							)
							UpperCamelCase__       :Optional[Any]							 =			logging.log_levels[env_level_str]

							UpperCamelCase__       :int							 =			logging.get_verbosity()
							self.assertEqual(
							    UpperCamelCase_   ,       UpperCamelCase_   ,       F'''TRANSFORMERS_VERBOSITY={env_level_str}/{env_level}, but internal verbosity is {current_level}'''   ,       )

							# restore to the original level
							UpperCamelCase__       :Union[str, Any]							 =			''''''
							transformers.utils.logging._reset_library_root_logger()




		@mockenv(TRANSFORMERS_VERBOSITY='''super-error'''							)
		def    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							transformers.utils.logging._reset_library_root_logger()
							UpperCamelCase__       :Dict							 =			logging.logging.getLogger()
							with CaptureLogger(UpperCamelCase_							) 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    lowerCAmelCase__    (		self							):

							'''simple docstring'''


							transformers.utils.logging._reset_library_root_logger()

							UpperCamelCase__       :Optional[int]							 =			logging.get_logger('''transformers.models.bart.tokenization_bart'''							)
							UpperCamelCase__       :int							 =			'''Testing 1, 2, 3'''

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

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



def       a				(      )  ->     str:



					'''simple docstring'''






					disable_progress_bar()
					assert are_progress_bars_disabled()

					enable_progress_bar()
					assert not are_progress_bars_disabled()