




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    lowerCamelCase    (		_lowerCamelCase						):






   '''simple docstring'''





   UpperCamelCase__								=ComputeEnvironment.AMAZON_SAGEMAKER
   UpperCamelCase__								=True
   UpperCamelCase__								='''ml.p3.2xlarge'''
   UpperCamelCase__								='''accelerate_sagemaker_execution_role'''
   UpperCamelCase__								='''hf-sm'''
   UpperCamelCase__								='''us-east-1'''
   UpperCamelCase__								=1
   UpperCamelCase__								='''accelerate-sagemaker-1'''
   UpperCamelCase__								='''1.6'''
   UpperCamelCase__								='''4.4'''
   UpperCamelCase__								='''train.py'''
   UpperCamelCase__								=[
       '''--model_name_or_path''',
       '''bert''',
       '''--do_train''',
       '''False''',
       '''--epochs''',
       '''3''',
       '''--learning_rate''',
       '''5e-5''',
       '''--max_steps''',
       '''50.5''',
   ]
   UpperCamelCase__								=[
       '''--model_name_or_path''',
       '''bert''',
       '''--do_train''',
       '''--do_test''',
       '''False''',
       '''--do_predict''',
       '''--epochs''',
       '''3''',
       '''--learning_rate''',
       '''5e-5''',
       '''--max_steps''',
       '''50.5''',
   ]






class    lowerCamelCase    (		unittest.TestCase						):






   '''simple docstring'''





   def 							UpperCAmelCase__       ( self			:   str  )						->   Optional[Any]:
        # If no defaults are changed, `to_kwargs` returns an empty dict.
        __magic_name__							:	int    							=							_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  )









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


__lowerCamelCase   :						Optional[int]				=			logging.get_logger(__name__)

__lowerCamelCase   :						Dict				=			{}


class    lowerCamelCase    (		_lowerCamelCase						):






			'''simple docstring'''





			UpperCamelCase__								='''llama'''
			UpperCamelCase__								=['''past_key_values''']

			def __init__( self			:   Dict       ,						lowerCamelCase_			:   List[str]=32000       ,						lowerCamelCase_			:   List[Any]=4096       ,						lowerCamelCase_			:   Any=11008       ,						lowerCamelCase_			:   Optional[Any]=32       ,						lowerCamelCase_			:   Dict=32       ,						lowerCamelCase_			:   Optional[Any]=None       ,						lowerCamelCase_			:   Dict="silu"       ,						lowerCamelCase_			:   Optional[int]=2048       ,						lowerCamelCase_			:   int=0.0_2       ,						lowerCamelCase_			:   Tuple=1E-6       ,						lowerCamelCase_			:   Tuple=True       ,						lowerCamelCase_			:   List[str]=0       ,						lowerCamelCase_			:   List[str]=1       ,						lowerCamelCase_			:   Optional[int]=2       ,						lowerCamelCase_			:   List[str]=1       ,						lowerCamelCase_			:   Dict=False       ,						lowerCamelCase_			:   int=None       ,						**lowerCamelCase_			:   Tuple       ,						)						->   Tuple:
								__magic_name__							:	Any    							=							vocab_size
								__magic_name__							:	Optional[int]    							=							max_position_embeddings
								__magic_name__							:	Union[str, Any]    							=							hidden_size
								__magic_name__							:	Dict    							=							intermediate_size
								__magic_name__							:	Union[str, Any]    							=							num_hidden_layers
								__magic_name__							:	Tuple    							=							num_attention_heads

								# for backward compatibility
								if num_key_value_heads is None:
													__magic_name__							:	Optional[int]    							=							num_attention_heads

								__magic_name__							:	Optional[int]    							=							num_key_value_heads
								__magic_name__							:	List[str]    							=							hidden_act
								__magic_name__							:	List[str]    							=							initializer_range
								__magic_name__							:	Tuple    							=							rms_norm_eps
								__magic_name__							:	Optional[int]    							=							pretraining_tp
								__magic_name__							:	Any    							=							use_cache
								__magic_name__							:	int    							=							rope_scaling
								self._rope_scaling_validation()

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


			def 							UpperCAmelCase__       ( self			:   str  )						->   Tuple:
								if self.rope_scaling is None:
													return

								if not isinstance(self.rope_scaling       ,						lowerCamelCase_  ) 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}'''  )
								__magic_name__							:	List[str]    							=							self.rope_scaling.get('''type'''       ,						lowerCamelCase_  )
								__magic_name__							:	str    							=							self.rope_scaling.get('''factor'''       ,						lowerCamelCase_  )
								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(lowerCamelCase_       ,						lowerCamelCase_  ) or rope_scaling_factor <= 1.0:
													raise ValueError(F'''`rope_scaling`\'s factor field must be an float > 1, got {rope_scaling_factor}'''  )



