
'''simple docstring'''


import inspect
import unittest
import warnings
from typing import List

from transformers import EfficientFormerConfig
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
	import torch

	from transformers import (
	    MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING,
	    MODEL_MAPPING,
	    EfficientFormerForImageClassification,
	    EfficientFormerForImageClassificationWithTeacher,
	    EfficientFormerModel,
	)
	from transformers.models.efficientformer.modeling_efficientformer import (
	    EFFICIENTFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
	)


if is_vision_available():
	from PIL import Image

	from transformers import EfficientFormerImageProcessor




class 						__snake_case :




		def __init__(     self				:List[Any] ,						_SCREAMING_SNAKE_CASE				:int ,						_SCREAMING_SNAKE_CASE				:int = 1_3 ,						_SCREAMING_SNAKE_CASE				:int = 6_4 ,						_SCREAMING_SNAKE_CASE				:int = 2 ,						_SCREAMING_SNAKE_CASE				:int = 3 ,						_SCREAMING_SNAKE_CASE				:int = 3 ,						_SCREAMING_SNAKE_CASE				:bool = True ,						_SCREAMING_SNAKE_CASE				:bool = True ,						_SCREAMING_SNAKE_CASE				:int = 1_2_8 ,						_SCREAMING_SNAKE_CASE				:List[str]=[1_6, 3_2, 6_4, 1_2_8] ,						_SCREAMING_SNAKE_CASE				:int = 7 ,						_SCREAMING_SNAKE_CASE				:int = 4 ,						_SCREAMING_SNAKE_CASE				:int = 3_7 ,						_SCREAMING_SNAKE_CASE				:str = "gelu" ,						_SCREAMING_SNAKE_CASE				:float = 0.1 ,						_SCREAMING_SNAKE_CASE				:float = 0.1 ,						_SCREAMING_SNAKE_CASE				:int = 1_0 ,						_SCREAMING_SNAKE_CASE				:float = 0.02 ,						_SCREAMING_SNAKE_CASE				:int = 2 ,						_SCREAMING_SNAKE_CASE				:int = 1 ,						_SCREAMING_SNAKE_CASE				:int = 1_2_8 ,						_SCREAMING_SNAKE_CASE				:List[int] = [2, 2, 2, 2] ,						_SCREAMING_SNAKE_CASE				:int = 2 ,						_SCREAMING_SNAKE_CASE				:int = 2 ,						)				-> Union[str, Any]:






								'''simple docstring'''






								UpperCamelCase_    :  List[Any]				    =    parent
								UpperCamelCase_    :  List[str]				    =    batch_size
								UpperCamelCase_    :  str				    =    image_size
								UpperCamelCase_    :  Dict				    =    patch_size
								UpperCamelCase_    :  Optional[int]				    =    num_channels
								UpperCamelCase_    :  Tuple				    =    is_training
								UpperCamelCase_    :  Optional[int]				    =    use_labels
								UpperCamelCase_    :  Optional[int]				    =    hidden_size
								UpperCamelCase_    :  List[str]				    =    num_hidden_layers
								UpperCamelCase_    :  int				    =    num_attention_heads
								UpperCamelCase_    :  Optional[Any]				    =    intermediate_size
								UpperCamelCase_    :  Tuple				    =    hidden_act
								UpperCamelCase_    :  Dict				    =    hidden_dropout_prob
								UpperCamelCase_    :  List[Any]				    =    attention_probs_dropout_prob
								UpperCamelCase_    :  str				    =    type_sequence_label_size
								UpperCamelCase_    :  Optional[Any]				    =    initializer_range
								UpperCamelCase_    :  int				    =    encoder_stride
								UpperCamelCase_    :  str				    =    num_attention_outputs
								UpperCamelCase_    :  List[Any]				    =    embed_dim
								UpperCamelCase_    :  List[Any]				    =    embed_dim + 1
								UpperCamelCase_    :  List[Any]				    =    resolution
								UpperCamelCase_    :  str				    =    depths
								UpperCamelCase_    :  List[Any]				    =    hidden_sizes
								UpperCamelCase_    :  Optional[Any]				    =    dim
								UpperCamelCase_    :  Union[str, Any]				    =    mlp_expansion_ratio




		def   _snake_case  (     self				:Tuple)				-> List[Any]:






								'''simple docstring'''






								UpperCamelCase_    :  int				    =    floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size])

								UpperCamelCase_    :  str				    =    None
								if self.use_labels:
														UpperCamelCase_    :  Dict				    =    ids_tensor([self.batch_size] ,						self.type_sequence_label_size)

								UpperCamelCase_    :  Any				    =    self.get_config()
								return config, pixel_values, labels




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






								'''simple docstring'''






								return EfficientFormerConfig(
								    image_size=self.image_size ,						patch_size=self.patch_size ,						num_channels=self.num_channels ,						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 ,						is_decoder=_SCREAMING_SNAKE_CASE ,						initializer_range=self.initializer_range ,						encoder_stride=self.encoder_stride ,						resolution=self.resolution ,						depths=self.depths ,						hidden_sizes=self.hidden_sizes ,						dim=self.dim ,						mlp_expansion_ratio=self.mlp_expansion_ratio ,						)




		def   _snake_case  (     self				:List[Any] ,						_SCREAMING_SNAKE_CASE				:Dict ,						_SCREAMING_SNAKE_CASE				:int ,						_SCREAMING_SNAKE_CASE				:int)				-> str:






								'''simple docstring'''






								UpperCamelCase_    :  List[str]				    =    EfficientFormerModel(config=_SCREAMING_SNAKE_CASE)
								model.to(_SCREAMING_SNAKE_CASE)
								model.eval()
								UpperCamelCase_    :  Optional[int]				    =    model(_SCREAMING_SNAKE_CASE)
								self.parent.assertEqual(result.last_hidden_state.shape ,						(self.batch_size, self.seq_length, self.hidden_size))




		def   _snake_case  (     self				:Optional[int] ,						_SCREAMING_SNAKE_CASE				:int ,						_SCREAMING_SNAKE_CASE				:Optional[int] ,						_SCREAMING_SNAKE_CASE				:int)				-> List[Any]:






								'''simple docstring'''






								UpperCamelCase_    :  int				    =    self.type_sequence_label_size
								UpperCamelCase_    :  Optional[Any]				    =    EfficientFormerForImageClassification(_SCREAMING_SNAKE_CASE)
								model.to(_SCREAMING_SNAKE_CASE)
								model.eval()
								UpperCamelCase_    :  Tuple				    =    model(_SCREAMING_SNAKE_CASE ,						labels=_SCREAMING_SNAKE_CASE)
								self.parent.assertEqual(result.logits.shape ,						(self.batch_size, self.type_sequence_label_size))

								# test greyscale images
								UpperCamelCase_    :  Optional[int]				    =    1
								UpperCamelCase_    :  List[Any]				    =    EfficientFormerForImageClassification(_SCREAMING_SNAKE_CASE)
								model.to(_SCREAMING_SNAKE_CASE)
								model.eval()

								UpperCamelCase_    :  int				    =    floats_tensor([self.batch_size, 1, self.image_size, self.image_size])
								UpperCamelCase_    :  Optional[int]				    =    model(_SCREAMING_SNAKE_CASE)
								self.parent.assertEqual(result.logits.shape ,						(self.batch_size, self.type_sequence_label_size))





		def   _snake_case  (     self				:Tuple)				-> Dict:






								'''simple docstring'''






								UpperCamelCase_    :  List[str]				    =    self.prepare_config_and_inputs()
								(
								    (
								    UpperCamelCase_
								)    ,(
								    UpperCamelCase_
								)    ,(
								    UpperCamelCase_
								)    ,
								)    :  Optional[Any]				    =    config_and_inputs
								UpperCamelCase_    :  Optional[Any]				    =    {"""pixel_values""": pixel_values}
								return config, inputs_dict







