



'''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 						lowerCamelCase_				:







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

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







						def        __lowercase     (	self :   str					):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE       :   int         =      ids_tensor([self.batch_size, self.seq_length]					,     self.vocab_size					)
													SCREAMING_SNAKE_CASE       :   List[Any]         =      random_attention_mask([self.batch_size, self.seq_length]					)

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

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

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

													SCREAMING_SNAKE_CASE       :   Optional[int]         =      self.get_config()

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







						def        __lowercase     (	self :   Dict					):

													"""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        __lowercase     (	self :   str					,     lowerCAmelCase__ :   int					,     lowerCAmelCase__ :   Optional[Any]					,     lowerCAmelCase__ :   Union[str, Any]					,     lowerCAmelCase__ :   Union[str, Any]					,     lowerCAmelCase__ :   Dict					,     lowerCAmelCase__ :   Union[str, Any]					,     lowerCAmelCase__ :   Union[str, Any]					,     lowerCAmelCase__ :   Optional[Any]					,     lowerCAmelCase__ :   int					,     ):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE       :   Any         =      XLMModel(config=lowerCAmelCase__					)
													model.to(lowerCAmelCase__					)
													model.eval()
													SCREAMING_SNAKE_CASE       :   Any         =      model(lowerCAmelCase__					,     lengths=lowerCAmelCase__					,     langs=lowerCAmelCase__					)
													SCREAMING_SNAKE_CASE       :   str         =      model(lowerCAmelCase__					,     langs=lowerCAmelCase__					)
													SCREAMING_SNAKE_CASE       :   Union[str, Any]         =      model(lowerCAmelCase__					)
													self.parent.assertEqual(result.last_hidden_state.shape					,     (self.batch_size, self.seq_length, self.hidden_size)					)







						def        __lowercase     (	self :   Union[str, Any]					,     lowerCAmelCase__ :   Dict					,     lowerCAmelCase__ :   Tuple					,     lowerCAmelCase__ :   Optional[int]					,     lowerCAmelCase__ :   Any					,     lowerCAmelCase__ :   Any					,     lowerCAmelCase__ :   Tuple					,     lowerCAmelCase__ :   List[Any]					,     lowerCAmelCase__ :   Optional[int]					,     lowerCAmelCase__ :   Optional[int]					,     ):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE       :   str         =      XLMWithLMHeadModel(lowerCAmelCase__					)
													model.to(lowerCAmelCase__					)
													model.eval()

													SCREAMING_SNAKE_CASE       :   Any         =      model(lowerCAmelCase__					,     token_type_ids=lowerCAmelCase__					,     labels=lowerCAmelCase__					)
													self.parent.assertEqual(result.loss.shape					,     ()					)
													self.parent.assertEqual(result.logits.shape					,     (self.batch_size, self.seq_length, self.vocab_size)					)







						def        __lowercase     (	self :   Tuple					,     lowerCAmelCase__ :   Dict					,     lowerCAmelCase__ :   List[Any]					,     lowerCAmelCase__ :   List[Any]					,     lowerCAmelCase__ :   Any					,     lowerCAmelCase__ :   Any					,     lowerCAmelCase__ :   Dict					,     lowerCAmelCase__ :   Tuple					,     lowerCAmelCase__ :   Union[str, Any]					,     lowerCAmelCase__ :   Optional[int]					,     ):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE       :   Optional[int]         =      XLMForQuestionAnsweringSimple(lowerCAmelCase__					)
													model.to(lowerCAmelCase__					)
													model.eval()

													SCREAMING_SNAKE_CASE       :   str         =      model(lowerCAmelCase__					)

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

													"""simple docstring"""
													SCREAMING_SNAKE_CASE       :   str         =      XLMForQuestionAnswering(lowerCAmelCase__					)
													model.to(lowerCAmelCase__					)
													model.eval()

													SCREAMING_SNAKE_CASE       :   Optional[Any]         =      model(lowerCAmelCase__					)

													SCREAMING_SNAKE_CASE       :   Optional[Any]         =      model(
													    lowerCAmelCase__					,     start_positions=lowerCAmelCase__					,     end_positions=lowerCAmelCase__					,     cls_index=lowerCAmelCase__					,     is_impossible=lowerCAmelCase__					,     p_mask=lowerCAmelCase__					,     )

													SCREAMING_SNAKE_CASE       :   Optional[int]         =      model(
													    lowerCAmelCase__					,     start_positions=lowerCAmelCase__					,     end_positions=lowerCAmelCase__					,     cls_index=lowerCAmelCase__					,     is_impossible=lowerCAmelCase__					,     )

													((SCREAMING_SNAKE_CASE)       ,)       :   Any         =      result_with_labels.to_tuple()

													SCREAMING_SNAKE_CASE       :   List[Any]         =      model(lowerCAmelCase__					,     start_positions=lowerCAmelCase__					,     end_positions=lowerCAmelCase__					)

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

													"""simple docstring"""
													SCREAMING_SNAKE_CASE       :   Dict         =      XLMForSequenceClassification(lowerCAmelCase__					)
													model.to(lowerCAmelCase__					)
													model.eval()

													SCREAMING_SNAKE_CASE       :   str         =      model(lowerCAmelCase__					)
													SCREAMING_SNAKE_CASE       :   Any         =      model(lowerCAmelCase__					,     labels=lowerCAmelCase__					)
													self.parent.assertEqual(result.loss.shape					,     ()					)
													self.parent.assertEqual(result.logits.shape					,     (self.batch_size, self.type_sequence_label_size)					)







						def        __lowercase     (	self :   int					,     lowerCAmelCase__ :   List[str]					,     lowerCAmelCase__ :   List[Any]					,     lowerCAmelCase__ :   Optional[int]					,     lowerCAmelCase__ :   List[str]					,     lowerCAmelCase__ :   Tuple					,     lowerCAmelCase__ :   str					,     lowerCAmelCase__ :   List[Any]					,     lowerCAmelCase__ :   Tuple					,     lowerCAmelCase__ :   Dict					,     ):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE       :   Union[str, Any]         =      self.num_labels
													SCREAMING_SNAKE_CASE       :   Any         =      XLMForTokenClassification(lowerCAmelCase__					)
													model.to(lowerCAmelCase__					)
													model.eval()

													SCREAMING_SNAKE_CASE       :   Union[str, Any]         =      model(lowerCAmelCase__					,     attention_mask=lowerCAmelCase__					,     labels=lowerCAmelCase__					)
													self.parent.assertEqual(result.logits.shape					,     (self.batch_size, self.seq_length, self.num_labels)					)







						def        __lowercase     (	self :   Union[str, Any]					,     lowerCAmelCase__ :   List[str]					,     lowerCAmelCase__ :   Optional[int]					,     lowerCAmelCase__ :   Any					,     lowerCAmelCase__ :   int					,     lowerCAmelCase__ :   str					,     lowerCAmelCase__ :   Optional[Any]					,     lowerCAmelCase__ :   Any					,     lowerCAmelCase__ :   Union[str, Any]					,     lowerCAmelCase__ :   Optional[Any]					,     ):

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







						def        __lowercase     (	self :   int					):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE       :   Tuple         =      self.prepare_config_and_inputs()
													(
													    (
													    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
													)       ,
													)       :   Tuple         =      config_and_inputs
													SCREAMING_SNAKE_CASE       :   str         =      {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''lengths''': input_lengths}
													return config, inputs_dict


