"""simple docstring"""





from math import sqrt





def 				a_     (      _lowerCAmelCase  : int     ):





       '''simple docstring'''

       assert isinstance(_lowerCAmelCase   , _lowerCAmelCase     ) and (
           number >= 0
       ), "'number' must been an int and positive"

       lowercase__			:		List[Any]       =	True

       # 0 and 1 are none primes.
       if number <= 1:
              lowercase__			:		List[Any]       =	False

       for divisor in range(2   , int(round(sqrt(_lowerCAmelCase     )     )     ) + 1     ):
              # if 'number' divisible by 'divisor' then sets 'status'
              # of false and break up the loop.
              if number % divisor == 0:
                     lowercase__			:		Any       =	False
                     break

    # precondition
       assert isinstance(_lowerCAmelCase   , _lowerCAmelCase     ), "'status' must been from type bool"

       return status





def 				a_     (      _lowerCAmelCase  : Dict     ):





       '''simple docstring'''

       assert isinstance(_lowerCAmelCase   , _lowerCAmelCase     ) and (n > 2), "'N' must been an int and > 2"

       # beginList: contains all natural numbers from 2 up to N
       lowercase__			:		int       =	list(range(2   , n + 1     )     )

       lowercase__			:		Optional[int]       =	[]  # this list will be returns.

       # actual sieve of erathostenes
       for i in range(len(_lowerCAmelCase     )     ):
              for j in range(i + 1   , len(_lowerCAmelCase     )     ):
                     if (begin_list[i] != 0) and (begin_list[j] % begin_list[i] == 0):
                            lowercase__			:		Optional[int]       =	0

    # filters actual prime numbers.
       lowercase__			:		Optional[Any]       =	[x for x in begin_list if x != 0]

       # precondition
       assert isinstance(_lowerCAmelCase   , _lowerCAmelCase     ), "'ans' must been from type list"

       return ans





def 				a_     (      _lowerCAmelCase  : int     ):





       '''simple docstring'''

       assert isinstance(_lowerCAmelCase   , _lowerCAmelCase     ) and (n > 2), "'N' must been an int and > 2"

       lowercase__			:		str       =	[]

       # iterates over all numbers between 2 up to N+1
       # if a number is prime then appends to list 'ans'
       for number in range(2   , n + 1     ):
              if is_prime(_lowerCAmelCase     ):
                     ans.append(_lowerCAmelCase     )

    # precondition
       assert isinstance(_lowerCAmelCase   , _lowerCAmelCase     ), "'ans' must been from type list"

       return ans





def 				a_     (      _lowerCAmelCase  : Any     ):





       '''simple docstring'''

       assert isinstance(_lowerCAmelCase   , _lowerCAmelCase     ) and number >= 0, "'number' must been an int and >= 0"

       lowercase__			:		Union[str, Any]       =	[]  # this list will be returns of the function.

       # potential prime number factors.

       lowercase__			:		int       =	2

       lowercase__			:		List[Any]       =	number

       if number == 0 or number == 1:
              ans.append(_lowerCAmelCase     )

       # if 'number' not prime then builds the prime factorization of 'number'
       elif not is_prime(_lowerCAmelCase     ):
              while quotient != 1:
                     if is_prime(_lowerCAmelCase     ) and (quotient % factor == 0):
                            ans.append(_lowerCAmelCase     )
                            quotient /= factor
                     else:
                            factor += 1

       else:
              ans.append(_lowerCAmelCase     )

       # precondition
       assert isinstance(_lowerCAmelCase   , _lowerCAmelCase     ), "'ans' must been from type list"

       return ans





def 				a_     (      _lowerCAmelCase  : Dict     ):





       '''simple docstring'''

       assert isinstance(_lowerCAmelCase   , _lowerCAmelCase     ) and (
           number >= 0
       ), "'number' bust been an int and >= 0"

       lowercase__			:		Optional[int]       =	0

       # prime factorization of 'number'
       lowercase__			:		List[str]       =	prime_factorization(_lowerCAmelCase     )

       lowercase__			:		Any       =	max(_lowerCAmelCase     )

       # precondition
       assert isinstance(_lowerCAmelCase   , _lowerCAmelCase     ), "'ans' must been from type int"

       return ans





