





"""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  _SCREAMING_SNAKE_CASE:




       def __init__(						self		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__=13		,SCREAMING_SNAKE_CASE__=7		,SCREAMING_SNAKE_CASE__=True		,SCREAMING_SNAKE_CASE__=True		,SCREAMING_SNAKE_CASE__=True		,SCREAMING_SNAKE_CASE__=True		,SCREAMING_SNAKE_CASE__=True		,SCREAMING_SNAKE_CASE__=False		,SCREAMING_SNAKE_CASE__=False		,SCREAMING_SNAKE_CASE__=False		,SCREAMING_SNAKE_CASE__=2		,SCREAMING_SNAKE_CASE__=99		,SCREAMING_SNAKE_CASE__=0		,SCREAMING_SNAKE_CASE__=32		,SCREAMING_SNAKE_CASE__=5		,SCREAMING_SNAKE_CASE__=4		,SCREAMING_SNAKE_CASE__=0.1		,SCREAMING_SNAKE_CASE__=0.1		,SCREAMING_SNAKE_CASE__=5_12		,SCREAMING_SNAKE_CASE__=2		,SCREAMING_SNAKE_CASE__=0.0_2		,SCREAMING_SNAKE_CASE__=2		,SCREAMING_SNAKE_CASE__=4		,SCREAMING_SNAKE_CASE__="last"		,SCREAMING_SNAKE_CASE__=True		,SCREAMING_SNAKE_CASE__=None		,SCREAMING_SNAKE_CASE__=0		,)      ->				Any:





             """simple docstring"""






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




       def    _UpperCamelCase					(						self							)      ->				Dict:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :Tuple		    =  ids_tensor([self.batch_size, self.seq_length]		,self.vocab_size							)
             __SCREAMING_SNAKE_CASE       :Dict		    =  random_attention_mask([self.batch_size, self.seq_length]							)

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

             __SCREAMING_SNAKE_CASE       :Tuple		    =  None
             if self.use_token_type_ids:
                   __SCREAMING_SNAKE_CASE       :List[Any]		    =  ids_tensor([self.batch_size, self.seq_length]		,self.n_langs							)

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

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

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




       def    _UpperCamelCase					(						self							)      ->				List[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    _UpperCamelCase					(						self		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,)      ->				Dict:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :Optional[int]		    =  XLMModel(config=SCREAMING_SNAKE_CASE_							)
             model.to(SCREAMING_SNAKE_CASE_							)
             model.eval()
             __SCREAMING_SNAKE_CASE       :int		    =  model(SCREAMING_SNAKE_CASE_		,lengths=SCREAMING_SNAKE_CASE_		,langs=SCREAMING_SNAKE_CASE_							)
             __SCREAMING_SNAKE_CASE       :List[str]		    =  model(SCREAMING_SNAKE_CASE_		,langs=SCREAMING_SNAKE_CASE_							)
             __SCREAMING_SNAKE_CASE       :Tuple		    =  model(SCREAMING_SNAKE_CASE_							)
             self.parent.assertEqual(result.last_hidden_state.shape		,(self.batch_size, self.seq_length, self.hidden_size)							)




       def    _UpperCamelCase					(						self		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,)      ->				Dict:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :Optional[Any]		    =  XLMWithLMHeadModel(SCREAMING_SNAKE_CASE_							)
             model.to(SCREAMING_SNAKE_CASE_							)
             model.eval()

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





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :List[str]		    =  XLMForQuestionAnsweringSimple(SCREAMING_SNAKE_CASE_							)
             model.to(SCREAMING_SNAKE_CASE_							)
             model.eval()

             __SCREAMING_SNAKE_CASE       :int		    =  model(SCREAMING_SNAKE_CASE_							)

             __SCREAMING_SNAKE_CASE       :Union[str, Any]		    =  model(SCREAMING_SNAKE_CASE_		,start_positions=SCREAMING_SNAKE_CASE_		,end_positions=SCREAMING_SNAKE_CASE_							)
             __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    _UpperCamelCase					(						self		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,)      ->				Dict:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :int		    =  XLMForQuestionAnswering(SCREAMING_SNAKE_CASE_							)
             model.to(SCREAMING_SNAKE_CASE_							)
             model.eval()

             __SCREAMING_SNAKE_CASE       :List[Any]		    =  model(SCREAMING_SNAKE_CASE_							)

             __SCREAMING_SNAKE_CASE       :List[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_		,p_mask=SCREAMING_SNAKE_CASE_		,)

             __SCREAMING_SNAKE_CASE       :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_		,)

             (__SCREAMING_SNAKE_CASE							)       :Union[str, Any]		    =  result_with_labels.to_tuple()

             __SCREAMING_SNAKE_CASE       :int		    =  model(SCREAMING_SNAKE_CASE_		,start_positions=SCREAMING_SNAKE_CASE_		,end_positions=SCREAMING_SNAKE_CASE_							)

             (__SCREAMING_SNAKE_CASE							)       :Tuple		    =  result_with_labels.to_tuple()

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




       def    _UpperCamelCase					(						self		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,)      ->				Optional[int]:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :Union[str, Any]		    =  XLMForSequenceClassification(SCREAMING_SNAKE_CASE_							)
             model.to(SCREAMING_SNAKE_CASE_							)
             model.eval()

             __SCREAMING_SNAKE_CASE       :Optional[Any]		    =  model(SCREAMING_SNAKE_CASE_							)
             __SCREAMING_SNAKE_CASE       :int		    =  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		,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__		,)      ->				Optional[int]:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :int		    =  self.num_labels
             __SCREAMING_SNAKE_CASE       :int		    =  XLMForTokenClassification(SCREAMING_SNAKE_CASE_							)
             model.to(SCREAMING_SNAKE_CASE_							)
             model.eval()

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





             """simple docstring"""






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




       def    _UpperCamelCase					(						self							)      ->				int:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :int		    =  self.prepare_config_and_inputs()
             (
                 __SCREAMING_SNAKE_CASE							
             )       :List[Any]		    =  config_and_inputs
             __SCREAMING_SNAKE_CASE       :Dict		    =  {"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """lengths""": input_lengths}
             return config, inputs_dict






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





             """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    _UpperCamelCase					(						self		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__=False							)      ->				str:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :Union[str, Any]		    =  super()._prepare_for_class(SCREAMING_SNAKE_CASE_		,SCREAMING_SNAKE_CASE_		,return_labels=SCREAMING_SNAKE_CASE_							)

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

             return inputs_dict




       def    _UpperCamelCase					(						self							)      ->				int:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :List[Any]		    =  XLMModelTester(self							)
             __SCREAMING_SNAKE_CASE       :Optional[int]		    =  ConfigTester(self		,config_class=SCREAMING_SNAKE_CASE_		,emb_dim=37							)




       def    _UpperCamelCase					(						self							)      ->				Dict:





             """simple docstring"""






             self.config_tester.run_common_tests()




       def    _UpperCamelCase					(						self							)      ->				int:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :Dict		    =  self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_xlm_model(*SCREAMING_SNAKE_CASE_							)




       def    _UpperCamelCase					(						self							)      ->				List[Any]:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :Optional[Any]		    =  self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_xlm_lm_head(*SCREAMING_SNAKE_CASE_							)




       def    _UpperCamelCase					(						self							)      ->				str:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :Optional[Any]		    =  self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_xlm_simple_qa(*SCREAMING_SNAKE_CASE_							)




       def    _UpperCamelCase					(						self							)      ->				Optional[int]:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :Tuple		    =  self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_xlm_qa(*SCREAMING_SNAKE_CASE_							)




       def    _UpperCamelCase					(						self							)      ->				Optional[int]:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :Dict		    =  self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_xlm_sequence_classif(*SCREAMING_SNAKE_CASE_							)




       def    _UpperCamelCase					(						self							)      ->				str:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :int		    =  self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_xlm_token_classif(*SCREAMING_SNAKE_CASE_							)




       def    _UpperCamelCase					(						self							)      ->				Union[str, Any]:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :List[str]		    =  self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_xlm_for_multiple_choice(*SCREAMING_SNAKE_CASE_							)




       def    _UpperCamelCase					(						self		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__=False		,SCREAMING_SNAKE_CASE__=1							)      ->				Tuple:





             """simple docstring"""






             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
                   __SCREAMING_SNAKE_CASE       :int		    =  min_length + idx + 1
                   __SCREAMING_SNAKE_CASE       :Tuple		    =  min_length + idx + 1

                   __SCREAMING_SNAKE_CASE       :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    _UpperCamelCase					(						self		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__=False		,SCREAMING_SNAKE_CASE__=1							)      ->				Tuple:





             """simple docstring"""






             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
                   __SCREAMING_SNAKE_CASE       :List[str]		    =  min_length + idx + 1
                   __SCREAMING_SNAKE_CASE       :Optional[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(SCREAMING_SNAKE_CASE_							)		,)
             pass




       @slow
       def    _UpperCamelCase					(						self							)      ->				Optional[int]:





             """simple docstring"""






             for model_name in XLM_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                   __SCREAMING_SNAKE_CASE       :str		    =  XLMModel.from_pretrained(SCREAMING_SNAKE_CASE_							)
                   self.assertIsNotNone(SCREAMING_SNAKE_CASE_							)






