





"""simple docstring"""
import unittest

from transformers.testing_utils import is_torch_available, require_torch, tooslow

from ...generation.test_utils import torch_device
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
  import torch

  from transformers import (
      CpmAntConfig,
      CpmAntForCausalLM,
      CpmAntModel,
      CpmAntTokenizer,
  )






@require_torch
class       _SCREAMING_SNAKE_CASE:




       def __init__(		self	,SCREAMING_SNAKE_CASE__	,SCREAMING_SNAKE_CASE__=2	,SCREAMING_SNAKE_CASE__=8	,SCREAMING_SNAKE_CASE__=True	,SCREAMING_SNAKE_CASE__=False	,SCREAMING_SNAKE_CASE__=False	,SCREAMING_SNAKE_CASE__=False	,SCREAMING_SNAKE_CASE__=False	,SCREAMING_SNAKE_CASE__=99	,SCREAMING_SNAKE_CASE__=32	,SCREAMING_SNAKE_CASE__=3	,SCREAMING_SNAKE_CASE__=4	,SCREAMING_SNAKE_CASE__=37	,SCREAMING_SNAKE_CASE__=32	,SCREAMING_SNAKE_CASE__=1_28	,SCREAMING_SNAKE_CASE__=8	,SCREAMING_SNAKE_CASE__=8	,SCREAMING_SNAKE_CASE__=8	,SCREAMING_SNAKE_CASE__=1.0	,SCREAMING_SNAKE_CASE__=True	,)    ->   Optional[int]:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE     :Dict	       =						parent
             __SCREAMING_SNAKE_CASE     :Optional[Any]	       =						batch_size
             __SCREAMING_SNAKE_CASE     :Dict	       =						seq_length
             __SCREAMING_SNAKE_CASE     :Optional[int]	       =						is_training
             __SCREAMING_SNAKE_CASE     :Optional[Any]	       =						use_token_type_ids
             __SCREAMING_SNAKE_CASE     :Optional[Any]	       =						use_input_mask
             __SCREAMING_SNAKE_CASE     :Optional[int]	       =						use_labels
             __SCREAMING_SNAKE_CASE     :List[Any]	       =						use_mc_token_ids
             __SCREAMING_SNAKE_CASE     :List[Any]	       =						vocab_size
             __SCREAMING_SNAKE_CASE     :Any	       =						hidden_size
             __SCREAMING_SNAKE_CASE     :List[str]	       =						num_hidden_layers
             __SCREAMING_SNAKE_CASE     :int	       =						num_attention_heads
             __SCREAMING_SNAKE_CASE     :List[str]	       =						intermediate_size
             __SCREAMING_SNAKE_CASE     :Tuple	       =						num_buckets
             __SCREAMING_SNAKE_CASE     :Dict	       =						max_distance
             __SCREAMING_SNAKE_CASE     :int	       =						prompt_length
             __SCREAMING_SNAKE_CASE     :Dict	       =						prompt_types
             __SCREAMING_SNAKE_CASE     :str	       =						segment_types
             __SCREAMING_SNAKE_CASE     :str	       =						init_std
             __SCREAMING_SNAKE_CASE     :Optional[Any]	       =						return_dict




       def 					_UpperCamelCase  (		self							)    ->   int:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE     :Any	       =						{}
             __SCREAMING_SNAKE_CASE     :Dict	       =						ids_tensor([self.batch_size, self.seq_length]	,self.vocab_size							).type(torch.intaa							)
             __SCREAMING_SNAKE_CASE     :Union[str, Any]	       =						False

             __SCREAMING_SNAKE_CASE     :Any	       =						self.get_config()

             return (config, input_ids)




       def 					_UpperCamelCase  (		self							)    ->   List[str]:





             """simple docstring"""






             return CpmAntConfig(
                 vocab_size=self.vocab_size	,hidden_size=self.hidden_size	,num_hidden_layers=self.num_hidden_layers	,num_attention_heads=self.num_attention_heads	,dim_ff=self.intermediate_size	,position_bias_num_buckets=self.num_buckets	,position_bias_max_distance=self.max_distance	,prompt_types=self.prompt_types	,prompt_length=self.prompt_length	,segment_types=self.segment_types	,use_cache=SCREAMING_SNAKE_CASE__	,init_std=self.init_std	,return_dict=self.return_dict	,)




       def 					_UpperCamelCase  (		self	,SCREAMING_SNAKE_CASE__	,SCREAMING_SNAKE_CASE__	,*SCREAMING_SNAKE_CASE__							)    ->   int:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE     :str	       =						CpmAntModel(config=SCREAMING_SNAKE_CASE__							)
             model.to(SCREAMING_SNAKE_CASE__							)
             model.eval()

             __SCREAMING_SNAKE_CASE     :Optional[int]	       =						model(**SCREAMING_SNAKE_CASE__							).last_hidden_state

             self.parent.assertEqual(hidden_states.shape	,(self.batch_size, self.seq_length, config.hidden_size)							)




       def 					_UpperCamelCase  (		self	,SCREAMING_SNAKE_CASE__	,SCREAMING_SNAKE_CASE__	,*SCREAMING_SNAKE_CASE__							)    ->   Dict:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE     :Dict	       =						CpmAntForCausalLM(SCREAMING_SNAKE_CASE__							)
             model.to(SCREAMING_SNAKE_CASE__							)
             __SCREAMING_SNAKE_CASE     :List[str]	       =						input_ids['''input_ids'''].to(SCREAMING_SNAKE_CASE__							)
             model.eval()

             __SCREAMING_SNAKE_CASE     :List[Any]	       =						model(**SCREAMING_SNAKE_CASE__							)
             self.parent.assertEqual(
                 model_output.logits.shape	,(self.batch_size, self.seq_length, config.vocab_size + config.prompt_types * config.prompt_length)	,)




       def 					_UpperCamelCase  (		self							)    ->   int:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       ,__SCREAMING_SNAKE_CASE     :Tuple	       =						self.prepare_config_and_inputs()
             return config, inputs_dict






