'''simple docstring'''




import unittest

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

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 (
      ErnieMForInformationExtraction,
      ErnieMForMultipleChoice,
      ErnieMForQuestionAnswering,
      ErnieMForSequenceClassification,
      ErnieMForTokenClassification,
      ErnieMModel,
  )
  from transformers.models.ernie_m.modeling_ernie_m import ERNIE_M_PRETRAINED_MODEL_ARCHIVE_LIST




class       __UpperCAmelCase							:





       '''simple docstring'''



       def __init__( self       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE=13       ,	_SCREAMING_SNAKE_CASE=7       ,	_SCREAMING_SNAKE_CASE=True       ,	_SCREAMING_SNAKE_CASE=True       ,	_SCREAMING_SNAKE_CASE=True       ,	_SCREAMING_SNAKE_CASE=99       ,	_SCREAMING_SNAKE_CASE=32       ,	_SCREAMING_SNAKE_CASE=5       ,	_SCREAMING_SNAKE_CASE=4       ,	_SCREAMING_SNAKE_CASE=37       ,	_SCREAMING_SNAKE_CASE="gelu"       ,	_SCREAMING_SNAKE_CASE=0.1       ,	_SCREAMING_SNAKE_CASE=0.1       ,	_SCREAMING_SNAKE_CASE=512       ,	_SCREAMING_SNAKE_CASE=16       ,	_SCREAMING_SNAKE_CASE=2       ,	_SCREAMING_SNAKE_CASE=0.02       ,	_SCREAMING_SNAKE_CASE=3       ,	_SCREAMING_SNAKE_CASE=4       ,	_SCREAMING_SNAKE_CASE=None       ,	)						->	List[str]:
           A_      =  parent
           A_      =  batch_size
           A_      =  seq_length
           A_      =  is_training
           A_      =  use_input_mask
           A_      =  use_labels
           A_      =  vocab_size
           A_      =  hidden_size
           A_      =  num_hidden_layers
           A_      =  num_attention_heads
           A_      =  intermediate_size
           A_      =  hidden_act
           A_      =  hidden_dropout_prob
           A_      =  attention_probs_dropout_prob
           A_      =  max_position_embeddings
           A_      =  type_vocab_size
           A_      =  type_sequence_label_size
           A_      =  initializer_range
           A_      =  num_labels
           A_      =  num_choices
           A_      =  scope

       def    __A			( self					)						->	Optional[Any]:
           A_      =  ids_tensor([self.batch_size, self.seq_length]       ,	self.vocab_size					)

           A_      =  None
           if self.use_input_mask:
               A_      =  random_attention_mask([self.batch_size, self.seq_length]					)

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

           A_      =  self.get_config()

           return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels

       def    __A			( self					)						->	Union[str, Any]:
           A_      =  ids_tensor([self.batch_size, self.seq_length]       ,	self.vocab_size					)

           A_      =  None
           if self.use_input_mask:
               A_      =  random_attention_mask([self.batch_size, self.seq_length]					)
           A_      =  self.get_config()

           return config, input_ids, input_mask

       def    __A			( self					)						->	Optional[Any]:
           return ErnieMConfig(
               vocab_size=self.vocab_size       ,	hidden_size=self.hidden_size       ,	num_hidden_layers=self.num_hidden_layers       ,	num_attention_heads=self.num_attention_heads       ,	intermediate_size=self.intermediate_size       ,	hidden_act=self.hidden_act       ,	hidden_dropout_prob=self.hidden_dropout_prob       ,	attention_probs_dropout_prob=self.attention_probs_dropout_prob       ,	max_position_embeddings=self.max_position_embeddings       ,	type_vocab_size=self.type_vocab_size       ,	initializer_range=self.initializer_range       ,	)

       def    __A			( self       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE					)						->	Dict:
           A_      =  ErnieMModel(config=_SCREAMING_SNAKE_CASE					)
           model.to(_SCREAMING_SNAKE_CASE					)
           model.eval()
           A_      =  model(_SCREAMING_SNAKE_CASE       ,	return_dict=_SCREAMING_SNAKE_CASE					)
           self.parent.assertEqual(result.last_hidden_state.shape       ,	(self.batch_size, self.seq_length, self.hidden_size)					)

       def    __A			( self       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE					)						->	int:
           A_      =  ErnieMForQuestionAnswering(config=_SCREAMING_SNAKE_CASE					)
           model.to(_SCREAMING_SNAKE_CASE					)
           model.eval()
           A_      =  model(
               _SCREAMING_SNAKE_CASE       ,	attention_mask=_SCREAMING_SNAKE_CASE       ,	start_positions=_SCREAMING_SNAKE_CASE       ,	end_positions=_SCREAMING_SNAKE_CASE       ,	)
           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    __A			( self       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE					)						->	Tuple:
           A_      =  ErnieMForInformationExtraction(config=_SCREAMING_SNAKE_CASE					)
           model.to(_SCREAMING_SNAKE_CASE					)
           model.eval()
           A_      =  torch.ones_like(_SCREAMING_SNAKE_CASE       ,	dtype=torch.floataa					)
           A_      =  model(
               _SCREAMING_SNAKE_CASE       ,	attention_mask=_SCREAMING_SNAKE_CASE       ,	start_positions=_SCREAMING_SNAKE_CASE       ,	end_positions=_SCREAMING_SNAKE_CASE       ,	)
           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    __A			( self       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE					)						->	Optional[Any]:
           A_      =  self.num_labels
           A_      =  ErnieMForSequenceClassification(_SCREAMING_SNAKE_CASE					)
           model.to(_SCREAMING_SNAKE_CASE					)
           model.eval()
           A_      =  model(_SCREAMING_SNAKE_CASE       ,	attention_mask=_SCREAMING_SNAKE_CASE       ,	labels=_SCREAMING_SNAKE_CASE					)
           self.parent.assertEqual(result.logits.shape       ,	(self.batch_size, self.num_labels)					)

       def    __A			( self       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE					)						->	Optional[Any]:
           A_      =  self.num_labels
           A_      =  ErnieMForTokenClassification(config=_SCREAMING_SNAKE_CASE					)
           model.to(_SCREAMING_SNAKE_CASE					)
           model.eval()
           input_ids.to(_SCREAMING_SNAKE_CASE					)
           input_mask.to(_SCREAMING_SNAKE_CASE					)
           token_labels.to(_SCREAMING_SNAKE_CASE					)

           A_      =  model(_SCREAMING_SNAKE_CASE       ,	attention_mask=_SCREAMING_SNAKE_CASE       ,	labels=_SCREAMING_SNAKE_CASE					)

           self.parent.assertEqual(result.logits.shape       ,	(self.batch_size, self.seq_length, self.num_labels)					)

       def    __A			( self       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE					)						->	Any:
           A_      =  self.num_choices
           A_      =  ErnieMForMultipleChoice(config=_SCREAMING_SNAKE_CASE					)
           model.to(_SCREAMING_SNAKE_CASE					)
           model.eval()
           A_      =  input_ids.unsqueeze(1					).expand(-1       ,	self.num_choices       ,	-1					).contiguous()
           A_      =  input_mask.unsqueeze(1					).expand(-1       ,	self.num_choices       ,	-1					).contiguous()
           A_      =  model(
               _SCREAMING_SNAKE_CASE       ,	attention_mask=_SCREAMING_SNAKE_CASE       ,	labels=_SCREAMING_SNAKE_CASE       ,	)
           self.parent.assertEqual(result.logits.shape       ,	(self.batch_size, self.num_choices)					)

       def    __A			( self					)						->	int:
           A_      =  self.prepare_config_and_inputs()
           (
               (
               A_
           )  ,(
               A_
           )  ,(
               A_
           )  ,(
               A_
           )  ,(
               A_
           )  ,(
               A_
           )  ,
           )      =  config_and_inputs
           A_      =  {'''input_ids''': input_ids, '''attention_mask''': input_mask}
           return config, inputs_dict




