


from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_torch_available,
)


UpperCAmelCase_		:       Union[str, Any]							       =		{
    'auto_factory': ['get_values'],
    'configuration_auto': ['ALL_PRETRAINED_CONFIG_ARCHIVE_MAP', 'CONFIG_MAPPING', 'MODEL_NAMES_MAPPING', 'AutoConfig'],
    'feature_extraction_auto': ['FEATURE_EXTRACTOR_MAPPING', 'AutoFeatureExtractor'],
    'image_processing_auto': ['IMAGE_PROCESSOR_MAPPING', 'AutoImageProcessor'],
    'processing_auto': ['PROCESSOR_MAPPING', 'AutoProcessor'],
    'tokenization_auto': ['TOKENIZER_MAPPING', 'AutoTokenizer'],
}

try:
				if not is_torch_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				UpperCAmelCase_		:       Optional[int]							       =		[
				    'MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING',
				    'MODEL_FOR_AUDIO_FRAME_CLASSIFICATION_MAPPING',
				    'MODEL_FOR_AUDIO_XVECTOR_MAPPING',
				    'MODEL_FOR_BACKBONE_MAPPING',
				    'MODEL_FOR_CAUSAL_IMAGE_MODELING_MAPPING',
				    'MODEL_FOR_CAUSAL_LM_MAPPING',
				    'MODEL_FOR_CTC_MAPPING',
				    'MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING',
				    'MODEL_FOR_DEPTH_ESTIMATION_MAPPING',
				    'MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING',
				    'MODEL_FOR_IMAGE_SEGMENTATION_MAPPING',
				    'MODEL_FOR_INSTANCE_SEGMENTATION_MAPPING',
				    'MODEL_FOR_MASKED_IMAGE_MODELING_MAPPING',
				    'MODEL_FOR_MASKED_LM_MAPPING',
				    'MODEL_FOR_MASK_GENERATION_MAPPING',
				    'MODEL_FOR_MULTIPLE_CHOICE_MAPPING',
				    'MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING',
				    'MODEL_FOR_OBJECT_DETECTION_MAPPING',
				    'MODEL_FOR_PRETRAINING_MAPPING',
				    'MODEL_FOR_QUESTION_ANSWERING_MAPPING',
				    'MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING',
				    'MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING',
				    'MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING',
				    'MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING',
				    'MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING',
				    'MODEL_FOR_TEXT_ENCODING_MAPPING',
				    'MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING',
				    'MODEL_FOR_UNIVERSAL_SEGMENTATION_MAPPING',
				    'MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING',
				    'MODEL_FOR_VISION_2_SEQ_MAPPING',
				    'MODEL_FOR_VISUAL_QUESTION_ANSWERING_MAPPING',
				    'MODEL_MAPPING',
				    'MODEL_WITH_LM_HEAD_MAPPING',
				    'MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING',
				    'MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING',
				    'AutoModel',
				    'AutoBackbone',
				    'AutoModelForAudioClassification',
				    'AutoModelForAudioFrameClassification',
				    'AutoModelForAudioXVector',
				    'AutoModelForCausalLM',
				    'AutoModelForCTC',
				    'AutoModelForDepthEstimation',
				    'AutoModelForImageClassification',
				    'AutoModelForImageSegmentation',
				    'AutoModelForInstanceSegmentation',
				    'AutoModelForMaskGeneration',
				    'AutoModelForTextEncoding',
				    'AutoModelForMaskedImageModeling',
				    'AutoModelForMaskedLM',
				    'AutoModelForMultipleChoice',
				    'AutoModelForNextSentencePrediction',
				    'AutoModelForObjectDetection',
				    'AutoModelForPreTraining',
				    'AutoModelForQuestionAnswering',
				    'AutoModelForSemanticSegmentation',
				    'AutoModelForSeq2SeqLM',
				    'AutoModelForSequenceClassification',
				    'AutoModelForSpeechSeq2Seq',
				    'AutoModelForTableQuestionAnswering',
				    'AutoModelForTokenClassification',
				    'AutoModelForUniversalSegmentation',
				    'AutoModelForVideoClassification',
				    'AutoModelForVision2Seq',
				    'AutoModelForVisualQuestionAnswering',
				    'AutoModelForDocumentQuestionAnswering',
				    'AutoModelWithLMHead',
				    'AutoModelForZeroShotImageClassification',
				    'AutoModelForZeroShotObjectDetection',
				]

