





"""simple docstring"""


import unittest

from transformers import AutoConfig, AutoTokenizer, BertConfig, TensorType, is_flax_available
from transformers.testing_utils import DUMMY_UNKNOWN_IDENTIFIER, require_flax, slow


if is_flax_available():
		import jax

		from transformers.models.auto.modeling_flax_auto import FlaxAutoModel
		from transformers.models.bert.modeling_flax_bert import FlaxBertModel
		from transformers.models.roberta.modeling_flax_roberta import FlaxRobertaModel






@require_flax
class 							lowercase__			(   unittest.TestCase	):

			"""simple docstring"""







			@slow
			def   _a      (      self    ):






									'''simple docstring'''







									for model_name in ["bert-base-cased", "bert-large-uncased"]:
															with self.subTest(_A    ):
																					UpperCamelCase				:		Any				   =			AutoConfig.from_pretrained(_A    )
																					self.assertIsNotNone(_A    )
																					self.assertIsInstance(_A						,   _A    )

																					UpperCamelCase				:		List[Any]				   =			FlaxAutoModel.from_pretrained(_A    )
																					self.assertIsNotNone(_A    )
																					self.assertIsInstance(_A						,   _A    )







			@slow
			def   _a      (      self    ):






									'''simple docstring'''







									for model_name in ["roberta-base", "roberta-large"]:
															with self.subTest(_A    ):
																					UpperCamelCase				:		Any				   =			AutoConfig.from_pretrained(_A    )
																					self.assertIsNotNone(_A    )
																					self.assertIsInstance(_A						,   _A    )

																					UpperCamelCase				:		Any				   =			FlaxAutoModel.from_pretrained(_A    )
																					self.assertIsNotNone(_A    )
																					self.assertIsInstance(_A						,   _A    )







			@slow
			def   _a      (      self    ):






									'''simple docstring'''







									for model_name in ["bert-base-cased", "bert-large-uncased"]:
															UpperCamelCase				:		Tuple				   =			AutoTokenizer.from_pretrained(_A    )
															UpperCamelCase				:		Optional[Any]				   =			FlaxBertModel.from_pretrained(_A    )
															UpperCamelCase				:		int				   =			tokenizer("""Do you support jax jitted function?"""						,   return_tensors=TensorType.JAX    )

															@jax.jit
															def eval(**_A    ):
																					return model(**_A    )

															eval(**_A    ).block_until_ready()







			@slow
			def   _a      (      self    ):






									'''simple docstring'''







									for model_name in ["roberta-base", "roberta-large"]:
															UpperCamelCase				:		str				   =			AutoTokenizer.from_pretrained(_A    )
															UpperCamelCase				:		List[str]				   =			FlaxRobertaModel.from_pretrained(_A    )
															UpperCamelCase				:		Any				   =			tokenizer("""Do you support jax jitted function?"""						,   return_tensors=TensorType.JAX    )

															@jax.jit
															def eval(**_A    ):
																					return model(**_A    )

															eval(**_A    ).block_until_ready()







			def   _a      (      self    ):






									'''simple docstring'''







									with self.assertRaisesRegex(
									    _A						,   """bert-base is not a local folder and is not a valid model identifier"""    ):
															UpperCamelCase				:		Optional[Any]				   =			FlaxAutoModel.from_pretrained("""bert-base"""    )







			def   _a      (      self    ):






									'''simple docstring'''







									with self.assertRaisesRegex(
									    _A						,   r"""aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)"""    ):
															UpperCamelCase				:		List[str]				   =			FlaxAutoModel.from_pretrained(_A						,   revision="""aaaaaa"""    )







			def   _a      (      self    ):






									'''simple docstring'''







									with self.assertRaisesRegex(
									    _A						,   """hf-internal-testing/config-no-model does not appear to have a file named flax_model.msgpack"""						,   ):
															UpperCamelCase				:		str				   =			FlaxAutoModel.from_pretrained("""hf-internal-testing/config-no-model"""    )







			def   _a      (      self    ):






									'''simple docstring'''







									with self.assertRaisesRegex(_A						,   """Use `from_pt=True` to load this model"""    ):
															UpperCamelCase				:		Dict				   =			FlaxAutoModel.from_pretrained("""hf-internal-testing/tiny-bert-pt-only"""    )








