



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





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







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





	def      UpperCamelCase_  (			self :    Dict			):







							'''simple docstring'''
							_UpperCamelCase :		Dict			    =       ids_tensor([self.batch_size, self.seq_length]			,self.vocab_size			)

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

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

							_UpperCamelCase :		Union[str, Any]			    =       self.get_config()

							return config, input_ids, input_mask, token_labels





	def      UpperCamelCase_  (			self :    Dict			):







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







							'''simple docstring'''
							_UpperCamelCase    ,      _UpperCamelCase    ,      _UpperCamelCase    ,      _UpperCamelCase :		Any			    =       self.prepare_config_and_inputs()

							_UpperCamelCase :		Optional[Any]			    =       True

							return config, input_ids, input_mask, token_labels





	def      UpperCamelCase_  (			self :    Union[str, Any]			,lowerCamelCase__ :    List[Any]			,lowerCamelCase__ :    List[Any]			,lowerCamelCase__ :    Optional[Any]			):







							'''simple docstring'''
							_UpperCamelCase :		int			    =       GPTNeoXJapaneseModel(config=lowerCamelCase__			)
							model.to(lowerCamelCase__			)
							model.eval()
							_UpperCamelCase :		Tuple			    =       model(lowerCamelCase__			,attention_mask=lowerCamelCase__			)
							_UpperCamelCase :		Any			    =       model(lowerCamelCase__			)
							self.parent.assertEqual(result.last_hidden_state.shape			,(self.batch_size, self.seq_length, self.hidden_size)			)





	def      UpperCamelCase_  (			self :    Optional[Any]			,lowerCamelCase__ :    Optional[Any]			,lowerCamelCase__ :    Optional[Any]			,lowerCamelCase__ :    int			):







							'''simple docstring'''
							_UpperCamelCase :		Optional[int]			    =       True
							_UpperCamelCase :		Tuple			    =       GPTNeoXJapaneseModel(lowerCamelCase__			)
							model.to(lowerCamelCase__			)
							model.eval()
							_UpperCamelCase :		Union[str, Any]			    =       model(lowerCamelCase__			,attention_mask=lowerCamelCase__			)
							self.parent.assertEqual(result.last_hidden_state.shape			,(self.batch_size, self.seq_length, self.hidden_size)			)





	def      UpperCamelCase_  (			self :    int			,lowerCamelCase__ :    Union[str, Any]			,lowerCamelCase__ :    List[Any]			,lowerCamelCase__ :    Union[str, Any]			,lowerCamelCase__ :    Optional[int]			):







							'''simple docstring'''
							_UpperCamelCase :		int			    =       GPTNeoXJapaneseForCausalLM(config=lowerCamelCase__			)
							model.to(lowerCamelCase__			)
							model.eval()
							_UpperCamelCase :		str			    =       model(lowerCamelCase__			,attention_mask=lowerCamelCase__			,labels=lowerCamelCase__			)
							self.parent.assertEqual(result.logits.shape			,(self.batch_size, self.seq_length, self.vocab_size)			)





	def      UpperCamelCase_  (			self :    str			,lowerCamelCase__ :    Union[str, Any]			,lowerCamelCase__ :    Any			,lowerCamelCase__ :    List[str]			):







							'''simple docstring'''
							_UpperCamelCase :		Tuple			    =       True
							_UpperCamelCase :		Dict			    =       GPTNeoXJapaneseForCausalLM(config=lowerCamelCase__			)
							model.to(lowerCamelCase__			)
							model.eval()

							# first forward pass
							_UpperCamelCase :		Optional[Any]			    =       model(lowerCamelCase__			,attention_mask=lowerCamelCase__			,use_cache=lowerCamelCase__			)
							_UpperCamelCase :		str			    =       outputs.past_key_values

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

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

							_UpperCamelCase :		List[Any]			    =       model(lowerCamelCase__			,attention_mask=lowerCamelCase__			,output_hidden_states=lowerCamelCase__			)
							_UpperCamelCase :		Optional[int]			    =       output_from_no_past['hidden_states'][0]
							_UpperCamelCase :		Union[str, Any]			    =       model(
							    lowerCamelCase__			,attention_mask=lowerCamelCase__			,past_key_values=lowerCamelCase__			,output_hidden_states=lowerCamelCase__			,)['hidden_states'][0]

							# select random slice
							_UpperCamelCase :		Union[str, Any]			    =       ids_tensor((1,)			,output_from_past.shape[-1]			).item()
							_UpperCamelCase :		int			    =       output_from_no_past[:, -3:, random_slice_idx].detach()
							_UpperCamelCase :		Dict			    =       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      UpperCamelCase_  (			self :    Optional[Any]			):







							'''simple docstring'''
							_UpperCamelCase :		Any			    =       self.prepare_config_and_inputs()
							_UpperCamelCase    ,      _UpperCamelCase    ,      _UpperCamelCase    ,      _UpperCamelCase :		List[Any]			    =       config_and_inputs
							_UpperCamelCase :		List[str]			    =       {'input_ids': input_ids, 'attention_mask': input_mask}
							return config, inputs_dict






