





import unittest

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

from ...generation.test_utils import GenerationTesterMixin
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.models.trocr.modeling_trocr import TrOCRDecoder, TrOCRForCausalLM





@require_torch
class 			lowerCAmelCase__:






       '''simple docstring'''


       def __init__(      self    ,						__lowerCamelCase    ,						__lowerCamelCase=9_9    ,						__lowerCamelCase=1_3    ,						__lowerCamelCase=1_6    ,						__lowerCamelCase=7    ,						__lowerCamelCase=True    ,						__lowerCamelCase=True    ,						__lowerCamelCase=True    ,						__lowerCamelCase=False    ,						__lowerCamelCase=True    ,						__lowerCamelCase=2    ,						__lowerCamelCase=3_2    ,						__lowerCamelCase=4    ,						__lowerCamelCase=4    ,						__lowerCamelCase=3_0    ,						__lowerCamelCase=0    ,						__lowerCamelCase=1    ,						__lowerCamelCase=2    ,						__lowerCamelCase=None    ,						)			->     Tuple:
            _SCREAMING_SNAKE_CASE       :	Dict						    =							parent
            _SCREAMING_SNAKE_CASE       :	List[str]						    =							batch_size
            _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							decoder_seq_length
            # For common tests
            _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							self.decoder_seq_length
            _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							is_training
            _SCREAMING_SNAKE_CASE       :	Optional[Any]						    =							use_attention_mask
            _SCREAMING_SNAKE_CASE       :	Optional[Any]						    =							use_labels

            _SCREAMING_SNAKE_CASE       :	Optional[Any]						    =							vocab_size
            _SCREAMING_SNAKE_CASE       :	List[str]						    =							d_model
            _SCREAMING_SNAKE_CASE       :	List[Any]						    =							d_model
            _SCREAMING_SNAKE_CASE       :	Any						    =							decoder_layers
            _SCREAMING_SNAKE_CASE       :	str						    =							decoder_layers
            _SCREAMING_SNAKE_CASE       :	int						    =							decoder_ffn_dim
            _SCREAMING_SNAKE_CASE       :	List[str]						    =							decoder_attention_heads
            _SCREAMING_SNAKE_CASE       :	str						    =							decoder_attention_heads
            _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							eos_token_id
            _SCREAMING_SNAKE_CASE       :	Tuple						    =							bos_token_id
            _SCREAMING_SNAKE_CASE       :	str						    =							pad_token_id
            _SCREAMING_SNAKE_CASE       :	List[Any]						    =							decoder_start_token_id
            _SCREAMING_SNAKE_CASE       :	List[Any]						    =							use_cache
            _SCREAMING_SNAKE_CASE       :	Optional[Any]						    =							max_position_embeddings

            _SCREAMING_SNAKE_CASE       :	int						    =							None
            _SCREAMING_SNAKE_CASE       :	List[str]						    =							decoder_seq_length
            _SCREAMING_SNAKE_CASE       :	List[Any]						    =							2
            _SCREAMING_SNAKE_CASE       :	Optional[Any]						    =							1




       def     UpperCamelCase_			(      self							)			->     Dict:
            _SCREAMING_SNAKE_CASE       :	List[Any]						    =							ids_tensor([self.batch_size, self.decoder_seq_length]    ,						self.vocab_size							)

            _SCREAMING_SNAKE_CASE       :	str						    =							None
            if self.use_attention_mask:
                 _SCREAMING_SNAKE_CASE       :	Dict						    =							ids_tensor([self.batch_size, self.decoder_seq_length]    ,						vocab_size=2							)

            _SCREAMING_SNAKE_CASE       :	List[str]						    =							None
            if self.use_labels:
                 _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							ids_tensor([self.batch_size, self.decoder_seq_length]    ,						self.vocab_size							)

            _SCREAMING_SNAKE_CASE       :	List[Any]						    =							TrOCRConfig(
                vocab_size=self.vocab_size    ,						d_model=self.d_model    ,						decoder_layers=self.decoder_layers    ,						decoder_ffn_dim=self.decoder_ffn_dim    ,						decoder_attention_heads=self.decoder_attention_heads    ,						eos_token_id=self.eos_token_id    ,						bos_token_id=self.bos_token_id    ,						use_cache=self.use_cache    ,						pad_token_id=self.pad_token_id    ,						decoder_start_token_id=self.decoder_start_token_id    ,						max_position_embeddings=self.max_position_embeddings    ,						)

            return (config, input_ids, attention_mask, lm_labels)




       def     UpperCamelCase_			(      self    ,						__lowerCamelCase    ,						__lowerCamelCase    ,						__lowerCamelCase    ,						__lowerCamelCase    ,						)			->     Union[str, Any]:
            _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							True
            _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							TrOCRDecoder(config=A_							).to(A_							).eval()
            _SCREAMING_SNAKE_CASE       :	Optional[Any]						    =							input_ids[:2]

            input_ids[input_ids == 0] += 1
            # first forward pass
            _SCREAMING_SNAKE_CASE       :	Any						    =							model(A_    ,						use_cache=A_							)
            _SCREAMING_SNAKE_CASE       :	str						    =							model(A_							)
            _SCREAMING_SNAKE_CASE       :	int						    =							model(A_    ,						use_cache=A_							)

            self.parent.assertTrue(len(A_							) == len(A_							)							)
            self.parent.assertTrue(len(A_							) == len(A_							) + 1							)

            _SCREAMING_SNAKE_CASE       :	str						    =							outputs["past_key_values"]

            # create hypothetical next token and extent to next_input_ids
            _SCREAMING_SNAKE_CASE       :	List[Any]						    =							ids_tensor((2, 1)    ,						config.vocab_size - 1							) + 1

            # append to next input_ids and
            _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							torch.cat([input_ids, next_tokens]    ,						dim=-1							)

            _SCREAMING_SNAKE_CASE       :	Tuple						    =							model(A_							)["last_hidden_state"]
            _SCREAMING_SNAKE_CASE       :	List[str]						    =							model(A_    ,						past_key_values=A_							)["last_hidden_state"]

            # select random slice
            _SCREAMING_SNAKE_CASE       :	Any						    =							ids_tensor((1,)    ,						output_from_past.shape[-1]							).item()
            _SCREAMING_SNAKE_CASE       :	Any						    =							output_from_no_past[:, next_input_ids.shape[-1] - 1, random_slice_idx].detach()
            _SCREAMING_SNAKE_CASE       :	Tuple						    =							output_from_past[:, 0, random_slice_idx].detach()

            # test that outputs are equal for slice
            assert torch.allclose(A_    ,						A_    ,						atol=1E-3							)







       def     UpperCamelCase_			(      self							)			->     Any:
            _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							self.prepare_config_and_inputs()
            _SCREAMING_SNAKE_CASE    ,			_SCREAMING_SNAKE_CASE    ,			_SCREAMING_SNAKE_CASE    ,			_SCREAMING_SNAKE_CASE       :	List[Any]						    =							config_and_inputs

            _SCREAMING_SNAKE_CASE       :	int						    =							{"input_ids": input_ids, "attention_mask": attention_mask}
            return config, inputs_dict