@require_torch
class 						__snake_case (						_a				, _a				, unittest.TestCase  ):
		a_        =				(
		    (
		        EfficientFormerModel,
		        EfficientFormerForImageClassificationWithTeacher,
		        EfficientFormerForImageClassification,
		    )
		    if is_torch_available()
		    else ()
		)
		a_        =				(
		    {
		        "feature-extraction": EfficientFormerModel,
		        "image-classification": (
		            EfficientFormerForImageClassification,
		            EfficientFormerForImageClassificationWithTeacher,
		        ),
		    }
		    if is_torch_available()
		    else {}
		)
		a_        =				False

		a_        =				False
		a_        =				False
		a_        =				False




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






								'''simple docstring'''






								UpperCamelCase_    :  Union[str, Any]				    =    EfficientFormerModelTester(self)
								UpperCamelCase_    :  List[str]				    =    ConfigTester(
								    self ,						config_class=_SCREAMING_SNAKE_CASE ,						has_text_modality=_SCREAMING_SNAKE_CASE ,						hidden_size=3_7)




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






								'''simple docstring'''






								self.config_tester.run_common_tests()




		@unittest.skip(reason="""EfficientFormer does not use inputs_embeds""")
		def   _snake_case  (     self				:Tuple)				-> str:






								'''simple docstring'''






								pass




		@unittest.skip(reason="""EfficientFormer does not support input and output embeddings""")
		def   _snake_case  (     self				:Optional[int])				-> str:






								'''simple docstring'''






								pass




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






								'''simple docstring'''






								UpperCamelCase_    ,UpperCamelCase_    :  List[Any]				    =    self.model_tester.prepare_config_and_inputs_for_common()

								for model_class in self.all_model_classes:
														UpperCamelCase_    :  Union[str, Any]				    =    model_class(_SCREAMING_SNAKE_CASE)
														UpperCamelCase_    :  Tuple				    =    inspect.signature(model.forward)
														# signature.parameters is an OrderedDict => so arg_names order is deterministic
														UpperCamelCase_    :  Union[str, Any]				    =    [*signature.parameters.keys()]

														UpperCamelCase_    :  List[Any]				    =    ["""pixel_values"""]
														self.assertListEqual(arg_names[:1] ,						_SCREAMING_SNAKE_CASE)




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






								'''simple docstring'''






								def check_hidden_states_output(_SCREAMING_SNAKE_CASE				:Union[str, Any] ,						_SCREAMING_SNAKE_CASE				:Dict ,						_SCREAMING_SNAKE_CASE				:List[Any]):
														UpperCamelCase_    :  Tuple				    =    model_class(_SCREAMING_SNAKE_CASE)
														model.to(_SCREAMING_SNAKE_CASE)
														model.eval()

														with torch.no_grad():
																				UpperCamelCase_    :  List[str]				    =    model(**self._prepare_for_class(_SCREAMING_SNAKE_CASE ,						_SCREAMING_SNAKE_CASE))

														UpperCamelCase_    :  Tuple				    =    outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

														UpperCamelCase_    :  Union[str, Any]				    =    getattr(
														    self.model_tester ,						"""expected_num_hidden_layers""" ,						self.model_tester.num_hidden_layers + 1)
														self.assertEqual(len(_SCREAMING_SNAKE_CASE) ,						_SCREAMING_SNAKE_CASE)

														if hasattr(self.model_tester ,						"""encoder_seq_length"""):
																				UpperCamelCase_    :  Union[str, Any]				    =    self.model_tester.encoder_seq_length
																				if hasattr(self.model_tester ,						"""chunk_length""") and self.model_tester.chunk_length > 1:
																										UpperCamelCase_    :  List[str]				    =    seq_length * self.model_tester.chunk_length
														else:
																				UpperCamelCase_    :  Union[str, Any]				    =    self.model_tester.seq_length

														self.assertListEqual(
														    list(hidden_states[-1].shape[-2:]) ,						[seq_length, self.model_tester.hidden_size] ,						)

														if config.is_encoder_decoder:
																				UpperCamelCase_    :  Dict				    =    outputs.decoder_hidden_states

																				self.assertIsInstance(_SCREAMING_SNAKE_CASE ,						(list, tuple))
																				self.assertEqual(len(_SCREAMING_SNAKE_CASE) ,						_SCREAMING_SNAKE_CASE)
																				UpperCamelCase_    :  Union[str, Any]				    =    getattr(self.model_tester ,						"""seq_length""" ,						_SCREAMING_SNAKE_CASE)
																				UpperCamelCase_    :  Optional[Any]				    =    getattr(self.model_tester ,						"""decoder_seq_length""" ,						_SCREAMING_SNAKE_CASE)

																				self.assertListEqual(
																				    list(hidden_states[-1].shape[-2:]) ,						[decoder_seq_length, self.model_tester.hidden_size] ,						)

								UpperCamelCase_    ,UpperCamelCase_    :  Optional[int]				    =    self.model_tester.prepare_config_and_inputs_for_common()

								for model_class in self.all_model_classes:
														UpperCamelCase_    :  List[Any]				    =    True
														check_hidden_states_output(_SCREAMING_SNAKE_CASE ,						_SCREAMING_SNAKE_CASE ,						_SCREAMING_SNAKE_CASE)

														# check that output_hidden_states also work using config
														del inputs_dict["output_hidden_states"]
														UpperCamelCase_    :  Union[str, Any]				    =    True

														check_hidden_states_output(_SCREAMING_SNAKE_CASE ,						_SCREAMING_SNAKE_CASE ,						_SCREAMING_SNAKE_CASE)




		def   _snake_case  (     self				:List[str] ,						_SCREAMING_SNAKE_CASE				:List[Any] ,						_SCREAMING_SNAKE_CASE				:Optional[Any] ,						_SCREAMING_SNAKE_CASE				:Optional[int]=False)				-> Union[str, Any]:






								'''simple docstring'''






								UpperCamelCase_    :  Optional[int]				    =    super()._prepare_for_class(_SCREAMING_SNAKE_CASE ,						_SCREAMING_SNAKE_CASE ,						return_labels=_SCREAMING_SNAKE_CASE)

								if return_labels:
														if model_class.__name__ == "EfficientFormerForImageClassificationWithTeacher":
																				del inputs_dict["labels"]

								return inputs_dict




		def   _snake_case  (     self				:List[Any])				-> Dict:






								'''simple docstring'''






								UpperCamelCase_    :  int				    =    self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_model(*_SCREAMING_SNAKE_CASE)




		@unittest.skip(reason="""EfficientFormer does not implement masked image modeling yet""")
		def   _snake_case  (     self				:List[str])				-> List[Any]:






								'''simple docstring'''






								UpperCamelCase_    :  int				    =    self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_masked_image_modeling(*_SCREAMING_SNAKE_CASE)




		def   _snake_case  (     self				:Dict)				-> str:






								'''simple docstring'''






								UpperCamelCase_    :  List[Any]				    =    self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_image_classification(*_SCREAMING_SNAKE_CASE)




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






								'''simple docstring'''






								if not self.model_tester.is_training:
														return

								UpperCamelCase_    ,UpperCamelCase_    :  Optional[Any]				    =    self.model_tester.prepare_config_and_inputs_for_common()
								UpperCamelCase_    :  Union[str, Any]				    =    True

								for model_class in self.all_model_classes:
														# EfficientFormerForImageClassificationWithTeacher supports inference-only
														if (
														    model_class in get_values(_SCREAMING_SNAKE_CASE)
														    or model_class.__name__ == "EfficientFormerForImageClassificationWithTeacher"
														):
																				continue
														UpperCamelCase_    :  Dict				    =    model_class(_SCREAMING_SNAKE_CASE)
														model.to(_SCREAMING_SNAKE_CASE)
														model.train()
														UpperCamelCase_    :  Union[str, Any]				    =    self._prepare_for_class(_SCREAMING_SNAKE_CASE ,						_SCREAMING_SNAKE_CASE ,						return_labels=_SCREAMING_SNAKE_CASE)
														UpperCamelCase_    :  Any				    =    model(**_SCREAMING_SNAKE_CASE).loss
														loss.backward()




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






								'''simple docstring'''






								UpperCamelCase_    ,UpperCamelCase_    :  Tuple				    =    self.model_tester.prepare_config_and_inputs_for_common()

								UpperCamelCase_    :  Optional[Any]				    =    [
								    {"""title""": """multi_label_classification""", """num_labels""": 2, """dtype""": torch.float},
								    {"""title""": """single_label_classification""", """num_labels""": 1, """dtype""": torch.long},
								    {"""title""": """regression""", """num_labels""": 1, """dtype""": torch.float},
								]

								for model_class in self.all_model_classes:
														if (
														    model_class
														    not in [
														        *get_values(_SCREAMING_SNAKE_CASE),
														    ]
														    or model_class.__name__ == "EfficientFormerForImageClassificationWithTeacher"
														):
																				continue

														for problem_type in problem_types:
																				with self.subTest(msg=F"""Testing {model_class} with {problem_type['title']}"""):
																										UpperCamelCase_    :  Union[str, Any]				    =    problem_type["""title"""]
																										UpperCamelCase_    :  Any				    =    problem_type["""num_labels"""]

																										UpperCamelCase_    :  int				    =    model_class(_SCREAMING_SNAKE_CASE)
																										model.to(_SCREAMING_SNAKE_CASE)
																										model.train()

																										UpperCamelCase_    :  Dict				    =    self._prepare_for_class(_SCREAMING_SNAKE_CASE ,						_SCREAMING_SNAKE_CASE ,						return_labels=_SCREAMING_SNAKE_CASE)

																										if problem_type["num_labels"] > 1:
																																UpperCamelCase_    :  List[str]				    =    inputs["""labels"""].unsqueeze(1).repeat(1 ,						problem_type["""num_labels"""])

																										UpperCamelCase_    :  int				    =    inputs["""labels"""].to(problem_type["""dtype"""])

																										# This tests that we do not trigger the warning form PyTorch "Using a target size that is different
																										# to the input size. This will likely lead to incorrect results due to broadcasting. Please ensure
																										# they have the same size." which is a symptom something in wrong for the regression problem.
																										# See https://github.com/huggingface/transformers/issues/11780
																										with warnings.catch_warnings(record=_SCREAMING_SNAKE_CASE) as warning_list:
																																UpperCamelCase_    :  Tuple				    =    model(**_SCREAMING_SNAKE_CASE).loss
																										for w in warning_list:
																																if "Using a target size that is different to the input size" in str(w.message):
																																						raise ValueError(
																																						    F"""Something is going wrong in the regression problem: intercepted {w.message}""")

																										loss.backward()




		@slow
		def   _snake_case  (     self				:Any)				-> Optional[Any]:






								'''simple docstring'''






								for model_name in EFFICIENTFORMER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
														UpperCamelCase_    :  Tuple				    =    EfficientFormerModel.from_pretrained(_SCREAMING_SNAKE_CASE)
														self.assertIsNotNone(_SCREAMING_SNAKE_CASE)





		def   _snake_case  (     self				:Union[str, Any])				-> List[str]:






								'''simple docstring'''






								UpperCamelCase_    ,UpperCamelCase_    :  Tuple				    =    self.model_tester.prepare_config_and_inputs_for_common()
								UpperCamelCase_    :  int				    =    True

								UpperCamelCase_    :  Tuple				    =    getattr(self.model_tester ,						"""seq_length""" ,						_SCREAMING_SNAKE_CASE)
								UpperCamelCase_    :  List[str]				    =    getattr(self.model_tester ,						"""encoder_seq_length""" ,						_SCREAMING_SNAKE_CASE)
								UpperCamelCase_    :  Any				    =    getattr(self.model_tester ,						"""key_length""" ,						_SCREAMING_SNAKE_CASE)
								UpperCamelCase_    :  Dict				    =    getattr(self.model_tester ,						"""chunk_length""" ,						_SCREAMING_SNAKE_CASE)

								if chunk_length is not None and hasattr(self.model_tester ,						"""num_hashes"""):
														UpperCamelCase_    :  Tuple				    =    encoder_seq_length * self.model_tester.num_hashes

								for model_class in self.all_model_classes:
														UpperCamelCase_    :  Any				    =    True
														UpperCamelCase_    :  Any				    =    False
														UpperCamelCase_    :  Optional[Any]				    =    True
														UpperCamelCase_    :  Union[str, Any]				    =    model_class(_SCREAMING_SNAKE_CASE)
														model.to(_SCREAMING_SNAKE_CASE)
														model.eval()
														with torch.no_grad():
																				UpperCamelCase_    :  Dict				    =    model(**self._prepare_for_class(_SCREAMING_SNAKE_CASE ,						_SCREAMING_SNAKE_CASE))
														UpperCamelCase_    :  Optional[Any]				    =    outputs.encoder_attentions if config.is_encoder_decoder else outputs.attentions
														self.assertEqual(len(_SCREAMING_SNAKE_CASE) ,						self.model_tester.num_attention_outputs)

														# check that output_attentions also work using config
														del inputs_dict["output_attentions"]
														UpperCamelCase_    :  Dict				    =    True
														UpperCamelCase_    :  Optional[Any]				    =    model_class(_SCREAMING_SNAKE_CASE)
														model.to(_SCREAMING_SNAKE_CASE)
														model.eval()
														with torch.no_grad():
																				UpperCamelCase_    :  Optional[Any]				    =    model(**self._prepare_for_class(_SCREAMING_SNAKE_CASE ,						_SCREAMING_SNAKE_CASE))
														UpperCamelCase_    :  Optional[int]				    =    outputs.encoder_attentions if config.is_encoder_decoder else outputs.attentions
														self.assertEqual(len(_SCREAMING_SNAKE_CASE) ,						self.model_tester.num_attention_outputs)

														if chunk_length is not None:
																				self.assertListEqual(
																				    list(attentions[0].shape[-4:]) ,						[self.model_tester.num_attention_heads, encoder_seq_length, chunk_length, encoder_key_length] ,						)
														else:
																				self.assertListEqual(
																				    list(attentions[0].shape[-3:]) ,						[self.model_tester.num_attention_heads, encoder_seq_length, encoder_key_length] ,						)