try:
				if not is_tf_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				UpperCAmelCase_		:       Dict							       =		[
				    'TF_MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING',
				    'TF_MODEL_FOR_CAUSAL_LM_MAPPING',
				    'TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING',
				    'TF_MODEL_FOR_MASK_GENERATION_MAPPING',
				    'TF_MODEL_FOR_MASKED_IMAGE_MODELING_MAPPING',
				    'TF_MODEL_FOR_MASKED_LM_MAPPING',
				    'TF_MODEL_FOR_MULTIPLE_CHOICE_MAPPING',
				    'TF_MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING',
				    'TF_MODEL_FOR_PRETRAINING_MAPPING',
				    'TF_MODEL_FOR_QUESTION_ANSWERING_MAPPING',
				    'TF_MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING',
				    'TF_MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING',
				    'TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING',
				    'TF_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING',
				    'TF_MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING',
				    'TF_MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING',
				    'TF_MODEL_FOR_TEXT_ENCODING_MAPPING',
				    'TF_MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING',
				    'TF_MODEL_FOR_VISION_2_SEQ_MAPPING',
				    'TF_MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING',
				    'TF_MODEL_MAPPING',
				    'TF_MODEL_WITH_LM_HEAD_MAPPING',
				    'TFAutoModel',
				    'TFAutoModelForAudioClassification',
				    'TFAutoModelForCausalLM',
				    'TFAutoModelForImageClassification',
				    'TFAutoModelForMaskedImageModeling',
				    'TFAutoModelForMaskedLM',
				    'TFAutoModelForMaskGeneration',
				    'TFAutoModelForMultipleChoice',
				    'TFAutoModelForNextSentencePrediction',
				    'TFAutoModelForPreTraining',
				    'TFAutoModelForDocumentQuestionAnswering',
				    'TFAutoModelForQuestionAnswering',
				    'TFAutoModelForSemanticSegmentation',
				    'TFAutoModelForSeq2SeqLM',
				    'TFAutoModelForSequenceClassification',
				    'TFAutoModelForSpeechSeq2Seq',
				    'TFAutoModelForTableQuestionAnswering',
				    'TFAutoModelForTextEncoding',
				    'TFAutoModelForTokenClassification',
				    'TFAutoModelForVision2Seq',
				    'TFAutoModelForZeroShotImageClassification',
				    'TFAutoModelWithLMHead',
				]

try:
				if not is_flax_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				UpperCAmelCase_		:       Any							       =		[
				    'FLAX_MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING',
				    'FLAX_MODEL_FOR_CAUSAL_LM_MAPPING',
				    'FLAX_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING',
				    'FLAX_MODEL_FOR_MASKED_LM_MAPPING',
				    'FLAX_MODEL_FOR_MULTIPLE_CHOICE_MAPPING',
				    'FLAX_MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING',
				    'FLAX_MODEL_FOR_PRETRAINING_MAPPING',
				    'FLAX_MODEL_FOR_QUESTION_ANSWERING_MAPPING',
				    'FLAX_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING',
				    'FLAX_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING',
				    'FLAX_MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING',
				    'FLAX_MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING',
				    'FLAX_MODEL_FOR_VISION_2_SEQ_MAPPING',
				    'FLAX_MODEL_MAPPING',
				    'FlaxAutoModel',
				    'FlaxAutoModelForCausalLM',
				    'FlaxAutoModelForImageClassification',
				    'FlaxAutoModelForMaskedLM',
				    'FlaxAutoModelForMultipleChoice',
				    'FlaxAutoModelForNextSentencePrediction',
				    'FlaxAutoModelForPreTraining',
				    'FlaxAutoModelForQuestionAnswering',
				    'FlaxAutoModelForSeq2SeqLM',
				    'FlaxAutoModelForSequenceClassification',
				    'FlaxAutoModelForSpeechSeq2Seq',
				    'FlaxAutoModelForTokenClassification',
				    'FlaxAutoModelForVision2Seq',
				]


