
from __future__ import annotations

import unittest
import warnings

from transformers import AutoTokenizer, MarianConfig, MarianTokenizer, TranslationPipeline, is_tf_available
from transformers.testing_utils import require_sentencepiece, require_tf, require_tokenizers, slow
from transformers.utils import cached_property

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
					import tensorflow as tf

					from transformers import TFAutoModelForSeqaSeqLM, TFMarianModel, TFMarianMTModel

@require_tf
class 	_SCREAMING_SNAKE_CASE							:
				lowerCamelCase_       =     MarianConfig
				lowerCamelCase_       =     {}
				lowerCamelCase_       =     'gelu'





				def __init__(		self :		Optional[Any]					,      snake_case_ :		Tuple					,      snake_case_ :		List[Any]=13					,      snake_case_ :		int=7					,      snake_case_ :		Tuple=True					,      snake_case_ :		List[str]=False					,      snake_case_ :		Tuple=99					,      snake_case_ :		int=32					,      snake_case_ :		Union[str, Any]=2					,      snake_case_ :		Optional[int]=4					,      snake_case_ :		Dict=37					,      snake_case_ :		Optional[int]=0.1					,      snake_case_ :		Dict=0.1					,      snake_case_ :		Optional[int]=20					,      snake_case_ :		List[str]=2					,      snake_case_ :		Dict=1					,      snake_case_ :		int=0					,      ):


								"""simple docstring"""

								A     :  int   =				parent
								A     :  int   =				batch_size
								A     :  str   =				seq_length
								A     :  Tuple   =				is_training
								A     :  List[Any]   =				use_labels
								A     :  Tuple   =				vocab_size
								A     :  int   =				hidden_size
								A     :  List[str]   =				num_hidden_layers
								A     :  Tuple   =				num_attention_heads
								A     :  Any   =				intermediate_size

								A     :  List[str]   =				hidden_dropout_prob
								A     :  Optional[int]   =				attention_probs_dropout_prob
								A     :  int   =				max_position_embeddings
								A     :  List[str]   =				eos_token_id
								A     :  Optional[int]   =				pad_token_id
								A     :  Any   =				bos_token_id





				def        _UpperCAmelCase						(		self :		Dict							):


								"""simple docstring"""

								A     :  Optional[int]   =				ids_tensor([self.batch_size, self.seq_length - 1]					,      self.vocab_size							)
								A     :  List[Any]   =				tf.expand_dims(tf.constant([self.eos_token_id] * self.batch_size							)					,      1							)
								A     :  Any   =				tf.concat([input_ids, eos_tensor]					,      axis=1							)

								A     :  Dict   =				ids_tensor([self.batch_size, self.seq_length]					,      self.vocab_size							)

								A     :  List[Any]   =				self.config_cls(
								    vocab_size=self.vocab_size					,      d_model=self.hidden_size					,      encoder_layers=self.num_hidden_layers					,      decoder_layers=self.num_hidden_layers					,      encoder_attention_heads=self.num_attention_heads					,      decoder_attention_heads=self.num_attention_heads					,      encoder_ffn_dim=self.intermediate_size					,      decoder_ffn_dim=self.intermediate_size					,      dropout=self.hidden_dropout_prob					,      attention_dropout=self.attention_probs_dropout_prob					,      max_position_embeddings=self.max_position_embeddings					,      eos_token_ids=[2]					,      bos_token_id=self.bos_token_id					,      pad_token_id=self.pad_token_id					,      decoder_start_token_id=self.pad_token_id					,      **self.config_updates					,      )
								A     :  Optional[Any]   =				prepare_marian_inputs_dict(snake_case_					,      snake_case_					,      snake_case_							)
								return config, inputs_dict






				def        _UpperCAmelCase						(		self :		List[Any]					,      snake_case_ :		List[Any]					,      snake_case_ :		Dict							):


								"""simple docstring"""

								A     :  Optional[Any]   =				TFMarianModel(config=snake_case_							).get_decoder()
								A     :  Any   =				inputs_dict['input_ids']

								A     :  Tuple   =				input_ids[:1, :]
								A     :  Any   =				inputs_dict['attention_mask'][:1, :]
								A     :  Optional[Any]   =				inputs_dict['head_mask']
								A     :  List[Any]   =				1

								# first forward pass
								A     :  Optional[int]   =				model(snake_case_					,      attention_mask=snake_case_					,      head_mask=snake_case_					,      use_cache=snake_case_							)

								A     :  int   =				outputs.to_tuple()

								# create hypothetical next token and extent to next_input_ids
								A     :  List[Any]   =				ids_tensor((self.batch_size, 3)					,      config.vocab_size							)
								A     :  Any   =				tf.cast(ids_tensor((self.batch_size, 3)					,      2							)					,      tf.inta							)

								# append to next input_ids and
								A     :  str   =				tf.concat([input_ids, next_tokens]					,      axis=-1							)
								A     :  Union[str, Any]   =				tf.concat([attention_mask, next_attn_mask]					,      axis=-1							)

								A     :  Optional[Any]   =				model(snake_case_					,      attention_mask=snake_case_							)[0]
								A     :  Union[str, Any]   =				model(snake_case_					,      attention_mask=snake_case_					,      past_key_values=snake_case_							)[0]

								self.parent.assertEqual(next_tokens.shape[1]					,      output_from_past.shape[1]							)

								# select random slice
								A     :  List[str]   =				int(ids_tensor((1,)					,      output_from_past.shape[-1]							)							)
								A     :  Any   =				output_from_no_past[:, -3:, random_slice_idx]
								A     :  Any   =				output_from_past[:, :, random_slice_idx]

								# test that outputs are equal for slice
								tf.debugging.assert_near(snake_case_					,      snake_case_					,      rtol=1E-3							)





