





'''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 							__lowerCAmelCase	:






       """simple docstring"""





       def __init__(				self  :						Tuple			,					lowerCAmelCase__  :						Dict			,					lowerCAmelCase__  :						Optional[int]=13			,					lowerCAmelCase__  :						Union[str, Any]=7			,					lowerCAmelCase__  :						List[Any]=True			,					lowerCAmelCase__  :						Tuple=True			,					lowerCAmelCase__  :						Optional[int]=True			,					lowerCAmelCase__  :						List[Any]=True			,					lowerCAmelCase__  :						Tuple=99			,					lowerCAmelCase__  :						List[Any]=32			,					lowerCAmelCase__  :						int=5			,					lowerCAmelCase__  :						Tuple=4			,					lowerCAmelCase__  :						Optional[int]=4			,					lowerCAmelCase__  :						Optional[int]="gelu"			,					lowerCAmelCase__  :						Optional[int]=0.0			,					lowerCAmelCase__  :						Optional[int]=0.1			,					lowerCAmelCase__  :						Any=True			,					lowerCAmelCase__  :						List[Any]=512			,					lowerCAmelCase__  :						Tuple=16			,					lowerCAmelCase__  :						Dict=2			,					lowerCAmelCase__  :						str=0.02			,					lowerCAmelCase__  :						Dict=3			,					lowerCAmelCase__  :						Optional[Any]=4			,					lowerCAmelCase__  :						Tuple=None			,					)       ->	List[str]:

            '''simple docstring'''




            _UpperCamelCase							       =			parent
            _UpperCamelCase							       =			batch_size
            _UpperCamelCase							       =			seq_length
            _UpperCamelCase							       =			is_training
            _UpperCamelCase							       =			use_input_mask
            _UpperCamelCase							       =			use_token_type_ids
            _UpperCamelCase							       =			use_labels
            _UpperCamelCase							       =			vocab_size
            _UpperCamelCase							       =			hidden_size
            _UpperCamelCase							       =			num_hidden_layers
            _UpperCamelCase							       =			num_attention_heads
            _UpperCamelCase							       =			intermediate_multiple_size
            _UpperCamelCase							       =			hidden_act
            _UpperCamelCase							       =			hidden_dropout
            _UpperCamelCase							       =			attention_dropout
            _UpperCamelCase							       =			weight_tying
            _UpperCamelCase							       =			max_position_embeddings
            _UpperCamelCase							       =			type_vocab_size
            _UpperCamelCase							       =			type_sequence_label_size
            _UpperCamelCase							       =			initializer_range
            _UpperCamelCase							       =			num_labels
            _UpperCamelCase							       =			num_choices
            _UpperCamelCase							       =			scope





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

            '''simple docstring'''




            _UpperCamelCase							       =			ids_tensor([self.batch_size, self.seq_length]			,					self.vocab_size	)

            _UpperCamelCase							       =			None
            if self.use_input_mask:
                 _UpperCamelCase							       =			random_attention_mask([self.batch_size, self.seq_length]	)

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

            _UpperCamelCase							       =			self.get_config()

            return config, input_ids, input_mask, token_labels





       def snake_case__		(				self  :						List[Any]	)       ->	List[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=lowerCAmelCase__			,					initializer_range=self.initializer_range			,					)





       def snake_case__		(				self  :						List[Any]	)       ->	List[str]:

            '''simple docstring'''




            _UpperCamelCase       ,							_UpperCamelCase       ,							_UpperCamelCase       ,							_UpperCamelCase							       =			self.prepare_config_and_inputs()

            _UpperCamelCase							       =			True

            return config, input_ids, input_mask, token_labels





       def snake_case__		(				self  :						Tuple			,					lowerCAmelCase__  :						int			,					lowerCAmelCase__  :						List[Any]			,					lowerCAmelCase__  :						Tuple	)       ->	Any:

            '''simple docstring'''




            _UpperCamelCase							       =			GPTNeoXJapaneseModel(config=lowerCAmelCase__	)
            model.to(lowerCAmelCase__	)
            model.eval()
            _UpperCamelCase							       =			model(lowerCAmelCase__			,					attention_mask=lowerCAmelCase__	)
            _UpperCamelCase							       =			model(lowerCAmelCase__	)
            self.parent.assertEqual(result.last_hidden_state.shape			,					(self.batch_size, self.seq_length, self.hidden_size)	)





       def snake_case__		(				self  :						Optional[Any]			,					lowerCAmelCase__  :						Optional[int]			,					lowerCAmelCase__  :						str			,					lowerCAmelCase__  :						int	)       ->	List[Any]:

            '''simple docstring'''




            _UpperCamelCase							       =			True
            _UpperCamelCase							       =			GPTNeoXJapaneseModel(lowerCAmelCase__	)
            model.to(lowerCAmelCase__	)
            model.eval()
            _UpperCamelCase							       =			model(lowerCAmelCase__			,					attention_mask=lowerCAmelCase__	)
            self.parent.assertEqual(result.last_hidden_state.shape			,					(self.batch_size, self.seq_length, self.hidden_size)	)





       def snake_case__		(				self  :						Optional[Any]			,					lowerCAmelCase__  :						Tuple			,					lowerCAmelCase__  :						str			,					lowerCAmelCase__  :						Tuple			,					lowerCAmelCase__  :						List[Any]	)       ->	List[Any]:

            '''simple docstring'''




            _UpperCamelCase							       =			GPTNeoXJapaneseForCausalLM(config=lowerCAmelCase__	)
            model.to(lowerCAmelCase__	)
            model.eval()
            _UpperCamelCase							       =			model(lowerCAmelCase__			,					attention_mask=lowerCAmelCase__			,					labels=lowerCAmelCase__	)
            self.parent.assertEqual(result.logits.shape			,					(self.batch_size, self.seq_length, self.vocab_size)	)





       def snake_case__		(				self  :						List[str]			,					lowerCAmelCase__  :						Any			,					lowerCAmelCase__  :						Tuple			,					lowerCAmelCase__  :						Any	)       ->	Any:

            '''simple docstring'''




            _UpperCamelCase							       =			True
            _UpperCamelCase							       =			GPTNeoXJapaneseForCausalLM(config=lowerCAmelCase__	)
            model.to(lowerCAmelCase__	)
            model.eval()

            # first forward pass
            _UpperCamelCase							       =			model(lowerCAmelCase__			,					attention_mask=lowerCAmelCase__			,					use_cache=lowerCAmelCase__	)
            _UpperCamelCase							       =			outputs.past_key_values

            # create hypothetical multiple next token and extent to next_input_ids
            _UpperCamelCase							       =			ids_tensor((self.batch_size, 3)			,					config.vocab_size	)
            _UpperCamelCase							       =			ids_tensor((self.batch_size, 3)			,					vocab_size=2	)

            # append to next input_ids and
            _UpperCamelCase							       =			torch.cat([input_ids, next_tokens]			,					dim=-1	)
            _UpperCamelCase							       =			torch.cat([input_mask, next_mask]			,					dim=-1	)

            _UpperCamelCase							       =			model(lowerCAmelCase__			,					attention_mask=lowerCAmelCase__			,					output_hidden_states=lowerCAmelCase__	)
            _UpperCamelCase							       =			output_from_no_past['''hidden_states'''][0]
            _UpperCamelCase							       =			model(
                lowerCAmelCase__			,					attention_mask=lowerCAmelCase__			,					past_key_values=lowerCAmelCase__			,					output_hidden_states=lowerCAmelCase__			,					)['''hidden_states'''][0]

            # select random slice
            _UpperCamelCase							       =			ids_tensor((1,)			,					output_from_past.shape[-1]	).item()
            _UpperCamelCase							       =			output_from_no_past[:, -3:, random_slice_idx].detach()
            _UpperCamelCase							       =			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(lowerCAmelCase__			,					lowerCAmelCase__			,					atol=1e-3	)	)







       def snake_case__		(				self  :						Tuple	)       ->	Any:

            '''simple docstring'''




            _UpperCamelCase							       =			self.prepare_config_and_inputs()
            _UpperCamelCase       ,							_UpperCamelCase       ,							_UpperCamelCase       ,							_UpperCamelCase							       =			config_and_inputs
            _UpperCamelCase							       =			{'''input_ids''': input_ids, '''attention_mask''': input_mask}
            return config, inputs_dict

@require_torch
class 							__lowerCAmelCase	(       __magic_name__		,		__magic_name__		,		unittest.TestCase					):






       """simple docstring"""
       _snake_case      :	Optional[int]									=       (GPTNeoXJapaneseModel, GPTNeoXJapaneseForCausalLM) if is_torch_available() else ()
       _snake_case      :	List[str]									=       (GPTNeoXJapaneseForCausalLM,) if is_torch_available() else ()
       _snake_case      :	Any									=       (
           {'feature-extraction': GPTNeoXJapaneseModel, 'text-generation': GPTNeoXJapaneseForCausalLM}
           if is_torch_available()
           else {}
       )
       _snake_case      :	List[Any]									=       False
       _snake_case      :	Optional[Any]									=       False
       _snake_case      :	Tuple									=       False
       _snake_case      :	List[str]									=       False





       def snake_case__		(				self  :						Dict	)       ->	Dict:

            '''simple docstring'''




            _UpperCamelCase							       =			GPTNeoXJapaneseModelTester(self	)
            _UpperCamelCase							       =			ConfigTester(self			,					config_class=lowerCAmelCase__			,					hidden_size=37	)





       def snake_case__		(				self  :						int	)       ->	str:

            '''simple docstring'''




            self.config_tester.run_common_tests()





       def snake_case__		(				self  :						Tuple	)       ->	Dict:

            '''simple docstring'''




            _UpperCamelCase       ,							_UpperCamelCase       ,							_UpperCamelCase       ,							_UpperCamelCase							       =			self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_model(lowerCAmelCase__			,					lowerCAmelCase__			,					lowerCAmelCase__	)





       def snake_case__		(				self  :						Optional[int]	)       ->	List[str]:

            '''simple docstring'''




            _UpperCamelCase       ,							_UpperCamelCase       ,							_UpperCamelCase       ,							_UpperCamelCase							       =			self.model_tester.prepare_config_and_inputs_for_decoder()
            self.model_tester.create_and_check_model_as_decoder(lowerCAmelCase__			,					lowerCAmelCase__			,					lowerCAmelCase__	)





       def snake_case__		(				self  :						Dict	)       ->	Dict:

            '''simple docstring'''




            _UpperCamelCase       ,							_UpperCamelCase       ,							_UpperCamelCase       ,							_UpperCamelCase							       =			self.model_tester.prepare_config_and_inputs_for_decoder()

            _UpperCamelCase							       =			None

            self.model_tester.create_and_check_model_as_decoder(lowerCAmelCase__			,					lowerCAmelCase__			,					lowerCAmelCase__	)





       def snake_case__		(				self  :						List[Any]	)       ->	Dict:

            '''simple docstring'''




            _UpperCamelCase       ,							_UpperCamelCase       ,							_UpperCamelCase       ,							_UpperCamelCase							       =			self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_decoder_model_past_large_inputs(lowerCAmelCase__			,					lowerCAmelCase__			,					lowerCAmelCase__	)





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

            '''simple docstring'''




            _UpperCamelCase							       =			self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_for_causal_lm(*lowerCAmelCase__	)







       @slow
       def snake_case__		(				self  :						List[str]	)       ->	List[str]:

            '''simple docstring'''




            _UpperCamelCase							       =			'''abeja/gpt-neox-japanese-2.7b'''

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

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

            _UpperCamelCase							       =			GPTNeoXJapaneseTokenizer.from_pretrained(lowerCAmelCase__	)
            _UpperCamelCase							       =			GPTNeoXJapaneseForCausalLM.from_pretrained(lowerCAmelCase__	)

            _UpperCamelCase							       =			[]
            for prompt in prompts:
                 _UpperCamelCase							       =			tokenizer(lowerCAmelCase__			,					return_tensors='''pt'''	).input_ids
                 _UpperCamelCase							       =			model.generate(lowerCAmelCase__			,					max_length=50	)
                 _UpperCamelCase							       =			tokenizer.batch_decode(lowerCAmelCase__			,					skip_special_tokens=lowerCAmelCase__	)
                 predicted_outputs += generated_string
            self.assertListEqual(lowerCAmelCase__			,					lowerCAmelCase__	)










'''simple docstring'''

def    a__							(							lowercase   :	str )						->						int:





     """simple docstring"""

     assert column_title.isupper()
     _UpperCamelCase							       =			0
     _UpperCamelCase							       =			len(lowercase ) - 1
     _UpperCamelCase							       =			0

     while index >= 0:
          _UpperCamelCase							       =			(ord(column_title[index] ) - 64) * pow(26,   lowercase )
          answer += value
          power += 1
          index -= 1

     return answer


if __name__ == "__main__":
   from doctest import testmod

   testmod()



