





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 		lowerCamelCase  :







							"""simple docstring"""




							def __init__(   self      :	Any,					_UpperCAmelCase      :	int,					_UpperCAmelCase      :	str=1_3,					_UpperCAmelCase      :	Tuple=7,					_UpperCAmelCase      :	int=True,					_UpperCAmelCase      :	Any=True,					_UpperCAmelCase      :	Optional[Any]=True,					_UpperCAmelCase      :	List[str]=True,					_UpperCAmelCase      :	Union[str, Any]=9_9,					_UpperCAmelCase      :	Tuple=6_4,					_UpperCAmelCase      :	Optional[Any]=3_2,					_UpperCAmelCase      :	Dict=5,					_UpperCAmelCase      :	Any=4,					_UpperCAmelCase      :	int=3_7,					_UpperCAmelCase      :	Union[str, Any]="gelu",					_UpperCAmelCase      :	Optional[int]=0.1,					_UpperCAmelCase      :	Optional[int]=0.1,					_UpperCAmelCase      :	str=5_1_2,					_UpperCAmelCase      :	Tuple=1_6,					_UpperCAmelCase      :	List[str]=2,					_UpperCAmelCase      :	int=0.02,					_UpperCAmelCase      :	Optional[Any]=3,					_UpperCAmelCase      :	int=4,					_UpperCAmelCase      :	Optional[int]=None,					) ->					Dict:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__  :     List[str]           =		parent
														SCREAMING_SNAKE_CASE__  :     List[Any]           =		batch_size
														SCREAMING_SNAKE_CASE__  :     List[str]           =		seq_length
														SCREAMING_SNAKE_CASE__  :     str           =		is_training
														SCREAMING_SNAKE_CASE__  :     Tuple           =		use_input_mask
														SCREAMING_SNAKE_CASE__  :     Optional[Any]           =		use_token_type_ids
														SCREAMING_SNAKE_CASE__  :     Any           =		use_labels
														SCREAMING_SNAKE_CASE__  :     Tuple           =		vocab_size
														SCREAMING_SNAKE_CASE__  :     Union[str, Any]           =		hidden_size
														SCREAMING_SNAKE_CASE__  :     int           =		embedding_size
														SCREAMING_SNAKE_CASE__  :     Union[str, Any]           =		num_hidden_layers
														SCREAMING_SNAKE_CASE__  :     List[str]           =		num_attention_heads
														SCREAMING_SNAKE_CASE__  :     Dict           =		intermediate_size
														SCREAMING_SNAKE_CASE__  :     str           =		hidden_act
														SCREAMING_SNAKE_CASE__  :     List[Any]           =		hidden_dropout_prob
														SCREAMING_SNAKE_CASE__  :     Any           =		attention_probs_dropout_prob
														SCREAMING_SNAKE_CASE__  :     Tuple           =		max_position_embeddings
														SCREAMING_SNAKE_CASE__  :     str           =		type_vocab_size
														SCREAMING_SNAKE_CASE__  :     Optional[int]           =		type_sequence_label_size
														SCREAMING_SNAKE_CASE__  :     Any           =		initializer_range
														SCREAMING_SNAKE_CASE__  :     Tuple           =		num_labels
														SCREAMING_SNAKE_CASE__  :     str           =		num_choices
														SCREAMING_SNAKE_CASE__  :     Optional[Any]           =		scope






							def    A_      (   self      :	Tuple		) ->					Optional[Any]:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__  :     Tuple           =		ids_tensor([self.batch_size, self.seq_length],					self.vocab_size		)

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

														SCREAMING_SNAKE_CASE__  :     Tuple           =		None
														if self.use_token_type_ids:
																					SCREAMING_SNAKE_CASE__  :     List[str]           =		ids_tensor([self.batch_size, self.seq_length],					self.type_vocab_size		)

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

														SCREAMING_SNAKE_CASE__  :     int           =		self.get_config()

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






							def    A_      (   self      :	Dict		) ->					List[str]:





														"""simple docstring"""
														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=__a,					initializer_range=self.initializer_range,					)






							def    A_      (   self      :	Optional[int],					_UpperCAmelCase      :	str,					_UpperCAmelCase      :	Tuple,					_UpperCAmelCase      :	Any,					_UpperCAmelCase      :	Tuple,					_UpperCAmelCase      :	Dict,					_UpperCAmelCase      :	Dict,					_UpperCAmelCase      :	List[str]		) ->					str:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__  :     Dict           =		MobileBertModel(config=__a		)
														model.to(__a		)
														model.eval()
														SCREAMING_SNAKE_CASE__  :     int           =		model(__a,					attention_mask=__a,					token_type_ids=__a		)
														SCREAMING_SNAKE_CASE__  :     List[str]           =		model(__a,					token_type_ids=__a		)
														SCREAMING_SNAKE_CASE__  :     Optional[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    A_      (   self      :	Optional[int],					_UpperCAmelCase      :	Union[str, Any],					_UpperCAmelCase      :	str,					_UpperCAmelCase      :	Optional[int],					_UpperCAmelCase      :	Any,					_UpperCAmelCase      :	Optional[int],					_UpperCAmelCase      :	Union[str, Any],					_UpperCAmelCase      :	List[Any]		) ->					Dict:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__  :     Tuple           =		MobileBertForMaskedLM(config=__a		)
														model.to(__a		)
														model.eval()
														SCREAMING_SNAKE_CASE__  :     List[str]           =		model(__a,					attention_mask=__a,					token_type_ids=__a,					labels=__a		)
														self.parent.assertEqual(result.logits.shape,					(self.batch_size, self.seq_length, self.vocab_size)		)






							def    A_      (   self      :	List[str],					_UpperCAmelCase      :	str,					_UpperCAmelCase      :	str,					_UpperCAmelCase      :	Dict,					_UpperCAmelCase      :	Tuple,					_UpperCAmelCase      :	Dict,					_UpperCAmelCase      :	Any,					_UpperCAmelCase      :	str		) ->					str:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__  :     Optional[Any]           =		MobileBertForNextSentencePrediction(config=__a		)
														model.to(__a		)
														model.eval()
														SCREAMING_SNAKE_CASE__  :     Any           =		model(
														    __a,					attention_mask=__a,					token_type_ids=__a,					labels=__a,					)
														self.parent.assertEqual(result.logits.shape,					(self.batch_size, 2)		)






							def    A_      (   self      :	Tuple,					_UpperCAmelCase      :	Optional[int],					_UpperCAmelCase      :	Union[str, Any],					_UpperCAmelCase      :	str,					_UpperCAmelCase      :	str,					_UpperCAmelCase      :	int,					_UpperCAmelCase      :	List[str],					_UpperCAmelCase      :	Dict		) ->					Union[str, Any]:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__  :     Dict           =		MobileBertForPreTraining(config=__a		)
														model.to(__a		)
														model.eval()
														SCREAMING_SNAKE_CASE__  :     Optional[int]           =		model(
														    __a,					attention_mask=__a,					token_type_ids=__a,					labels=__a,					next_sentence_label=__a,					)
														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    A_      (   self      :	Optional[Any],					_UpperCAmelCase      :	List[str],					_UpperCAmelCase      :	str,					_UpperCAmelCase      :	str,					_UpperCAmelCase      :	List[Any],					_UpperCAmelCase      :	Optional[Any],					_UpperCAmelCase      :	str,					_UpperCAmelCase      :	List[str]		) ->					Dict:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__  :     List[Any]           =		MobileBertForQuestionAnswering(config=__a		)
														model.to(__a		)
														model.eval()
														SCREAMING_SNAKE_CASE__  :     int           =		model(
														    __a,					attention_mask=__a,					token_type_ids=__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    A_      (   self      :	Optional[Any],					_UpperCAmelCase      :	Union[str, Any],					_UpperCAmelCase      :	Optional[Any],					_UpperCAmelCase      :	List[str],					_UpperCAmelCase      :	Dict,					_UpperCAmelCase      :	int,					_UpperCAmelCase      :	int,					_UpperCAmelCase      :	List[Any]		) ->					Union[str, Any]:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__  :     Optional[int]           =		self.num_labels
														SCREAMING_SNAKE_CASE__  :     Dict           =		MobileBertForSequenceClassification(__a		)
														model.to(__a		)
														model.eval()
														SCREAMING_SNAKE_CASE__  :     Any           =		model(__a,					attention_mask=__a,					token_type_ids=__a,					labels=__a		)
														self.parent.assertEqual(result.logits.shape,					(self.batch_size, self.num_labels)		)






							def    A_      (   self      :	Optional[Any],					_UpperCAmelCase      :	Optional[int],					_UpperCAmelCase      :	List[str],					_UpperCAmelCase      :	List[Any],					_UpperCAmelCase      :	Union[str, Any],					_UpperCAmelCase      :	Tuple,					_UpperCAmelCase      :	str,					_UpperCAmelCase      :	List[Any]		) ->					int:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__  :     Tuple           =		self.num_labels
														SCREAMING_SNAKE_CASE__  :     Any           =		MobileBertForTokenClassification(config=__a		)
														model.to(__a		)
														model.eval()
														SCREAMING_SNAKE_CASE__  :     List[Any]           =		model(__a,					attention_mask=__a,					token_type_ids=__a,					labels=__a		)
														self.parent.assertEqual(result.logits.shape,					(self.batch_size, self.seq_length, self.num_labels)		)






							def    A_      (   self      :	Union[str, Any],					_UpperCAmelCase      :	List[str],					_UpperCAmelCase      :	Optional[int],					_UpperCAmelCase      :	Any,					_UpperCAmelCase      :	str,					_UpperCAmelCase      :	Dict,					_UpperCAmelCase      :	Optional[Any],					_UpperCAmelCase      :	int		) ->					List[str]:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__  :     List[str]           =		self.num_choices
														SCREAMING_SNAKE_CASE__  :     Any           =		MobileBertForMultipleChoice(config=__a		)
														model.to(__a		)
														model.eval()
														SCREAMING_SNAKE_CASE__  :     List[str]           =		input_ids.unsqueeze(1		).expand(-1,					self.num_choices,					-1		).contiguous()
														SCREAMING_SNAKE_CASE__  :     Union[str, Any]           =		token_type_ids.unsqueeze(1		).expand(-1,					self.num_choices,					-1		).contiguous()
														SCREAMING_SNAKE_CASE__  :     Optional[int]           =		input_mask.unsqueeze(1		).expand(-1,					self.num_choices,					-1		).contiguous()
														SCREAMING_SNAKE_CASE__  :     Tuple           =		model(
														    __a,					attention_mask=__a,					token_type_ids=__a,					labels=__a,					)
														self.parent.assertEqual(result.logits.shape,					(self.batch_size, self.num_choices)		)






							def    A_      (   self      :	Optional[int]		) ->					Tuple:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__  :     str           =		self.prepare_config_and_inputs()
														(
														    (
														    SCREAMING_SNAKE_CASE__    
														)       ,(
														    SCREAMING_SNAKE_CASE__    
														)       ,(
														    SCREAMING_SNAKE_CASE__    
														)       ,(
														    SCREAMING_SNAKE_CASE__    
														)       ,(
														    SCREAMING_SNAKE_CASE__    
														)       ,(
														    SCREAMING_SNAKE_CASE__    
														)       ,(
														    SCREAMING_SNAKE_CASE__    
														)       ,    
														)  :     Optional[int]           =		config_and_inputs
														SCREAMING_SNAKE_CASE__  :     Optional[Any]           =		{"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
														return config, inputs_dict


@require_torch
class 		lowerCamelCase  (__lowerCamelCase				,      __lowerCamelCase				,      unittest.TestCase     ):







							"""simple docstring"""




							UpperCAmelCase_     		=       (
							    (
							        MobileBertModel,
							        MobileBertForMaskedLM,
							        MobileBertForMultipleChoice,
							        MobileBertForNextSentencePrediction,
							        MobileBertForPreTraining,
							        MobileBertForQuestionAnswering,
							        MobileBertForSequenceClassification,
							        MobileBertForTokenClassification,
							    )
							    if is_torch_available()
							    else ()
							)
							UpperCAmelCase_     		=       (
							    {
							        "feature-extraction": MobileBertModel,
							        "fill-mask": MobileBertForMaskedLM,
							        "question-answering": MobileBertForQuestionAnswering,
							        "text-classification": MobileBertForSequenceClassification,
							        "token-classification": MobileBertForTokenClassification,
							        "zero-shot": MobileBertForSequenceClassification,
							    }
							    if is_torch_available()
							    else {}
							)
							UpperCAmelCase_     		=       True






							def    A_      (   self      :	Optional[Any],					_UpperCAmelCase      :	Dict,					_UpperCAmelCase      :	Tuple,					_UpperCAmelCase      :	List[str]=False		) ->					Tuple:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__  :     Dict           =		super()._prepare_for_class(__a,					__a,					return_labels=__a		)

														if return_labels:
																					if model_class in get_values(__a		):
																												SCREAMING_SNAKE_CASE__  :     Optional[Any]           =		torch.zeros(
																												    (self.model_tester.batch_size, self.model_tester.seq_length),					dtype=torch.long,					device=__a		)
																												SCREAMING_SNAKE_CASE__  :     List[Any]           =		torch.zeros(
																												    self.model_tester.batch_size,					dtype=torch.long,					device=__a		)
														return inputs_dict






							def    A_      (   self      :	Optional[Any]		) ->					Dict:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__  :     int           =		MobileBertModelTester(self		)
														SCREAMING_SNAKE_CASE__  :     Tuple           =		ConfigTester(self,					config_class=__a,					hidden_size=3_7		)






							def    A_      (   self      :	Tuple		) ->					int:





														"""simple docstring"""
														self.config_tester.run_common_tests()






							def    A_      (   self      :	int		) ->					List[str]:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__  :     Optional[Any]           =		self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_mobilebert_model(*__a		)






							def    A_      (   self      :	Tuple		) ->					Any:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__  :     List[str]           =		self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_mobilebert_for_masked_lm(*__a		)






							def    A_      (   self      :	str		) ->					Optional[int]:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__  :     Optional[Any]           =		self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_mobilebert_for_multiple_choice(*__a		)






							def    A_      (   self      :	Union[str, Any]		) ->					Optional[int]:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__  :     str           =		self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_mobilebert_for_next_sequence_prediction(*__a		)






							def    A_      (   self      :	str		) ->					List[Any]:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__  :     Optional[int]           =		self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_mobilebert_for_pretraining(*__a		)






							def    A_      (   self      :	str		) ->					Optional[int]:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__  :     List[str]           =		self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_mobilebert_for_question_answering(*__a		)






							def    A_      (   self      :	Dict		) ->					List[str]:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__  :     int           =		self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_mobilebert_for_sequence_classification(*__a		)






							def    A_      (   self      :	int		) ->					Union[str, Any]:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__  :     Optional[int]           =		self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_mobilebert_for_token_classification(*__a		)




def _a   (    SCREAMING_SNAKE_CASE__     :    int  )			->							Tuple:

							'''simple docstring'''






							return torch.tensor(
							    __snake_case					, dtype=torch.long					, device=__snake_case					, )


_lowerCamelCase   :							Union[str, Any]    				=   1e-3







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







							"""simple docstring"""




							@slow
							def    A_      (   self      :	Dict		) ->					Any:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__  :     Optional[Any]           =		MobileBertModel.from_pretrained("google/mobilebert-uncased"		).to(__a		)
														SCREAMING_SNAKE_CASE__  :     Union[str, Any]           =		_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():
																					SCREAMING_SNAKE_CASE__  :     Optional[int]           =		model(__a		)[0]
														SCREAMING_SNAKE_CASE__  :     Optional[int]           =		torch.Size((1, 9, 5_1_2)		)
														self.assertEqual(output.shape,					__a		)
														SCREAMING_SNAKE_CASE__  :     Optional[Any]           =		torch.tensor(
														    [
														        [
														            [-2.4736526E07, 8.2691656E04, 1.6521838E05],
														            [-5.7541704E-01, 3.9056022E00, 4.4011507E00],
														            [2.6047359E00, 1.5677652E00, -1.7324188E-01],
														        ]
														    ],					device=__a,					)

														# 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
														SCREAMING_SNAKE_CASE__  :     List[str]           =		torch.all((expected_slice / output[..., :3, :3]) >= 1 - TOLERANCE		)
														SCREAMING_SNAKE_CASE__  :     Union[str, Any]           =		torch.all((expected_slice / output[..., :3, :3]) <= 1 + TOLERANCE		)

														self.assertTrue(lower_bound and upper_bound		)








"""simple docstring"""





from __future__ import annotations

from functools import lru_cache
from math import ceil

_a								=						100

_a								=						set(range(3, NUM_PRIMES, 2))
primes.add(2)
_a								=						42

for prime in range(3, ceil(NUM_PRIMES**0.5), 2):
				if prime not in primes:
								continue
				primes.difference_update(set(range(prime * prime, NUM_PRIMES, prime)))



@lru_cache(maxsize=1_00      )
def  lowerCamelCase__						(     __snake_case      )				->						set[int]:


					"""simple docstring"""





					if number_to_partition < 0:
										return set()
					elif number_to_partition == 0:
										return {1}

					_UpperCamelCase									=    set()
					_UpperCamelCase									=    42
					_UpperCamelCase									=    42

					for prime in primes:
										if prime > number_to_partition:
															continue
										for sub in partition(number_to_partition - prime      ):
															ret.add(sub * prime      )

					return ret



def  lowerCamelCase__						(     __snake_case = 50_00      )				->						int | None:


					"""simple docstring"""





					for number_to_partition in range(1,	__snake_case      ):
										if len(partition(__snake_case      )      ) > number_unique_partitions:
															return number_to_partition
					return None


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






