




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      UpperCAmelCase						:






   def __init__(	self   :       Tuple						,					UpperCamelCase_   :       int						,					UpperCamelCase_   :       Optional[int]=2						,					UpperCamelCase_   :       Tuple=8						,					UpperCamelCase_   :       Union[str, Any]=True						,					UpperCamelCase_   :       Any=False						,					UpperCamelCase_   :       Optional[int]=False						,					UpperCamelCase_   :       Dict=False						,					UpperCamelCase_   :       Tuple=False						,					UpperCamelCase_   :       Optional[Any]=99						,					UpperCamelCase_   :       str=32						,					UpperCamelCase_   :       str=3						,					UpperCamelCase_   :       Any=4						,					UpperCamelCase_   :       Any=37						,					UpperCamelCase_   :       Dict=32						,					UpperCamelCase_   :       List[str]=1_28						,					UpperCamelCase_   :       Dict=8						,					UpperCamelCase_   :       Tuple=8						,					UpperCamelCase_   :       Optional[int]=8						,					UpperCamelCase_   :       Dict=1.0						,					UpperCamelCase_   :       Optional[int]=True						,					)->			Optional[int]:
     _lowercase: Dict						     =    parent
     _lowercase: Optional[Any]						     =    batch_size
     _lowercase: Any						     =    seq_length
     _lowercase: List[Any]						     =    is_training
     _lowercase: str						     =    use_token_type_ids
     _lowercase: Union[str, Any]						     =    use_input_mask
     _lowercase: Any						     =    use_labels
     _lowercase: int						     =    use_mc_token_ids
     _lowercase: Dict						     =    vocab_size
     _lowercase: List[Any]						     =    hidden_size
     _lowercase: int						     =    num_hidden_layers
     _lowercase: Any						     =    num_attention_heads
     _lowercase: str						     =    intermediate_size
     _lowercase: Optional[int]						     =    num_buckets
     _lowercase: List[str]						     =    max_distance
     _lowercase: str						     =    prompt_length
     _lowercase: int						     =    prompt_types
     _lowercase: List[Any]						     =    segment_types
     _lowercase: List[str]						     =    init_std
     _lowercase: Optional[int]						     =    return_dict






   def  _a						(	self   :       Dict     )->			Optional[Any]:
     _lowercase: Any						     =    {}
     _lowercase: Union[str, Any]						     =    ids_tensor([self.batch_size, self.seq_length]						,					self.vocab_size     ).type(torch.intaa     )
     _lowercase: Optional[Any]						     =    False

     _lowercase: int						     =    self.get_config()

     return (config, input_ids)






   def  _a						(	self   :       Any     )->			List[Any]:
     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=UpperCamelCase_						,					init_std=self.init_std						,					return_dict=self.return_dict						,					)






   def  _a						(	self   :       Optional[int]						,					UpperCamelCase_   :       int						,					UpperCamelCase_   :       int						,					*UpperCamelCase_   :       str     )->			Optional[Any]:
     _lowercase: List[str]						     =    CpmAntModel(config=UpperCamelCase_     )
     model.to(UpperCamelCase_     )
     model.eval()

     _lowercase: Any						     =    model(**UpperCamelCase_     ).last_hidden_state

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






   def  _a						(	self   :       Union[str, Any]						,					UpperCamelCase_   :       Union[str, Any]						,					UpperCamelCase_   :       Any						,					*UpperCamelCase_   :       Tuple     )->			int:
     _lowercase: Union[str, Any]						     =    CpmAntForCausalLM(UpperCamelCase_     )
     model.to(UpperCamelCase_     )
     _lowercase: Optional[Any]						     =    input_ids['input_ids'].to(UpperCamelCase_     )
     model.eval()

     _lowercase: Optional[Any]						     =    model(**UpperCamelCase_     )
     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   :       List[Any]     )->			Optional[int]:
     _lowercase     ,					_lowercase: Optional[int]						     =    self.prepare_config_and_inputs()
     return config, inputs_dict

@require_torch
class      UpperCAmelCase						(			A   ,					A   ,					unittest.TestCase   ):
   __SCREAMING_SNAKE_CASE		:							Optional[Any]							=					(CpmAntModel, CpmAntForCausalLM) if is_torch_available() else ()
   __SCREAMING_SNAKE_CASE		:							Optional[int]							=					(
       {"feature-extraction": CpmAntModel, "text-generation": CpmAntForCausalLM} if is_torch_available() else {}
   )

   __SCREAMING_SNAKE_CASE		:							Dict							=					False
   __SCREAMING_SNAKE_CASE		:							Optional[int]							=					False
   __SCREAMING_SNAKE_CASE		:							List[Any]							=					False
   __SCREAMING_SNAKE_CASE		:							Dict							=					False
   __SCREAMING_SNAKE_CASE		:							Tuple							=					False






   def  _a						(	self   :       Union[str, Any]     )->			int:
     _lowercase: Tuple						     =    CpmAntModelTester(self     )
     _lowercase: Any						     =    ConfigTester(self						,					config_class=UpperCamelCase_     )






   def  _a						(	self   :       List[Any]     )->			Optional[Any]:
     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   :       Optional[Any]     )->			Union[str, Any]:
     unittest.skip('CPMAnt doesn\'t support input_embeds.'     )(self.test_inputs_embeds     )






   def  _a						(	self   :       List[str]     )->			str:
     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   :       List[Any]     )->			str:
     _lowercase     ,					_lowercase: Dict						     =    self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_cpmant_model(UpperCamelCase_						,					UpperCamelCase_     )






   def  _a						(	self   :       Optional[int]     )->			List[Any]:
     _lowercase     ,					_lowercase: Tuple						     =    self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_lm_head_model(UpperCamelCase_						,					UpperCamelCase_     )