def 				a_     (      _lowerCAmelCase  : Union[str, Any]     ):





       '''simple docstring'''

       assert isinstance(_lowerCAmelCase   , _lowerCAmelCase     ) and (
           number >= 0
       ), "'number' bust been an int and >= 0"

       lowercase__			:		int       =	0

       # prime factorization of 'number'
       lowercase__			:		List[str]       =	prime_factorization(_lowerCAmelCase     )

       lowercase__			:		Union[str, Any]       =	min(_lowerCAmelCase     )

       # precondition
       assert isinstance(_lowerCAmelCase   , _lowerCAmelCase     ), "'ans' must been from type int"

       return ans





def 				a_     (      _lowerCAmelCase  : Tuple     ):





       '''simple docstring'''

       assert isinstance(_lowerCAmelCase   , _lowerCAmelCase     ), "'number' must been an int"
       assert isinstance(number % 2 == 0   , _lowerCAmelCase     ), "compare bust been from type bool"

       return number % 2 == 0





def 				a_     (      _lowerCAmelCase  : str     ):





       '''simple docstring'''

       assert isinstance(_lowerCAmelCase   , _lowerCAmelCase     ), "'number' must been an int"
       assert isinstance(number % 2 != 0   , _lowerCAmelCase     ), "compare bust been from type bool"

       return number % 2 != 0





def 				a_     (      _lowerCAmelCase  : Dict     ):





       '''simple docstring'''

       assert (
           isinstance(_lowerCAmelCase   , _lowerCAmelCase     ) and (number > 2) and is_even(_lowerCAmelCase     )
       ), "'number' must been an int, even and > 2"

       lowercase__			:		List[Any]       =	[]  # this list will returned

       # creates a list of prime numbers between 2 up to 'number'
       lowercase__			:		List[str]       =	get_prime_numbers(_lowerCAmelCase     )
       lowercase__			:		Any       =	len(_lowerCAmelCase     )

       # run variable for while-loops.
       lowercase__			:		Optional[int]       =	0
       lowercase__			:		str       =	None

       # exit variable. for break up the loops
       lowercase__			:		Optional[int]       =	True

       while i < len_pn and loop:
              lowercase__			:		Any       =	i + 1

              while j < len_pn and loop:
                     if prime_numbers[i] + prime_numbers[j] == number:
                            lowercase__			:		Optional[Any]       =	False
                            ans.append(prime_numbers[i]     )
                            ans.append(prime_numbers[j]     )

                     j += 1

              i += 1

       # precondition
       assert (
           isinstance(_lowerCAmelCase   , _lowerCAmelCase     )
           and (len(_lowerCAmelCase     ) == 2)
           and (ans[0] + ans[1] == number)
           and is_prime(ans[0]     )
           and is_prime(ans[1]     )
       ), "'ans' must contains two primes. And sum of elements must been eq 'number'"

       return ans





def 				a_     (      _lowerCAmelCase  : Any   , _lowerCAmelCase  : List[str]     ):





       '''simple docstring'''

       assert (
           isinstance(_lowerCAmelCase   , _lowerCAmelCase     )
           and isinstance(_lowerCAmelCase   , _lowerCAmelCase     )
           and (numbera >= 0)
           and (numbera >= 0)
       ), "'number1' and 'number2' must been positive integer."

       lowercase__			:		List[Any]       =	0

       while numbera != 0:
              lowercase__			:		Optional[int]       =	numbera % numbera
              lowercase__			:		Optional[Any]       =	numbera
              lowercase__			:		Tuple       =	rest

       # precondition
       assert isinstance(_lowerCAmelCase   , _lowerCAmelCase     ) and (
           numbera >= 0
       ), "'number' must been from type int and positive"

       return numbera





