




'''simple docstring'''




import collections
import importlib.util
import os
import re
from pathlib import Path


lowercase__  							=					'''src/transformers'''


# Matches is_xxx_available()
lowercase__  							=					re.compile(R'''is\_([a-z_]*)_available()''')
# Catches a one-line _import_struct = {xxx}
lowercase__  							=					re.compile(R'''^_import_structure\s+=\s+\{([^\}]+)\}''')
# Catches a line with a key-values pattern: "bla": ["foo", "bar"]
lowercase__  							=					re.compile(R'''\s+"\S*":\s+\[([^\]]*)\]''')
# Catches a line if not is_foo_available
lowercase__  							=					re.compile(R'''^\s*if\s+not\s+is\_[a-z_]*\_available\(\)''')
# Catches a line _import_struct["bla"].append("foo")
lowercase__  							=					re.compile(R'''^\s*_import_structure\["\S*"\]\.append\("(\S*)"\)''')
# Catches a line _import_struct["bla"].extend(["foo", "bar"]) or _import_struct["bla"] = ["foo", "bar"]
lowercase__  							=					re.compile(R'''^\s*_import_structure\[\S*\](?:\.extend\(|\s*=\s+)\[([^\]]*)\]''')
# Catches a line with an object between quotes and a comma:     "MyModel",
lowercase__  							=					re.compile('''^\s+"([^"]+)",''')
# Catches a line with objects between brackets only:    ["foo", "bar"],
lowercase__  							=					re.compile('''^\s+\[([^\]]+)\]''')
# Catches a line with from foo import bar, bla, boo
lowercase__  							=					re.compile(R'''\s+from\s+\S*\s+import\s+([^\(\s].*)\n''')
# Catches a line with try:
lowercase__  							=					re.compile(R'''^\s*try:''')
# Catches a line with else:
lowercase__  							=					re.compile(R'''^\s*else:''')
def      __snake_case       (   lowercase   :							int  ):




					if _re_test_backend.search(_SCREAMING_SNAKE_CASE  ) is None:
										return None
					snake_case_	=      [b[0] for b in _re_backend.findall(_SCREAMING_SNAKE_CASE  )]
					backends.sort()
					return "_and_".join(_SCREAMING_SNAKE_CASE  )
