

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

  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=5_12      , _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      , ):





      '''simple docstring'''

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

  def   _SCREAMING_SNAKE_CASE				(				self	):





      '''simple docstring'''

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

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

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

      lowerCAmelCase 						=							self.get_config()

      return config, input_ids, input_mask, token_labels

  def   _SCREAMING_SNAKE_CASE				(				self	):





      '''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   _SCREAMING_SNAKE_CASE				(				self	):





      '''simple docstring'''

      lowerCAmelCase 						=							self.prepare_config_and_inputs()

      lowerCAmelCase 						=							True

      return config, input_ids, input_mask, token_labels

  def   _SCREAMING_SNAKE_CASE				(				self      , _SCREAMING_SNAKE_CASE      , _SCREAMING_SNAKE_CASE      , _SCREAMING_SNAKE_CASE	):





      '''simple docstring'''

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

  def   _SCREAMING_SNAKE_CASE				(				self      , _SCREAMING_SNAKE_CASE      , _SCREAMING_SNAKE_CASE      , _SCREAMING_SNAKE_CASE	):





      '''simple docstring'''

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

  def   _SCREAMING_SNAKE_CASE				(				self      , _SCREAMING_SNAKE_CASE      , _SCREAMING_SNAKE_CASE      , _SCREAMING_SNAKE_CASE      , _SCREAMING_SNAKE_CASE	):





      '''simple docstring'''

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

  def   _SCREAMING_SNAKE_CASE				(				self      , _SCREAMING_SNAKE_CASE      , _SCREAMING_SNAKE_CASE      , _SCREAMING_SNAKE_CASE	):





      '''simple docstring'''

      lowerCAmelCase 						=							True
      lowerCAmelCase 						=							GPTNeoXJapaneseForCausalLM(config=__lowerCAmelCase	)
      model.to(__lowerCAmelCase	)
      model.eval()

      # first forward pass
      lowerCAmelCase 						=							model(__lowerCAmelCase      , attention_mask=__lowerCAmelCase      , use_cache=__lowerCAmelCase	)
      lowerCAmelCase 						=							outputs.past_key_values

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

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

      lowerCAmelCase 						=							model(__lowerCAmelCase      , attention_mask=__lowerCAmelCase      , output_hidden_states=__lowerCAmelCase	)
      lowerCAmelCase 						=							output_from_no_past['''hidden_states'''][0]
      lowerCAmelCase 						=							model(
          __lowerCAmelCase      , attention_mask=__lowerCAmelCase      , past_key_values=__lowerCAmelCase      , output_hidden_states=__lowerCAmelCase      , )['''hidden_states'''][0]

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





      '''simple docstring'''

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



@require_torch
class 				_snake_case					(   a_     , a_     , unittest.TestCase			):
  SCREAMING_SNAKE_CASE			:       List[Any]				=     (GPTNeoXJapaneseModel, GPTNeoXJapaneseForCausalLM) if is_torch_available() else ()
  SCREAMING_SNAKE_CASE			:       List[Any]				=     (GPTNeoXJapaneseForCausalLM,) if is_torch_available() else ()
  SCREAMING_SNAKE_CASE			:       Tuple				=     (
      {'''feature-extraction''': GPTNeoXJapaneseModel, '''text-generation''': GPTNeoXJapaneseForCausalLM}
      if is_torch_available()
      else {}
  )
  SCREAMING_SNAKE_CASE			:       List[Any]				=     False
  SCREAMING_SNAKE_CASE			:       List[Any]				=     False
  SCREAMING_SNAKE_CASE			:       Dict				=     False
  SCREAMING_SNAKE_CASE			:       List[Any]				=     False

  def   _SCREAMING_SNAKE_CASE				(				self	):





      '''simple docstring'''

      lowerCAmelCase 						=							GPTNeoXJapaneseModelTester(self	)
      lowerCAmelCase 						=							ConfigTester(self      , config_class=__lowerCAmelCase      , hidden_size=37	)

  def   _SCREAMING_SNAKE_CASE				(				self	):





      '''simple docstring'''

      self.config_tester.run_common_tests()

  def   _SCREAMING_SNAKE_CASE				(				self	):





      '''simple docstring'''

      lowerCAmelCase 						=							self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_model(__lowerCAmelCase      , __lowerCAmelCase      , __lowerCAmelCase	)

  def   _SCREAMING_SNAKE_CASE				(				self	):





      '''simple docstring'''

      lowerCAmelCase 						=							self.model_tester.prepare_config_and_inputs_for_decoder()
      self.model_tester.create_and_check_model_as_decoder(__lowerCAmelCase      , __lowerCAmelCase      , __lowerCAmelCase	)

  def   _SCREAMING_SNAKE_CASE				(				self	):





      '''simple docstring'''

      lowerCAmelCase 						=							self.model_tester.prepare_config_and_inputs_for_decoder()

      lowerCAmelCase 						=							None

      self.model_tester.create_and_check_model_as_decoder(__lowerCAmelCase      , __lowerCAmelCase      , __lowerCAmelCase	)

  def   _SCREAMING_SNAKE_CASE				(				self	):





      '''simple docstring'''

      lowerCAmelCase 						=							self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_decoder_model_past_large_inputs(__lowerCAmelCase      , __lowerCAmelCase      , __lowerCAmelCase	)

  def   _SCREAMING_SNAKE_CASE				(				self	):





      '''simple docstring'''

      lowerCAmelCase 						=							self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_causal_lm(*__lowerCAmelCase	)


  @slow
  def   _SCREAMING_SNAKE_CASE				(				self	):





      '''simple docstring'''

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

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

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

      lowerCAmelCase 						=							GPTNeoXJapaneseTokenizer.from_pretrained(__lowerCAmelCase	)
      lowerCAmelCase 						=							GPTNeoXJapaneseForCausalLM.from_pretrained(__lowerCAmelCase	)

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













import sys

SCREAMING_SNAKE_CASE__   :      Optional[Any]				=		(
    """73167176531330624919225119674426574742355349194934"""
    """96983520312774506326239578318016984801869478851843"""
    """85861560789112949495459501737958331952853208805511"""
    """12540698747158523863050715693290963295227443043557"""
    """66896648950445244523161731856403098711121722383113"""
    """62229893423380308135336276614282806444486645238749"""
    """30358907296290491560440772390713810515859307960866"""
    """70172427121883998797908792274921901699720888093776"""
    """65727333001053367881220235421809751254540594752243"""
    """52584907711670556013604839586446706324415722155397"""
    """53697817977846174064955149290862569321978468622482"""
    """83972241375657056057490261407972968652414535100474"""
    """82166370484403199890008895243450658541227588666881"""
    """16427171479924442928230863465674813919123162824586"""
    """17866458359124566529476545682848912883142607690042"""
    """24219022671055626321111109370544217506941658960408"""
    """07198403850962455444362981230987879927244284909188"""
    """84580156166097919133875499200524063689912560717606"""
    """05886116467109405077541002256983155200055935729725"""
    """71636269561882670428252483600823257530420752963450"""
)

def   __lowercase       (			snake_case = N			):







				"""simple docstring"""






				__magic_name__		:Optional[int]   =   -sys.maxsize - 1
				for i in range(len(snake_case			) - 1_2			):
								__magic_name__		:List[Any]   =   1
								for j in range(1_3			):
												product *= int(n[i + j]			)
								if product > largest_product:
												__magic_name__		:str   =   product
				return largest_product


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






