"""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				,     a__				,     a__=13				,     a__=7				,     a__=True				,     a__=True				,     a__=True				,     a__=True				,     a__=99				,     a__=32				,     a__=5				,     a__=4				,     a__=4				,     a__="gelu"				,     a__=0.0				,     a__=0.1				,     a__=True				,     a__=512				,     a__=16				,     a__=2				,     a__=0.0_2				,     a__=3				,     a__=4				,     a__=None				,     ):
       _lowerCAmelCase						:       Optional[int]  			=     parent
       _lowerCAmelCase						:       List[str]  			=     batch_size
       _lowerCAmelCase						:       List[Any]  			=     seq_length
       _lowerCAmelCase						:       Optional[int]  			=     is_training
       _lowerCAmelCase						:       List[str]  			=     use_input_mask
       _lowerCAmelCase						:       int  			=     use_token_type_ids
       _lowerCAmelCase						:       str  			=     use_labels
       _lowerCAmelCase						:       Optional[int]  			=     vocab_size
       _lowerCAmelCase						:       List[str]  			=     hidden_size
       _lowerCAmelCase						:       Optional[int]  			=     num_hidden_layers
       _lowerCAmelCase						:       Dict  			=     num_attention_heads
       _lowerCAmelCase						:       Union[str, Any]  			=     intermediate_multiple_size
       _lowerCAmelCase						:       Dict  			=     hidden_act
       _lowerCAmelCase						:       List[str]  			=     hidden_dropout
       _lowerCAmelCase						:       Dict  			=     attention_dropout
       _lowerCAmelCase						:       List[str]  			=     weight_tying
       _lowerCAmelCase						:       str  			=     max_position_embeddings
       _lowerCAmelCase						:       Optional[Any]  			=     type_vocab_size
       _lowerCAmelCase						:       str  			=     type_sequence_label_size
       _lowerCAmelCase						:       Optional[int]  			=     initializer_range
       _lowerCAmelCase						:       Union[str, Any]  			=     num_labels
       _lowerCAmelCase						:       Optional[Any]  			=     num_choices
       _lowerCAmelCase						:       Any  			=     scope






     def     __A  (		self  ):
       _lowerCAmelCase						:       int  			=     ids_tensor([self.batch_size, self.seq_length]				,     self.vocab_size  )

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

       _lowerCAmelCase						:       Union[str, Any]  			=     None
       if self.use_labels:
         _lowerCAmelCase						:       str  			=     ids_tensor([self.batch_size, self.seq_length]				,     self.num_labels  )

       _lowerCAmelCase						:       int  			=     self.get_config()

       return config, input_ids, input_mask, token_labels






     def     __A  (		self  ):
       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=a__				,     initializer_range=self.initializer_range				,     )






     def     __A  (		self  ):
       _lowerCAmelCase			,	_lowerCAmelCase			,	_lowerCAmelCase			,	_lowerCAmelCase						:       Tuple  			=     self.prepare_config_and_inputs()

       _lowerCAmelCase						:       Dict  			=     True

       return config, input_ids, input_mask, token_labels






     def     __A  (		self				,     a__				,     a__				,     a__  ):
       _lowerCAmelCase						:       List[str]  			=     GPTNeoXJapaneseModel(config=a__  )
       model.to(a__  )
       model.eval()
       _lowerCAmelCase						:       Dict  			=     model(a__				,     attention_mask=a__  )
       _lowerCAmelCase						:       Optional[Any]  			=     model(a__  )
       self.parent.assertEqual(result.last_hidden_state.shape				,     (self.batch_size, self.seq_length, self.hidden_size)  )






     def     __A  (		self				,     a__				,     a__				,     a__  ):
       _lowerCAmelCase						:       List[Any]  			=     True
       _lowerCAmelCase						:       Optional[int]  			=     GPTNeoXJapaneseModel(a__  )
       model.to(a__  )
       model.eval()
       _lowerCAmelCase						:       List[Any]  			=     model(a__				,     attention_mask=a__  )
       self.parent.assertEqual(result.last_hidden_state.shape				,     (self.batch_size, self.seq_length, self.hidden_size)  )






     def     __A  (		self				,     a__				,     a__				,     a__				,     a__  ):
       _lowerCAmelCase						:       Union[str, Any]  			=     GPTNeoXJapaneseForCausalLM(config=a__  )
       model.to(a__  )
       model.eval()
       _lowerCAmelCase						:       List[str]  			=     model(a__				,     attention_mask=a__				,     labels=a__  )
       self.parent.assertEqual(result.logits.shape				,     (self.batch_size, self.seq_length, self.vocab_size)  )






     def     __A  (		self				,     a__				,     a__				,     a__  ):
       _lowerCAmelCase						:       Any  			=     True
       _lowerCAmelCase						:       str  			=     GPTNeoXJapaneseForCausalLM(config=a__  )
       model.to(a__  )
       model.eval()

       # first forward pass
       _lowerCAmelCase						:       List[Any]  			=     model(a__				,     attention_mask=a__				,     use_cache=a__  )
       _lowerCAmelCase						:       Tuple  			=     outputs.past_key_values

       # create hypothetical multiple next token and extent to next_input_ids
       _lowerCAmelCase						:       Optional[int]  			=     ids_tensor((self.batch_size, 3)				,     config.vocab_size  )
       _lowerCAmelCase						:       Optional[int]  			=     ids_tensor((self.batch_size, 3)				,     vocab_size=2  )

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

       _lowerCAmelCase						:       List[str]  			=     model(a__				,     attention_mask=a__				,     output_hidden_states=a__  )
       _lowerCAmelCase						:       Union[str, Any]  			=     output_from_no_past["""hidden_states"""][0]
       _lowerCAmelCase						:       int  			=     model(
           a__				,     attention_mask=a__				,     past_key_values=a__				,     output_hidden_states=a__				,     )["""hidden_states"""][0]

       # select random slice
       _lowerCAmelCase						:       Tuple  			=     ids_tensor((1,)				,     output_from_past.shape[-1]  ).item()
       _lowerCAmelCase						:       List[Any]  			=     output_from_no_past[:, -3:, random_slice_idx].detach()
       _lowerCAmelCase						:       Optional[int]  			=     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(a__				,     a__				,     atol=1e-3  )  )






     def     __A  (		self  ):
       _lowerCAmelCase						:       Optional[int]  			=     self.prepare_config_and_inputs()
       _lowerCAmelCase			,	_lowerCAmelCase			,	_lowerCAmelCase			,	_lowerCAmelCase						:       Any  			=     config_and_inputs
       _lowerCAmelCase						:       Tuple  			=     {"""input_ids""": input_ids, """attention_mask""": input_mask}
       return config, inputs_dict







@require_torch
class 						__A							( SCREAMING_SNAKE_CASE_    ,	SCREAMING_SNAKE_CASE_    ,	unittest.TestCase		):
     _UpperCamelCase							:			Optional[Any]							=		(GPTNeoXJapaneseModel, GPTNeoXJapaneseForCausalLM) if is_torch_available() else ()
     _UpperCamelCase							:			int							=		(GPTNeoXJapaneseForCausalLM,) if is_torch_available() else ()
     _UpperCamelCase							:			str							=		(
         {"feature-extraction": GPTNeoXJapaneseModel, "text-generation": GPTNeoXJapaneseForCausalLM}
         if is_torch_available()
         else {}
     )
     _UpperCamelCase							:			List[str]							=		False
     _UpperCamelCase							:			Optional[int]							=		False
     _UpperCamelCase							:			str							=		False
     _UpperCamelCase							:			int							=		False






     def     __A  (		self  ):
       _lowerCAmelCase						:       Optional[Any]  			=     GPTNeoXJapaneseModelTester(self  )
       _lowerCAmelCase						:       Union[str, Any]  			=     ConfigTester(self				,     config_class=a__				,     hidden_size=37  )






     def     __A  (		self  ):
       self.config_tester.run_common_tests()






     def     __A  (		self  ):
       _lowerCAmelCase			,	_lowerCAmelCase			,	_lowerCAmelCase			,	_lowerCAmelCase						:       Optional[Any]  			=     self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_model(a__				,     a__				,     a__  )






     def     __A  (		self  ):
       _lowerCAmelCase			,	_lowerCAmelCase			,	_lowerCAmelCase			,	_lowerCAmelCase						:       Union[str, Any]  			=     self.model_tester.prepare_config_and_inputs_for_decoder()
       self.model_tester.create_and_check_model_as_decoder(a__				,     a__				,     a__  )






     def     __A  (		self  ):
       # This regression test was failing with PyTorch < 1.3
       _lowerCAmelCase			,	_lowerCAmelCase			,	_lowerCAmelCase			,	_lowerCAmelCase						:       Optional[Any]  			=     self.model_tester.prepare_config_and_inputs_for_decoder()

       _lowerCAmelCase						:       Tuple  			=     None

       self.model_tester.create_and_check_model_as_decoder(a__				,     a__				,     a__  )






     def     __A  (		self  ):
       _lowerCAmelCase			,	_lowerCAmelCase			,	_lowerCAmelCase			,	_lowerCAmelCase						:       Optional[Any]  			=     self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_decoder_model_past_large_inputs(a__				,     a__				,     a__  )






     def     __A  (		self  ):
       _lowerCAmelCase						:       str  			=     self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_causal_lm(*a__  )






     @slow
     def     __A  (		self  ):
       _lowerCAmelCase						:       Optional[int]  			=     """abeja/gpt-neox-japanese-2.7b"""

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

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

       _lowerCAmelCase						:       Tuple  			=     GPTNeoXJapaneseTokenizer.from_pretrained(a__  )
       _lowerCAmelCase						:       int  			=     GPTNeoXJapaneseForCausalLM.from_pretrained(a__  )

       _lowerCAmelCase						:       List[str]  			=     []
       for prompt in prompts:
         _lowerCAmelCase						:       str  			=     tokenizer(a__				,     return_tensors="""pt"""  ).input_ids
         _lowerCAmelCase						:       int  			=     model.generate(a__				,     max_length=50  )
         _lowerCAmelCase						:       Dict  			=     tokenizer.batch_decode(a__				,     skip_special_tokens=a__  )
         predicted_outputs += generated_string
       self.assertListEqual(a__				,     a__  )







from diffusers.utils.testing_utils import require_onnxruntime

@require_onnxruntime
class 				UpperCAmelCase_		:
							"""simple docstring"""







							pass