@require_torch
class 							lowercase__     (							lowercase						, lowercase						, unittest.TestCase       ):
	lowercase__      =      (GPTNeoXJapaneseModel, GPTNeoXJapaneseForCausalLM) if is_torch_available() else ()
	lowercase__      =      (GPTNeoXJapaneseForCausalLM,) if is_torch_available() else ()
	lowercase__      =      (
	    {"""feature-extraction""": GPTNeoXJapaneseModel, """text-generation""": GPTNeoXJapaneseForCausalLM}
	    if is_torch_available()
	    else {}
	)
	lowercase__      =      False
	lowercase__      =      False
	lowercase__      =      False
	lowercase__      =      False





	def      UpperCamelCase_  (			self :    Optional[int]			):







							'''simple docstring'''
							_UpperCamelCase :		Optional[int]			    =       GPTNeoXJapaneseModelTester(self			)
							_UpperCamelCase :		Tuple			    =       ConfigTester(self			,config_class=lowerCamelCase__			,hidden_size=37			)





	def      UpperCamelCase_  (			self :    Dict			):







							'''simple docstring'''
							self.config_tester.run_common_tests()





	def      UpperCamelCase_  (			self :    str			):







							'''simple docstring'''
							_UpperCamelCase    ,      _UpperCamelCase    ,      _UpperCamelCase    ,      _UpperCamelCase :		Optional[int]			    =       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(lowerCamelCase__			,lowerCamelCase__			,lowerCamelCase__			)





	def      UpperCamelCase_  (			self :    int			):







							'''simple docstring'''
							_UpperCamelCase    ,      _UpperCamelCase    ,      _UpperCamelCase    ,      _UpperCamelCase :		Dict			    =       self.model_tester.prepare_config_and_inputs_for_decoder()
							self.model_tester.create_and_check_model_as_decoder(lowerCamelCase__			,lowerCamelCase__			,lowerCamelCase__			)





	def      UpperCamelCase_  (			self :    Optional[Any]			):







							'''simple docstring'''
							# This regression test was failing with PyTorch < 1.3
							_UpperCamelCase    ,      _UpperCamelCase    ,      _UpperCamelCase    ,      _UpperCamelCase :		Optional[Any]			    =       self.model_tester.prepare_config_and_inputs_for_decoder()

							_UpperCamelCase :		Union[str, Any]			    =       None

							self.model_tester.create_and_check_model_as_decoder(lowerCamelCase__			,lowerCamelCase__			,lowerCamelCase__			)





	def      UpperCamelCase_  (			self :    int			):







							'''simple docstring'''
							_UpperCamelCase    ,      _UpperCamelCase    ,      _UpperCamelCase    ,      _UpperCamelCase :		Optional[int]			    =       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_decoder_model_past_large_inputs(lowerCamelCase__			,lowerCamelCase__			,lowerCamelCase__			)





	def      UpperCamelCase_  (			self :    Union[str, Any]			):







							'''simple docstring'''
							_UpperCamelCase :		Dict			    =       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_causal_lm(*lowerCamelCase__			)





	@slow
	def      UpperCamelCase_  (			self :    Optional[int]			):







							'''simple docstring'''
							_UpperCamelCase :		str			    =       'abeja/gpt-neox-japanese-2.7b'

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

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

							_UpperCamelCase :		str			    =       GPTNeoXJapaneseTokenizer.from_pretrained(lowerCamelCase__			)
							_UpperCamelCase :		Optional[int]			    =       GPTNeoXJapaneseForCausalLM.from_pretrained(lowerCamelCase__			)

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







'''simple docstring'''
from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tokenizers_available, is_torch_available


snake_case_			:     Any  	=  {
    'configuration_mvp': ['MVP_PRETRAINED_CONFIG_ARCHIVE_MAP', 'MvpConfig', 'MvpOnnxConfig'],
    'tokenization_mvp': ['MvpTokenizer'],
}

try:
					if not is_tokenizers_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					snake_case_			:     Dict  	=  ['MvpTokenizerFast']

try:
					if not is_torch_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					snake_case_			:     List[Any]  	=  [
					    'MVP_PRETRAINED_MODEL_ARCHIVE_LIST',
					    'MvpForCausalLM',
					    'MvpForConditionalGeneration',
					    'MvpForQuestionAnswering',
					    'MvpForSequenceClassification',
					    'MvpModel',
					    'MvpPreTrainedModel',
					]

if TYPE_CHECKING:
					from .configuration_mvp import MVP_PRETRAINED_CONFIG_ARCHIVE_MAP, MvpConfig, MvpOnnxConfig
					from .tokenization_mvp import MvpTokenizer

					try:
										if not is_tokenizers_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .tokenization_mvp_fast import MvpTokenizerFast

					try:
										if not is_torch_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_mvp import (
										    MVP_PRETRAINED_MODEL_ARCHIVE_LIST,
										    MvpForCausalLM,
										    MvpForConditionalGeneration,
										    MvpForQuestionAnswering,
										    MvpForSequenceClassification,
										    MvpModel,
										    MvpPreTrainedModel,
										)

else:
					import sys

					snake_case_			:     Optional[Any]  	=  _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)


