"""simple docstring"""






import json
import os
import random
import shutil
import tempfile
import unittest

import numpy as np
import pytest

from transformers import BertTokenizer, BertTokenizerFast
from transformers.models.bert.tokenization_bert import VOCAB_FILES_NAMES
from transformers.testing_utils import require_vision
from transformers.utils import IMAGE_PROCESSOR_NAME, is_vision_available


if is_vision_available():
				from PIL import Image

				from transformers import FlavaImageProcessor, FlavaProcessor
				from transformers.models.flava.image_processing_flava import (
				    FLAVA_CODEBOOK_MEAN,
				    FLAVA_CODEBOOK_STD,
				    FLAVA_IMAGE_MEAN,
				    FLAVA_IMAGE_STD,
				)
@require_vision
class   UpperCAmelCase__				(    unittest.TestCase			):


	"""simple docstring"""







	def       A    (			self )    ->	Tuple:
							a_							:			str     		=					tempfile.mkdtemp()

							# fmt: off
							a_							:			Optional[Any]     		=					["[UNK]", "[CLS]", "[SEP]", "[PAD]", "[MASK]", "want", "##want", "##ed", "wa", "un", "runn", "##ing", ",", "low", "lowest"]
							# fmt: on
							a_							:			Any     		=					os.path.join(self.tmpdirname       ,     VOCAB_FILES_NAMES["vocab_file"] )

							with open(self.vocab_file       ,     "w"       ,     encoding="utf-8" ) as fp:
													fp.write("".join([x + "\n" for x in vocab_tokens] ) )

							a_							:			Optional[Any]     		=					{
							    "image_mean": FLAVA_IMAGE_MEAN,
							    "image_std": FLAVA_IMAGE_STD,
							    "do_normalize": True,
							    "do_resize": True,
							    "size": 2_2_4,
							    "do_center_crop": True,
							    "crop_size": 2_2_4,
							    "input_size_patches": 1_4,
							    "total_mask_patches": 7_5,
							    "mask_group_max_patches": None,
							    "mask_group_min_patches": 1_6,
							    "mask_group_min_aspect_ratio": 0.3,
							    "mask_group_max_aspect_ratio": None,
							    "codebook_do_resize": True,
							    "codebook_size": 1_1_2,
							    "codebook_do_center_crop": True,
							    "codebook_crop_size": 1_1_2,
							    "codebook_do_map_pixels": True,
							    "codebook_do_normalize": True,
							    "codebook_image_mean": FLAVA_CODEBOOK_MEAN,
							    "codebook_image_std": FLAVA_CODEBOOK_STD,
							}

							a_							:			Optional[int]     		=					os.path.join(self.tmpdirname       ,     _SCREAMING_SNAKE_CASE )
							with open(self.image_processor_file       ,     "w"       ,     encoding="utf-8" ) as fp:
													json.dump(_SCREAMING_SNAKE_CASE       ,     _SCREAMING_SNAKE_CASE )







	def       A    (			self       ,     **_SCREAMING_SNAKE_CASE )    ->	Dict:
							return BertTokenizer.from_pretrained(self.tmpdirname       ,     **_SCREAMING_SNAKE_CASE )







	def       A    (			self       ,     **_SCREAMING_SNAKE_CASE )    ->	List[Any]:
							return BertTokenizerFast.from_pretrained(self.tmpdirname       ,     **_SCREAMING_SNAKE_CASE )







	def       A    (			self       ,     **_SCREAMING_SNAKE_CASE )    ->	List[Any]:
							return FlavaImageProcessor.from_pretrained(self.tmpdirname       ,     **_SCREAMING_SNAKE_CASE )







	def       A    (			self )    ->	List[str]:
							shutil.rmtree(self.tmpdirname )







	def       A    (			self )    ->	int:
							a_							:			Optional[int]     		=					[np.random.randint(2_5_5       ,     size=(3, 3_0, 4_0_0)       ,     dtype=np.uinta )]

							a_							:			Dict     		=					[Image.fromarray(np.moveaxis(_SCREAMING_SNAKE_CASE       ,     0       ,     -1 ) ) for x in image_inputs]

							return image_inputs







	def       A    (			self )    ->	List[Any]:
							a_							:			Optional[int]     		=					self.get_tokenizer()
							a_							:			int     		=					self.get_rust_tokenizer()
							a_							:			Tuple     		=					self.get_image_processor()

							a_							:			Union[str, Any]     		=					FlavaProcessor(tokenizer=_SCREAMING_SNAKE_CASE       ,     image_processor=_SCREAMING_SNAKE_CASE )
							processor_slow.save_pretrained(self.tmpdirname )
							a_							:			Any     		=					FlavaProcessor.from_pretrained(self.tmpdirname       ,     use_fast=_SCREAMING_SNAKE_CASE )

							a_							:			Dict     		=					FlavaProcessor(tokenizer=_SCREAMING_SNAKE_CASE       ,     image_processor=_SCREAMING_SNAKE_CASE )
							processor_fast.save_pretrained(self.tmpdirname )
							a_							:			Tuple     		=					FlavaProcessor.from_pretrained(self.tmpdirname )

							self.assertEqual(processor_slow.tokenizer.get_vocab()       ,     tokenizer_slow.get_vocab() )
							self.assertEqual(processor_fast.tokenizer.get_vocab()       ,     tokenizer_fast.get_vocab() )
							self.assertEqual(tokenizer_slow.get_vocab()       ,     tokenizer_fast.get_vocab() )
							self.assertIsInstance(processor_slow.tokenizer       ,     _SCREAMING_SNAKE_CASE )
							self.assertIsInstance(processor_fast.tokenizer       ,     _SCREAMING_SNAKE_CASE )

							self.assertEqual(processor_slow.image_processor.to_json_string()       ,     image_processor.to_json_string() )
							self.assertEqual(processor_fast.image_processor.to_json_string()       ,     image_processor.to_json_string() )
							self.assertIsInstance(processor_slow.image_processor       ,     _SCREAMING_SNAKE_CASE )
							self.assertIsInstance(processor_fast.image_processor       ,     _SCREAMING_SNAKE_CASE )







	def       A    (			self )    ->	Tuple:
							a_							:			Union[str, Any]     		=					FlavaProcessor(tokenizer=self.get_tokenizer()       ,     image_processor=self.get_image_processor() )
							processor.save_pretrained(self.tmpdirname )

							a_							:			str     		=					self.get_tokenizer(bos_token="(BOS)"       ,     eos_token="(EOS)" )
							a_							:			List[str]     		=					self.get_image_processor(do_normalize=_SCREAMING_SNAKE_CASE       ,     padding_value=1.0 )

							a_							:			Tuple     		=					FlavaProcessor.from_pretrained(
							    self.tmpdirname       ,     bos_token="(BOS)"       ,     eos_token="(EOS)"       ,     do_normalize=_SCREAMING_SNAKE_CASE       ,     padding_value=1.0 )

							self.assertEqual(processor.tokenizer.get_vocab()       ,     tokenizer_add_kwargs.get_vocab() )
							self.assertIsInstance(processor.tokenizer       ,     _SCREAMING_SNAKE_CASE )

							self.assertEqual(processor.image_processor.to_json_string()       ,     image_processor_add_kwargs.to_json_string() )
							self.assertIsInstance(processor.image_processor       ,     _SCREAMING_SNAKE_CASE )







	def       A    (			self )    ->	List[str]:
							a_							:			List[Any]     		=					self.get_image_processor()
							a_							:			List[str]     		=					self.get_tokenizer()

							a_							:			Tuple     		=					FlavaProcessor(tokenizer=_SCREAMING_SNAKE_CASE       ,     image_processor=_SCREAMING_SNAKE_CASE )

							a_							:			List[str]     		=					self.prepare_image_inputs()

							a_							:			Tuple     		=					image_processor(_SCREAMING_SNAKE_CASE       ,     return_tensors="np" )
							a_							:			Tuple     		=					processor(images=_SCREAMING_SNAKE_CASE       ,     return_tensors="np" )

							for key in input_feat_extract.keys():
													self.assertAlmostEqual(input_feat_extract[key].sum()       ,     input_processor[key].sum()       ,     delta=1E-2 )

							# With rest of the args
							random.seed(1_2_3_4 )
							a_							:			Any     		=					image_processor(
							    _SCREAMING_SNAKE_CASE       ,     return_image_mask=_SCREAMING_SNAKE_CASE       ,     return_codebook_pixels=_SCREAMING_SNAKE_CASE       ,     return_tensors="np" )
							random.seed(1_2_3_4 )
							a_							:			Optional[Any]     		=					processor(
							    images=_SCREAMING_SNAKE_CASE       ,     return_image_mask=_SCREAMING_SNAKE_CASE       ,     return_codebook_pixels=_SCREAMING_SNAKE_CASE       ,     return_tensors="np" )

							for key in input_feat_extract.keys():
													self.assertAlmostEqual(input_feat_extract[key].sum()       ,     input_processor[key].sum()       ,     delta=1E-2 )







	def       A    (			self )    ->	Optional[Any]:
							a_							:			Tuple     		=					self.get_image_processor()
							a_							:			List[str]     		=					self.get_tokenizer()

							a_							:			Union[str, Any]     		=					FlavaProcessor(tokenizer=_SCREAMING_SNAKE_CASE       ,     image_processor=_SCREAMING_SNAKE_CASE )

							a_							:			Any     		=					"lower newer"

							a_							:			int     		=					processor(text=_SCREAMING_SNAKE_CASE )

							a_							:			Optional[int]     		=					tokenizer(_SCREAMING_SNAKE_CASE )

							for key in encoded_tok.keys():
													self.assertListEqual(encoded_tok[key]       ,     encoded_processor[key] )







	def       A    (			self )    ->	List[Any]:
							a_							:			Union[str, Any]     		=					self.get_image_processor()
							a_							:			Tuple     		=					self.get_tokenizer()

							a_							:			List[str]     		=					FlavaProcessor(tokenizer=_SCREAMING_SNAKE_CASE       ,     image_processor=_SCREAMING_SNAKE_CASE )

							a_							:			Dict     		=					"lower newer"
							a_							:			Union[str, Any]     		=					self.prepare_image_inputs()

							a_							:			Union[str, Any]     		=					processor(text=_SCREAMING_SNAKE_CASE       ,     images=_SCREAMING_SNAKE_CASE )

							self.assertListEqual(list(inputs.keys() )       ,     ["input_ids", "token_type_ids", "attention_mask", "pixel_values"] )

							# add extra args
							a_							:			Dict     		=					processor(text=_SCREAMING_SNAKE_CASE       ,     images=_SCREAMING_SNAKE_CASE       ,     return_codebook_pixels=_SCREAMING_SNAKE_CASE       ,     return_image_mask=_SCREAMING_SNAKE_CASE )

							self.assertListEqual(
							    list(inputs.keys() )       ,     [
							        "input_ids",
							        "token_type_ids",
							        "attention_mask",
							        "pixel_values",
							        "codebook_pixel_values",
							        "bool_masked_pos",
							    ]       ,     )

							# test if it raises when no input is passed
							with pytest.raises(_SCREAMING_SNAKE_CASE ):
													processor()







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

							a_							:			List[str]     		=					FlavaProcessor(tokenizer=_SCREAMING_SNAKE_CASE       ,     image_processor=_SCREAMING_SNAKE_CASE )

							a_							:			int     		=					[[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

							a_							:			List[Any]     		=					processor.batch_decode(_SCREAMING_SNAKE_CASE )
							a_							:			Union[str, Any]     		=					tokenizer.batch_decode(_SCREAMING_SNAKE_CASE )

							self.assertListEqual(_SCREAMING_SNAKE_CASE       ,     _SCREAMING_SNAKE_CASE )







	def       A    (			self )    ->	str:
							a_							:			Dict     		=					self.get_image_processor()
							a_							:			Optional[int]     		=					self.get_tokenizer()

							a_							:			int     		=					FlavaProcessor(tokenizer=_SCREAMING_SNAKE_CASE       ,     image_processor=_SCREAMING_SNAKE_CASE )

							a_							:			Dict     		=					"lower newer"
							a_							:			List[Any]     		=					self.prepare_image_inputs()

							a_							:			int     		=					processor(text=_SCREAMING_SNAKE_CASE       ,     images=_SCREAMING_SNAKE_CASE )

							self.assertListEqual(list(inputs.keys() )       ,     processor.model_input_names )





"""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 ) )