@require_torch
class       _SCREAMING_SNAKE_CASE(     A					,			A					,			unittest.TestCase						):
       SCREAMING_SNAKE_CASE_     :   Optional[Any]					=						(CpmAntModel, CpmAntForCausalLM) if is_torch_available() else ()
       SCREAMING_SNAKE_CASE_     :   Dict					=						(
           {'''feature-extraction''': CpmAntModel, '''text-generation''': CpmAntForCausalLM} if is_torch_available() else {}
       )

       SCREAMING_SNAKE_CASE_     :   Optional[Any]					=						False
       SCREAMING_SNAKE_CASE_     :   Optional[Any]					=						False
       SCREAMING_SNAKE_CASE_     :   List[str]					=						False
       SCREAMING_SNAKE_CASE_     :   str					=						False
       SCREAMING_SNAKE_CASE_     :   str					=						False




       def 					_UpperCamelCase  (		self							)    ->   Tuple:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE     :Dict	       =						CpmAntModelTester(self							)
             __SCREAMING_SNAKE_CASE     :Dict	       =						ConfigTester(self	,config_class=SCREAMING_SNAKE_CASE__							)




       def 					_UpperCamelCase  (		self							)    ->   Any:





             """simple docstring"""






             self.config_tester.create_and_test_config_common_properties()
             self.config_tester.create_and_test_config_to_json_string()
             self.config_tester.create_and_test_config_to_json_file()
             self.config_tester.create_and_test_config_from_and_save_pretrained()
             self.config_tester.check_config_can_be_init_without_params()
             self.config_tester.check_config_arguments_init()




       def 					_UpperCamelCase  (		self							)    ->   Dict:





             """simple docstring"""






             unittest.skip('''CPMAnt doesn\'t support input_embeds.'''							)(self.test_inputs_embeds							)




       def 					_UpperCamelCase  (		self							)    ->   List[Any]:





             """simple docstring"""






             unittest.skip(
                 '''CPMAnt doesn\'t support retain grad in hidden_states or attentions, because prompt management will peel off the output.hidden_states from graph.\
                 So is attentions. We strongly recommand you use loss to tune model.'''							)(self.test_retain_grad_hidden_states_attentions							)




       def 					_UpperCamelCase  (		self							)    ->   str:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       ,__SCREAMING_SNAKE_CASE     :List[str]	       =						self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_cpmant_model(SCREAMING_SNAKE_CASE__	,SCREAMING_SNAKE_CASE__							)




       def 					_UpperCamelCase  (		self							)    ->   Optional[int]:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       ,__SCREAMING_SNAKE_CASE     :Any	       =						self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_lm_head_model(SCREAMING_SNAKE_CASE__	,SCREAMING_SNAKE_CASE__							)