if TYPE_CHECKING:
				from .auto_factory import get_values
				from .configuration_auto import ALL_PRETRAINED_CONFIG_ARCHIVE_MAP, CONFIG_MAPPING, MODEL_NAMES_MAPPING, AutoConfig
				from .feature_extraction_auto import FEATURE_EXTRACTOR_MAPPING, AutoFeatureExtractor
				from .image_processing_auto import IMAGE_PROCESSOR_MAPPING, AutoImageProcessor
				from .processing_auto import PROCESSOR_MAPPING, AutoProcessor
				from .tokenization_auto import TOKENIZER_MAPPING, AutoTokenizer

				try:
								if not is_torch_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .modeling_auto import (
								    MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING,
								    MODEL_FOR_AUDIO_FRAME_CLASSIFICATION_MAPPING,
								    MODEL_FOR_AUDIO_XVECTOR_MAPPING,
								    MODEL_FOR_BACKBONE_MAPPING,
								    MODEL_FOR_CAUSAL_IMAGE_MODELING_MAPPING,
								    MODEL_FOR_CAUSAL_LM_MAPPING,
								    MODEL_FOR_CTC_MAPPING,
								    MODEL_FOR_DEPTH_ESTIMATION_MAPPING,
								    MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING,
								    MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING,
								    MODEL_FOR_IMAGE_SEGMENTATION_MAPPING,
								    MODEL_FOR_INSTANCE_SEGMENTATION_MAPPING,
								    MODEL_FOR_MASK_GENERATION_MAPPING,
								    MODEL_FOR_MASKED_IMAGE_MODELING_MAPPING,
								    MODEL_FOR_MASKED_LM_MAPPING,
								    MODEL_FOR_MULTIPLE_CHOICE_MAPPING,
								    MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING,
								    MODEL_FOR_OBJECT_DETECTION_MAPPING,
								    MODEL_FOR_PRETRAINING_MAPPING,
								    MODEL_FOR_QUESTION_ANSWERING_MAPPING,
								    MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING,
								    MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING,
								    MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING,
								    MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING,
								    MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING,
								    MODEL_FOR_TEXT_ENCODING_MAPPING,
								    MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING,
								    MODEL_FOR_UNIVERSAL_SEGMENTATION_MAPPING,
								    MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING,
								    MODEL_FOR_VISION_2_SEQ_MAPPING,
								    MODEL_FOR_VISUAL_QUESTION_ANSWERING_MAPPING,
								    MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING,
								    MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING,
								    MODEL_MAPPING,
								    MODEL_WITH_LM_HEAD_MAPPING,
								    AutoBackbone,
								    AutoModel,
								    AutoModelForAudioClassification,
								    AutoModelForAudioFrameClassification,
								    AutoModelForAudioXVector,
								    AutoModelForCausalLM,
								    AutoModelForCTC,
								    AutoModelForDepthEstimation,
								    AutoModelForDocumentQuestionAnswering,
								    AutoModelForImageClassification,
								    AutoModelForImageSegmentation,
								    AutoModelForInstanceSegmentation,
								    AutoModelForMaskedImageModeling,
								    AutoModelForMaskedLM,
								    AutoModelForMaskGeneration,
								    AutoModelForMultipleChoice,
								    AutoModelForNextSentencePrediction,
								    AutoModelForObjectDetection,
								    AutoModelForPreTraining,
								    AutoModelForQuestionAnswering,
								    AutoModelForSemanticSegmentation,
								    AutoModelForSeqaSeqLM,
								    AutoModelForSequenceClassification,
								    AutoModelForSpeechSeqaSeq,
								    AutoModelForTableQuestionAnswering,
								    AutoModelForTextEncoding,
								    AutoModelForTokenClassification,
								    AutoModelForUniversalSegmentation,
								    AutoModelForVideoClassification,
								    AutoModelForVisionaSeq,
								    AutoModelForVisualQuestionAnswering,
								    AutoModelForZeroShotImageClassification,
								    AutoModelForZeroShotObjectDetection,
								    AutoModelWithLMHead,
								)

				try:
								if not is_tf_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .modeling_tf_auto import (
								    TF_MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING,
								    TF_MODEL_FOR_CAUSAL_LM_MAPPING,
								    TF_MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING,
								    TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING,
								    TF_MODEL_FOR_MASK_GENERATION_MAPPING,
								    TF_MODEL_FOR_MASKED_IMAGE_MODELING_MAPPING,
								    TF_MODEL_FOR_MASKED_LM_MAPPING,
								    TF_MODEL_FOR_MULTIPLE_CHOICE_MAPPING,
								    TF_MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING,
								    TF_MODEL_FOR_PRETRAINING_MAPPING,
								    TF_MODEL_FOR_QUESTION_ANSWERING_MAPPING,
								    TF_MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING,
								    TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING,
								    TF_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING,
								    TF_MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING,
								    TF_MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING,
								    TF_MODEL_FOR_TEXT_ENCODING_MAPPING,
								    TF_MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING,
								    TF_MODEL_FOR_VISION_2_SEQ_MAPPING,
								    TF_MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING,
								    TF_MODEL_MAPPING,
								    TF_MODEL_WITH_LM_HEAD_MAPPING,
								    TFAutoModel,
								    TFAutoModelForAudioClassification,
								    TFAutoModelForCausalLM,
								    TFAutoModelForDocumentQuestionAnswering,
								    TFAutoModelForImageClassification,
								    TFAutoModelForMaskedImageModeling,
								    TFAutoModelForMaskedLM,
								    TFAutoModelForMaskGeneration,
								    TFAutoModelForMultipleChoice,
								    TFAutoModelForNextSentencePrediction,
								    TFAutoModelForPreTraining,
								    TFAutoModelForQuestionAnswering,
								    TFAutoModelForSemanticSegmentation,
								    TFAutoModelForSeqaSeqLM,
								    TFAutoModelForSequenceClassification,
								    TFAutoModelForSpeechSeqaSeq,
								    TFAutoModelForTableQuestionAnswering,
								    TFAutoModelForTextEncoding,
								    TFAutoModelForTokenClassification,
								    TFAutoModelForVisionaSeq,
								    TFAutoModelForZeroShotImageClassification,
								    TFAutoModelWithLMHead,
								)

				try:
								if not is_flax_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .modeling_flax_auto import (
								    FLAX_MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING,
								    FLAX_MODEL_FOR_CAUSAL_LM_MAPPING,
								    FLAX_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING,
								    FLAX_MODEL_FOR_MASKED_LM_MAPPING,
								    FLAX_MODEL_FOR_MULTIPLE_CHOICE_MAPPING,
								    FLAX_MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING,
								    FLAX_MODEL_FOR_PRETRAINING_MAPPING,
								    FLAX_MODEL_FOR_QUESTION_ANSWERING_MAPPING,
								    FLAX_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING,
								    FLAX_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING,
								    FLAX_MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING,
								    FLAX_MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING,
								    FLAX_MODEL_FOR_VISION_2_SEQ_MAPPING,
								    FLAX_MODEL_MAPPING,
								    FlaxAutoModel,
								    FlaxAutoModelForCausalLM,
								    FlaxAutoModelForImageClassification,
								    FlaxAutoModelForMaskedLM,
								    FlaxAutoModelForMultipleChoice,
								    FlaxAutoModelForNextSentencePrediction,
								    FlaxAutoModelForPreTraining,
								    FlaxAutoModelForQuestionAnswering,
								    FlaxAutoModelForSeqaSeqLM,
								    FlaxAutoModelForSequenceClassification,
								    FlaxAutoModelForSpeechSeqaSeq,
								    FlaxAutoModelForTokenClassification,
								    FlaxAutoModelForVisionaSeq,
								)

