



"""simple docstring"""






import os
import unittest

from transformers import ElectraTokenizerFast
from transformers.models.electra.tokenization_electra import (
    VOCAB_FILES_NAMES,
    BasicTokenizer,
    ElectraTokenizer,
    WordpieceTokenizer,
    _is_control,
    _is_punctuation,
    _is_whitespace,
)
from transformers.testing_utils import require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin, filter_non_english
@require_tokenizers
class   UpperCAmelCase__				(    UpperCamelCase_,      unittest.TestCase			):


	"""simple docstring"""
	lowerCAmelCase__    :					Dict						      =							ElectraTokenizer
	lowerCAmelCase__    :					Any						      =							ElectraTokenizerFast
	lowerCAmelCase__    :					Union[str, Any]						      =							True
	lowerCAmelCase__    :					Optional[int]						      =							True
	lowerCAmelCase__    :					Tuple						      =							filter_non_english







	def       A    (			self )    ->	str:
							super().setUp()

							a_							:			Tuple     		=					[
							    '''[UNK]''',
							    '''[CLS]''',
							    '''[SEP]''',
							    '''[PAD]''',
							    '''[MASK]''',
							    '''want''',
							    '''##want''',
							    '''##ed''',
							    '''wa''',
							    '''un''',
							    '''runn''',
							    '''##ing''',
							    ''',''',
							    '''low''',
							    '''lowest''',
							]
							a_							:			Dict     		=					os.path.join(self.tmpdirname       ,     VOCAB_FILES_NAMES["vocab_file"] )
							with open(self.vocab_file       ,     "w"       ,     encoding="utf-8" ) as vocab_writer:
													vocab_writer.write("".join([x + "\n" for x in vocab_tokens] ) )







	def       A    (			self       ,     _SCREAMING_SNAKE_CASE )    ->	int:
							a_							:			Any     		=					'''UNwant\u00E9d,running'''
							a_							:			Dict     		=					'''unwanted, running'''
							return input_text, output_text







	def       A    (			self )    ->	Dict:
							a_							:			str     		=					self.tokenizer_class(self.vocab_file )

							a_							:			Optional[Any]     		=					tokenizer.tokenize("UNwant\u00E9d,running" )
							self.assertListEqual(__UpperCamelCase       ,     ["un", "##want", "##ed", ",", "runn", "##ing"] )
							self.assertListEqual(tokenizer.convert_tokens_to_ids(__UpperCamelCase )       ,     [9, 6, 7, 1_2, 1_0, 1_1] )







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


							if not self.test_rust_tokenizer:
													return

							a_							:			str     		=					self.get_tokenizer()
							a_							:			List[str]     		=					self.get_rust_tokenizer()

							a_							:			str     		=					'''UNwant\u00E9d,running'''

							a_							:			Union[str, Any]     		=					tokenizer.tokenize(__UpperCamelCase )
							a_							:			Optional[Any]     		=					rust_tokenizer.tokenize(__UpperCamelCase )
							self.assertListEqual(__UpperCamelCase       ,     __UpperCamelCase )

							a_							:			str     		=					tokenizer.encode(__UpperCamelCase       ,     add_special_tokens=__UpperCamelCase )
							a_							:			List[Any]     		=					rust_tokenizer.encode(__UpperCamelCase       ,     add_special_tokens=__UpperCamelCase )
							self.assertListEqual(__UpperCamelCase       ,     __UpperCamelCase )

							a_							:			Any     		=					self.get_rust_tokenizer()
							a_							:			Optional[Any]     		=					tokenizer.encode(__UpperCamelCase )
							a_							:			Any     		=					rust_tokenizer.encode(__UpperCamelCase )
							self.assertListEqual(__UpperCamelCase       ,     __UpperCamelCase )

							# With lower casing
							a_							:			Union[str, Any]     		=					self.get_tokenizer(do_lower_case=__UpperCamelCase )
							a_							:			str     		=					self.get_rust_tokenizer(do_lower_case=__UpperCamelCase )

							a_							:			Optional[int]     		=					'''UNwant\u00E9d,running'''

							a_							:			Optional[int]     		=					tokenizer.tokenize(__UpperCamelCase )
							a_							:			List[str]     		=					rust_tokenizer.tokenize(__UpperCamelCase )
							self.assertListEqual(__UpperCamelCase       ,     __UpperCamelCase )

							a_							:			Optional[int]     		=					tokenizer.encode(__UpperCamelCase       ,     add_special_tokens=__UpperCamelCase )
							a_							:			str     		=					rust_tokenizer.encode(__UpperCamelCase       ,     add_special_tokens=__UpperCamelCase )
							self.assertListEqual(__UpperCamelCase       ,     __UpperCamelCase )

							a_							:			Union[str, Any]     		=					self.get_rust_tokenizer()
							a_							:			Optional[Any]     		=					tokenizer.encode(__UpperCamelCase )
							a_							:			str     		=					rust_tokenizer.encode(__UpperCamelCase )
							self.assertListEqual(__UpperCamelCase       ,     __UpperCamelCase )







	def       A    (			self )    ->	str:
							a_							:			List[str]     		=					BasicTokenizer()

							self.assertListEqual(tokenizer.tokenize("ah\u535A\u63A8zz" )       ,     ["ah", "\u535A", "\u63A8", "zz"] )







	def       A    (			self )    ->	Tuple:
							a_							:			List[str]     		=					BasicTokenizer(do_lower_case=__UpperCamelCase )

							self.assertListEqual(
							    tokenizer.tokenize(" \tHeLLo!how  \n Are yoU?  " )       ,     ["hello", "!", "how", "are", "you", "?"] )
							self.assertListEqual(tokenizer.tokenize("H\u00E9llo" )       ,     ["hello"] )







	def       A    (			self )    ->	int:
							a_							:			Optional[Any]     		=					BasicTokenizer(do_lower_case=__UpperCamelCase       ,     strip_accents=__UpperCamelCase )

							self.assertListEqual(
							    tokenizer.tokenize(" \tHäLLo!how  \n Are yoU?  " )       ,     ["hällo", "!", "how", "are", "you", "?"] )
							self.assertListEqual(tokenizer.tokenize("H\u00E9llo" )       ,     ["h\u00E9llo"] )







	def       A    (			self )    ->	Optional[Any]:
							a_							:			Optional[int]     		=					BasicTokenizer(do_lower_case=__UpperCamelCase       ,     strip_accents=__UpperCamelCase )

							self.assertListEqual(
							    tokenizer.tokenize(" \tHäLLo!how  \n Are yoU?  " )       ,     ["hallo", "!", "how", "are", "you", "?"] )
							self.assertListEqual(tokenizer.tokenize("H\u00E9llo" )       ,     ["hello"] )







	def       A    (			self )    ->	List[Any]:
							a_							:			Optional[int]     		=					BasicTokenizer(do_lower_case=__UpperCamelCase )

							self.assertListEqual(
							    tokenizer.tokenize(" \tHäLLo!how  \n Are yoU?  " )       ,     ["hallo", "!", "how", "are", "you", "?"] )
							self.assertListEqual(tokenizer.tokenize("H\u00E9llo" )       ,     ["hello"] )







	def       A    (			self )    ->	str:
							a_							:			int     		=					BasicTokenizer(do_lower_case=__UpperCamelCase )

							self.assertListEqual(
							    tokenizer.tokenize(" \tHeLLo!how  \n Are yoU?  " )       ,     ["HeLLo", "!", "how", "Are", "yoU", "?"] )







	def       A    (			self )    ->	Optional[int]:
							a_							:			Dict     		=					BasicTokenizer(do_lower_case=__UpperCamelCase       ,     strip_accents=__UpperCamelCase )

							self.assertListEqual(
							    tokenizer.tokenize(" \tHäLLo!how  \n Are yoU?  " )       ,     ["HäLLo", "!", "how", "Are", "yoU", "?"] )







	def       A    (			self )    ->	str:
							a_							:			Any     		=					BasicTokenizer(do_lower_case=__UpperCamelCase       ,     strip_accents=__UpperCamelCase )

							self.assertListEqual(
							    tokenizer.tokenize(" \tHäLLo!how  \n Are yoU?  " )       ,     ["HaLLo", "!", "how", "Are", "yoU", "?"] )







	def       A    (			self )    ->	Optional[Any]:
							a_							:			List[Any]     		=					BasicTokenizer(do_lower_case=__UpperCamelCase       ,     never_split=["[UNK]"] )

							self.assertListEqual(
							    tokenizer.tokenize(" \tHeLLo!how  \n Are yoU? [UNK]" )       ,     ["HeLLo", "!", "how", "Are", "yoU", "?", "[UNK]"] )







	def       A    (			self )    ->	List[str]:
							a_							:			Any     		=					['''[UNK]''', '''[CLS]''', '''[SEP]''', '''want''', '''##want''', '''##ed''', '''wa''', '''un''', '''runn''', '''##ing''']

							a_							:			str     		=					{}
							for i, token in enumerate(__UpperCamelCase ):
													a_							:			Optional[Any]     		=					i
							a_							:			Any     		=					WordpieceTokenizer(vocab=__UpperCamelCase       ,     unk_token="[UNK]" )

							self.assertListEqual(tokenizer.tokenize("" )       ,     [] )

							self.assertListEqual(tokenizer.tokenize("unwanted running" )       ,     ["un", "##want", "##ed", "runn", "##ing"] )

							self.assertListEqual(tokenizer.tokenize("unwantedX running" )       ,     ["[UNK]", "runn", "##ing"] )







	def       A    (			self )    ->	str:
							self.assertTrue(_is_whitespace(" " ) )
							self.assertTrue(_is_whitespace("\t" ) )
							self.assertTrue(_is_whitespace("\r" ) )
							self.assertTrue(_is_whitespace("\n" ) )
							self.assertTrue(_is_whitespace("\u00A0" ) )

							self.assertFalse(_is_whitespace("A" ) )
							self.assertFalse(_is_whitespace("-" ) )







	def       A    (			self )    ->	Union[str, Any]:
							self.assertTrue(_is_control("\u0005" ) )

							self.assertFalse(_is_control("A" ) )
							self.assertFalse(_is_control(" " ) )
							self.assertFalse(_is_control("\t" ) )
							self.assertFalse(_is_control("\r" ) )







	def       A    (			self )    ->	List[str]:
							self.assertTrue(_is_punctuation("-" ) )
							self.assertTrue(_is_punctuation("$" ) )
							self.assertTrue(_is_punctuation("`" ) )
							self.assertTrue(_is_punctuation("." ) )

							self.assertFalse(_is_punctuation("A" ) )
							self.assertFalse(_is_punctuation(" " ) )







	def       A    (			self )    ->	Union[str, Any]:
							a_							:			Optional[int]     		=					self.get_tokenizer()
							a_							:			Optional[int]     		=					self.get_rust_tokenizer()

							# Example taken from the issue https://github.com/huggingface/tokenizers/issues/340
							self.assertListEqual([tokenizer.tokenize(__UpperCamelCase ) for t in ["Test", "\xad", "test"]]       ,     [["[UNK]"], [], ["[UNK]"]] )

							self.assertListEqual(
							    [rust_tokenizer.tokenize(__UpperCamelCase ) for t in ["Test", "\xad", "test"]]       ,     [["[UNK]"], [], ["[UNK]"]] )







	@slow
	def       A    (			self )    ->	Optional[int]:
							a_							:			Dict     		=					self.tokenizer_class.from_pretrained("google/electra-base-discriminator" )

							a_							:			Dict     		=					tokenizer.encode("sequence builders"       ,     add_special_tokens=__UpperCamelCase )
							a_							:			Optional[Any]     		=					tokenizer.encode("multi-sequence build"       ,     add_special_tokens=__UpperCamelCase )

							a_							:			int     		=					tokenizer.build_inputs_with_special_tokens(__UpperCamelCase )
							a_							:			List[str]     		=					tokenizer.build_inputs_with_special_tokens(__UpperCamelCase       ,     __UpperCamelCase )

							assert encoded_sentence == [1_0_1] + text + [1_0_2]
							assert encoded_pair == [1_0_1] + text + [1_0_2] + text_a + [1_0_2]







	def       A    (			self )    ->	Tuple:


							for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
													with self.subTest(f'''{tokenizer.__class__.__name__} ({pretrained_name})''' ):
																			a_							:			Dict     		=					self.rust_tokenizer_class.from_pretrained(__UpperCamelCase       ,     **__UpperCamelCase )

																			a_							:			List[str]     		=					f'''A, naïve {tokenizer_r.mask_token} AllenNLP sentence.'''
																			a_							:			Optional[int]     		=					tokenizer_r.encode_plus(
																			    __UpperCamelCase       ,     return_attention_mask=__UpperCamelCase       ,     return_token_type_ids=__UpperCamelCase       ,     return_offsets_mapping=__UpperCamelCase       ,     add_special_tokens=__UpperCamelCase       ,     )

																			a_							:			Dict     		=					tokenizer_r.do_lower_case if hasattr(__UpperCamelCase       ,     "do_lower_case" ) else False
																			a_							:			Union[str, Any]     		=					(
																			    [
																			        ((0, 0), tokenizer_r.cls_token),
																			        ((0, 1), '''A'''),
																			        ((1, 2), ''','''),
																			        ((3, 5), '''na'''),
																			        ((5, 6), '''##ï'''),
																			        ((6, 8), '''##ve'''),
																			        ((9, 1_5), tokenizer_r.mask_token),
																			        ((1_6, 2_1), '''Allen'''),
																			        ((2_1, 2_3), '''##NL'''),
																			        ((2_3, 2_4), '''##P'''),
																			        ((2_5, 3_3), '''sentence'''),
																			        ((3_3, 3_4), '''.'''),
																			        ((0, 0), tokenizer_r.sep_token),
																			    ]
																			    if not do_lower_case
																			    else [
																			        ((0, 0), tokenizer_r.cls_token),
																			        ((0, 1), '''a'''),
																			        ((1, 2), ''','''),
																			        ((3, 8), '''naive'''),
																			        ((9, 1_5), tokenizer_r.mask_token),
																			        ((1_6, 2_1), '''allen'''),
																			        ((2_1, 2_3), '''##nl'''),
																			        ((2_3, 2_4), '''##p'''),
																			        ((2_5, 3_3), '''sentence'''),
																			        ((3_3, 3_4), '''.'''),
																			        ((0, 0), tokenizer_r.sep_token),
																			    ]
																			)

																			self.assertEqual(
																			    [e[1] for e in expected_results]       ,     tokenizer_r.convert_ids_to_tokens(tokens["input_ids"] ) )
																			self.assertEqual([e[0] for e in expected_results]       ,     tokens["offset_mapping"] )







	def       A    (			self )    ->	List[Any]:
							a_							:			Dict     		=					['''的''', '''人''', '''有''']
							a_							:			Any     		=					''''''.join(__UpperCamelCase )
							for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
													with self.subTest(f'''{tokenizer.__class__.__name__} ({pretrained_name})''' ):
																			a_							:			Optional[int]     		=					True
																			a_							:			List[Any]     		=					self.tokenizer_class.from_pretrained(__UpperCamelCase       ,     **__UpperCamelCase )
																			a_							:			List[str]     		=					self.rust_tokenizer_class.from_pretrained(__UpperCamelCase       ,     **__UpperCamelCase )

																			a_							:			Optional[Any]     		=					tokenizer_p.encode(__UpperCamelCase       ,     add_special_tokens=__UpperCamelCase )
																			a_							:			int     		=					tokenizer_r.encode(__UpperCamelCase       ,     add_special_tokens=__UpperCamelCase )

																			a_							:			Any     		=					tokenizer_r.convert_ids_to_tokens(__UpperCamelCase )
																			a_							:			List[Any]     		=					tokenizer_p.convert_ids_to_tokens(__UpperCamelCase )

																			# it is expected that each Chinese character is not preceded by "##"
																			self.assertListEqual(__UpperCamelCase       ,     __UpperCamelCase )
																			self.assertListEqual(__UpperCamelCase       ,     __UpperCamelCase )

																			a_							:			int     		=					False
																			a_							:			Union[str, Any]     		=					self.rust_tokenizer_class.from_pretrained(__UpperCamelCase       ,     **__UpperCamelCase )
																			a_							:			str     		=					self.tokenizer_class.from_pretrained(__UpperCamelCase       ,     **__UpperCamelCase )

																			a_							:			List[str]     		=					tokenizer_r.encode(__UpperCamelCase       ,     add_special_tokens=__UpperCamelCase )
																			a_							:			List[Any]     		=					tokenizer_p.encode(__UpperCamelCase       ,     add_special_tokens=__UpperCamelCase )

																			a_							:			List[str]     		=					tokenizer_r.convert_ids_to_tokens(__UpperCamelCase )
																			a_							:			Any     		=					tokenizer_p.convert_ids_to_tokens(__UpperCamelCase )

																			# it is expected that only the first Chinese character is not preceded by "##".
																			a_							:			Optional[int]     		=					[
																			    f'''##{token}''' if idx != 0 else token for idx, token in enumerate(__UpperCamelCase )
																			]
																			self.assertListEqual(__UpperCamelCase       ,     __UpperCamelCase )
																			self.assertListEqual(__UpperCamelCase       ,     __UpperCamelCase )





