




import unittest

from transformers.testing_utils import is_torch_available, require_torch, tooslow

from ...generation.test_utils import torch_device
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
						import torch

						from transformers import (
						    CpmAntConfig,
						    CpmAntForCausalLM,
						    CpmAntModel,
						    CpmAntTokenizer,
						)



@require_torch
class       lowercase_		:



						def __init__( self  :      Optional[Any]				,       snake_case__  :      Union[str, Any]				,       snake_case__  :      Optional[int]=2				,       snake_case__  :      List[Any]=8				,       snake_case__  :      Union[str, Any]=True				,       snake_case__  :      Dict=False				,       snake_case__  :      int=False				,       snake_case__  :      List[Any]=False				,       snake_case__  :      List[str]=False				,       snake_case__  :      int=99				,       snake_case__  :      Dict=32				,       snake_case__  :      Union[str, Any]=3				,       snake_case__  :      Tuple=4				,       snake_case__  :      Optional[int]=37				,       snake_case__  :      Tuple=32				,       snake_case__  :      Tuple=1_28				,       snake_case__  :      Union[str, Any]=8				,       snake_case__  :      Tuple=8				,       snake_case__  :      str=8				,       snake_case__  :      Optional[int]=1.0				,       snake_case__  :      str=True				,       ):

								"""simple docstring"""

								SCREAMING_SNAKE_CASE_							=       parent
								SCREAMING_SNAKE_CASE_							=       batch_size
								SCREAMING_SNAKE_CASE_							=       seq_length
								SCREAMING_SNAKE_CASE_							=       is_training
								SCREAMING_SNAKE_CASE_							=       use_token_type_ids
								SCREAMING_SNAKE_CASE_							=       use_input_mask
								SCREAMING_SNAKE_CASE_							=       use_labels
								SCREAMING_SNAKE_CASE_							=       use_mc_token_ids
								SCREAMING_SNAKE_CASE_							=       vocab_size
								SCREAMING_SNAKE_CASE_							=       hidden_size
								SCREAMING_SNAKE_CASE_							=       num_hidden_layers
								SCREAMING_SNAKE_CASE_							=       num_attention_heads
								SCREAMING_SNAKE_CASE_							=       intermediate_size
								SCREAMING_SNAKE_CASE_							=       num_buckets
								SCREAMING_SNAKE_CASE_							=       max_distance
								SCREAMING_SNAKE_CASE_							=       prompt_length
								SCREAMING_SNAKE_CASE_							=       prompt_types
								SCREAMING_SNAKE_CASE_							=       segment_types
								SCREAMING_SNAKE_CASE_							=       init_std
								SCREAMING_SNAKE_CASE_							=       return_dict



						def   __a				( self  :      Any     ):

								"""simple docstring"""

								SCREAMING_SNAKE_CASE_							=       {}
								SCREAMING_SNAKE_CASE_							=       ids_tensor([self.batch_size, self.seq_length]				,       self.vocab_size     ).type(torch.intaa     )
								SCREAMING_SNAKE_CASE_							=       False

								SCREAMING_SNAKE_CASE_							=       self.get_config()

								return (config, input_ids)



						def   __a				( self  :      Any     ):

								"""simple docstring"""

								return CpmAntConfig(
								    vocab_size=self.vocab_size				,       hidden_size=self.hidden_size				,       num_hidden_layers=self.num_hidden_layers				,       num_attention_heads=self.num_attention_heads				,       dim_ff=self.intermediate_size				,       position_bias_num_buckets=self.num_buckets				,       position_bias_max_distance=self.max_distance				,       prompt_types=self.prompt_types				,       prompt_length=self.prompt_length				,       segment_types=self.segment_types				,       use_cache=snake_case__				,       init_std=self.init_std				,       return_dict=self.return_dict				,       )



						def   __a				( self  :      List[Any]				,       snake_case__  :      int				,       snake_case__  :      Dict				,       *snake_case__  :      Union[str, Any]     ):

								"""simple docstring"""

								SCREAMING_SNAKE_CASE_							=       CpmAntModel(config=snake_case__     )
								model.to(snake_case__     )
								model.eval()

								SCREAMING_SNAKE_CASE_							=       model(**snake_case__     ).last_hidden_state

								self.parent.assertEqual(hidden_states.shape				,       (self.batch_size, self.seq_length, config.hidden_size)     )



						def   __a				( self  :      Tuple				,       snake_case__  :      Optional[Any]				,       snake_case__  :      Optional[Any]				,       *snake_case__  :      Tuple     ):

								"""simple docstring"""

								SCREAMING_SNAKE_CASE_							=       CpmAntForCausalLM(snake_case__     )
								model.to(snake_case__     )
								SCREAMING_SNAKE_CASE_							=       input_ids['input_ids'].to(snake_case__     )
								model.eval()

								SCREAMING_SNAKE_CASE_							=       model(**snake_case__     )
								self.parent.assertEqual(
								    model_output.logits.shape				,       (self.batch_size, self.seq_length, config.vocab_size + config.prompt_types * config.prompt_length)				,       )






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

								"""simple docstring"""

								SCREAMING_SNAKE_CASE_			,							SCREAMING_SNAKE_CASE_							=       self.prepare_config_and_inputs()
								return config, inputs_dict