def      __snake_case       (   lowercase   :							Union[str, Any]  ):




					with open(_SCREAMING_SNAKE_CASE			, "r"			, encoding="utf-8"			, newline="\n"  ) as f:
										snake_case_	=      f.readlines()

					snake_case_	=      0
					while line_index < len(_SCREAMING_SNAKE_CASE  ) and not lines[line_index].startswith("_import_structure = {"  ):
										line_index += 1

					# If this is a traditional init, just return.
					if line_index >= len(_SCREAMING_SNAKE_CASE  ):
										return None

					# First grab the objects without a specific backend in _import_structure
					snake_case_	=      []
					while not lines[line_index].startswith("if TYPE_CHECKING"  ) and find_backend(lines[line_index]  ) is None:
										snake_case_	=      lines[line_index]
										# If we have everything on a single line, let's deal with it.
										if _re_one_line_import_struct.search(_SCREAMING_SNAKE_CASE  ):
															snake_case_	=      _re_one_line_import_struct.search(_SCREAMING_SNAKE_CASE  ).groups()[0]
															snake_case_	=      re.findall("\[([^\]]+)\]"			, _SCREAMING_SNAKE_CASE  )
															for imp in imports:
																				objects.extend([obj[1:-1] for obj in imp.split(", "  )]  )
															line_index += 1
															continue
										snake_case_	=      _re_import_struct_key_value.search(_SCREAMING_SNAKE_CASE  )
										if single_line_import_search is not None:
															snake_case_	=      [obj[1:-1] for obj in single_line_import_search.groups()[0].split(", "  ) if len(_SCREAMING_SNAKE_CASE  ) > 0]
															objects.extend(_SCREAMING_SNAKE_CASE  )
										elif line.startswith(" " * 8 + "\""  ):
															objects.append(line[9:-3]  )
										line_index += 1

					snake_case_	=      {"none": objects}
					# Let's continue with backend-specific objects in _import_structure
					while not lines[line_index].startswith("if TYPE_CHECKING"  ):
										# If the line is an if not is_backend_available, we grab all objects associated.
										snake_case_	=      find_backend(lines[line_index]  )
										# Check if the backend declaration is inside a try block:
										if _re_try.search(lines[line_index - 1]  ) is None:
															snake_case_	=      None

										if backend is not None:
															line_index += 1

															# Scroll until we hit the else block of try-except-else
															while _re_else.search(lines[line_index]  ) is None:
																				line_index += 1

															line_index += 1

															snake_case_	=      []
															# Until we unindent, add backend objects to the list
															while len(lines[line_index]  ) <= 1 or lines[line_index].startswith(" " * 4  ):
																				snake_case_	=      lines[line_index]
																				if _re_import_struct_add_one.search(_SCREAMING_SNAKE_CASE  ) is not None:
																									objects.append(_re_import_struct_add_one.search(_SCREAMING_SNAKE_CASE  ).groups()[0]  )
																				elif _re_import_struct_add_many.search(_SCREAMING_SNAKE_CASE  ) is not None:
																									snake_case_	=      _re_import_struct_add_many.search(_SCREAMING_SNAKE_CASE  ).groups()[0].split(", "  )
																									snake_case_	=      [obj[1:-1] for obj in imports if len(_SCREAMING_SNAKE_CASE  ) > 0]
																									objects.extend(_SCREAMING_SNAKE_CASE  )
																				elif _re_between_brackets.search(_SCREAMING_SNAKE_CASE  ) is not None:
																									snake_case_	=      _re_between_brackets.search(_SCREAMING_SNAKE_CASE  ).groups()[0].split(", "  )
																									snake_case_	=      [obj[1:-1] for obj in imports if len(_SCREAMING_SNAKE_CASE  ) > 0]
																									objects.extend(_SCREAMING_SNAKE_CASE  )
																				elif _re_quote_object.search(_SCREAMING_SNAKE_CASE  ) is not None:
																									objects.append(_re_quote_object.search(_SCREAMING_SNAKE_CASE  ).groups()[0]  )
																				elif line.startswith(" " * 8 + "\""  ):
																									objects.append(line[9:-3]  )
																				elif line.startswith(" " * 12 + "\""  ):
																									objects.append(line[13:-3]  )
																				line_index += 1

															snake_case_	=      objects
										else:
															line_index += 1

    # At this stage we are in the TYPE_CHECKING part, first grab the objects without a specific backend
					snake_case_	=      []
					while (
					    line_index < len(_SCREAMING_SNAKE_CASE  )
					    and find_backend(lines[line_index]  ) is None
					    and not lines[line_index].startswith("else"  )
					):
										snake_case_	=      lines[line_index]
										snake_case_	=      _re_import.search(_SCREAMING_SNAKE_CASE  )
										if single_line_import_search is not None:
															objects.extend(single_line_import_search.groups()[0].split(", "  )  )
										elif line.startswith(" " * 8  ):
															objects.append(line[8:-2]  )
										line_index += 1

					snake_case_	=      {"none": objects}
					# Let's continue with backend-specific objects
					while line_index < len(_SCREAMING_SNAKE_CASE  ):
										# If the line is an if is_backend_available, we grab all objects associated.
										snake_case_	=      find_backend(lines[line_index]  )
										# Check if the backend declaration is inside a try block:
										if _re_try.search(lines[line_index - 1]  ) is None:
															snake_case_	=      None

										if backend is not None:
															line_index += 1

															# Scroll until we hit the else block of try-except-else
															while _re_else.search(lines[line_index]  ) is None:
																				line_index += 1

															line_index += 1

															snake_case_	=      []
															# Until we unindent, add backend objects to the list
															while len(lines[line_index]  ) <= 1 or lines[line_index].startswith(" " * 8  ):
																				snake_case_	=      lines[line_index]
																				snake_case_	=      _re_import.search(_SCREAMING_SNAKE_CASE  )
																				if single_line_import_search is not None:
																									objects.extend(single_line_import_search.groups()[0].split(", "  )  )
																				elif line.startswith(" " * 12  ):
																									objects.append(line[12:-2]  )
																				line_index += 1

															snake_case_	=      objects
										else:
															line_index += 1

					return import_dict_objects, type_hint_objects