@require_torch
class 						lowerCamelCase_				(       snake_case_     ,					snake_case_     ,					snake_case_     ,					unittest.TestCase      ):
						_lowerCAmelCase  : List[str]						  =					(
						    (
						        XLMModel,
						        XLMWithLMHeadModel,
						        XLMForQuestionAnswering,
						        XLMForSequenceClassification,
						        XLMForQuestionAnsweringSimple,
						        XLMForTokenClassification,
						        XLMForMultipleChoice,
						    )
						    if is_torch_available()
						    else ()
						)
						_lowerCAmelCase  : List[str]						  =					(
						    (XLMWithLMHeadModel,) if is_torch_available() else ()
						)  # TODO (PVP): Check other models whether language generation is also applicable
						_lowerCAmelCase  : 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        __lowercase     (	self :   Optional[int]					,     lowerCAmelCase__ :   Union[str, Any]					,     lowerCAmelCase__ :   Dict					,     lowerCAmelCase__ :   Any					,     lowerCAmelCase__ :   Optional[Any]					,     lowerCAmelCase__ :   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        __lowercase     (	self :   List[Any]					,     lowerCAmelCase__ :   str					,     lowerCAmelCase__ :   Optional[int]					,     lowerCAmelCase__ :   Tuple=False					):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE       :   Optional[Any]         =      super()._prepare_for_class(lowerCAmelCase__					,     lowerCAmelCase__					,     return_labels=lowerCAmelCase__					)

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

													return inputs_dict







						def        __lowercase     (	self :   Dict					):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE       :   Any         =      XLMModelTester(self					)
													SCREAMING_SNAKE_CASE       :   Optional[int]         =      ConfigTester(self					,     config_class=lowerCAmelCase__					,     emb_dim=37					)







						def        __lowercase     (	self :   Dict					):

													"""simple docstring"""
													self.config_tester.run_common_tests()







						def        __lowercase     (	self :   Dict					):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE       :   Union[str, Any]         =      self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_xlm_model(*lowerCAmelCase__					)







						def        __lowercase     (	self :   int					):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE       :   Any         =      self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_xlm_lm_head(*lowerCAmelCase__					)







						def        __lowercase     (	self :   Optional[Any]					):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE       :   List[str]         =      self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_xlm_simple_qa(*lowerCAmelCase__					)







						def        __lowercase     (	self :   List[str]					):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE       :   Optional[Any]         =      self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_xlm_qa(*lowerCAmelCase__					)







						def        __lowercase     (	self :   str					):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE       :   str         =      self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_xlm_sequence_classif(*lowerCAmelCase__					)







						def        __lowercase     (	self :   Dict					):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE       :   Dict         =      self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_xlm_token_classif(*lowerCAmelCase__					)







						def        __lowercase     (	self :   Tuple					):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE       :   Optional[int]         =      self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_xlm_for_multiple_choice(*lowerCAmelCase__					)







						def        __lowercase     (	self :   Union[str, Any]					,     lowerCAmelCase__ :   Optional[Any]					,     lowerCAmelCase__ :   List[str]					,     lowerCAmelCase__ :   Dict					,     lowerCAmelCase__ :   str					,     lowerCAmelCase__ :   List[str]					,     lowerCAmelCase__ :   List[str]=False					,     lowerCAmelCase__ :   List[Any]=1					):

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

													for idx, iter_attentions in enumerate(lowerCAmelCase__					):
																				# adds PAD dummy token
																				SCREAMING_SNAKE_CASE       :   Optional[Any]         =      min_length + idx + 1
																				SCREAMING_SNAKE_CASE       :   Union[str, Any]         =      min_length + idx + 1

																				SCREAMING_SNAKE_CASE       :   str         =      (
																				    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(lowerCAmelCase__					)					)







						def        __lowercase     (	self :   List[str]					,     lowerCAmelCase__ :   str					,     lowerCAmelCase__ :   Tuple					,     lowerCAmelCase__ :   Any					,     lowerCAmelCase__ :   Any					,     lowerCAmelCase__ :   str					,     lowerCAmelCase__ :   List[str]=False					,     lowerCAmelCase__ :   List[Any]=1					):

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

													for idx, iter_hidden_states in enumerate(lowerCAmelCase__					):
																				# adds PAD dummy token
																				SCREAMING_SNAKE_CASE       :   Optional[int]         =      min_length + idx + 1
																				SCREAMING_SNAKE_CASE       :   List[Any]         =      (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(lowerCAmelCase__					)					,     )
													pass







						@slow
						def        __lowercase     (	self :   Optional[Any]					):

													"""simple docstring"""
													for model_name in XLM_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																				SCREAMING_SNAKE_CASE       :   List[Any]         =      XLMModel.from_pretrained(lowerCAmelCase__					)
																				self.assertIsNotNone(lowerCAmelCase__					)


@require_torch
class 						lowerCamelCase_				(       unittest.TestCase      ):







						@slow
						def        __lowercase     (	self :   int					):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE       :   Optional[int]         =      XLMWithLMHeadModel.from_pretrained('''xlm-mlm-en-2048'''					)
													model.to(lowerCAmelCase__					)
													SCREAMING_SNAKE_CASE       :   int         =      torch.tensor([[14, 4_47]]					,     dtype=torch.long					,     device=lowerCAmelCase__					)  # the president
													SCREAMING_SNAKE_CASE       :   Tuple         =      [
													    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
													SCREAMING_SNAKE_CASE       :   int         =      model.generate(lowerCAmelCase__					,     do_sample=lowerCAmelCase__					)
													self.assertListEqual(output_ids[0].cpu().numpy().tolist()					,     lowerCAmelCase__					)









'''simple docstring'''



def        UpperCAmelCase (    A	:					int					):
							if not isinstance(A       ,		A					):
														SCREAMING_SNAKE_CASE       :   List[str]         =      F"""Input value of [number={number}] must be an integer"""
														raise TypeError(A					)
							if number < 0:
														return False
							SCREAMING_SNAKE_CASE       :   List[str]         =      number * number
							while number > 0:
														if number % 10 != number_square % 10:
																					return False
														number //= 10
														number_square //= 10
							return True


if __name__ == "__main__":
							import doctest

							doctest.testmod()




