
"""simple docstring"""







import unittest

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

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
							import torch

							from transformers import (
							    XLMForMultipleChoice,
							    XLMForQuestionAnswering,
							    XLMForQuestionAnsweringSimple,
							    XLMForSequenceClassification,
							    XLMForTokenClassification,
							    XLMModel,
							    XLMWithLMHeadModel,
							)
							from transformers.models.xlm.modeling_xlm import XLM_PRETRAINED_MODEL_ARCHIVE_LIST




class 				A__ :

		def __init__(   self ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE=13 ,	_SCREAMING_SNAKE_CASE=7 ,	_SCREAMING_SNAKE_CASE=True ,	_SCREAMING_SNAKE_CASE=True ,	_SCREAMING_SNAKE_CASE=True ,	_SCREAMING_SNAKE_CASE=True ,	_SCREAMING_SNAKE_CASE=True ,	_SCREAMING_SNAKE_CASE=False ,	_SCREAMING_SNAKE_CASE=False ,	_SCREAMING_SNAKE_CASE=False ,	_SCREAMING_SNAKE_CASE=2 ,	_SCREAMING_SNAKE_CASE=99 ,	_SCREAMING_SNAKE_CASE=0 ,	_SCREAMING_SNAKE_CASE=32 ,	_SCREAMING_SNAKE_CASE=5 ,	_SCREAMING_SNAKE_CASE=4 ,	_SCREAMING_SNAKE_CASE=0.1 ,	_SCREAMING_SNAKE_CASE=0.1 ,	_SCREAMING_SNAKE_CASE=5_12 ,	_SCREAMING_SNAKE_CASE=2 ,	_SCREAMING_SNAKE_CASE=0.02 ,	_SCREAMING_SNAKE_CASE=2 ,	_SCREAMING_SNAKE_CASE=4 ,	_SCREAMING_SNAKE_CASE="last" ,	_SCREAMING_SNAKE_CASE=True ,	_SCREAMING_SNAKE_CASE=None ,	_SCREAMING_SNAKE_CASE=0 ,	):
			__lowerCAmelCase    :		Optional[Any]		    =   parent
			__lowerCAmelCase    :		Dict		    =   batch_size
			__lowerCAmelCase    :		Optional[int]		    =   seq_length
			__lowerCAmelCase    :		int		    =   is_training
			__lowerCAmelCase    :		List[str]		    =   use_input_lengths
			__lowerCAmelCase    :		Union[str, Any]		    =   use_token_type_ids
			__lowerCAmelCase    :		Union[str, Any]		    =   use_labels
			__lowerCAmelCase    :		Dict		    =   gelu_activation
			__lowerCAmelCase    :		Union[str, Any]		    =   sinusoidal_embeddings
			__lowerCAmelCase    :		Union[str, Any]		    =   causal
			__lowerCAmelCase    :		Union[str, Any]		    =   asm
			__lowerCAmelCase    :		Dict		    =   n_langs
			__lowerCAmelCase    :		Optional[Any]		    =   vocab_size
			__lowerCAmelCase    :		Union[str, Any]		    =   n_special
			__lowerCAmelCase    :		Tuple		    =   hidden_size
			__lowerCAmelCase    :		Any		    =   num_hidden_layers
			__lowerCAmelCase    :		List[Any]		    =   num_attention_heads
			__lowerCAmelCase    :		Optional[Any]		    =   hidden_dropout_prob
			__lowerCAmelCase    :		Any		    =   attention_probs_dropout_prob
			__lowerCAmelCase    :		Optional[Any]		    =   max_position_embeddings
			__lowerCAmelCase    :		Any		    =   type_sequence_label_size
			__lowerCAmelCase    :		Optional[Any]		    =   initializer_range
			__lowerCAmelCase    :		int		    =   num_labels
			__lowerCAmelCase    :		Any		    =   num_choices
			__lowerCAmelCase    :		List[Any]		    =   summary_type
			__lowerCAmelCase    :		str		    =   use_proj
			__lowerCAmelCase    :		Union[str, Any]		    =   scope
			__lowerCAmelCase    :		str		    =   bos_token_id

		def 							__lowerCamelCase							(   self				):
			__lowerCAmelCase    :		str		    =   ids_tensor([self.batch_size, self.seq_length] ,	self.vocab_size				)
			__lowerCAmelCase    :		Optional[Any]		    =   random_attention_mask([self.batch_size, self.seq_length]				)

			__lowerCAmelCase    :		Dict		    =   None
			if self.use_input_lengths:
				__lowerCAmelCase    :		Tuple		    =   (
				    ids_tensor([self.batch_size] ,	vocab_size=2				) + self.seq_length - 2
				)  # small variation of seq_length

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

			__lowerCAmelCase    :		Union[str, Any]		    =   None
			__lowerCAmelCase    :		Optional[Any]		    =   None
			__lowerCAmelCase    :		Optional[int]		    =   None
			if self.use_labels:
				__lowerCAmelCase    :		Tuple		    =   ids_tensor([self.batch_size] ,	self.type_sequence_label_size				)
				__lowerCAmelCase    :		Optional[int]		    =   ids_tensor([self.batch_size, self.seq_length] ,	self.num_labels				)
				__lowerCAmelCase    :		List[str]		    =   ids_tensor([self.batch_size] ,	2				).float()
				__lowerCAmelCase    :		Tuple		    =   ids_tensor([self.batch_size] ,	self.num_choices				)

			__lowerCAmelCase    :		List[str]		    =   self.get_config()

			return (
			    config,
			    input_ids,
			    token_type_ids,
			    input_lengths,
			    sequence_labels,
			    token_labels,
			    is_impossible_labels,
			    choice_labels,
			    input_mask,
			)

		def 							__lowerCamelCase							(   self				):
			return XLMConfig(
			    vocab_size=self.vocab_size ,	n_special=self.n_special ,	emb_dim=self.hidden_size ,	n_layers=self.num_hidden_layers ,	n_heads=self.num_attention_heads ,	dropout=self.hidden_dropout_prob ,	attention_dropout=self.attention_probs_dropout_prob ,	gelu_activation=self.gelu_activation ,	sinusoidal_embeddings=self.sinusoidal_embeddings ,	asm=self.asm ,	causal=self.causal ,	n_langs=self.n_langs ,	max_position_embeddings=self.max_position_embeddings ,	initializer_range=self.initializer_range ,	summary_type=self.summary_type ,	use_proj=self.use_proj ,	num_labels=self.num_labels ,	bos_token_id=self.bos_token_id ,	)

		def 							__lowerCamelCase							(   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 ,	):
			__lowerCAmelCase    :		List[str]		    =   XLMModel(config=_SCREAMING_SNAKE_CASE				)
			model.to(_SCREAMING_SNAKE_CASE				)
			model.eval()
			__lowerCAmelCase    :		Union[str, Any]		    =   model(_SCREAMING_SNAKE_CASE ,	lengths=_SCREAMING_SNAKE_CASE ,	langs=_SCREAMING_SNAKE_CASE				)
			__lowerCAmelCase    :		Optional[Any]		    =   model(_SCREAMING_SNAKE_CASE ,	langs=_SCREAMING_SNAKE_CASE				)
			__lowerCAmelCase    :		List[str]		    =   model(_SCREAMING_SNAKE_CASE				)
			self.parent.assertEqual(result.last_hidden_state.shape ,	(self.batch_size, self.seq_length, self.hidden_size)				)

		def 							__lowerCamelCase							(   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 ,	):
			__lowerCAmelCase    :		int		    =   XLMWithLMHeadModel(_SCREAMING_SNAKE_CASE				)
			model.to(_SCREAMING_SNAKE_CASE				)
			model.eval()

			__lowerCAmelCase    :		str		    =   model(_SCREAMING_SNAKE_CASE ,	token_type_ids=_SCREAMING_SNAKE_CASE ,	labels=_SCREAMING_SNAKE_CASE				)
			self.parent.assertEqual(result.loss.shape ,	()				)
			self.parent.assertEqual(result.logits.shape ,	(self.batch_size, self.seq_length, self.vocab_size)				)

		def 							__lowerCamelCase							(   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 ,	):
			__lowerCAmelCase    :		Optional[Any]		    =   XLMForQuestionAnsweringSimple(_SCREAMING_SNAKE_CASE				)
			model.to(_SCREAMING_SNAKE_CASE				)
			model.eval()

			__lowerCAmelCase    :		Optional[int]		    =   model(_SCREAMING_SNAKE_CASE				)

			__lowerCAmelCase    :		Optional[Any]		    =   model(_SCREAMING_SNAKE_CASE ,	start_positions=_SCREAMING_SNAKE_CASE ,	end_positions=_SCREAMING_SNAKE_CASE				)
			__lowerCAmelCase    :		List[str]		    =   outputs
			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 							__lowerCamelCase							(   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 ,	):
			__lowerCAmelCase    :		Any		    =   XLMForQuestionAnswering(_SCREAMING_SNAKE_CASE				)
			model.to(_SCREAMING_SNAKE_CASE				)
			model.eval()

			__lowerCAmelCase    :		Optional[Any]		    =   model(_SCREAMING_SNAKE_CASE				)

			__lowerCAmelCase    :		Tuple		    =   model(
			    _SCREAMING_SNAKE_CASE ,	start_positions=_SCREAMING_SNAKE_CASE ,	end_positions=_SCREAMING_SNAKE_CASE ,	cls_index=_SCREAMING_SNAKE_CASE ,	is_impossible=_SCREAMING_SNAKE_CASE ,	p_mask=_SCREAMING_SNAKE_CASE ,	)

			__lowerCAmelCase    :		Any		    =   model(
			    _SCREAMING_SNAKE_CASE ,	start_positions=_SCREAMING_SNAKE_CASE ,	end_positions=_SCREAMING_SNAKE_CASE ,	cls_index=_SCREAMING_SNAKE_CASE ,	is_impossible=_SCREAMING_SNAKE_CASE ,	)

			((__lowerCAmelCase)    ,     )    :		int		    =   result_with_labels.to_tuple()

			__lowerCAmelCase    :		str		    =   model(_SCREAMING_SNAKE_CASE ,	start_positions=_SCREAMING_SNAKE_CASE ,	end_positions=_SCREAMING_SNAKE_CASE				)

			((__lowerCAmelCase)    ,     )    :		Tuple		    =   result_with_labels.to_tuple()

			self.parent.assertEqual(result_with_labels.loss.shape ,	()				)
			self.parent.assertEqual(result.start_top_log_probs.shape ,	(self.batch_size, model.config.start_n_top)				)
			self.parent.assertEqual(result.start_top_index.shape ,	(self.batch_size, model.config.start_n_top)				)
			self.parent.assertEqual(
			    result.end_top_log_probs.shape ,	(self.batch_size, model.config.start_n_top * model.config.end_n_top)				)
			self.parent.assertEqual(
			    result.end_top_index.shape ,	(self.batch_size, model.config.start_n_top * model.config.end_n_top)				)
			self.parent.assertEqual(result.cls_logits.shape ,	(self.batch_size,)				)

		def 							__lowerCamelCase							(   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 ,	):
			__lowerCAmelCase    :		Any		    =   XLMForSequenceClassification(_SCREAMING_SNAKE_CASE				)
			model.to(_SCREAMING_SNAKE_CASE				)
			model.eval()

			__lowerCAmelCase    :		Dict		    =   model(_SCREAMING_SNAKE_CASE				)
			__lowerCAmelCase    :		Tuple		    =   model(_SCREAMING_SNAKE_CASE ,	labels=_SCREAMING_SNAKE_CASE				)
			self.parent.assertEqual(result.loss.shape ,	()				)
			self.parent.assertEqual(result.logits.shape ,	(self.batch_size, self.type_sequence_label_size)				)

		def 							__lowerCamelCase							(   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 ,	):
			__lowerCAmelCase    :		List[str]		    =   self.num_labels
			__lowerCAmelCase    :		Dict		    =   XLMForTokenClassification(_SCREAMING_SNAKE_CASE				)
			model.to(_SCREAMING_SNAKE_CASE				)
			model.eval()

			__lowerCAmelCase    :		Optional[Any]		    =   model(_SCREAMING_SNAKE_CASE ,	attention_mask=_SCREAMING_SNAKE_CASE ,	labels=_SCREAMING_SNAKE_CASE				)
			self.parent.assertEqual(result.logits.shape ,	(self.batch_size, self.seq_length, self.num_labels)				)

		def 							__lowerCamelCase							(   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 ,	):
			__lowerCAmelCase    :		List[str]		    =   self.num_choices
			__lowerCAmelCase    :		Any		    =   XLMForMultipleChoice(config=_SCREAMING_SNAKE_CASE				)
			model.to(_SCREAMING_SNAKE_CASE				)
			model.eval()
			__lowerCAmelCase    :		Tuple		    =   input_ids.unsqueeze(1				).expand(-1 ,	self.num_choices ,	-1				).contiguous()
			__lowerCAmelCase    :		Optional[int]		    =   token_type_ids.unsqueeze(1				).expand(-1 ,	self.num_choices ,	-1				).contiguous()
			__lowerCAmelCase    :		int		    =   input_mask.unsqueeze(1				).expand(-1 ,	self.num_choices ,	-1				).contiguous()
			__lowerCAmelCase    :		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_choices)				)







		def 							__lowerCamelCase							(   self				):
			__lowerCAmelCase    :		str		    =   self.prepare_config_and_inputs()
			(
			    (
			    __lowerCAmelCase
			)    ,     (
			    __lowerCAmelCase
			)    ,     (
			    __lowerCAmelCase
			)    ,     (
			    __lowerCAmelCase
			)    ,     (
			    __lowerCAmelCase
			)    ,     (
			    __lowerCAmelCase
			)    ,     (
			    __lowerCAmelCase
			)    ,     (
			    __lowerCAmelCase
			)    ,     (
			    __lowerCAmelCase
			)    ,     
			)    :		Dict		    =   config_and_inputs
			__lowerCAmelCase    :		Tuple		    =   {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'lengths': input_lengths}
			return config, inputs_dict




