



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




  def __init__(					self	:		Dict		,   __lowerCAmelCase	:		Dict		,   __lowerCAmelCase	:		Optional[int]=1_3		,   __lowerCAmelCase	:		Tuple=7		,   __lowerCAmelCase	:		int=True		,   __lowerCAmelCase	:		Optional[int]=True		,   __lowerCAmelCase	:		int=True		,   __lowerCAmelCase	:		Union[str, Any]=True		,   __lowerCAmelCase	:		str=True		,   __lowerCAmelCase	:		List[str]=False		,   __lowerCAmelCase	:		Dict=False		,   __lowerCAmelCase	:		Optional[Any]=False		,   __lowerCAmelCase	:		Dict=2		,   __lowerCAmelCase	:		Union[str, Any]=9_9		,   __lowerCAmelCase	:		Optional[Any]=0		,   __lowerCAmelCase	:		List[str]=3_2		,   __lowerCAmelCase	:		Optional[int]=5		,   __lowerCAmelCase	:		int=4		,   __lowerCAmelCase	:		Tuple=0.1		,   __lowerCAmelCase	:		List[str]=0.1		,   __lowerCAmelCase	:		List[str]=5_1_2		,   __lowerCAmelCase	:		List[Any]=2		,   __lowerCAmelCase	:		Any=0.02		,   __lowerCAmelCase	:		Tuple=2		,   __lowerCAmelCase	:		List[Any]=4		,   __lowerCAmelCase	:		List[Any]="last"		,   __lowerCAmelCase	:		List[Any]=True		,   __lowerCAmelCase	:		Tuple=None		,   __lowerCAmelCase	:		int=0		,   ):






         """simple docstring"""






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




  def 		SCREAMING_SNAKE_CASE							(					self	:		str						):






         """simple docstring"""






         _lowerCamelCase		:							int            =					ids_tensor([self.batch_size, self.seq_length]		,   self.vocab_size						)
         _lowerCamelCase		:							List[str]            =					random_attention_mask([self.batch_size, self.seq_length]						)

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

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

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

         _lowerCamelCase		:							Any            =					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	:		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	:		str		,   __lowerCAmelCase	:		int		,   __lowerCAmelCase	:		Any		,   __lowerCAmelCase	:		List[Any]		,   __lowerCAmelCase	:		Dict		,   __lowerCAmelCase	:		Union[str, Any]		,   __lowerCAmelCase	:		List[str]		,   __lowerCAmelCase	:		List[str]		,   __lowerCAmelCase	:		Any		,   __lowerCAmelCase	:		List[Any]		,   ):






         """simple docstring"""






         _lowerCamelCase		:							Union[str, Any]            =					XLMModel(config=_lowercase						)
         model.to(_lowercase						)
         model.eval()
         _lowerCamelCase		:							str            =					model(_lowercase		,   lengths=_lowercase		,   langs=_lowercase						)
         _lowerCamelCase		:							Optional[Any]            =					model(_lowercase		,   langs=_lowercase						)
         _lowerCamelCase		:							Dict            =					model(_lowercase						)
         self.parent.assertEqual(result.last_hidden_state.shape		,   (self.batch_size, self.seq_length, self.hidden_size)						)




  def 		SCREAMING_SNAKE_CASE							(					self	:		List[Any]		,   __lowerCAmelCase	:		int		,   __lowerCAmelCase	:		Dict		,   __lowerCAmelCase	:		List[Any]		,   __lowerCAmelCase	:		str		,   __lowerCAmelCase	:		Tuple		,   __lowerCAmelCase	:		List[Any]		,   __lowerCAmelCase	:		List[Any]		,   __lowerCAmelCase	:		List[str]		,   __lowerCAmelCase	:		str		,   ):






         """simple docstring"""






         _lowerCamelCase		:							Union[str, Any]            =					XLMWithLMHeadModel(_lowercase						)
         model.to(_lowercase						)
         model.eval()

         _lowerCamelCase		:							int            =					model(_lowercase		,   token_type_ids=_lowercase		,   labels=_lowercase						)
         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	:		Optional[Any]		,   __lowerCAmelCase	:		Dict		,   __lowerCAmelCase	:		Any		,   __lowerCAmelCase	:		List[str]		,   __lowerCAmelCase	:		str		,   __lowerCAmelCase	:		Optional[int]		,   __lowerCAmelCase	:		str		,   __lowerCAmelCase	:		int		,   __lowerCAmelCase	:		Union[str, Any]		,   __lowerCAmelCase	:		Union[str, Any]		,   ):






         """simple docstring"""






         _lowerCamelCase		:							Any            =					XLMForQuestionAnsweringSimple(_lowercase						)
         model.to(_lowercase						)
         model.eval()

         _lowerCamelCase		:							Union[str, Any]            =					model(_lowercase						)

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






         """simple docstring"""






         _lowerCamelCase		:							Dict            =					XLMForQuestionAnswering(_lowercase						)
         model.to(_lowercase						)
         model.eval()

         _lowerCamelCase		:							Dict            =					model(_lowercase						)

         _lowerCamelCase		:							Union[str, Any]            =					model(
             _lowercase		,   start_positions=_lowercase		,   end_positions=_lowercase		,   cls_index=_lowercase		,   is_impossible=_lowercase		,   p_mask=_lowercase		,   )

         _lowerCamelCase		:							Union[str, Any]            =					model(
             _lowercase		,   start_positions=_lowercase		,   end_positions=_lowercase		,   cls_index=_lowercase		,   is_impossible=_lowercase		,   )

         (_lowerCamelCase			)		:							Dict            =					result_with_labels.to_tuple()

         _lowerCamelCase		:							Any            =					model(_lowercase		,   start_positions=_lowercase		,   end_positions=_lowercase						)

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






         """simple docstring"""






         _lowerCamelCase		:							Optional[Any]            =					XLMForSequenceClassification(_lowercase						)
         model.to(_lowercase						)
         model.eval()

         _lowerCamelCase		:							Optional[int]            =					model(_lowercase						)
         _lowerCamelCase		:							Optional[int]            =					model(_lowercase		,   labels=_lowercase						)
         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	:		Any		,   __lowerCAmelCase	:		List[Any]		,   __lowerCAmelCase	:		Tuple		,   __lowerCAmelCase	:		Optional[int]		,   __lowerCAmelCase	:		Dict		,   __lowerCAmelCase	:		List[str]		,   __lowerCAmelCase	:		Any		,   __lowerCAmelCase	:		Optional[Any]		,   __lowerCAmelCase	:		Any		,   __lowerCAmelCase	:		Optional[Any]		,   ):






         """simple docstring"""






         _lowerCamelCase		:							Any            =					self.num_labels
         _lowerCamelCase		:							Optional[Any]            =					XLMForTokenClassification(_lowercase						)
         model.to(_lowercase						)
         model.eval()

         _lowerCamelCase		:							Any            =					model(_lowercase		,   attention_mask=_lowercase		,   labels=_lowercase						)
         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	:		Any		,   __lowerCAmelCase	:		int		,   __lowerCAmelCase	:		Dict		,   __lowerCAmelCase	:		Dict		,   __lowerCAmelCase	:		List[Any]		,   __lowerCAmelCase	:		Optional[Any]		,   __lowerCAmelCase	:		int		,   __lowerCAmelCase	:		Union[str, Any]		,   ):






         """simple docstring"""






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




  def 		SCREAMING_SNAKE_CASE							(					self	:		Optional[int]						):






         """simple docstring"""






         _lowerCamelCase		:							Any            =					self.prepare_config_and_inputs()
         (
             _lowerCamelCase			
         )		:							int            =					config_and_inputs
         _lowerCamelCase		:							str            =					{"input_ids": input_ids, "token_type_ids": token_type_ids, "lengths": input_lengths}
         return config, inputs_dict






