




import time
import warnings
from abc import ABC
from copy import deepcopy
from typing import Optional

import torch

from ..utils import add_start_docstrings, logging


lowerCamelCase__ :   List[Any]					=							logging.get_logger(__name__)


lowerCamelCase__ :   Optional[int]					=							r'\n    Args:\n        input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):\n            Indices of input sequence tokens in the vocabulary.\n\n            Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and\n            [`PreTrainedTokenizer.__call__`] for details.\n\n            [What are input IDs?](../glossary#input-ids)\n        scores (`torch.FloatTensor` of shape `(batch_size, config.vocab_size)`):\n            Prediction scores of a language modeling head. These can be scores for each vocabulary token before SoftMax\n            or scores for each vocabulary token after SoftMax.\n        kwargs (`Dict[str, Any]`, *optional*):\n            Additional stopping criteria specific kwargs.\n\n    Return:\n        `bool`. `False` indicates we should continue, `True` indicates we should stop.\n\n'





class        lowerCamelCase_							(      A_					):


 '''simple docstring'''







 @add_start_docstrings(snake_case__						)
 def __call__(							self  :		Union[str, Any]				,				_lowerCAmelCase  :		torch.LongTensor				,				_lowerCAmelCase  :		torch.FloatTensor				,				**_lowerCAmelCase  :		Optional[int]						):
       raise NotImplementedError('StoppingCriteria needs to be subclassed'						)





class        lowerCamelCase_							(      A_					):


 '''simple docstring'''







 def __init__(							self  :		Union[str, Any]				,				_lowerCAmelCase  :		int				,				_lowerCAmelCase  :		Optional[int] = None						):
       SCREAMING_SNAKE_CASE_							=			max_length
       SCREAMING_SNAKE_CASE_							=			max_position_embeddings




 @add_start_docstrings(snake_case__						)
 def __call__(							self  :		str				,				_lowerCAmelCase  :		torch.LongTensor				,				_lowerCAmelCase  :		torch.FloatTensor				,				**_lowerCAmelCase  :		int						):
       SCREAMING_SNAKE_CASE_							=			input_ids.shape[-1]
       SCREAMING_SNAKE_CASE_							=			cur_len >= self.max_length
       if self.max_position_embeddings is not None and not is_done and cur_len >= self.max_position_embeddings:
             logger.warning_once(
                 'This is a friendly reminder - the current text generation call will exceed the model\'s predefined '
                 F"maximum length ({self.max_position_embeddings}). Depending on the model, you may observe "
                 'exceptions, performance degradation, or nothing at all.'						)
       return is_done





class        lowerCamelCase_							(      A_					):


 '''simple docstring'''







 def __init__(							self  :		List[Any]				,				_lowerCAmelCase  :		int				,				_lowerCAmelCase  :		int						):
       warnings.warn(
           'The class `MaxNewTokensCriteria` is deprecated. '
           F"Please use `MaxLengthCriteria(max_length={start_length + max_new_tokens})` "
           'with `max_length = start_length + max_new_tokens` instead.'				,				snake_case__				,				)
       SCREAMING_SNAKE_CASE_							=			start_length
       SCREAMING_SNAKE_CASE_							=			max_new_tokens
       SCREAMING_SNAKE_CASE_							=			start_length + max_new_tokens




 @add_start_docstrings(snake_case__						)
 def __call__(							self  :		Optional[Any]				,				_lowerCAmelCase  :		torch.LongTensor				,				_lowerCAmelCase  :		torch.FloatTensor				,				**_lowerCAmelCase  :		Any						):
       return input_ids.shape[-1] >= self.max_length





