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







     def __init__(							self			:			List[Any]    ,      _lowerCamelCase			:			Union[str, Any]    ,      _lowerCamelCase			:			Optional[int]=13    ,      _lowerCamelCase			:			Optional[int]=7    ,      _lowerCamelCase			:			Optional[Any]=True    ,      _lowerCamelCase			:			Optional[int]=True    ,      _lowerCamelCase			:			str=True    ,      _lowerCamelCase			:			Tuple=True    ,      _lowerCamelCase			:			Union[str, Any]=True    ,      _lowerCamelCase			:			List[str]=False    ,      _lowerCamelCase			:			Optional[int]=False    ,      _lowerCamelCase			:			Tuple=False    ,      _lowerCamelCase			:			Dict=2    ,      _lowerCamelCase			:			List[Any]=99    ,      _lowerCamelCase			:			List[str]=0    ,      _lowerCamelCase			:			Tuple=32    ,      _lowerCamelCase			:			List[Any]=5    ,      _lowerCamelCase			:			Union[str, Any]=4    ,      _lowerCamelCase			:			int=0.1    ,      _lowerCamelCase			:			Optional[int]=0.1    ,      _lowerCamelCase			:			Tuple=512    ,      _lowerCamelCase			:			str=2    ,      _lowerCamelCase			:			Tuple=0.0_2    ,      _lowerCamelCase			:			Dict=2    ,      _lowerCamelCase			:			Optional[int]=4    ,      _lowerCamelCase			:			Optional[Any]="last"    ,      _lowerCamelCase			:			List[Any]=True    ,      _lowerCamelCase			:			int=None    ,      _lowerCamelCase			:			Any=0    ,      ):
       _snake_case					     =       parent
       _snake_case					     =       batch_size
       _snake_case					     =       seq_length
       _snake_case					     =       is_training
       _snake_case					     =       use_input_lengths
       _snake_case					     =       use_token_type_ids
       _snake_case					     =       use_labels
       _snake_case					     =       gelu_activation
       _snake_case					     =       sinusoidal_embeddings
       _snake_case					     =       causal
       _snake_case					     =       asm
       _snake_case					     =       n_langs
       _snake_case					     =       vocab_size
       _snake_case					     =       n_special
       _snake_case					     =       hidden_size
       _snake_case					     =       num_hidden_layers
       _snake_case					     =       num_attention_heads
       _snake_case					     =       hidden_dropout_prob
       _snake_case					     =       attention_probs_dropout_prob
       _snake_case					     =       max_position_embeddings
       _snake_case					     =       type_sequence_label_size
       _snake_case					     =       initializer_range
       _snake_case					     =       num_labels
       _snake_case					     =       num_choices
       _snake_case					     =       summary_type
       _snake_case					     =       use_proj
       _snake_case					     =       scope
       _snake_case					     =       bos_token_id







     def      lowercase	(							self			:			Union[str, Any]			):
       _snake_case					     =       ids_tensor([self.batch_size, self.seq_length]    ,      self.vocab_size			)
       _snake_case					     =       random_attention_mask([self.batch_size, self.seq_length]			)

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

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

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

       _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      lowercase	(							self			:			int			):
       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      lowercase	(							self			:			Optional[Any]    ,      _lowerCamelCase			:			Union[str, Any]    ,      _lowerCamelCase			:			List[str]    ,      _lowerCamelCase			:			Optional[Any]    ,      _lowerCamelCase			:			List[Any]    ,      _lowerCamelCase			:			Optional[Any]    ,      _lowerCamelCase			:			str    ,      _lowerCamelCase			:			str    ,      _lowerCamelCase			:			Optional[Any]    ,      _lowerCamelCase			:			Tuple    ,      ):
       _snake_case					     =       XLMModel(config=_lowerCamelCase			)
       model.to(_lowerCamelCase			)
       model.eval()
       _snake_case					     =       model(_lowerCamelCase    ,      lengths=_lowerCamelCase    ,      langs=_lowerCamelCase			)
       _snake_case					     =       model(_lowerCamelCase    ,      langs=_lowerCamelCase			)
       _snake_case					     =       model(_lowerCamelCase			)
       self.parent.assertEqual(result.last_hidden_state.shape    ,      (self.batch_size, self.seq_length, self.hidden_size)			)







     def      lowercase	(							self			:			Any    ,      _lowerCamelCase			:			str    ,      _lowerCamelCase			:			List[Any]    ,      _lowerCamelCase			:			Tuple    ,      _lowerCamelCase			:			str    ,      _lowerCamelCase			:			List[Any]    ,      _lowerCamelCase			:			Optional[Any]    ,      _lowerCamelCase			:			int    ,      _lowerCamelCase			:			List[Any]    ,      _lowerCamelCase			:			Tuple    ,      ):
       _snake_case					     =       XLMWithLMHeadModel(_lowerCamelCase			)
       model.to(_lowerCamelCase			)
       model.eval()

       _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      lowercase	(							self			:			List[str]    ,      _lowerCamelCase			:			int    ,      _lowerCamelCase			:			int    ,      _lowerCamelCase			:			Union[str, Any]    ,      _lowerCamelCase			:			int    ,      _lowerCamelCase			:			int    ,      _lowerCamelCase			:			Optional[Any]    ,      _lowerCamelCase			:			str    ,      _lowerCamelCase			:			int    ,      _lowerCamelCase			:			Any    ,      ):
       _snake_case					     =       XLMForQuestionAnsweringSimple(_lowerCamelCase			)
       model.to(_lowerCamelCase			)
       model.eval()

       _snake_case					     =       model(_lowerCamelCase			)

       _snake_case					     =       model(_lowerCamelCase    ,      start_positions=_lowerCamelCase    ,      end_positions=_lowerCamelCase			)
       _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      lowercase	(							self			:			List[Any]    ,      _lowerCamelCase			:			Optional[int]    ,      _lowerCamelCase			:			str    ,      _lowerCamelCase			:			List[str]    ,      _lowerCamelCase			:			List[Any]    ,      _lowerCamelCase			:			List[Any]    ,      _lowerCamelCase			:			List[Any]    ,      _lowerCamelCase			:			int    ,      _lowerCamelCase			:			Optional[Any]    ,      _lowerCamelCase			:			Any    ,      ):
       _snake_case					     =       XLMForQuestionAnswering(_lowerCamelCase			)
       model.to(_lowerCamelCase			)
       model.eval()

       _snake_case					     =       model(_lowerCamelCase			)

       _snake_case					     =       model(
           _lowerCamelCase    ,      start_positions=_lowerCamelCase    ,      end_positions=_lowerCamelCase    ,      cls_index=_lowerCamelCase    ,      is_impossible=_lowerCamelCase    ,      p_mask=_lowerCamelCase    ,      )

       _snake_case					     =       model(
           _lowerCamelCase    ,      start_positions=_lowerCamelCase    ,      end_positions=_lowerCamelCase    ,      cls_index=_lowerCamelCase    ,      is_impossible=_lowerCamelCase    ,      )

       ((_snake_case)     ,					)					     =       result_with_labels.to_tuple()

       _snake_case					     =       model(_lowerCamelCase    ,      start_positions=_lowerCamelCase    ,      end_positions=_lowerCamelCase			)

       ((_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      lowercase	(							self			:			Tuple    ,      _lowerCamelCase			:			List[Any]    ,      _lowerCamelCase			:			int    ,      _lowerCamelCase			:			Dict    ,      _lowerCamelCase			:			List[str]    ,      _lowerCamelCase			:			Tuple    ,      _lowerCamelCase			:			Optional[int]    ,      _lowerCamelCase			:			int    ,      _lowerCamelCase			:			Any    ,      _lowerCamelCase			:			str    ,      ):
       _snake_case					     =       XLMForSequenceClassification(_lowerCamelCase			)
       model.to(_lowerCamelCase			)
       model.eval()

       _snake_case					     =       model(_lowerCamelCase			)
       _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      lowercase	(							self			:			Any    ,      _lowerCamelCase			:			List[Any]    ,      _lowerCamelCase			:			Optional[Any]    ,      _lowerCamelCase			:			int    ,      _lowerCamelCase			:			Optional[int]    ,      _lowerCamelCase			:			Union[str, Any]    ,      _lowerCamelCase			:			int    ,      _lowerCamelCase			:			str    ,      _lowerCamelCase			:			str    ,      _lowerCamelCase			:			str    ,      ):
       _snake_case					     =       self.num_labels
       _snake_case					     =       XLMForTokenClassification(_lowerCamelCase			)
       model.to(_lowerCamelCase			)
       model.eval()

       _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      lowercase	(							self			:			Any    ,      _lowerCamelCase			:			Dict    ,      _lowerCamelCase			:			List[Any]    ,      _lowerCamelCase			:			Optional[int]    ,      _lowerCamelCase			:			Optional[Any]    ,      _lowerCamelCase			:			Optional[int]    ,      _lowerCamelCase			:			List[Any]    ,      _lowerCamelCase			:			Optional[Any]    ,      _lowerCamelCase			:			str    ,      _lowerCamelCase			:			Optional[Any]    ,      ):
       _snake_case					     =       self.num_choices
       _snake_case					     =       XLMForMultipleChoice(config=_lowerCamelCase			)
       model.to(_lowerCamelCase			)
       model.eval()
       _snake_case					     =       input_ids.unsqueeze(1			).expand(-1    ,      self.num_choices    ,      -1			).contiguous()
       _snake_case					     =       token_type_ids.unsqueeze(1			).expand(-1    ,      self.num_choices    ,      -1			).contiguous()
       _snake_case					     =       input_mask.unsqueeze(1			).expand(-1    ,      self.num_choices    ,      -1			).contiguous()
       _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      lowercase	(							self			:			List[Any]			):
       _snake_case					     =       self.prepare_config_and_inputs()
       (
           (
           _snake_case
       )     ,					(
           _snake_case
       )     ,					(
           _snake_case
       )     ,					(
           _snake_case
       )     ,					(
           _snake_case
       )     ,					(
           _snake_case
       )     ,					(
           _snake_case
       )     ,					(
           _snake_case
       )     ,					(
           _snake_case
       )     ,					
       )					     =       config_and_inputs
       _snake_case					     =       {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''lengths''': input_lengths}
       return config, inputs_dict






@require_torch
class       lowerCAmelCase__				(						A_ ,	A_ ,	A_ ,	unittest.TestCase	):
     __a						=					(
         (
             XLMModel,
             XLMWithLMHeadModel,
             XLMForQuestionAnswering,
             XLMForSequenceClassification,
             XLMForQuestionAnsweringSimple,
             XLMForTokenClassification,
             XLMForMultipleChoice,
         )
         if is_torch_available()
         else ()
     )
     __a						=					(
         (XLMWithLMHeadModel,) if is_torch_available() else ()
     )  # TODO (PVP): Check other models whether language generation is also applicable
     __a						=					(
         {
             """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      lowercase	(							self			:			Tuple    ,      _lowerCamelCase			:			Dict    ,      _lowerCamelCase			:			Tuple    ,      _lowerCamelCase			:			Optional[Any]    ,      _lowerCamelCase			:			Union[str, Any]    ,      _lowerCamelCase			:			str			):
       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      lowercase	(							self			:			str    ,      _lowerCamelCase			:			List[str]    ,      _lowerCamelCase			:			str    ,      _lowerCamelCase			:			List[str]=False			):
       _snake_case					     =       super()._prepare_for_class(_lowerCamelCase    ,      _lowerCamelCase    ,      return_labels=_lowerCamelCase			)

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

       return inputs_dict







     def      lowercase	(							self			:			Optional[Any]			):
       _snake_case					     =       XLMModelTester(self			)
       _snake_case					     =       ConfigTester(self    ,      config_class=_lowerCamelCase    ,      emb_dim=37			)







     def      lowercase	(							self			:			List[Any]			):
       self.config_tester.run_common_tests()







     def      lowercase	(							self			:			Optional[int]			):
       _snake_case					     =       self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_xlm_model(*_lowerCamelCase			)







     def      lowercase	(							self			:			Optional[int]			):
       _snake_case					     =       self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_xlm_lm_head(*_lowerCamelCase			)







     def      lowercase	(							self			:			Any			):
       _snake_case					     =       self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_xlm_simple_qa(*_lowerCamelCase			)







     def      lowercase	(							self			:			int			):
       _snake_case					     =       self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_xlm_qa(*_lowerCamelCase			)







     def      lowercase	(							self			:			Union[str, Any]			):
       _snake_case					     =       self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_xlm_sequence_classif(*_lowerCamelCase			)







     def      lowercase	(							self			:			Union[str, Any]			):
       _snake_case					     =       self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_xlm_token_classif(*_lowerCamelCase			)







     def      lowercase	(							self			:			Tuple			):
       _snake_case					     =       self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_xlm_for_multiple_choice(*_lowerCamelCase			)







     def      lowercase	(							self			:			Any    ,      _lowerCamelCase			:			Optional[Any]    ,      _lowerCamelCase			:			Any    ,      _lowerCamelCase			:			int    ,      _lowerCamelCase			:			List[str]    ,      _lowerCamelCase			:			Union[str, Any]    ,      _lowerCamelCase			:			Union[str, Any]=False    ,      _lowerCamelCase			:			int=1			):
       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
         _snake_case					     =       min_length + idx + 1
         _snake_case					     =       min_length + idx + 1

         _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      lowercase	(							self			:			List[str]    ,      _lowerCamelCase			:			Dict    ,      _lowerCamelCase			:			Tuple    ,      _lowerCamelCase			:			Tuple    ,      _lowerCamelCase			:			Optional[int]    ,      _lowerCamelCase			:			Optional[int]    ,      _lowerCamelCase			:			Dict=False    ,      _lowerCamelCase			:			List[Any]=1			):
       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
         _snake_case					     =       min_length + idx + 1
         _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      lowercase	(							self			:			Dict			):
       for model_name in XLM_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
         _snake_case					     =       XLMModel.from_pretrained(_lowerCamelCase			)
         self.assertIsNotNone(_lowerCamelCase			)






@require_torch
class       lowerCAmelCase__				(						unittest.TestCase	):







     @slow
     def      lowercase	(							self			:			List[str]			):
       _snake_case					     =       XLMWithLMHeadModel.from_pretrained('''xlm-mlm-en-2048'''			)
       model.to(_lowerCamelCase			)
       _snake_case					     =       torch.tensor([[14, 447]]    ,      dtype=torch.long    ,      device=_lowerCamelCase			)  # the president
       _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
       _snake_case					     =       model.generate(_lowerCamelCase    ,      do_sample=_lowerCamelCase			)
       self.assertListEqual(output_ids[0].cpu().numpy().tolist()    ,      _lowerCamelCase			)





"""simple docstring"""



from math import sqrt
def 					_UpperCAmelCase      ( __lowerCamelCase   :       int = 1_00_00_00		)     ->					int:
  _snake_case					     =       0
  _snake_case					     =       0
  _snake_case					     =       42

  while num_cuboids <= limit:
    max_cuboid_size += 1
    for sum_shortest_sides in range(2 ,					2 * max_cuboid_size + 1		):
      if sqrt(sum_shortest_sides**2 + max_cuboid_size**2		).is_integer():
        num_cuboids += (
            min(__lowerCamelCase ,					sum_shortest_sides // 2		)
            - max(1 ,					sum_shortest_sides - max_cuboid_size		)
            + 1
        )

  return max_cuboid_size


if __name__ == "__main__":
 print(F"{solution() = }")