@require_torch
class       _SCREAMING_SNAKE_CASE(     unittest.TestCase						):




       @tooslow
       def 					_UpperCamelCase  (		self							)    ->   Dict:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE     :List[Any]	       =						'''今天天气真好！'''
             __SCREAMING_SNAKE_CASE     :Optional[int]	       =						'''openbmb/cpm-ant-10b'''
             __SCREAMING_SNAKE_CASE     :Dict	       =						CpmAntModel.from_pretrained(SCREAMING_SNAKE_CASE__							)
             __SCREAMING_SNAKE_CASE     :Tuple	       =						CpmAntTokenizer.from_pretrained(SCREAMING_SNAKE_CASE__							)
             __SCREAMING_SNAKE_CASE     :Tuple	       =						tokenizer(SCREAMING_SNAKE_CASE__	,return_tensors='''pt'''							)
             __SCREAMING_SNAKE_CASE     :str	       =						model(**SCREAMING_SNAKE_CASE__							).last_hidden_state

             __SCREAMING_SNAKE_CASE     :Tuple	       =						torch.tensor(
                 [[[6.1_7_0_8, 5.9_2_4_4, 1.0_8_3_5], [6.5_2_0_7, 6.2_8_9_3, -1_1.3_3_2_4], [-1.0_1_0_7, -0.0_5_7_6, -5.9_5_7_7]]]	,)
             self.assertTrue(torch.allclose(hidden_states[:, :3, :3]	,SCREAMING_SNAKE_CASE__	,atol=1E-2							)							)






@require_torch
class       _SCREAMING_SNAKE_CASE(     unittest.TestCase						):




       @tooslow
       def 					_UpperCamelCase  (		self							)    ->   int:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE     :Optional[Any]	       =						'''今天天气真好！'''
             __SCREAMING_SNAKE_CASE     :str	       =						'''openbmb/cpm-ant-10b'''
             __SCREAMING_SNAKE_CASE     :Any	       =						CpmAntForCausalLM.from_pretrained(SCREAMING_SNAKE_CASE__							)
             __SCREAMING_SNAKE_CASE     :Tuple	       =						CpmAntTokenizer.from_pretrained(SCREAMING_SNAKE_CASE__							)
             __SCREAMING_SNAKE_CASE     :Dict	       =						tokenizer(SCREAMING_SNAKE_CASE__	,return_tensors='''pt'''							)
             __SCREAMING_SNAKE_CASE     :int	       =						model(**SCREAMING_SNAKE_CASE__							).logits

             __SCREAMING_SNAKE_CASE     :str	       =						torch.tensor(
                 [[[-6.4_2_6_7, -6.4_0_8_3, -6.3_9_5_8], [-5.8_8_0_2, -5.9_4_4_7, -5.7_8_1_1], [-5.3_8_9_6, -5.4_8_2_0, -5.4_2_9_5]]]	,)
             self.assertTrue(torch.allclose(hidden_states[:, :3, :3]	,SCREAMING_SNAKE_CASE__	,atol=1E-2							)							)




       @tooslow
       def 					_UpperCamelCase  (		self							)    ->   int:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE     :List[str]	       =						'''openbmb/cpm-ant-10b'''
             __SCREAMING_SNAKE_CASE     :str	       =						CpmAntForCausalLM.from_pretrained(SCREAMING_SNAKE_CASE__							)
             __SCREAMING_SNAKE_CASE     :List[str]	       =						CpmAntTokenizer.from_pretrained(SCREAMING_SNAKE_CASE__							)
             __SCREAMING_SNAKE_CASE     :List[Any]	       =						'''今天天气不错，'''
             __SCREAMING_SNAKE_CASE     :Any	       =						'''今天天气不错，阳光明媚，我和妈妈一起去超市买东西。\n在超市里，我看到了一个很好玩的玩具，它的名字叫“机器人”。它有一个圆圆的脑袋，两只圆圆的眼睛，还有一个圆圆的'''
             __SCREAMING_SNAKE_CASE     :str	       =						tokenizer(SCREAMING_SNAKE_CASE__	,return_tensors='''pt'''							)
             __SCREAMING_SNAKE_CASE     :Tuple	       =						model.generate(**SCREAMING_SNAKE_CASE__							)
             __SCREAMING_SNAKE_CASE     :Optional[int]	       =						tokenizer.batch_decode(SCREAMING_SNAKE_CASE__							)
             self.assertEqual(SCREAMING_SNAKE_CASE__	,SCREAMING_SNAKE_CASE__							)




       @tooslow
       def 					_UpperCamelCase  (		self							)    ->   Tuple:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE     :str	       =						'''openbmb/cpm-ant-10b'''
             __SCREAMING_SNAKE_CASE     :List[Any]	       =						CpmAntForCausalLM.from_pretrained(SCREAMING_SNAKE_CASE__							)
             __SCREAMING_SNAKE_CASE     :Optional[int]	       =						CpmAntTokenizer.from_pretrained(SCREAMING_SNAKE_CASE__							)
             __SCREAMING_SNAKE_CASE     :List[str]	       =						['''今天天气不错，''', '''新年快乐，万事如意！''']
             __SCREAMING_SNAKE_CASE     :List[str]	       =						[
                 '''今天天气不错，阳光明媚，我和妈妈一起去超市买东西。\n在超市里，我看到了一个很好玩的玩具，它的名字叫“机器人”。它有一个圆圆的脑袋，两只圆圆的眼睛，还有一个圆圆的''',
                 '''新年快乐，万事如意！在这辞旧迎新的美好时刻，我谨代表《农村新技术》杂志社全体同仁，向一直以来关心、支持《农村新技术》杂志发展的各级领导、各界朋友和广大读者致以最诚挚的''',
             ]
             __SCREAMING_SNAKE_CASE     :Any	       =						tokenizer(SCREAMING_SNAKE_CASE__	,return_tensors='''pt'''	,padding=SCREAMING_SNAKE_CASE__							)
             __SCREAMING_SNAKE_CASE     :Dict	       =						model.generate(**SCREAMING_SNAKE_CASE__							)
             __SCREAMING_SNAKE_CASE     :Optional[Any]	       =						tokenizer.batch_decode(SCREAMING_SNAKE_CASE__							)
             self.assertEqual(SCREAMING_SNAKE_CASE__	,SCREAMING_SNAKE_CASE__							)