else:
				import sys

				UpperCAmelCase_		:       Any							       =		_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)








'''simple docstring'''


from __future__ import annotations

import inspect
import unittest

from transformers import MobileViTConfig
from transformers.file_utils import is_tf_available, is_vision_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
				import numpy as np
				import tensorflow as tf

				from transformers import TFMobileViTForImageClassification, TFMobileViTForSemanticSegmentation, TFMobileViTModel
				from transformers.models.mobilevit.modeling_tf_mobilevit import TF_MOBILEVIT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
				from PIL import Image

				from transformers import MobileViTImageProcessor





class    lowercase__  (						_snake_case ):





							'''simple docstring'''


							def UpperCAmelCase_     (   self  ):
											_SCREAMING_SNAKE_CASE			:	Union[str, Any]							=				self.config_class(**self.inputs_dict  )
											self.parent.assertTrue(hasattr(__snake_case   , """hidden_sizes"""  )  )
											self.parent.assertTrue(hasattr(__snake_case   , """neck_hidden_sizes"""  )  )
											self.parent.assertTrue(hasattr(__snake_case   , """num_attention_heads"""  )  )





class    lowercase__  :





							'''simple docstring'''


							def __init__(   self   , __snake_case   , __snake_case=13   , __snake_case=32   , __snake_case=2   , __snake_case=3   , __snake_case=640   , __snake_case=4   , __snake_case="silu"   , __snake_case=3   , __snake_case=32   , __snake_case=0.1   , __snake_case=0.1   , __snake_case=0.1   , __snake_case=0.02   , __snake_case=True   , __snake_case=True   , __snake_case=10   , __snake_case=None   , ):
											_SCREAMING_SNAKE_CASE			:	Optional[int]							=				parent
											_SCREAMING_SNAKE_CASE			:	Any							=				batch_size
											_SCREAMING_SNAKE_CASE			:	str							=				image_size
											_SCREAMING_SNAKE_CASE			:	str							=				patch_size
											_SCREAMING_SNAKE_CASE			:	Any							=				num_channels
											_SCREAMING_SNAKE_CASE			:	List[Any]							=				last_hidden_size
											_SCREAMING_SNAKE_CASE			:	Any							=				num_attention_heads
											_SCREAMING_SNAKE_CASE			:	Any							=				hidden_act
											_SCREAMING_SNAKE_CASE			:	Any							=				conv_kernel_size
											_SCREAMING_SNAKE_CASE			:	int							=				output_stride
											_SCREAMING_SNAKE_CASE			:	List[Any]							=				hidden_dropout_prob
											_SCREAMING_SNAKE_CASE			:	int							=				attention_probs_dropout_prob
											_SCREAMING_SNAKE_CASE			:	Any							=				classifier_dropout_prob
											_SCREAMING_SNAKE_CASE			:	List[Any]							=				use_labels
											_SCREAMING_SNAKE_CASE			:	List[str]							=				is_training
											_SCREAMING_SNAKE_CASE			:	Dict							=				num_labels
											_SCREAMING_SNAKE_CASE			:	Optional[Any]							=				initializer_range
											_SCREAMING_SNAKE_CASE			:	List[str]							=				scope






							def UpperCAmelCase_     (   self  ):
											_SCREAMING_SNAKE_CASE			:	Optional[Any]							=				floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]  )

											_SCREAMING_SNAKE_CASE			:	str							=				None
											_SCREAMING_SNAKE_CASE			:	int							=				None
											if self.use_labels:
															_SCREAMING_SNAKE_CASE			:	Optional[Any]							=				ids_tensor([self.batch_size]   , self.num_labels  )
															_SCREAMING_SNAKE_CASE			:	Union[str, Any]							=				ids_tensor([self.batch_size, self.image_size, self.image_size]   , self.num_labels  )

											_SCREAMING_SNAKE_CASE			:	Dict							=				self.get_config()

											return config, pixel_values, labels, pixel_labels






							def UpperCAmelCase_     (   self  ):
											return MobileViTConfig(
											    image_size=self.image_size   , patch_size=self.patch_size   , num_channels=self.num_channels   , num_attention_heads=self.num_attention_heads   , hidden_act=self.hidden_act   , conv_kernel_size=self.conv_kernel_size   , output_stride=self.output_stride   , hidden_dropout_prob=self.hidden_dropout_prob   , attention_probs_dropout_prob=self.attention_probs_dropout_prob   , classifier_dropout_prob=self.classifier_dropout_prob   , initializer_range=self.initializer_range   , )






							def UpperCAmelCase_     (   self   , __snake_case   , __snake_case   , __snake_case   , __snake_case  ):
											_SCREAMING_SNAKE_CASE			:	Any							=				TFMobileViTModel(config=__snake_case  )
											_SCREAMING_SNAKE_CASE			:	Any							=				model(__snake_case   , training=__snake_case  )
											_SCREAMING_SNAKE_CASE			:	Dict							=				self.image_size // self.output_stride
											self.parent.assertEqual(
											    result.last_hidden_state.shape   , (self.batch_size, self.last_hidden_size, expected_height, expected_width)  )






							def UpperCAmelCase_     (   self   , __snake_case   , __snake_case   , __snake_case   , __snake_case  ):
											_SCREAMING_SNAKE_CASE			:	Union[str, Any]							=				self.num_labels
											_SCREAMING_SNAKE_CASE			:	Any							=				TFMobileViTForImageClassification(__snake_case  )
											_SCREAMING_SNAKE_CASE			:	Dict							=				model(__snake_case   , labels=__snake_case   , training=__snake_case  )
											self.parent.assertEqual(result.logits.shape   , (self.batch_size, self.num_labels)  )






							def UpperCAmelCase_     (   self   , __snake_case   , __snake_case   , __snake_case   , __snake_case  ):
											_SCREAMING_SNAKE_CASE			:	Tuple							=				self.num_labels
											_SCREAMING_SNAKE_CASE			:	Optional[Any]							=				TFMobileViTForSemanticSegmentation(__snake_case  )
											_SCREAMING_SNAKE_CASE			:	Tuple							=				self.image_size // self.output_stride

											_SCREAMING_SNAKE_CASE			:	Union[str, Any]							=				model(__snake_case   , training=__snake_case  )
											self.parent.assertEqual(
											    result.logits.shape   , (self.batch_size, self.num_labels, expected_height, expected_width)  )

											_SCREAMING_SNAKE_CASE			:	Union[str, Any]							=				model(__snake_case   , labels=__snake_case   , training=__snake_case  )
											self.parent.assertEqual(
											    result.logits.shape   , (self.batch_size, self.num_labels, expected_height, expected_width)  )






							def UpperCAmelCase_     (   self  ):
											_SCREAMING_SNAKE_CASE			:	str							=				self.prepare_config_and_inputs()
											_SCREAMING_SNAKE_CASE		,	_SCREAMING_SNAKE_CASE		,	_SCREAMING_SNAKE_CASE		,	_SCREAMING_SNAKE_CASE			:	int							=				config_and_inputs
											_SCREAMING_SNAKE_CASE			:	Tuple							=				{"""pixel_values""": pixel_values}
											return config, inputs_dict