'''simple docstring'''

from ...configuration_utils import PretrainedConfig
from ...utils import logging


__lowerCAmelCase		     =  logging.get_logger(__name__)

__lowerCAmelCase		     =  {
    '''s-JoL/Open-Llama-V1''': '''https://huggingface.co/s-JoL/Open-Llama-V1/blob/main/config.json''',
}

class       __magic_name__		(       _UpperCamelCase  ):
							lowerCAmelCase			:       str  							=   'open-llama'







							def __init__(				self   :			str      ,_UpperCAmelCase   :			int=100000      ,_UpperCAmelCase   :			List[str]=4096      ,_UpperCAmelCase   :			Dict=11008      ,_UpperCAmelCase   :			int=32      ,_UpperCAmelCase   :			Union[str, Any]=32      ,_UpperCAmelCase   :			List[str]="silu"      ,_UpperCAmelCase   :			List[Any]=2048      ,_UpperCAmelCase   :			Any=0.02      ,_UpperCAmelCase   :			int=1E-6      ,_UpperCAmelCase   :			Optional[int]=True      ,_UpperCAmelCase   :			Dict=0      ,_UpperCAmelCase   :			Optional[Any]=1      ,_UpperCAmelCase   :			Dict=2      ,_UpperCAmelCase   :			Tuple=False      ,_UpperCAmelCase   :			Dict=True      ,_UpperCAmelCase   :			Dict=0.1      ,_UpperCAmelCase   :			Optional[int]=0.1      ,_UpperCAmelCase   :			List[str]=True      ,_UpperCAmelCase   :			int=True      ,_UpperCAmelCase   :			Union[str, Any]=None      ,**_UpperCAmelCase   :			Optional[int]      ,):
									_a	: str								=				vocab_size
									_a	: str								=				max_position_embeddings
									_a	: List[str]								=				hidden_size
									_a	: Any								=				intermediate_size
									_a	: Union[str, Any]								=				num_hidden_layers
									_a	: Tuple								=				num_attention_heads
									_a	: int								=				hidden_act
									_a	: str								=				initializer_range
									_a	: Any								=				rms_norm_eps
									_a	: Dict								=				use_cache
									_a	: Optional[int]								=				kwargs.pop(
									    'use_memorry_efficient_attention'      ,_UpperCAmelCase						)
									_a	: int								=				hidden_dropout_prob
									_a	: int								=				attention_dropout_prob
									_a	: Union[str, Any]								=				use_stable_embedding
									_a	: str								=				shared_input_output_embedding
									_a	: Any								=				rope_scaling
									self._rope_scaling_validation()

									super().__init__(
									    pad_token_id=_UpperCAmelCase      ,bos_token_id=_UpperCAmelCase      ,eos_token_id=_UpperCAmelCase      ,tie_word_embeddings=_UpperCAmelCase      ,**_UpperCAmelCase      ,)







							def 				__lowercase     (				self   :			Optional[Any]						):
									if self.rope_scaling is None:
											return

									if not isinstance(self.rope_scaling      ,_UpperCAmelCase						) or len(self.rope_scaling						) != 2:
											raise ValueError(
											    '`rope_scaling` must be a dictionary with with two fields, `name` and `factor`, '
											    F"""got {self.rope_scaling}"""						)
									_a	: Optional[Any]								=				self.rope_scaling.get('type'      ,_UpperCAmelCase						)
									_a	: Optional[Any]								=				self.rope_scaling.get('factor'      ,_UpperCAmelCase						)
									if rope_scaling_type is None or rope_scaling_type not in ["linear", "dynamic"]:
											raise ValueError(
											    F"""`rope_scaling`'s name field must be one of ['linear', 'dynamic'], got {rope_scaling_type}"""						)
									if rope_scaling_factor is None or not isinstance(_UpperCAmelCase      ,_UpperCAmelCase						) or rope_scaling_factor <= 1.0:
											raise ValueError(F"""`rope_scaling`'s factor field must be an float > 1, got {rope_scaling_factor}"""						)




