


from __future__ import annotations

import unittest

from transformers import BlenderbotConfig, BlenderbotTokenizer, is_tf_available
from transformers.testing_utils import require_tf, require_tokenizers, slow
from transformers.utils import cached_property

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


if is_tf_available():
				import tensorflow as tf

				from transformers import TFAutoModelForSeqaSeqLM, TFBlenderbotForConditionalGeneration, TFBlenderbotModel







@require_tf
class 	__lowercase    :





							"""simple docstring"""







							_UpperCAmelCase      =						BlenderbotConfig
							_UpperCAmelCase      =						{}
							_UpperCAmelCase      =						"""gelu"""






							def __init__(      self			,						lowerCAmelCase__			,						lowerCAmelCase__=1_3			,						lowerCAmelCase__=7			,						lowerCAmelCase__=True			,						lowerCAmelCase__=False			,						lowerCAmelCase__=9_9			,						lowerCAmelCase__=3_2			,						lowerCAmelCase__=2			,						lowerCAmelCase__=4			,						lowerCAmelCase__=3_7			,						lowerCAmelCase__=0.1			,						lowerCAmelCase__=0.1			,						lowerCAmelCase__=2_0			,						lowerCAmelCase__=2			,						lowerCAmelCase__=1			,						lowerCAmelCase__=0			,						):





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_		:     int					=					parent
										SCREAMING_SNAKE_CASE_		:     Union[str, Any]					=					batch_size
										SCREAMING_SNAKE_CASE_		:     Dict					=					seq_length
										SCREAMING_SNAKE_CASE_		:     Union[str, Any]					=					is_training
										SCREAMING_SNAKE_CASE_		:     Dict					=					use_labels
										SCREAMING_SNAKE_CASE_		:     Any					=					vocab_size
										SCREAMING_SNAKE_CASE_		:     int					=					hidden_size
										SCREAMING_SNAKE_CASE_		:     Dict					=					num_hidden_layers
										SCREAMING_SNAKE_CASE_		:     Optional[int]					=					num_attention_heads
										SCREAMING_SNAKE_CASE_		:     Any					=					intermediate_size

										SCREAMING_SNAKE_CASE_		:     List[Any]					=					hidden_dropout_prob
										SCREAMING_SNAKE_CASE_		:     List[str]					=					attention_probs_dropout_prob
										SCREAMING_SNAKE_CASE_		:     Dict					=					max_position_embeddings
										SCREAMING_SNAKE_CASE_		:     Optional[Any]					=					eos_token_id
										SCREAMING_SNAKE_CASE_		:     str					=					pad_token_id
										SCREAMING_SNAKE_CASE_		:     List[Any]					=					bos_token_id






							def 					UpperCamelCase__     (      self       ):





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_		:     List[Any]					=					ids_tensor([self.batch_size, self.seq_length - 1]			,						self.vocab_size       )
										SCREAMING_SNAKE_CASE_		:     List[Any]					=					tf.expand_dims(tf.constant([self.eos_token_id] * self.batch_size       )			,						1       )
										SCREAMING_SNAKE_CASE_		:     Optional[Any]					=					tf.concat([input_ids, eos_tensor]			,						axis=1       )

										SCREAMING_SNAKE_CASE_		:     Union[str, Any]					=					ids_tensor([self.batch_size, self.seq_length]			,						self.vocab_size       )

										SCREAMING_SNAKE_CASE_		:     Any					=					self.config_cls(
										    vocab_size=self.vocab_size			,						d_model=self.hidden_size			,						encoder_layers=self.num_hidden_layers			,						decoder_layers=self.num_hidden_layers			,						encoder_attention_heads=self.num_attention_heads			,						decoder_attention_heads=self.num_attention_heads			,						encoder_ffn_dim=self.intermediate_size			,						decoder_ffn_dim=self.intermediate_size			,						dropout=self.hidden_dropout_prob			,						attention_dropout=self.attention_probs_dropout_prob			,						max_position_embeddings=self.max_position_embeddings			,						eos_token_ids=[2]			,						bos_token_id=self.bos_token_id			,						pad_token_id=self.pad_token_id			,						decoder_start_token_id=self.pad_token_id			,						**self.config_updates			,						)
										SCREAMING_SNAKE_CASE_		:     Dict					=					prepare_blenderbot_inputs_dict(lowerCAmelCase__			,						lowerCAmelCase__			,						lowerCAmelCase__       )
										return config, inputs_dict






							def 					UpperCamelCase__     (      self			,						lowerCAmelCase__			,						lowerCAmelCase__       ):





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_		:     int					=					TFBlenderbotModel(config=lowerCAmelCase__       ).get_decoder()
										SCREAMING_SNAKE_CASE_		:     Optional[Any]					=					inputs_dict['input_ids']

										SCREAMING_SNAKE_CASE_		:     str					=					input_ids[:1, :]
										SCREAMING_SNAKE_CASE_		:     List[str]					=					inputs_dict['attention_mask'][:1, :]
										SCREAMING_SNAKE_CASE_		:     Optional[Any]					=					inputs_dict['head_mask']
										SCREAMING_SNAKE_CASE_		:     Dict					=					1

										# first forward pass
										SCREAMING_SNAKE_CASE_		:     Optional[int]					=					model(lowerCAmelCase__			,						attention_mask=lowerCAmelCase__			,						head_mask=lowerCAmelCase__			,						use_cache=lowerCAmelCase__       )

										SCREAMING_SNAKE_CASE_		,      SCREAMING_SNAKE_CASE_		:     List[str]					=					outputs.to_tuple()

										# create hypothetical next token and extent to next_input_ids
										SCREAMING_SNAKE_CASE_		:     Dict					=					ids_tensor((self.batch_size, 3)			,						config.vocab_size       )
										SCREAMING_SNAKE_CASE_		:     List[Any]					=					tf.cast(ids_tensor((self.batch_size, 3)			,						2       )			,						tf.inta       )

										# append to next input_ids and
										SCREAMING_SNAKE_CASE_		:     Union[str, Any]					=					tf.concat([input_ids, next_tokens]			,						axis=-1       )
										SCREAMING_SNAKE_CASE_		:     Any					=					tf.concat([attention_mask, next_attn_mask]			,						axis=-1       )

										SCREAMING_SNAKE_CASE_		:     str					=					model(lowerCAmelCase__			,						attention_mask=lowerCAmelCase__       )[0]
										SCREAMING_SNAKE_CASE_		:     Union[str, Any]					=					model(lowerCAmelCase__			,						attention_mask=lowerCAmelCase__			,						past_key_values=lowerCAmelCase__       )[0]

										self.parent.assertEqual(next_tokens.shape[1]			,						output_from_past.shape[1]       )

										# select random slice
										SCREAMING_SNAKE_CASE_		:     Tuple					=					int(ids_tensor((1,)			,						output_from_past.shape[-1]       )       )
										SCREAMING_SNAKE_CASE_		:     str					=					output_from_no_past[:, -3:, random_slice_idx]
										SCREAMING_SNAKE_CASE_		:     Tuple					=					output_from_past[:, :, random_slice_idx]

										# test that outputs are equal for slice
										tf.debugging.assert_near(lowerCAmelCase__			,						lowerCAmelCase__			,						rtol=1E-3       )







