



# We ignore warnings about stepping the scheduler since we step it ourselves during gradient accumulation

import warnings

from .state import AcceleratorState, GradientState


warnings.filterwarnings('''ignore''', category=UserWarning, module='''torch.optim.lr_scheduler''')

class    _A	:



       def __init__(		self							:					List[str]					,		__SCREAMING_SNAKE_CASE							:					str					,		__SCREAMING_SNAKE_CASE							:					Union[str, Any]					,		__SCREAMING_SNAKE_CASE							:					bool = True					,		__SCREAMING_SNAKE_CASE							:					bool = False):


           '''simple docstring'''

           __a							=    scheduler
           __a							=    optimizers if isinstance(__SCREAMING_SNAKE_CASE					,		(list, tuple)) else [optimizers]
           __a							=    split_batches
           __a							=    step_with_optimizer
           __a							=    GradientState()



       def 		_lowerCamelCase      (		self							:					Tuple					,		*__SCREAMING_SNAKE_CASE							:					Tuple					,		**__SCREAMING_SNAKE_CASE							:					Any):


           '''simple docstring'''

           if not self.step_with_optimizer:
               # No link between scheduler and optimizer -> just step
               self.scheduler.step(*__SCREAMING_SNAKE_CASE					,		**__SCREAMING_SNAKE_CASE)
               return

           # Otherwise, first make sure the optimizer was stepped.
           if not self.gradient_state.sync_gradients:
               if self.gradient_state.adjust_scheduler:
                   self.scheduler._step_count += 1
               return

           for opt in self.optimizers:
               if opt.step_was_skipped:
                   return
           if self.split_batches:
               # Split batches -> the training dataloader batch size is not changed so one step per training step
               self.scheduler.step(*__SCREAMING_SNAKE_CASE					,		**__SCREAMING_SNAKE_CASE)
           else:
               # Otherwise the training dataloader batch size was multiplied by `num_processes`, so we need to do
               # num_processes steps per training step
               __a							=    AcceleratorState().num_processes
               for _ in range(__SCREAMING_SNAKE_CASE):
                   # Special case when using OneCycle and `drop_last` was not used
                   if hasattr(self.scheduler					,		'''total_steps'''):
                       if self.scheduler._step_count <= self.scheduler.total_steps:
                           self.scheduler.step(*__SCREAMING_SNAKE_CASE					,		**__SCREAMING_SNAKE_CASE)
                   else:
                       self.scheduler.step(*__SCREAMING_SNAKE_CASE					,		**__SCREAMING_SNAKE_CASE)



       def 		_lowerCamelCase      (		self							:					Dict):


           '''simple docstring'''

           return self.scheduler.get_last_lr()



       def 		_lowerCamelCase      (		self							:					List[str]):


           '''simple docstring'''

           return self.scheduler.state_dict()



       def 		_lowerCamelCase      (		self							:					Union[str, Any]					,		__SCREAMING_SNAKE_CASE							:					Optional[int]):


           '''simple docstring'''

           self.scheduler.load_state_dict(__SCREAMING_SNAKE_CASE)



       def 		_lowerCamelCase      (		self							:					Dict):


           '''simple docstring'''

           return self.scheduler.get_lr()





       def 		_lowerCamelCase      (		self							:					Union[str, Any]					,		*__SCREAMING_SNAKE_CASE							:					Optional[Any]					,		**__SCREAMING_SNAKE_CASE							:					List[str]):


           '''simple docstring'''

           return self.scheduler.print_lr(*__SCREAMING_SNAKE_CASE					,		**__SCREAMING_SNAKE_CASE)










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


__snake_case						:Dict						=					logging.get_logger(__name__)

__snake_case						:List[Any]						=					{
    '''tanreinama/GPTSAN-2.8B-spout_is_uniform''': (
        '''https://huggingface.co/tanreinama/GPTSAN-2.8B-spout_is_uniform/resolve/main/config.json'''
    ),
}

class    _A	(     __UpperCAmelCase   ):
       UpperCamelCase__  :   List[str]						 =						'''gptsan-japanese'''
       UpperCamelCase__  :   Dict						 =						[
           '''past_key_values''',
       ]
       UpperCamelCase__  :   Dict						 =						{
           '''hidden_size''': '''d_model''',
           '''num_attention_heads''': '''num_heads''',
           '''num_hidden_layers''': '''num_layers''',
       }



       def __init__(		self							:					List[str]					,		__SCREAMING_SNAKE_CASE							:					Optional[Any]=36_000					,		__SCREAMING_SNAKE_CASE							:					Tuple=1_280					,		__SCREAMING_SNAKE_CASE							:					List[Any]=1_024					,		__SCREAMING_SNAKE_CASE							:					List[Any]=8_192					,		__SCREAMING_SNAKE_CASE							:					str=4_096					,		__SCREAMING_SNAKE_CASE							:					Any=128					,		__SCREAMING_SNAKE_CASE							:					int=10					,		__SCREAMING_SNAKE_CASE							:					Optional[int]=0					,		__SCREAMING_SNAKE_CASE							:					Optional[Any]=16					,		__SCREAMING_SNAKE_CASE							:					List[Any]=16					,		__SCREAMING_SNAKE_CASE							:					Optional[Any]=128					,		__SCREAMING_SNAKE_CASE							:					Tuple=0.0					,		__SCREAMING_SNAKE_CASE							:					List[Any]=1E-5					,		__SCREAMING_SNAKE_CASE							:					str=False					,		__SCREAMING_SNAKE_CASE							:					Optional[int]=0.0					,		__SCREAMING_SNAKE_CASE							:					List[str]="float32"					,		__SCREAMING_SNAKE_CASE							:					List[str]=False					,		__SCREAMING_SNAKE_CASE							:					Any=False					,		__SCREAMING_SNAKE_CASE							:					Any=False					,		__SCREAMING_SNAKE_CASE							:					int=0.0_02					,		__SCREAMING_SNAKE_CASE							:					Any=False					,		__SCREAMING_SNAKE_CASE							:					Tuple=True					,		__SCREAMING_SNAKE_CASE							:					int=35_998					,		__SCREAMING_SNAKE_CASE							:					Optional[int]=35_995					,		__SCREAMING_SNAKE_CASE							:					List[str]=35_999					,		**__SCREAMING_SNAKE_CASE							:					List[str]					,		):


           '''simple docstring'''

           __a							=    vocab_size
           __a							=    max_position_embeddings
           __a							=    d_model
           __a							=    d_ff
           __a							=    d_ext
           __a							=    d_spout
           __a							=    num_switch_layers
           __a							=    num_ext_layers
           __a							=    num_switch_layers + num_ext_layers
           __a							=    num_heads
           __a							=    num_experts
           __a							=    expert_capacity
           __a							=    dropout_rate
           __a							=    layer_norm_epsilon
           __a							=    router_bias
           __a							=    router_jitter_noise
           __a							=    router_dtype
           __a							=    router_ignore_padding_tokens
           __a							=    output_hidden_states
           __a							=    output_attentions
           __a							=    initializer_factor
           __a							=    output_router_logits
           __a							=    use_cache

           super().__init__(
               separator_token_id=__SCREAMING_SNAKE_CASE					,		pad_token_id=__SCREAMING_SNAKE_CASE					,		eos_token_id=__SCREAMING_SNAKE_CASE					,		**__SCREAMING_SNAKE_CASE					,		)