class        lowerCamelCase_							(      A_					):


 '''simple docstring'''







 def __init__(							self  :		List[str]				,				_lowerCAmelCase  :		float				,				_lowerCAmelCase  :		Optional[float] = None						):
       SCREAMING_SNAKE_CASE_							=			max_time
       SCREAMING_SNAKE_CASE_							=			time.time() if initial_timestamp is None else initial_timestamp




 @add_start_docstrings(snake_case__						)
 def __call__(							self  :		Dict				,				_lowerCAmelCase  :		torch.LongTensor				,				_lowerCAmelCase  :		torch.FloatTensor				,				**_lowerCAmelCase  :		str						):
       return time.time() - self.initial_timestamp > self.max_time





class        lowerCamelCase_							(      A_					):


 '''simple docstring'''







 @add_start_docstrings(snake_case__						)
 def __call__(							self  :		Any				,				_lowerCAmelCase  :		torch.LongTensor				,				_lowerCAmelCase  :		torch.FloatTensor				,				**_lowerCAmelCase  :		List[str]						):
       return any(criteria(snake_case__				,				snake_case__						) for criteria in self						)




 @property
 def       lowerCAmelCase_  (							self  :		Optional[int]						):


       for stopping_criterium in self:
             if isinstance(snake_case__				,				snake_case__						):
                   return stopping_criterium.max_length
             elif isinstance(snake_case__				,				snake_case__						):
                   return stopping_criterium.max_length
       return None


def 					UpperCAmelCase_							(      __UpperCAmelCase						:	StoppingCriteriaList			,			__UpperCAmelCase						:	int							)					-> Optional[Any]:
      SCREAMING_SNAKE_CASE_							=			stopping_criteria.max_length
      SCREAMING_SNAKE_CASE_							=			deepcopy(__lowerCamelCase							)
      if stopping_max_length is not None and stopping_max_length != max_length:
            warnings.warn('You set different `max_length` for stopping criteria and `max_length` parameter'			,			__lowerCamelCase							)
      elif stopping_max_length is None:
            new_stopping_criteria.append(MaxLengthCriteria(max_length=__lowerCamelCase							)							)
      return new_stopping_criteria

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


__lowerCamelCase							=       logging.get_logger(__name__)

__lowerCamelCase							=       {
    # See all MEGATRON_BERT models at https://huggingface.co/models?filter=bert
}






class   UpperCAmelCase		(						A_ ):
   A__					:		List[str]						     =     "megatron-bert"



   def __init__(self		:					Optional[int]    ,						snake_case__		:					List[str]=2_90_56    ,						snake_case__		:					List[Any]=10_24    ,						snake_case__		:					str=24    ,						snake_case__		:					Tuple=16    ,						snake_case__		:					Union[str, Any]=40_96    ,						snake_case__		:					str="gelu"    ,						snake_case__		:					str=0.1    ,						snake_case__		:					Optional[int]=0.1    ,						snake_case__		:					Tuple=5_12    ,						snake_case__		:					Union[str, Any]=2    ,						snake_case__		:					Dict=0.02    ,						snake_case__		:					List[Any]=1e-12    ,						snake_case__		:					int=0    ,						snake_case__		:					Tuple="absolute"    ,						snake_case__		:					Any=True    ,						**snake_case__		:					Union[str, Any]    ,						)		->	Optional[Any]:


          '''simple docstring'''


          super().__init__(pad_token_id=snake_case__    ,						**snake_case__ )

          snake_case       :   Tuple							=      vocab_size
          snake_case       :   str							=      hidden_size
          snake_case       :   str							=      num_hidden_layers
          snake_case       :   str							=      num_attention_heads
          snake_case       :   Optional[int]							=      hidden_act
          snake_case       :   int							=      intermediate_size
          snake_case       :   List[str]							=      hidden_dropout_prob
          snake_case       :   Union[str, Any]							=      attention_probs_dropout_prob
          snake_case       :   Dict							=      max_position_embeddings
          snake_case       :   List[str]							=      type_vocab_size
          snake_case       :   List[str]							=      initializer_range
          snake_case       :   Tuple							=      layer_norm_eps
          snake_case       :   int							=      position_embedding_type
          snake_case       :   str							=      use_cache