def 						a__			(				A__,      A__,      A__,      A__=None,      A__=None,      A__=None,      A__=None,      A__=None,      ):
			if attention_mask is None:
						SCREAMING_SNAKE_CASE_		:     Union[str, Any]					=					tf.cast(tf.math.not_equal(A__,      config.pad_token_id				),      tf.inta				)
			if decoder_attention_mask is None:
						SCREAMING_SNAKE_CASE_		:     Optional[int]					=					tf.concat(
						    [
						        tf.ones(decoder_input_ids[:, :1].shape,      dtype=tf.inta				),
						        tf.cast(tf.math.not_equal(decoder_input_ids[:, 1:],      config.pad_token_id				),      tf.inta				),
						    ],      axis=-1,      )
			if head_mask is None:
						SCREAMING_SNAKE_CASE_		:     Tuple					=					tf.ones((config.encoder_layers, config.encoder_attention_heads)				)
			if decoder_head_mask is None:
						SCREAMING_SNAKE_CASE_		:     Dict					=					tf.ones((config.decoder_layers, config.decoder_attention_heads)				)
			if cross_attn_head_mask is None:
						SCREAMING_SNAKE_CASE_		:     Optional[int]					=					tf.ones((config.decoder_layers, config.decoder_attention_heads)				)
			return {
			    "input_ids": input_ids,
			    "decoder_input_ids": decoder_input_ids,
			    "attention_mask": attention_mask,
			    "decoder_attention_mask": decoder_attention_mask,
			    "head_mask": head_mask,
			    "decoder_head_mask": decoder_head_mask,
			    "cross_attn_head_mask": cross_attn_head_mask,
			}







