
"""simple docstring"""


import unittest

from transformers import XLMConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
      import torch

      from transformers import (
          XLMForMultipleChoice,
          XLMForQuestionAnswering,
          XLMForQuestionAnsweringSimple,
          XLMForSequenceClassification,
          XLMForTokenClassification,
          XLMModel,
          XLMWithLMHeadModel,
      )
      from transformers.models.xlm.modeling_xlm import XLM_PRETRAINED_MODEL_ARCHIVE_LIST



class 	__a	:






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







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






       def 						_SCREAMING_SNAKE_CASE							(	self			:				Any      )->	Any:







              """simple docstring"""
              UpperCamelCase       			=		ids_tensor([self.batch_size, self.seq_length]							,   self.vocab_size      )
              UpperCamelCase       			=		random_attention_mask([self.batch_size, self.seq_length]      )

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

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

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

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







              """simple docstring"""
              UpperCamelCase       			=		XLMModel(config=UpperCAmelCase_      )
              model.to(UpperCAmelCase_      )
              model.eval()
              UpperCamelCase       			=		model(UpperCAmelCase_							,   lengths=UpperCAmelCase_							,   langs=UpperCAmelCase_      )
              UpperCamelCase       			=		model(UpperCAmelCase_							,   langs=UpperCAmelCase_      )
              UpperCamelCase       			=		model(UpperCAmelCase_      )
              self.parent.assertEqual(result.last_hidden_state.shape							,   (self.batch_size, self.seq_length, self.hidden_size)      )






       def 						_SCREAMING_SNAKE_CASE							(	self			:				List[Any]							,   UpperCAmelCase_			:				Dict							,   UpperCAmelCase_			:				List[str]							,   UpperCAmelCase_			:				Any							,   UpperCAmelCase_			:				str							,   UpperCAmelCase_			:				List[Any]							,   UpperCAmelCase_			:				int							,   UpperCAmelCase_			:				Union[str, Any]							,   UpperCAmelCase_			:				Any							,   UpperCAmelCase_			:				Optional[int]							,   )->	Dict:







              """simple docstring"""
              UpperCamelCase       			=		XLMWithLMHeadModel(UpperCAmelCase_      )
              model.to(UpperCAmelCase_      )
              model.eval()

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







              """simple docstring"""
              UpperCamelCase       			=		XLMForQuestionAnsweringSimple(UpperCAmelCase_      )
              model.to(UpperCAmelCase_      )
              model.eval()

              UpperCamelCase       			=		model(UpperCAmelCase_      )

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







              """simple docstring"""
              UpperCamelCase       			=		XLMForQuestionAnswering(UpperCAmelCase_      )
              model.to(UpperCAmelCase_      )
              model.eval()

              UpperCamelCase       			=		model(UpperCAmelCase_      )

              UpperCamelCase       			=		model(
                  UpperCAmelCase_							,   start_positions=UpperCAmelCase_							,   end_positions=UpperCAmelCase_							,   cls_index=UpperCAmelCase_							,   is_impossible=UpperCAmelCase_							,   p_mask=UpperCAmelCase_							,   )

              UpperCamelCase       			=		model(
                  UpperCAmelCase_							,   start_positions=UpperCAmelCase_							,   end_positions=UpperCAmelCase_							,   cls_index=UpperCAmelCase_							,   is_impossible=UpperCAmelCase_							,   )

              ((UpperCamelCase)			,							)       			=		result_with_labels.to_tuple()

              UpperCamelCase       			=		model(UpperCAmelCase_							,   start_positions=UpperCAmelCase_							,   end_positions=UpperCAmelCase_      )

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







              """simple docstring"""
              UpperCamelCase       			=		XLMForSequenceClassification(UpperCAmelCase_      )
              model.to(UpperCAmelCase_      )
              model.eval()

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







              """simple docstring"""
              UpperCamelCase       			=		self.num_labels
              UpperCamelCase       			=		XLMForTokenClassification(UpperCAmelCase_      )
              model.to(UpperCAmelCase_      )
              model.eval()

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






       def 						_SCREAMING_SNAKE_CASE							(	self			:				Dict							,   UpperCAmelCase_			:				Optional[int]							,   UpperCAmelCase_			:				str							,   UpperCAmelCase_			:				Tuple							,   UpperCAmelCase_			:				str							,   UpperCAmelCase_			:				Union[str, Any]							,   UpperCAmelCase_			:				Dict							,   UpperCAmelCase_			:				str							,   UpperCAmelCase_			:				str							,   UpperCAmelCase_			:				List[str]							,   )->	Optional[int]:







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






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







              """simple docstring"""
              UpperCamelCase       			=		self.prepare_config_and_inputs()
              (
                  (
                  UpperCamelCase
              )			,							(
                  UpperCamelCase
              )			,							(
                  UpperCamelCase
              )			,							(
                  UpperCamelCase
              )			,							(
                  UpperCamelCase
              )			,							(
                  UpperCamelCase
              )			,							(
                  UpperCamelCase
              )			,							(
                  UpperCamelCase
              )			,							(
                  UpperCamelCase
              )			,							
              )       			=		config_and_inputs
              UpperCamelCase       			=		{"input_ids": input_ids, "token_type_ids": token_type_ids, "lengths": input_lengths}
              return config, inputs_dict