def 				__magic_name__(					):
						UpperCamelCase_    :  Dict				    =    Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""  )
						return image







@require_torch
@require_vision
class 						__snake_case (						unittest.TestCase  ):




		@cached_property
		def   _snake_case  (     self				:Tuple)				-> Union[str, Any]:






								'''simple docstring'''






								return (
								    EfficientFormerImageProcessor.from_pretrained("""snap-research/efficientformer-l1-300""")
								    if is_vision_available()
								    else None
								)




		@slow
		def   _snake_case  (     self				:Dict)				-> str:






								'''simple docstring'''






								UpperCamelCase_    :  Tuple				    =    EfficientFormerForImageClassification.from_pretrained("""snap-research/efficientformer-l1-300""").to(
								    _SCREAMING_SNAKE_CASE)

								UpperCamelCase_    :  List[str]				    =    self.default_image_processor
								UpperCamelCase_    :  Optional[Any]				    =    prepare_img()
								UpperCamelCase_    :  List[str]				    =    image_processor(images=_SCREAMING_SNAKE_CASE ,						return_tensors="""pt""").to(_SCREAMING_SNAKE_CASE)

								# forward pass
								with torch.no_grad():
														UpperCamelCase_    :  int				    =    model(**_SCREAMING_SNAKE_CASE)

								# verify the logits
								UpperCamelCase_    :  int				    =    (1, 1_0_0_0)
								self.assertEqual(outputs.logits.shape ,						_SCREAMING_SNAKE_CASE)

								UpperCamelCase_    :  str				    =    torch.tensor([-0.0555, 0.4825, -0.0852]).to(_SCREAMING_SNAKE_CASE)
								self.assertTrue(torch.allclose(outputs.logits[0][:3] ,						_SCREAMING_SNAKE_CASE ,						atol=1E-4))





		@slow
		def   _snake_case  (     self				:Tuple)				-> Optional[Any]:






								'''simple docstring'''






								UpperCamelCase_    :  Union[str, Any]				    =    EfficientFormerForImageClassificationWithTeacher.from_pretrained(
								    """snap-research/efficientformer-l1-300""").to(_SCREAMING_SNAKE_CASE)

								UpperCamelCase_    :  Tuple				    =    self.default_image_processor
								UpperCamelCase_    :  int				    =    prepare_img()
								UpperCamelCase_    :  List[str]				    =    image_processor(images=_SCREAMING_SNAKE_CASE ,						return_tensors="""pt""").to(_SCREAMING_SNAKE_CASE)

								# forward pass
								with torch.no_grad():
														UpperCamelCase_    :  Dict				    =    model(**_SCREAMING_SNAKE_CASE)

								# verify the logits
								UpperCamelCase_    :  Optional[int]				    =    (1, 1_0_0_0)
								self.assertEqual(outputs.logits.shape ,						_SCREAMING_SNAKE_CASE)

								UpperCamelCase_    :  List[str]				    =    torch.tensor([-0.1312, 0.4353, -1.0499]).to(_SCREAMING_SNAKE_CASE)
								self.assertTrue(torch.allclose(outputs.logits[0][:3] ,						_SCREAMING_SNAKE_CASE ,						atol=1E-4))






