
'''simple docstring'''




import unittest

from transformers import GPTNeoXJapaneseConfig, is_torch_available
from transformers.models.gpt_neox_japanese.tokenization_gpt_neox_japanese import GPTNeoXJapaneseTokenizer
from transformers.testing_utils import require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
      import torch

      from transformers import GPTNeoXJapaneseForCausalLM, GPTNeoXJapaneseModel





class  A				:





     def __init__(							self						,			SCREAMING_SNAKE_CASE						,			SCREAMING_SNAKE_CASE=13						,			SCREAMING_SNAKE_CASE=7						,			SCREAMING_SNAKE_CASE=True						,			SCREAMING_SNAKE_CASE=True						,			SCREAMING_SNAKE_CASE=True						,			SCREAMING_SNAKE_CASE=True						,			SCREAMING_SNAKE_CASE=99						,			SCREAMING_SNAKE_CASE=32						,			SCREAMING_SNAKE_CASE=5						,			SCREAMING_SNAKE_CASE=4						,			SCREAMING_SNAKE_CASE=4						,			SCREAMING_SNAKE_CASE="gelu"						,			SCREAMING_SNAKE_CASE=0.0						,			SCREAMING_SNAKE_CASE=0.1						,			SCREAMING_SNAKE_CASE=True						,			SCREAMING_SNAKE_CASE=512						,			SCREAMING_SNAKE_CASE=16						,			SCREAMING_SNAKE_CASE=2						,			SCREAMING_SNAKE_CASE=0.02						,			SCREAMING_SNAKE_CASE=3						,			SCREAMING_SNAKE_CASE=4						,			SCREAMING_SNAKE_CASE=None						,			) ->				str:






         """simple docstring"""






         A       :   Optional[Any]					=						parent
         A       :   Optional[Any]					=						batch_size
         A       :   Union[str, Any]					=						seq_length
         A       :   List[Any]					=						is_training
         A       :   int					=						use_input_mask
         A       :   Optional[Any]					=						use_token_type_ids
         A       :   int					=						use_labels
         A       :   List[str]					=						vocab_size
         A       :   Optional[int]					=						hidden_size
         A       :   int					=						num_hidden_layers
         A       :   Tuple					=						num_attention_heads
         A       :   Optional[Any]					=						intermediate_multiple_size
         A       :   Optional[int]					=						hidden_act
         A       :   int					=						hidden_dropout
         A       :   Tuple					=						attention_dropout
         A       :   Optional[int]					=						weight_tying
         A       :   List[str]					=						max_position_embeddings
         A       :   Any					=						type_vocab_size
         A       :   Tuple					=						type_sequence_label_size
         A       :   Any					=						initializer_range
         A       :   List[Any]					=						num_labels
         A       :   Optional[Any]					=						num_choices
         A       :   str					=						scope





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






         """simple docstring"""






         A       :   List[str]					=						ids_tensor([self.batch_size, self.seq_length]						,			self.vocab_size	)

         A       :   Union[str, Any]					=						None
         if self.use_input_mask:
             A       :   Optional[Any]					=						random_attention_mask([self.batch_size, self.seq_length]	)

         A       :   Optional[int]					=						None
         if self.use_labels:
             A       :   Optional[int]					=						ids_tensor([self.batch_size, self.seq_length]						,			self.num_labels	)

         A       :   Any					=						self.get_config()

         return config, input_ids, input_mask, token_labels





     def 				__lowerCAmelCase							(							self	) ->				str:






         """simple docstring"""






         return GPTNeoXJapaneseConfig(
             vocab_size=self.vocab_size						,			hidden_size=self.hidden_size						,			num_hidden_layers=self.num_hidden_layers						,			num_attention_heads=self.num_attention_heads						,			intermediate_multiple_size=self.intermediate_multiple_size						,			hidden_act=self.hidden_act						,			hidden_dropout=self.hidden_dropout						,			attention_dropout=self.attention_dropout						,			weight_tying=self.weight_tying						,			max_position_embeddings=self.max_position_embeddings						,			type_vocab_size=self.type_vocab_size						,			is_decoder=SCREAMING_SNAKE_CASE						,			initializer_range=self.initializer_range						,			)





     def 				__lowerCAmelCase							(							self	) ->				Optional[Any]:






         """simple docstring"""






         A,  A,  A,  A       :   Tuple					=						self.prepare_config_and_inputs()

         A       :   int					=						True

         return config, input_ids, input_mask, token_labels





     def 				__lowerCAmelCase							(							self						,			SCREAMING_SNAKE_CASE						,			SCREAMING_SNAKE_CASE						,			SCREAMING_SNAKE_CASE	) ->				List[str]:






         """simple docstring"""






         A       :   str					=						GPTNeoXJapaneseModel(config=SCREAMING_SNAKE_CASE	)
         model.to(SCREAMING_SNAKE_CASE	)
         model.eval()
         A       :   List[Any]					=						model(SCREAMING_SNAKE_CASE						,			attention_mask=SCREAMING_SNAKE_CASE	)
         A       :   Dict					=						model(SCREAMING_SNAKE_CASE	)
         self.parent.assertEqual(result.last_hidden_state.shape						,			(self.batch_size, self.seq_length, self.hidden_size)	)





     def 				__lowerCAmelCase							(							self						,			SCREAMING_SNAKE_CASE						,			SCREAMING_SNAKE_CASE						,			SCREAMING_SNAKE_CASE	) ->				List[str]:






         """simple docstring"""






         A       :   Any					=						True
         A       :   Tuple					=						GPTNeoXJapaneseModel(SCREAMING_SNAKE_CASE	)
         model.to(SCREAMING_SNAKE_CASE	)
         model.eval()
         A       :   Any					=						model(SCREAMING_SNAKE_CASE						,			attention_mask=SCREAMING_SNAKE_CASE	)
         self.parent.assertEqual(result.last_hidden_state.shape						,			(self.batch_size, self.seq_length, self.hidden_size)	)





     def 				__lowerCAmelCase							(							self						,			SCREAMING_SNAKE_CASE						,			SCREAMING_SNAKE_CASE						,			SCREAMING_SNAKE_CASE						,			SCREAMING_SNAKE_CASE	) ->				str:






         """simple docstring"""






         A       :   Union[str, Any]					=						GPTNeoXJapaneseForCausalLM(config=SCREAMING_SNAKE_CASE	)
         model.to(SCREAMING_SNAKE_CASE	)
         model.eval()
         A       :   Dict					=						model(SCREAMING_SNAKE_CASE						,			attention_mask=SCREAMING_SNAKE_CASE						,			labels=SCREAMING_SNAKE_CASE	)
         self.parent.assertEqual(result.logits.shape						,			(self.batch_size, self.seq_length, self.vocab_size)	)





     def 				__lowerCAmelCase							(							self						,			SCREAMING_SNAKE_CASE						,			SCREAMING_SNAKE_CASE						,			SCREAMING_SNAKE_CASE	) ->				Optional[int]:






         """simple docstring"""






         A       :   List[str]					=						True
         A       :   Optional[int]					=						GPTNeoXJapaneseForCausalLM(config=SCREAMING_SNAKE_CASE	)
         model.to(SCREAMING_SNAKE_CASE	)
         model.eval()

         # first forward pass
         A       :   List[str]					=						model(SCREAMING_SNAKE_CASE						,			attention_mask=SCREAMING_SNAKE_CASE						,			use_cache=SCREAMING_SNAKE_CASE	)
         A       :   Dict					=						outputs.past_key_values

         # create hypothetical multiple next token and extent to next_input_ids
         A       :   Union[str, Any]					=						ids_tensor((self.batch_size, 3)						,			config.vocab_size	)
         A       :   Union[str, Any]					=						ids_tensor((self.batch_size, 3)						,			vocab_size=2	)

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

         A       :   int					=						model(SCREAMING_SNAKE_CASE						,			attention_mask=SCREAMING_SNAKE_CASE						,			output_hidden_states=SCREAMING_SNAKE_CASE	)
         A       :   Tuple					=						output_from_no_past['''hidden_states'''][0]
         A       :   Tuple					=						model(
             SCREAMING_SNAKE_CASE						,			attention_mask=SCREAMING_SNAKE_CASE						,			past_key_values=SCREAMING_SNAKE_CASE						,			output_hidden_states=SCREAMING_SNAKE_CASE						,			)['''hidden_states'''][0]

         # select random slice
         A       :   Dict					=						ids_tensor((1,)						,			output_from_past.shape[-1]	).item()
         A       :   int					=						output_from_no_past[:, -3:, random_slice_idx].detach()
         A       :   Union[str, Any]					=						output_from_past[:, :, random_slice_idx].detach()

         self.parent.assertTrue(output_from_past_slice.shape[1] == next_tokens.shape[1]	)

         # test that outputs are equal for slice
         self.parent.assertTrue(torch.allclose(SCREAMING_SNAKE_CASE						,			SCREAMING_SNAKE_CASE						,			atol=1e-3	)	)





     def 				__lowerCAmelCase							(							self	) ->				Tuple:






         """simple docstring"""






         A       :   List[str]					=						self.prepare_config_and_inputs()
         A,  A,  A,  A       :   Optional[int]					=						config_and_inputs
         A       :   Optional[int]					=						{'''input_ids''': input_ids, '''attention_mask''': input_mask}
         return config, inputs_dict





