


'''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


UpperCAmelCase_			:  Tuple										=   logging.get_logger(__name__)


UpperCAmelCase_			:  Dict										=   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       (     snake_case_					):




 '''simple docstring'''


 @add_start_docstrings(__lowercase    )
 def __call__(   self   ,   __lowercase   ,   __lowercase   ,   **__lowercase    ):

  """simple docstring"""







  raise NotImplementedError('StoppingCriteria needs to be subclassed'    )


class     _lowerCamelCase       (     snake_case_					):




 '''simple docstring'''


 def __init__(   self   ,   __lowercase   ,   __lowercase = None    ):

  """simple docstring"""







  __A	:		str	  =      max_length
  __A	:		List[Any]	  =      max_position_embeddings







 @add_start_docstrings(__lowercase    )
 def __call__(   self   ,   __lowercase   ,   __lowercase   ,   **__lowercase    ):

  """simple docstring"""







  __A	:		Dict	  =      input_ids.shape[-1]
  __A	:		Optional[Any]	  =      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       (     snake_case_					):




 '''simple docstring'''


 def __init__(   self   ,   __lowercase   ,   __lowercase    ):

  """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.'   ,   __lowercase   ,   )
  __A	:		Optional[Any]	  =      start_length
  __A	:		Optional[Any]	  =      max_new_tokens
  __A	:		Tuple	  =      start_length + max_new_tokens







 @add_start_docstrings(__lowercase    )
 def __call__(   self   ,   __lowercase   ,   __lowercase   ,   **__lowercase    ):

  """simple docstring"""







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


class     _lowerCamelCase       (     snake_case_					):




 '''simple docstring'''


 def __init__(   self   ,   __lowercase   ,   __lowercase = None    ):

  """simple docstring"""







  __A	:		Union[str, Any]	  =      max_time
  __A	:		Union[str, Any]	  =      time.time() if initial_timestamp is None else initial_timestamp







 @add_start_docstrings(__lowercase    )
 def __call__(   self   ,   __lowercase   ,   __lowercase   ,   **__lowercase    ):

  """simple docstring"""







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


class     _lowerCamelCase       (     snake_case_					):




 '''simple docstring'''


 @add_start_docstrings(__lowercase    )
 def __call__(   self   ,   __lowercase   ,   __lowercase   ,   **__lowercase    ):

  """simple docstring"""







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







 @property
 def 			snake_case__ (   self    ):

  """simple docstring"""







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


def       _lowercase							(					UpperCamelCase__							:       StoppingCriteriaList,					UpperCamelCase__							:       int      ):
 __A	:		List[str]	  =      stopping_criteria.max_length
 __A	:		Optional[int]	  =      deepcopy(UpperCamelCase__      )
 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',					UpperCamelCase__      )
 elif stopping_max_length is None:
  new_stopping_criteria.append(MaxLengthCriteria(max_length=UpperCamelCase__      )      )
 return new_stopping_criteria










'''simple docstring'''
from typing import TYPE_CHECKING

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


UpperCAmelCase_			:  Optional[Any]										=   {
    'configuration_transfo_xl': ['TRANSFO_XL_PRETRAINED_CONFIG_ARCHIVE_MAP', 'TransfoXLConfig'],
    'tokenization_transfo_xl': ['TransfoXLCorpus', 'TransfoXLTokenizer'],
}

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 UpperCAmelCase_			:  Any										=   [
     'TRANSFO_XL_PRETRAINED_MODEL_ARCHIVE_LIST',
     'AdaptiveEmbedding',
     'TransfoXLForSequenceClassification',
     'TransfoXLLMHeadModel',
     'TransfoXLModel',
     'TransfoXLPreTrainedModel',
     'load_tf_weights_in_transfo_xl',
 ]

try:
 if not is_tf_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 UpperCAmelCase_			:  Optional[Any]										=   [
     'TF_TRANSFO_XL_PRETRAINED_MODEL_ARCHIVE_LIST',
     'TFAdaptiveEmbedding',
     'TFTransfoXLForSequenceClassification',
     'TFTransfoXLLMHeadModel',
     'TFTransfoXLMainLayer',
     'TFTransfoXLModel',
     'TFTransfoXLPreTrainedModel',
 ]


if TYPE_CHECKING:
 from .configuration_transfo_xl import TRANSFO_XL_PRETRAINED_CONFIG_ARCHIVE_MAP, TransfoXLConfig
 from .tokenization_transfo_xl import TransfoXLCorpus, TransfoXLTokenizer

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_transfo_xl import (
      TRANSFO_XL_PRETRAINED_MODEL_ARCHIVE_LIST,
      AdaptiveEmbedding,
      TransfoXLForSequenceClassification,
      TransfoXLLMHeadModel,
      TransfoXLModel,
      TransfoXLPreTrainedModel,
      load_tf_weights_in_transfo_xl,
  )

 try:
  if not is_tf_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_tf_transfo_xl import (
      TF_TRANSFO_XL_PRETRAINED_MODEL_ARCHIVE_LIST,
      TFAdaptiveEmbedding,
      TFTransfoXLForSequenceClassification,
      TFTransfoXLLMHeadModel,
      TFTransfoXLMainLayer,
      TFTransfoXLModel,
      TFTransfoXLPreTrainedModel,
  )

else:
 import sys

 UpperCAmelCase_			:  Optional[int]										=   _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)






