



"""simple docstring"""


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


snake_case_				     =       logging.get_logger(__name__)

snake_case_				     =       {}







class       A_			(     SCREAMING_SNAKE_CASE_				):



						"""simple docstring"""
						__UpperCamelCase						=							"""llama"""
						__UpperCamelCase						=							["""past_key_values"""]






						def __init__(					self :Tuple   ,  lowercase_ :Any=3_20_00   ,  lowercase_ :Tuple=40_96   ,  lowercase_ :Any=1_10_08   ,  lowercase_ :int=32   ,  lowercase_ :str=32   ,  lowercase_ :Optional[Any]=None   ,  lowercase_ :Dict="silu"   ,  lowercase_ :Any=20_48   ,  lowercase_ :Tuple=0.02   ,  lowercase_ :Tuple=1E-6   ,  lowercase_ :str=True   ,  lowercase_ :Dict=0   ,  lowercase_ :Optional[Any]=1   ,  lowercase_ :List[str]=2   ,  lowercase_ :Union[str, Any]=1   ,  lowercase_ :List[Any]=False   ,  lowercase_ :Union[str, Any]=None   ,  **lowercase_ :int   ,  )				->			int:
												UpperCAmelCase             = vocab_size
												UpperCAmelCase             = max_position_embeddings
												UpperCAmelCase             = hidden_size
												UpperCAmelCase             = intermediate_size
												UpperCAmelCase             = num_hidden_layers
												UpperCAmelCase             = num_attention_heads

												# for backward compatibility
												if num_key_value_heads is None:
																		UpperCAmelCase             = num_attention_heads

												UpperCAmelCase             = num_key_value_heads
												UpperCAmelCase             = hidden_act
												UpperCAmelCase             = initializer_range
												UpperCAmelCase             = rms_norm_eps
												UpperCAmelCase             = pretraining_tp
												UpperCAmelCase             = use_cache
												UpperCAmelCase             = rope_scaling
												self._rope_scaling_validation()

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






						def 	UpperCAmelCase__     (					self :List[str]					)				->			Any:
												if self.rope_scaling is None:
																		return

												if not isinstance(self.rope_scaling   ,  lowercase_					) 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}"""					)
												UpperCAmelCase             = self.rope_scaling.get('type'   ,  lowercase_					)
												UpperCAmelCase             = self.rope_scaling.get('factor'   ,  lowercase_					)
												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(lowercase_   ,  lowercase_					) or rope_scaling_factor <= 1.0:
																		raise ValueError(f"""`rope_scaling`'s factor field must be an float > 1, got {rope_scaling_factor}"""					)












"""simple docstring"""




import unittest
from dataclasses import dataclass

import pytest

from accelerate.commands.config.config_args import SageMakerConfig
from accelerate.utils import ComputeEnvironment
from accelerate.utils.launch import _convert_nargs_to_dict


@dataclass
class        __UpperCamelCase				(						a__						):
							lowerCamelCase   :					List[str]      					=ComputeEnvironment.AMAZON_SAGEMAKER
							lowerCamelCase   :					str      					=True
							lowerCamelCase   :					Union[str, Any]      					="""ml.p3.2xlarge"""
							lowerCamelCase   :					str      					="""accelerate_sagemaker_execution_role"""
							lowerCamelCase   :					int      					="""hf-sm"""
							lowerCamelCase   :					int      					="""us-east-1"""
							lowerCamelCase   :					Tuple      					=1
							lowerCamelCase   :					Any      					="""accelerate-sagemaker-1"""
							lowerCamelCase   :					str      					="""1.6"""
							lowerCamelCase   :					Tuple      					="""4.4"""
							lowerCamelCase   :					Optional[int]      					="""train.py"""
							lowerCamelCase   :					Optional[Any]      					=[
							    """--model_name_or_path""",
							    """bert""",
							    """--do_train""",
							    """False""",
							    """--epochs""",
							    """3""",
							    """--learning_rate""",
							    """5e-5""",
							    """--max_steps""",
							    """50.5""",
							]
							lowerCamelCase   :					Union[str, Any]      					=[
							    """--model_name_or_path""",
							    """bert""",
							    """--do_train""",
							    """--do_test""",
							    """False""",
							    """--do_predict""",
							    """--epochs""",
							    """3""",
							    """--learning_rate""",
							    """5e-5""",
							    """--max_steps""",
							    """50.5""",
							]


class        __UpperCamelCase				(						unittest.TestCase						):






							def     __a   (   self      )	-> List[str]:
								# If no defaults are changed, `to_kwargs` returns an empty dict.
								a      :		str	=				_convert_nargs_to_dict(MockLaunchConfig.success_training_script_args      )
								assert isinstance(converted_args["model_name_or_path"]      ,					lowerCAmelCase__      )
								assert isinstance(converted_args["do_train"]      ,					lowerCAmelCase__      )
								assert isinstance(converted_args["epochs"]      ,					lowerCAmelCase__      )
								assert isinstance(converted_args["learning_rate"]      ,					lowerCAmelCase__      )
								assert isinstance(converted_args["max_steps"]      ,					lowerCAmelCase__      )

								with pytest.raises(lowerCAmelCase__      ):
									_convert_nargs_to_dict(MockLaunchConfig.fail_training_script_args      )