def      __snake_case       (   lowercase   :							Optional[Any]			, lowercase   :							Dict  ):




					def find_duplicates(lowercase   :							str  ):
										return [k for k, v in collections.Counter(_SCREAMING_SNAKE_CASE  ).items() if v > 1]

					if list(import_dict_objects.keys()  ) != list(type_hint_objects.keys()  ):
										return ["Both sides of the init do not have the same backends!"]

					snake_case_	=      []
					for key in import_dict_objects.keys():
										snake_case_	=      find_duplicates(import_dict_objects[key]  )
										if duplicate_imports:
															errors.append(f'''Duplicate _import_structure definitions for: {duplicate_imports}'''  )
										snake_case_	=      find_duplicates(type_hint_objects[key]  )
										if duplicate_type_hints:
															errors.append(f'''Duplicate TYPE_CHECKING objects for: {duplicate_type_hints}'''  )

										if sorted(set(import_dict_objects[key]  )  ) != sorted(set(type_hint_objects[key]  )  ):
															snake_case_	=      "base imports" if key == "none" else f'''{key} backend'''
															errors.append(f'''Differences for {name}:'''  )
															for a in type_hint_objects[key]:
																				if a not in import_dict_objects[key]:
																									errors.append(f'''  {a} in TYPE_HINT but not in _import_structure.'''  )
															for a in import_dict_objects[key]:
																				if a not in type_hint_objects[key]:
																									errors.append(f'''  {a} in _import_structure but not in TYPE_HINT.'''  )
					return errors
def      __snake_case       (   ):
					snake_case_	=      []
					for root, _, files in os.walk(_SCREAMING_SNAKE_CASE  ):
										if "__init__.py" in files:
															snake_case_	=      os.path.join(_SCREAMING_SNAKE_CASE			, "__init__.py"  )
															snake_case_	=      parse_init(_SCREAMING_SNAKE_CASE  )
															if objects is not None:
																				snake_case_	=      analyze_results(*_SCREAMING_SNAKE_CASE  )
																				if len(_SCREAMING_SNAKE_CASE  ) > 0:
																									snake_case_	=      f'''Problem in {fname}, both halves do not define the same objects.\n{errors[0]}'''
																									failures.append("\n".join(_SCREAMING_SNAKE_CASE  )  )
					if len(_SCREAMING_SNAKE_CASE  ) > 0:
										raise ValueError("\n\n".join(_SCREAMING_SNAKE_CASE  )  )
def      __snake_case       (   ):
					snake_case_	=      []
					for path, directories, files in os.walk(_SCREAMING_SNAKE_CASE  ):
										for folder in directories:
															# Ignore private modules
															if folder.startswith("_"  ):
																				directories.remove(_SCREAMING_SNAKE_CASE  )
																				continue
															# Ignore leftovers from branches (empty folders apart from pycache)
															if len(list((Path(_SCREAMING_SNAKE_CASE  ) / folder).glob("*.py"  )  )  ) == 0:
																				continue
															snake_case_	=      str((Path(_SCREAMING_SNAKE_CASE  ) / folder).relative_to(_SCREAMING_SNAKE_CASE  )  )
															snake_case_	=      short_path.replace(os.path.sep			, "."  )
															submodules.append(_SCREAMING_SNAKE_CASE  )
										for fname in files:
															if fname == "__init__.py":
																				continue
															snake_case_	=      str((Path(_SCREAMING_SNAKE_CASE  ) / fname).relative_to(_SCREAMING_SNAKE_CASE  )  )
															snake_case_	=      short_path.replace(".py"			, ""  ).replace(os.path.sep			, "."  )
															if len(submodule.split("."  )  ) == 1:
																				submodules.append(_SCREAMING_SNAKE_CASE  )
					return submodules


lowercase__  							=					[
    '''convert_pytorch_checkpoint_to_tf2''',
    '''modeling_flax_pytorch_utils''',
]
def      __snake_case       (   ):
					snake_case_	=      importlib.util.spec_from_file_location(
					    "transformers"			, os.path.join(_SCREAMING_SNAKE_CASE			, "__init__.py"  )			, submodule_search_locations=[PATH_TO_TRANSFORMERS]			, )
					snake_case_	=      spec.loader.load_module()

					snake_case_	=      [
					    module
					    for module in get_transformers_submodules()
					    if module not in IGNORE_SUBMODULES and module not in transformers._import_structure.keys()
					]
					if len(_SCREAMING_SNAKE_CASE  ) > 0:
										snake_case_	=      "\n".join(f'''- {module}''' for module in module_not_registered  )
										raise ValueError(
										    "The following submodules are not properly registered in the main init of Transformers:\n"
										    f'''{list_of_modules}\n'''
										    "Make sure they appear somewhere in the keys of `_import_structure` with an empty list as value."  )


