

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     :   Union[str, Any]										=  logging.get_logger(__name__)


lowerCAmelCase     :   Optional[Any]										=  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 ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					**_SCREAMING_SNAKE_CASE					):





        """simple docstring"""







        raise NotImplementedError('StoppingCriteria needs to be subclassed'					)

class  _A		(  _A):

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





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  str           =     max_length
        SCREAMING_SNAKE_CASE_				:  Optional[int]           =     max_position_embeddings



  @add_start_docstrings(__lowerCamelCase					)
  def __call__(				self ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					**_SCREAMING_SNAKE_CASE					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  List[Any]           =     input_ids.shape[-1]
        SCREAMING_SNAKE_CASE_				:  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  _A		(  _A):

  def __init__(				self ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE					):





        """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 ,					)
        SCREAMING_SNAKE_CASE_				:  str           =     start_length
        SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     max_new_tokens
        SCREAMING_SNAKE_CASE_				:  Dict           =     start_length + max_new_tokens



  @add_start_docstrings(__lowerCamelCase					)
  def __call__(				self ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					**_SCREAMING_SNAKE_CASE					):





        """simple docstring"""







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

class  _A		(  _A):

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





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  str           =     max_time
        SCREAMING_SNAKE_CASE_				:  Dict           =     time.time() if initial_timestamp is None else initial_timestamp



  @add_start_docstrings(__lowerCamelCase					)
  def __call__(				self ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					**_SCREAMING_SNAKE_CASE					):





        """simple docstring"""







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

class  _A		(  _A):

  @add_start_docstrings(__lowerCamelCase					)
  def __call__(				self ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE ,					**_SCREAMING_SNAKE_CASE					):





        """simple docstring"""







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



  @property
  def  UpperCAmelCase    (				self					):





        """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_  (							a					,   a  ):

      """simple docstring"""



      SCREAMING_SNAKE_CASE_				:  Optional[int]           =     stopping_criteria.max_length
      SCREAMING_SNAKE_CASE_				:  Any           =     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









import copy
import os
from typing import Union

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


lowerCAmelCase     :   Optional[int]						     =  logging.get_logger(__name__)

lowerCAmelCase     :   str						     =  {
    'microsoft/git-base': 'https://huggingface.co/microsoft/git-base/resolve/main/config.json',
}
class  _A		(  __magic_name__):
  SCREAMING_SNAKE_CASE    :      Optional[int]       =  '''git_vision_model'''

  def __init__(				self ,					_SCREAMING_SNAKE_CASE=768 ,					_SCREAMING_SNAKE_CASE=3072 ,					_SCREAMING_SNAKE_CASE=12 ,					_SCREAMING_SNAKE_CASE=12 ,					_SCREAMING_SNAKE_CASE=3 ,					_SCREAMING_SNAKE_CASE=224 ,					_SCREAMING_SNAKE_CASE=16 ,					_SCREAMING_SNAKE_CASE="quick_gelu" ,					_SCREAMING_SNAKE_CASE=1e-5 ,					_SCREAMING_SNAKE_CASE=0.0 ,					_SCREAMING_SNAKE_CASE=0.02 ,					**_SCREAMING_SNAKE_CASE ,					):





        """simple docstring"""







        super().__init__(**_SCREAMING_SNAKE_CASE					)

        SCREAMING_SNAKE_CASE_				:  List[str]           =     hidden_size
        SCREAMING_SNAKE_CASE_				:  Any           =     intermediate_size
        SCREAMING_SNAKE_CASE_				:  List[str]           =     num_hidden_layers
        SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     num_attention_heads
        SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     num_channels
        SCREAMING_SNAKE_CASE_				:  Dict           =     patch_size
        SCREAMING_SNAKE_CASE_				:  Any           =     image_size
        SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     initializer_range
        SCREAMING_SNAKE_CASE_				:  Any           =     attention_dropout
        SCREAMING_SNAKE_CASE_				:  List[Any]           =     layer_norm_eps
        SCREAMING_SNAKE_CASE_				:  Tuple           =     hidden_act



  @classmethod
  def  UpperCAmelCase    (				cls ,					_SCREAMING_SNAKE_CASE ,					**_SCREAMING_SNAKE_CASE					):





        """simple docstring"""







        cls._set_token_in_kwargs(_SCREAMING_SNAKE_CASE					)

        SCREAMING_SNAKE_CASE_       ,						SCREAMING_SNAKE_CASE_				:  str           =     cls.get_config_dict(_SCREAMING_SNAKE_CASE ,					**_SCREAMING_SNAKE_CASE					)

        # get the vision config dict if we are loading from GITConfig
        if config_dict.get('model_type'					) == "git":
              SCREAMING_SNAKE_CASE_				:  str           =     config_dict['vision_config']

        if "model_type" in config_dict and hasattr(cls ,					'model_type'					) and config_dict["model_type"] != cls.model_type:
              logger.warning(
                  f"You are using a model of type {config_dict['model_type']} to instantiate a model of type "
                  f"{cls.model_type}. This is not supported for all configurations of models and can yield errors."					)

        return cls.from_dict(_SCREAMING_SNAKE_CASE ,					**_SCREAMING_SNAKE_CASE					)

class  _A		(  __magic_name__):
  SCREAMING_SNAKE_CASE    :      Optional[Any]       =  '''git'''

  def __init__(				self ,					_SCREAMING_SNAKE_CASE=None ,					_SCREAMING_SNAKE_CASE=3_0522 ,					_SCREAMING_SNAKE_CASE=768 ,					_SCREAMING_SNAKE_CASE=6 ,					_SCREAMING_SNAKE_CASE=12 ,					_SCREAMING_SNAKE_CASE=3072 ,					_SCREAMING_SNAKE_CASE="gelu" ,					_SCREAMING_SNAKE_CASE=0.1 ,					_SCREAMING_SNAKE_CASE=0.1 ,					_SCREAMING_SNAKE_CASE=1024 ,					_SCREAMING_SNAKE_CASE=0.02 ,					_SCREAMING_SNAKE_CASE=1e-12 ,					_SCREAMING_SNAKE_CASE=0 ,					_SCREAMING_SNAKE_CASE="absolute" ,					_SCREAMING_SNAKE_CASE=True ,					_SCREAMING_SNAKE_CASE=False ,					_SCREAMING_SNAKE_CASE=101 ,					_SCREAMING_SNAKE_CASE=102 ,					_SCREAMING_SNAKE_CASE=None ,					**_SCREAMING_SNAKE_CASE ,					):





        """simple docstring"""







        super().__init__(bos_token_id=_SCREAMING_SNAKE_CASE ,					eos_token_id=_SCREAMING_SNAKE_CASE ,					pad_token_id=_SCREAMING_SNAKE_CASE ,					**_SCREAMING_SNAKE_CASE					)

        if vision_config is None:
              SCREAMING_SNAKE_CASE_				:  Any           =     {}
              logger.info('vision_config is None. initializing the GitVisionConfig with default values.'					)

        SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     GitVisionConfig(**_SCREAMING_SNAKE_CASE					)
        SCREAMING_SNAKE_CASE_				:  Dict           =     vocab_size
        SCREAMING_SNAKE_CASE_				:  List[Any]           =     hidden_size
        SCREAMING_SNAKE_CASE_				:  Dict           =     num_hidden_layers
        SCREAMING_SNAKE_CASE_				:  List[str]           =     num_attention_heads
        SCREAMING_SNAKE_CASE_				:  List[str]           =     hidden_act
        SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     intermediate_size
        SCREAMING_SNAKE_CASE_				:  Any           =     hidden_dropout_prob
        SCREAMING_SNAKE_CASE_				:  Tuple           =     attention_probs_dropout_prob
        SCREAMING_SNAKE_CASE_				:  int           =     max_position_embeddings
        SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     initializer_range
        SCREAMING_SNAKE_CASE_				:  int           =     layer_norm_eps
        SCREAMING_SNAKE_CASE_				:  List[str]           =     position_embedding_type
        SCREAMING_SNAKE_CASE_				:  List[str]           =     use_cache
        SCREAMING_SNAKE_CASE_				:  Optional[int]           =     tie_word_embeddings
        SCREAMING_SNAKE_CASE_				:  List[Any]           =     num_image_with_embedding

        SCREAMING_SNAKE_CASE_				:  Tuple           =     bos_token_id
        SCREAMING_SNAKE_CASE_				:  Optional[int]           =     eos_token_id



  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  List[str]           =     copy.deepcopy(self.__dict__					)
        SCREAMING_SNAKE_CASE_				:  List[str]           =     self.vision_config.to_dict()
        SCREAMING_SNAKE_CASE_				:  int           =     self.__class__.model_type
        return output






