





'''simple docstring'''






import unittest

from transformers import SqueezeBertConfig, is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, 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 (
          SQUEEZEBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
          SqueezeBertForMaskedLM,
          SqueezeBertForMultipleChoice,
          SqueezeBertForQuestionAnswering,
          SqueezeBertForSequenceClassification,
          SqueezeBertForTokenClassification,
          SqueezeBertModel,
      )







class 		UpperCAmelCase   (				lowercase_):


  """simple docstring"""







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


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

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

    _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]							,	self.num_choices  )

    _UpperCamelCase       			=self.get_config()

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


  def   UpperCamelCase__      (				self    :					Union[str, Any]  )     ->						Any:
    return SqueezeBertConfig(
        embedding_size=self.hidden_size							,	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							,	attention_probs_dropout_prob=self.hidden_dropout_prob							,	attention_dropout=self.attention_probs_dropout_prob							,	max_position_embeddings=self.max_position_embeddings							,	initializer_range=self.initializer_range							,	q_groups=self.q_groups							,	k_groups=self.k_groups							,	v_groups=self.v_groups							,	post_attention_groups=self.post_attention_groups							,	intermediate_groups=self.intermediate_groups							,	output_groups=self.output_groups							,	)


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


  def   UpperCamelCase__      (				self    :					Any							,	UpperCamelCase__    :					Optional[Any]							,	UpperCamelCase__    :					Optional[int]							,	UpperCamelCase__    :					Dict							,	UpperCamelCase__    :					List[str]							,	UpperCamelCase__    :					Dict							,	UpperCamelCase__    :					Union[str, Any]  )     ->						Optional[int]:
    _UpperCamelCase       			=SqueezeBertForMaskedLM(config=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.vocab_size)  )


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


  def   UpperCamelCase__      (				self    :					Any							,	UpperCamelCase__    :					Tuple							,	UpperCamelCase__    :					List[Any]							,	UpperCamelCase__    :					Union[str, Any]							,	UpperCamelCase__    :					int							,	UpperCamelCase__    :					Dict							,	UpperCamelCase__    :					List[Any]  )     ->						Any:
    _UpperCamelCase       			=self.num_labels
    _UpperCamelCase       			=SqueezeBertForTokenClassification(config=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   UpperCamelCase__      (				self    :					Dict							,	UpperCamelCase__    :					int							,	UpperCamelCase__    :					Tuple							,	UpperCamelCase__    :					List[str]							,	UpperCamelCase__    :					Optional[Any]							,	UpperCamelCase__    :					List[str]							,	UpperCamelCase__    :					Union[str, Any]  )     ->						List[Any]:
    _UpperCamelCase       			=self.num_choices
    _UpperCamelCase       			=SqueezeBertForMultipleChoice(config=UpperCamelCase__  )
    model.to(UpperCamelCase__  )
    model.eval()
    _UpperCamelCase       			=input_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__							,	labels=UpperCamelCase__							,	)
    self.parent.assertEqual(result.logits.shape							,	(self.batch_size, self.num_choices)  )




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