@require_torch
class 	__a	(   _lowerCAmelCase     ,  _lowerCAmelCase     ,  _lowerCAmelCase     ,  unittest.TestCase						):
       UpperCamelCase_		:       int				=      (
           (
               XLMModel,
               XLMWithLMHeadModel,
               XLMForQuestionAnswering,
               XLMForSequenceClassification,
               XLMForQuestionAnsweringSimple,
               XLMForTokenClassification,
               XLMForMultipleChoice,
           )
           if is_torch_available()
           else ()
       )
       UpperCamelCase_		:       Dict				=      (
           (XLMWithLMHeadModel,) if is_torch_available() else ()
       )  # TODO (PVP): Check other models whether language generation is also applicable
       UpperCamelCase_		:       Tuple				=      (
           {
               '''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			:				str							,   UpperCAmelCase_			:				List[Any]							,   UpperCAmelCase_			:				Optional[Any]							,   UpperCAmelCase_			:				List[str]							,   UpperCAmelCase_			:				Optional[int]							,   UpperCAmelCase_			:				Any      )->	Union[str, Any]:







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







              """simple docstring"""
              UpperCamelCase       			=		super()._prepare_for_class(UpperCAmelCase_							,   UpperCAmelCase_							,   return_labels=UpperCAmelCase_      )

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

              return inputs_dict






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







              """simple docstring"""
              UpperCamelCase       			=		XLMModelTester(self      )
              UpperCamelCase       			=		ConfigTester(self							,   config_class=UpperCAmelCase_							,   emb_dim=37      )






       def 						_SCREAMING_SNAKE_CASE							(	self			:				int      )->	int:







              """simple docstring"""
              self.config_tester.run_common_tests()






       def 						_SCREAMING_SNAKE_CASE							(	self			:				Optional[Any]      )->	Dict:







              """simple docstring"""
              UpperCamelCase       			=		self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_xlm_model(*UpperCAmelCase_      )






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







              """simple docstring"""
              UpperCamelCase       			=		self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_xlm_lm_head(*UpperCAmelCase_      )






       def 						_SCREAMING_SNAKE_CASE							(	self			:				Dict      )->	Optional[Any]:







              """simple docstring"""
              UpperCamelCase       			=		self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_xlm_simple_qa(*UpperCAmelCase_      )






       def 						_SCREAMING_SNAKE_CASE							(	self			:				List[str]      )->	Any:







              """simple docstring"""
              UpperCamelCase       			=		self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_xlm_qa(*UpperCAmelCase_      )






       def 						_SCREAMING_SNAKE_CASE							(	self			:				Dict      )->	str:







              """simple docstring"""
              UpperCamelCase       			=		self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_xlm_sequence_classif(*UpperCAmelCase_      )






       def 						_SCREAMING_SNAKE_CASE							(	self			:				Optional[int]      )->	str:







              """simple docstring"""
              UpperCamelCase       			=		self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_xlm_token_classif(*UpperCAmelCase_      )






       def 						_SCREAMING_SNAKE_CASE							(	self			:				Tuple      )->	Any:







              """simple docstring"""
              UpperCamelCase       			=		self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_xlm_for_multiple_choice(*UpperCAmelCase_      )






       def 						_SCREAMING_SNAKE_CASE							(	self			:				Optional[int]							,   UpperCAmelCase_			:				Optional[Any]							,   UpperCAmelCase_			:				Optional[Any]							,   UpperCAmelCase_			:				Any							,   UpperCAmelCase_			:				str							,   UpperCAmelCase_			:				Any							,   UpperCAmelCase_			:				Union[str, Any]=False							,   UpperCAmelCase_			:				Any=1      )->	Dict:







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

              for idx, iter_attentions in enumerate(UpperCAmelCase_      ):
                     # adds PAD dummy token
                     UpperCamelCase       			=		min_length + idx + 1
                     UpperCamelCase       			=		min_length + idx + 1

                     UpperCamelCase       			=		(
                         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(UpperCAmelCase_      )      )






       def 						_SCREAMING_SNAKE_CASE							(	self			:				str							,   UpperCAmelCase_			:				Optional[Any]							,   UpperCAmelCase_			:				Tuple							,   UpperCAmelCase_			:				Dict							,   UpperCAmelCase_			:				List[str]							,   UpperCAmelCase_			:				Tuple							,   UpperCAmelCase_			:				Dict=False							,   UpperCAmelCase_			:				int=1      )->	Union[str, Any]:







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

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






       @slow
       def 						_SCREAMING_SNAKE_CASE							(	self			:				Any      )->	Dict:







              """simple docstring"""
              for model_name in XLM_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                     UpperCamelCase       			=		XLMModel.from_pretrained(UpperCAmelCase_      )
                     self.assertIsNotNone(UpperCAmelCase_      )





@require_torch
class 	__a	(   unittest.TestCase						):






       @slow
       def 						_SCREAMING_SNAKE_CASE							(	self			:				Optional[Any]      )->	Optional[Any]:







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







"""simple docstring"""


class 	__a	:






       def __init__(	self			:				Any							,   UpperCAmelCase_			:				List[str]							,   UpperCAmelCase_			:				Optional[Any]							,   UpperCAmelCase_			:				Optional[Any]      )->	Optional[int]:







              """simple docstring"""
              UpperCamelCase       			=		name
              UpperCamelCase       			=		value
              UpperCamelCase       			=		weight






       def __repr__(	self			:				int      )->	Any:







              """simple docstring"""
              return f"{self.__class__.__name__}({self.name}, {self.value}, {self.weight})"






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







              """simple docstring"""
              return self.value






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







              """simple docstring"""
              return self.name






       def 						_SCREAMING_SNAKE_CASE							(	self			:				Tuple      )->	List[Any]:







              """simple docstring"""
              return self.weight






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







              """simple docstring"""
              return self.value / self.weight





def 						lowerCamelCase__      (				UpperCAmelCase_		,   UpperCAmelCase_		,   UpperCAmelCase_					)->				Union[str, Any]:







       """simple docstring"""
       UpperCamelCase       			=		[]
       for i in range(len(UpperCAmelCase_					)					):
              menu.append(Things(name[i]		,   value[i]		,   weight[i]					)					)
       return menu



def 						lowerCamelCase__      (				UpperCAmelCase_		,   UpperCAmelCase_		,   UpperCAmelCase_					)->				Dict:







       """simple docstring"""
       UpperCamelCase       			=		sorted(UpperCAmelCase_		,   key=UpperCAmelCase_		,   reverse=UpperCAmelCase_					)
       UpperCamelCase       			=		[]
       UpperCamelCase			,							UpperCamelCase       			=		0.0, 0.0
       for i in range(len(UpperCAmelCase_					)					):
              if (total_cost + items_copy[i].get_weight()) <= max_cost:
                     result.append(items_copy[i]					)
                     total_cost += items_copy[i].get_weight()
                     total_value += items_copy[i].get_value()
       return (result, total_value)



def 						lowerCamelCase__      (				)->				Dict:







       """simple docstring"""


if __name__ == "__main__":
      import doctest

      doctest.testmod()





