




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



				def __init__(      self      :		Optional[Any]		,	_UpperCAmelCase      :		List[str]		,	_UpperCAmelCase      :		List[Any]=13		,	_UpperCAmelCase      :		Optional[int]=7		,	_UpperCAmelCase      :		Optional[Any]=True		,	_UpperCAmelCase      :		Union[str, Any]=True		,	_UpperCAmelCase      :		str=True		,	_UpperCAmelCase      :		Optional[int]=True		,	_UpperCAmelCase      :		Optional[Any]=True		,	_UpperCAmelCase      :		List[Any]=False		,	_UpperCAmelCase      :		List[str]=False		,	_UpperCAmelCase      :		List[str]=False		,	_UpperCAmelCase      :		int=2		,	_UpperCAmelCase      :		int=99		,	_UpperCAmelCase      :		List[str]=0		,	_UpperCAmelCase      :		Dict=32		,	_UpperCAmelCase      :		Tuple=5		,	_UpperCAmelCase      :		List[str]=4		,	_UpperCAmelCase      :		Optional[int]=0.1		,	_UpperCAmelCase      :		List[str]=0.1		,	_UpperCAmelCase      :		Optional[Any]=512		,	_UpperCAmelCase      :		Tuple=2		,	_UpperCAmelCase      :		str=0.02		,	_UpperCAmelCase      :		Any=2		,	_UpperCAmelCase      :		int=4		,	_UpperCAmelCase      :		Any="last"		,	_UpperCAmelCase      :		Optional[Any]=True		,	_UpperCAmelCase      :		int=None		,	_UpperCAmelCase      :		Dict=0		,	)  ->    Tuple:





								'''simple docstring'''




								_lowerCAmelCase    :    Tuple										=      parent
								_lowerCAmelCase    :    Optional[Any]										=      batch_size
								_lowerCAmelCase    :    Tuple										=      seq_length
								_lowerCAmelCase    :    Optional[int]										=      is_training
								_lowerCAmelCase    :    Tuple										=      use_input_lengths
								_lowerCAmelCase    :    int										=      use_token_type_ids
								_lowerCAmelCase    :    int										=      use_labels
								_lowerCAmelCase    :    Union[str, Any]										=      gelu_activation
								_lowerCAmelCase    :    Union[str, Any]										=      sinusoidal_embeddings
								_lowerCAmelCase    :    Dict										=      causal
								_lowerCAmelCase    :    Tuple										=      asm
								_lowerCAmelCase    :    Union[str, Any]										=      n_langs
								_lowerCAmelCase    :    Union[str, Any]										=      vocab_size
								_lowerCAmelCase    :    Union[str, Any]										=      n_special
								_lowerCAmelCase    :    Optional[Any]										=      hidden_size
								_lowerCAmelCase    :    List[Any]										=      num_hidden_layers
								_lowerCAmelCase    :    Dict										=      num_attention_heads
								_lowerCAmelCase    :    Optional[int]										=      hidden_dropout_prob
								_lowerCAmelCase    :    List[Any]										=      attention_probs_dropout_prob
								_lowerCAmelCase    :    Optional[Any]										=      max_position_embeddings
								_lowerCAmelCase    :    Tuple										=      type_sequence_label_size
								_lowerCAmelCase    :    str										=      initializer_range
								_lowerCAmelCase    :    str										=      num_labels
								_lowerCAmelCase    :    Tuple										=      num_choices
								_lowerCAmelCase    :    Optional[Any]										=      summary_type
								_lowerCAmelCase    :    Dict										=      use_proj
								_lowerCAmelCase    :    str										=      scope
								_lowerCAmelCase    :    int										=      bos_token_id



				def       SCREAMING_SNAKE_CASE       (      self      :		List[Any]      )  ->    List[str]:





								'''simple docstring'''




								_lowerCAmelCase    :    Union[str, Any]										=      ids_tensor([self.batch_size, self.seq_length]		,	self.vocab_size      )
								_lowerCAmelCase    :    List[Any]										=      random_attention_mask([self.batch_size, self.seq_length]      )

								_lowerCAmelCase    :    Optional[Any]										=      None
								if self.use_input_lengths:
												_lowerCAmelCase    :    Optional[int]										=      (
												    ids_tensor([self.batch_size]		,	vocab_size=2      ) + self.seq_length - 2
												)  # small variation of seq_length

								_lowerCAmelCase    :    Dict										=      None
								if self.use_token_type_ids:
												_lowerCAmelCase    :    Optional[Any]										=      ids_tensor([self.batch_size, self.seq_length]		,	self.n_langs      )

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

								_lowerCAmelCase    :    Dict										=      self.get_config()

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



				def       SCREAMING_SNAKE_CASE       (      self      :		List[str]      )  ->    Optional[Any]:





								'''simple docstring'''




								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       SCREAMING_SNAKE_CASE       (      self      :		str		,	_UpperCAmelCase      :		Union[str, Any]		,	_UpperCAmelCase      :		List[str]		,	_UpperCAmelCase      :		List[str]		,	_UpperCAmelCase      :		int		,	_UpperCAmelCase      :		Any		,	_UpperCAmelCase      :		List[str]		,	_UpperCAmelCase      :		Union[str, Any]		,	_UpperCAmelCase      :		str		,	_UpperCAmelCase      :		Optional[Any]		,	)  ->    int:





								'''simple docstring'''




								_lowerCAmelCase    :    Any										=      XLMModel(config=_lowercase      )
								model.to(_lowercase      )
								model.eval()
								_lowerCAmelCase    :    List[str]										=      model(_lowercase		,	lengths=_lowercase		,	langs=_lowercase      )
								_lowerCAmelCase    :    Tuple										=      model(_lowercase		,	langs=_lowercase      )
								_lowerCAmelCase    :    Tuple										=      model(_lowercase      )
								self.parent.assertEqual(result.last_hidden_state.shape		,	(self.batch_size, self.seq_length, self.hidden_size)      )



				def       SCREAMING_SNAKE_CASE       (      self      :		Any		,	_UpperCAmelCase      :		int		,	_UpperCAmelCase      :		Optional[int]		,	_UpperCAmelCase      :		Dict		,	_UpperCAmelCase      :		Any		,	_UpperCAmelCase      :		Any		,	_UpperCAmelCase      :		List[str]		,	_UpperCAmelCase      :		List[Any]		,	_UpperCAmelCase      :		Optional[Any]		,	_UpperCAmelCase      :		Union[str, Any]		,	)  ->    List[Any]:





								'''simple docstring'''




								_lowerCAmelCase    :    int										=      XLMWithLMHeadModel(_lowercase      )
								model.to(_lowercase      )
								model.eval()

								_lowerCAmelCase    :    Optional[int]										=      model(_lowercase		,	token_type_ids=_lowercase		,	labels=_lowercase      )
								self.parent.assertEqual(result.loss.shape		,	()      )
								self.parent.assertEqual(result.logits.shape		,	(self.batch_size, self.seq_length, self.vocab_size)      )



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





								'''simple docstring'''




								_lowerCAmelCase    :    Union[str, Any]										=      XLMForQuestionAnsweringSimple(_lowercase      )
								model.to(_lowercase      )
								model.eval()

								_lowerCAmelCase    :    str										=      model(_lowercase      )

								_lowerCAmelCase    :    str										=      model(_lowercase		,	start_positions=_lowercase		,	end_positions=_lowercase      )
								_lowerCAmelCase    :    Optional[Any]										=      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       SCREAMING_SNAKE_CASE       (      self      :		Optional[Any]		,	_UpperCAmelCase      :		Union[str, Any]		,	_UpperCAmelCase      :		List[Any]		,	_UpperCAmelCase      :		Dict		,	_UpperCAmelCase      :		Union[str, Any]		,	_UpperCAmelCase      :		Dict		,	_UpperCAmelCase      :		Tuple		,	_UpperCAmelCase      :		int		,	_UpperCAmelCase      :		str		,	_UpperCAmelCase      :		List[Any]		,	)  ->    int:





								'''simple docstring'''




								_lowerCAmelCase    :    int										=      XLMForQuestionAnswering(_lowercase      )
								model.to(_lowercase      )
								model.eval()

								_lowerCAmelCase    :    Union[str, Any]										=      model(_lowercase      )

								_lowerCAmelCase    :    Any										=      model(
								    _lowercase		,	start_positions=_lowercase		,	end_positions=_lowercase		,	cls_index=_lowercase		,	is_impossible=_lowercase		,	p_mask=_lowercase		,	)

								_lowerCAmelCase    :    Any										=      model(
								    _lowercase		,	start_positions=_lowercase		,	end_positions=_lowercase		,	cls_index=_lowercase		,	is_impossible=_lowercase		,	)

								(_lowerCAmelCase      )    :    str										=      result_with_labels.to_tuple()

								_lowerCAmelCase    :    Tuple										=      model(_lowercase		,	start_positions=_lowercase		,	end_positions=_lowercase      )

								(_lowerCAmelCase      )    :    Union[str, Any]										=      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       SCREAMING_SNAKE_CASE       (      self      :		Dict		,	_UpperCAmelCase      :		Optional[int]		,	_UpperCAmelCase      :		Any		,	_UpperCAmelCase      :		Optional[Any]		,	_UpperCAmelCase      :		str		,	_UpperCAmelCase      :		Union[str, Any]		,	_UpperCAmelCase      :		List[Any]		,	_UpperCAmelCase      :		Optional[Any]		,	_UpperCAmelCase      :		Optional[int]		,	_UpperCAmelCase      :		Union[str, Any]		,	)  ->    Optional[Any]:





								'''simple docstring'''




								_lowerCAmelCase    :    str										=      XLMForSequenceClassification(_lowercase      )
								model.to(_lowercase      )
								model.eval()

								_lowerCAmelCase    :    int										=      model(_lowercase      )
								_lowerCAmelCase    :    Any										=      model(_lowercase		,	labels=_lowercase      )
								self.parent.assertEqual(result.loss.shape		,	()      )
								self.parent.assertEqual(result.logits.shape		,	(self.batch_size, self.type_sequence_label_size)      )



				def       SCREAMING_SNAKE_CASE       (      self      :		Dict		,	_UpperCAmelCase      :		str		,	_UpperCAmelCase      :		str		,	_UpperCAmelCase      :		Optional[int]		,	_UpperCAmelCase      :		Any		,	_UpperCAmelCase      :		Optional[Any]		,	_UpperCAmelCase      :		Dict		,	_UpperCAmelCase      :		Any		,	_UpperCAmelCase      :		Union[str, Any]		,	_UpperCAmelCase      :		Union[str, Any]		,	)  ->    Optional[Any]:





								'''simple docstring'''




								_lowerCAmelCase    :    int										=      self.num_labels
								_lowerCAmelCase    :    Any										=      XLMForTokenClassification(_lowercase      )
								model.to(_lowercase      )
								model.eval()

								_lowerCAmelCase    :    Dict										=      model(_lowercase		,	attention_mask=_lowercase		,	labels=_lowercase      )
								self.parent.assertEqual(result.logits.shape		,	(self.batch_size, self.seq_length, self.num_labels)      )



				def       SCREAMING_SNAKE_CASE       (      self      :		Optional[Any]		,	_UpperCAmelCase      :		str		,	_UpperCAmelCase      :		Dict		,	_UpperCAmelCase      :		str		,	_UpperCAmelCase      :		Optional[Any]		,	_UpperCAmelCase      :		Dict		,	_UpperCAmelCase      :		Tuple		,	_UpperCAmelCase      :		Any		,	_UpperCAmelCase      :		int		,	_UpperCAmelCase      :		List[Any]		,	)  ->    Optional[Any]:





								'''simple docstring'''




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



				def       SCREAMING_SNAKE_CASE       (      self      :		Dict      )  ->    Any:





								'''simple docstring'''




								_lowerCAmelCase    :    Tuple										=      self.prepare_config_and_inputs()
								(
								    _lowerCAmelCase      
								)    :    List[str]										=      config_and_inputs
								_lowerCAmelCase    :    Optional[int]										=      {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'lengths': input_lengths}
								return config, inputs_dict






