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


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

__a  :     Optional[int]       =  {
    """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    _UpperCamelCase      (						_UpperCAmelCase ):


			"""simple docstring"""






			__a  : str			 =						'''bloom'''
			__a  : int			 =						['''past_key_values''']
			__a  : Union[str, Any]			 =						{
			    '''num_hidden_layers''': '''n_layer''',
			    '''num_attention_heads''': '''n_head''',
			}





			def __init__(   self      ,   lowerCAmelCase__=25_08_80      ,   lowerCAmelCase__=64      ,   lowerCAmelCase__=2      ,   lowerCAmelCase__=8      ,   lowerCAmelCase__=1E-5      ,   lowerCAmelCase__=0.02      ,   lowerCAmelCase__=True      ,   lowerCAmelCase__=1      ,   lowerCAmelCase__=2      ,   lowerCAmelCase__=False      ,   lowerCAmelCase__=0.0      ,   lowerCAmelCase__=0.0      ,   lowerCAmelCase__=1      ,   lowerCAmelCase__=False      ,   **lowerCAmelCase__      ,   )     ->					Union[str, Any]:

							'''simple docstring'''


							__lowercase 			=							vocab_size
							# Backward compatibility with n_embed kwarg
							__lowercase 			=							kwargs.pop('''n_embed'''      ,   lowerCAmelCase__						)
							__lowercase 			=							hidden_size if n_embed is None else n_embed
							__lowercase 			=							n_layer
							__lowercase 			=							n_head
							__lowercase 			=							layer_norm_epsilon
							__lowercase 			=							initializer_range
							__lowercase 			=							use_cache
							__lowercase 			=							pretraining_tp
							__lowercase 			=							apply_residual_connection_post_layernorm
							__lowercase 			=							hidden_dropout
							__lowercase 			=							attention_dropout

							__lowercase 			=							bos_token_id
							__lowercase 			=							eos_token_id
							__lowercase 			=							slow_but_exact

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




class    _UpperCamelCase      (						_UpperCAmelCase ):


			"""simple docstring"""






			__a  : Optional[Any]			 =						version.parse('''1.12''' )





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

							'''simple docstring'''


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





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

							'''simple docstring'''


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

							return common_inputs





			@property
			def        _SCREAMING_SNAKE_CASE			(   self						)     ->					int:

							'''simple docstring'''


							return self._config.n_layer





			@property
			def        _SCREAMING_SNAKE_CASE			(   self						)     ->					int:

							'''simple docstring'''


							return self._config.n_head





			@property
			def        _SCREAMING_SNAKE_CASE			(   self						)     ->					float:

							'''simple docstring'''


							return 1E-3





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

							'''simple docstring'''


							__lowercase 			=							super(lowerCAmelCase__      ,   self						).generate_dummy_inputs(
							    lowerCAmelCase__      ,   batch_size=lowerCAmelCase__      ,   seq_length=lowerCAmelCase__      ,   is_pair=lowerCAmelCase__      ,   framework=lowerCAmelCase__						)

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

							__lowercase 			=							common_inputs['''attention_mask''']
							if self.use_past:
											__lowercase 			=							ordered_inputs['''attention_mask'''].dtype
											__lowercase 			=							torch.cat(
											    [ordered_inputs['''attention_mask'''], torch.ones(lowerCAmelCase__      ,   lowerCAmelCase__      ,   dtype=lowerCAmelCase__						)]      ,   dim=1						)

							return ordered_inputs





			@property
			def        _SCREAMING_SNAKE_CASE			(   self						)     ->					int:

							'''simple docstring'''


							return 13
# Copyright 2022 The HuggingFace Team and The OpenBMB Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import TYPE_CHECKING

# rely on isort to merge the imports
from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tokenizers_available, is_torch_available


__a  :     Any       =  {
    """configuration_cpmant""": ["""CPMANT_PRETRAINED_CONFIG_ARCHIVE_MAP""", """CpmAntConfig"""],
    """tokenization_cpmant""": ["""CpmAntTokenizer"""],
}

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__a  :     List[Any]       =  [
		    """CPMANT_PRETRAINED_MODEL_ARCHIVE_LIST""",
		    """CpmAntForCausalLM""",
		    """CpmAntModel""",
		    """CpmAntPreTrainedModel""",
		]


if TYPE_CHECKING:
		from .configuration_cpmant import CPMANT_PRETRAINED_CONFIG_ARCHIVE_MAP, CpmAntConfig
		from .tokenization_cpmant import CpmAntTokenizer

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_cpmant import (
				    CPMANT_PRETRAINED_MODEL_ARCHIVE_LIST,
				    CpmAntForCausalLM,
				    CpmAntModel,
				    CpmAntPreTrainedModel,
				)


else:
		import sys

		__a  :     Any       =  _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)