@require_torch
class       lowercase_		(SCREAMING_SNAKE_CASE__       ,  SCREAMING_SNAKE_CASE__       ,  unittest.TestCase   ):
						lowerCAmelCase__ 			=(CpmAntModel, CpmAntForCausalLM) if is_torch_available() else ()
						lowerCAmelCase__ 			=(
						    {"feature-extraction": CpmAntModel, "text-generation": CpmAntForCausalLM} if is_torch_available() else {}
						)

						lowerCAmelCase__ 			=False
						lowerCAmelCase__ 			=False
						lowerCAmelCase__ 			=False
						lowerCAmelCase__ 			=False
						lowerCAmelCase__ 			=False



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

								"""simple docstring"""

								SCREAMING_SNAKE_CASE_							=       CpmAntModelTester(self     )
								SCREAMING_SNAKE_CASE_							=       ConfigTester(self				,       config_class=snake_case__     )



						def   __a				( self  :      int     ):

								"""simple docstring"""

								self.config_tester.create_and_test_config_common_properties()
								self.config_tester.create_and_test_config_to_json_string()
								self.config_tester.create_and_test_config_to_json_file()
								self.config_tester.create_and_test_config_from_and_save_pretrained()
								self.config_tester.check_config_can_be_init_without_params()
								self.config_tester.check_config_arguments_init()



						def   __a				( self  :      Dict     ):

								"""simple docstring"""

								unittest.skip('CPMAnt doesn\'t support input_embeds.'     )(self.test_inputs_embeds     )



						def   __a				( self  :      List[Any]     ):

								"""simple docstring"""

								unittest.skip(
								    'CPMAnt doesn\'t support retain grad in hidden_states or attentions, because prompt management will peel off the output.hidden_states from graph.\
                 So is attentions. We strongly recommand you use loss to tune model.'     )(self.test_retain_grad_hidden_states_attentions     )



						def   __a				( self  :      int     ):

								"""simple docstring"""

								SCREAMING_SNAKE_CASE_			,							SCREAMING_SNAKE_CASE_							=       self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_cpmant_model(snake_case__				,       snake_case__     )






						def   __a				( self  :      Any     ):

								"""simple docstring"""

								SCREAMING_SNAKE_CASE_			,							SCREAMING_SNAKE_CASE_							=       self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_lm_head_model(snake_case__				,       snake_case__     )



@require_torch
class       lowercase_		(unittest.TestCase   ):



						@tooslow
						def   __a				( self  :      Optional[Any]     ):

								"""simple docstring"""

								SCREAMING_SNAKE_CASE_							=       '今天天气真好！'
								SCREAMING_SNAKE_CASE_							=       'openbmb/cpm-ant-10b'
								SCREAMING_SNAKE_CASE_							=       CpmAntModel.from_pretrained(snake_case__     )
								SCREAMING_SNAKE_CASE_							=       CpmAntTokenizer.from_pretrained(snake_case__     )
								SCREAMING_SNAKE_CASE_							=       tokenizer(snake_case__				,       return_tensors='pt'     )
								SCREAMING_SNAKE_CASE_							=       model(**snake_case__     ).last_hidden_state

								SCREAMING_SNAKE_CASE_							=       torch.tensor(
								    [[[6.17_08, 5.92_44, 1.08_35], [6.52_07, 6.28_93, -11.33_24], [-1.01_07, -0.05_76, -5.95_77]]]				,       )
								self.assertTrue(torch.allclose(hidden_states[:, :3, :3]				,       snake_case__				,       atol=1e-2     )     )