@require_torch
class        __snake_case  (UpperCAmelCase_						,	UpperCAmelCase_						,	UpperCAmelCase_						,	unittest.TestCase		):
				lowerCAmelCase__				=     (
				    (
				        XLMModel,
				        XLMWithLMHeadModel,
				        XLMForQuestionAnswering,
				        XLMForSequenceClassification,
				        XLMForQuestionAnsweringSimple,
				        XLMForTokenClassification,
				        XLMForMultipleChoice,
				    )
				    if is_torch_available()
				    else ()
				)
				lowerCAmelCase__				=     (
				    (XLMWithLMHeadModel,) if is_torch_available() else ()
				)  # TODO (PVP): Check other models whether language generation is also applicable
				lowerCAmelCase__				=     (
				    {
				        '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       SCREAMING_SNAKE_CASE       (      self      :		Optional[int]		,	_UpperCAmelCase      :		Optional[int]		,	_UpperCAmelCase      :		int		,	_UpperCAmelCase      :		List[Any]		,	_UpperCAmelCase      :		int		,	_UpperCAmelCase      :		List[Any]      )  ->    Optional[Any]:





								'''simple docstring'''




								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       SCREAMING_SNAKE_CASE       (      self      :		List[str]		,	_UpperCAmelCase      :		Union[str, Any]		,	_UpperCAmelCase      :		Union[str, Any]		,	_UpperCAmelCase      :		List[Any]=False      )  ->    Optional[Any]:





								'''simple docstring'''




								_lowerCAmelCase    :    Dict										=      super()._prepare_for_class(_lowercase		,	_lowercase		,	return_labels=_lowercase      )

								if return_labels:
												if model_class.__name__ == "XLMForQuestionAnswering":
																_lowerCAmelCase    :    str										=      torch.zeros(
																    self.model_tester.batch_size		,	dtype=torch.long		,	device=_lowercase      )
																_lowerCAmelCase    :    Union[str, Any]										=      torch.zeros(
																    self.model_tester.batch_size		,	dtype=torch.long		,	device=_lowercase      )

								return inputs_dict



				def       SCREAMING_SNAKE_CASE       (      self      :		int      )  ->    str:





								'''simple docstring'''




								_lowerCAmelCase    :    Optional[Any]										=      XLMModelTester(self      )
								_lowerCAmelCase    :    Tuple										=      ConfigTester(self		,	config_class=_lowercase		,	emb_dim=37      )



				def       SCREAMING_SNAKE_CASE       (      self      :		int      )  ->    str:





								'''simple docstring'''




								self.config_tester.run_common_tests()



				def       SCREAMING_SNAKE_CASE       (      self      :		Optional[Any]      )  ->    Dict:





								'''simple docstring'''




								_lowerCAmelCase    :    List[str]										=      self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_xlm_model(*_lowercase      )



				def       SCREAMING_SNAKE_CASE       (      self      :		int      )  ->    Any:





								'''simple docstring'''




								_lowerCAmelCase    :    Dict										=      self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_xlm_lm_head(*_lowercase      )



				def       SCREAMING_SNAKE_CASE       (      self      :		int      )  ->    str:





								'''simple docstring'''




								_lowerCAmelCase    :    Optional[int]										=      self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_xlm_simple_qa(*_lowercase      )



				def       SCREAMING_SNAKE_CASE       (      self      :		int      )  ->    Tuple:





								'''simple docstring'''




								_lowerCAmelCase    :    Tuple										=      self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_xlm_qa(*_lowercase      )



				def       SCREAMING_SNAKE_CASE       (      self      :		Optional[int]      )  ->    List[str]:





								'''simple docstring'''




								_lowerCAmelCase    :    Optional[Any]										=      self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_xlm_sequence_classif(*_lowercase      )



				def       SCREAMING_SNAKE_CASE       (      self      :		List[Any]      )  ->    Dict:





								'''simple docstring'''




								_lowerCAmelCase    :    Dict										=      self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_xlm_token_classif(*_lowercase      )



				def       SCREAMING_SNAKE_CASE       (      self      :		Any      )  ->    List[str]:





								'''simple docstring'''




								_lowerCAmelCase    :    int										=      self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_xlm_for_multiple_choice(*_lowercase      )



				def       SCREAMING_SNAKE_CASE       (      self      :		List[str]		,	_UpperCAmelCase      :		str		,	_UpperCAmelCase      :		Any		,	_UpperCAmelCase      :		Any		,	_UpperCAmelCase      :		Tuple		,	_UpperCAmelCase      :		Union[str, Any]		,	_UpperCAmelCase      :		Optional[Any]=False		,	_UpperCAmelCase      :		Any=1      )  ->    int:





								'''simple docstring'''




								self.assertIsInstance(_lowercase		,	_lowercase      )
								self.assertListEqual(
								    [isinstance(_lowercase		,	_lowercase      ) for iter_attentions in attentions]		,	[True] * len(_lowercase      )      )
								self.assertEqual(len(_lowercase      )		,	(max_length - min_length) * num_beam_groups      )

								for idx, iter_attentions in enumerate(_lowercase      ):
												# adds PAD dummy token
												_lowerCAmelCase    :    Optional[int]										=      min_length + idx + 1
												_lowerCAmelCase    :    Optional[Any]										=      min_length + idx + 1

												_lowerCAmelCase    :    int										=      (
												    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(_lowercase      )      )



				def       SCREAMING_SNAKE_CASE       (      self      :		Dict		,	_UpperCAmelCase      :		List[Any]		,	_UpperCAmelCase      :		Optional[Any]		,	_UpperCAmelCase      :		Optional[Any]		,	_UpperCAmelCase      :		Optional[int]		,	_UpperCAmelCase      :		Union[str, Any]		,	_UpperCAmelCase      :		Dict=False		,	_UpperCAmelCase      :		List[str]=1      )  ->    Any:





								'''simple docstring'''




								self.assertIsInstance(_lowercase		,	_lowercase      )
								self.assertListEqual(
								    [isinstance(_lowercase		,	_lowercase      ) for iter_hidden_states in hidden_states]		,	[True] * len(_lowercase      )		,	)
								self.assertEqual(len(_lowercase      )		,	(max_length - min_length) * num_beam_groups      )

								for idx, iter_hidden_states in enumerate(_lowercase      ):
												# adds PAD dummy token
												_lowerCAmelCase    :    Union[str, Any]										=      min_length + idx + 1
												_lowerCAmelCase    :    Tuple										=      (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(_lowercase      )		,	)
								pass



				@slow
				def       SCREAMING_SNAKE_CASE       (      self      :		Tuple      )  ->    int:





								'''simple docstring'''




								for model_name in XLM_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
												_lowerCAmelCase    :    Optional[Any]										=      XLMModel.from_pretrained(_lowercase      )
												self.assertIsNotNone(_lowercase      )






@require_torch
class        __snake_case  (unittest.TestCase		):



				@slow
				def       SCREAMING_SNAKE_CASE       (      self      :		Dict      )  ->    int:





								'''simple docstring'''




								_lowerCAmelCase    :    str										=      XLMWithLMHeadModel.from_pretrained("""xlm-mlm-en-2048"""      )
								model.to(_lowercase      )
								_lowerCAmelCase    :    List[Any]										=      torch.tensor([[14, 447]]		,	dtype=torch.long		,	device=_lowercase      )  # the president
								_lowerCAmelCase    :    int										=      [
								    14,
								    447,
								    14,
								    447,
								    14,
								    447,
								    14,
								    447,
								    14,
								    447,
								    14,
								    447,
								    14,
								    447,
								    14,
								    447,
								    14,
								    447,
								    14,
								    447,
								]  # 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    :    Optional[int]										=      model.generate(_lowercase		,	do_sample=_lowercase      )
								self.assertListEqual(output_ids[0].cpu().numpy().tolist()		,	_lowercase      )







def 							_UpperCAmelCase  (UpperCamelCase_ : str       ):
				'''simple docstring'''
				_lowerCAmelCase    :    Dict										=      [0] * len(UpperCamelCase_       )

				for i in range(1      ,    len(UpperCamelCase_       )       ):
								# use last results for better performance - dynamic programming
								_lowerCAmelCase    :    Union[str, Any]										=      prefix_result[i - 1]
								while j > 0 and input_string[i] != input_string[j]:
												_lowerCAmelCase    :    str										=      prefix_result[j - 1]

								if input_string[i] == input_string[j]:
												j += 1
								_lowerCAmelCase    :    Optional[int]										=      j

				return prefix_result




def 							_UpperCAmelCase  (UpperCamelCase_ : str       ):
				'''simple docstring'''
				return max(prefix_function(UpperCamelCase_       )       )


if __name__ == "__main__":
	import doctest

	doctest.testmod()