if __name__ == "__main__":
					check_all_inits()
					check_submodules()









'''simple docstring'''





import inspect
import unittest

from transformers import MobileViTConfig
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 MobileViTForImageClassification, MobileViTForSemanticSegmentation, MobileViTModel
					from transformers.models.mobilevit.modeling_mobilevit import MOBILEVIT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
					from PIL import Image

					from transformers import MobileViTImageProcessor
class 						a__					(					a_   ):





			'''simple docstring'''

			def 					lowerCAmelCase     (  self							:			Tuple	)      ->		Optional[int]:
						__A=	self.config_class(**self.inputs_dict	)
						self.parent.assertTrue(hasattr(lowerCAmelCase_			,    'hidden_sizes'	)	)
						self.parent.assertTrue(hasattr(lowerCAmelCase_			,    'neck_hidden_sizes'	)	)
						self.parent.assertTrue(hasattr(lowerCAmelCase_			,    'num_attention_heads'	)	)


class 						a__					:





			'''simple docstring'''

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

						__A=	None
						__A=	None
						if self.use_labels:
									__A=	ids_tensor([self.batch_size]			,    self.num_labels	)
									__A=	ids_tensor([self.batch_size, self.image_size, self.image_size]			,    self.num_labels	)

						__A=	self.get_config()

						return config, pixel_values, labels, pixel_labels
			def 					lowerCAmelCase     (  self							:			List[Any]	)      ->		List[Any]:
						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 					lowerCAmelCase     (  self							:			Any			,    lowerCAmelCase_							:			List[Any]			,    lowerCAmelCase_							:			Any			,    lowerCAmelCase_							:			Tuple			,    lowerCAmelCase_							:			Optional[Any]	)      ->		Dict:
						__A=	MobileViTModel(config=lowerCAmelCase_	)
						model.to(lowerCAmelCase_	)
						model.eval()
						__A=	model(lowerCAmelCase_	)
						self.parent.assertEqual(
						    result.last_hidden_state.shape			,    (
						        self.batch_size,
						        self.last_hidden_size,
						        self.image_size // self.output_stride,
						        self.image_size // self.output_stride,
						    )			,    )
			def 					lowerCAmelCase     (  self							:			List[str]			,    lowerCAmelCase_							:			List[str]			,    lowerCAmelCase_							:			Optional[int]			,    lowerCAmelCase_							:			List[Any]			,    lowerCAmelCase_							:			Any	)      ->		Optional[Any]:
						__A=	self.num_labels
						__A=	MobileViTForImageClassification(lowerCAmelCase_	)
						model.to(lowerCAmelCase_	)
						model.eval()
						__A=	model(lowerCAmelCase_			,    labels=lowerCAmelCase_	)
						self.parent.assertEqual(result.logits.shape			,    (self.batch_size, self.num_labels)	)
			def 					lowerCAmelCase     (  self							:			Optional[int]			,    lowerCAmelCase_							:			Optional[Any]			,    lowerCAmelCase_							:			Optional[Any]			,    lowerCAmelCase_							:			Optional[int]			,    lowerCAmelCase_							:			int	)      ->		int:
						__A=	self.num_labels
						__A=	MobileViTForSemanticSegmentation(lowerCAmelCase_	)
						model.to(lowerCAmelCase_	)
						model.eval()
						__A=	model(lowerCAmelCase_	)
						self.parent.assertEqual(
						    result.logits.shape			,    (
						        self.batch_size,
						        self.num_labels,
						        self.image_size // self.output_stride,
						        self.image_size // self.output_stride,
						    )			,    )
						__A=	model(lowerCAmelCase_			,    labels=lowerCAmelCase_	)
						self.parent.assertEqual(
						    result.logits.shape			,    (
						        self.batch_size,
						        self.num_labels,
						        self.image_size // self.output_stride,
						        self.image_size // self.output_stride,
						    )			,    )

			def 					lowerCAmelCase     (  self							:			Optional[int]	)      ->		Optional[int]:
						__A=	self.prepare_config_and_inputs()
						__A,	__A,	__A,	__A=	config_and_inputs
						__A=	{'pixel_values': pixel_values}
						return config, inputs_dict


