

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

lowerCAmelCase__								=		{
    """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							):


		"""simple docstring"""




		a__					       =  "bloom"
		a__					       =  ["past_key_values"]
		a__					       =  {
		    "num_hidden_layers": "n_layer",
		    "num_attention_heads": "n_head",
		}


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

			_UpperCamelCase   :		List[str]			=						bos_token_id
			_UpperCamelCase   :		Dict			=						eos_token_id
			_UpperCamelCase   :		Optional[int]			=						slow_but_exact

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







class 	lowercase    (				_lowercase							):


		"""simple docstring"""




		a__					       =  version.parse("1.12"							)


		def __init__(				self	,       __snake_case	,       __snake_case = "default"	,       __snake_case = None	,       __snake_case = False	,       ):
			super().__init__(__snake_case	,       task=__snake_case	,       patching_specs=__snake_case	,       use_past=__snake_case)
			if not getattr(self._config	,       'pad_token_id'	,       __snake_case):
				# TODO: how to do that better?
				_UpperCamelCase   :		int			=						0


		@property
		def 		A__					(				self):
			_UpperCamelCase   :		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_(__snake_case	,       direction='inputs'	,       inverted_values_shape=__snake_case)
				_UpperCamelCase   :		int			=						{0: 'batch', 1: 'past_sequence + sequence'}
			else:
				_UpperCamelCase   :		Dict			=						{0: 'batch', 1: 'sequence'}

			return common_inputs


		@property
		def 		A__					(				self):
			return self._config.n_layer


		@property
		def 		A__					(				self):
			return self._config.n_head


		@property
		def 		A__					(				self):
			return 1e-3


		def 		A__					(				self	,       __snake_case	,       __snake_case = -1	,       __snake_case = -1	,       __snake_case = False	,       __snake_case = None	,       ):
			_UpperCamelCase   :		int			=						super(__snake_case	,       self).generate_dummy_inputs(
			    __snake_case	,       batch_size=__snake_case	,       seq_length=__snake_case	,       is_pair=__snake_case	,       framework=__snake_case)

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

			_UpperCamelCase   :		Optional[Any]			=						common_inputs['attention_mask']
			if self.use_past:
				_UpperCamelCase   :		List[Any]			=						ordered_inputs['attention_mask'].dtype
				_UpperCamelCase   :		Optional[int]			=						torch.cat(
				    [ordered_inputs['attention_mask'], torch.ones(__snake_case	,       __snake_case	,       dtype=__snake_case)]	,       dim=1)

			return ordered_inputs






		@property
		def 		A__					(				self):
			return 13







# tests directory-specific settings - this file is run automatically
# by pytest before any tests are run

import doctest
import sys
import warnings
from os.path import abspath, dirname, join

import _pytest

from transformers.testing_utils import HfDoctestModule, HfDocTestParser


# allow having multiple repository checkouts and not needing to remember to rerun
# 'pip install -e .[dev]' when switching between checkouts and running tests.
lowerCAmelCase__								=		abspath(join(dirname(__file__), """src"""))
sys.path.insert(1, git_repo_path)

# silence FutureWarning warnings in tests since often we can't act on them until
# they become normal warnings - i.e. the tests still need to test the current functionality
warnings.simplefilter(action="""ignore""", category=FutureWarning)






def 					lowerCamelCase_     (							UpperCAmelCase_							:     Any	)						->				Union[str, Any]:




	'''simple docstring'''




	config.addinivalue_line(
	    'markers'							,       'is_pt_tf_cross_test: mark test to run only when PT and TF interactions are tested'	)
	config.addinivalue_line(
	    'markers'							,       'is_pt_flax_cross_test: mark test to run only when PT and FLAX interactions are tested'	)
	config.addinivalue_line('markers'							,       'is_pipeline_test: mark test to run only when pipelines are tested'	)
	config.addinivalue_line('markers'							,       'is_staging_test: mark test to run only in the staging environment'	)
	config.addinivalue_line('markers'							,       'accelerate_tests: mark test that require accelerate'	)
	config.addinivalue_line('markers'							,       'tool_tests: mark the tool tests that are run on their specific schedule'	)






def 					lowerCamelCase_     (							UpperCAmelCase_							:     Optional[int]	)						->				List[Any]:




	'''simple docstring'''




	from transformers.testing_utils import pytest_addoption_shared

	pytest_addoption_shared(UpperCAmelCase_	)






def 					lowerCamelCase_     (							UpperCAmelCase_							:     Any	)						->				List[Any]:




	'''simple docstring'''




	from transformers.testing_utils import pytest_terminal_summary_main

	_UpperCamelCase   :		str			=						terminalreporter.config.getoption('--make-reports'	)
	if make_reports:
		pytest_terminal_summary_main(UpperCAmelCase_							,       id=UpperCAmelCase_	)






def 					lowerCamelCase_     (							UpperCAmelCase_							:     Dict							,       UpperCAmelCase_							:     Dict	)						->				Tuple:




	'''simple docstring'''




	if exitstatus == 5:
		_UpperCamelCase   :		List[Any]			=						0


# Doctest custom flag to ignore output.
lowerCAmelCase__								=		doctest.register_optionflag("""IGNORE_RESULT""")

lowerCAmelCase__								=		doctest.OutputChecker







class 	lowercase    (				_lowercase							):


		"""simple docstring"""




		def 		A__					(				self	,       __snake_case	,       __snake_case	,       __snake_case):
			if IGNORE_RESULT & optionflags:
				return True
			return OutputChecker.check_output(self	,       __snake_case	,       __snake_case	,       __snake_case)

lowerCAmelCase__								=		CustomOutputChecker
lowerCAmelCase__								=		HfDoctestModule







lowerCAmelCase__								=		HfDocTestParser




