






"""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	:				Any			,		__SCREAMING_SNAKE_CASE	:				str			,		__SCREAMING_SNAKE_CASE	:				List[str]=13			,		__SCREAMING_SNAKE_CASE	:				Dict=7			,		__SCREAMING_SNAKE_CASE	:				int=True			,		__SCREAMING_SNAKE_CASE	:				Optional[int]=True			,		__SCREAMING_SNAKE_CASE	:				Dict=True			,		__SCREAMING_SNAKE_CASE	:				Union[str, Any]=True			,		__SCREAMING_SNAKE_CASE	:				List[Any]=True			,		__SCREAMING_SNAKE_CASE	:				Optional[int]=False			,		__SCREAMING_SNAKE_CASE	:				List[Any]=False			,		__SCREAMING_SNAKE_CASE	:				Optional[int]=False			,		__SCREAMING_SNAKE_CASE	:				Any=2			,		__SCREAMING_SNAKE_CASE	:				Dict=99			,		__SCREAMING_SNAKE_CASE	:				List[str]=0			,		__SCREAMING_SNAKE_CASE	:				List[Any]=32			,		__SCREAMING_SNAKE_CASE	:				Dict=5			,		__SCREAMING_SNAKE_CASE	:				Tuple=4			,		__SCREAMING_SNAKE_CASE	:				str=0.1			,		__SCREAMING_SNAKE_CASE	:				Tuple=0.1			,		__SCREAMING_SNAKE_CASE	:				int=512			,		__SCREAMING_SNAKE_CASE	:				int=2			,		__SCREAMING_SNAKE_CASE	:				str=0.02			,		__SCREAMING_SNAKE_CASE	:				Union[str, Any]=2			,		__SCREAMING_SNAKE_CASE	:				int=4			,		__SCREAMING_SNAKE_CASE	:				List[Any]="last"			,		__SCREAMING_SNAKE_CASE	:				Optional[int]=True			,		__SCREAMING_SNAKE_CASE	:				List[Any]=None			,		__SCREAMING_SNAKE_CASE	:				Optional[int]=0			,		)	->						Any:
      lowerCamelCase_       	=		parent
      lowerCamelCase_       	=		batch_size
      lowerCamelCase_       	=		seq_length
      lowerCamelCase_       	=		is_training
      lowerCamelCase_       	=		use_input_lengths
      lowerCamelCase_       	=		use_token_type_ids
      lowerCamelCase_       	=		use_labels
      lowerCamelCase_       	=		gelu_activation
      lowerCamelCase_       	=		sinusoidal_embeddings
      lowerCamelCase_       	=		causal
      lowerCamelCase_       	=		asm
      lowerCamelCase_       	=		n_langs
      lowerCamelCase_       	=		vocab_size
      lowerCamelCase_       	=		n_special
      lowerCamelCase_       	=		hidden_size
      lowerCamelCase_       	=		num_hidden_layers
      lowerCamelCase_       	=		num_attention_heads
      lowerCamelCase_       	=		hidden_dropout_prob
      lowerCamelCase_       	=		attention_probs_dropout_prob
      lowerCamelCase_       	=		max_position_embeddings
      lowerCamelCase_       	=		type_sequence_label_size
      lowerCamelCase_       	=		initializer_range
      lowerCamelCase_       	=		num_labels
      lowerCamelCase_       	=		num_choices
      lowerCamelCase_       	=		summary_type
      lowerCamelCase_       	=		use_proj
      lowerCamelCase_       	=		scope
      lowerCamelCase_       	=		bos_token_id






    def   UpperCamelCase			(			self	:				List[Any]   )	->						List[Any]:
      lowerCamelCase_       	=		ids_tensor([self.batch_size, self.seq_length]			,		self.vocab_size   )
      lowerCamelCase_       	=		random_attention_mask([self.batch_size, self.seq_length]   )

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

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

      lowerCamelCase_       	=		None
      lowerCamelCase_       	=		None
      lowerCamelCase_       	=		None
      if self.use_labels:
        lowerCamelCase_       	=		ids_tensor([self.batch_size]			,		self.type_sequence_label_size   )
        lowerCamelCase_       	=		ids_tensor([self.batch_size, self.seq_length]			,		self.num_labels   )
        lowerCamelCase_       	=		ids_tensor([self.batch_size]			,		2   ).float()
        lowerCamelCase_       	=		ids_tensor([self.batch_size]			,		self.num_choices   )

      lowerCamelCase_       	=		self.get_config()

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






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






    def   UpperCamelCase			(			self	:				str			,		__SCREAMING_SNAKE_CASE	:				Any			,		__SCREAMING_SNAKE_CASE	:				Tuple			,		__SCREAMING_SNAKE_CASE	:				str			,		__SCREAMING_SNAKE_CASE	:				Optional[Any]			,		__SCREAMING_SNAKE_CASE	:				str			,		__SCREAMING_SNAKE_CASE	:				List[Any]			,		__SCREAMING_SNAKE_CASE	:				Union[str, Any]			,		__SCREAMING_SNAKE_CASE	:				str			,		__SCREAMING_SNAKE_CASE	:				str			,		)	->						Union[str, Any]:
      lowerCamelCase_       	=		XLMWithLMHeadModel(__SCREAMING_SNAKE_CASE   )
      model.to(__SCREAMING_SNAKE_CASE   )
      model.eval()

      lowerCamelCase_       	=		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   UpperCamelCase			(			self	:				Union[str, Any]			,		__SCREAMING_SNAKE_CASE	:				Any			,		__SCREAMING_SNAKE_CASE	:				Dict			,		__SCREAMING_SNAKE_CASE	:				Union[str, Any]			,		__SCREAMING_SNAKE_CASE	:				List[str]			,		__SCREAMING_SNAKE_CASE	:				List[Any]			,		__SCREAMING_SNAKE_CASE	:				List[str]			,		__SCREAMING_SNAKE_CASE	:				Optional[Any]			,		__SCREAMING_SNAKE_CASE	:				Dict			,		__SCREAMING_SNAKE_CASE	:				Optional[int]			,		)	->						Optional[int]:
      lowerCamelCase_       	=		XLMForQuestionAnsweringSimple(__SCREAMING_SNAKE_CASE   )
      model.to(__SCREAMING_SNAKE_CASE   )
      model.eval()

      lowerCamelCase_       	=		model(__SCREAMING_SNAKE_CASE   )

      lowerCamelCase_       	=		model(__SCREAMING_SNAKE_CASE			,		start_positions=__SCREAMING_SNAKE_CASE			,		end_positions=__SCREAMING_SNAKE_CASE   )
      lowerCamelCase_       	=		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   UpperCamelCase			(			self	:				Optional[Any]			,		__SCREAMING_SNAKE_CASE	:				List[str]			,		__SCREAMING_SNAKE_CASE	:				str			,		__SCREAMING_SNAKE_CASE	:				Dict			,		__SCREAMING_SNAKE_CASE	:				List[str]			,		__SCREAMING_SNAKE_CASE	:				str			,		__SCREAMING_SNAKE_CASE	:				int			,		__SCREAMING_SNAKE_CASE	:				List[str]			,		__SCREAMING_SNAKE_CASE	:				Optional[int]			,		__SCREAMING_SNAKE_CASE	:				Optional[Any]			,		)	->						int:
      lowerCamelCase_       	=		XLMForQuestionAnswering(__SCREAMING_SNAKE_CASE   )
      model.to(__SCREAMING_SNAKE_CASE   )
      model.eval()

      lowerCamelCase_       	=		model(__SCREAMING_SNAKE_CASE   )

      lowerCamelCase_       	=		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_       	=		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_)	,      )       	=		result_with_labels.to_tuple()

      lowerCamelCase_       	=		model(__SCREAMING_SNAKE_CASE			,		start_positions=__SCREAMING_SNAKE_CASE			,		end_positions=__SCREAMING_SNAKE_CASE   )

      ((lowerCamelCase_)	,      )       	=		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   UpperCamelCase			(			self	:				int			,		__SCREAMING_SNAKE_CASE	:				Dict			,		__SCREAMING_SNAKE_CASE	:				str			,		__SCREAMING_SNAKE_CASE	:				List[str]			,		__SCREAMING_SNAKE_CASE	:				str			,		__SCREAMING_SNAKE_CASE	:				Optional[Any]			,		__SCREAMING_SNAKE_CASE	:				Optional[Any]			,		__SCREAMING_SNAKE_CASE	:				Optional[Any]			,		__SCREAMING_SNAKE_CASE	:				Dict			,		__SCREAMING_SNAKE_CASE	:				Any			,		)	->						Union[str, Any]:
      lowerCamelCase_       	=		XLMForSequenceClassification(__SCREAMING_SNAKE_CASE   )
      model.to(__SCREAMING_SNAKE_CASE   )
      model.eval()

      lowerCamelCase_       	=		model(__SCREAMING_SNAKE_CASE   )
      lowerCamelCase_       	=		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   UpperCamelCase			(			self	:				int			,		__SCREAMING_SNAKE_CASE	:				List[str]			,		__SCREAMING_SNAKE_CASE	:				List[str]			,		__SCREAMING_SNAKE_CASE	:				str			,		__SCREAMING_SNAKE_CASE	:				Any			,		__SCREAMING_SNAKE_CASE	:				str			,		__SCREAMING_SNAKE_CASE	:				Dict			,		__SCREAMING_SNAKE_CASE	:				Dict			,		__SCREAMING_SNAKE_CASE	:				Tuple			,		__SCREAMING_SNAKE_CASE	:				str			,		)	->						Dict:
      lowerCamelCase_       	=		self.num_labels
      lowerCamelCase_       	=		XLMForTokenClassification(__SCREAMING_SNAKE_CASE   )
      model.to(__SCREAMING_SNAKE_CASE   )
      model.eval()

      lowerCamelCase_       	=		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   UpperCamelCase			(			self	:				str			,		__SCREAMING_SNAKE_CASE	:				Union[str, Any]			,		__SCREAMING_SNAKE_CASE	:				List[Any]			,		__SCREAMING_SNAKE_CASE	:				Union[str, Any]			,		__SCREAMING_SNAKE_CASE	:				Dict			,		__SCREAMING_SNAKE_CASE	:				Union[str, Any]			,		__SCREAMING_SNAKE_CASE	:				Any			,		__SCREAMING_SNAKE_CASE	:				List[str]			,		__SCREAMING_SNAKE_CASE	:				Optional[int]			,		__SCREAMING_SNAKE_CASE	:				List[Any]			,		)	->						Any:
      lowerCamelCase_       	=		self.num_choices
      lowerCamelCase_       	=		XLMForMultipleChoice(config=__SCREAMING_SNAKE_CASE   )
      model.to(__SCREAMING_SNAKE_CASE   )
      model.eval()
      lowerCamelCase_       	=		input_ids.unsqueeze(1   ).expand(-1			,		self.num_choices			,		-1   ).contiguous()
      lowerCamelCase_       	=		token_type_ids.unsqueeze(1   ).expand(-1			,		self.num_choices			,		-1   ).contiguous()
      lowerCamelCase_       	=		input_mask.unsqueeze(1   ).expand(-1			,		self.num_choices			,		-1   ).contiguous()
      lowerCamelCase_       	=		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   UpperCamelCase			(			self	:				Optional[Any]   )	->						Tuple:
      lowerCamelCase_       	=		self.prepare_config_and_inputs()
      (
          (
          lowerCamelCase_
      )	,      (
          lowerCamelCase_
      )	,      (
          lowerCamelCase_
      )	,      (
          lowerCamelCase_
      )	,      (
          lowerCamelCase_
      )	,      (
          lowerCamelCase_
      )	,      (
          lowerCamelCase_
      )	,      (
          lowerCamelCase_
      )	,      (
          lowerCamelCase_
      )	,      
      )       	=		config_and_inputs
      lowerCamelCase_       	=		{'input_ids': input_ids, 'token_type_ids': token_type_ids, 'lengths': input_lengths}
      return config, inputs_dict






@require_torch
class 	a		(   __snake_case    , __snake_case    , __snake_case    , unittest.TestCase						):
    SCREAMING_SNAKE_CASE		:	Any		=					(
        (
            XLMModel,
            XLMWithLMHeadModel,
            XLMForQuestionAnswering,
            XLMForSequenceClassification,
            XLMForQuestionAnsweringSimple,
            XLMForTokenClassification,
            XLMForMultipleChoice,
        )
        if is_torch_available()
        else ()
    )
    SCREAMING_SNAKE_CASE		:	Tuple		=					(
        (XLMWithLMHeadModel,) if is_torch_available() else ()
    )  # TODO (PVP): Check other models whether language generation is also applicable
    SCREAMING_SNAKE_CASE		:	int		=					(
        {
            """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   UpperCamelCase			(			self	:				Tuple			,		__SCREAMING_SNAKE_CASE	:				str			,		__SCREAMING_SNAKE_CASE	:				List[Any]			,		__SCREAMING_SNAKE_CASE	:				Tuple			,		__SCREAMING_SNAKE_CASE	:				Tuple			,		__SCREAMING_SNAKE_CASE	:				Tuple   )	->						Dict:
      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   UpperCamelCase			(			self	:				List[Any]			,		__SCREAMING_SNAKE_CASE	:				Union[str, Any]			,		__SCREAMING_SNAKE_CASE	:				int			,		__SCREAMING_SNAKE_CASE	:				Union[str, Any]=False   )	->						Optional[int]:
      lowerCamelCase_       	=		super()._prepare_for_class(__SCREAMING_SNAKE_CASE			,		__SCREAMING_SNAKE_CASE			,		return_labels=__SCREAMING_SNAKE_CASE   )

      if return_labels:
        if model_class.__name__ == "XLMForQuestionAnswering":
          lowerCamelCase_       	=		torch.zeros(
              self.model_tester.batch_size			,		dtype=torch.long			,		device=__SCREAMING_SNAKE_CASE   )
          lowerCamelCase_       	=		torch.zeros(
              self.model_tester.batch_size			,		dtype=torch.long			,		device=__SCREAMING_SNAKE_CASE   )

      return inputs_dict






    def   UpperCamelCase			(			self	:				Tuple   )	->						Optional[Any]:
      lowerCamelCase_       	=		XLMModelTester(self   )
      lowerCamelCase_       	=		ConfigTester(self			,		config_class=__SCREAMING_SNAKE_CASE			,		emb_dim=37   )






    def   UpperCamelCase			(			self	:				List[str]   )	->						Dict:
      self.config_tester.run_common_tests()






    def   UpperCamelCase			(			self	:				List[str]   )	->						Tuple:
      lowerCamelCase_       	=		self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_xlm_model(*__SCREAMING_SNAKE_CASE   )






    def   UpperCamelCase			(			self	:				Optional[int]   )	->						List[Any]:
      lowerCamelCase_       	=		self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_xlm_lm_head(*__SCREAMING_SNAKE_CASE   )






    def   UpperCamelCase			(			self	:				Union[str, Any]   )	->						Optional[int]:
      lowerCamelCase_       	=		self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_xlm_simple_qa(*__SCREAMING_SNAKE_CASE   )






    def   UpperCamelCase			(			self	:				List[str]   )	->						Any:
      lowerCamelCase_       	=		self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_xlm_qa(*__SCREAMING_SNAKE_CASE   )






    def   UpperCamelCase			(			self	:				Union[str, Any]   )	->						Any:
      lowerCamelCase_       	=		self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_xlm_sequence_classif(*__SCREAMING_SNAKE_CASE   )






    def   UpperCamelCase			(			self	:				Union[str, Any]   )	->						Union[str, Any]:
      lowerCamelCase_       	=		self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_xlm_token_classif(*__SCREAMING_SNAKE_CASE   )






    def   UpperCamelCase			(			self	:				str   )	->						Any:
      lowerCamelCase_       	=		self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_xlm_for_multiple_choice(*__SCREAMING_SNAKE_CASE   )






    def   UpperCamelCase			(			self	:				Optional[int]			,		__SCREAMING_SNAKE_CASE	:				List[Any]			,		__SCREAMING_SNAKE_CASE	:				Union[str, Any]			,		__SCREAMING_SNAKE_CASE	:				Union[str, Any]			,		__SCREAMING_SNAKE_CASE	:				List[str]			,		__SCREAMING_SNAKE_CASE	:				Tuple			,		__SCREAMING_SNAKE_CASE	:				Optional[Any]=False			,		__SCREAMING_SNAKE_CASE	:				List[str]=1   )	->						List[Any]:
      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_       	=		min_length + idx + 1
        lowerCamelCase_       	=		min_length + idx + 1

        lowerCamelCase_       	=		(
            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   UpperCamelCase			(			self	:				str			,		__SCREAMING_SNAKE_CASE	:				str			,		__SCREAMING_SNAKE_CASE	:				List[Any]			,		__SCREAMING_SNAKE_CASE	:				Dict			,		__SCREAMING_SNAKE_CASE	:				List[str]			,		__SCREAMING_SNAKE_CASE	:				int			,		__SCREAMING_SNAKE_CASE	:				List[str]=False			,		__SCREAMING_SNAKE_CASE	:				Any=1   )	->						Any:
      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_       	=		min_length + idx + 1
        lowerCamelCase_       	=		(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   UpperCamelCase			(			self	:				Dict   )	->						Tuple:
      for model_name in XLM_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
        lowerCamelCase_       	=		XLMModel.from_pretrained(__SCREAMING_SNAKE_CASE   )
        self.assertIsNotNone(__SCREAMING_SNAKE_CASE   )






@require_torch
class 	a		(   unittest.TestCase						):






    @slow
    def   UpperCamelCase			(			self	:				Any   )	->						List[Any]:
      lowerCamelCase_       	=		XLMWithLMHeadModel.from_pretrained('xlm-mlm-en-2048'   )
      model.to(__SCREAMING_SNAKE_CASE   )
      lowerCamelCase_       	=		torch.tensor([[14, 447]]			,		dtype=torch.long			,		device=__SCREAMING_SNAKE_CASE   )  # the president
      lowerCamelCase_       	=		[
          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_       	=		model.generate(__SCREAMING_SNAKE_CASE			,		do_sample=__SCREAMING_SNAKE_CASE   )
      self.assertListEqual(output_ids[0].cpu().numpy().tolist()			,		__SCREAMING_SNAKE_CASE   )












"""simple docstring"""





def 	lowerCamelCase__			(				_lowerCamelCase			:						int = 10						,							_lowerCamelCase			:						int = 1000						,							_lowerCamelCase			:						bool = True					) ->							int:
  assert (
      isinstance(_lowerCamelCase						,							_lowerCamelCase					)
      and isinstance(_lowerCamelCase						,							_lowerCamelCase					)
      and isinstance(_lowerCamelCase						,							_lowerCamelCase					)
  ), "Invalid type of value(s) specified to function!"

  if min_val > max_val:
    raise ValueError('Invalid value for min_val or max_val (min_value < max_value)'					)
  return min_val if option else max_val







def 	lowerCamelCase__			(				_lowerCamelCase			:						int						,							_lowerCamelCase			:						int					) ->							int:
  return int((number_a + number_a) / 2					)







def 	lowerCamelCase__			(				_lowerCamelCase			:						int						,							_lowerCamelCase			:						int						,							_lowerCamelCase			:						int					) ->							None:
  assert (
      isinstance(_lowerCamelCase						,							_lowerCamelCase					) and isinstance(_lowerCamelCase						,							_lowerCamelCase					) and isinstance(_lowerCamelCase						,							_lowerCamelCase					)
  ), 'argument values must be type of "int"'

  if lower > higher:
    raise ValueError('argument value for lower and higher must be(lower > higher)'					)

  if not lower < to_guess < higher:
    raise ValueError(
        'guess value must be within the range of lower and higher value'					)

  def answer(_lowerCamelCase			:						int					) -> str:
    if number > to_guess:
      return "high"
    elif number < to_guess:
      return "low"
    else:
      return "same"

  print('started...'					)

  lowerCamelCase_       	=		lower
  lowerCamelCase_       	=		higher

  lowerCamelCase_       	=		[]

  while True:
    lowerCamelCase_       	=		get_avg(_lowerCamelCase						,							_lowerCamelCase					)
    last_numbers.append(_lowerCamelCase					)

    if answer(_lowerCamelCase					) == "low":
      lowerCamelCase_       	=		number
    elif answer(_lowerCamelCase					) == "high":
      lowerCamelCase_       	=		number
    else:
      break

  print(F'''guess the number : {last_numbers[-1]}'''					)
  print(F'''details : {last_numbers!s}'''					)







def 	lowerCamelCase__			(				) ->							None:
  lowerCamelCase_       	=		int(input('Enter lower value : '					).strip()					)
  lowerCamelCase_       	=		int(input('Enter high value : '					).strip()					)
  lowerCamelCase_       	=		int(input('Enter value to guess : '					).strip()					)
  guess_the_number(_lowerCamelCase						,							_lowerCamelCase						,							_lowerCamelCase					)


if __name__ == "__main__":
  main()




