

"""simple docstring"""




import time
import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_torch, torch_device

from ..test_modeling_common import ids_tensor


if is_torch_available():
       import torch

       from transformers.generation import (
           MaxLengthCriteria,
           MaxNewTokensCriteria,
           MaxTimeCriteria,
           StoppingCriteriaList,
           validate_stopping_criteria,
       )






@require_torch
class 	UpperCAmelCase__		(	unittest.TestCase	):






  """simple docstring"""


  def 				lowercase_		(							self						:		Optional[int]     ,       __lowerCamelCase						:		List[str] )		->							Optional[int]:
       SCREAMING_SNAKE_CASE__   =   3
       SCREAMING_SNAKE_CASE__   =   250

       SCREAMING_SNAKE_CASE__   =   ids_tensor((batch_size, length)     ,       _lowerCamelCase )
       SCREAMING_SNAKE_CASE__   =   torch.ones((batch_size, length)     ,       device=_lowerCamelCase     ,       dtype=torch.float ) / length
       return input_ids, scores






  def 				lowercase_		(							self						:		List[str] )		->							Optional[Any]:
       SCREAMING_SNAKE_CASE__,SCREAMING_SNAKE_CASE__   =   self._get_tensors(5 )

       SCREAMING_SNAKE_CASE__   =   StoppingCriteriaList(
           [
               MaxLengthCriteria(max_length=10 ),
               MaxTimeCriteria(max_time=0.1 ),
           ] )

       self.assertFalse(criteria(_lowerCamelCase     ,       _lowerCamelCase ) )

       SCREAMING_SNAKE_CASE__,SCREAMING_SNAKE_CASE__   =   self._get_tensors(9 )
       self.assertFalse(criteria(_lowerCamelCase     ,       _lowerCamelCase ) )

       SCREAMING_SNAKE_CASE__,SCREAMING_SNAKE_CASE__   =   self._get_tensors(10 )
       self.assertTrue(criteria(_lowerCamelCase     ,       _lowerCamelCase ) )






  def 				lowercase_		(							self						:		Optional[Any] )		->							Dict:
       SCREAMING_SNAKE_CASE__   =   MaxLengthCriteria(max_length=10 )

       SCREAMING_SNAKE_CASE__,SCREAMING_SNAKE_CASE__   =   self._get_tensors(5 )
       self.assertFalse(criteria(_lowerCamelCase     ,       _lowerCamelCase ) )

       SCREAMING_SNAKE_CASE__,SCREAMING_SNAKE_CASE__   =   self._get_tensors(9 )
       self.assertFalse(criteria(_lowerCamelCase     ,       _lowerCamelCase ) )

       SCREAMING_SNAKE_CASE__,SCREAMING_SNAKE_CASE__   =   self._get_tensors(10 )
       self.assertTrue(criteria(_lowerCamelCase     ,       _lowerCamelCase ) )






  def 				lowercase_		(							self						:		List[Any] )		->							List[Any]:
       SCREAMING_SNAKE_CASE__   =   MaxNewTokensCriteria(start_length=5     ,       max_new_tokens=5 )

       SCREAMING_SNAKE_CASE__,SCREAMING_SNAKE_CASE__   =   self._get_tensors(5 )
       self.assertFalse(criteria(_lowerCamelCase     ,       _lowerCamelCase ) )

       SCREAMING_SNAKE_CASE__,SCREAMING_SNAKE_CASE__   =   self._get_tensors(9 )
       self.assertFalse(criteria(_lowerCamelCase     ,       _lowerCamelCase ) )

       SCREAMING_SNAKE_CASE__,SCREAMING_SNAKE_CASE__   =   self._get_tensors(10 )
       self.assertTrue(criteria(_lowerCamelCase     ,       _lowerCamelCase ) )

       SCREAMING_SNAKE_CASE__   =   StoppingCriteriaList([criteria] )
       self.assertEqual(criteria_list.max_length     ,       10 )






  def 				lowercase_		(							self						:		Any )		->							List[str]:
       SCREAMING_SNAKE_CASE__,SCREAMING_SNAKE_CASE__   =   self._get_tensors(5 )

       SCREAMING_SNAKE_CASE__   =   MaxTimeCriteria(max_time=0.1 )
       self.assertFalse(criteria(_lowerCamelCase     ,       _lowerCamelCase ) )

       SCREAMING_SNAKE_CASE__   =   MaxTimeCriteria(max_time=0.1     ,       initial_timestamp=time.time() - 0.2 )
       self.assertTrue(criteria(_lowerCamelCase     ,       _lowerCamelCase ) )







  def 				lowercase_		(							self						:		Optional[int] )		->							List[str]:
       validate_stopping_criteria(StoppingCriteriaList([MaxLengthCriteria(10 )] )     ,       10 )

       with self.assertWarns(_lowerCamelCase ):
            validate_stopping_criteria(StoppingCriteriaList([MaxLengthCriteria(10 )] )     ,       11 )

       SCREAMING_SNAKE_CASE__   =   validate_stopping_criteria(StoppingCriteriaList()     ,       11 )

       self.assertEqual(len(_lowerCamelCase )     ,       1 )





def     UpperCAmelCase_       (						_A    ):





     '''simple docstring'''




     if divisor % 5 == 0 or divisor % 2 == 0:
          return 0
     SCREAMING_SNAKE_CASE__   =   1
     SCREAMING_SNAKE_CASE__   =   1
     while repunit:
          SCREAMING_SNAKE_CASE__   =   (10 * repunit + 1) % divisor
          repunit_index += 1
     return repunit_index
def     UpperCAmelCase_       (						_A = 1_00_00_00    ):





     '''simple docstring'''




     SCREAMING_SNAKE_CASE__   =   limit - 1
     if divisor % 2 == 0:
          divisor += 1
     while least_divisible_repunit(_A    ) <= limit:
          divisor += 2
     return divisor


if __name__ == "__main__":
       print(F"{solution() = }")