def 				a_     (      _lowerCAmelCase  : List[Any]   , _lowerCAmelCase  : int     ):





       '''simple docstring'''

       assert (
           isinstance(_lowerCAmelCase   , _lowerCAmelCase     )
           and isinstance(_lowerCAmelCase   , _lowerCAmelCase     )
           and (numbera >= 1)
           and (numbera >= 1)
       ), "'number1' and 'number2' must been positive integer."

       lowercase__			:		List[str]       =	1  # actual answer that will be return.

       # for kgV (x,1)
       if numbera > 1 and numbera > 1:
              # builds the prime factorization of 'number1' and 'number2'
              lowercase__			:		Tuple       =	prime_factorization(_lowerCAmelCase     )
              lowercase__			:		int       =	prime_factorization(_lowerCAmelCase     )

       elif numbera == 1 or numbera == 1:
              lowercase__			:		Optional[Any]       =	[]
              lowercase__			:		Tuple       =	[]
              lowercase__			:		List[Any]       =	max(_lowerCAmelCase   , _lowerCAmelCase     )

       lowercase__			:		List[Any]       =	0
       lowercase__			:		List[Any]       =	0

       lowercase__			:		List[str]       =	[]  # captured numbers int both 'primeFac1' and 'primeFac2'

       # iterates through primeFac1
       for n in prime_fac_a:
              if n not in done:
                     if n in prime_fac_a:
                            lowercase__			:		Any       =	prime_fac_a.count(_lowerCAmelCase     )
                            lowercase__			:		int       =	prime_fac_a.count(_lowerCAmelCase     )

                            for _ in range(max(_lowerCAmelCase   , _lowerCAmelCase     )     ):
                                   ans *= n

                     else:
                            lowercase__			:		Optional[Any]       =	prime_fac_a.count(_lowerCAmelCase     )

                            for _ in range(_lowerCAmelCase     ):
                                   ans *= n

                     done.append(_lowerCAmelCase     )

    # iterates through primeFac2
       for n in prime_fac_a:
              if n not in done:
                     lowercase__			:		List[Any]       =	prime_fac_a.count(_lowerCAmelCase     )

                     for _ in range(_lowerCAmelCase     ):
                            ans *= n

                     done.append(_lowerCAmelCase     )

    # precondition
       assert isinstance(_lowerCAmelCase   , _lowerCAmelCase     ) and (
           ans >= 0
       ), "'ans' must been from type int and positive"

       return ans





def 				a_     (      _lowerCAmelCase  : Dict     ):





       '''simple docstring'''

       assert isinstance(_lowerCAmelCase   , _lowerCAmelCase     ) and (n >= 0), "'number' must been a positive int"

       lowercase__			:		Union[str, Any]       =	0
       lowercase__			:		int       =	2  # this variable holds the answer

       while index < n:
              index += 1

              ans += 1  # counts to the next number

              # if ans not prime then
              # runs to the next prime number.
              while not is_prime(_lowerCAmelCase     ):
                     ans += 1

    # precondition
       assert isinstance(_lowerCAmelCase   , _lowerCAmelCase     ) and is_prime(
           _lowerCAmelCase     ), "'ans' must been a prime number and from type int"

       return ans





def 				a_     (      _lowerCAmelCase  : Any   , _lowerCAmelCase  : int     ):





       '''simple docstring'''

       assert (
           is_prime(_lowerCAmelCase     ) and is_prime(_lowerCAmelCase     ) and (p_number_a < p_number_a)
       ), "The arguments must been prime numbers and 'pNumber1' < 'pNumber2'"

       lowercase__			:		Any       =	p_number_a + 1  # jump to the next number

       lowercase__			:		str       =	[]  # this list will be returns.

       # if number is not prime then
       # fetch the next prime number.
       while not is_prime(_lowerCAmelCase     ):
              number += 1

       while number < p_number_a:
              ans.append(_lowerCAmelCase     )

              number += 1

              # fetch the next prime number.
              while not is_prime(_lowerCAmelCase     ):
                     number += 1

    # precondition
       assert (
           isinstance(_lowerCAmelCase   , _lowerCAmelCase     )
           and ans[0] != p_number_a
           and ans[len(_lowerCAmelCase     ) - 1] != p_number_a
       ), "'ans' must been a list without the arguments"

       # 'ans' contains not 'pNumber1' and 'pNumber2' !
       return ans