@require_tf
class 	__lowercase    (__SCREAMING_SNAKE_CASE	,       __SCREAMING_SNAKE_CASE	,       unittest.TestCase  ):





							"""simple docstring"""







							_UpperCAmelCase      =						(TFBlenderbotForConditionalGeneration, TFBlenderbotModel) if is_tf_available() else ()
							_UpperCAmelCase      =						(TFBlenderbotForConditionalGeneration,) if is_tf_available() else ()
							_UpperCAmelCase      =						(
							    {
							        """conversational""": TFBlenderbotForConditionalGeneration,
							        """feature-extraction""": TFBlenderbotModel,
							        """summarization""": TFBlenderbotForConditionalGeneration,
							        """text2text-generation""": TFBlenderbotForConditionalGeneration,
							        """translation""": TFBlenderbotForConditionalGeneration,
							    }
							    if is_tf_available()
							    else {}
							)
							_UpperCAmelCase      =						True
							_UpperCAmelCase      =						False
							_UpperCAmelCase      =						False






							def 					UpperCamelCase__     (      self       ):





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_		:     List[str]					=					TFBlenderbotModelTester(self       )
										SCREAMING_SNAKE_CASE_		:     Dict					=					ConfigTester(self			,						config_class=lowerCAmelCase__       )






							def 					UpperCamelCase__     (      self       ):





										"""simple docstring"""




										self.config_tester.run_common_tests()






							def 					UpperCamelCase__     (      self       ):





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_		:     List[Any]					=					self.model_tester.prepare_config_and_inputs_for_common()
										self.model_tester.check_decoder_model_past_large_inputs(*lowerCAmelCase__       )







@require_tokenizers
@require_tf
class 	__lowercase    (unittest.TestCase  ):





							"""simple docstring"""







							_UpperCAmelCase      =						["""My friends are cool but they eat too many carbs."""]
							_UpperCAmelCase      =						"""facebook/blenderbot-400M-distill"""






							@cached_property
							def 					UpperCamelCase__     (      self       ):





										"""simple docstring"""




										return BlenderbotTokenizer.from_pretrained(self.model_name       )






							@cached_property
							def 					UpperCamelCase__     (      self       ):





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_		:     Optional[int]					=					TFAutoModelForSeqaSeqLM.from_pretrained(self.model_name       )
										return model






							@slow
							def 					UpperCamelCase__     (      self       ):





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_		:     List[Any]					=					self.tokenizer(self.src_text			,						return_tensors='tf'       )
										SCREAMING_SNAKE_CASE_		:     Optional[int]					=					self.model.generate(
										    model_inputs.input_ids			,						)
										SCREAMING_SNAKE_CASE_		:     Optional[Any]					=					self.tokenizer.batch_decode(generated_ids.numpy()			,						skip_special_tokens=lowerCAmelCase__       )[0]
										assert (
										    generated_words
										    == " That's unfortunate. Are they trying to lose weight or are they just trying to be healthier?"
										)