"""simple docstring"""






import unittest

from transformers import YosoConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
				import torch

				from transformers import (
				    YosoForMaskedLM,
				    YosoForMultipleChoice,
				    YosoForQuestionAnswering,
				    YosoForSequenceClassification,
				    YosoForTokenClassification,
				    YosoModel,
				)
				from transformers.models.yoso.modeling_yoso import YOSO_PRETRAINED_MODEL_ARCHIVE_LIST
class   UpperCAmelCase__				:


	"""simple docstring"""







	def __init__(			self       ,     _SCREAMING_SNAKE_CASE       ,     _SCREAMING_SNAKE_CASE=1_3       ,     _SCREAMING_SNAKE_CASE=7       ,     _SCREAMING_SNAKE_CASE=True       ,     _SCREAMING_SNAKE_CASE=True       ,     _SCREAMING_SNAKE_CASE=True       ,     _SCREAMING_SNAKE_CASE=True       ,     _SCREAMING_SNAKE_CASE=9_9       ,     _SCREAMING_SNAKE_CASE=3_2       ,     _SCREAMING_SNAKE_CASE=5       ,     _SCREAMING_SNAKE_CASE=4       ,     _SCREAMING_SNAKE_CASE=3_7       ,     _SCREAMING_SNAKE_CASE="gelu"       ,     _SCREAMING_SNAKE_CASE=0.1       ,     _SCREAMING_SNAKE_CASE=0.1       ,     _SCREAMING_SNAKE_CASE=5_1_2       ,     _SCREAMING_SNAKE_CASE=1_6       ,     _SCREAMING_SNAKE_CASE=2       ,     _SCREAMING_SNAKE_CASE=0.0_2       ,     _SCREAMING_SNAKE_CASE=3       ,     _SCREAMING_SNAKE_CASE=4       ,     _SCREAMING_SNAKE_CASE=None       ,     )    ->	Optional[int]:
							a_							:			str     		=					parent
							a_							:			Tuple     		=					batch_size
							a_							:			Optional[int]     		=					seq_length
							a_							:			Any     		=					is_training
							a_							:			List[str]     		=					use_input_mask
							a_							:			Optional[Any]     		=					use_token_type_ids
							a_							:			Dict     		=					use_labels
							a_							:			str     		=					vocab_size
							a_							:			Optional[int]     		=					hidden_size
							a_							:			str     		=					num_hidden_layers
							a_							:			List[str]     		=					num_attention_heads
							a_							:			List[Any]     		=					intermediate_size
							a_							:			Any     		=					hidden_act
							a_							:			Union[str, Any]     		=					hidden_dropout_prob
							a_							:			Tuple     		=					attention_probs_dropout_prob
							a_							:			Tuple     		=					max_position_embeddings
							a_							:			Tuple     		=					type_vocab_size
							a_							:			Union[str, Any]     		=					type_sequence_label_size
							a_							:			List[str]     		=					initializer_range
							a_							:			List[str]     		=					num_labels
							a_							:			Optional[Any]     		=					num_choices
							a_							:			Dict     		=					scope







	def       A    (			self )    ->	Optional[int]:
							a_							:			int     		=					ids_tensor([self.batch_size, self.seq_length]       ,     self.vocab_size )

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

							a_							:			List[str]     		=					None
							if self.use_token_type_ids:
													a_							:			str     		=					ids_tensor([self.batch_size, self.seq_length]       ,     self.type_vocab_size )

							a_							:			Dict     		=					None
							a_							:			Dict     		=					None
							a_							:			Union[str, Any]     		=					None
							if self.use_labels:
													a_							:			List[str]     		=					ids_tensor([self.batch_size]       ,     self.type_sequence_label_size )
													a_							:			List[Any]     		=					ids_tensor([self.batch_size, self.seq_length]       ,     self.num_labels )
													a_							:			List[Any]     		=					ids_tensor([self.batch_size]       ,     self.num_choices )

							a_							:			str     		=					self.get_config()

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







	def       A    (			self )    ->	Dict:
							return YosoConfig(
							    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=_SCREAMING_SNAKE_CASE       ,     initializer_range=self.initializer_range       ,     )







	def       A    (			self )    ->	Optional[Any]:
							a_							:			Optional[int]     		=					self.get_config()
							a_							:			List[Any]     		=					3_0_0
							return config







	def       A    (			self )    ->	int:
							(
							    (
							    a_
							)		,					(
							    a_
							)		,					(
							    a_
							)		,					(
							    a_
							)		,					(
							    a_
							)		,					(
							    a_
							)		,					(
							    a_
							)		,					
							)							:			Tuple     		=					self.prepare_config_and_inputs()

							a_							:			Optional[int]     		=					True
							a_							:			str     		=					floats_tensor([self.batch_size, self.seq_length, self.hidden_size] )
							a_							:			Tuple     		=					ids_tensor([self.batch_size, self.seq_length]       ,     vocab_size=2 )

							return (
							    config,
							    input_ids,
							    token_type_ids,
							    input_mask,
							    sequence_labels,
							    token_labels,
							    choice_labels,
							    encoder_hidden_states,
							    encoder_attention_mask,
							)







	def       A    (			self       ,     _SCREAMING_SNAKE_CASE       ,     _SCREAMING_SNAKE_CASE       ,     _SCREAMING_SNAKE_CASE       ,     _SCREAMING_SNAKE_CASE       ,     _SCREAMING_SNAKE_CASE       ,     _SCREAMING_SNAKE_CASE       ,     _SCREAMING_SNAKE_CASE )    ->	List[str]:
							a_							:			Tuple     		=					YosoModel(config=_SCREAMING_SNAKE_CASE )
							model.to(_SCREAMING_SNAKE_CASE )
							model.eval()
							a_							:			Optional[Any]     		=					model(_SCREAMING_SNAKE_CASE       ,     attention_mask=_SCREAMING_SNAKE_CASE       ,     token_type_ids=_SCREAMING_SNAKE_CASE )
							a_							:			Optional[Any]     		=					model(_SCREAMING_SNAKE_CASE       ,     token_type_ids=_SCREAMING_SNAKE_CASE )
							a_							:			Union[str, Any]     		=					model(_SCREAMING_SNAKE_CASE )
							self.parent.assertEqual(result.last_hidden_state.shape       ,     (self.batch_size, self.seq_length, self.hidden_size) )







	def       A    (			self       ,     _SCREAMING_SNAKE_CASE       ,     _SCREAMING_SNAKE_CASE       ,     _SCREAMING_SNAKE_CASE       ,     _SCREAMING_SNAKE_CASE       ,     _SCREAMING_SNAKE_CASE       ,     _SCREAMING_SNAKE_CASE       ,     _SCREAMING_SNAKE_CASE       ,     _SCREAMING_SNAKE_CASE       ,     _SCREAMING_SNAKE_CASE       ,     )    ->	List[Any]:
							a_							:			int     		=					True
							a_							:			Optional[Any]     		=					YosoModel(_SCREAMING_SNAKE_CASE )
							model.to(_SCREAMING_SNAKE_CASE )
							model.eval()
							a_							:			Tuple     		=					model(
							    _SCREAMING_SNAKE_CASE       ,     attention_mask=_SCREAMING_SNAKE_CASE       ,     token_type_ids=_SCREAMING_SNAKE_CASE       ,     encoder_hidden_states=_SCREAMING_SNAKE_CASE       ,     encoder_attention_mask=_SCREAMING_SNAKE_CASE       ,     )
							a_							:			str     		=					model(
							    _SCREAMING_SNAKE_CASE       ,     attention_mask=_SCREAMING_SNAKE_CASE       ,     token_type_ids=_SCREAMING_SNAKE_CASE       ,     encoder_hidden_states=_SCREAMING_SNAKE_CASE       ,     )
							a_							:			str     		=					model(_SCREAMING_SNAKE_CASE       ,     attention_mask=_SCREAMING_SNAKE_CASE       ,     token_type_ids=_SCREAMING_SNAKE_CASE )
							self.parent.assertEqual(result.last_hidden_state.shape       ,     (self.batch_size, self.seq_length, self.hidden_size) )







	def       A    (			self       ,     _SCREAMING_SNAKE_CASE       ,     _SCREAMING_SNAKE_CASE       ,     _SCREAMING_SNAKE_CASE       ,     _SCREAMING_SNAKE_CASE       ,     _SCREAMING_SNAKE_CASE       ,     _SCREAMING_SNAKE_CASE       ,     _SCREAMING_SNAKE_CASE )    ->	List[str]:
							a_							:			Optional[int]     		=					YosoForMaskedLM(config=_SCREAMING_SNAKE_CASE )
							model.to(_SCREAMING_SNAKE_CASE )
							model.eval()
							a_							:			str     		=					model(_SCREAMING_SNAKE_CASE       ,     attention_mask=_SCREAMING_SNAKE_CASE       ,     token_type_ids=_SCREAMING_SNAKE_CASE       ,     labels=_SCREAMING_SNAKE_CASE )
							self.parent.assertEqual(result.logits.shape       ,     (self.batch_size, self.seq_length, self.vocab_size) )







	def       A    (			self       ,     _SCREAMING_SNAKE_CASE       ,     _SCREAMING_SNAKE_CASE       ,     _SCREAMING_SNAKE_CASE       ,     _SCREAMING_SNAKE_CASE       ,     _SCREAMING_SNAKE_CASE       ,     _SCREAMING_SNAKE_CASE       ,     _SCREAMING_SNAKE_CASE )    ->	Optional[int]:
							a_							:			Tuple     		=					YosoForQuestionAnswering(config=_SCREAMING_SNAKE_CASE )
							model.to(_SCREAMING_SNAKE_CASE )
							model.eval()
							a_							:			Optional[int]     		=					model(
							    _SCREAMING_SNAKE_CASE       ,     attention_mask=_SCREAMING_SNAKE_CASE       ,     token_type_ids=_SCREAMING_SNAKE_CASE       ,     start_positions=_SCREAMING_SNAKE_CASE       ,     end_positions=_SCREAMING_SNAKE_CASE       ,     )
							self.parent.assertEqual(result.start_logits.shape       ,     (self.batch_size, self.seq_length) )
							self.parent.assertEqual(result.end_logits.shape       ,     (self.batch_size, self.seq_length) )







	def       A    (			self       ,     _SCREAMING_SNAKE_CASE       ,     _SCREAMING_SNAKE_CASE       ,     _SCREAMING_SNAKE_CASE       ,     _SCREAMING_SNAKE_CASE       ,     _SCREAMING_SNAKE_CASE       ,     _SCREAMING_SNAKE_CASE       ,     _SCREAMING_SNAKE_CASE )    ->	int:
							a_							:			int     		=					self.num_labels
							a_							:			Optional[int]     		=					YosoForSequenceClassification(_SCREAMING_SNAKE_CASE )
							model.to(_SCREAMING_SNAKE_CASE )
							model.eval()
							a_							:			Union[str, Any]     		=					model(_SCREAMING_SNAKE_CASE       ,     attention_mask=_SCREAMING_SNAKE_CASE       ,     token_type_ids=_SCREAMING_SNAKE_CASE       ,     labels=_SCREAMING_SNAKE_CASE )
							self.parent.assertEqual(result.logits.shape       ,     (self.batch_size, self.num_labels) )







	def       A    (			self       ,     _SCREAMING_SNAKE_CASE       ,     _SCREAMING_SNAKE_CASE       ,     _SCREAMING_SNAKE_CASE       ,     _SCREAMING_SNAKE_CASE       ,     _SCREAMING_SNAKE_CASE       ,     _SCREAMING_SNAKE_CASE       ,     _SCREAMING_SNAKE_CASE )    ->	List[str]:
							a_							:			str     		=					self.num_labels
							a_							:			List[str]     		=					YosoForTokenClassification(config=_SCREAMING_SNAKE_CASE )
							model.to(_SCREAMING_SNAKE_CASE )
							model.eval()
							a_							:			Tuple     		=					model(_SCREAMING_SNAKE_CASE       ,     attention_mask=_SCREAMING_SNAKE_CASE       ,     token_type_ids=_SCREAMING_SNAKE_CASE       ,     labels=_SCREAMING_SNAKE_CASE )
							self.parent.assertEqual(result.logits.shape       ,     (self.batch_size, self.seq_length, self.num_labels) )







	def       A    (			self       ,     _SCREAMING_SNAKE_CASE       ,     _SCREAMING_SNAKE_CASE       ,     _SCREAMING_SNAKE_CASE       ,     _SCREAMING_SNAKE_CASE       ,     _SCREAMING_SNAKE_CASE       ,     _SCREAMING_SNAKE_CASE       ,     _SCREAMING_SNAKE_CASE )    ->	Union[str, Any]:
							a_							:			Optional[int]     		=					self.num_choices
							a_							:			int     		=					YosoForMultipleChoice(config=_SCREAMING_SNAKE_CASE )
							model.to(_SCREAMING_SNAKE_CASE )
							model.eval()
							a_							:			Optional[Any]     		=					input_ids.unsqueeze(1 ).expand(-1       ,     self.num_choices       ,     -1 ).contiguous()
							a_							:			Optional[Any]     		=					token_type_ids.unsqueeze(1 ).expand(-1       ,     self.num_choices       ,     -1 ).contiguous()
							a_							:			Optional[int]     		=					input_mask.unsqueeze(1 ).expand(-1       ,     self.num_choices       ,     -1 ).contiguous()
							a_							:			Optional[int]     		=					model(
							    _SCREAMING_SNAKE_CASE       ,     attention_mask=_SCREAMING_SNAKE_CASE       ,     token_type_ids=_SCREAMING_SNAKE_CASE       ,     labels=_SCREAMING_SNAKE_CASE       ,     )
							self.parent.assertEqual(result.logits.shape       ,     (self.batch_size, self.num_choices) )







	def       A    (			self )    ->	Tuple:
							a_							:			Optional[Any]     		=					self.prepare_config_and_inputs()
							(
							    (
							    a_
							)		,					(
							    a_
							)		,					(
							    a_
							)		,					(
							    a_
							)		,					(
							    a_
							)		,					(
							    a_
							)		,					(
							    a_
							)		,					
							)							:			Any     		=					config_and_inputs
							a_							:			Any     		=					{"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
							return config, inputs_dict




@require_torch
class   UpperCAmelCase__				(    __lowerCamelCase,      __lowerCamelCase,      unittest.TestCase			):


	"""simple docstring"""
	lowerCAmelCase__    :					List[str]						      =							(
	    (
	        YosoModel,
	        YosoForMaskedLM,
	        YosoForMultipleChoice,
	        YosoForQuestionAnswering,
	        YosoForSequenceClassification,
	        YosoForTokenClassification,
	    )
	    if is_torch_available()
	    else ()
	)
	lowerCAmelCase__    :					Any						      =							False
	lowerCAmelCase__    :					List[Any]						      =							False
	lowerCAmelCase__    :					Dict						      =							False

	lowerCAmelCase__    :					Optional[int]						      =							()
	lowerCAmelCase__    :					int						      =							(
	    {
	        """feature-extraction""": YosoModel,
	        """fill-mask""": YosoForMaskedLM,
	        """question-answering""": YosoForQuestionAnswering,
	        """text-classification""": YosoForSequenceClassification,
	        """token-classification""": YosoForTokenClassification,
	        """zero-shot""": YosoForSequenceClassification,
	    }
	    if is_torch_available()
	    else {}
	)







	def       A    (			self )    ->	Optional[Any]:
							a_							:			str     		=					YosoModelTester(self )
							a_							:			Any     		=					ConfigTester(self       ,     config_class=_SCREAMING_SNAKE_CASE       ,     hidden_size=3_7 )







	def       A    (			self )    ->	Optional[Any]:
							self.config_tester.run_common_tests()







	def       A    (			self )    ->	Optional[int]:
							a_							:			Dict     		=					self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*_SCREAMING_SNAKE_CASE )







	def       A    (			self )    ->	Union[str, Any]:
							a_							:			Any     		=					self.model_tester.prepare_config_and_inputs()
							for type in ["absolute", "relative_key", "relative_key_query"]:
													a_							:			Optional[Any]     		=					type
													self.model_tester.create_and_check_model(*_SCREAMING_SNAKE_CASE )







	def       A    (			self )    ->	Any:
							a_							:			str     		=					self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_masked_lm(*_SCREAMING_SNAKE_CASE )







	def       A    (			self )    ->	int:
							a_							:			str     		=					self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_multiple_choice(*_SCREAMING_SNAKE_CASE )







	def       A    (			self )    ->	Union[str, Any]:
							a_							:			Tuple     		=					self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_question_answering(*_SCREAMING_SNAKE_CASE )







	def       A    (			self )    ->	Optional[Any]:
							a_							:			int     		=					self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_sequence_classification(*_SCREAMING_SNAKE_CASE )







	def       A    (			self )    ->	Optional[Any]:
							a_							:			str     		=					self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_token_classification(*_SCREAMING_SNAKE_CASE )







	@slow
	def       A    (			self )    ->	int:
							for model_name in YOSO_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
													a_							:			Optional[int]     		=					YosoModel.from_pretrained(_SCREAMING_SNAKE_CASE )
													self.assertIsNotNone(_SCREAMING_SNAKE_CASE )







	def       A    (			self )    ->	Any:
							return




