





import unittest

from transformers import DebertaVaTokenizer, DebertaVaTokenizerFast
from transformers.testing_utils import get_tests_dir, require_sentencepiece, require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin


_UpperCAmelCase				:       Any	   =				get_tests_dir("""fixtures/spiece.model""")

@require_sentencepiece
@require_tokenizers
class    lowerCAmelCase							(					__UpperCamelCase,  unittest.TestCase			):
 UpperCAmelCase__													=		DebertaVaTokenizer
 UpperCAmelCase__													=		DebertaVaTokenizerFast
 UpperCAmelCase__													=		True
 UpperCAmelCase__													=		True
 def      A_	(      self  :      Dict	)			->	int:
     super().setUp()

     # We have a SentencePiece fixture for testing
     lowerCamelCase__    :      Optional[Any]					 =		DebertaVaTokenizer(UpperCAmelCase			,     unk_token='<unk>'	)
     tokenizer.save_pretrained(self.tmpdirname	)
 def      A_	(      self  :      Dict			,     UpperCAmelCase  :      Tuple	)			->	int:
     lowerCamelCase__    :      Dict					 =		'this is a test'
     lowerCamelCase__    :      Union[str, Any]					 =		'this is a test'
     return input_text, output_text
 def      A_	(      self  :      Union[str, Any]	)			->	Optional[Any]:
     lowerCamelCase__    :      str					 =		'<pad>'
     lowerCamelCase__    :      int					 =		0

     self.assertEqual(self.get_tokenizer()._convert_token_to_id(UpperCAmelCase	)			,     UpperCAmelCase	)
     self.assertEqual(self.get_tokenizer()._convert_id_to_token(UpperCAmelCase	)			,     UpperCAmelCase	)
 def      A_	(      self  :      Union[str, Any]	)			->	Optional[int]:
     lowerCamelCase__    :      Tuple					 =		list(self.get_tokenizer().get_vocab().keys()	)
     self.assertEqual(vocab_keys[0]			,     '<pad>'	)
     self.assertEqual(vocab_keys[1]			,     '<unk>'	)
     self.assertEqual(vocab_keys[-1]			,     '[PAD]'	)
     self.assertEqual(len(UpperCAmelCase	)			,     30001	)
 def      A_	(      self  :      Optional[Any]	)			->	int:
     self.assertEqual(self.get_tokenizer().vocab_size			,     30000	)
 def      A_	(      self  :      str	)			->	List[str]:
     # fmt: off
     lowerCamelCase__    :      Union[str, Any]					 =		' \tHeLLo!how  \n Are yoU?  '
     lowerCamelCase__    :      int					 =		['▁hello', '!', 'how', '▁are', '▁you', '?']
     # fmt: on

     lowerCamelCase__    :      Any					 =		DebertaVaTokenizer(UpperCAmelCase			,     do_lower_case=UpperCAmelCase	)
     lowerCamelCase__    :      Optional[int]					 =		tokenizer.convert_ids_to_tokens(tokenizer.encode(UpperCAmelCase			,     add_special_tokens=UpperCAmelCase	)	)

     self.assertListEqual(UpperCAmelCase			,     UpperCAmelCase	)

     lowerCamelCase__    :      Tuple					 =		DebertaVaTokenizerFast(UpperCAmelCase			,     do_lower_case=UpperCAmelCase	)
     lowerCamelCase__    :      int					 =		rust_tokenizer.convert_ids_to_tokens(rust_tokenizer.encode(UpperCAmelCase			,     add_special_tokens=UpperCAmelCase	)	)

     self.assertListEqual(UpperCAmelCase			,     UpperCAmelCase	)
 @unittest.skip('There is an inconsistency between slow and fast tokenizer due to a bug in the fast one.'	)
 def      A_	(      self  :      Optional[int]	)			->	int:
     pass
 @unittest.skip('There is an inconsistency between slow and fast tokenizer due to a bug in the fast one.'	)
 def      A_	(      self  :      Dict	)			->	List[str]:
     pass
 def      A_	(      self  :      str	)			->	Any:
     # fmt: off
     lowerCamelCase__    :      List[Any]					 =		'I was born in 92000, and this is falsé.'
     lowerCamelCase__    :      int					 =		['▁', '<unk>', '▁was', '▁born', '▁in', '▁9', '2000', '▁', ',', '▁and', '▁this', '▁is', '▁fal', 's', '<unk>', '▁', '.', ]
     # fmt: on

     lowerCamelCase__    :      Union[str, Any]					 =		DebertaVaTokenizer(UpperCAmelCase			,     split_by_punct=UpperCAmelCase	)
     lowerCamelCase__    :      List[Any]					 =		tokenizer.convert_ids_to_tokens(tokenizer.encode(UpperCAmelCase			,     add_special_tokens=UpperCAmelCase	)	)

     self.assertListEqual(UpperCAmelCase			,     UpperCAmelCase	)

     lowerCamelCase__    :      int					 =		DebertaVaTokenizerFast(UpperCAmelCase			,     split_by_punct=UpperCAmelCase	)
     lowerCamelCase__    :      Tuple					 =		rust_tokenizer.convert_ids_to_tokens(rust_tokenizer.encode(UpperCAmelCase			,     add_special_tokens=UpperCAmelCase	)	)

     self.assertListEqual(UpperCAmelCase			,     UpperCAmelCase	)
 def      A_	(      self  :      int	)			->	Tuple:
     # fmt: off
     lowerCamelCase__    :      str					 =		'I was born in 92000, and this is falsé.'
     lowerCamelCase__    :      Dict					 =		['▁i', '▁was', '▁born', '▁in', '▁9', '2000', '▁', ',', '▁and', '▁this', '▁is', '▁fal', 's', '<unk>', '▁', '.', ]
     # fmt: on

     lowerCamelCase__    :      str					 =		DebertaVaTokenizer(UpperCAmelCase			,     do_lower_case=UpperCAmelCase			,     split_by_punct=UpperCAmelCase	)
     lowerCamelCase__    :      Union[str, Any]					 =		tokenizer.convert_ids_to_tokens(tokenizer.encode(UpperCAmelCase			,     add_special_tokens=UpperCAmelCase	)	)
     self.assertListEqual(UpperCAmelCase			,     UpperCAmelCase	)

     lowerCamelCase__    :      Union[str, Any]					 =		DebertaVaTokenizerFast(UpperCAmelCase			,     do_lower_case=UpperCAmelCase			,     split_by_punct=UpperCAmelCase	)
     lowerCamelCase__    :      Optional[Any]					 =		rust_tokenizer.convert_ids_to_tokens(rust_tokenizer.encode(UpperCAmelCase			,     add_special_tokens=UpperCAmelCase	)	)
     self.assertListEqual(UpperCAmelCase			,     UpperCAmelCase	)
 def      A_	(      self  :      Union[str, Any]	)			->	str:
     # fmt: off
     lowerCamelCase__    :      Any					 =		'I was born in 92000, and this is falsé.'
     lowerCamelCase__    :      Tuple					 =		['▁i', '▁was', '▁born', '▁in', '▁9', '2000', ',', '▁and', '▁this', '▁is', '▁fal', 's', '<unk>', '.', ]
     # fmt: on

     lowerCamelCase__    :      Tuple					 =		DebertaVaTokenizer(UpperCAmelCase			,     do_lower_case=UpperCAmelCase			,     split_by_punct=UpperCAmelCase	)
     lowerCamelCase__    :      List[Any]					 =		tokenizer.convert_ids_to_tokens(tokenizer.encode(UpperCAmelCase			,     add_special_tokens=UpperCAmelCase	)	)

     self.assertListEqual(UpperCAmelCase			,     UpperCAmelCase	)

     lowerCamelCase__    :      Tuple					 =		DebertaVaTokenizerFast(UpperCAmelCase			,     do_lower_case=UpperCAmelCase			,     split_by_punct=UpperCAmelCase	)
     lowerCamelCase__    :      List[Any]					 =		rust_tokenizer.convert_ids_to_tokens(rust_tokenizer.encode(UpperCAmelCase			,     add_special_tokens=UpperCAmelCase	)	)

     self.assertListEqual(UpperCAmelCase			,     UpperCAmelCase	)
 def      A_	(      self  :      List[str]	)			->	Tuple:
     # fmt: off
     lowerCamelCase__    :      Dict					 =		'I was born in 92000, and this is falsé.'
     lowerCamelCase__    :      List[str]					 =		['▁', '<unk>', '▁was', '▁born', '▁in', '▁9', '2000', '▁', ',', '▁and', '▁this', '▁is', '▁fal', 's', '<unk>', '▁', '.', ]
     # fmt: on

     lowerCamelCase__    :      List[Any]					 =		DebertaVaTokenizer(UpperCAmelCase			,     do_lower_case=UpperCAmelCase			,     split_by_punct=UpperCAmelCase	)
     lowerCamelCase__    :      Tuple					 =		tokenizer.convert_ids_to_tokens(tokenizer.encode(UpperCAmelCase			,     add_special_tokens=UpperCAmelCase	)	)

     self.assertListEqual(UpperCAmelCase			,     UpperCAmelCase	)

     lowerCamelCase__    :      str					 =		DebertaVaTokenizerFast(UpperCAmelCase			,     do_lower_case=UpperCAmelCase			,     split_by_punct=UpperCAmelCase	)
     lowerCamelCase__    :      Dict					 =		rust_tokenizer.convert_ids_to_tokens(rust_tokenizer.encode(UpperCAmelCase			,     add_special_tokens=UpperCAmelCase	)	)

     self.assertListEqual(UpperCAmelCase			,     UpperCAmelCase	)
 def      A_	(      self  :      Optional[int]	)			->	Union[str, Any]:
     # fmt: off
     lowerCamelCase__    :      str					 =		' \tHeLLo!how  \n Are yoU?  '
     lowerCamelCase__    :      Union[str, Any]					 =		['▁', '<unk>', 'e', '<unk>', 'o', '!', 'how', '▁', '<unk>', 're', '▁yo', '<unk>', '?']
     # fmt: on

     lowerCamelCase__    :      str					 =		DebertaVaTokenizer(UpperCAmelCase			,     do_lower_case=UpperCAmelCase			,     split_by_punct=UpperCAmelCase	)
     lowerCamelCase__    :      int					 =		tokenizer.convert_ids_to_tokens(tokenizer.encode(UpperCAmelCase			,     add_special_tokens=UpperCAmelCase	)	)

     self.assertListEqual(UpperCAmelCase			,     UpperCAmelCase	)

     lowerCamelCase__    :      str					 =		DebertaVaTokenizerFast(UpperCAmelCase			,     do_lower_case=UpperCAmelCase			,     split_by_punct=UpperCAmelCase	)
     lowerCamelCase__    :      Tuple					 =		rust_tokenizer.convert_ids_to_tokens(rust_tokenizer.encode(UpperCAmelCase			,     add_special_tokens=UpperCAmelCase	)	)

     self.assertListEqual(UpperCAmelCase			,     UpperCAmelCase	)
 def      A_	(      self  :      Dict	)			->	int:
     lowerCamelCase__    :      Optional[Any]					 =		self.get_tokenizer()
     lowerCamelCase__    :      Optional[int]					 =		self.get_rust_tokenizer()

     lowerCamelCase__    :      List[Any]					 =		'I was born in 92000, and this is falsé.'

     lowerCamelCase__    :      List[Any]					 =		tokenizer.convert_ids_to_tokens(tokenizer.encode(UpperCAmelCase			,     add_special_tokens=UpperCAmelCase	)	)
     lowerCamelCase__    :      List[str]					 =		rust_tokenizer.convert_ids_to_tokens(rust_tokenizer.encode(UpperCAmelCase			,     add_special_tokens=UpperCAmelCase	)	)
     self.assertListEqual(UpperCAmelCase			,     UpperCAmelCase	)

     lowerCamelCase__    :      Dict					 =		tokenizer.encode(UpperCAmelCase			,     add_special_tokens=UpperCAmelCase	)
     lowerCamelCase__    :      Optional[Any]					 =		rust_tokenizer.encode(UpperCAmelCase			,     add_special_tokens=UpperCAmelCase	)
     self.assertListEqual(UpperCAmelCase			,     UpperCAmelCase	)

     lowerCamelCase__    :      Any					 =		self.get_rust_tokenizer()
     lowerCamelCase__    :      Dict					 =		tokenizer.encode(UpperCAmelCase	)
     lowerCamelCase__    :      Optional[Any]					 =		rust_tokenizer.encode(UpperCAmelCase	)
     self.assertListEqual(UpperCAmelCase			,     UpperCAmelCase	)
 def      A_	(      self  :      List[Any]	)			->	int:
     lowerCamelCase__    :      List[Any]					 =		'This is a test'
     lowerCamelCase__    :      Optional[int]					 =		[13, 1, 4398, 25, 21, 1289]
     lowerCamelCase__    :      Dict					 =		['▁', 'T', 'his', '▁is', '▁a', '▁test']
     lowerCamelCase__    :      str					 =		['▁', '<unk>', 'his', '▁is', '▁a', '▁test']

     lowerCamelCase__    :      Dict					 =		DebertaVaTokenizer(UpperCAmelCase			,     keep_accents=UpperCAmelCase	)
     lowerCamelCase__    :      Optional[int]					 =		DebertaVaTokenizerFast(UpperCAmelCase			,     keep_accents=UpperCAmelCase	)

     lowerCamelCase__    :      Tuple					 =		tokenizer.encode(UpperCAmelCase			,     add_special_tokens=UpperCAmelCase	)
     self.assertListEqual(UpperCAmelCase			,     UpperCAmelCase	)
     lowerCamelCase__    :      Tuple					 =		tokenizer.tokenize(UpperCAmelCase	)
     self.assertListEqual(UpperCAmelCase			,     UpperCAmelCase	)
     lowerCamelCase__    :      Tuple					 =		tokenizer.convert_ids_to_tokens(UpperCAmelCase	)
     self.assertListEqual(UpperCAmelCase			,     UpperCAmelCase	)

     lowerCamelCase__    :      Union[str, Any]					 =		rust_tokenizer.encode(UpperCAmelCase			,     add_special_tokens=UpperCAmelCase	)
     self.assertListEqual(UpperCAmelCase			,     UpperCAmelCase	)
     lowerCamelCase__    :      List[str]					 =		rust_tokenizer.tokenize(UpperCAmelCase	)
     self.assertListEqual(UpperCAmelCase			,     UpperCAmelCase	)
     lowerCamelCase__    :      str					 =		rust_tokenizer.convert_ids_to_tokens(UpperCAmelCase	)
     self.assertListEqual(UpperCAmelCase			,     UpperCAmelCase	)

     # fmt: off
     lowerCamelCase__    :      Optional[int]					 =		'I was born in 92000, and this is falsé.'
     lowerCamelCase__    :      Dict					 =		[13, 1, 23, 386, 19, 561, 3050, 15, 17, 48, 25, 8256, 18, 1, 9]
     lowerCamelCase__    :      List[str]					 =		['▁', 'I', '▁was', '▁born', '▁in', '▁9', '2000', ',', '▁and', '▁this', '▁is', '▁fal', 's', 'é', '.', ]
     lowerCamelCase__    :      Dict					 =		['▁', '<unk>', '▁was', '▁born', '▁in', '▁9', '2000', ',', '▁and', '▁this', '▁is', '▁fal', 's', '<unk>', '.', ]
     # fmt: on

     lowerCamelCase__    :      Any					 =		tokenizer.encode(UpperCAmelCase			,     add_special_tokens=UpperCAmelCase	)
     self.assertListEqual(UpperCAmelCase			,     UpperCAmelCase	)
     lowerCamelCase__    :      Dict					 =		tokenizer.tokenize(UpperCAmelCase	)
     self.assertListEqual(UpperCAmelCase			,     UpperCAmelCase	)
     lowerCamelCase__    :      Optional[int]					 =		tokenizer.convert_ids_to_tokens(UpperCAmelCase	)
     self.assertListEqual(UpperCAmelCase			,     UpperCAmelCase	)

     lowerCamelCase__    :      List[Any]					 =		rust_tokenizer.encode(UpperCAmelCase			,     add_special_tokens=UpperCAmelCase	)
     self.assertListEqual(UpperCAmelCase			,     UpperCAmelCase	)
     lowerCamelCase__    :      List[str]					 =		rust_tokenizer.tokenize(UpperCAmelCase	)
     self.assertListEqual(UpperCAmelCase			,     UpperCAmelCase	)
     lowerCamelCase__    :      List[Any]					 =		rust_tokenizer.convert_ids_to_tokens(UpperCAmelCase	)
     self.assertListEqual(UpperCAmelCase			,     UpperCAmelCase	)
 def      A_	(      self  :      int	)			->	List[Any]:
     lowerCamelCase__    :      Union[str, Any]					 =		DebertaVaTokenizer(UpperCAmelCase	)

     lowerCamelCase__    :      Dict					 =		tokenizer.encode('sequence builders'	)
     lowerCamelCase__    :      str					 =		tokenizer.encode('multi-sequence build'	)

     lowerCamelCase__    :      Optional[Any]					 =		tokenizer.build_inputs_with_special_tokens(UpperCAmelCase	)
     lowerCamelCase__    :      Union[str, Any]					 =		tokenizer.build_inputs_with_special_tokens(UpperCAmelCase			,     UpperCAmelCase	)

     self.assertEqual([tokenizer.cls_token_id] + text + [tokenizer.sep_token_id]			,     UpperCAmelCase	)
     self.assertEqual(
         [tokenizer.cls_token_id] + text + [tokenizer.sep_token_id] + text_a + [tokenizer.sep_token_id]			,     UpperCAmelCase			,     )







 @slow
 def      A_	(      self  :      Tuple	)			->	int:
     # fmt: off
     lowerCamelCase__    :      str					 =		{'input_ids': [[1, 39867, 36, 19390, 486, 27, 35052, 81436, 18, 60685, 1225, 7, 35052, 81436, 18, 9367, 16899, 18, 15937, 53, 594, 773, 18, 16287, 30465, 36, 15937, 6, 41139, 38, 36979, 60763, 191, 6, 34132, 99, 6, 50538, 390, 43230, 6, 34132, 2779, 20850, 14, 699, 1072, 1194, 36, 382, 10901, 53, 7, 699, 1072, 2084, 36, 20422, 630, 53, 19, 105, 3049, 1896, 1053, 16899, 1506, 11, 37978, 4243, 7, 1237, 31869, 200, 16566, 654, 6, 35052, 81436, 7, 55630, 13593, 4, 2], [1, 26, 15011, 13, 667, 8, 1053, 18, 23611, 1237, 72356, 12820, 34, 104134, 1209, 35, 13313, 6627, 21, 202, 347, 7, 164, 2399, 11, 46, 4485, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 5, 1232, 2864, 15785, 14951, 105, 5, 8581, 1250, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], 'token_type_ids': [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], 'attention_mask': [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]}  # noqa: E501
     # fmt: on

     self.tokenizer_integration_test_util(
         expected_encoding=UpperCAmelCase			,     model_name='microsoft/deberta-v2-xlarge'			,     revision='ad6e42c1532ddf3a15c39246b63f5559d558b670'			,     )








"""simple docstring"""


import unittest

from parameterized import parameterized

from transformers import OpenLlamaConfig, is_torch_available, set_seed
from transformers.testing_utils import require_torch, torch_device

from ...generation.test_utils import GenerationTesterMixin
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 OpenLlamaForCausalLM, OpenLlamaForSequenceClassification, OpenLlamaModel





class     snake_case	:

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



						'''simple docstring'''


						__lowerCAmelCase:       Tuple          =			parent
						__lowerCAmelCase:       Optional[int]          =			batch_size
						__lowerCAmelCase:       int          =			seq_length
						__lowerCAmelCase:       Any          =			is_training
						__lowerCAmelCase:       List[Any]          =			use_input_mask
						__lowerCAmelCase:       Any          =			use_token_type_ids
						__lowerCAmelCase:       Dict          =			use_labels
						__lowerCAmelCase:       Union[str, Any]          =			vocab_size
						__lowerCAmelCase:       Union[str, Any]          =			hidden_size
						__lowerCAmelCase:       int          =			num_hidden_layers
						__lowerCAmelCase:       List[Any]          =			num_attention_heads
						__lowerCAmelCase:       int          =			intermediate_size
						__lowerCAmelCase:       Optional[Any]          =			hidden_act
						__lowerCAmelCase:       Optional[Any]          =			hidden_dropout_prob
						__lowerCAmelCase:       Optional[int]          =			attention_probs_dropout_prob
						__lowerCAmelCase:       Any          =			max_position_embeddings
						__lowerCAmelCase:       Optional[int]          =			type_vocab_size
						__lowerCAmelCase:       str          =			type_sequence_label_size
						__lowerCAmelCase:       int          =			initializer_range
						__lowerCAmelCase:       Dict          =			num_labels
						__lowerCAmelCase:       Dict          =			num_choices
						__lowerCAmelCase:       str          =			scope

				def 							lowercase_     (	self							:				Optional[Any])->   Optional[Any]:



						'''simple docstring'''


						__lowerCAmelCase:       Optional[int]          =			ids_tensor([self.batch_size, self.seq_length]     ,  self.vocab_size)

						__lowerCAmelCase:       List[Any]          =			None
						if self.use_input_mask:
								__lowerCAmelCase:       int          =			random_attention_mask([self.batch_size, self.seq_length])

						__lowerCAmelCase:       Dict          =			None
						if self.use_token_type_ids:
								__lowerCAmelCase:       Any          =			ids_tensor([self.batch_size, self.seq_length]     ,  self.type_vocab_size)

						__lowerCAmelCase:       str          =			None
						__lowerCAmelCase:       Any          =			None
						__lowerCAmelCase:       Dict          =			None
						if self.use_labels:
								__lowerCAmelCase:       Any          =			ids_tensor([self.batch_size]     ,  self.type_sequence_label_size)
								__lowerCAmelCase:       Dict          =			ids_tensor([self.batch_size, self.seq_length]     ,  self.num_labels)
								__lowerCAmelCase:       Optional[int]          =			ids_tensor([self.batch_size]     ,  self.num_choices)

						__lowerCAmelCase:       Any          =			self.get_config()

						return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels

				def 							lowercase_     (	self							:				str)->   Dict:



						'''simple docstring'''


						return OpenLlamaConfig(
						    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_size=self.intermediate_size     ,  hidden_act=self.hidden_act     ,  hidden_dropout_prob=self.hidden_dropout_prob     ,  attention_probs_dropout_prob=self.attention_probs_dropout_prob     ,  max_position_embeddings=self.max_position_embeddings     ,  type_vocab_size=self.type_vocab_size     ,  is_decoder=UpperCamelCase__     ,  initializer_range=self.initializer_range     ,  use_stable_embedding=UpperCamelCase__     ,  )

				def 							lowercase_     (	self							:				Optional[Any]     ,  UpperCamelCase__							:				int     ,  UpperCamelCase__							:				Tuple     ,  UpperCamelCase__							:				List[Any]     ,  UpperCamelCase__							:				List[Any]     ,  UpperCamelCase__							:				Tuple     ,  UpperCamelCase__							:				List[Any]     ,  UpperCamelCase__							:				Optional[Any])->   str:



						'''simple docstring'''


						__lowerCAmelCase:       List[Any]          =			OpenLlamaModel(config=UpperCamelCase__)
						model.to(UpperCamelCase__)
						model.eval()
						__lowerCAmelCase:       Union[str, Any]          =			model(UpperCamelCase__     ,  attention_mask=UpperCamelCase__)
						__lowerCAmelCase:       int          =			model(UpperCamelCase__)
						self.parent.assertEqual(result.last_hidden_state.shape     ,  (self.batch_size, self.seq_length, self.hidden_size))

				def 							lowercase_     (	self							:				Optional[Any]     ,  UpperCamelCase__							:				List[str]     ,  UpperCamelCase__							:				Dict     ,  UpperCamelCase__							:				Union[str, Any]     ,  UpperCamelCase__							:				List[Any]     ,  UpperCamelCase__							:				Any     ,  UpperCamelCase__							:				Any     ,  UpperCamelCase__							:				List[Any]     ,  UpperCamelCase__							:				Union[str, Any]     ,  UpperCamelCase__							:				Tuple     ,  )->   Optional[int]:



						'''simple docstring'''


						__lowerCAmelCase:       Optional[Any]          =			True
						__lowerCAmelCase:       Any          =			OpenLlamaModel(UpperCamelCase__)
						model.to(UpperCamelCase__)
						model.eval()
						__lowerCAmelCase:       List[Any]          =			model(
						    UpperCamelCase__     ,  attention_mask=UpperCamelCase__     ,  encoder_hidden_states=UpperCamelCase__     ,  encoder_attention_mask=UpperCamelCase__     ,  )
						__lowerCAmelCase:       Optional[int]          =			model(
						    UpperCamelCase__     ,  attention_mask=UpperCamelCase__     ,  encoder_hidden_states=UpperCamelCase__     ,  )
						__lowerCAmelCase:       Optional[Any]          =			model(UpperCamelCase__     ,  attention_mask=UpperCamelCase__)
						self.parent.assertEqual(result.last_hidden_state.shape     ,  (self.batch_size, self.seq_length, self.hidden_size))

				def 							lowercase_     (	self							:				Dict     ,  UpperCamelCase__							:				Optional[int]     ,  UpperCamelCase__							:				Optional[int]     ,  UpperCamelCase__							:				List[Any]     ,  UpperCamelCase__							:				List[Any]     ,  UpperCamelCase__							:				Tuple     ,  UpperCamelCase__							:				List[Any]     ,  UpperCamelCase__							:				Union[str, Any]     ,  UpperCamelCase__							:				Union[str, Any]     ,  UpperCamelCase__							:				List[str]     ,  )->   Optional[int]:



						'''simple docstring'''


						__lowerCAmelCase:       str          =			OpenLlamaForCausalLM(config=UpperCamelCase__)
						model.to(UpperCamelCase__)
						model.eval()
						__lowerCAmelCase:       Optional[int]          =			model(UpperCamelCase__     ,  attention_mask=UpperCamelCase__     ,  labels=UpperCamelCase__)
						self.parent.assertEqual(result.logits.shape     ,  (self.batch_size, self.seq_length, self.vocab_size))

				def 							lowercase_     (	self							:				Tuple     ,  UpperCamelCase__							:				Union[str, Any]     ,  UpperCamelCase__							:				str     ,  UpperCamelCase__							:				Optional[int]     ,  UpperCamelCase__							:				Any     ,  UpperCamelCase__							:				int     ,  UpperCamelCase__							:				int     ,  UpperCamelCase__							:				List[Any]     ,  UpperCamelCase__							:				List[Any]     ,  UpperCamelCase__							:				int     ,  )->   Tuple:



						'''simple docstring'''


						__lowerCAmelCase:       Union[str, Any]          =			True
						__lowerCAmelCase:       Dict          =			True
						__lowerCAmelCase:       Union[str, Any]          =			OpenLlamaForCausalLM(config=UpperCamelCase__)
						model.to(UpperCamelCase__)
						model.eval()

						# first forward pass
						__lowerCAmelCase:       Optional[int]          =			model(
						    UpperCamelCase__     ,  attention_mask=UpperCamelCase__     ,  encoder_hidden_states=UpperCamelCase__     ,  encoder_attention_mask=UpperCamelCase__     ,  use_cache=UpperCamelCase__     ,  )
						__lowerCAmelCase:       Optional[int]          =			outputs.past_key_values

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

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

						__lowerCAmelCase:       Union[str, Any]          =			model(
						    UpperCamelCase__     ,  attention_mask=UpperCamelCase__     ,  encoder_hidden_states=UpperCamelCase__     ,  encoder_attention_mask=UpperCamelCase__     ,  output_hidden_states=UpperCamelCase__     ,  )["hidden_states"][0]
						__lowerCAmelCase:       List[str]          =			model(
						    UpperCamelCase__     ,  attention_mask=UpperCamelCase__     ,  encoder_hidden_states=UpperCamelCase__     ,  encoder_attention_mask=UpperCamelCase__     ,  past_key_values=UpperCamelCase__     ,  output_hidden_states=UpperCamelCase__     ,  )["hidden_states"][0]

						# select random slice
						__lowerCAmelCase:       List[str]          =			ids_tensor((1,)     ,  output_from_past.shape[-1]).item()
						__lowerCAmelCase:       List[Any]          =			output_from_no_past[:, -3:, random_slice_idx].detach()
						__lowerCAmelCase:       Union[str, Any]          =			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 							lowercase_     (	self							:				Tuple)->   str:



						'''simple docstring'''


						__lowerCAmelCase:       Union[str, Any]          =			self.prepare_config_and_inputs()
						(
						    (
						    __lowerCAmelCase
						)      , (
						    __lowerCAmelCase
						)      , (
						    __lowerCAmelCase
						)      , (
						    __lowerCAmelCase
						)      , (
						    __lowerCAmelCase
						)      , (
						    __lowerCAmelCase
						)      , (
						    __lowerCAmelCase
						)      , 
						):       List[Any]          =			config_and_inputs
						__lowerCAmelCase:       Any          =			{"input_ids": input_ids, "attention_mask": input_mask}
						return config, inputs_dict





@require_torch
class     snake_case	(				__snake_case,							__snake_case,							__snake_case,							unittest.TestCase  ):
				SCREAMING_SNAKE_CASE_   :      Tuple         =  (
				    (OpenLlamaModel, OpenLlamaForCausalLM, OpenLlamaForSequenceClassification) if is_torch_available() else ()
				)
				SCREAMING_SNAKE_CASE_   :      Any         =  (OpenLlamaForCausalLM,) if is_torch_available() else ()
				SCREAMING_SNAKE_CASE_   :      Optional[int]         =  (
				    {
				        """feature-extraction""": OpenLlamaModel,
				        """text-classification""": OpenLlamaForSequenceClassification,
				        """text-generation""": OpenLlamaForCausalLM,
				        """zero-shot""": OpenLlamaForSequenceClassification,
				    }
				    if is_torch_available()
				    else {}
				)
				SCREAMING_SNAKE_CASE_   :      List[str]         =  False
				SCREAMING_SNAKE_CASE_   :      List[Any]         =  False

				def 							lowercase_     (	self							:				Dict)->   Union[str, Any]:



						'''simple docstring'''


						__lowerCAmelCase:       int          =			OpenLlamaModelTester(self)
						__lowerCAmelCase:       Optional[Any]          =			ConfigTester(self     ,  config_class=UpperCamelCase__     ,  hidden_size=3_7)

				def 							lowercase_     (	self							:				List[str])->   Union[str, Any]:



						'''simple docstring'''


						self.config_tester.run_common_tests()

				def 							lowercase_     (	self							:				Union[str, Any])->   List[Any]:



						'''simple docstring'''


						__lowerCAmelCase:       Any          =			self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_model(*UpperCamelCase__)

				def 							lowercase_     (	self							:				int)->   str:



						'''simple docstring'''


						__lowerCAmelCase:       Optional[Any]          =			self.model_tester.prepare_config_and_inputs()
						for type in ["absolute", "relative_key", "relative_key_query"]:
								__lowerCAmelCase:       Union[str, Any]          =			type
								self.model_tester.create_and_check_model(*UpperCamelCase__)

				def 							lowercase_     (	self							:				Tuple)->   Optional[Any]:



						'''simple docstring'''


						__lowerCAmelCase      , __lowerCAmelCase:       List[Any]          =			self.model_tester.prepare_config_and_inputs_for_common()
						__lowerCAmelCase:       Dict          =			3
						__lowerCAmelCase:       Optional[Any]          =			input_dict["input_ids"]
						__lowerCAmelCase:       Optional[Any]          =			input_ids.ne(1).to(UpperCamelCase__)
						__lowerCAmelCase:       Union[str, Any]          =			ids_tensor([self.model_tester.batch_size]     ,  self.model_tester.type_sequence_label_size)
						__lowerCAmelCase:       Dict          =			OpenLlamaForSequenceClassification(UpperCamelCase__)
						model.to(UpperCamelCase__)
						model.eval()
						__lowerCAmelCase:       Optional[int]          =			model(UpperCamelCase__     ,  attention_mask=UpperCamelCase__     ,  labels=UpperCamelCase__)
						self.assertEqual(result.logits.shape     ,  (self.model_tester.batch_size, self.model_tester.num_labels))

				def 							lowercase_     (	self							:				Dict)->   Tuple:



						'''simple docstring'''


						__lowerCAmelCase      , __lowerCAmelCase:       Union[str, Any]          =			self.model_tester.prepare_config_and_inputs_for_common()
						__lowerCAmelCase:       int          =			3
						__lowerCAmelCase:       Dict          =			"single_label_classification"
						__lowerCAmelCase:       str          =			input_dict["input_ids"]
						__lowerCAmelCase:       Tuple          =			input_ids.ne(1).to(UpperCamelCase__)
						__lowerCAmelCase:       Tuple          =			ids_tensor([self.model_tester.batch_size]     ,  self.model_tester.type_sequence_label_size)
						__lowerCAmelCase:       List[Any]          =			OpenLlamaForSequenceClassification(UpperCamelCase__)
						model.to(UpperCamelCase__)
						model.eval()
						__lowerCAmelCase:       Optional[Any]          =			model(UpperCamelCase__     ,  attention_mask=UpperCamelCase__     ,  labels=UpperCamelCase__)
						self.assertEqual(result.logits.shape     ,  (self.model_tester.batch_size, self.model_tester.num_labels))

				def 							lowercase_     (	self							:				Optional[int])->   Any:



						'''simple docstring'''


						__lowerCAmelCase      , __lowerCAmelCase:       str          =			self.model_tester.prepare_config_and_inputs_for_common()
						__lowerCAmelCase:       Tuple          =			3
						__lowerCAmelCase:       Any          =			"multi_label_classification"
						__lowerCAmelCase:       str          =			input_dict["input_ids"]
						__lowerCAmelCase:       Optional[int]          =			input_ids.ne(1).to(UpperCamelCase__)
						__lowerCAmelCase:       Optional[int]          =			ids_tensor(
						    [self.model_tester.batch_size, config.num_labels]     ,  self.model_tester.type_sequence_label_size).to(torch.float)
						__lowerCAmelCase:       Dict          =			OpenLlamaForSequenceClassification(UpperCamelCase__)
						model.to(UpperCamelCase__)
						model.eval()
						__lowerCAmelCase:       Union[str, Any]          =			model(UpperCamelCase__     ,  attention_mask=UpperCamelCase__     ,  labels=UpperCamelCase__)
						self.assertEqual(result.logits.shape     ,  (self.model_tester.batch_size, self.model_tester.num_labels))

				@unittest.skip("Open-Llama buffers include complex numbers, which breaks this test")
				def 							lowercase_     (	self							:				Any)->   Tuple:



						'''simple docstring'''


						pass




				@parameterized.expand([("linear",), ("dynamic",)])
				def 							lowercase_     (	self							:				Any     ,  UpperCamelCase__							:				List[str])->   Dict:



						'''simple docstring'''


						__lowerCAmelCase      , __lowerCAmelCase:       Optional[Any]          =			self.model_tester.prepare_config_and_inputs_for_common()
						__lowerCAmelCase:       Any          =			ids_tensor([1, 1_0]     ,  config.vocab_size)
						__lowerCAmelCase:       Union[str, Any]          =			ids_tensor([1, int(config.max_position_embeddings * 1.5)]     ,  config.vocab_size)

						set_seed(4_2)  # Fixed seed at init time so the two models get the same random weights
						__lowerCAmelCase:       List[Any]          =			OpenLlamaModel(UpperCamelCase__)
						original_model.to(UpperCamelCase__)
						original_model.eval()
						__lowerCAmelCase:       int          =			original_model(UpperCamelCase__).last_hidden_state
						__lowerCAmelCase:       str          =			original_model(UpperCamelCase__).last_hidden_state

						set_seed(4_2)  # Fixed seed at init time so the two models get the same random weights
						__lowerCAmelCase:       Dict          =			{"type": scaling_type, "factor": 10.0}
						__lowerCAmelCase:       List[str]          =			OpenLlamaModel(UpperCamelCase__)
						scaled_model.to(UpperCamelCase__)
						scaled_model.eval()
						__lowerCAmelCase:       Dict          =			scaled_model(UpperCamelCase__).last_hidden_state
						__lowerCAmelCase:       Any          =			scaled_model(UpperCamelCase__).last_hidden_state

						# Dynamic scaling does not change the RoPE embeddings until it receives an input longer than the original
						# maximum sequence length, so the outputs for the short input should match.
						if scaling_type == "dynamic":
								self.assertTrue(torch.allclose(UpperCamelCase__     ,  UpperCamelCase__     ,  atol=1e-5))
						else:
								self.assertFalse(torch.allclose(UpperCamelCase__     ,  UpperCamelCase__     ,  atol=1e-5))

						# The output should be different for long inputs
						self.assertFalse(torch.allclose(UpperCamelCase__     ,  UpperCamelCase__     ,  atol=1e-5))