@require_torch
class 			__snake_case			(      SCREAMING_SNAKE_CASE__    ,	SCREAMING_SNAKE_CASE__    ,	SCREAMING_SNAKE_CASE__    ,	unittest.TestCase):
  snake_case__							:  int         =		(
      (
          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__							:  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	:		Optional[Any]		,   __lowerCAmelCase	:		Dict		,   __lowerCAmelCase	:		Any		,   __lowerCAmelCase	:		List[Any]		,   __lowerCAmelCase	:		Optional[int]		,   __lowerCAmelCase	:		List[str]						):






         """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	:		List[Any]		,   __lowerCAmelCase	:		int		,   __lowerCAmelCase	:		Tuple=False						):






         """simple docstring"""






         _lowerCamelCase		:							Dict            =					super()._prepare_for_class(_lowercase		,   _lowercase		,   return_labels=_lowercase						)

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

         return inputs_dict




  def 		SCREAMING_SNAKE_CASE							(					self	:		Dict						):






         """simple docstring"""






         _lowerCamelCase		:							Union[str, Any]            =					XLMModelTester(self						)
         _lowerCamelCase		:							int            =					ConfigTester(self		,   config_class=_lowercase		,   emb_dim=3_7						)




  def 		SCREAMING_SNAKE_CASE							(					self	:		int						):






         """simple docstring"""






         self.config_tester.run_common_tests()




  def 		SCREAMING_SNAKE_CASE							(					self	:		int						):






         """simple docstring"""






         _lowerCamelCase		:							List[Any]            =					self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_xlm_model(*_lowercase						)




  def 		SCREAMING_SNAKE_CASE							(					self	:		int						):






         """simple docstring"""






         _lowerCamelCase		:							Dict            =					self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_xlm_lm_head(*_lowercase						)




  def 		SCREAMING_SNAKE_CASE							(					self	:		str						):






         """simple docstring"""






         _lowerCamelCase		:							Optional[int]            =					self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_xlm_simple_qa(*_lowercase						)




  def 		SCREAMING_SNAKE_CASE							(					self	:		str						):






         """simple docstring"""






         _lowerCamelCase		:							str            =					self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_xlm_qa(*_lowercase						)




  def 		SCREAMING_SNAKE_CASE							(					self	:		Union[str, Any]						):






         """simple docstring"""






         _lowerCamelCase		:							Dict            =					self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_xlm_sequence_classif(*_lowercase						)




  def 		SCREAMING_SNAKE_CASE							(					self	:		Any						):






         """simple docstring"""






         _lowerCamelCase		:							Dict            =					self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_xlm_token_classif(*_lowercase						)




  def 		SCREAMING_SNAKE_CASE							(					self	:		str						):






         """simple docstring"""






         _lowerCamelCase		:							Optional[int]            =					self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_xlm_for_multiple_choice(*_lowercase						)




  def 		SCREAMING_SNAKE_CASE							(					self	:		Optional[Any]		,   __lowerCAmelCase	:		int		,   __lowerCAmelCase	:		Dict		,   __lowerCAmelCase	:		int		,   __lowerCAmelCase	:		str		,   __lowerCAmelCase	:		Dict		,   __lowerCAmelCase	:		int=False		,   __lowerCAmelCase	:		Optional[int]=1						):






         """simple docstring"""






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

         for idx, iter_attentions in enumerate(_lowercase						):
                # adds PAD dummy token
                _lowerCamelCase		:							Tuple            =					min_length + idx + 1
                _lowerCamelCase		:							List[Any]            =					min_length + idx + 1

                _lowerCamelCase		:							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(_lowercase						)						)




  def 		SCREAMING_SNAKE_CASE							(					self	:		int		,   __lowerCAmelCase	:		Any		,   __lowerCAmelCase	:		str		,   __lowerCAmelCase	:		List[str]		,   __lowerCAmelCase	:		Dict		,   __lowerCAmelCase	:		Optional[int]		,   __lowerCAmelCase	:		Optional[Any]=False		,   __lowerCAmelCase	:		Union[str, Any]=1						):






         """simple docstring"""






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

         for idx, iter_hidden_states in enumerate(_lowercase						):
                # adds PAD dummy token
                _lowerCamelCase		:							Dict            =					min_length + idx + 1
                _lowerCamelCase		:							str            =					(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(_lowercase						)		,   )
         pass




  @slow
  def 		SCREAMING_SNAKE_CASE							(					self	:		Optional[int]						):






         """simple docstring"""






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






@require_torch
class 			__snake_case			(      unittest.TestCase):




  @slow
  def 		SCREAMING_SNAKE_CASE							(					self	:		List[str]						):






         """simple docstring"""






         _lowerCamelCase		:							str            =					XLMWithLMHeadModel.from_pretrained('''xlm-mlm-en-2048'''						)
         model.to(_lowercase						)
         _lowerCamelCase		:							Optional[Any]            =					torch.tensor([[1_4, 4_4_7]]		,   dtype=torch.long		,   device=_lowercase						)  # the president
         _lowerCamelCase		:							Optional[int]            =					[
             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
         _lowerCamelCase		:							Union[str, Any]            =					model.generate(_lowercase		,   do_sample=_lowercase						)
         self.assertListEqual(output_ids[0].cpu().numpy().tolist()		,   _lowercase						)







"""simple docstring"""







import importlib
import inspect
import os
import re


# All paths are set with the intent you should run this script from the root of the repo with the command
# python utils/check_config_docstrings.py
A		=						'src/transformers'


# This is to make sure the transformers module imported is the one in the repo.
A		=						importlib.util.spec_from_file_location(
    'transformers',
    os.path.join(PATH_TO_TRANSFORMERS, '__init__.py'),
    submodule_search_locations=[PATH_TO_TRANSFORMERS],
)
A		=						spec.loader.load_module()

A		=						transformers.models.auto.configuration_auto.CONFIG_MAPPING

# Regex pattern used to find the checkpoint mentioned in the docstring of `config_class`.
# For example, `[bert-base-uncased](https://huggingface.co/bert-base-uncased)`
A		=						re.compile('\[(.+?)\]\((https://huggingface\.co/.+?)\)')


A		=						{
    'CLIPConfigMixin',
    'DecisionTransformerConfigMixin',
    'EncoderDecoderConfigMixin',
    'RagConfigMixin',
    'SpeechEncoderDecoderConfigMixin',
    'VisionEncoderDecoderConfigMixin',
    'VisionTextDualEncoderConfigMixin',
}

def  __SCREAMING_SNAKE_CASE		(			):
						"""simple docstring"""






						snake_case   :			Union[str, Any]						    = []

						for config_class in list(CONFIG_MAPPING.values() ):
												snake_case   :			List[str]						    = False

												# source code of `config_class`
												snake_case   :			Optional[int]						    = inspect.getsource(lowerCamelCase_ )
												snake_case   :			Optional[int]						    = _re_checkpoint.findall(lowerCamelCase_ )

												for checkpoint in checkpoints:
																		# Each `checkpoint` is a tuple of a checkpoint name and a checkpoint link.
																		# For example, `('bert-base-uncased', 'https://huggingface.co/bert-base-uncased')`
																		snake_case    ,			snake_case   :			Tuple						    = checkpoint

																		# verify the checkpoint name corresponds to the checkpoint link
																		snake_case   :			Any						    = f'''https://huggingface.co/{ckpt_name}'''
																		if ckpt_link == ckpt_link_from_name:
																								snake_case   :			List[str]						    = True
																								break

												snake_case   :			Any						    = config_class.__name__
												if not checkpoint_found and name not in CONFIG_CLASSES_TO_IGNORE_FOR_DOCSTRING_CHECKPOINT_CHECK:
																		configs_without_checkpoint.append(lowerCamelCase_ )

						if len(lowerCamelCase_ ) > 0:
												snake_case   :			List[str]						    = "\n".join(sorted(lowerCamelCase_ ) )
												raise ValueError(f'''The following configurations don\'t contain any valid checkpoint:\n{message}''' )


if __name__ == "__main__":
			check_config_docstrings_have_checkpoints()