'''simple docstring'''


import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils import AddedToken
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_mpnet import MPNetTokenizer


__SCREAMING_SNAKE_CASE  =			logging.get_logger(__name__)

__SCREAMING_SNAKE_CASE  =			{"vocab_file": "vocab.txt", "tokenizer_file": "tokenizer.json"}

__SCREAMING_SNAKE_CASE  =			{
    "vocab_file": {
        "microsoft/mpnet-base": "https://huggingface.co/microsoft/mpnet-base/resolve/main/vocab.txt",
    },
    "tokenizer_file": {
        "microsoft/mpnet-base": "https://huggingface.co/microsoft/mpnet-base/resolve/main/tokenizer.json",
    },
}

__SCREAMING_SNAKE_CASE  =			{
    "microsoft/mpnet-base": 512,
}

__SCREAMING_SNAKE_CASE  =			{
    "microsoft/mpnet-base": {"do_lower_case": True},
}




class 						__snake_case (						_a  ):
		a_        =				VOCAB_FILES_NAMES
		a_        =				PRETRAINED_VOCAB_FILES_MAP
		a_        =				PRETRAINED_INIT_CONFIGURATION
		a_        =				PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
		a_        =				MPNetTokenizer
		a_        =				["input_ids", "attention_mask"]




		def __init__(     self				:Tuple ,						_SCREAMING_SNAKE_CASE				:Dict=None ,						_SCREAMING_SNAKE_CASE				:List[Any]=None ,						_SCREAMING_SNAKE_CASE				:Optional[Any]=True ,						_SCREAMING_SNAKE_CASE				:Any="<s>" ,						_SCREAMING_SNAKE_CASE				:int="</s>" ,						_SCREAMING_SNAKE_CASE				:Optional[Any]="</s>" ,						_SCREAMING_SNAKE_CASE				:Any="<s>" ,						_SCREAMING_SNAKE_CASE				:Optional[int]="[UNK]" ,						_SCREAMING_SNAKE_CASE				:List[Any]="<pad>" ,						_SCREAMING_SNAKE_CASE				:int="<mask>" ,						_SCREAMING_SNAKE_CASE				:Union[str, Any]=True ,						_SCREAMING_SNAKE_CASE				:Union[str, Any]=None ,						**_SCREAMING_SNAKE_CASE				:Optional[int] ,						)				-> Optional[Any]:






								'''simple docstring'''






								super().__init__(
								    _SCREAMING_SNAKE_CASE ,						tokenizer_file=_SCREAMING_SNAKE_CASE ,						do_lower_case=_SCREAMING_SNAKE_CASE ,						bos_token=_SCREAMING_SNAKE_CASE ,						eos_token=_SCREAMING_SNAKE_CASE ,						sep_token=_SCREAMING_SNAKE_CASE ,						cls_token=_SCREAMING_SNAKE_CASE ,						unk_token=_SCREAMING_SNAKE_CASE ,						pad_token=_SCREAMING_SNAKE_CASE ,						mask_token=_SCREAMING_SNAKE_CASE ,						tokenize_chinese_chars=_SCREAMING_SNAKE_CASE ,						strip_accents=_SCREAMING_SNAKE_CASE ,						**_SCREAMING_SNAKE_CASE ,						)

								UpperCamelCase_    :  Dict				    =    json.loads(self.backend_tokenizer.normalizer.__getstate__())
								if (
								    pre_tok_state.get("""lowercase""" ,						_SCREAMING_SNAKE_CASE) != do_lower_case
								    or pre_tok_state.get("""strip_accents""" ,						_SCREAMING_SNAKE_CASE) != strip_accents
								):
														UpperCamelCase_    :  Any				    =    getattr(_SCREAMING_SNAKE_CASE ,						pre_tok_state.pop("""type"""))
														UpperCamelCase_    :  Optional[int]				    =    do_lower_case
														UpperCamelCase_    :  str				    =    strip_accents
														UpperCamelCase_    :  str				    =    pre_tok_class(**_SCREAMING_SNAKE_CASE)

								UpperCamelCase_    :  List[str]				    =    do_lower_case




		@property
		def   _snake_case  (     self				:Optional[int])				-> str:






								'''simple docstring'''






								if self._mask_token is None:
														if self.verbose:
																				logger.error("""Using mask_token, but it is not set yet.""")
														return None
								return str(self._mask_token)




		@mask_token.setter
		def   _snake_case  (     self				:Optional[Any] ,						_SCREAMING_SNAKE_CASE				:List[Any])				-> int:






								'''simple docstring'''






								UpperCamelCase_    :  Tuple				    =    AddedToken(_SCREAMING_SNAKE_CASE ,						lstrip=_SCREAMING_SNAKE_CASE ,						rstrip=_SCREAMING_SNAKE_CASE) if isinstance(_SCREAMING_SNAKE_CASE ,						_SCREAMING_SNAKE_CASE) else value
								UpperCamelCase_    :  int				    =    value




		def   _snake_case  (     self				:str ,						_SCREAMING_SNAKE_CASE				:int ,						_SCREAMING_SNAKE_CASE				:Any=None)				-> str:






								'''simple docstring'''






								UpperCamelCase_    :  Tuple				    =    [self.bos_token_id] + token_ids_a + [self.eos_token_id]
								if token_ids_a is None:
														return output

								return output + [self.eos_token_id] + token_ids_a + [self.eos_token_id]




		def   _snake_case  (     self				:Optional[Any] ,						_SCREAMING_SNAKE_CASE				:List[int] ,						_SCREAMING_SNAKE_CASE				:Optional[List[int]] = None)				-> List[int]:






								'''simple docstring'''






								UpperCamelCase_    :  Optional[Any]				    =    [self.sep_token_id]
								UpperCamelCase_    :  Dict				    =    [self.cls_token_id]

								if token_ids_a is None:
														return len(cls + token_ids_a + sep) * [0]
								return len(cls + token_ids_a + sep + sep + token_ids_a + sep) * [0]





		def   _snake_case  (     self				:List[str] ,						_SCREAMING_SNAKE_CASE				:str ,						_SCREAMING_SNAKE_CASE				:Optional[str] = None)				-> Tuple[str]:






								'''simple docstring'''






								UpperCamelCase_    :  List[str]				    =    self._tokenizer.model.save(_SCREAMING_SNAKE_CASE ,						name=_SCREAMING_SNAKE_CASE)
								return tuple(_SCREAMING_SNAKE_CASE)