"""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   SCREAMING_SNAKE_CASE						(     self       )			->							List[str]:




										'''simple docstring'''
										__lowercase       =       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  ,    _lowerCamelCase  ,    _lowerCamelCase=13  ,    _lowerCamelCase=32  ,    _lowerCamelCase=2  ,    _lowerCamelCase=3  ,    _lowerCamelCase=640  ,    _lowerCamelCase=4  ,    _lowerCamelCase="silu"  ,    _lowerCamelCase=3  ,    _lowerCamelCase=32  ,    _lowerCamelCase=0.1  ,    _lowerCamelCase=0.1  ,    _lowerCamelCase=0.1  ,    _lowerCamelCase=0.02  ,    _lowerCamelCase=True  ,    _lowerCamelCase=True  ,    _lowerCamelCase=10  ,    _lowerCamelCase=None  ,    )			->							Tuple:




										'''simple docstring'''
										__lowercase       =       parent
										__lowercase       =       batch_size
										__lowercase       =       image_size
										__lowercase       =       patch_size
										__lowercase       =       num_channels
										__lowercase       =       last_hidden_size
										__lowercase       =       num_attention_heads
										__lowercase       =       hidden_act
										__lowercase       =       conv_kernel_size
										__lowercase       =       output_stride
										__lowercase       =       hidden_dropout_prob
										__lowercase       =       attention_probs_dropout_prob
										__lowercase       =       classifier_dropout_prob
										__lowercase       =       use_labels
										__lowercase       =       is_training
										__lowercase       =       num_labels
										__lowercase       =       initializer_range
										__lowercase       =       scope
							def   SCREAMING_SNAKE_CASE						(     self       )			->							Tuple:




										'''simple docstring'''
										__lowercase       =       floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]       )

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

										__lowercase       =       self.get_config()

										return config, pixel_values, labels, pixel_labels
							def   SCREAMING_SNAKE_CASE						(     self       )			->							Tuple:




										'''simple docstring'''
										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   SCREAMING_SNAKE_CASE						(     self  ,    _lowerCamelCase  ,    _lowerCamelCase  ,    _lowerCamelCase  ,    _lowerCamelCase       )			->							str:




										'''simple docstring'''
										__lowercase       =       MobileViTModel(config=_lowerCamelCase       )
										model.to(_lowerCamelCase       )
										model.eval()
										__lowercase       =       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   SCREAMING_SNAKE_CASE						(     self  ,    _lowerCamelCase  ,    _lowerCamelCase  ,    _lowerCamelCase  ,    _lowerCamelCase       )			->							int:




										'''simple docstring'''
										__lowercase       =       self.num_labels
										__lowercase       =       MobileViTForImageClassification(_lowerCamelCase       )
										model.to(_lowerCamelCase       )
										model.eval()
										__lowercase       =       model(_lowerCamelCase  ,    labels=_lowerCamelCase       )
										self.parent.assertEqual(result.logits.shape  ,    (self.batch_size, self.num_labels)       )
							def   SCREAMING_SNAKE_CASE						(     self  ,    _lowerCamelCase  ,    _lowerCamelCase  ,    _lowerCamelCase  ,    _lowerCamelCase       )			->							Optional[int]:




										'''simple docstring'''
										__lowercase       =       self.num_labels
										__lowercase       =       MobileViTForSemanticSegmentation(_lowerCamelCase       )
										model.to(_lowerCamelCase       )
										model.eval()
										__lowercase       =       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,
										    )  ,    )
										__lowercase       =       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   SCREAMING_SNAKE_CASE						(     self       )			->							List[str]:




										'''simple docstring'''
										__lowercase       =       self.prepare_config_and_inputs()
										__lowercase   ,					__lowercase   ,					__lowercase   ,					__lowercase       =       config_and_inputs
										__lowercase       =       {"pixel_values": pixel_values}
										return config, inputs_dict





@require_torch
class 					__a     ( __a					,   __a					,   unittest.TestCase       ):



							'''simple docstring'''







							_lowerCamelCase					:			str          =   (
							    (MobileViTModel, MobileViTForImageClassification, MobileViTForSemanticSegmentation)
							    if is_torch_available()
							    else ()
							)
							_lowerCamelCase					:			Optional[int]          =   (
							    {
							        """feature-extraction""": MobileViTModel,
							        """image-classification""": MobileViTForImageClassification,
							        """image-segmentation""": MobileViTForSemanticSegmentation,
							    }
							    if is_torch_available()
							    else {}
							)

							_lowerCamelCase					:			Tuple          =   False
							_lowerCamelCase					:			Optional[Any]          =   False
							_lowerCamelCase					:			Any          =   False
							_lowerCamelCase					:			List[Any]          =   False
							def   SCREAMING_SNAKE_CASE						(     self       )			->							Tuple:




										'''simple docstring'''
										__lowercase       =       MobileViTModelTester(self       )
										__lowercase       =       MobileViTConfigTester(self  ,    config_class=_lowerCamelCase  ,    has_text_modality=_lowerCamelCase       )
							def   SCREAMING_SNAKE_CASE						(     self       )			->							Dict:




										'''simple docstring'''
										self.config_tester.run_common_tests()
							@unittest.skip(reason="MobileViT does not use inputs_embeds"       )
							def   SCREAMING_SNAKE_CASE						(     self       )			->							str:




										'''simple docstring'''
										pass
							@unittest.skip(reason="MobileViT does not support input and output embeddings"       )
							def   SCREAMING_SNAKE_CASE						(     self       )			->							Dict:




										'''simple docstring'''
										pass
							@unittest.skip(reason="MobileViT does not output attentions"       )
							def   SCREAMING_SNAKE_CASE						(     self       )			->							Dict:




										'''simple docstring'''
										pass
							def   SCREAMING_SNAKE_CASE						(     self       )			->							int:




										'''simple docstring'''
										__lowercase   ,					__lowercase       =       self.model_tester.prepare_config_and_inputs_for_common()

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

													__lowercase       =       ["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   SCREAMING_SNAKE_CASE						(     self       )			->							Dict:




										'''simple docstring'''
										pass
							def   SCREAMING_SNAKE_CASE						(     self       )			->							Tuple:




										'''simple docstring'''
										__lowercase       =       self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_model(*_lowerCamelCase       )
							def   SCREAMING_SNAKE_CASE						(     self       )			->							List[Any]:




										'''simple docstring'''
										def check_hidden_states_output(_lowerCamelCase  ,    _lowerCamelCase  ,    _lowerCamelCase       ):
													__lowercase       =       model_class(_lowerCamelCase       )
													model.to(_lowerCamelCase       )
													model.eval()

													with torch.no_grad():
																__lowercase       =       model(**self._prepare_for_class(_lowerCamelCase  ,    _lowerCamelCase       )       )

													__lowercase       =       outputs.hidden_states

													__lowercase       =       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.
													__lowercase       =       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       )

										__lowercase   ,					__lowercase       =       self.model_tester.prepare_config_and_inputs_for_common()

										for model_class in self.all_model_classes:
													__lowercase       =       True
													check_hidden_states_output(_lowerCamelCase  ,    _lowerCamelCase  ,    _lowerCamelCase       )

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

													check_hidden_states_output(_lowerCamelCase  ,    _lowerCamelCase  ,    _lowerCamelCase       )
							def   SCREAMING_SNAKE_CASE						(     self       )			->							List[str]:




										'''simple docstring'''
										__lowercase       =       self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_image_classification(*_lowerCamelCase       )
							def   SCREAMING_SNAKE_CASE						(     self       )			->							Optional[Any]:




										'''simple docstring'''
										__lowercase       =       self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_semantic_segmentation(*_lowerCamelCase       )





							@slow
							def   SCREAMING_SNAKE_CASE						(     self       )			->							Tuple:




										'''simple docstring'''
										for model_name in MOBILEVIT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
													__lowercase       =       MobileViTModel.from_pretrained(_lowerCamelCase       )
													self.assertIsNotNone(_lowerCamelCase       )





def      lowerCAmelCase__			(		)						->List[Any]:
			__lowercase       =       Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"      )
			return image







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



							'''simple docstring'''







							@cached_property
							def   SCREAMING_SNAKE_CASE						(     self       )			->							str:




										'''simple docstring'''
										return MobileViTImageProcessor.from_pretrained("apple/mobilevit-xx-small"       ) if is_vision_available() else None
							@slow
							def   SCREAMING_SNAKE_CASE						(     self       )			->							Optional[int]:




										'''simple docstring'''
										__lowercase       =       MobileViTForImageClassification.from_pretrained("apple/mobilevit-xx-small"       ).to(_lowerCamelCase       )

										__lowercase       =       self.default_image_processor
										__lowercase       =       prepare_img()
										__lowercase       =       image_processor(images=_lowerCamelCase  ,    return_tensors="pt"       ).to(_lowerCamelCase       )

										# forward pass
										with torch.no_grad():
													__lowercase       =       model(**_lowerCamelCase       )

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

										__lowercase       =       torch.tensor([-1.9364, -1.2327, -0.4653]       ).to(_lowerCamelCase       )

										self.assertTrue(torch.allclose(outputs.logits[0, :3]  ,    _lowerCamelCase  ,    atol=1e-4       )       )
							@slow
							def   SCREAMING_SNAKE_CASE						(     self       )			->							List[str]:




										'''simple docstring'''
										__lowercase       =       MobileViTForSemanticSegmentation.from_pretrained("apple/deeplabv3-mobilevit-xx-small"       )
										__lowercase       =       model.to(_lowerCamelCase       )

										__lowercase       =       MobileViTImageProcessor.from_pretrained("apple/deeplabv3-mobilevit-xx-small"       )

										__lowercase       =       prepare_img()
										__lowercase       =       image_processor(images=_lowerCamelCase  ,    return_tensors="pt"       ).to(_lowerCamelCase       )

										# forward pass
										with torch.no_grad():
													__lowercase       =       model(**_lowerCamelCase       )
										__lowercase       =       outputs.logits

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

										__lowercase       =       torch.tensor(
										    [
										        [[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]],
										    ]  ,    device=_lowerCamelCase  ,    )

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





							@slow
							def   SCREAMING_SNAKE_CASE						(     self       )			->							List[str]:




										'''simple docstring'''
										__lowercase       =       MobileViTForSemanticSegmentation.from_pretrained("apple/deeplabv3-mobilevit-xx-small"       )
										__lowercase       =       model.to(_lowerCamelCase       )

										__lowercase       =       MobileViTImageProcessor.from_pretrained("apple/deeplabv3-mobilevit-xx-small"       )

										__lowercase       =       prepare_img()
										__lowercase       =       image_processor(images=_lowerCamelCase  ,    return_tensors="pt"       ).to(_lowerCamelCase       )

										# forward pass
										with torch.no_grad():
													__lowercase       =       model(**_lowerCamelCase       )

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

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

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





