






"""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        UpperCamelCase__ :







    """simple docstring"""







    def __init__(		self :	Tuple				,    UpperCamelCase_ :	Dict				,    UpperCamelCase_ :	Any=1_3				,    UpperCamelCase_ :	List[Any]=7				,    UpperCamelCase_ :	List[Any]=True				,    UpperCamelCase_ :	Optional[int]=True				,    UpperCamelCase_ :	Any=True				,    UpperCamelCase_ :	Optional[int]=True				,    UpperCamelCase_ :	str=9_9				,    UpperCamelCase_ :	Tuple=3_2				,    UpperCamelCase_ :	List[str]=5				,    UpperCamelCase_ :	Tuple=4				,    UpperCamelCase_ :	str=4				,    UpperCamelCase_ :	List[str]="gelu"				,    UpperCamelCase_ :	Union[str, Any]=0.0				,    UpperCamelCase_ :	Any=0.1				,    UpperCamelCase_ :	Tuple=True				,    UpperCamelCase_ :	int=5_1_2				,    UpperCamelCase_ :	Union[str, Any]=1_6				,    UpperCamelCase_ :	int=2				,    UpperCamelCase_ :	int=0.02				,    UpperCamelCase_ :	Optional[Any]=3				,    UpperCamelCase_ :	Union[str, Any]=4				,    UpperCamelCase_ :	List[str]=None				,    ):





           '''simple docstring'''

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







    def 				a__			(		self :	str ):





           '''simple docstring'''

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

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

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

           __magic_name__      				=    self.get_config()

           return config, input_ids, input_mask, token_labels







    def 				a__			(		self :	Optional[int] ):





           '''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=UpperCamelCase_				,    initializer_range=self.initializer_range				,    )







    def 				a__			(		self :	List[str] ):





           '''simple docstring'''

           __magic_name__				,  __magic_name__				,  __magic_name__				,  __magic_name__      				=    self.prepare_config_and_inputs()

           __magic_name__      				=    True

           return config, input_ids, input_mask, token_labels







    def 				a__			(		self :	Tuple				,    UpperCamelCase_ :	Optional[Any]				,    UpperCamelCase_ :	Any				,    UpperCamelCase_ :	Any ):





           '''simple docstring'''

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







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





           '''simple docstring'''

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







    def 				a__			(		self :	List[Any]				,    UpperCamelCase_ :	List[str]				,    UpperCamelCase_ :	int				,    UpperCamelCase_ :	Any				,    UpperCamelCase_ :	Dict ):





           '''simple docstring'''

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







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





           '''simple docstring'''

           __magic_name__      				=    True
           __magic_name__      				=    GPTNeoXJapaneseForCausalLM(config=UpperCamelCase_ )
           model.to(UpperCamelCase_ )
           model.eval()

           # first forward pass
           __magic_name__      				=    model(UpperCamelCase_				,    attention_mask=UpperCamelCase_				,    use_cache=UpperCamelCase_ )
           __magic_name__      				=    outputs.past_key_values

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

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

           __magic_name__      				=    model(UpperCamelCase_				,    attention_mask=UpperCamelCase_				,    output_hidden_states=UpperCamelCase_ )
           __magic_name__      				=    output_from_no_past['hidden_states'][0]
           __magic_name__      				=    model(
               UpperCamelCase_				,    attention_mask=UpperCamelCase_				,    past_key_values=UpperCamelCase_				,    output_hidden_states=UpperCamelCase_				,    )['hidden_states'][0]

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







    def 				a__			(		self :	List[Any] ):





           '''simple docstring'''

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



@require_torch
class        UpperCamelCase__ (				a_							,	a_							,	unittest.TestCase):







    """simple docstring"""
    __UpperCAmelCase           = (GPTNeoXJapaneseModel, GPTNeoXJapaneseForCausalLM) if is_torch_available() else ()
    __UpperCAmelCase           = (GPTNeoXJapaneseForCausalLM,) if is_torch_available() else ()
    __UpperCAmelCase           = (
        {"""feature-extraction""": GPTNeoXJapaneseModel, """text-generation""": GPTNeoXJapaneseForCausalLM}
        if is_torch_available()
        else {}
    )
    __UpperCAmelCase           = False
    __UpperCAmelCase           = False
    __UpperCAmelCase           = False
    __UpperCAmelCase           = False







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





           '''simple docstring'''

           __magic_name__      				=    GPTNeoXJapaneseModelTester(self )
           __magic_name__      				=    ConfigTester(self				,    config_class=UpperCamelCase_				,    hidden_size=3_7 )







    def 				a__			(		self :	Optional[Any] ):





           '''simple docstring'''

           self.config_tester.run_common_tests()







    def 				a__			(		self :	str ):





           '''simple docstring'''

           __magic_name__				,  __magic_name__				,  __magic_name__				,  __magic_name__      				=    self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_model(UpperCamelCase_				,    UpperCamelCase_				,    UpperCamelCase_ )







    def 				a__			(		self :	Optional[int] ):





           '''simple docstring'''

           __magic_name__				,  __magic_name__				,  __magic_name__				,  __magic_name__      				=    self.model_tester.prepare_config_and_inputs_for_decoder()
           self.model_tester.create_and_check_model_as_decoder(UpperCamelCase_				,    UpperCamelCase_				,    UpperCamelCase_ )







    def 				a__			(		self :	List[Any] ):





           '''simple docstring'''

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

           __magic_name__      				=    None

           self.model_tester.create_and_check_model_as_decoder(UpperCamelCase_				,    UpperCamelCase_				,    UpperCamelCase_ )







    def 				a__			(		self :	Any ):





           '''simple docstring'''

           __magic_name__				,  __magic_name__				,  __magic_name__				,  __magic_name__      				=    self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_decoder_model_past_large_inputs(UpperCamelCase_				,    UpperCamelCase_				,    UpperCamelCase_ )







    def 				a__			(		self :	str ):





           '''simple docstring'''

           __magic_name__      				=    self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_causal_lm(*UpperCamelCase_ )







    @slow
    def 				a__			(		self :	Dict ):





           '''simple docstring'''

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

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

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

           __magic_name__      				=    GPTNeoXJapaneseTokenizer.from_pretrained(UpperCamelCase_ )
           __magic_name__      				=    GPTNeoXJapaneseForCausalLM.from_pretrained(UpperCamelCase_ )

           __magic_name__      				=    []
           for prompt in prompts:
                  __magic_name__      				=    tokenizer(UpperCamelCase_				,    return_tensors='pt' ).input_ids
                  __magic_name__      				=    model.generate(UpperCamelCase_				,    max_length=5_0 )
                  __magic_name__      				=    tokenizer.batch_decode(UpperCamelCase_				,    skip_special_tokens=UpperCamelCase_ )
                  predicted_outputs += generated_string
           self.assertListEqual(UpperCamelCase_				,    UpperCamelCase_ )







"""simple docstring"""
def 							A						(				__snake_case: int = 3 ,     __snake_case: int = 7 ,     __snake_case: int = 1_0_0_0_0_0_0  )    ->		int:

       """simple docstring"""





       __magic_name__      				=    0
       __magic_name__      				=    1

       for current_denominator in range(1 ,     limit + 1  ):
              __magic_name__      				=    current_denominator * numerator // denominator
              if current_denominator % denominator == 0:
                     current_numerator -= 1
              if current_numerator * max_denominator > current_denominator * max_numerator:
                     __magic_name__      				=    current_numerator
                     __magic_name__      				=    current_denominator
       return max_numerator


if __name__ == "__main__":
 print(solution(numerator=3, denominator=7, limit=1_0_0_0_0_0_0))