def 				a_     (      _lowerCAmelCase  : str     ):





       '''simple docstring'''

       assert isinstance(_lowerCAmelCase   , _lowerCAmelCase     ) and (n >= 1), "'n' must been int and >= 1"

       lowercase__			:		Optional[int]       =	[]  # will be returned.

       for divisor in range(1   , n + 1     ):
              if n % divisor == 0:
                     ans.append(_lowerCAmelCase     )

    # precondition
       assert ans[0] == 1 and ans[len(_lowerCAmelCase     ) - 1] == n, "Error in function getDivisiors(...)"

       return ans





def 				a_     (      _lowerCAmelCase  : Any     ):





       '''simple docstring'''

       assert isinstance(_lowerCAmelCase   , _lowerCAmelCase     ) and (
           number > 1
       ), "'number' must been an int and >= 1"

       lowercase__			:		List[str]       =	get_divisors(_lowerCAmelCase     )

       # precondition
       assert (
           isinstance(_lowerCAmelCase   , _lowerCAmelCase     )
           and (divisors[0] == 1)
           and (divisors[len(_lowerCAmelCase     ) - 1] == number)
       ), "Error in help-function getDivisiors(...)"

       # summed all divisors up to 'number' (exclusive), hence [:-1]
       return sum(divisors[:-1]     ) == number