@require_torch
class 						a__					(					a_      ,  a_      ,  unittest.TestCase   ):





			'''simple docstring'''

			A						:				Union[str, Any]					      =			(
			    (MobileViTModel, MobileViTForImageClassification, MobileViTForSemanticSegmentation)
			    if is_torch_available()
			    else ()
			)
			A						:				Any					      =			(
			    {
			        '''feature-extraction''': MobileViTModel,
			        '''image-classification''': MobileViTForImageClassification,
			        '''image-segmentation''': MobileViTForSemanticSegmentation,
			    }
			    if is_torch_available()
			    else {}
			)

			A						:				int					      =			False
			A						:				Dict					      =			False
			A						:				Dict					      =			False
			A						:				str					      =			False
			def 					lowerCAmelCase     (  self							:			Union[str, Any]	)      ->		Union[str, Any]:
						__A=	MobileViTModelTester(self	)
						__A=	MobileViTConfigTester(self			,    config_class=lowerCAmelCase_			,    has_text_modality=lowerCAmelCase_	)
			def 					lowerCAmelCase     (  self							:			Any	)      ->		str:
						self.config_tester.run_common_tests()
			@unittest.skip(reason='MobileViT does not use inputs_embeds'	)
			def 					lowerCAmelCase     (  self							:			int	)      ->		Any:
						pass
			@unittest.skip(reason='MobileViT does not support input and output embeddings'	)
			def 					lowerCAmelCase     (  self							:			List[str]	)      ->		List[Any]:
						pass
			@unittest.skip(reason='MobileViT does not output attentions'	)
			def 					lowerCAmelCase     (  self							:			List[str]	)      ->		Optional[int]:
						pass
			def 					lowerCAmelCase     (  self							:			Optional[int]	)      ->		Optional[Any]:
						__A,	__A=	self.model_tester.prepare_config_and_inputs_for_common()

						for model_class in self.all_model_classes:
									__A=	model_class(lowerCAmelCase_	)
									__A=	inspect.signature(model.forward	)
									# signature.parameters is an OrderedDict => so arg_names order is deterministic
									__A=	[*signature.parameters.keys()]

									__A=	['pixel_values']
									self.assertListEqual(arg_names[:1]			,    lowerCAmelCase_	)
			@unittest.skip('Will be fixed soon by reducing the size of the model used for common tests.'	)
			def 					lowerCAmelCase     (  self							:			str	)      ->		int:
						pass
			def 					lowerCAmelCase     (  self							:			str	)      ->		Any:
						__A=	self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_model(*lowerCAmelCase_	)
			def 					lowerCAmelCase     (  self							:			Optional[Any]	)      ->		str:
						def check_hidden_states_output(lowerCAmelCase_							:			Optional[int]			,    lowerCAmelCase_							:			int			,    lowerCAmelCase_							:			List[str]	):
									__A=	model_class(lowerCAmelCase_	)
									model.to(lowerCAmelCase_	)
									model.eval()

									with torch.no_grad():
												__A=	model(**self._prepare_for_class(lowerCAmelCase_			,    lowerCAmelCase_	)	)

									__A=	outputs.hidden_states

									__A=	5
									self.assertEqual(len(lowerCAmelCase_	)			,    lowerCAmelCase_	)

									# MobileViT's feature maps are of shape (batch_size, num_channels, height, width)
									# with the width and height being successively divided by 2.
									__A=	2
									for i in range(len(lowerCAmelCase_	)	):
												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	)

						__A,	__A=	self.model_tester.prepare_config_and_inputs_for_common()

						for model_class in self.all_model_classes:
									__A=	True
									check_hidden_states_output(lowerCAmelCase_			,    lowerCAmelCase_			,    lowerCAmelCase_	)

									# check that output_hidden_states also work using config
									del inputs_dict["output_hidden_states"]
									__A=	True

									check_hidden_states_output(lowerCAmelCase_			,    lowerCAmelCase_			,    lowerCAmelCase_	)
			def 					lowerCAmelCase     (  self							:			Tuple	)      ->		Optional[Any]:
						__A=	self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_image_classification(*lowerCAmelCase_	)
			def 					lowerCAmelCase     (  self							:			Union[str, Any]	)      ->		Union[str, Any]:
						__A=	self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_semantic_segmentation(*lowerCAmelCase_	)

			@slow
			def 					lowerCAmelCase     (  self							:			Union[str, Any]	)      ->		Optional[Any]:
						for model_name in MOBILEVIT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
									__A=	MobileViTModel.from_pretrained(lowerCAmelCase_	)
									self.assertIsNotNone(lowerCAmelCase_	)