@require_torch
class      UpperCAmelCase						(			unittest.TestCase   ):






   @tooslow
   def  _a						(	self   :       Dict     )->			List[Any]:
     _lowercase: List[Any]						     =    '今天天气真好！'
     _lowercase: Union[str, Any]						     =    'openbmb/cpm-ant-10b'
     _lowercase: Optional[Any]						     =    CpmAntModel.from_pretrained(UpperCamelCase_     )
     _lowercase: Union[str, Any]						     =    CpmAntTokenizer.from_pretrained(UpperCamelCase_     )
     _lowercase: List[str]						     =    tokenizer(UpperCamelCase_						,					return_tensors='pt'     )
     _lowercase: List[str]						     =    model(**UpperCamelCase_     ).last_hidden_state

     _lowercase: Optional[int]						     =    torch.tensor(
         [[[6.1_708, 5.9_244, 1.0_835], [6.5_207, 6.2_893, -11.3_324], [-1.0_107, -0.0_576, -5.9_577]]]						,					)
     self.assertTrue(torch.allclose(hidden_states[:, :3, :3]						,					UpperCamelCase_						,					atol=1E-2     )     )

@require_torch
class      UpperCAmelCase						(			unittest.TestCase   ):






   @tooslow
   def  _a						(	self   :       Optional[int]     )->			Optional[Any]:
     _lowercase: List[str]						     =    '今天天气真好！'
     _lowercase: Any						     =    'openbmb/cpm-ant-10b'
     _lowercase: List[Any]						     =    CpmAntForCausalLM.from_pretrained(UpperCamelCase_     )
     _lowercase: Optional[Any]						     =    CpmAntTokenizer.from_pretrained(UpperCamelCase_     )
     _lowercase: str						     =    tokenizer(UpperCamelCase_						,					return_tensors='pt'     )
     _lowercase: int						     =    model(**UpperCamelCase_     ).logits

     _lowercase: Optional[Any]						     =    torch.tensor(
         [[[-6.4_267, -6.4_083, -6.3_958], [-5.8_802, -5.9_447, -5.7_811], [-5.3_896, -5.4_820, -5.4_295]]]						,					)
     self.assertTrue(torch.allclose(hidden_states[:, :3, :3]						,					UpperCamelCase_						,					atol=1E-2     )     )






   @tooslow
   def  _a						(	self   :       Tuple     )->			List[str]:
     _lowercase: Dict						     =    'openbmb/cpm-ant-10b'
     _lowercase: Union[str, Any]						     =    CpmAntForCausalLM.from_pretrained(UpperCamelCase_     )
     _lowercase: Tuple						     =    CpmAntTokenizer.from_pretrained(UpperCamelCase_     )
     _lowercase: Any						     =    '今天天气不错，'
     _lowercase: Any						     =    '今天天气不错，阳光明媚，我和妈妈一起去超市买东西。\n在超市里，我看到了一个很好玩的玩具，它的名字叫“机器人”。它有一个圆圆的脑袋，两只圆圆的眼睛，还有一个圆圆的'
     _lowercase: Any						     =    tokenizer(UpperCamelCase_						,					return_tensors='pt'     )
     _lowercase: Optional[int]						     =    model.generate(**UpperCamelCase_     )
     _lowercase: List[Any]						     =    tokenizer.batch_decode(UpperCamelCase_     )
     self.assertEqual(UpperCamelCase_						,					UpperCamelCase_     )






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






from __future__ import annotations

from pathlib import Path


def 		_lowerCamelCase				(					UpperCamelCase					,     UpperCamelCase							)			->		int:





  """simple docstring"""





  return pointa[0] * pointa[1] - pointa[1] * pointa[0]


def 		_lowerCamelCase				(					UpperCamelCase					,     UpperCamelCase					,     UpperCamelCase					,     UpperCamelCase					,     UpperCamelCase					,     UpperCamelCase							)			->		bool:





  """simple docstring"""





  _lowercase: tuple[int, int]						     =    (xa, ya)
  _lowercase: tuple[int, int]						     =    (xa - xa, ya - ya)
  _lowercase: tuple[int, int]						     =    (xa - xa, ya - ya)
  _lowercase: float						     =    -vector_product(UpperCamelCase					,     UpperCamelCase							) / vector_product(
      UpperCamelCase					,     UpperCamelCase							)
  _lowercase: float						     =    +vector_product(UpperCamelCase					,     UpperCamelCase							) / vector_product(
      UpperCamelCase					,     UpperCamelCase							)

  return a > 0 and b > 0 and a + b < 1


def 		_lowerCamelCase				(					UpperCamelCase = "p102_triangles.txt"							)			->		int:





  """simple docstring"""





  _lowercase: str						     =    Path(UpperCamelCase							).parent.joinpath(UpperCamelCase							).read_text(encoding='utf-8'							)

  _lowercase: list[list[int]]						     =    []
  for line in data.strip().split('\n'							):
    triangles.append([int(UpperCamelCase							) for number in line.split(','							)]							)

  _lowercase: int						     =    0
  _lowercase: list[int]

  for triangle in triangles:
    ret += contains_origin(*UpperCamelCase							)

  return ret


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