@require_torch
class   UpperCAmelCase__				(    unittest.TestCase			):


	"""simple docstring"""







	@slow
	def       A    (			self )    ->	Optional[Any]:
							a_							:			Optional[int]     		=					YosoModel.from_pretrained("uw-madison/yoso-4096" )
							a_							:			Union[str, Any]     		=					torch.tensor([[0, 1, 2, 3, 4, 5]] )

							with torch.no_grad():
													a_							:			Tuple     		=					model(_SCREAMING_SNAKE_CASE )[0]

							a_							:			int     		=					torch.Size((1, 6, 7_6_8) )
							self.assertEqual(output.shape       ,     _SCREAMING_SNAKE_CASE )

							a_							:			List[str]     		=					torch.tensor(
							    [[[-0.0_6_1_1, 0.1_2_4_2, 0.0_8_4_0], [0.0_2_8_0, -0.0_0_4_8, 0.1_1_2_5], [0.0_1_0_6, 0.0_2_2_6, 0.0_7_5_1]]] )

							self.assertTrue(torch.allclose(output[:, :3, :3]       ,     _SCREAMING_SNAKE_CASE       ,     atol=1E-4 ) )







	@slow
	def       A    (			self )    ->	Optional[int]:
							a_							:			int     		=					YosoForMaskedLM.from_pretrained("uw-madison/yoso-4096" )
							a_							:			Tuple     		=					torch.tensor([[0, 1, 2, 3, 4, 5]] )

							with torch.no_grad():
													a_							:			Any     		=					model(_SCREAMING_SNAKE_CASE )[0]

							a_							:			List[str]     		=					5_0_2_6_5

							a_							:			Union[str, Any]     		=					torch.Size((1, 6, vocab_size) )
							self.assertEqual(output.shape       ,     _SCREAMING_SNAKE_CASE )

							a_							:			Optional[Any]     		=					torch.tensor(
							    [[[-2.1_3_1_3, -3.7_2_8_5, -2.2_4_0_7], [-2.7_0_4_7, -3.3_3_1_4, -2.6_4_0_8], [0.0_6_2_9, -2.5_1_6_6, -0.3_3_5_6]]] )

							self.assertTrue(torch.allclose(output[:, :3, :3]       ,     _SCREAMING_SNAKE_CASE       ,     atol=1E-4 ) )







	@slow
	def       A    (			self )    ->	int:
							a_							:			List[str]     		=					YosoForMaskedLM.from_pretrained("uw-madison/yoso-4096" )
							a_							:			Dict     		=					torch.arange(4_0_9_6 ).unsqueeze(0 )

							with torch.no_grad():
													a_							:			Tuple     		=					model(_SCREAMING_SNAKE_CASE )[0]

							a_							:			str     		=					5_0_2_6_5

							a_							:			List[Any]     		=					torch.Size((1, 4_0_9_6, vocab_size) )
							self.assertEqual(output.shape       ,     _SCREAMING_SNAKE_CASE )

							a_							:			str     		=					torch.tensor(
							    [[[-2.3_9_1_4, -4.3_7_4_2, -5.0_9_5_6], [-4.0_9_8_8, -4.2_3_8_4, -7.0_4_0_6], [-3.1_4_2_7, -3.7_1_9_2, -6.6_8_0_0]]] )

							self.assertTrue(torch.allclose(output[:, :3, :3]       ,     _SCREAMING_SNAKE_CASE       ,     atol=1E-4 ) )