@require_torch
class 			lowerCAmelCase__( _SCREAMING_SNAKE_CASE  ,     _SCREAMING_SNAKE_CASE  ,     _SCREAMING_SNAKE_CASE  ,     unittest.TestCase    ):






       '''simple docstring'''


       __snake_case 			=    (TrOCRDecoder, TrOCRForCausalLM) if is_torch_available() else ()
       __snake_case 			=    (TrOCRForCausalLM,) if is_torch_available() else ()
       __snake_case 			=    {"text-generation": TrOCRForCausalLM} if is_torch_available() else {}
       __snake_case 			=    True
       __snake_case 			=    False




       def     UpperCamelCase_			(      self							)			->     List[str]:
            _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							TrOCRStandaloneDecoderModelTester(self    ,						is_training=A_							)
            _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							ConfigTester(self    ,						config_class=A_							)




       def     UpperCamelCase_			(      self							)			->     List[Any]:
            pass




       def     UpperCamelCase_			(      self							)			->     Optional[Any]:
            pass




       def     UpperCamelCase_			(      self							)			->     Tuple:
            pass




       def     UpperCamelCase_			(      self							)			->     Union[str, Any]:
            self.config_tester.run_common_tests()




       def     UpperCamelCase_			(      self							)			->     Tuple:
            _SCREAMING_SNAKE_CASE       :	Dict						    =							self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_decoder_model_past(*A_							)




       def     UpperCamelCase_			(      self							)			->     List[Any]:
            return







       @unittest.skip("The model doesn\'t support left padding"							)  # and it's not used enough to be worth fixing :)
       def     UpperCamelCase_			(      self							)			->     List[Any]:
            pass






from __future__ import annotations

UpperCamelCase__      =[True] * 100_0001
UpperCamelCase__      =2
while i * i <= 100_0000:
       if seive[i]:
              for j in range(i * i, 100_0001, i):
                     UpperCamelCase__      =False
       i += 1






def     lowerCamelCase__			(__lowerCamelCase	):
     return seive[n]






def     lowerCamelCase__			(__lowerCamelCase	):
     return any(digit in "02468" for digit in str(__lowerCamelCase	)	)






def     lowerCamelCase__			(__lowerCamelCase = 1000000	):
     _SCREAMING_SNAKE_CASE       :	Optional[Any]						    =							[2]  # result already includes the number 2.
     for num in range(3,       limit + 1,       2	):
          if is_prime(__lowerCamelCase	) and not contains_an_even_digit(__lowerCamelCase	):
               _SCREAMING_SNAKE_CASE       :	List[Any]						    =							str(__lowerCamelCase	)
               _SCREAMING_SNAKE_CASE       :	Optional[Any]						    =							[int(str_num[j:] + str_num[:j]	) for j in range(len(__lowerCamelCase	)	)]
               if all(is_prime(__lowerCamelCase	) for i in list_nums	):
                    result.append(__lowerCamelCase	)
     return result






def     lowerCamelCase__			():
     return len(find_circular_primes()	)


if __name__ == "__main__":
       print(f"{len(find_circular_primes()) = }")