"""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]   ,				__lowerCAmelCase	:  int   ,				__lowerCAmelCase	:  str=13   ,				__lowerCAmelCase	:  List[str]=7   ,				__lowerCAmelCase	:  str=True   ,				__lowerCAmelCase	:  Optional[int]=True   ,				__lowerCAmelCase	:  List[str]=True   ,				__lowerCAmelCase	:  int=True   ,				__lowerCAmelCase	:  Tuple=True   ,				__lowerCAmelCase	:  str=False   ,				__lowerCAmelCase	:  Tuple=False   ,				__lowerCAmelCase	:  Optional[Any]=False   ,				__lowerCAmelCase	:  List[Any]=2   ,				__lowerCAmelCase	:  Union[str, Any]=99   ,				__lowerCAmelCase	:  Union[str, Any]=0   ,				__lowerCAmelCase	:  int=32   ,				__lowerCAmelCase	:  Optional[int]=5   ,				__lowerCAmelCase	:  Union[str, Any]=4   ,				__lowerCAmelCase	:  Optional[Any]=0.1   ,				__lowerCAmelCase	:  Dict=0.1   ,				__lowerCAmelCase	:  Union[str, Any]=512   ,				__lowerCAmelCase	:  Any=2   ,				__lowerCAmelCase	:  int=0.02   ,				__lowerCAmelCase	:  str=2   ,				__lowerCAmelCase	:  Dict=4   ,				__lowerCAmelCase	:  Dict="last"   ,				__lowerCAmelCase	:  List[str]=True   ,				__lowerCAmelCase	:  Union[str, Any]=None   ,				__lowerCAmelCase	:  Optional[Any]=0   ,				):
      _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      lowerCAmelCase_  (					self	:  Dict					):
      _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      lowerCAmelCase_  (					self	:  Union[str, Any]					):
      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      lowerCAmelCase_  (					self	:  Optional[Any]   ,				__lowerCAmelCase	:  Any   ,				__lowerCAmelCase	:  int   ,				__lowerCAmelCase	:  List[Any]   ,				__lowerCAmelCase	:  Tuple   ,				__lowerCAmelCase	:  List[str]   ,				__lowerCAmelCase	:  Optional[int]   ,				__lowerCAmelCase	:  Tuple   ,				__lowerCAmelCase	:  Optional[int]   ,				__lowerCAmelCase	:  str   ,				):
      _UpperCAmelCase						 =      XLMModel(config=__lowerCAmelCase					)
      model.to(__lowerCAmelCase					)
      model.eval()
      _UpperCAmelCase						 =      model(__lowerCAmelCase   ,				lengths=__lowerCAmelCase   ,				langs=__lowerCAmelCase					)
      _UpperCAmelCase						 =      model(__lowerCAmelCase   ,				langs=__lowerCAmelCase					)
      _UpperCAmelCase						 =      model(__lowerCAmelCase					)
      self.parent.assertEqual(result.last_hidden_state.shape   ,				(self.batch_size, self.seq_length, self.hidden_size)					)


    def      lowerCAmelCase_  (					self	:  Union[str, Any]   ,				__lowerCAmelCase	:  str   ,				__lowerCAmelCase	:  Optional[int]   ,				__lowerCAmelCase	:  Optional[int]   ,				__lowerCAmelCase	:  Tuple   ,				__lowerCAmelCase	:  Any   ,				__lowerCAmelCase	:  str   ,				__lowerCAmelCase	:  Optional[int]   ,				__lowerCAmelCase	:  List[Any]   ,				__lowerCAmelCase	:  str   ,				):
      _UpperCAmelCase						 =      XLMWithLMHeadModel(__lowerCAmelCase					)
      model.to(__lowerCAmelCase					)
      model.eval()

      _UpperCAmelCase						 =      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      lowerCAmelCase_  (					self	:  int   ,				__lowerCAmelCase	:  Any   ,				__lowerCAmelCase	:  Optional[Any]   ,				__lowerCAmelCase	:  Any   ,				__lowerCAmelCase	:  Tuple   ,				__lowerCAmelCase	:  Optional[int]   ,				__lowerCAmelCase	:  Any   ,				__lowerCAmelCase	:  Dict   ,				__lowerCAmelCase	:  Optional[int]   ,				__lowerCAmelCase	:  Dict   ,				):
      _UpperCAmelCase						 =      XLMForQuestionAnsweringSimple(__lowerCAmelCase					)
      model.to(__lowerCAmelCase					)
      model.eval()

      _UpperCAmelCase						 =      model(__lowerCAmelCase					)

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

      _UpperCAmelCase						 =      model(__lowerCAmelCase					)

      _UpperCAmelCase						 =      model(
          __lowerCAmelCase   ,				start_positions=__lowerCAmelCase   ,				end_positions=__lowerCAmelCase   ,				cls_index=__lowerCAmelCase   ,				is_impossible=__lowerCAmelCase   ,				p_mask=__lowerCAmelCase   ,				)

      _UpperCAmelCase						 =      model(
          __lowerCAmelCase   ,				start_positions=__lowerCAmelCase   ,				end_positions=__lowerCAmelCase   ,				cls_index=__lowerCAmelCase   ,				is_impossible=__lowerCAmelCase   ,				)

      ((_UpperCAmelCase) ,				)						 =      result_with_labels.to_tuple()

      _UpperCAmelCase						 =      model(__lowerCAmelCase   ,				start_positions=__lowerCAmelCase   ,				end_positions=__lowerCAmelCase					)

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

      _UpperCAmelCase						 =      model(__lowerCAmelCase					)
      _UpperCAmelCase						 =      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      lowerCAmelCase_  (					self	:  Optional[Any]   ,				__lowerCAmelCase	:  int   ,				__lowerCAmelCase	:  int   ,				__lowerCAmelCase	:  Dict   ,				__lowerCAmelCase	:  str   ,				__lowerCAmelCase	:  Optional[int]   ,				__lowerCAmelCase	:  Optional[Any]   ,				__lowerCAmelCase	:  Optional[Any]   ,				__lowerCAmelCase	:  List[str]   ,				__lowerCAmelCase	:  Tuple   ,				):
      _UpperCAmelCase						 =      self.num_labels
      _UpperCAmelCase						 =      XLMForTokenClassification(__lowerCAmelCase					)
      model.to(__lowerCAmelCase					)
      model.eval()

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


    def      lowerCAmelCase_  (					self	:  Optional[Any]   ,				__lowerCAmelCase	:  List[Any]   ,				__lowerCAmelCase	:  str   ,				__lowerCAmelCase	:  List[Any]   ,				__lowerCAmelCase	:  str   ,				__lowerCAmelCase	:  Any   ,				__lowerCAmelCase	:  Optional[int]   ,				__lowerCAmelCase	:  List[Any]   ,				__lowerCAmelCase	:  List[Any]   ,				__lowerCAmelCase	:  Tuple   ,				):
      _UpperCAmelCase						 =      self.num_choices
      _UpperCAmelCase						 =      XLMForMultipleChoice(config=__lowerCAmelCase					)
      model.to(__lowerCAmelCase					)
      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(
          __lowerCAmelCase   ,				attention_mask=__lowerCAmelCase   ,				token_type_ids=__lowerCAmelCase   ,				labels=__lowerCAmelCase   ,				)
      self.parent.assertEqual(result.logits.shape   ,				(self.batch_size, self.num_choices)					)


    def      lowerCAmelCase_  (					self	:  Dict					):
      _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   ):
    _snake_case     :  List[Any]     							=							(
        (
            XLMModel,
            XLMWithLMHeadModel,
            XLMForQuestionAnswering,
            XLMForSequenceClassification,
            XLMForQuestionAnsweringSimple,
            XLMForTokenClassification,
            XLMForMultipleChoice,
        )
        if is_torch_available()
        else ()
    )
    _snake_case     :  Dict     							=							(
        (XLMWithLMHeadModel,) if is_torch_available() else ()
    )  # TODO (PVP): Check other models whether language generation is also applicable
    _snake_case     :  Dict     							=							(
        {
            '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      lowerCAmelCase_  (					self	:  List[Any]   ,				__lowerCAmelCase	:  int   ,				__lowerCAmelCase	:  List[Any]   ,				__lowerCAmelCase	:  str   ,				__lowerCAmelCase	:  Dict   ,				__lowerCAmelCase	:  Any					):
      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      lowerCAmelCase_  (					self	:  Dict   ,				__lowerCAmelCase	:  Union[str, Any]   ,				__lowerCAmelCase	:  Union[str, Any]   ,				__lowerCAmelCase	:  List[Any]=False					):
      _UpperCAmelCase						 =      super()._prepare_for_class(__lowerCAmelCase   ,				__lowerCAmelCase   ,				return_labels=__lowerCAmelCase					)

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

      return inputs_dict


    def      lowerCAmelCase_  (					self	:  Dict					):
      _UpperCAmelCase						 =      XLMModelTester(self					)
      _UpperCAmelCase						 =      ConfigTester(self   ,				config_class=__lowerCAmelCase   ,				emb_dim=37					)


    def      lowerCAmelCase_  (					self	:  Dict					):
      self.config_tester.run_common_tests()


    def      lowerCAmelCase_  (					self	:  Union[str, Any]					):
      _UpperCAmelCase						 =      self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_xlm_model(*__lowerCAmelCase					)


    def      lowerCAmelCase_  (					self	:  List[str]					):
      _UpperCAmelCase						 =      self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_xlm_lm_head(*__lowerCAmelCase					)


    def      lowerCAmelCase_  (					self	:  List[Any]					):
      _UpperCAmelCase						 =      self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_xlm_simple_qa(*__lowerCAmelCase					)


    def      lowerCAmelCase_  (					self	:  Tuple					):
      _UpperCAmelCase						 =      self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_xlm_qa(*__lowerCAmelCase					)


    def      lowerCAmelCase_  (					self	:  List[str]					):
      _UpperCAmelCase						 =      self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_xlm_sequence_classif(*__lowerCAmelCase					)


    def      lowerCAmelCase_  (					self	:  str					):
      _UpperCAmelCase						 =      self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_xlm_token_classif(*__lowerCAmelCase					)


    def      lowerCAmelCase_  (					self	:  str					):
      _UpperCAmelCase						 =      self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_xlm_for_multiple_choice(*__lowerCAmelCase					)


    def      lowerCAmelCase_  (					self	:  Optional[int]   ,				__lowerCAmelCase	:  str   ,				__lowerCAmelCase	:  Any   ,				__lowerCAmelCase	:  Optional[Any]   ,				__lowerCAmelCase	:  Union[str, Any]   ,				__lowerCAmelCase	:  str   ,				__lowerCAmelCase	:  List[str]=False   ,				__lowerCAmelCase	:  List[Any]=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
        _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(__lowerCAmelCase					)					)


    def      lowerCAmelCase_  (					self	:  List[str]   ,				__lowerCAmelCase	:  List[str]   ,				__lowerCAmelCase	:  Optional[Any]   ,				__lowerCAmelCase	:  Optional[Any]   ,				__lowerCAmelCase	:  Optional[int]   ,				__lowerCAmelCase	:  str   ,				__lowerCAmelCase	:  Union[str, Any]=False   ,				__lowerCAmelCase	:  List[str]=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
        _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(__lowerCAmelCase					)   ,				)
      pass


    @slow
    def      lowerCAmelCase_  (					self	:  List[Any]					):
      for model_name in XLM_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
        _UpperCAmelCase						 =      XLMModel.from_pretrained(__lowerCAmelCase					)
        self.assertIsNotNone(__lowerCAmelCase					)



@require_torch
class        a				(		unittest.TestCase   ):


    @slow
    def      lowerCAmelCase_  (					self	:  List[Any]					):
      _UpperCAmelCase						 =      XLMWithLMHeadModel.from_pretrained("""xlm-mlm-en-2048"""					)
      model.to(__lowerCAmelCase					)
      _UpperCAmelCase						 =      torch.tensor([[14, 447]]   ,				dtype=torch.long   ,				device=__lowerCAmelCase					)  # 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(__lowerCAmelCase   ,				do_sample=__lowerCAmelCase					)
      self.assertListEqual(output_ids[0].cpu().numpy().tolist()   ,				__lowerCAmelCase					)

"""simple docstring"""


def     __UpperCAmelCase					(			lowercase		):







  """simple docstring"""
  _UpperCAmelCase						 =      abs(lowercase		)
  _UpperCAmelCase						 =      0
  while n > 0:
    res += n % 10
    n //= 10
  return res






def     __UpperCAmelCase					(			lowercase		):







  """simple docstring"""
  _UpperCAmelCase						 =      abs(lowercase		)
  return n if n < 10 else n % 10 + sum_of_digits(n // 10		)






def     __UpperCAmelCase					(			lowercase		):







  """simple docstring"""
  return sum(int(lowercase		) for c in str(abs(lowercase		)		)		)






def     __UpperCAmelCase					(			):







  """simple docstring"""
  from collections.abc import Callable
  from timeit import timeit

  def benchmark_a_function(lowercase   ,lowercase		) -> None:
    _UpperCAmelCase						 =      f'''{func.__name__}({value})'''
    _UpperCAmelCase						 =      timeit(f'''__main__.{call}'''   ,setup="""import __main__"""		)
    print(f'''{call:56} = {func(lowercase		)} -- {timing:.4f} seconds'''		)

  for value in (26_21_44, 11_25_89_99_06_84_26_24, 1_26_76_50_60_02_28_22_94_01_49_67_03_20_53_76):
    for func in (sum_of_digits, sum_of_digits_recursion, sum_of_digits_compact):
      benchmark_a_function(lowercase   ,lowercase		)
    print()


if __name__ == "__main__":
    import doctest

    doctest.testmod()
    benchmark()