@require_torch
class  A				(							__snake_case    ,			__snake_case    ,			unittest.TestCase						):
     __magic_name__						=		(GPTNeoXJapaneseModel, GPTNeoXJapaneseForCausalLM) if is_torch_available() else ()
     __magic_name__						=		(GPTNeoXJapaneseForCausalLM,) if is_torch_available() else ()
     __magic_name__						=		(
         {'''feature-extraction''': GPTNeoXJapaneseModel, '''text-generation''': GPTNeoXJapaneseForCausalLM}
         if is_torch_available()
         else {}
     )
     __magic_name__						=		False
     __magic_name__						=		False
     __magic_name__						=		False
     __magic_name__						=		False





     def 				__lowerCAmelCase							(							self	) ->				Tuple:






         """simple docstring"""






         A       :   int					=						GPTNeoXJapaneseModelTester(self	)
         A       :   Optional[int]					=						ConfigTester(self						,			config_class=SCREAMING_SNAKE_CASE						,			hidden_size=37	)





     def 				__lowerCAmelCase							(							self	) ->				str:






         """simple docstring"""






         self.config_tester.run_common_tests()





     def 				__lowerCAmelCase							(							self	) ->				int:






         """simple docstring"""






         A,  A,  A,  A       :   Optional[int]					=						self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(SCREAMING_SNAKE_CASE						,			SCREAMING_SNAKE_CASE						,			SCREAMING_SNAKE_CASE	)





     def 				__lowerCAmelCase							(							self	) ->				Union[str, Any]:






         """simple docstring"""






         A,  A,  A,  A       :   Optional[Any]					=						self.model_tester.prepare_config_and_inputs_for_decoder()
         self.model_tester.create_and_check_model_as_decoder(SCREAMING_SNAKE_CASE						,			SCREAMING_SNAKE_CASE						,			SCREAMING_SNAKE_CASE	)





     def 				__lowerCAmelCase							(							self	) ->				int:






         """simple docstring"""






         A,  A,  A,  A       :   Optional[Any]					=						self.model_tester.prepare_config_and_inputs_for_decoder()

         A       :   List[str]					=						None

         self.model_tester.create_and_check_model_as_decoder(SCREAMING_SNAKE_CASE						,			SCREAMING_SNAKE_CASE						,			SCREAMING_SNAKE_CASE	)





     def 				__lowerCAmelCase							(							self	) ->				Optional[Any]:






         """simple docstring"""






         A,  A,  A,  A       :   Optional[Any]					=						self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_decoder_model_past_large_inputs(SCREAMING_SNAKE_CASE						,			SCREAMING_SNAKE_CASE						,			SCREAMING_SNAKE_CASE	)





     def 				__lowerCAmelCase							(							self	) ->				Union[str, Any]:






         """simple docstring"""






         A       :   List[Any]					=						self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_causal_lm(*SCREAMING_SNAKE_CASE	)





     @slow
     def 				__lowerCAmelCase							(							self	) ->				Union[str, Any]:






         """simple docstring"""






         A       :   Union[str, Any]					=						'''abeja/gpt-neox-japanese-2.7b'''

         A       :   Union[str, Any]					=						['''データサイエンティストとは、''', '''100年後に必要とされる会社は、''', '''フルリモートの環境で働くために必要なことは、''', '''国境の長いトンネルを抜けると''', '''美味しい日本食といえば、''']

         A       :   Any					=						[
             '''データサイエンティストとは、データを分析し、ビジネスに役立つ知見を導き出す専門家のことです。''',
             '''100年後に必要とされる会社は、「人」が中心の会社です。''',
             '''フルリモートの環境で働くために必要なことは、「自分の時間をコントロールする」ことです。''',
             '''国境の長いトンネルを抜けると、そこは雪国だった。''',
             '''美味しい日本食といえば、やっぱりお寿司ですよね。''',
         ]

         A       :   str					=						GPTNeoXJapaneseTokenizer.from_pretrained(SCREAMING_SNAKE_CASE	)
         A       :   Any					=						GPTNeoXJapaneseForCausalLM.from_pretrained(SCREAMING_SNAKE_CASE	)

         A       :   str					=						[]
         for prompt in prompts:
             A       :   Any					=						tokenizer(SCREAMING_SNAKE_CASE						,			return_tensors='''pt'''	).input_ids
             A       :   List[Any]					=						model.generate(SCREAMING_SNAKE_CASE						,			max_length=50	)
             A       :   int					=						tokenizer.batch_decode(SCREAMING_SNAKE_CASE						,			skip_special_tokens=SCREAMING_SNAKE_CASE	)
             predicted_outputs += generated_string
         self.assertListEqual(SCREAMING_SNAKE_CASE						,			SCREAMING_SNAKE_CASE	)











def 		lowerCAmelCase_    (  __UpperCAmelCase:			int = 100_0000      )      ->	int:
    UpperCamelCase__							:				str          =      limit + 1
    UpperCamelCase__							:				List[str]          =      [0] * limit
    for first_term in range(1		,   __UpperCAmelCase      ):
        for n in range(__UpperCAmelCase		,   __UpperCAmelCase		,   __UpperCAmelCase      ):
            UpperCamelCase__							:				str          =      first_term + n / first_term
            if common_difference % 4:  # d must be divisble by 4
                continue
            else:
                common_difference /= 4
                if (
                    first_term > common_difference
                    and first_term < 4 * common_difference
                ):  # since x,y,z are positive integers
                    frequency[n] += 1  # so z>0 and a>d ,also 4d<a

    UpperCamelCase__							:				Any          =      sum(1 for x in frequency[1:limit] if x == 10      )

    return count


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