@require_torch
class  _SCREAMING_SNAKE_CASE(       unittest.TestCase  ):




       @slow
       def    _UpperCamelCase					(						self							)      ->				List[str]:





             """simple docstring"""






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






"""simple docstring"""
from ...configuration_utils import PretrainedConfig
from ...utils import logging


lowerCamelCase_       =		logging.get_logger(__name__)

lowerCamelCase_       =		{
    "google/vivit-b-16x2-kinetics400": (
        "https://huggingface.co/google/vivit-b-16x2-kinetics400/resolve/main/config.json"
    ),
    # See all Vivit models at https://huggingface.co/models?filter=vivit
}






class  _SCREAMING_SNAKE_CASE(       A  ):
       SCREAMING_SNAKE_CASE_       :				Optional[Any]     						=  '''vivit'''




       def __init__(						self		,SCREAMING_SNAKE_CASE__=2_24		,SCREAMING_SNAKE_CASE__=32		,SCREAMING_SNAKE_CASE__=[2, 16, 16]		,SCREAMING_SNAKE_CASE__=3		,SCREAMING_SNAKE_CASE__=7_68		,SCREAMING_SNAKE_CASE__=12		,SCREAMING_SNAKE_CASE__=12		,SCREAMING_SNAKE_CASE__=30_72		,SCREAMING_SNAKE_CASE__="gelu_fast"		,SCREAMING_SNAKE_CASE__=0.0		,SCREAMING_SNAKE_CASE__=0.0		,SCREAMING_SNAKE_CASE__=0.0_2		,SCREAMING_SNAKE_CASE__=1E-06		,SCREAMING_SNAKE_CASE__=True		,**SCREAMING_SNAKE_CASE__		,)      ->				str:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE       :Optional[Any]		    =  hidden_size
             __SCREAMING_SNAKE_CASE       :List[str]		    =  num_hidden_layers
             __SCREAMING_SNAKE_CASE       :List[str]		    =  num_attention_heads
             __SCREAMING_SNAKE_CASE       :Any		    =  intermediate_size
             __SCREAMING_SNAKE_CASE       :Optional[Any]		    =  hidden_act
             __SCREAMING_SNAKE_CASE       :int		    =  hidden_dropout_prob
             __SCREAMING_SNAKE_CASE       :Union[str, Any]		    =  attention_probs_dropout_prob
             __SCREAMING_SNAKE_CASE       :Dict		    =  initializer_range
             __SCREAMING_SNAKE_CASE       :Dict		    =  layer_norm_eps

             __SCREAMING_SNAKE_CASE       :Any		    =  image_size
             __SCREAMING_SNAKE_CASE       :Any		    =  num_frames
             __SCREAMING_SNAKE_CASE       :Any		    =  tubelet_size
             __SCREAMING_SNAKE_CASE       :Tuple		    =  num_channels
             __SCREAMING_SNAKE_CASE       :List[str]		    =  qkv_bias

             super().__init__(**SCREAMING_SNAKE_CASE__							)