@require_tf
class    lowercase__  (						_snake_case					,					_snake_case					,					unittest.TestCase ):





							'''simple docstring'''


							A_							:				List[Any]				     =  (
							    (TFMobileViTModel, TFMobileViTForImageClassification, TFMobileViTForSemanticSegmentation)
							    if is_tf_available()
							    else ()
							)
							A_							:				List[str]				     =  (
							    {"""feature-extraction""": TFMobileViTModel, """image-classification""": TFMobileViTForImageClassification}
							    if is_tf_available()
							    else {}
							)

							A_							:				str				     =  False
							A_							:				int				     =  False
							A_							:				Union[str, Any]				     =  False
							A_							:				List[str]				     =  False
							A_							:				str				     =  False






							def UpperCAmelCase_     (   self  ):
											_SCREAMING_SNAKE_CASE			:	List[Any]							=				TFMobileViTModelTester(self  )
											_SCREAMING_SNAKE_CASE			:	Dict							=				TFMobileViTConfigTester(self   , config_class=__snake_case   , has_text_modality=__snake_case  )






							def UpperCAmelCase_     (   self  ):
											self.config_tester.run_common_tests()






							@unittest.skip(reason="""MobileViT does not use inputs_embeds"""  )
							def UpperCAmelCase_     (   self  ):
											pass






							@unittest.skip(reason="""MobileViT does not support input and output embeddings"""  )
							def UpperCAmelCase_     (   self  ):
											pass






							@unittest.skip(reason="""MobileViT does not output attentions"""  )
							def UpperCAmelCase_     (   self  ):
											pass






							def UpperCAmelCase_     (   self  ):
											_SCREAMING_SNAKE_CASE		,	_SCREAMING_SNAKE_CASE			:	str							=				self.model_tester.prepare_config_and_inputs_for_common()

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

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






							def UpperCAmelCase_     (   self  ):
											_SCREAMING_SNAKE_CASE			:	List[Any]							=				self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_model(*__snake_case  )






							def UpperCAmelCase_     (   self  ):
											def check_hidden_states_output(__snake_case   , __snake_case   , __snake_case  ):
															_SCREAMING_SNAKE_CASE			:	Optional[Any]							=				model_class(__snake_case  )

															_SCREAMING_SNAKE_CASE			:	List[str]							=				model(**self._prepare_for_class(__snake_case   , __snake_case  )  )

															_SCREAMING_SNAKE_CASE			:	Optional[int]							=				outputs.hidden_states

															_SCREAMING_SNAKE_CASE			:	Dict							=				5
															self.assertEqual(len(__snake_case  )   , __snake_case  )

															# MobileViT's feature maps are of shape (batch_size, num_channels, height, width)
															# with the width and height being successively divided by 2.
															_SCREAMING_SNAKE_CASE			:	int							=				2
															for i in range(len(__snake_case  )  ):
																			self.assertListEqual(
																			    list(hidden_states[i].shape[-2:]  )   , [self.model_tester.image_size // divisor, self.model_tester.image_size // divisor]   , )
																			divisor *= 2

															self.assertEqual(self.model_tester.output_stride   , divisor // 2  )

											_SCREAMING_SNAKE_CASE		,	_SCREAMING_SNAKE_CASE			:	Union[str, Any]							=				self.model_tester.prepare_config_and_inputs_for_common()

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

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

															check_hidden_states_output(__snake_case   , __snake_case   , __snake_case  )






							def UpperCAmelCase_     (   self  ):
											_SCREAMING_SNAKE_CASE			:	List[str]							=				self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_image_classification(*__snake_case  )






							def UpperCAmelCase_     (   self  ):
											_SCREAMING_SNAKE_CASE			:	Optional[Any]							=				self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_semantic_segmentation(*__snake_case  )






							@unittest.skipIf(
							    not is_tf_available() or len(tf.config.list_physical_devices("""GPU"""  )  ) == 0   , reason="""TF does not support backprop for grouped convolutions on CPU."""   , )
							def UpperCAmelCase_     (   self  ):
											super().test_dataset_conversion()






							def UpperCAmelCase_     (   self   , __snake_case   , __snake_case   , __snake_case=2e-1   , __snake_case=2e-1  ):
											self.assertTrue(np.allclose(__snake_case   , __snake_case   , atol=__snake_case   , rtol=__snake_case  )  )






							@unittest.skipIf(
							    not is_tf_available() or len(tf.config.list_physical_devices("""GPU"""  )  ) == 0   , reason="""TF does not support backprop for grouped convolutions on CPU."""   , )
							@slow
							def UpperCAmelCase_     (   self  ):
											_SCREAMING_SNAKE_CASE		,	_SCREAMING_SNAKE_CASE			:	Optional[int]							=				self.model_tester.prepare_config_and_inputs_for_common()

											for model_class in self.all_model_classes:
															# Since `TFMobileViTModel` cannot operate with the default `fit()` method.
															if model_class.__name__ != "TFMobileViTModel":
																			_SCREAMING_SNAKE_CASE			:	Optional[Any]							=				model_class(__snake_case  )
																			if getattr(__snake_case   , """hf_compute_loss"""   , __snake_case  ):
																							super().test_keras_fit()






							def UpperCAmelCase_     (   self  ):
											_SCREAMING_SNAKE_CASE		,	_SCREAMING_SNAKE_CASE			:	Dict							=				self.model_tester.prepare_config_and_inputs_for_common()
											for model_class in self.all_model_classes:
															# set an ignore index to correctly test the masked loss used in
															# `TFMobileViTForSemanticSegmentation`.
															if model_class.__name__ != "TFMobileViTForSemanticSegmentation":
																			_SCREAMING_SNAKE_CASE			:	int							=				5

															_SCREAMING_SNAKE_CASE			:	Dict							=				model_class(__snake_case  )
															if getattr(__snake_case   , """hf_compute_loss"""   , __snake_case  ):
																			# The number of elements in the loss should be the same as the number of elements in the label
																			_SCREAMING_SNAKE_CASE			:	Optional[int]							=				self._prepare_for_class(inputs_dict.copy()   , __snake_case   , return_labels=__snake_case  )
																			_SCREAMING_SNAKE_CASE			:	Union[str, Any]							=				prepared_for_class[
																			    sorted(prepared_for_class.keys() - inputs_dict.keys()   , reverse=__snake_case  )[0]
																			]
																			_SCREAMING_SNAKE_CASE			:	List[Any]							=				added_label.shape.as_list()[:1]

																			# Test that model correctly compute the loss with kwargs
																			_SCREAMING_SNAKE_CASE			:	int							=				self._prepare_for_class(inputs_dict.copy()   , __snake_case   , return_labels=__snake_case  )
																			_SCREAMING_SNAKE_CASE			:	Optional[Any]							=				{"""input_ids""", """pixel_values""", """input_features"""}
																			_SCREAMING_SNAKE_CASE			:	List[str]							=				possible_input_names.intersection(set(__snake_case  )  ).pop()
																			_SCREAMING_SNAKE_CASE			:	int							=				prepared_for_class.pop(__snake_case  )

																			_SCREAMING_SNAKE_CASE			:	List[Any]							=				model(__snake_case   , **__snake_case  )[0]
																			self.assertTrue(loss.shape.as_list() == expected_loss_size or loss.shape.as_list() == [1]  )

																			# Test that model correctly compute the loss when we mask some positions
																			_SCREAMING_SNAKE_CASE			:	List[Any]							=				self._prepare_for_class(inputs_dict.copy()   , __snake_case   , return_labels=__snake_case  )
																			_SCREAMING_SNAKE_CASE			:	Dict							=				{"""input_ids""", """pixel_values""", """input_features"""}
																			_SCREAMING_SNAKE_CASE			:	Tuple							=				possible_input_names.intersection(set(__snake_case  )  ).pop()
																			_SCREAMING_SNAKE_CASE			:	List[str]							=				prepared_for_class.pop(__snake_case  )
																			if "labels" in prepared_for_class:
																							_SCREAMING_SNAKE_CASE			:	int							=				prepared_for_class["""labels"""].numpy()
																							if len(labels.shape  ) > 1 and labels.shape[1] != 1:
																											# labels[0] = -100
																											_SCREAMING_SNAKE_CASE			:	int							=				tf.convert_to_tensor(__snake_case  )
																											_SCREAMING_SNAKE_CASE			:	Optional[int]							=				model(__snake_case   , **__snake_case  )[0]
																											self.assertTrue(loss.shape.as_list() == expected_loss_size or loss.shape.as_list() == [1]  )
																											self.assertTrue(not np.any(np.isnan(loss.numpy()  )  )  )

                # Test that model correctly compute the loss with a dict
																			_SCREAMING_SNAKE_CASE			:	int							=				self._prepare_for_class(inputs_dict.copy()   , __snake_case   , return_labels=__snake_case  )
																			_SCREAMING_SNAKE_CASE			:	List[Any]							=				model(__snake_case  )[0]
																			self.assertTrue(loss.shape.as_list() == expected_loss_size or loss.shape.as_list() == [1]  )

																			# Test that model correctly compute the loss with a tuple
																			_SCREAMING_SNAKE_CASE			:	Optional[int]							=				self._prepare_for_class(inputs_dict.copy()   , __snake_case   , return_labels=__snake_case  )

																			# Get keys that were added with the _prepare_for_class function
																			_SCREAMING_SNAKE_CASE			:	Union[str, Any]							=				prepared_for_class.keys() - inputs_dict.keys()
																			_SCREAMING_SNAKE_CASE			:	Any							=				inspect.signature(model.call  ).parameters
																			_SCREAMING_SNAKE_CASE			:	Dict							=				list(signature.keys()  )

																			# Create a dictionary holding the location of the tensors in the tuple
																			_SCREAMING_SNAKE_CASE			:	str							=				{0: input_name}
																			for label_key in label_keys:
																							_SCREAMING_SNAKE_CASE			:	Optional[Any]							=				signature_names.index(__snake_case  )
																							_SCREAMING_SNAKE_CASE			:	int							=				label_key
																			_SCREAMING_SNAKE_CASE			:	List[str]							=				sorted(tuple_index_mapping.items()  )
																			# Initialize a list with their default values, update the values and convert to a tuple
																			_SCREAMING_SNAKE_CASE			:	List[str]							=				[]

																			for name in signature_names:
																							if name != "kwargs":
																											list_input.append(signature[name].default  )

																			for index, value in sorted_tuple_index_mapping:
																							_SCREAMING_SNAKE_CASE			:	List[str]							=				prepared_for_class[value]

																			_SCREAMING_SNAKE_CASE			:	Optional[int]							=				tuple(__snake_case  )

																			# Send to model
																			_SCREAMING_SNAKE_CASE			:	List[Any]							=				model(tuple_input[:-1]  )[0]

																			self.assertTrue(loss.shape.as_list() == expected_loss_size or loss.shape.as_list() == [1]  )






							@slow
							def UpperCAmelCase_     (   self  ):
											for model_name in TF_MOBILEVIT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
															_SCREAMING_SNAKE_CASE			:	List[Any]							=				TFMobileViTModel.from_pretrained(__snake_case  )
															self.assertIsNotNone(__snake_case  )







def       snake_case_       (  ):







				"""simple docstring"""





				_SCREAMING_SNAKE_CASE			:	Tuple							=				Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""					)
				return image







@require_tf
class    lowercase__  (						unittest.TestCase ):





							'''simple docstring'''


							@slow
							def UpperCAmelCase_     (   self  ):
											_SCREAMING_SNAKE_CASE			:	Dict							=				TFMobileViTForImageClassification.from_pretrained("""apple/mobilevit-xx-small"""  )

											_SCREAMING_SNAKE_CASE			:	List[Any]							=				MobileViTImageProcessor.from_pretrained("""apple/mobilevit-xx-small"""  )
											_SCREAMING_SNAKE_CASE			:	Optional[Any]							=				prepare_img()
											_SCREAMING_SNAKE_CASE			:	Optional[int]							=				image_processor(images=__snake_case   , return_tensors="""tf"""  )

											# forward pass
											_SCREAMING_SNAKE_CASE			:	Optional[int]							=				model(**__snake_case   , training=__snake_case  )

											# verify the logits
											_SCREAMING_SNAKE_CASE			:	int							=				tf.TensorShape((1, 1000)  )
											self.assertEqual(outputs.logits.shape   , __snake_case  )

											_SCREAMING_SNAKE_CASE			:	Optional[int]							=				tf.constant([-1.9364, -1.2327, -0.4653]  )

											tf.debugging.assert_near(outputs.logits[0, :3]   , __snake_case   , atol=1e-4   , rtol=1e-04  )






							@slow
							def UpperCAmelCase_     (   self  ):
											# `from_pt` will be removed
											_SCREAMING_SNAKE_CASE			:	Tuple							=				TFMobileViTForSemanticSegmentation.from_pretrained("""apple/deeplabv3-mobilevit-xx-small"""  )

											_SCREAMING_SNAKE_CASE			:	int							=				MobileViTImageProcessor.from_pretrained("""apple/deeplabv3-mobilevit-xx-small"""  )

											_SCREAMING_SNAKE_CASE			:	Dict							=				prepare_img()
											_SCREAMING_SNAKE_CASE			:	Optional[int]							=				image_processor(images=__snake_case   , return_tensors="""tf"""  )

											# forward pass
											_SCREAMING_SNAKE_CASE			:	Any							=				model(inputs.pixel_values   , training=__snake_case  )
											_SCREAMING_SNAKE_CASE			:	List[Any]							=				outputs.logits

											# verify the logits
											_SCREAMING_SNAKE_CASE			:	List[Any]							=				tf.TensorShape((1, 21, 32, 32)  )
											self.assertEqual(logits.shape   , __snake_case  )

											_SCREAMING_SNAKE_CASE			:	List[Any]							=				tf.constant(
											    [
											        [[6.9713, 6.9786, 7.2422], [7.2893, 7.2825, 7.4446], [7.6580, 7.8797, 7.9420]],
											        [[-10.6869, -10.3250, -10.3471], [-10.4228, -9.9868, -9.7132], [-11.0405, -11.0221, -10.7318]],
											        [[-3.3089, -2.8539, -2.6740], [-3.2706, -2.5621, -2.5108], [-3.2534, -2.6615, -2.6651]],
											    ]  )

											tf.debugging.assert_near(logits[0, :3, :3, :3]   , __snake_case   , rtol=1e-4   , atol=1e-4  )




