





"""simple docstring"""


import unittest

from transformers import MPNetConfig, 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 (
      MPNetForMaskedLM,
      MPNetForMultipleChoice,
      MPNetForQuestionAnswering,
      MPNetForSequenceClassification,
      MPNetForTokenClassification,
      MPNetModel,
  )



class      __SCREAMING_SNAKE_CASE    :







  '''simple docstring'''


  def __init__(		self   :       int					,   __a   :       Optional[Any]					,   __a   :       str=13					,   __a   :       int=7					,   __a   :       List[Any]=True					,   __a   :       Optional[int]=True					,   __a   :       Any=False					,   __a   :       Optional[int]=True					,   __a   :       Optional[Any]=99					,   __a   :       Dict=64					,   __a   :       Union[str, Any]=5					,   __a   :       Union[str, Any]=4					,   __a   :       List[Any]=64					,   __a   :       List[Any]="gelu"					,   __a   :       Tuple=0.1					,   __a   :       Any=0.1					,   __a   :       Dict=512					,   __a   :       Optional[Any]=16					,   __a   :       str=2					,   __a   :       Union[str, Any]=0.02					,   __a   :       List[Any]=3					,   __a   :       List[Any]=4					,   __a   :       Dict=None					,   )		->				int:
        _UpperCamelCase      :	List[str]						=       parent
        _UpperCamelCase      :	Tuple						=       batch_size
        _UpperCamelCase      :	Optional[Any]						=       seq_length
        _UpperCamelCase      :	Union[str, Any]						=       is_training
        _UpperCamelCase      :	Dict						=       use_input_mask
        _UpperCamelCase      :	List[str]						=       use_token_type_ids
        _UpperCamelCase      :	Any						=       use_labels
        _UpperCamelCase      :	Optional[int]						=       vocab_size
        _UpperCamelCase      :	Tuple						=       hidden_size
        _UpperCamelCase      :	Union[str, Any]						=       num_hidden_layers
        _UpperCamelCase      :	List[Any]						=       num_attention_heads
        _UpperCamelCase      :	Dict						=       intermediate_size
        _UpperCamelCase      :	int						=       hidden_act
        _UpperCamelCase      :	Optional[int]						=       hidden_dropout_prob
        _UpperCamelCase      :	Dict						=       attention_probs_dropout_prob
        _UpperCamelCase      :	Any						=       max_position_embeddings
        _UpperCamelCase      :	Dict						=       type_vocab_size
        _UpperCamelCase      :	str						=       type_sequence_label_size
        _UpperCamelCase      :	Optional[Any]						=       initializer_range
        _UpperCamelCase      :	List[Any]						=       num_labels
        _UpperCamelCase      :	int						=       num_choices
        _UpperCamelCase      :	List[Any]						=       scope

  def    __SCREAMING_SNAKE_CASE				(		self   :       int	)		->				str:
        return MPNetConfig.from_pretrained("microsoft/mpnet-base"	)

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

        _UpperCamelCase      :	Tuple						=       None
        if self.use_input_mask:
              _UpperCamelCase      :	List[str]						=       random_attention_mask([self.batch_size, self.seq_length]	)

        _UpperCamelCase      :	Dict						=       None
        _UpperCamelCase      :	Tuple						=       None
        _UpperCamelCase      :	Optional[int]						=       None
        if self.use_labels:
              _UpperCamelCase      :	str						=       ids_tensor([self.batch_size]					,   self.type_sequence_label_size	)
              _UpperCamelCase      :	List[str]						=       ids_tensor([self.batch_size, self.seq_length]					,   self.num_labels	)
              _UpperCamelCase      :	Optional[int]						=       ids_tensor([self.batch_size]					,   self.num_choices	)

        _UpperCamelCase      :	List[str]						=       self.get_config()
        return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels

  def    __SCREAMING_SNAKE_CASE				(		self   :       Tuple	)		->				str:
        return MPNetConfig(
            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					,   initializer_range=self.initializer_range					,   )

  def    __SCREAMING_SNAKE_CASE				(		self   :       Dict					,   __a   :       Optional[Any]					,   __a   :       Optional[Any]					,   __a   :       Union[str, Any]					,   __a   :       Dict					,   __a   :       int					,   __a   :       List[Any]	)		->				Optional[Any]:
        _UpperCamelCase      :	str						=       MPNetModel(config=__a	)
        model.to(__a	)
        model.eval()
        _UpperCamelCase      :	Optional[int]						=       model(__a					,   __a	)
        _UpperCamelCase      :	List[Any]						=       model(__a	)
        self.parent.assertEqual(result.last_hidden_state.shape					,   (self.batch_size, self.seq_length, self.hidden_size)	)
        self.parent.assertEqual(result.pooler_output.shape					,   (self.batch_size, self.hidden_size)	)

  def    __SCREAMING_SNAKE_CASE				(		self   :       Tuple					,   __a   :       Optional[int]					,   __a   :       Union[str, Any]					,   __a   :       Any					,   __a   :       Optional[int]					,   __a   :       List[Any]					,   __a   :       str	)		->				str:
        _UpperCamelCase      :	Tuple						=       MPNetForQuestionAnswering(config=__a	)
        model.to(__a	)
        model.eval()
        _UpperCamelCase      :	List[str]						=       model(
            __a					,   attention_mask=__a					,   start_positions=__a					,   end_positions=__a					,   )
        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   :       Union[str, Any]					,   __a   :       Dict					,   __a   :       int					,   __a   :       Optional[Any]					,   __a   :       Optional[Any]					,   __a   :       List[str]					,   __a   :       Optional[int]	)		->				Dict:
        _UpperCamelCase      :	str						=       self.num_labels
        _UpperCamelCase      :	List[str]						=       MPNetForSequenceClassification(__a	)
        model.to(__a	)
        model.eval()
        _UpperCamelCase      :	Any						=       model(__a					,   attention_mask=__a					,   labels=__a	)
        self.parent.assertEqual(result.logits.shape					,   (self.batch_size, self.num_labels)	)

  def    __SCREAMING_SNAKE_CASE				(		self   :       int					,   __a   :       Tuple					,   __a   :       Any					,   __a   :       Dict					,   __a   :       Optional[int]					,   __a   :       str					,   __a   :       str	)		->				List[str]:
        _UpperCamelCase      :	int						=       self.num_choices
        _UpperCamelCase      :	Any						=       MPNetForMultipleChoice(config=__a	)
        model.to(__a	)
        model.eval()
        _UpperCamelCase      :	Any						=       input_ids.unsqueeze(1	).expand(-1					,   self.num_choices					,   -1	).contiguous()
        _UpperCamelCase      :	Optional[int]						=       input_mask.unsqueeze(1	).expand(-1					,   self.num_choices					,   -1	).contiguous()
        _UpperCamelCase      :	Any						=       model(
            __a					,   attention_mask=__a					,   labels=__a					,   )
        self.parent.assertEqual(result.logits.shape					,   (self.batch_size, self.num_choices)	)

  def    __SCREAMING_SNAKE_CASE				(		self   :       str					,   __a   :       List[Any]					,   __a   :       Union[str, Any]					,   __a   :       str					,   __a   :       Any					,   __a   :       List[str]					,   __a   :       List[str]	)		->				Optional[int]:
        _UpperCamelCase      :	Tuple						=       self.num_labels
        _UpperCamelCase      :	List[Any]						=       MPNetForTokenClassification(config=__a	)
        model.to(__a	)
        model.eval()
        _UpperCamelCase      :	Dict						=       model(__a					,   attention_mask=__a					,   labels=__a	)
        self.parent.assertEqual(result.logits.shape					,   (self.batch_size, self.seq_length, self.num_labels)	)


  def    __SCREAMING_SNAKE_CASE				(		self   :       Optional[Any]	)		->				Optional[int]:
        _UpperCamelCase      :	str						=       self.prepare_config_and_inputs()
        ((_UpperCamelCase),  (_UpperCamelCase),  (_UpperCamelCase),  (_UpperCamelCase),  (_UpperCamelCase),  (_UpperCamelCase))      :	List[str]						=       config_and_inputs
        _UpperCamelCase      :	Union[str, Any]						=       {"input_ids": input_ids, "attention_mask": input_mask}
        return config, inputs_dict





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







  '''simple docstring'''


  SCREAMING_SNAKE_CASE__							:Optional[Any]	     =					(
      (
          MPNetForMaskedLM,
          MPNetForMultipleChoice,
          MPNetForQuestionAnswering,
          MPNetForSequenceClassification,
          MPNetForTokenClassification,
          MPNetModel,
      )
      if is_torch_available()
      else ()
  )
  SCREAMING_SNAKE_CASE__							:Dict	     =					(
      {
          "feature-extraction": MPNetModel,
          "fill-mask": MPNetForMaskedLM,
          "question-answering": MPNetForQuestionAnswering,
          "text-classification": MPNetForSequenceClassification,
          "token-classification": MPNetForTokenClassification,
          "zero-shot": MPNetForSequenceClassification,
      }
      if is_torch_available()
      else {}
  )
  SCREAMING_SNAKE_CASE__							:int	     =					False
  SCREAMING_SNAKE_CASE__							:Union[str, Any]	     =					True

  def    __SCREAMING_SNAKE_CASE				(		self   :       Optional[Any]	)		->				Tuple:
        _UpperCamelCase      :	int						=       MPNetModelTester(self	)
        _UpperCamelCase      :	str						=       ConfigTester(self					,   config_class=__a					,   hidden_size=37	)

  def    __SCREAMING_SNAKE_CASE				(		self   :       Any	)		->				Any:
        self.config_tester.run_common_tests()

  def    __SCREAMING_SNAKE_CASE				(		self   :       List[Any]	)		->				Tuple:
        _UpperCamelCase      :	Tuple						=       self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_mpnet_model(*__a	)

  def    __SCREAMING_SNAKE_CASE				(		self   :       int	)		->				str:
        _UpperCamelCase      :	int						=       self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_mpnet_for_sequence_classification(*__a	)

  def    __SCREAMING_SNAKE_CASE				(		self   :       int	)		->				List[str]:
        _UpperCamelCase      :	Tuple						=       self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_mpnet_for_multiple_choice(*__a	)

  def    __SCREAMING_SNAKE_CASE				(		self   :       Dict	)		->				int:
        _UpperCamelCase      :	Tuple						=       self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_mpnet_for_token_classification(*__a	)


  def    __SCREAMING_SNAKE_CASE				(		self   :       List[str]	)		->				List[Any]:
        _UpperCamelCase      :	int						=       self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_mpnet_for_question_answering(*__a	)