"""simple docstring"""
import math
from collections.abc import Generator



def   __lowerCamelCase     (							a_  :	int							)    ->   Generator[int, None, None]:
      __SCREAMING_SNAKE_CASE     :Generator	       =						(i for i in range(1				,     (max_n + 1)							))
      for i in (n for n in numbers if n > 1):
            for j in range(2				,     a_							):
                  if (i % j) == 0:
                        break
            else:
                  yield i



def   __lowerCamelCase     (							a_  :	int							)    ->   Generator[int, None, None]:
      __SCREAMING_SNAKE_CASE     :Generator	       =						(i for i in range(1				,     (max_n + 1)							))
      for i in (n for n in numbers if n > 1):
            # only need to check for factors up to sqrt(i)
            __SCREAMING_SNAKE_CASE     :Tuple	       =						int(math.sqrt(a_							)							) + 1
            for j in range(2				,     a_							):
                  if (i % j) == 0:
                        break
            else:
                  yield i



def   __lowerCamelCase     (							a_  :	int							)    ->   Generator[int, None, None]:
      __SCREAMING_SNAKE_CASE     :Generator	       =						(i for i in range(1				,     (max_n + 1)				,     2							))
      # It's useless to test even numbers as they will not be prime
      if max_n > 2:
            yield 2  # Because 2 will not be tested, it's necessary to yield it now
      for i in (n for n in numbers if n > 1):
            __SCREAMING_SNAKE_CASE     :int	       =						int(math.sqrt(a_							)							) + 1
            for j in range(3				,     a_				,     2							):
                  # As we removed the even numbers, we don't need them now
                  if (i % j) == 0:
                        break
            else:
                  yield i



def   __lowerCamelCase     (							)    ->   Union[str, Any]:
      from timeit import timeit

      __SCREAMING_SNAKE_CASE     :Optional[Any]	       =						'''from __main__ import slow_primes, primes, fast_primes'''
      print(timeit('''slow_primes(1_000_000_000_000)'''				,     setup=a_				,     number=1_00_00_00							)							)
      print(timeit('''primes(1_000_000_000_000)'''				,     setup=a_				,     number=1_00_00_00							)							)
      print(timeit('''fast_primes(1_000_000_000_000)'''				,     setup=a_				,     number=1_00_00_00							)							)


if __name__ == "__main__":
  lowerCamelCase_          =	int(input("Calculate primes up to:\n>> ").strip())
  for ret in primes(number):
    print(ret)
  benchmark()