
"""simple docstring"""






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


__SCREAMING_SNAKE_CASE							=     logging.get_logger(__name__)


__SCREAMING_SNAKE_CASE							=     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 				a__					(						A__       ):



     @add_start_docstrings(_lowerCamelCase   )
     def __call__(							self :Any      ,  _lowerCamelCase :torch.LongTensor      ,  _lowerCamelCase :torch.FloatTensor      ,  **_lowerCamelCase :Union[str, Any]   ):







      '''simple docstring'''



      raise NotImplementedError('StoppingCriteria needs to be subclassed'   )





class 				a__					(						A__       ):



     def __init__(							self :int      ,  _lowerCamelCase :int      ,  _lowerCamelCase :Optional[int] = None   ):







      '''simple docstring'''



      UpperCamelCase_     :					List[str]   	=max_length
      UpperCamelCase_     :					Optional[int]   	=max_position_embeddings




     @add_start_docstrings(_lowerCamelCase   )
     def __call__(							self :Any      ,  _lowerCamelCase :torch.LongTensor      ,  _lowerCamelCase :torch.FloatTensor      ,  **_lowerCamelCase :Union[str, Any]   ):







      '''simple docstring'''



      UpperCamelCase_     :					List[Any]   	=input_ids.shape[-1]
      UpperCamelCase_     :					Dict   	=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 				a__					(						A__       ):



     def __init__(							self :Dict      ,  _lowerCamelCase :int      ,  _lowerCamelCase :int   ):







      '''simple docstring'''



      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.'      ,  _lowerCamelCase      ,  )
      UpperCamelCase_     :					int   	=start_length
      UpperCamelCase_     :					Tuple   	=max_new_tokens
      UpperCamelCase_     :					List[Any]   	=start_length + max_new_tokens




     @add_start_docstrings(_lowerCamelCase   )
     def __call__(							self :Union[str, Any]      ,  _lowerCamelCase :torch.LongTensor      ,  _lowerCamelCase :torch.FloatTensor      ,  **_lowerCamelCase :Tuple   ):







      '''simple docstring'''



      return input_ids.shape[-1] >= self.max_length





class 				a__					(						A__       ):



     def __init__(							self :str      ,  _lowerCamelCase :float      ,  _lowerCamelCase :Optional[float] = None   ):







      '''simple docstring'''



      UpperCamelCase_     :					Any   	=max_time
      UpperCamelCase_     :					Any   	=time.time() if initial_timestamp is None else initial_timestamp




     @add_start_docstrings(_lowerCamelCase   )
     def __call__(							self :Union[str, Any]      ,  _lowerCamelCase :torch.LongTensor      ,  _lowerCamelCase :torch.FloatTensor      ,  **_lowerCamelCase :Any   ):







      '''simple docstring'''



      return time.time() - self.initial_timestamp > self.max_time





class 				a__					(						A__       ):



     @add_start_docstrings(_lowerCamelCase   )
     def __call__(							self :Optional[Any]      ,  _lowerCamelCase :torch.LongTensor      ,  _lowerCamelCase :torch.FloatTensor      ,  **_lowerCamelCase :Dict   ):







      '''simple docstring'''



      return any(criteria(_lowerCamelCase      ,  _lowerCamelCase   ) for criteria in self   )




     @property
     def  lowerCamelCase_						(							self :List[str]   ):







      '''simple docstring'''



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




def       A_  (				__lowercase						,	__lowercase	):
 UpperCamelCase_     :					Union[str, Any]   	=stopping_criteria.max_length
 UpperCamelCase_     :					Optional[Any]   	=deepcopy(__lowercase	)
 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'						,	__lowercase	)
 elif stopping_max_length is None:
  new_stopping_criteria.append(MaxLengthCriteria(max_length=__lowercase	)	)
 return new_stopping_criteria


"""simple docstring"""






from typing import TYPE_CHECKING

from ....utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


__SCREAMING_SNAKE_CASE							=     {
    'configuration_mctct': ['MCTCT_PRETRAINED_CONFIG_ARCHIVE_MAP', 'MCTCTConfig'],
    'feature_extraction_mctct': ['MCTCTFeatureExtractor'],
    'processing_mctct': ['MCTCTProcessor'],
}


try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 __SCREAMING_SNAKE_CASE							=     [
     'MCTCT_PRETRAINED_MODEL_ARCHIVE_LIST',
     'MCTCTForCTC',
     'MCTCTModel',
     'MCTCTPreTrainedModel',
 ]


if TYPE_CHECKING:
 from .configuration_mctct import MCTCT_PRETRAINED_CONFIG_ARCHIVE_MAP, MCTCTConfig
 from .feature_extraction_mctct import MCTCTFeatureExtractor
 from .processing_mctct import MCTCTProcessor

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_mctct import MCTCT_PRETRAINED_MODEL_ARCHIVE_LIST, MCTCTForCTC, MCTCTModel, MCTCTPreTrainedModel

else:
 import sys

 __SCREAMING_SNAKE_CASE							=     _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)