@require_torch
class 				A__ (			_lowerCamelCase ,  _lowerCamelCase ,  _lowerCamelCase ,  unittest.TestCase):
		A_		: str            =			(
		    (
		        XLMModel,
		        XLMWithLMHeadModel,
		        XLMForQuestionAnswering,
		        XLMForSequenceClassification,
		        XLMForQuestionAnsweringSimple,
		        XLMForTokenClassification,
		        XLMForMultipleChoice,
		    )
		    if is_torch_available()
		    else ()
		)
		A_		: Any            =			(
		    (XLMWithLMHeadModel,) if is_torch_available() else ()
		)  # TODO (PVP): Check other models whether language generation is also applicable
		A_		: Any            =			(
		    {
		        'feature-extraction': XLMModel,
		        'fill-mask': XLMWithLMHeadModel,
		        'question-answering': XLMForQuestionAnsweringSimple,
		        'text-classification': XLMForSequenceClassification,
		        'text-generation': XLMWithLMHeadModel,
		        'token-classification': XLMForTokenClassification,
		        'zero-shot': XLMForSequenceClassification,
		    }
		    if is_torch_available()
		    else {}
		)

		def 							__lowerCamelCase							(   self ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE				):
			if (
			    pipeline_test_casse_name == "QAPipelineTests"
			    and tokenizer_name is not None
			    and not tokenizer_name.endswith('Fast'				)
			):
				# `QAPipelineTests` fails for a few models when the slower tokenizer are used.
				# (The slower tokenizers were never used for pipeline tests before the pipeline testing rework)
				# TODO: check (and possibly fix) the `QAPipelineTests` with slower tokenizer
				return True

			return False

		def 							__lowerCamelCase							(   self ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE=False				):
			__lowerCAmelCase    :		List[Any]		    =   super()._prepare_for_class(_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	return_labels=_SCREAMING_SNAKE_CASE				)

			if return_labels:
				if model_class.__name__ == "XLMForQuestionAnswering":
					__lowerCAmelCase    :		Tuple		    =   torch.zeros(
					    self.model_tester.batch_size ,	dtype=torch.long ,	device=_SCREAMING_SNAKE_CASE				)
					__lowerCAmelCase    :		Optional[int]		    =   torch.zeros(
					    self.model_tester.batch_size ,	dtype=torch.long ,	device=_SCREAMING_SNAKE_CASE				)

			return inputs_dict

		def 							__lowerCamelCase							(   self				):
			__lowerCAmelCase    :		Optional[Any]		    =   XLMModelTester(self				)
			__lowerCAmelCase    :		Dict		    =   ConfigTester(self ,	config_class=_SCREAMING_SNAKE_CASE ,	emb_dim=37				)

		def 							__lowerCamelCase							(   self				):
			self.config_tester.run_common_tests()

		def 							__lowerCamelCase							(   self				):
			__lowerCAmelCase    :		Tuple		    =   self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_xlm_model(*_SCREAMING_SNAKE_CASE				)

		def 							__lowerCamelCase							(   self				):
			__lowerCAmelCase    :		List[Any]		    =   self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_xlm_lm_head(*_SCREAMING_SNAKE_CASE				)

		def 							__lowerCamelCase							(   self				):
			__lowerCAmelCase    :		int		    =   self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_xlm_simple_qa(*_SCREAMING_SNAKE_CASE				)

		def 							__lowerCamelCase							(   self				):
			__lowerCAmelCase    :		Tuple		    =   self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_xlm_qa(*_SCREAMING_SNAKE_CASE				)

		def 							__lowerCamelCase							(   self				):
			__lowerCAmelCase    :		List[Any]		    =   self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_xlm_sequence_classif(*_SCREAMING_SNAKE_CASE				)

		def 							__lowerCamelCase							(   self				):
			__lowerCAmelCase    :		Union[str, Any]		    =   self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_xlm_token_classif(*_SCREAMING_SNAKE_CASE				)

		def 							__lowerCamelCase							(   self				):
			__lowerCAmelCase    :		Optional[Any]		    =   self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_xlm_for_multiple_choice(*_SCREAMING_SNAKE_CASE				)

		def 							__lowerCamelCase							(   self ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE=False ,	_SCREAMING_SNAKE_CASE=1				):
			self.assertIsInstance(_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE				)
			self.assertListEqual(
			    [isinstance(_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE				) for iter_attentions in attentions] ,	[True] * len(_SCREAMING_SNAKE_CASE				)				)
			self.assertEqual(len(_SCREAMING_SNAKE_CASE				) ,	(max_length - min_length) * num_beam_groups				)

			for idx, iter_attentions in enumerate(_SCREAMING_SNAKE_CASE				):
				# adds PAD dummy token
				__lowerCAmelCase    :		List[Any]		    =   min_length + idx + 1
				__lowerCAmelCase    :		int		    =   min_length + idx + 1

				__lowerCAmelCase    :		Any		    =   (
				    batch_size * num_beam_groups,
				    config.num_attention_heads,
				    tgt_len,
				    src_len,
				)
				# check attn size
				self.assertListEqual(
				    [layer_attention.shape for layer_attention in iter_attentions] ,	[expected_shape] * len(_SCREAMING_SNAKE_CASE				)				)

		def 							__lowerCamelCase							(   self ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE=False ,	_SCREAMING_SNAKE_CASE=1				):
			self.assertIsInstance(_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE				)
			self.assertListEqual(
			    [isinstance(_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE				) for iter_hidden_states in hidden_states] ,	[True] * len(_SCREAMING_SNAKE_CASE				) ,	)
			self.assertEqual(len(_SCREAMING_SNAKE_CASE				) ,	(max_length - min_length) * num_beam_groups				)

			for idx, iter_hidden_states in enumerate(_SCREAMING_SNAKE_CASE				):
				# adds PAD dummy token
				__lowerCAmelCase    :		str		    =   min_length + idx + 1
				__lowerCAmelCase    :		int		    =   (batch_size * num_beam_groups, seq_len, config.hidden_size)
				# check hidden size
				self.assertListEqual(
				    [layer_hidden_states.shape for layer_hidden_states in iter_hidden_states] ,	[expected_shape] * len(_SCREAMING_SNAKE_CASE				) ,	)
			pass







		@slow
		def 							__lowerCamelCase							(   self				):
			for model_name in XLM_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
				__lowerCAmelCase    :		Optional[Any]		    =   XLMModel.from_pretrained(_SCREAMING_SNAKE_CASE				)
				self.assertIsNotNone(_SCREAMING_SNAKE_CASE				)