@require_torch
class      __SCREAMING_SNAKE_CASE    (						unittest.TestCase   ):







  '''simple docstring'''


  @slow
  def    __SCREAMING_SNAKE_CASE				(		self   :       int	)		->				Tuple:
        _UpperCamelCase      :	Tuple						=       MPNetModel.from_pretrained("microsoft/mpnet-base"	)
        _UpperCamelCase      :	str						=       torch.tensor([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]	)
        _UpperCamelCase      :	int						=       model(__a	)[0]
        _UpperCamelCase      :	Tuple						=       torch.Size((1, 11, 768)	)
        self.assertEqual(output.shape					,   __a	)
        _UpperCamelCase      :	Optional[int]						=       torch.tensor(
            [[[-0.05_50, 0.19_43, -0.07_40], [-0.05_62, 0.22_11, -0.05_79], [-0.04_37, 0.33_37, -0.06_41]]]	)
        # compare the actual values for a slice.
        self.assertTrue(torch.allclose(output[:, :3, :3]					,   __a					,   atol=1e-4	)	)







"""simple docstring"""


from collections import defaultdict
from math import ceil, sqrt




def 					lowercase__    (					lowercase_ = 1_000_000		,lowercase_ = 10			)					->		int:




      """simple docstring"""

      _UpperCamelCase      :	defaultdict						=       defaultdict(lowercase_			)

      for outer_width in range(3		,(t_limit // 4) + 2			):
            if outer_width * outer_width > t_limit:
                  _UpperCamelCase      :	Any						=       max(
                      ceil(sqrt(outer_width * outer_width - t_limit			)			)		,1			)
            else:
                  _UpperCamelCase      :	str						=       1

            hole_width_lower_bound += (outer_width - hole_width_lower_bound) % 2

            for hole_width in range(lowercase_		,outer_width - 1		,2			):
                  count[outer_width * outer_width - hole_width * hole_width] += 1

      return sum(1 for n in count.values() if 1 <= n <= 10			)


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