def 							_lowerCamelCase			(					lowerCamelCase_:  List[Any]				,	lowerCamelCase_:  Any				,	lowerCamelCase_:  str				,	lowerCamelCase_:  Tuple=None				,	lowerCamelCase_:  List[Any]=None				,	lowerCamelCase_:  Dict=None				,	lowerCamelCase_:  str=None				,	lowerCamelCase_:  str=None				,	):



				'''simple docstring'''







				if attention_mask is None:
								A     :  Any   =				tf.cast(tf.math.not_equal(lowerCAmelCase__				,	config.pad_token_id		)				,	tf.inta		)
				if decoder_attention_mask is None:
								A     :  Union[str, Any]   =				tf.concat(
								    [
								        tf.ones(decoder_input_ids[:, :1].shape				,	dtype=tf.inta		),
								        tf.cast(tf.math.not_equal(decoder_input_ids[:, 1:]				,	config.pad_token_id		)				,	tf.inta		),
								    ]				,	axis=-1				,	)
				if head_mask is None:
								A     :  Optional[int]   =				tf.ones((config.encoder_layers, config.encoder_attention_heads)		)
				if decoder_head_mask is None:
								A     :  List[Any]   =				tf.ones((config.decoder_layers, config.decoder_attention_heads)		)
				if cross_attn_head_mask is None:
								A     :  List[str]   =				tf.ones((config.decoder_layers, config.decoder_attention_heads)		)
				return {
				    "input_ids": input_ids,
				    "decoder_input_ids": decoder_input_ids,
				    "attention_mask": attention_mask,
				    "decoder_attention_mask": decoder_attention_mask,
				    "head_mask": head_mask,
				    "decoder_head_mask": decoder_head_mask,
				    "cross_attn_head_mask": cross_attn_head_mask,
				}