@require_torch
class 				A__ (			unittest.TestCase):

		@slow
		def 							__lowerCamelCase							(   self				):
			__lowerCAmelCase    :		Tuple		    =   XLMWithLMHeadModel.from_pretrained('xlm-mlm-en-2048'				)
			model.to(_SCREAMING_SNAKE_CASE				)
			__lowerCAmelCase    :		Dict		    =   torch.tensor([[14, 4_47]] ,	dtype=torch.long ,	device=_SCREAMING_SNAKE_CASE				)  # the president
			__lowerCAmelCase    :		Any		    =   [
			    14,
			    4_47,
			    14,
			    4_47,
			    14,
			    4_47,
			    14,
			    4_47,
			    14,
			    4_47,
			    14,
			    4_47,
			    14,
			    4_47,
			    14,
			    4_47,
			    14,
			    4_47,
			    14,
			    4_47,
			]  # the president the president the president the president the president the president the president the president the president the president
			# TODO(PVP): this and other input_ids I tried for generation give pretty bad results. Not sure why. Model might just not be made for auto-regressive inference
			__lowerCAmelCase    :		int		    =   model.generate(_SCREAMING_SNAKE_CASE ,	do_sample=_SCREAMING_SNAKE_CASE				)
			self.assertListEqual(output_ids[0].cpu().numpy().tolist() ,	_SCREAMING_SNAKE_CASE				)

