






'''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							=logging.get_logger(__name__)


UpperCamelCase							=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    (      UpperCAmelCase__						):






	"""simple docstring"""





	@add_start_docstrings(__lowerCAmelCase )
	def __call__(							self			,     __lowerCAmelCase			,     __lowerCAmelCase			,     **__lowerCAmelCase ):
							raise NotImplementedError("""StoppingCriteria needs to be subclassed""" )






class     A    (      UpperCAmelCase__						):






	"""simple docstring"""





	def __init__(							self			,     __lowerCAmelCase			,     __lowerCAmelCase = None ):
							UpperCamelCase_				:   Optional[Any]					    =							max_length
							UpperCamelCase_				:   Dict					    =							max_position_embeddings





	@add_start_docstrings(__lowerCAmelCase )
	def __call__(							self			,     __lowerCAmelCase			,     __lowerCAmelCase			,     **__lowerCAmelCase ):
							UpperCamelCase_				:   List[Any]					    =							input_ids.shape[-1]
							UpperCamelCase_				:   int					    =							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    (      UpperCAmelCase__						):






	"""simple docstring"""





	def __init__(							self			,     __lowerCAmelCase			,     __lowerCAmelCase ):
							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_				:   Optional[int]					    =							start_length
							UpperCamelCase_				:   Optional[int]					    =							max_new_tokens
							UpperCamelCase_				:   Optional[Any]					    =							start_length + max_new_tokens





	@add_start_docstrings(__lowerCAmelCase )
	def __call__(							self			,     __lowerCAmelCase			,     __lowerCAmelCase			,     **__lowerCAmelCase ):
							return input_ids.shape[-1] >= self.max_length






class     A    (      UpperCAmelCase__						):






	"""simple docstring"""





	def __init__(							self			,     __lowerCAmelCase			,     __lowerCAmelCase = None ):
							UpperCamelCase_				:   Any					    =							max_time
							UpperCamelCase_				:   Optional[int]					    =							time.time() if initial_timestamp is None else initial_timestamp





	@add_start_docstrings(__lowerCAmelCase )
	def __call__(							self			,     __lowerCAmelCase			,     __lowerCAmelCase			,     **__lowerCAmelCase ):
							return time.time() - self.initial_timestamp > self.max_time






class     A    (      UpperCAmelCase__						):






	"""simple docstring"""





	@add_start_docstrings(__lowerCAmelCase )
	def __call__(							self			,     __lowerCAmelCase			,     __lowerCAmelCase			,     **__lowerCAmelCase ):
							return any(criteria(__lowerCAmelCase			,     __lowerCAmelCase ) for criteria in self )





	@property
	def   _UpperCAmelCase       (							self ):




							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 							snake_case					(     a_							: List[Any]    ,   a_							: List[Any]	)       ->				Union[str, Any]:





						"""simple docstring"""

						UpperCamelCase_				:   List[Any]					    =							stopping_criteria.max_length
						UpperCamelCase_				:   Tuple					    =							deepcopy(a_	)
						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"""    ,   a_	)
						elif stopping_max_length is None:
												new_stopping_criteria.append(MaxLengthCriteria(max_length=a_	)	)
						return new_stopping_criteria














'''simple docstring'''

from typing import TYPE_CHECKING

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


UpperCamelCase							={
    "configuration_data2vec_audio": ["DATA2VEC_AUDIO_PRETRAINED_CONFIG_ARCHIVE_MAP", "Data2VecAudioConfig"],
    "configuration_data2vec_text": [
        "DATA2VEC_TEXT_PRETRAINED_CONFIG_ARCHIVE_MAP",
        "Data2VecTextConfig",
        "Data2VecTextOnnxConfig",
    ],
    "configuration_data2vec_vision": [
        "DATA2VEC_VISION_PRETRAINED_CONFIG_ARCHIVE_MAP",
        "Data2VecVisionConfig",
        "Data2VecVisionOnnxConfig",
    ],
}

try:
      if not is_torch_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      UpperCamelCase							=[
          "DATA2VEC_AUDIO_PRETRAINED_MODEL_ARCHIVE_LIST",
          "Data2VecAudioForAudioFrameClassification",
          "Data2VecAudioForCTC",
          "Data2VecAudioForSequenceClassification",
          "Data2VecAudioForXVector",
          "Data2VecAudioModel",
          "Data2VecAudioPreTrainedModel",
      ]
      UpperCamelCase							=[
          "DATA2VEC_TEXT_PRETRAINED_MODEL_ARCHIVE_LIST",
          "Data2VecTextForCausalLM",
          "Data2VecTextForMaskedLM",
          "Data2VecTextForMultipleChoice",
          "Data2VecTextForQuestionAnswering",
          "Data2VecTextForSequenceClassification",
          "Data2VecTextForTokenClassification",
          "Data2VecTextModel",
          "Data2VecTextPreTrainedModel",
      ]
      UpperCamelCase							=[
          "DATA2VEC_VISION_PRETRAINED_MODEL_ARCHIVE_LIST",
          "Data2VecVisionForImageClassification",
          "Data2VecVisionForMaskedImageModeling",
          "Data2VecVisionForSemanticSegmentation",
          "Data2VecVisionModel",
          "Data2VecVisionPreTrainedModel",
      ]

if is_tf_available():
      UpperCamelCase							=[
          "TFData2VecVisionForImageClassification",
          "TFData2VecVisionForSemanticSegmentation",
          "TFData2VecVisionModel",
          "TFData2VecVisionPreTrainedModel",
      ]

if TYPE_CHECKING:
      from .configuration_dataavec_audio import DATA2VEC_AUDIO_PRETRAINED_CONFIG_ARCHIVE_MAP, DataaVecAudioConfig
      from .configuration_dataavec_text import (
          DATA2VEC_TEXT_PRETRAINED_CONFIG_ARCHIVE_MAP,
          DataaVecTextConfig,
          DataaVecTextOnnxConfig,
      )
      from .configuration_dataavec_vision import (
          DATA2VEC_VISION_PRETRAINED_CONFIG_ARCHIVE_MAP,
          DataaVecVisionConfig,
          DataaVecVisionOnnxConfig,
      )

      try:
            if not is_torch_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_dataavec_audio import (
                DATA2VEC_AUDIO_PRETRAINED_MODEL_ARCHIVE_LIST,
                DataaVecAudioForAudioFrameClassification,
                DataaVecAudioForCTC,
                DataaVecAudioForSequenceClassification,
                DataaVecAudioForXVector,
                DataaVecAudioModel,
                DataaVecAudioPreTrainedModel,
            )
            from .modeling_dataavec_text import (
                DATA2VEC_TEXT_PRETRAINED_MODEL_ARCHIVE_LIST,
                DataaVecTextForCausalLM,
                DataaVecTextForMaskedLM,
                DataaVecTextForMultipleChoice,
                DataaVecTextForQuestionAnswering,
                DataaVecTextForSequenceClassification,
                DataaVecTextForTokenClassification,
                DataaVecTextModel,
                DataaVecTextPreTrainedModel,
            )
            from .modeling_dataavec_vision import (
                DATA2VEC_VISION_PRETRAINED_MODEL_ARCHIVE_LIST,
                DataaVecVisionForImageClassification,
                DataaVecVisionForMaskedImageModeling,
                DataaVecVisionForSemanticSegmentation,
                DataaVecVisionModel,
                DataaVecVisionPreTrainedModel,
            )
      if is_tf_available():
            from .modeling_tf_dataavec_vision import (
                TFDataaVecVisionForImageClassification,
                TFDataaVecVisionForSemanticSegmentation,
                TFDataaVecVisionModel,
                TFDataaVecVisionPreTrainedModel,
            )

else:
      import sys

      UpperCamelCase							=_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)