@require_tf
class 	_SCREAMING_SNAKE_CASE							(		snake_case__,    snake_case__,    unittest.TestCase							):
				lowerCamelCase_       =     (TFMarianMTModel, TFMarianModel) if is_tf_available() else ()
				lowerCamelCase_       =     (TFMarianMTModel,) if is_tf_available() else ()
				lowerCamelCase_       =     (
				    {
				        'conversational': TFMarianMTModel,
				        'feature-extraction': TFMarianModel,
				        'summarization': TFMarianMTModel,
				        'text2text-generation': TFMarianMTModel,
				        'translation': TFMarianMTModel,
				    }
				    if is_tf_available()
				    else {}
				)
				lowerCamelCase_       =     True
				lowerCamelCase_       =     False
				lowerCamelCase_       =     False





				def        _UpperCAmelCase						(		self :		Optional[Any]							):


								"""simple docstring"""

								A     :  str   =				TFMarianModelTester(self							)
								A     :  Tuple   =				ConfigTester(self					,      config_class=snake_case_							)





				def        _UpperCAmelCase						(		self :		Tuple							):


								"""simple docstring"""

								self.config_tester.run_common_tests()






				def        _UpperCAmelCase						(		self :		Any							):


								"""simple docstring"""

								A     :  int   =				self.model_tester.prepare_config_and_inputs_for_common()
								self.model_tester.check_decoder_model_past_large_inputs(*snake_case_							)



@require_tf
class 	_SCREAMING_SNAKE_CASE							(		unittest.TestCase							):
				lowerCamelCase_       =     1_0_0_0  # show more chars for failing integration tests





				@classmethod
				def        _UpperCAmelCase						(		cls :		Dict							):


								"""simple docstring"""

								A     :  Optional[Any]   =				f"""Helsinki-NLP/opus-mt-{cls.src}-{cls.tgt}"""
								return cls





				@cached_property
				def        _UpperCAmelCase						(		self :		Union[str, Any]							):


								"""simple docstring"""

								return AutoTokenizer.from_pretrained(self.model_name							)





				@property
				def        _UpperCAmelCase						(		self :		Optional[Any]							):


								"""simple docstring"""

								return self.tokenizer.eos_token_id





				@cached_property
				def        _UpperCAmelCase						(		self :		Any							):


								"""simple docstring"""

								warnings.simplefilter('''error'''							)
								A     :  TFMarianMTModel   =				TFAutoModelForSeqaSeqLM.from_pretrained(self.model_name							)
								assert isinstance(snake_case_					,      snake_case_							)
								A     :  List[Any]   =				model.config
								self.assertListEqual(c.bad_words_ids					,      [[c.pad_token_id]]							)
								self.assertEqual(c.max_length					,      512							)
								self.assertEqual(c.decoder_start_token_id					,      c.pad_token_id							)
								return model





				def        _UpperCAmelCase						(		self :		int					,      **snake_case_ :		int							):


								"""simple docstring"""

								A     :  List[str]   =				self.translate_src_text(**snake_case_							)
								self.assertListEqual(self.expected_text					,      snake_case_							)






				def        _UpperCAmelCase						(		self :		Optional[int]					,      **snake_case_ :		int							):


								"""simple docstring"""

								A     :  str   =				self.tokenizer(self.src_text					,      **snake_case_					,      padding=snake_case_					,      return_tensors='''tf'''							)
								A     :  Dict   =				self.model.generate(
								    model_inputs.input_ids					,      attention_mask=model_inputs.attention_mask					,      num_beams=2					,      max_length=128							)
								A     :  Dict   =				self.tokenizer.batch_decode(generated_ids.numpy()					,      skip_special_tokens=snake_case_							)
								return generated_words



@require_sentencepiece
@require_tokenizers
@require_tf
class 	_SCREAMING_SNAKE_CASE							(		snake_case__							):
				lowerCamelCase_       =     'mt'
				lowerCamelCase_       =     'en'
				lowerCamelCase_       =     ['Billi messu b\'mod ġentili, Ġesù fejjaq raġel li kien milqut bil - marda kerha tal - ġdiem.']
				lowerCamelCase_       =     ['Touching gently, Jesus healed a man who was affected by the sad disease of leprosy.']





				@unittest.skip('''Skipping until #12647 is resolved.'''							)
				@slow
				def        _UpperCAmelCase						(		self :		Optional[Any]							):


								"""simple docstring"""

								self._assert_generated_batch_equal_expected()