def 						UpperCAmelCase__(				):






			"""simple docstring"""




			__A=	Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png' )
			return image






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





			'''simple docstring'''

			@cached_property
			def 					lowerCAmelCase     (  self							:			Optional[Any]	)      ->		Tuple:
						return MobileViTImageProcessor.from_pretrained('apple/mobilevit-xx-small'	) if is_vision_available() else None
			@slow
			def 					lowerCAmelCase     (  self							:			int	)      ->		str:
						__A=	MobileViTForImageClassification.from_pretrained('apple/mobilevit-xx-small'	).to(lowerCAmelCase_	)

						__A=	self.default_image_processor
						__A=	prepare_img()
						__A=	image_processor(images=lowerCAmelCase_			,    return_tensors='pt'	).to(lowerCAmelCase_	)

						# forward pass
						with torch.no_grad():
									__A=	model(**lowerCAmelCase_	)

						# verify the logits
						__A=	torch.Size((1, 1_000)	)
						self.assertEqual(outputs.logits.shape			,    lowerCAmelCase_	)

						__A=	torch.tensor([-1.93_64, -1.23_27, -0.46_53]	).to(lowerCAmelCase_	)

						self.assertTrue(torch.allclose(outputs.logits[0, :3]			,    lowerCAmelCase_			,    atol=1E-4	)	)
			@slow
			def 					lowerCAmelCase     (  self							:			Union[str, Any]	)      ->		List[str]:
						__A=	MobileViTForSemanticSegmentation.from_pretrained('apple/deeplabv3-mobilevit-xx-small'	)
						__A=	model.to(lowerCAmelCase_	)

						__A=	MobileViTImageProcessor.from_pretrained('apple/deeplabv3-mobilevit-xx-small'	)

						__A=	prepare_img()
						__A=	image_processor(images=lowerCAmelCase_			,    return_tensors='pt'	).to(lowerCAmelCase_	)

						# forward pass
						with torch.no_grad():
									__A=	model(**lowerCAmelCase_	)
						__A=	outputs.logits

						# verify the logits
						__A=	torch.Size((1, 21, 32, 32)	)
						self.assertEqual(logits.shape			,    lowerCAmelCase_	)

						__A=	torch.tensor(
						    [
						        [[6.97_13, 6.97_86, 7.24_22], [7.28_93, 7.28_25, 7.44_46], [7.65_80, 7.87_97, 7.94_20]],
						        [[-10.68_69, -10.32_50, -10.34_71], [-10.42_28, -9.98_68, -9.71_32], [-11.04_05, -11.02_21, -10.73_18]],
						        [[-3.30_89, -2.85_39, -2.67_40], [-3.27_06, -2.56_21, -2.51_08], [-3.25_34, -2.66_15, -2.66_51]],
						    ]			,    device=lowerCAmelCase_			,    )

						self.assertTrue(torch.allclose(logits[0, :3, :3, :3]			,    lowerCAmelCase_			,    atol=1E-4	)	)

			@slow
			def 					lowerCAmelCase     (  self							:			Tuple	)      ->		str:
						__A=	MobileViTForSemanticSegmentation.from_pretrained('apple/deeplabv3-mobilevit-xx-small'	)
						__A=	model.to(lowerCAmelCase_	)

						__A=	MobileViTImageProcessor.from_pretrained('apple/deeplabv3-mobilevit-xx-small'	)

						__A=	prepare_img()
						__A=	image_processor(images=lowerCAmelCase_			,    return_tensors='pt'	).to(lowerCAmelCase_	)

						# forward pass
						with torch.no_grad():
									__A=	model(**lowerCAmelCase_	)

						__A=	outputs.logits.detach().cpu()

						__A=	image_processor.post_process_semantic_segmentation(outputs=lowerCAmelCase_			,    target_sizes=[(50, 60)]	)
						__A=	torch.Size((50, 60)	)
						self.assertEqual(segmentation[0].shape			,    lowerCAmelCase_	)

						__A=	image_processor.post_process_semantic_segmentation(outputs=lowerCAmelCase_	)
						__A=	torch.Size((32, 32)	)
						self.assertEqual(segmentation[0].shape			,    lowerCAmelCase_	)