@require_torch
class       lowercase_		(unittest.TestCase   ):



						@tooslow
						def   __a				( self  :      Optional[Any]     ):

								"""simple docstring"""

								SCREAMING_SNAKE_CASE_							=       '今天天气真好！'
								SCREAMING_SNAKE_CASE_							=       'openbmb/cpm-ant-10b'
								SCREAMING_SNAKE_CASE_							=       CpmAntForCausalLM.from_pretrained(snake_case__     )
								SCREAMING_SNAKE_CASE_							=       CpmAntTokenizer.from_pretrained(snake_case__     )
								SCREAMING_SNAKE_CASE_							=       tokenizer(snake_case__				,       return_tensors='pt'     )
								SCREAMING_SNAKE_CASE_							=       model(**snake_case__     ).logits

								SCREAMING_SNAKE_CASE_							=       torch.tensor(
								    [[[-6.42_67, -6.40_83, -6.39_58], [-5.88_02, -5.94_47, -5.78_11], [-5.38_96, -5.48_20, -5.42_95]]]				,       )
								self.assertTrue(torch.allclose(hidden_states[:, :3, :3]				,       snake_case__				,       atol=1e-2     )     )



						@tooslow
						def   __a				( self  :      List[Any]     ):

								"""simple docstring"""

								SCREAMING_SNAKE_CASE_							=       'openbmb/cpm-ant-10b'
								SCREAMING_SNAKE_CASE_							=       CpmAntForCausalLM.from_pretrained(snake_case__     )
								SCREAMING_SNAKE_CASE_							=       CpmAntTokenizer.from_pretrained(snake_case__     )
								SCREAMING_SNAKE_CASE_							=       '今天天气不错，'
								SCREAMING_SNAKE_CASE_							=       '今天天气不错，阳光明媚，我和妈妈一起去超市买东西。\n在超市里，我看到了一个很好玩的玩具，它的名字叫“机器人”。它有一个圆圆的脑袋，两只圆圆的眼睛，还有一个圆圆的'
								SCREAMING_SNAKE_CASE_							=       tokenizer(snake_case__				,       return_tensors='pt'     )
								SCREAMING_SNAKE_CASE_							=       model.generate(**snake_case__     )
								SCREAMING_SNAKE_CASE_							=       tokenizer.batch_decode(snake_case__     )
								self.assertEqual(snake_case__				,       snake_case__     )






						@tooslow
						def   __a				( self  :      str     ):

								"""simple docstring"""

								SCREAMING_SNAKE_CASE_							=       'openbmb/cpm-ant-10b'
								SCREAMING_SNAKE_CASE_							=       CpmAntForCausalLM.from_pretrained(snake_case__     )
								SCREAMING_SNAKE_CASE_							=       CpmAntTokenizer.from_pretrained(snake_case__     )
								SCREAMING_SNAKE_CASE_							=       ['今天天气不错，', '新年快乐，万事如意！']
								SCREAMING_SNAKE_CASE_							=       [
								    '今天天气不错，阳光明媚，我和妈妈一起去超市买东西。\n在超市里，我看到了一个很好玩的玩具，它的名字叫“机器人”。它有一个圆圆的脑袋，两只圆圆的眼睛，还有一个圆圆的',
								    '新年快乐，万事如意！在这辞旧迎新的美好时刻，我谨代表《农村新技术》杂志社全体同仁，向一直以来关心、支持《农村新技术》杂志发展的各级领导、各界朋友和广大读者致以最诚挚的',
								]
								SCREAMING_SNAKE_CASE_							=       tokenizer(snake_case__				,       return_tensors='pt'				,       padding=snake_case__     )
								SCREAMING_SNAKE_CASE_							=       model.generate(**snake_case__     )
								SCREAMING_SNAKE_CASE_							=       tokenizer.batch_decode(snake_case__     )
								self.assertEqual(snake_case__				,       snake_case__     )





from __future__ import annotations


def 				_a       (				lowerCAmelCase						,	lowerCAmelCase   )->  int:
		SCREAMING_SNAKE_CASE_			,							SCREAMING_SNAKE_CASE_							=       0, len(lowerCAmelCase   ) - 1
		while start_ind <= end_ind:
				if array[start_ind] == search_item:
						return start_ind
				elif array[end_ind] == search_item:
						return end_ind
				else:
						start_ind += 1
						end_ind -= 1
    # returns -1 if search_item is not found in array
		return -1


if __name__ == "__main__":
						print(double_linear_search(list(range(1_0_0)), 4_0))