





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



     '''simple docstring'''

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




           '''simple docstring'''


           SCREAMING_SNAKE_CASE	=		parent
           SCREAMING_SNAKE_CASE	=		batch_size
           SCREAMING_SNAKE_CASE	=		seq_length
           SCREAMING_SNAKE_CASE	=		is_training
           SCREAMING_SNAKE_CASE	=		use_input_lengths
           SCREAMING_SNAKE_CASE	=		use_token_type_ids
           SCREAMING_SNAKE_CASE	=		use_labels
           SCREAMING_SNAKE_CASE	=		gelu_activation
           SCREAMING_SNAKE_CASE	=		sinusoidal_embeddings
           SCREAMING_SNAKE_CASE	=		causal
           SCREAMING_SNAKE_CASE	=		asm
           SCREAMING_SNAKE_CASE	=		n_langs
           SCREAMING_SNAKE_CASE	=		vocab_size
           SCREAMING_SNAKE_CASE	=		n_special
           SCREAMING_SNAKE_CASE	=		hidden_size
           SCREAMING_SNAKE_CASE	=		num_hidden_layers
           SCREAMING_SNAKE_CASE	=		num_attention_heads
           SCREAMING_SNAKE_CASE	=		hidden_dropout_prob
           SCREAMING_SNAKE_CASE	=		attention_probs_dropout_prob
           SCREAMING_SNAKE_CASE	=		max_position_embeddings
           SCREAMING_SNAKE_CASE	=		type_sequence_label_size
           SCREAMING_SNAKE_CASE	=		initializer_range
           SCREAMING_SNAKE_CASE	=		num_labels
           SCREAMING_SNAKE_CASE	=		num_choices
           SCREAMING_SNAKE_CASE	=		summary_type
           SCREAMING_SNAKE_CASE	=		use_proj
           SCREAMING_SNAKE_CASE	=		scope
           SCREAMING_SNAKE_CASE	=		bos_token_id






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




           '''simple docstring'''


           SCREAMING_SNAKE_CASE	=		ids_tensor([self.batch_size, self.seq_length]		,self.vocab_size )
           SCREAMING_SNAKE_CASE	=		random_attention_mask([self.batch_size, self.seq_length] )

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

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

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

           SCREAMING_SNAKE_CASE	=		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		:					Union[str, Any] )  ->	Union[str, Any]:




           '''simple docstring'''


           return XLMConfig(
               vocab_size=self.vocab_size		,n_special=self.n_special		,emb_dim=self.hidden_size		,n_layers=self.num_hidden_layers		,n_heads=self.num_attention_heads		,dropout=self.hidden_dropout_prob		,attention_dropout=self.attention_probs_dropout_prob		,gelu_activation=self.gelu_activation		,sinusoidal_embeddings=self.sinusoidal_embeddings		,asm=self.asm		,causal=self.causal		,n_langs=self.n_langs		,max_position_embeddings=self.max_position_embeddings		,initializer_range=self.initializer_range		,summary_type=self.summary_type		,use_proj=self.use_proj		,num_labels=self.num_labels		,bos_token_id=self.bos_token_id		,)






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




           '''simple docstring'''


           SCREAMING_SNAKE_CASE	=		XLMModel(config=lowerCamelCase__ )
           model.to(lowerCamelCase__ )
           model.eval()
           SCREAMING_SNAKE_CASE	=		model(lowerCamelCase__		,lengths=lowerCamelCase__		,langs=lowerCamelCase__ )
           SCREAMING_SNAKE_CASE	=		model(lowerCamelCase__		,langs=lowerCamelCase__ )
           SCREAMING_SNAKE_CASE	=		model(lowerCamelCase__ )
           self.parent.assertEqual(result.last_hidden_state.shape		,(self.batch_size, self.seq_length, self.hidden_size) )






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




           '''simple docstring'''


           SCREAMING_SNAKE_CASE	=		XLMWithLMHeadModel(lowerCamelCase__ )
           model.to(lowerCamelCase__ )
           model.eval()

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




           '''simple docstring'''


           SCREAMING_SNAKE_CASE	=		XLMForQuestionAnsweringSimple(lowerCamelCase__ )
           model.to(lowerCamelCase__ )
           model.eval()

           SCREAMING_SNAKE_CASE	=		model(lowerCamelCase__ )

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




           '''simple docstring'''


           SCREAMING_SNAKE_CASE	=		XLMForQuestionAnswering(lowerCamelCase__ )
           model.to(lowerCamelCase__ )
           model.eval()

           SCREAMING_SNAKE_CASE	=		model(lowerCamelCase__ )

           SCREAMING_SNAKE_CASE	=		model(
               lowerCamelCase__		,start_positions=lowerCamelCase__		,end_positions=lowerCamelCase__		,cls_index=lowerCamelCase__		,is_impossible=lowerCamelCase__		,p_mask=lowerCamelCase__		,)

           SCREAMING_SNAKE_CASE	=		model(
               lowerCamelCase__		,start_positions=lowerCamelCase__		,end_positions=lowerCamelCase__		,cls_index=lowerCamelCase__		,is_impossible=lowerCamelCase__		,)

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

           SCREAMING_SNAKE_CASE	=		model(lowerCamelCase__		,start_positions=lowerCamelCase__		,end_positions=lowerCamelCase__ )

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




           '''simple docstring'''


           SCREAMING_SNAKE_CASE	=		XLMForSequenceClassification(lowerCamelCase__ )
           model.to(lowerCamelCase__ )
           model.eval()

           SCREAMING_SNAKE_CASE	=		model(lowerCamelCase__ )
           SCREAMING_SNAKE_CASE	=		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        SCREAMING_SNAKE_CASE__						(							self		:					List[Any]		,lowerCamelCase__		:					Tuple		,lowerCamelCase__		:					Union[str, Any]		,lowerCamelCase__		:					Tuple		,lowerCamelCase__		:					Optional[Any]		,lowerCamelCase__		:					List[str]		,lowerCamelCase__		:					Dict		,lowerCamelCase__		:					Union[str, Any]		,lowerCamelCase__		:					str		,lowerCamelCase__		:					List[Any]		,)  ->	Optional[Any]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE	=		self.num_labels
           SCREAMING_SNAKE_CASE	=		XLMForTokenClassification(lowerCamelCase__ )
           model.to(lowerCamelCase__ )
           model.eval()

           SCREAMING_SNAKE_CASE	=		model(lowerCamelCase__		,attention_mask=lowerCamelCase__		,labels=lowerCamelCase__ )
           self.parent.assertEqual(result.logits.shape		,(self.batch_size, self.seq_length, self.num_labels) )






     def        SCREAMING_SNAKE_CASE__						(							self		:					Tuple		,lowerCamelCase__		:					List[Any]		,lowerCamelCase__		:					int		,lowerCamelCase__		:					int		,lowerCamelCase__		:					Union[str, Any]		,lowerCamelCase__		:					Union[str, Any]		,lowerCamelCase__		:					Any		,lowerCamelCase__		:					Tuple		,lowerCamelCase__		:					List[Any]		,lowerCamelCase__		:					Optional[Any]		,)  ->	int:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE	=		self.num_choices
           SCREAMING_SNAKE_CASE	=		XLMForMultipleChoice(config=lowerCamelCase__ )
           model.to(lowerCamelCase__ )
           model.eval()
           SCREAMING_SNAKE_CASE	=		input_ids.unsqueeze(1 ).expand(-1		,self.num_choices		,-1 ).contiguous()
           SCREAMING_SNAKE_CASE	=		token_type_ids.unsqueeze(1 ).expand(-1		,self.num_choices		,-1 ).contiguous()
           SCREAMING_SNAKE_CASE	=		input_mask.unsqueeze(1 ).expand(-1		,self.num_choices		,-1 ).contiguous()
           SCREAMING_SNAKE_CASE	=		model(
               lowerCamelCase__		,attention_mask=lowerCamelCase__		,token_type_ids=lowerCamelCase__		,labels=lowerCamelCase__		,)
           self.parent.assertEqual(result.logits.shape		,(self.batch_size, self.num_choices) )






     def        SCREAMING_SNAKE_CASE__						(							self		:					str )  ->	int:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE	=		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      
           ),            
           )	=		config_and_inputs
           SCREAMING_SNAKE_CASE	=		{"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """lengths""": input_lengths}
           return config, inputs_dict

@require_torch
class 	UpperCamelCase__				(   lowerCAmelCase_							,   lowerCAmelCase_							,   lowerCAmelCase_							,   unittest.TestCase     ):



     '''simple docstring'''

     __snake_case					:			Tuple				=    (
         (
             XLMModel,
             XLMWithLMHeadModel,
             XLMForQuestionAnswering,
             XLMForSequenceClassification,
             XLMForQuestionAnsweringSimple,
             XLMForTokenClassification,
             XLMForMultipleChoice,
         )
         if is_torch_available()
         else ()
     )
     __snake_case					:			Optional[Any]				=    (
         (XLMWithLMHeadModel,) if is_torch_available() else ()
     )  # TODO (PVP): Check other models whether language generation is also applicable
     __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        SCREAMING_SNAKE_CASE__						(							self		:					int		,lowerCamelCase__		:					Tuple		,lowerCamelCase__		:					Tuple		,lowerCamelCase__		:					List[str]		,lowerCamelCase__		:					Tuple		,lowerCamelCase__		:					Optional[int] )  ->	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        SCREAMING_SNAKE_CASE__						(							self		:					Any		,lowerCamelCase__		:					Dict		,lowerCamelCase__		:					Tuple		,lowerCamelCase__		:					Any=False )  ->	Dict:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE	=		super()._prepare_for_class(lowerCamelCase__		,lowerCamelCase__		,return_labels=lowerCamelCase__ )

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

           return inputs_dict






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




           '''simple docstring'''


           SCREAMING_SNAKE_CASE	=		XLMModelTester(self )
           SCREAMING_SNAKE_CASE	=		ConfigTester(self		,config_class=lowerCamelCase__		,emb_dim=37 )






     def        SCREAMING_SNAKE_CASE__						(							self		:					List[Any] )  ->	int:




           '''simple docstring'''


           self.config_tester.run_common_tests()






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




           '''simple docstring'''


           SCREAMING_SNAKE_CASE	=		self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_xlm_model(*lowerCamelCase__ )






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




           '''simple docstring'''


           SCREAMING_SNAKE_CASE	=		self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_xlm_lm_head(*lowerCamelCase__ )






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




           '''simple docstring'''


           SCREAMING_SNAKE_CASE	=		self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_xlm_simple_qa(*lowerCamelCase__ )






     def        SCREAMING_SNAKE_CASE__						(							self		:					Dict )  ->	Tuple:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE	=		self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_xlm_qa(*lowerCamelCase__ )






     def        SCREAMING_SNAKE_CASE__						(							self		:					Tuple )  ->	int:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE	=		self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_xlm_sequence_classif(*lowerCamelCase__ )






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




           '''simple docstring'''


           SCREAMING_SNAKE_CASE	=		self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_xlm_token_classif(*lowerCamelCase__ )






     def        SCREAMING_SNAKE_CASE__						(							self		:					str )  ->	Tuple:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE	=		self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_xlm_for_multiple_choice(*lowerCamelCase__ )






     def        SCREAMING_SNAKE_CASE__						(							self		:					List[str]		,lowerCamelCase__		:					List[Any]		,lowerCamelCase__		:					Union[str, Any]		,lowerCamelCase__		:					Optional[Any]		,lowerCamelCase__		:					Union[str, Any]		,lowerCamelCase__		:					str		,lowerCamelCase__		:					str=False		,lowerCamelCase__		:					Any=1 )  ->	Union[str, Any]:




           '''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	=		min_length + idx + 1
                 SCREAMING_SNAKE_CASE	=		min_length + idx + 1

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




           '''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	=		min_length + idx + 1
                 SCREAMING_SNAKE_CASE	=		(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        SCREAMING_SNAKE_CASE__						(							self		:					List[str] )  ->	Union[str, Any]:




           '''simple docstring'''


           for model_name in XLM_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                 SCREAMING_SNAKE_CASE	=		XLMModel.from_pretrained(lowerCamelCase__ )
                 self.assertIsNotNone(lowerCamelCase__ )

@require_torch
class 	UpperCamelCase__				(   unittest.TestCase     ):



     '''simple docstring'''

     @slow
     def        SCREAMING_SNAKE_CASE__						(							self		:					str )  ->	Any:




           '''simple docstring'''


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










import warnings

from ...utils import logging
from .image_processing_deformable_detr import DeformableDetrImageProcessor


SCREAMING_SNAKE_CASE_		     = logging.get_logger(__name__)

class 	UpperCamelCase__				(   lowerCAmelCase_     ):



     '''simple docstring'''

     def __init__(							self		:					int		,*lowerCamelCase__		:					int		,**lowerCamelCase__		:					List[Any] )  ->	None:




           '''simple docstring'''


           warnings.warn(
               """The class DeformableDetrFeatureExtractor is deprecated and will be removed in version 5 of Transformers."""
               """ Please use DeformableDetrImageProcessor instead."""		,lowerCamelCase__		,)
           super().__init__(*lowerCamelCase__		,**lowerCamelCase__ )