@require_torch
class       __UpperCAmelCase							(							_UpperCamelCase		, _UpperCamelCase		, unittest.TestCase	):





       '''simple docstring'''



       __lowercase   :   Optional[Any]  					=							(
           (
               ErnieMModel,
               ErnieMForMultipleChoice,
               ErnieMForQuestionAnswering,
               ErnieMForSequenceClassification,
               ErnieMForTokenClassification,
           )
           if is_torch_available()
           else ()
       )
       __lowercase   :   Optional[int]  					=							()
       __lowercase   :   Dict  					=							(
           {
               'feature-extraction': ErnieMModel,
               'question-answering': ErnieMForQuestionAnswering,
               'text-classification': ErnieMForSequenceClassification,
               'token-classification': ErnieMForTokenClassification,
               'zero-shot': ErnieMForSequenceClassification,
           }
           if is_torch_available()
           else {}
       )
       __lowercase   :   List[Any]  					=							False

       def    __A			( self       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE       ,	_SCREAMING_SNAKE_CASE					)						->	Optional[int]:
           if pipeline_test_casse_name == "QAPipelineTests":
               return True

           return False

       def    __A			( self					)						->	str:
           A_      =  ErnieMModelTester(self					)
           A_      =  ConfigTester(self       ,	config_class=_SCREAMING_SNAKE_CASE       ,	hidden_size=37					)

       def    __A			( self					)						->	Union[str, Any]:
           self.config_tester.run_common_tests()

       def    __A			( self					)						->	Dict:
           A_      =  self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_model(*_SCREAMING_SNAKE_CASE					)

       def    __A			( self					)						->	Dict:
           A_      =  self.model_tester.prepare_config_and_inputs()
           for type in ["absolute", "relative_key", "relative_key_query"]:
               A_      =  type
               self.model_tester.create_and_check_model(*_SCREAMING_SNAKE_CASE					)

       def    __A			( self					)						->	Union[str, Any]:
           A_      =  self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_multiple_choice(*_SCREAMING_SNAKE_CASE					)

       def    __A			( self					)						->	Dict:
           A_      =  self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_question_answering(*_SCREAMING_SNAKE_CASE					)

       def    __A			( self					)						->	Union[str, Any]:
           A_      =  self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_sequence_classification(*_SCREAMING_SNAKE_CASE					)

       def    __A			( self					)						->	Optional[Any]:
           A_      =  self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_information_extraction(*_SCREAMING_SNAKE_CASE					)

       def    __A			( self					)						->	Dict:
           A_      =  self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_token_classification(*_SCREAMING_SNAKE_CASE					)

       @slow
       def    __A			( self					)						->	Dict:
           for model_name in ERNIE_M_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
               A_      =  ErnieMModel.from_pretrained(_SCREAMING_SNAKE_CASE					)
               self.assertIsNotNone(_SCREAMING_SNAKE_CASE					)




