'''simple docstring'''

import unittest
from queue import Empty
from threading import Thread

from transformers import AutoTokenizer, TextIteratorStreamer, TextStreamer, is_torch_available
from transformers.testing_utils import CaptureStdout, require_torch, torch_device

from ..test_modeling_common import ids_tensor


if is_torch_available():
       import torch

       from transformers import AutoModelForCausalLM



@require_torch
class       UpperCAmelCase  (						unittest.TestCase ):





       '''simple docstring'''



       def _lowerCAmelCase(						self			)  ->  Optional[Any]:
        lowercase__    :   List[Any]						= AutoTokenizer.from_pretrained('''hf-internal-testing/tiny-random-gpt2'''			)
        lowercase__    :   Tuple						= AutoModelForCausalLM.from_pretrained('''hf-internal-testing/tiny-random-gpt2'''			).to(_a			)
        lowercase__    :   Optional[Any]						= -1

        lowercase__    :   str						= ids_tensor((1, 5)     ,       vocab_size=model.config.vocab_size			).to(_a			)
        lowercase__    :   Tuple						= model.generate(_a     ,       max_new_tokens=10     ,       do_sample=_a			)
        lowercase__    :   List[str]						= tokenizer.decode(greedy_ids[0]			)

        with CaptureStdout() as cs:
         lowercase__    :   List[Any]						= TextStreamer(_a			)
         model.generate(_a     ,       max_new_tokens=10     ,       do_sample=_a     ,       streamer=_a			)
        # The greedy text should be printed to stdout, except for the final "\n" in the streamer
        lowercase__    :   Union[str, Any]						= cs.out[:-1]

        self.assertEqual(_a     ,       _a			)

       def _lowerCAmelCase(						self			)  ->  Any:
        lowercase__    :   int						= AutoTokenizer.from_pretrained('''hf-internal-testing/tiny-random-gpt2'''			)
        lowercase__    :   Tuple						= AutoModelForCausalLM.from_pretrained('''hf-internal-testing/tiny-random-gpt2'''			).to(_a			)
        lowercase__    :   Dict						= -1

        lowercase__    :   List[Any]						= ids_tensor((1, 5)     ,       vocab_size=model.config.vocab_size			).to(_a			)
        lowercase__    :   List[str]						= model.generate(_a     ,       max_new_tokens=10     ,       do_sample=_a			)
        lowercase__    :   Union[str, Any]						= tokenizer.decode(greedy_ids[0]			)

        lowercase__    :   Union[str, Any]						= TextIteratorStreamer(_a			)
        lowercase__    :   Optional[int]						= {"input_ids": input_ids, "max_new_tokens": 10, "do_sample": False, "streamer": streamer}
        lowercase__    :   Union[str, Any]						= Thread(target=model.generate     ,       kwargs=_a			)
        thread.start()
        lowercase__    :   Any						= ""
        for new_text in streamer:
         streamer_text += new_text

        self.assertEqual(_a     ,       _a			)

       def _lowerCAmelCase(						self			)  ->  Dict:
        lowercase__    :   str						= AutoTokenizer.from_pretrained('''hf-internal-testing/tiny-random-gpt2'''			)
        lowercase__    :   Dict						= AutoModelForCausalLM.from_pretrained('''hf-internal-testing/tiny-random-gpt2'''			).to(_a			)
        lowercase__    :   List[str]						= -1

        lowercase__    :   str						= ids_tensor((1, 5)     ,       vocab_size=model.config.vocab_size			).to(_a			)
        lowercase__    :   List[Any]						= model.generate(_a     ,       max_new_tokens=10     ,       do_sample=_a			)
        lowercase__    :   Tuple						= greedy_ids[:, input_ids.shape[1] :]
        lowercase__    :   List[Any]						= tokenizer.decode(new_greedy_ids[0]			)

        with CaptureStdout() as cs:
         lowercase__    :   Dict						= TextStreamer(_a     ,       skip_prompt=_a			)
         model.generate(_a     ,       max_new_tokens=10     ,       do_sample=_a     ,       streamer=_a			)
        # The greedy text should be printed to stdout, except for the final "\n" in the streamer
        lowercase__    :   Union[str, Any]						= cs.out[:-1]

        self.assertEqual(_a     ,       _a			)

       def _lowerCAmelCase(						self			)  ->  Tuple:
        # Tests that we can pass `decode_kwargs` to the streamer to control how the tokens are decoded. Must be tested
        # with actual models -- the dummy models' tokenizers are not aligned with their models, and
        # `skip_special_tokens=True` has no effect on them
        lowercase__    :   Optional[Any]						= AutoTokenizer.from_pretrained('''distilgpt2'''			)
        lowercase__    :   str						= AutoModelForCausalLM.from_pretrained('''distilgpt2'''			).to(_a			)
        lowercase__    :   Any						= -1

        lowercase__    :   Optional[int]						= torch.ones((1, 5)     ,       device=_a			).long() * model.config.bos_token_id
        with CaptureStdout() as cs:
         lowercase__    :   Optional[int]						= TextStreamer(_a     ,       skip_special_tokens=_a			)
         model.generate(_a     ,       max_new_tokens=1     ,       do_sample=_a     ,       streamer=_a			)

        # The prompt contains a special token, so the streamer should not print it. As such, the output text, when
        # re-tokenized, must only contain one token
        lowercase__    :   Union[str, Any]						= cs.out[:-1]  # Remove the final "\n"
        lowercase__    :   int						= tokenizer(_a     ,       return_tensors='''pt'''			)
        self.assertEqual(streamer_text_tokenized.input_ids.shape     ,       (1, 1)			)


       def _lowerCAmelCase(						self			)  ->  Optional[Any]:
        lowercase__    :   Optional[Any]						= AutoTokenizer.from_pretrained('''hf-internal-testing/tiny-random-gpt2'''			)
        lowercase__    :   Optional[Any]						= AutoModelForCausalLM.from_pretrained('''hf-internal-testing/tiny-random-gpt2'''			).to(_a			)
        lowercase__    :   Tuple						= -1

        lowercase__    :   Optional[int]						= ids_tensor((1, 5)     ,       vocab_size=model.config.vocab_size			).to(_a			)
        lowercase__    :   Any						= TextIteratorStreamer(_a     ,       timeout=0.0_0_1			)
        lowercase__    :   Dict						= {"input_ids": input_ids, "max_new_tokens": 10, "do_sample": False, "streamer": streamer}
        lowercase__    :   int						= Thread(target=model.generate     ,       kwargs=_a			)
        thread.start()

        # The streamer will timeout after 0.001 seconds, so an exception will be raised
        with self.assertRaises(_a			):
         lowercase__    :   Tuple						= ""
         for new_text in streamer:
          streamer_text += new_text


'''simple docstring'''

def       __UpperCamelCase	(       ):
 lowercase__    :   Any						= [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

 lowercase__    :   Any						= 6
 lowercase__    :   Optional[Any]						= 1
 lowercase__    :   int						= 1901

 lowercase__    :   List[str]						= 0

 while year < 2001:
  day += 7

  if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
   if day > days_per_month[month - 1] and month != 2:
    month += 1
    lowercase__    :   List[Any]						= day - days_per_month[month - 2]
   elif day > 29 and month == 2:
    month += 1
    lowercase__    :   Any						= day - 29
  else:
   if day > days_per_month[month - 1]:
    month += 1
    lowercase__    :   List[Any]						= day - days_per_month[month - 2]

  if month > 12:
   year += 1
   lowercase__    :   Dict						= 1

  if year < 2001 and day == 1:
   sundays += 1
 return sundays


if __name__ == "__main__":
  print(solution())