@require_torch
class 		UpperCAmelCase   (				lowercase_   ,     lowercase_   ,     unittest.TestCase):


  """simple docstring"""







  lowerCAmelCase_					=				(
      (
          SqueezeBertModel,
          SqueezeBertForMaskedLM,
          SqueezeBertForMultipleChoice,
          SqueezeBertForQuestionAnswering,
          SqueezeBertForSequenceClassification,
          SqueezeBertForTokenClassification,
      )
      if is_torch_available()
      else None
  )
  lowerCAmelCase_					=				(
      {
          """feature-extraction""": SqueezeBertModel,
          """fill-mask""": SqueezeBertForMaskedLM,
          """question-answering""": SqueezeBertForQuestionAnswering,
          """text-classification""": SqueezeBertForSequenceClassification,
          """token-classification""": SqueezeBertForTokenClassification,
          """zero-shot""": SqueezeBertForSequenceClassification,
      }
      if is_torch_available()
      else {}
  )
  lowerCAmelCase_					=				False
  lowerCAmelCase_					=				True
  lowerCAmelCase_					=				False


  def   UpperCamelCase__      (				self    :					Dict  )     ->						Union[str, Any]:
    _UpperCamelCase       			=SqueezeBertModelTester(self  )
    _UpperCamelCase       			=ConfigTester(self							,	config_class=UpperCamelCase__							,	dim=37  )


  def   UpperCamelCase__      (				self    :					int  )     ->						List[Any]:
    self.config_tester.run_common_tests()


  def   UpperCamelCase__      (				self    :					Tuple  )     ->						str:
    _UpperCamelCase       			=self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_squeezebert_model(*UpperCamelCase__  )


  def   UpperCamelCase__      (				self    :					Optional[int]  )     ->						int:
    _UpperCamelCase       			=self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_squeezebert_for_masked_lm(*UpperCamelCase__  )


  def   UpperCamelCase__      (				self    :					Optional[int]  )     ->						Dict:
    _UpperCamelCase       			=self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_squeezebert_for_question_answering(*UpperCamelCase__  )


  def   UpperCamelCase__      (				self    :					str  )     ->						Optional[Any]:
    _UpperCamelCase       			=self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_squeezebert_for_sequence_classification(*UpperCamelCase__  )


  def   UpperCamelCase__      (				self    :					List[str]  )     ->						int:
    _UpperCamelCase       			=self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_squeezebert_for_token_classification(*UpperCamelCase__  )


  def   UpperCamelCase__      (				self    :					List[str]  )     ->						Any:
    _UpperCamelCase       			=self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_squeezebert_for_multiple_choice(*UpperCamelCase__  )




  @slow
  def   UpperCamelCase__      (				self    :					Optional[int]  )     ->						List[str]:
    for model_name in SQUEEZEBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
      _UpperCamelCase       			=SqueezeBertModel.from_pretrained(UpperCamelCase__  )
      self.assertIsNotNone(UpperCamelCase__  )







@require_sentencepiece
@require_tokenizers
@require_torch
class 		UpperCAmelCase   (				unittest.TestCase):


  """simple docstring"""







  @slow
  def   UpperCamelCase__      (				self    :					List[str]  )     ->						Any:
    _UpperCamelCase       			=SqueezeBertForSequenceClassification.from_pretrained('''squeezebert/squeezebert-mnli'''  )

    _UpperCamelCase       			=torch.tensor([[1, 2_9414, 232, 328, 740, 1140, 1_2695, 69, 13, 1588, 2]]  )
    _UpperCamelCase       			=model(UpperCamelCase__  )[0]
    _UpperCamelCase       			=torch.Size((1, 3)  )
    self.assertEqual(output.shape							,	UpperCamelCase__  )
    _UpperCamelCase       			=torch.tensor([[0.6401, -0.0349, -0.6041]]  )
    self.assertTrue(torch.allclose(UpperCamelCase__							,	UpperCamelCase__							,	atol=1E-4  )  )













'''simple docstring'''






def 					_a   (__SCREAMING_SNAKE_CASE   ):


  """simple docstring"""

  return 1 if digit in (0, 1) else (digit * factorial(digit - 1   ))


def 					_a   (__SCREAMING_SNAKE_CASE   ):


  """simple docstring"""

  _UpperCamelCase       			=0
  _UpperCamelCase       			=number
  while duplicate > 0:
    _UpperCamelCase			,     _UpperCamelCase       			=divmod(__SCREAMING_SNAKE_CASE  ,      10   )
    fact_sum += factorial(__SCREAMING_SNAKE_CASE   )
  return fact_sum == number


if __name__ == "__main__":
      print('Program to check whether a number is a Krisnamurthy Number or not.')
      __lowerCamelCase						: Optional[Any]		=   int(input('Enter number: ').strip())
      print(
          F"""{number} is {'' if krishnamurthy(number) else 'not '}a Krishnamurthy Number."""
      )






