


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 			SCREAMING_SNAKE_CASE__  :
      def __init__(	self    :	Optional[int]					,							SCREAMING_SNAKE_CASE__    :	Any					,							SCREAMING_SNAKE_CASE__    :	int=1_3					,							SCREAMING_SNAKE_CASE__    :	List[str]=7					,							SCREAMING_SNAKE_CASE__    :	str=True					,							SCREAMING_SNAKE_CASE__    :	Optional[Any]=True					,							SCREAMING_SNAKE_CASE__    :	int=True					,							SCREAMING_SNAKE_CASE__    :	Tuple=True					,							SCREAMING_SNAKE_CASE__    :	int=True					,							SCREAMING_SNAKE_CASE__    :	List[Any]=False					,							SCREAMING_SNAKE_CASE__    :	List[Any]=False					,							SCREAMING_SNAKE_CASE__    :	Optional[Any]=False					,							SCREAMING_SNAKE_CASE__    :	int=2					,							SCREAMING_SNAKE_CASE__    :	Union[str, Any]=9_9					,							SCREAMING_SNAKE_CASE__    :	Dict=0					,							SCREAMING_SNAKE_CASE__    :	List[str]=3_2					,							SCREAMING_SNAKE_CASE__    :	Dict=5					,							SCREAMING_SNAKE_CASE__    :	Tuple=4					,							SCREAMING_SNAKE_CASE__    :	Dict=0.1					,							SCREAMING_SNAKE_CASE__    :	Dict=0.1					,							SCREAMING_SNAKE_CASE__    :	str=5_1_2					,							SCREAMING_SNAKE_CASE__    :	Any=2					,							SCREAMING_SNAKE_CASE__    :	Any=0.02					,							SCREAMING_SNAKE_CASE__    :	Tuple=2					,							SCREAMING_SNAKE_CASE__    :	Optional[Any]=4					,							SCREAMING_SNAKE_CASE__    :	List[Any]="last"					,							SCREAMING_SNAKE_CASE__    :	List[str]=True					,							SCREAMING_SNAKE_CASE__    :	Union[str, Any]=None					,							SCREAMING_SNAKE_CASE__    :	List[str]=0					,							)		->      List[str]:
             a_ :		List[Any]							=  parent
             a_ :		int							=  batch_size
             a_ :		Union[str, Any]							=  seq_length
             a_ :		Union[str, Any]							=  is_training
             a_ :		Optional[int]							=  use_input_lengths
             a_ :		List[Any]							=  use_token_type_ids
             a_ :		str							=  use_labels
             a_ :		List[str]							=  gelu_activation
             a_ :		Tuple							=  sinusoidal_embeddings
             a_ :		Optional[Any]							=  causal
             a_ :		Union[str, Any]							=  asm
             a_ :		Dict							=  n_langs
             a_ :		Tuple							=  vocab_size
             a_ :		Optional[int]							=  n_special
             a_ :		Optional[Any]							=  hidden_size
             a_ :		int							=  num_hidden_layers
             a_ :		int							=  num_attention_heads
             a_ :		int							=  hidden_dropout_prob
             a_ :		Dict							=  attention_probs_dropout_prob
             a_ :		int							=  max_position_embeddings
             a_ :		Dict							=  type_sequence_label_size
             a_ :		List[Any]							=  initializer_range
             a_ :		List[Any]							=  num_labels
             a_ :		Dict							=  num_choices
             a_ :		Optional[int]							=  summary_type
             a_ :		int							=  use_proj
             a_ :		Dict							=  scope
             a_ :		Any							=  bos_token_id
      def 	SCREAMING_SNAKE_CASE							(	self    :	Tuple					)		->      Optional[int]:
             a_ :		int							=  ids_tensor([self.batch_size, self.seq_length]					,							self.vocab_size					)
             a_ :		Optional[int]							=  random_attention_mask([self.batch_size, self.seq_length]					)

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

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

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

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

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

             a_ :		int							=  model(SCREAMING_SNAKE_CASE__					)

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

             a_ :		Optional[int]							=  model(SCREAMING_SNAKE_CASE__					)

             a_ :		Optional[int]							=  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__					,							)

             a_ :		Optional[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__					,							)

             ((a_)							,		) :		Dict							=  result_with_labels.to_tuple()

             a_ :		str							=  model(SCREAMING_SNAKE_CASE__					,							start_positions=SCREAMING_SNAKE_CASE__					,							end_positions=SCREAMING_SNAKE_CASE__					)

             ((a_)							,		) :		List[str]							=  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    :	Optional[int]					,							SCREAMING_SNAKE_CASE__    :	List[Any]					,							SCREAMING_SNAKE_CASE__    :	List[Any]					,							SCREAMING_SNAKE_CASE__    :	str					,							SCREAMING_SNAKE_CASE__    :	int					,							SCREAMING_SNAKE_CASE__    :	Any					,							SCREAMING_SNAKE_CASE__    :	Dict					,							SCREAMING_SNAKE_CASE__    :	List[Any]					,							SCREAMING_SNAKE_CASE__    :	Tuple					,							SCREAMING_SNAKE_CASE__    :	List[Any]					,							)		->      int:
             a_ :		str							=  XLMForSequenceClassification(SCREAMING_SNAKE_CASE__					)
             model.to(SCREAMING_SNAKE_CASE__					)
             model.eval()

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

             a_ :		Tuple							=  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 	SCREAMING_SNAKE_CASE							(	self    :	str					,							SCREAMING_SNAKE_CASE__    :	int					,							SCREAMING_SNAKE_CASE__    :	List[str]					,							SCREAMING_SNAKE_CASE__    :	List[Any]					,							SCREAMING_SNAKE_CASE__    :	List[str]					,							SCREAMING_SNAKE_CASE__    :	Optional[int]					,							SCREAMING_SNAKE_CASE__    :	Optional[int]					,							SCREAMING_SNAKE_CASE__    :	Dict					,							SCREAMING_SNAKE_CASE__    :	Dict					,							SCREAMING_SNAKE_CASE__    :	Optional[int]					,							)		->      Union[str, Any]:
             a_ :		List[Any]							=  self.num_choices
             a_ :		Optional[int]							=  XLMForMultipleChoice(config=SCREAMING_SNAKE_CASE__					)
             model.to(SCREAMING_SNAKE_CASE__					)
             model.eval()
             a_ :		Optional[Any]							=  input_ids.unsqueeze(1					).expand(-1					,							self.num_choices					,							-1					).contiguous()
             a_ :		List[str]							=  token_type_ids.unsqueeze(1					).expand(-1					,							self.num_choices					,							-1					).contiguous()
             a_ :		int							=  input_mask.unsqueeze(1					).expand(-1					,							self.num_choices					,							-1					).contiguous()
             a_ :		List[str]							=  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 	SCREAMING_SNAKE_CASE							(	self    :	Optional[int]					)		->      Any:
             a_ :		List[Any]							=  self.prepare_config_and_inputs()
             (
                 (
                 a_
             )							,		(
                 a_
             )							,		(
                 a_
             )							,		(
                 a_
             )							,		(
                 a_
             )							,		(
                 a_
             )							,		(
                 a_
             )							,		(
                 a_
             )							,		(
                 a_
             )							,		
             ) :		Tuple							=  config_and_inputs
             a_ :		Optional[Any]							=  {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'lengths': input_lengths}
             return config, inputs_dict