"""simple docstring"""







from typing import List, Optional, Union

from ...image_utils import ImageInput
from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding, PaddingStrategy, PreTokenizedInput, TextInput, TruncationStrategy
from ...utils import TensorType




class 				A__ (			_lowerCamelCase):
		A_		: Any            =			['image_processor', 'tokenizer']
		A_		: Optional[Any]            =			'BlipImageProcessor'
		A_		: int            =			'AutoTokenizer'

		def __init__(   self ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE				):
			__lowerCAmelCase    :		Union[str, Any]		    =   False
			super().__init__(_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE				)
			__lowerCAmelCase    :		List[Any]		    =   self.image_processor

		def __call__(   self ,	_SCREAMING_SNAKE_CASE = None ,	_SCREAMING_SNAKE_CASE = None ,	_SCREAMING_SNAKE_CASE = True ,	_SCREAMING_SNAKE_CASE = False ,	_SCREAMING_SNAKE_CASE = None ,	_SCREAMING_SNAKE_CASE = None ,	_SCREAMING_SNAKE_CASE = 0 ,	_SCREAMING_SNAKE_CASE = None ,	_SCREAMING_SNAKE_CASE = None ,	_SCREAMING_SNAKE_CASE = False ,	_SCREAMING_SNAKE_CASE = False ,	_SCREAMING_SNAKE_CASE = False ,	_SCREAMING_SNAKE_CASE = False ,	_SCREAMING_SNAKE_CASE = False ,	_SCREAMING_SNAKE_CASE = True ,	_SCREAMING_SNAKE_CASE = None ,	**_SCREAMING_SNAKE_CASE ,	):
			if images is None and text is None:
				raise ValueError('You have to specify either images or text.'				)

			# Get only text
			if images is None:
				__lowerCAmelCase    :		Optional[int]		    =   self.tokenizer
				__lowerCAmelCase    :		List[str]		    =   self.tokenizer(
				    text=_SCREAMING_SNAKE_CASE ,	add_special_tokens=_SCREAMING_SNAKE_CASE ,	padding=_SCREAMING_SNAKE_CASE ,	truncation=_SCREAMING_SNAKE_CASE ,	max_length=_SCREAMING_SNAKE_CASE ,	stride=_SCREAMING_SNAKE_CASE ,	pad_to_multiple_of=_SCREAMING_SNAKE_CASE ,	return_attention_mask=_SCREAMING_SNAKE_CASE ,	return_overflowing_tokens=_SCREAMING_SNAKE_CASE ,	return_special_tokens_mask=_SCREAMING_SNAKE_CASE ,	return_offsets_mapping=_SCREAMING_SNAKE_CASE ,	return_token_type_ids=_SCREAMING_SNAKE_CASE ,	return_length=_SCREAMING_SNAKE_CASE ,	verbose=_SCREAMING_SNAKE_CASE ,	return_tensors=_SCREAMING_SNAKE_CASE ,	**_SCREAMING_SNAKE_CASE ,	)
				return text_encoding

			# add pixel_values
			__lowerCAmelCase    :		List[Any]		    =   self.image_processor(_SCREAMING_SNAKE_CASE ,	return_tensors=_SCREAMING_SNAKE_CASE				)

			if text is not None:
				__lowerCAmelCase    :		Optional[int]		    =   self.tokenizer(
				    text=_SCREAMING_SNAKE_CASE ,	add_special_tokens=_SCREAMING_SNAKE_CASE ,	padding=_SCREAMING_SNAKE_CASE ,	truncation=_SCREAMING_SNAKE_CASE ,	max_length=_SCREAMING_SNAKE_CASE ,	stride=_SCREAMING_SNAKE_CASE ,	pad_to_multiple_of=_SCREAMING_SNAKE_CASE ,	return_attention_mask=_SCREAMING_SNAKE_CASE ,	return_overflowing_tokens=_SCREAMING_SNAKE_CASE ,	return_special_tokens_mask=_SCREAMING_SNAKE_CASE ,	return_offsets_mapping=_SCREAMING_SNAKE_CASE ,	return_token_type_ids=_SCREAMING_SNAKE_CASE ,	return_length=_SCREAMING_SNAKE_CASE ,	verbose=_SCREAMING_SNAKE_CASE ,	return_tensors=_SCREAMING_SNAKE_CASE ,	**_SCREAMING_SNAKE_CASE ,	)
			else:
				__lowerCAmelCase    :		int		    =   None

			if text_encoding is not None:
				encoding_image_processor.update(_SCREAMING_SNAKE_CASE				)

			return encoding_image_processor

		def 							__lowerCamelCase							(   self ,	*_SCREAMING_SNAKE_CASE ,	**_SCREAMING_SNAKE_CASE				):
			return self.tokenizer.batch_decode(*_SCREAMING_SNAKE_CASE ,	**_SCREAMING_SNAKE_CASE				)

		def 							__lowerCamelCase							(   self ,	*_SCREAMING_SNAKE_CASE ,	**_SCREAMING_SNAKE_CASE				):
			return self.tokenizer.decode(*_SCREAMING_SNAKE_CASE ,	**_SCREAMING_SNAKE_CASE				)







		@property
		# Copied from transformers.models.blip.processing_blip.BlipProcessor.model_input_names
		def 							__lowerCamelCase							(   self				):
			__lowerCAmelCase    :		int		    =   self.tokenizer.model_input_names
			__lowerCAmelCase    :		Union[str, Any]		    =   self.image_processor.model_input_names
			return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names				)				)