




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"""
    Args:
        input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
            Indices of input sequence tokens in the vocabulary.

            Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
            [`PreTrainedTokenizer.__call__`] for details.

            [What are input IDs?](../glossary#input-ids)
        scores (`torch.FloatTensor` of shape `(batch_size, config.vocab_size)`):
            Prediction scores of a language modeling head. These can be scores for each vocabulary token before SoftMax
            or scores for each vocabulary token after SoftMax.
        kwargs (`Dict[str, Any]`, *optional*):
            Additional stopping criteria specific kwargs.

    Return:
        `bool`. `False` indicates we should continue, `True` indicates we should stop.

"""







class lowerCAmelCase_		(				SCREAMING_SNAKE_CASE__ ):

 '''simple docstring'''

 @add_start_docstrings(snake_case__      )
 def __call__(			self	,   _UpperCAmelCase	,   _UpperCAmelCase	,   **_UpperCAmelCase      ):
       raise NotImplementedError('''StoppingCriteria needs to be subclassed'''      )







class lowerCAmelCase_		(				SCREAMING_SNAKE_CASE__ ):

 '''simple docstring'''

 def __init__(			self	,   _UpperCAmelCase	,   _UpperCAmelCase = None      ):
       snake_case_ =   max_length
       snake_case_ =   max_position_embeddings





 @add_start_docstrings(snake_case__      )
 def __call__(			self	,   _UpperCAmelCase	,   _UpperCAmelCase	,   **_UpperCAmelCase      ):
       snake_case_ =   input_ids.shape[-1]
       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_		(				SCREAMING_SNAKE_CASE__ ):

 '''simple docstring'''

 def __init__(			self	,   _UpperCAmelCase	,   _UpperCAmelCase      ):
       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__	,   )
       snake_case_ =   start_length
       snake_case_ =   max_new_tokens
       snake_case_ =   start_length + max_new_tokens





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







class lowerCAmelCase_		(				SCREAMING_SNAKE_CASE__ ):

 '''simple docstring'''

 def __init__(			self	,   _UpperCAmelCase	,   _UpperCAmelCase = None      ):
       snake_case_ =   max_time
       snake_case_ =   time.time() if initial_timestamp is None else initial_timestamp





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







class lowerCAmelCase_		(				SCREAMING_SNAKE_CASE__ ):

 '''simple docstring'''

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





 @property
 def 		UpperCamelCase__  (			self      ):
       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  __lowerCAmelCase					(SCREAMING_SNAKE_CASE      ,      SCREAMING_SNAKE_CASE      )->						StoppingCriteriaList:




      """simple docstring"""

      snake_case_ =   stopping_criteria.max_length
      snake_case_ =   deepcopy(SCREAMING_SNAKE_CASE      )
      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'''      ,      SCREAMING_SNAKE_CASE      )
      elif stopping_max_length is None:
            new_stopping_criteria.append(MaxLengthCriteria(max_length=SCREAMING_SNAKE_CASE      )      )
      return new_stopping_criteria



def  __lowerCAmelCase					(SCREAMING_SNAKE_CASE      ,      SCREAMING_SNAKE_CASE      )->						int:




      """simple docstring"""

      return int((input_a, input_a).count(0      ) == 0      )






def  __lowerCAmelCase					()->						None:




      """simple docstring"""

      assert and_gate(0      ,      0      ) == 0
      assert and_gate(0      ,      1      ) == 0
      assert and_gate(1      ,      0      ) == 0
      assert and_gate(1      ,      1      ) == 1


if __name__ == "__main__":
   test_and_gate()
   print(and_gate(1, 0))
   print(and_gate(0, 0))
   print(and_gate(0, 1))
   print(and_gate(1, 1))