@require_sentencepiece
@require_tokenizers
@require_tf
class 	_SCREAMING_SNAKE_CASE							(		snake_case__							):
				lowerCamelCase_       =     'en'
				lowerCamelCase_       =     'zh'
				lowerCamelCase_       =     ['My name is Wolfgang and I live in Berlin']
				lowerCamelCase_       =     ['我叫沃尔夫冈 我住在柏林']





				@unittest.skip('''Skipping until #12647 is resolved.'''							)
				@slow
				def        _UpperCAmelCase						(		self :		Tuple							):


								"""simple docstring"""

								self._assert_generated_batch_equal_expected()



@require_sentencepiece
@require_tokenizers
@require_tf
class 	_SCREAMING_SNAKE_CASE							(		snake_case__							):
				lowerCamelCase_       =     'en'
				lowerCamelCase_       =     'ROMANCE'
				lowerCamelCase_       =     [
				    '>>fr<< Don\'t spend so much time watching TV.',
				    '>>pt<< Your message has been sent.',
				    '>>es<< He\'s two years older than me.',
				]
				lowerCamelCase_       =     [
				    'Ne passez pas autant de temps à regarder la télé.',
				    'A sua mensagem foi enviada.',
				    'Es dos años más viejo que yo.',
				]





				@unittest.skip('''Skipping until #12647 is resolved.'''							)
				@slow
				def        _UpperCAmelCase						(		self :		List[Any]							):


								"""simple docstring"""

								self._assert_generated_batch_equal_expected()






				@unittest.skip('''Skipping until #12647 is resolved.'''							)
				@slow
				def        _UpperCAmelCase						(		self :		Any							):


								"""simple docstring"""

								A     :  Union[str, Any]   =				TranslationPipeline(self.model					,      self.tokenizer					,      framework='''tf'''							)
								A     :  List[Any]   =				pipeline(self.src_text							)
								self.assertEqual(self.expected_text					,      [x['''translation_text'''] for x in output]							)

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





				def __init__(		self :		Dict					,      snake_case_ :		Tuple					,      snake_case_ :		Union[str, Any]=13					,      snake_case_ :		int=7					,      snake_case_ :		int=True					,      snake_case_ :		int=True					,      snake_case_ :		Optional[Any]=True					,      snake_case_ :		Optional[int]=True					,      snake_case_ :		Tuple=99					,      snake_case_ :		List[str]=32					,      snake_case_ :		Any=5					,      snake_case_ :		Union[str, Any]=4					,      snake_case_ :		List[Any]=37					,      snake_case_ :		str="gelu"					,      snake_case_ :		int=0.1					,      snake_case_ :		Optional[Any]=0.1					,      snake_case_ :		Union[str, Any]=512					,      snake_case_ :		Optional[int]=16					,      snake_case_ :		Any=2					,      snake_case_ :		Union[str, Any]=0.02					,      snake_case_ :		List[str]=3					,      snake_case_ :		List[str]=4					,      snake_case_ :		Optional[int]=None					,      ):


								"""simple docstring"""

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





				def        _UpperCAmelCase						(		self :		Any							):


								"""simple docstring"""

								A     :  str   =				ids_tensor([self.batch_size, self.seq_length]					,      self.vocab_size							)

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

								A     :  int   =				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     :  Any   =				None
								A     :  Union[str, Any]   =				None
								if self.use_labels:
												A     :  Optional[int]   =				ids_tensor([self.batch_size]					,      self.type_sequence_label_size							)
												A     :  Union[str, Any]   =				ids_tensor([self.batch_size, self.seq_length]					,      self.num_labels							)
												A     :  Optional[Any]   =				ids_tensor([self.batch_size]					,      self.num_choices							)

								A     :  Dict   =				self.get_config()

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





				def        _UpperCAmelCase						(		self :		Dict							):


								"""simple docstring"""

								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=snake_case_					,      initializer_range=self.initializer_range					,      )





				def        _UpperCAmelCase						(		self :		Optional[int]							):


								"""simple docstring"""

								A     :  List[Any]   =				self.get_config()
								A     :  Tuple   =				300
								return config





				def        _UpperCAmelCase						(		self :		List[Any]							):


								"""simple docstring"""

								(
								    (
								    A
								) ,       (
								    A
								) ,       (
								    A
								) ,       (
								    A
								) ,       (
								    A
								) ,       (
								    A
								) ,       (
								    A
								) ,       
								)     :  List[Any]   =				self.prepare_config_and_inputs()

								A     :  Tuple   =				True
								A     :  Tuple   =				floats_tensor([self.batch_size, self.seq_length, self.hidden_size]							)
								A     :  Union[str, Any]   =				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        _UpperCAmelCase						(		self :		Dict					,      snake_case_ :		int					,      snake_case_ :		Optional[Any]					,      snake_case_ :		Union[str, Any]					,      snake_case_ :		Union[str, Any]					,      snake_case_ :		List[str]					,      snake_case_ :		Tuple					,      snake_case_ :		List[str]							):


								"""simple docstring"""

								A     :  Optional[Any]   =				YosoModel(config=snake_case_							)
								model.to(snake_case_							)
								model.eval()
								A     :  List[str]   =				model(snake_case_					,      attention_mask=snake_case_					,      token_type_ids=snake_case_							)
								A     :  int   =				model(snake_case_					,      token_type_ids=snake_case_							)
								A     :  int   =				model(snake_case_							)
								self.parent.assertEqual(result.last_hidden_state.shape					,      (self.batch_size, self.seq_length, self.hidden_size)							)





				def        _UpperCAmelCase						(		self :		List[str]					,      snake_case_ :		int					,      snake_case_ :		Tuple					,      snake_case_ :		List[str]					,      snake_case_ :		str					,      snake_case_ :		int					,      snake_case_ :		List[str]					,      snake_case_ :		Union[str, Any]					,      snake_case_ :		Optional[int]					,      snake_case_ :		int					,      ):


								"""simple docstring"""

								A     :  List[str]   =				True
								A     :  Tuple   =				YosoModel(snake_case_							)
								model.to(snake_case_							)
								model.eval()
								A     :  str   =				model(
								    snake_case_					,      attention_mask=snake_case_					,      token_type_ids=snake_case_					,      encoder_hidden_states=snake_case_					,      encoder_attention_mask=snake_case_					,      )
								A     :  Any   =				model(
								    snake_case_					,      attention_mask=snake_case_					,      token_type_ids=snake_case_					,      encoder_hidden_states=snake_case_					,      )
								A     :  List[Any]   =				model(snake_case_					,      attention_mask=snake_case_					,      token_type_ids=snake_case_							)
								self.parent.assertEqual(result.last_hidden_state.shape					,      (self.batch_size, self.seq_length, self.hidden_size)							)





				def        _UpperCAmelCase						(		self :		Tuple					,      snake_case_ :		Union[str, Any]					,      snake_case_ :		List[str]					,      snake_case_ :		Any					,      snake_case_ :		Union[str, Any]					,      snake_case_ :		int					,      snake_case_ :		Tuple					,      snake_case_ :		str							):


								"""simple docstring"""

								A     :  List[Any]   =				YosoForMaskedLM(config=snake_case_							)
								model.to(snake_case_							)
								model.eval()
								A     :  List[Any]   =				model(snake_case_					,      attention_mask=snake_case_					,      token_type_ids=snake_case_					,      labels=snake_case_							)
								self.parent.assertEqual(result.logits.shape					,      (self.batch_size, self.seq_length, self.vocab_size)							)





				def        _UpperCAmelCase						(		self :		Union[str, Any]					,      snake_case_ :		Tuple					,      snake_case_ :		str					,      snake_case_ :		Dict					,      snake_case_ :		Any					,      snake_case_ :		Optional[int]					,      snake_case_ :		int					,      snake_case_ :		Tuple							):


								"""simple docstring"""

								A     :  Optional[int]   =				YosoForQuestionAnswering(config=snake_case_							)
								model.to(snake_case_							)
								model.eval()
								A     :  int   =				model(
								    snake_case_					,      attention_mask=snake_case_					,      token_type_ids=snake_case_					,      start_positions=snake_case_					,      end_positions=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        _UpperCAmelCase						(		self :		Tuple					,      snake_case_ :		Any					,      snake_case_ :		List[Any]					,      snake_case_ :		List[Any]					,      snake_case_ :		Optional[Any]					,      snake_case_ :		List[Any]					,      snake_case_ :		Optional[Any]					,      snake_case_ :		str							):


								"""simple docstring"""

								A     :  List[str]   =				self.num_labels
								A     :  int   =				YosoForSequenceClassification(snake_case_							)
								model.to(snake_case_							)
								model.eval()
								A     :  Optional[int]   =				model(snake_case_					,      attention_mask=snake_case_					,      token_type_ids=snake_case_					,      labels=snake_case_							)
								self.parent.assertEqual(result.logits.shape					,      (self.batch_size, self.num_labels)							)





				def        _UpperCAmelCase						(		self :		Any					,      snake_case_ :		Any					,      snake_case_ :		Any					,      snake_case_ :		Union[str, Any]					,      snake_case_ :		Tuple					,      snake_case_ :		Union[str, Any]					,      snake_case_ :		Tuple					,      snake_case_ :		int							):


								"""simple docstring"""

								A     :  List[str]   =				self.num_labels
								A     :  Optional[Any]   =				YosoForTokenClassification(config=snake_case_							)
								model.to(snake_case_							)
								model.eval()
								A     :  Dict   =				model(snake_case_					,      attention_mask=snake_case_					,      token_type_ids=snake_case_					,      labels=snake_case_							)
								self.parent.assertEqual(result.logits.shape					,      (self.batch_size, self.seq_length, self.num_labels)							)





				def        _UpperCAmelCase						(		self :		int					,      snake_case_ :		List[str]					,      snake_case_ :		List[Any]					,      snake_case_ :		str					,      snake_case_ :		Tuple					,      snake_case_ :		Any					,      snake_case_ :		Optional[int]					,      snake_case_ :		str							):


								"""simple docstring"""

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






				def        _UpperCAmelCase						(		self :		Tuple							):


								"""simple docstring"""

								A     :  Tuple   =				self.prepare_config_and_inputs()
								(
								    (
								    A
								) ,       (
								    A
								) ,       (
								    A
								) ,       (
								    A
								) ,       (
								    A
								) ,       (
								    A
								) ,       (
								    A
								) ,       
								)     :  Dict   =				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     _SCREAMING_SNAKE_CASE							(		snake_case,    snake_case,    unittest.TestCase							):
				lowerCamelCase_       =     (
				    (
				        YosoModel,
				        YosoForMaskedLM,
				        YosoForMultipleChoice,
				        YosoForQuestionAnswering,
				        YosoForSequenceClassification,
				        YosoForTokenClassification,
				    )
				    if is_torch_available()
				    else ()
				)
				lowerCamelCase_       =     False
				lowerCamelCase_       =     False
				lowerCamelCase_       =     False

				lowerCamelCase_       =     ()
				lowerCamelCase_       =     (
				    {
				        'feature-extraction': YosoModel,
				        'fill-mask': YosoForMaskedLM,
				        'question-answering': YosoForQuestionAnswering,
				        'text-classification': YosoForSequenceClassification,
				        'token-classification': YosoForTokenClassification,
				        'zero-shot': YosoForSequenceClassification,
				    }
				    if is_torch_available()
				    else {}
				)





				def        _UpperCAmelCase						(		self :		Optional[int]							):


								"""simple docstring"""

								A     :  Optional[Any]   =				YosoModelTester(self							)
								A     :  Dict   =				ConfigTester(self					,      config_class=snake_case_					,      hidden_size=37							)





				def        _UpperCAmelCase						(		self :		Optional[Any]							):


								"""simple docstring"""

								self.config_tester.run_common_tests()





				def        _UpperCAmelCase						(		self :		int							):


								"""simple docstring"""

								A     :  Union[str, Any]   =				self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_model(*snake_case_							)





				def        _UpperCAmelCase						(		self :		int							):


								"""simple docstring"""

								A     :  Optional[Any]   =				self.model_tester.prepare_config_and_inputs()
								for type in ["absolute", "relative_key", "relative_key_query"]:
												A     :  Dict   =				type
												self.model_tester.create_and_check_model(*snake_case_							)





				def        _UpperCAmelCase						(		self :		str							):


								"""simple docstring"""

								A     :  Tuple   =				self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_masked_lm(*snake_case_							)





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


								"""simple docstring"""

								A     :  Any   =				self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_multiple_choice(*snake_case_							)





				def        _UpperCAmelCase						(		self :		Optional[Any]							):


								"""simple docstring"""

								A     :  List[str]   =				self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_question_answering(*snake_case_							)





				def        _UpperCAmelCase						(		self :		Dict							):


								"""simple docstring"""

								A     :  Dict   =				self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_sequence_classification(*snake_case_							)





				def        _UpperCAmelCase						(		self :		List[str]							):


								"""simple docstring"""

								A     :  Dict   =				self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_token_classification(*snake_case_							)





				@slow
				def        _UpperCAmelCase						(		self :		Tuple							):


								"""simple docstring"""

								for model_name in YOSO_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
												A     :  Dict   =				YosoModel.from_pretrained(snake_case_							)
												self.assertIsNotNone(snake_case_							)






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


								"""simple docstring"""

								return



@require_torch
class     _SCREAMING_SNAKE_CASE							(		unittest.TestCase							):





				@slow
				def        _UpperCAmelCase						(		self :		List[Any]							):


								"""simple docstring"""

								A     :  Optional[int]   =				YosoModel.from_pretrained('''uw-madison/yoso-4096'''							)
								A     :  Any   =				torch.tensor([[0, 1, 2, 3, 4, 5]]							)

								with torch.no_grad():
												A     :  str   =				model(snake_case_							)[0]

								A     :  Union[str, Any]   =				torch.Size((1, 6, 768)							)
								self.assertEqual(output.shape					,      snake_case_							)

								A     :  int   =				torch.tensor(
								    [[[-0.06_11, 0.12_42, 0.08_40], [0.02_80, -0.00_48, 0.11_25], [0.01_06, 0.02_26, 0.07_51]]]							)

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





				@slow
				def        _UpperCAmelCase						(		self :		int							):


								"""simple docstring"""

								A     :  Tuple   =				YosoForMaskedLM.from_pretrained('''uw-madison/yoso-4096'''							)
								A     :  Dict   =				torch.tensor([[0, 1, 2, 3, 4, 5]]							)

								with torch.no_grad():
												A     :  str   =				model(snake_case_							)[0]

								A     :  Optional[Any]   =				5_0265

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

								A     :  str   =				torch.tensor(
								    [[[-2.13_13, -3.72_85, -2.24_07], [-2.70_47, -3.33_14, -2.64_08], [0.06_29, -2.51_66, -0.33_56]]]							)

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






				@slow
				def        _UpperCAmelCase						(		self :		Dict							):


								"""simple docstring"""

								A     :  str   =				YosoForMaskedLM.from_pretrained('''uw-madison/yoso-4096'''							)
								A     :  Tuple   =				torch.arange(4096							).unsqueeze(0							)

								with torch.no_grad():
												A     :  Optional[Any]   =				model(snake_case_							)[0]

								A     :  Optional[int]   =				5_0265

								A     :  Tuple   =				torch.Size((1, 4096, vocab_size)							)
								self.assertEqual(output.shape					,      snake_case_							)

								A     :  Optional[Any]   =				torch.tensor(
								    [[[-2.39_14, -4.37_42, -5.09_56], [-4.09_88, -4.23_84, -7.04_06], [-3.14_27, -3.71_92, -6.68_00]]]							)

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