def 				a_     (      _lowerCAmelCase  : Union[str, Any]   , _lowerCAmelCase  : Any     ):





       '''simple docstring'''

       assert (
           isinstance(_lowerCAmelCase   , _lowerCAmelCase     )
           and isinstance(_lowerCAmelCase   , _lowerCAmelCase     )
           and (denominator != 0)
       ), "The arguments must been from type int and 'denominator' != 0"

       # build the greatest common divisor of numerator and denominator.
       lowercase__			:		Dict       =	gcd(abs(_lowerCAmelCase     )   , abs(_lowerCAmelCase     )     )

       # precondition
       assert (
           isinstance(_lowerCAmelCase   , _lowerCAmelCase     )
           and (numerator % gcd_of_fraction == 0)
           and (denominator % gcd_of_fraction == 0)
       ), "Error in function gcd(...,...)"

       return (numerator // gcd_of_fraction, denominator // gcd_of_fraction)





def 				a_     (      _lowerCAmelCase  : Any     ):





       '''simple docstring'''

       assert isinstance(_lowerCAmelCase   , _lowerCAmelCase     ) and (n >= 0), "'n' must been a int and >= 0"

       lowercase__			:		Any       =	1  # this will be return.

       for factor in range(1   , n + 1     ):
              ans *= factor

       return ans






def 				a_     (      _lowerCAmelCase  : Optional[Any]     ):





       '''simple docstring'''

       assert isinstance(_lowerCAmelCase   , _lowerCAmelCase     ) and (n >= 0), "'n' must been an int and >= 0"

       lowercase__			:		List[Any]       =	0
       lowercase__			:		Union[str, Any]       =	1
       lowercase__			:		List[str]       =	1  # this will be return

       for _ in range(n - 1     ):
              lowercase__			:		List[Any]       =	ans
              ans += fiba
              lowercase__			:		Tuple       =	tmp

       return ans



import unittest

from transformers import MobileBertConfig, is_torch_available
from transformers.models.auto import get_values
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 (
          MODEL_FOR_PRETRAINING_MAPPING,
          MobileBertForMaskedLM,
          MobileBertForMultipleChoice,
          MobileBertForNextSentencePrediction,
          MobileBertForPreTraining,
          MobileBertForQuestionAnswering,
          MobileBertForSequenceClassification,
          MobileBertForTokenClassification,
          MobileBertModel,
      )



class 		UpperCamelCase__  :
   def __init__(self :					List[Any]					,				snake_case_ :					int					,				snake_case_ :					List[str]=1_3					,				snake_case_ :					Tuple=7					,				snake_case_ :					List[Any]=True					,				snake_case_ :					List[Any]=True					,				snake_case_ :					Dict=True					,				snake_case_ :					Optional[int]=True					,				snake_case_ :					str=9_9					,				snake_case_ :					Dict=6_4					,				snake_case_ :					Any=3_2					,				snake_case_ :					str=5					,				snake_case_ :					int=4					,				snake_case_ :					List[Any]=3_7					,				snake_case_ :					Any="gelu"					,				snake_case_ :					Dict=0.1					,				snake_case_ :					List[str]=0.1					,				snake_case_ :					str=5_1_2					,				snake_case_ :					Any=1_6					,				snake_case_ :					str=2					,				snake_case_ :					int=0.02					,				snake_case_ :					Union[str, Any]=3					,				snake_case_ :					Optional[Any]=4					,				snake_case_ :					List[Any]=None					,				):
    __a :  Any						=  parent
    __a :  Optional[int]						=  batch_size
    __a :  Any						=  seq_length
    __a :  int						=  is_training
    __a :  Optional[int]						=  use_input_mask
    __a :  List[Any]						=  use_token_type_ids
    __a :  Dict						=  use_labels
    __a :  Tuple						=  vocab_size
    __a :  str						=  hidden_size
    __a :  List[Any]						=  embedding_size
    __a :  List[Any]						=  num_hidden_layers
    __a :  str						=  num_attention_heads
    __a :  str						=  intermediate_size
    __a :  Union[str, Any]						=  hidden_act
    __a :  Optional[Any]						=  hidden_dropout_prob
    __a :  Tuple						=  attention_probs_dropout_prob
    __a :  Union[str, Any]						=  max_position_embeddings
    __a :  Any						=  type_vocab_size
    __a :  int						=  type_sequence_label_size
    __a :  int						=  initializer_range
    __a :  int						=  num_labels
    __a :  Union[str, Any]						=  num_choices
    __a :  Dict						=  scope
   def       lowerCAmelCase			(self :					str   ):
    __a :  int						=  ids_tensor([self.batch_size, self.seq_length]					,				self.vocab_size   )

    __a :  List[Any]						=  None
    if self.use_input_mask:
     __a :  Dict						=  random_attention_mask([self.batch_size, self.seq_length]   )

    __a :  Optional[Any]						=  None
    if self.use_token_type_ids:
     __a :  List[Any]						=  ids_tensor([self.batch_size, self.seq_length]					,				self.type_vocab_size   )

    __a :  Dict						=  None
    __a :  List[str]						=  None
    __a :  Optional[Any]						=  None
    if self.use_labels:
     __a :  str						=  ids_tensor([self.batch_size]					,				self.type_sequence_label_size   )
     __a :  Dict						=  ids_tensor([self.batch_size, self.seq_length]					,				self.num_labels   )
     __a :  Union[str, Any]						=  ids_tensor([self.batch_size]					,				self.num_choices   )

    __a :  Optional[int]						=  self.get_config()

    return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels
   def       lowerCAmelCase			(self :					int   ):
    return MobileBertConfig(
        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					,				embedding_size=self.embedding_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					,				is_decoder=snake_case_					,				initializer_range=self.initializer_range					,				)
   def       lowerCAmelCase			(self :					str					,				snake_case_ :					Tuple					,				snake_case_ :					List[str]					,				snake_case_ :					int					,				snake_case_ :					int					,				snake_case_ :					Any					,				snake_case_ :					List[Any]					,				snake_case_ :					Any   ):
    __a :  Any						=  MobileBertModel(config=snake_case_   )
    model.to(snake_case_   )
    model.eval()
    __a :  List[str]						=  model(snake_case_					,				attention_mask=snake_case_					,				token_type_ids=snake_case_   )
    __a :  Optional[Any]						=  model(snake_case_					,				token_type_ids=snake_case_   )
    __a :  Optional[Any]						=  model(snake_case_   )

    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       lowerCAmelCase			(self :					Any					,				snake_case_ :					Dict					,				snake_case_ :					Optional[Any]					,				snake_case_ :					Tuple					,				snake_case_ :					Dict					,				snake_case_ :					Tuple					,				snake_case_ :					str					,				snake_case_ :					List[Any]   ):
    __a :  str						=  MobileBertForMaskedLM(config=snake_case_   )
    model.to(snake_case_   )
    model.eval()
    __a :  Tuple						=  model(snake_case_					,				attention_mask=snake_case_					,				token_type_ids=snake_case_					,				labels=snake_case_   )
    self.parent.assertEqual(result.logits.shape					,				(self.batch_size, self.seq_length, self.vocab_size)   )
   def       lowerCAmelCase			(self :					Tuple					,				snake_case_ :					Any					,				snake_case_ :					Dict					,				snake_case_ :					List[Any]					,				snake_case_ :					Any					,				snake_case_ :					Union[str, Any]					,				snake_case_ :					Optional[int]					,				snake_case_ :					Dict   ):
    __a :  Optional[Any]						=  MobileBertForNextSentencePrediction(config=snake_case_   )
    model.to(snake_case_   )
    model.eval()
    __a :  int						=  model(
        snake_case_					,				attention_mask=snake_case_					,				token_type_ids=snake_case_					,				labels=snake_case_					,				)
    self.parent.assertEqual(result.logits.shape					,				(self.batch_size, 2)   )
   def       lowerCAmelCase			(self :					Any					,				snake_case_ :					Dict					,				snake_case_ :					Optional[int]					,				snake_case_ :					Any					,				snake_case_ :					Any					,				snake_case_ :					Union[str, Any]					,				snake_case_ :					Dict					,				snake_case_ :					Optional[Any]   ):
    __a :  str						=  MobileBertForPreTraining(config=snake_case_   )
    model.to(snake_case_   )
    model.eval()
    __a :  Union[str, Any]						=  model(
        snake_case_					,				attention_mask=snake_case_					,				token_type_ids=snake_case_					,				labels=snake_case_					,				next_sentence_label=snake_case_					,				)
    self.parent.assertEqual(result.prediction_logits.shape					,				(self.batch_size, self.seq_length, self.vocab_size)   )
    self.parent.assertEqual(result.seq_relationship_logits.shape					,				(self.batch_size, 2)   )
   def       lowerCAmelCase			(self :					Dict					,				snake_case_ :					Tuple					,				snake_case_ :					Any					,				snake_case_ :					Dict					,				snake_case_ :					int					,				snake_case_ :					int					,				snake_case_ :					str					,				snake_case_ :					str   ):
    __a :  str						=  MobileBertForQuestionAnswering(config=snake_case_   )
    model.to(snake_case_   )
    model.eval()
    __a :  Optional[Any]						=  model(
        snake_case_					,				attention_mask=snake_case_					,				token_type_ids=snake_case_					,				start_positions=snake_case_					,				end_positions=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       lowerCAmelCase			(self :					Optional[int]					,				snake_case_ :					Any					,				snake_case_ :					List[str]					,				snake_case_ :					List[Any]					,				snake_case_ :					str					,				snake_case_ :					Any					,				snake_case_ :					Tuple					,				snake_case_ :					Optional[int]   ):
    __a :  Any						=  self.num_labels
    __a :  Union[str, Any]						=  MobileBertForSequenceClassification(snake_case_   )
    model.to(snake_case_   )
    model.eval()
    __a :  Tuple						=  model(snake_case_					,				attention_mask=snake_case_					,				token_type_ids=snake_case_					,				labels=snake_case_   )
    self.parent.assertEqual(result.logits.shape					,				(self.batch_size, self.num_labels)   )
   def       lowerCAmelCase			(self :					List[Any]					,				snake_case_ :					Optional[int]					,				snake_case_ :					str					,				snake_case_ :					Dict					,				snake_case_ :					List[Any]					,				snake_case_ :					Optional[Any]					,				snake_case_ :					Dict					,				snake_case_ :					Optional[int]   ):
    __a :  Union[str, Any]						=  self.num_labels
    __a :  str						=  MobileBertForTokenClassification(config=snake_case_   )
    model.to(snake_case_   )
    model.eval()
    __a :  Any						=  model(snake_case_					,				attention_mask=snake_case_					,				token_type_ids=snake_case_					,				labels=snake_case_   )
    self.parent.assertEqual(result.logits.shape					,				(self.batch_size, self.seq_length, self.num_labels)   )
   def       lowerCAmelCase			(self :					Union[str, Any]					,				snake_case_ :					List[str]					,				snake_case_ :					Any					,				snake_case_ :					Optional[Any]					,				snake_case_ :					Optional[Any]					,				snake_case_ :					Any					,				snake_case_ :					Dict					,				snake_case_ :					Union[str, Any]   ):
    __a :  Union[str, Any]						=  self.num_choices
    __a :  List[str]						=  MobileBertForMultipleChoice(config=snake_case_   )
    model.to(snake_case_   )
    model.eval()
    __a :  List[Any]						=  input_ids.unsqueeze(1   ).expand(-1					,				self.num_choices					,				-1   ).contiguous()
    __a :  int						=  token_type_ids.unsqueeze(1   ).expand(-1					,				self.num_choices					,				-1   ).contiguous()
    __a :  str						=  input_mask.unsqueeze(1   ).expand(-1					,				self.num_choices					,				-1   ).contiguous()
    __a :  Any						=  model(
        snake_case_					,				attention_mask=snake_case_					,				token_type_ids=snake_case_					,				labels=snake_case_					,				)
    self.parent.assertEqual(result.logits.shape					,				(self.batch_size, self.num_choices)   )







   def       lowerCAmelCase			(self :					Optional[Any]   ):
    __a :  Optional[Any]						=  self.prepare_config_and_inputs()
    (
        (
        __a
    )				,       (
        __a
    )				,       (
        __a
    )				,       (
        __a
    )				,       (
        __a
    )				,       (
        __a
    )				,       (
        __a
    )				,       
    ) :  int						=  config_and_inputs
    __a :  Union[str, Any]						=  {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
    return config, inputs_dict





@require_torch
class 		UpperCamelCase__  (       __lowercase    ,__lowercase    ,unittest.TestCase    ):
   _SCREAMING_SNAKE_CASE      :							str	       =      (
       (
           MobileBertModel,
           MobileBertForMaskedLM,
           MobileBertForMultipleChoice,
           MobileBertForNextSentencePrediction,
           MobileBertForPreTraining,
           MobileBertForQuestionAnswering,
           MobileBertForSequenceClassification,
           MobileBertForTokenClassification,
       )
       if is_torch_available()
       else ()
   )
   _SCREAMING_SNAKE_CASE      :							Any	       =      (
       {
           "feature-extraction": MobileBertModel,
           "fill-mask": MobileBertForMaskedLM,
           "question-answering": MobileBertForQuestionAnswering,
           "text-classification": MobileBertForSequenceClassification,
           "token-classification": MobileBertForTokenClassification,
           "zero-shot": MobileBertForSequenceClassification,
       }
       if is_torch_available()
       else {}
   )
   _SCREAMING_SNAKE_CASE      :							Union[str, Any]	       =      True
   def       lowerCAmelCase			(self :					str					,				snake_case_ :					Tuple					,				snake_case_ :					List[Any]					,				snake_case_ :					Union[str, Any]=False   ):
    __a :  List[str]						=  super()._prepare_for_class(snake_case_					,				snake_case_					,				return_labels=snake_case_   )

    if return_labels:
     if model_class in get_values(snake_case_   ):
      __a :  Optional[int]						=  torch.zeros(
          (self.model_tester.batch_size, self.model_tester.seq_length)					,				dtype=torch.long					,				device=snake_case_   )
      __a :  int						=  torch.zeros(
          self.model_tester.batch_size					,				dtype=torch.long					,				device=snake_case_   )
    return inputs_dict
   def       lowerCAmelCase			(self :					Tuple   ):
    __a :  List[Any]						=  MobileBertModelTester(self   )
    __a :  int						=  ConfigTester(self					,				config_class=snake_case_					,				hidden_size=3_7   )
   def       lowerCAmelCase			(self :					Union[str, Any]   ):
    self.config_tester.run_common_tests()
   def       lowerCAmelCase			(self :					Optional[Any]   ):
    __a :  Dict						=  self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_mobilebert_model(*snake_case_   )
   def       lowerCAmelCase			(self :					str   ):
    __a :  Any						=  self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_mobilebert_for_masked_lm(*snake_case_   )
   def       lowerCAmelCase			(self :					Tuple   ):
    __a :  str						=  self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_mobilebert_for_multiple_choice(*snake_case_   )
   def       lowerCAmelCase			(self :					Dict   ):
    __a :  Optional[Any]						=  self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_mobilebert_for_next_sequence_prediction(*snake_case_   )
   def       lowerCAmelCase			(self :					int   ):
    __a :  Tuple						=  self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_mobilebert_for_pretraining(*snake_case_   )
   def       lowerCAmelCase			(self :					List[Any]   ):
    __a :  int						=  self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_mobilebert_for_question_answering(*snake_case_   )
   def       lowerCAmelCase			(self :					int   ):
    __a :  Optional[int]						=  self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_mobilebert_for_sequence_classification(*snake_case_   )







   def       lowerCAmelCase			(self :					Tuple   ):
    __a :  Optional[int]						=  self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_mobilebert_for_token_classification(*snake_case_   )





def    __UpperCamelCase     (				lowerCAmelCase__							:				str  ):
 return torch.tensor(
     lowerCAmelCase__  ,   dtype=torch.long  ,   device=lowerCAmelCase__  ,   )


lowercase__       =1e-3



@require_torch
@require_sentencepiece
@require_tokenizers
class 		UpperCamelCase__  (       unittest.TestCase    ):
   @slow
   def       lowerCAmelCase			(self :					Any   ):
    __a :  Dict						=  MobileBertModel.from_pretrained('''google/mobilebert-uncased'''   ).to(snake_case_   )
    __a :  Tuple						=  _long_tensor([[1_0_1, 7_1_1_0, 1_0_0_5, 1_0_5_6, 2_0_2_3, 1_1_3_3_3, 1_7_4_1_3, 1_0_2_9, 1_0_2]]   )
    with torch.no_grad():
     __a :  str						=  model(snake_case_   )[0]
    __a :  List[Any]						=  torch.Size((1, 9, 5_1_2)   )
    self.assertEqual(output.shape					,				snake_case_   )
    __a :  Union[str, Any]						=  torch.tensor(
        [
            [
                [-2.473_6526E07, 8.269_1656E04, 1.652_1838E05],
                [-5.754_1704E-01, 3.905_6022E00, 4.401_1507E00],
                [2.604_7359E00, 1.567_7652E00, -1.732_4188E-01],
            ]
        ]					,				device=snake_case_					,				)

    # MobileBERT results range from 10e0 to 10e8. Even a 0.0000001% difference with a value of 10e8 results in a
    # ~1 difference, it's therefore not a good idea to measure using addition.
    # Here, we instead divide the expected result with the result in order to obtain ~1. We then check that the
    # result is held between bounds: 1 - TOLERANCE < expected_result / result < 1 + TOLERANCE
    __a :  List[str]						=  torch.all((expected_slice / output[..., :3, :3]) >= 1 - TOLERANCE   )
    __a :  Any						=  torch.all((expected_slice / output[..., :3, :3]) <= 1 + TOLERANCE   )

    self.assertTrue(lower_bound and upper_bound   )