@require_torch
class 			SCREAMING_SNAKE_CASE__  (    lowercase__						,   lowercase__						,   lowercase__						,   unittest.TestCase      ):
      snake_case__    :					int					       =						(
          (
              XLMModel,
              XLMWithLMHeadModel,
              XLMForQuestionAnswering,
              XLMForSequenceClassification,
              XLMForQuestionAnsweringSimple,
              XLMForTokenClassification,
              XLMForMultipleChoice,
          )
          if is_torch_available()
          else ()
      )
      snake_case__    :					Optional[int]					       =						(
          (XLMWithLMHeadModel,) if is_torch_available() else ()
      )  # TODO (PVP): Check other models whether language generation is also applicable
      snake_case__    :					List[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 	SCREAMING_SNAKE_CASE							(	self    :	Tuple					,							SCREAMING_SNAKE_CASE__    :	List[Any]					,							SCREAMING_SNAKE_CASE__    :	Tuple					,							SCREAMING_SNAKE_CASE__    :	Any					,							SCREAMING_SNAKE_CASE__    :	List[str]					,							SCREAMING_SNAKE_CASE__    :	Optional[Any]					)		->      Union[str, Any]:
             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    :	Dict					,							SCREAMING_SNAKE_CASE__    :	Tuple					,							SCREAMING_SNAKE_CASE__    :	List[str]					,							SCREAMING_SNAKE_CASE__    :	List[Any]=False					)		->      List[Any]:
             a_ :		Optional[Any]							=  super()._prepare_for_class(SCREAMING_SNAKE_CASE__					,							SCREAMING_SNAKE_CASE__					,							return_labels=SCREAMING_SNAKE_CASE__					)

             if return_labels:
                    if model_class.__name__ == "XLMForQuestionAnswering":
                           a_ :		Any							=  torch.zeros(
                               self.model_tester.batch_size					,							dtype=torch.long					,							device=SCREAMING_SNAKE_CASE__					)
                           a_ :		Optional[Any]							=  torch.zeros(
                               self.model_tester.batch_size					,							dtype=torch.long					,							device=SCREAMING_SNAKE_CASE__					)

             return inputs_dict
      def 	SCREAMING_SNAKE_CASE							(	self    :	str					)		->      Any:
             a_ :		Any							=  XLMModelTester(self					)
             a_ :		List[str]							=  ConfigTester(self					,							config_class=SCREAMING_SNAKE_CASE__					,							emb_dim=3_7					)
      def 	SCREAMING_SNAKE_CASE							(	self    :	str					)		->      List[Any]:
             self.config_tester.run_common_tests()
      def 	SCREAMING_SNAKE_CASE							(	self    :	Optional[int]					)		->      List[str]:
             a_ :		Union[str, Any]							=  self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_xlm_model(*SCREAMING_SNAKE_CASE__					)
      def 	SCREAMING_SNAKE_CASE							(	self    :	Optional[Any]					)		->      int:
             a_ :		Union[str, Any]							=  self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_xlm_lm_head(*SCREAMING_SNAKE_CASE__					)
      def 	SCREAMING_SNAKE_CASE							(	self    :	str					)		->      str:
             a_ :		List[Any]							=  self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_xlm_simple_qa(*SCREAMING_SNAKE_CASE__					)
      def 	SCREAMING_SNAKE_CASE							(	self    :	List[str]					)		->      str:
             a_ :		List[str]							=  self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_xlm_qa(*SCREAMING_SNAKE_CASE__					)
      def 	SCREAMING_SNAKE_CASE							(	self    :	Tuple					)		->      int:
             a_ :		Optional[int]							=  self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_xlm_sequence_classif(*SCREAMING_SNAKE_CASE__					)
      def 	SCREAMING_SNAKE_CASE							(	self    :	Optional[int]					)		->      int:
             a_ :		List[str]							=  self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_xlm_token_classif(*SCREAMING_SNAKE_CASE__					)
      def 	SCREAMING_SNAKE_CASE							(	self    :	Tuple					)		->      List[Any]:
             a_ :		List[str]							=  self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_xlm_for_multiple_choice(*SCREAMING_SNAKE_CASE__					)
      def 	SCREAMING_SNAKE_CASE							(	self    :	Tuple					,							SCREAMING_SNAKE_CASE__    :	Dict					,							SCREAMING_SNAKE_CASE__    :	Optional[int]					,							SCREAMING_SNAKE_CASE__    :	Dict					,							SCREAMING_SNAKE_CASE__    :	Optional[int]					,							SCREAMING_SNAKE_CASE__    :	Optional[int]					,							SCREAMING_SNAKE_CASE__    :	Optional[int]=False					,							SCREAMING_SNAKE_CASE__    :	int=1					)		->      int:
             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
                    a_ :		int							=  min_length + idx + 1
                    a_ :		str							=  min_length + idx + 1

                    a_ :		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 	SCREAMING_SNAKE_CASE							(	self    :	Optional[int]					,							SCREAMING_SNAKE_CASE__    :	Tuple					,							SCREAMING_SNAKE_CASE__    :	Optional[Any]					,							SCREAMING_SNAKE_CASE__    :	Any					,							SCREAMING_SNAKE_CASE__    :	str					,							SCREAMING_SNAKE_CASE__    :	Optional[int]					,							SCREAMING_SNAKE_CASE__    :	int=False					,							SCREAMING_SNAKE_CASE__    :	Any=1					)		->      int:
             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
                    a_ :		List[str]							=  min_length + idx + 1
                    a_ :		Dict							=  (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 	SCREAMING_SNAKE_CASE							(	self    :	Optional[int]					)		->      int:
             for model_name in XLM_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                    a_ :		List[Any]							=  XLMModel.from_pretrained(SCREAMING_SNAKE_CASE__					)
                    self.assertIsNotNone(SCREAMING_SNAKE_CASE__					)
@require_torch
class 			SCREAMING_SNAKE_CASE__  (    unittest.TestCase      ):
      @slow
      def 	SCREAMING_SNAKE_CASE							(	self    :	str					)		->      Dict:
             a_ :		Tuple							=  XLMWithLMHeadModel.from_pretrained('xlm-mlm-en-2048'					)
             model.to(SCREAMING_SNAKE_CASE__					)
             a_ :		Optional[Any]							=  torch.tensor([[1_4, 4_4_7]]					,							dtype=torch.long					,							device=SCREAMING_SNAKE_CASE__					)  # the president
             a_ :		List[str]							=  [
                 1_4,
                 4_4_7,
                 1_4,
                 4_4_7,
                 1_4,
                 4_4_7,
                 1_4,
                 4_4_7,
                 1_4,
                 4_4_7,
                 1_4,
                 4_4_7,
                 1_4,
                 4_4_7,
                 1_4,
                 4_4_7,
                 1_4,
                 4_4_7,
                 1_4,
                 4_4_7,
             ]  # 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
             a_ :		Dict							=  model.generate(SCREAMING_SNAKE_CASE__					,							do_sample=SCREAMING_SNAKE_CASE__					)
             self.assertListEqual(output_ids[0].cpu().numpy().tolist()					,							SCREAMING_SNAKE_CASE__					)






def 	SCREAMING_SNAKE_CASE_						(      __A			:      int  ,   __A			:      int    )     ->		int:

       """simple docstring"""

       while b:
              a_							,		a_ :		int							=  b, a % b
       return a







def 	SCREAMING_SNAKE_CASE_						(      __A			:      int  ,   __A			:      int    )     ->		int:

       """simple docstring"""

       return a if b == 0 else euclidean_gcd_recursive(__A  ,   a % b    )







def 	SCREAMING_SNAKE_CASE_						(      )     ->		str:

       """simple docstring"""

       print(F"""euclidean_gcd(3, 5) = {euclidean_gcd(3  ,   5    )}"""    )
       print(F"""euclidean_gcd(5, 3) = {euclidean_gcd(5  ,   3    )}"""    )
       print(F"""euclidean_gcd(1, 3) = {euclidean_gcd(1  ,   3    )}"""    )
       print(F"""euclidean_gcd(3, 6) = {euclidean_gcd(3  ,   6    )}"""    )
       print(F"""euclidean_gcd(6, 3) = {euclidean_gcd(6  ,   3    )}"""    )

       print(F"""euclidean_gcd_recursive(3, 5) = {euclidean_gcd_recursive(3  ,   5    )}"""    )
       print(F"""euclidean_gcd_recursive(5, 3) = {euclidean_gcd_recursive(5  ,   3    )}"""    )
       print(F"""euclidean_gcd_recursive(1, 3) = {euclidean_gcd_recursive(1  ,   3    )}"""    )
       print(F"""euclidean_gcd_recursive(3, 6) = {euclidean_gcd_recursive(3  ,   6    )}"""    )
       print(F"""euclidean_gcd_recursive(6, 3) = {euclidean_gcd_recursive(6  ,   3    )}"""    )


if __name__ == "__main__":
   main()