@require_torch
class       __UpperCAmelCase							(							unittest.TestCase	):





       '''simple docstring'''



       @slow
       def    __A			( self					)						->	List[Any]:
           A_      =  ErnieMModel.from_pretrained('''susnato/ernie-m-base_pytorch'''					)
           model.eval()
           A_      =  torch.tensor([[0, 1, 2, 3, 4, 5]]					)
           A_      =  model(_SCREAMING_SNAKE_CASE					)[0]

           # TODO Replace vocab size
           A_      =  768

           A_      =  torch.Size((1, 6, hidden_size)					)
           self.assertEqual(output.shape       ,	_SCREAMING_SNAKE_CASE					)

           A_      =  torch.tensor(
               [[[-0.0_012, 0.1_245, -0.0_214], [-0.0_742, 0.0_244, -0.0_771], [-0.0_333, 0.1_164, -0.1_554]]]					)

           self.assertTrue(torch.allclose(output[:, :3, :3]       ,	_SCREAMING_SNAKE_CASE       ,	atol=1E-3					)					)







'''simple docstring'''




import itertools





def 	_UpperCAmelCase       (				_UpperCamelCase       :      int = 1_00_00_00  )      -> int:
    A_      =  [1]

    for i in itertools.count(len(_UpperCamelCase  )  ):
        A_      =  0
        for j in itertools.count(1  ):
            A_      =  -1 if j % 2 == 0 else +1
            A_      =  (j * j * 3 - j) // 2
            if index > i:
                break
            item += partitions[i - index] * sign
            item %= number
            index += j
            if index > i:
                break
            item += partitions[i - index] * sign
            item %= number

        if item == 0:
            return i
        partitions.append(_UpperCamelCase  )

    return 0


if __name__ == "__main__":
  import doctest

  doctest.testmod()

  print(F"""{solution() = }""")






