"""simple docstring"""





import random
import timeit
from functools import wraps
from typing import Callable, Optional

from ..configuration_utils import PretrainedConfig
from ..models.auto.modeling_tf_auto import TF_MODEL_MAPPING, TF_MODEL_WITH_LM_HEAD_MAPPING
from ..utils import is_pyanvml_available, is_tf_available, logging
from .benchmark_utils import (
    Benchmark,
    Memory,
    MemorySummary,
    measure_peak_memory_cpu,
    start_memory_tracing,
    stop_memory_tracing,
)


if is_tf_available():
       import tensorflow as tf
       from tensorflow.python.framework.errors_impl import ResourceExhaustedError

       from .benchmark_args_tf import TensorFlowBenchmarkArguments

if is_pyanvml_available():
       import pyanvml.pyanvml as nvml

_UpperCamelCase   :						Optional[int]      =    logging.get_logger(__name__)





def 				a_     (      _lowerCAmelCase  : Union[str, Any]   , _lowerCAmelCase  : Optional[Any]     ):





       '''simple docstring'''

       def run_func(_lowerCAmelCase  : Union[str, Any]     ):
              @wraps(_lowerCAmelCase     )
              def run_in_eager_mode(*_lowerCAmelCase  : Tuple   , **_lowerCAmelCase  : List[Any]     ):
                     return func(*_lowerCAmelCase   , **_lowerCAmelCase     )

              @wraps(_lowerCAmelCase     )
              @tf.function(experimental_compile=_lowerCAmelCase     )
              def run_in_graph_mode(*_lowerCAmelCase  : Union[str, Any]   , **_lowerCAmelCase  : str     ):
                     return func(*_lowerCAmelCase   , **_lowerCAmelCase     )

              if do_eager_mode is True:
                     if use_xla is not False:
                            raise ValueError(
                                'Cannot run model in XLA, if `args.eager_mode` is set to `True`. Please set `args.eager_mode=False`.'     )
                     return run_in_eager_mode
              else:
                     return run_in_graph_mode

       return run_func





def 				a_     (      _lowerCAmelCase  : Union[str, Any]   , _lowerCAmelCase  : List[str]   , _lowerCAmelCase  : int     ):





       '''simple docstring'''

       lowercase__			:		str       =	random.Random()
       lowercase__			:		Any       =	[rng.randint(0   , vocab_size - 1     ) for i in range(batch_size * sequence_length     )]
       return tf.constant(_lowerCAmelCase   , shape=(batch_size, sequence_length)   , dtype=tf.intaa     )






class      UpperCAmelCase_	(    _lowercase):
      lowerCamelCase__		:    Dict   =  4_2
      lowerCamelCase__		:    Optional[Any]   =  4_2
      lowerCamelCase__		:    Optional[int]   =  "TensorFlow"


      @property
      def 		_UpperCAmelCase       (   self							)       ->					int:
             return tf.__version__


      def 		_UpperCAmelCase       (   self		,			a		,			a		,			a							)       ->					Any:
             # initialize GPU on separate process
             lowercase__			:		str       =	self.args.strategy
             if strategy is None:
                    raise ValueError('A device strategy has to be initialized before using TensorFlow.'							)
             lowercase__			:		Tuple       =	self._prepare_inference_func(UpperCamelCase__		,			UpperCamelCase__		,			UpperCamelCase__							)
             return self._measure_speed(_inference							)


      def 		_UpperCAmelCase       (   self		,			a		,			a		,			a							)       ->					Any:
             lowercase__			:		Union[str, Any]       =	self.args.strategy
             if strategy is None:
                    raise ValueError('A device strategy has to be initialized before using TensorFlow.'							)
             lowercase__			:		Dict       =	self._prepare_train_func(UpperCamelCase__		,			UpperCamelCase__		,			UpperCamelCase__							)
             return self._measure_speed(_train							)


      def 		_UpperCAmelCase       (   self		,			a		,			a		,			a							)       ->					Any:
             # initialize GPU on separate process
             if self.args.is_gpu:
                    tf.config.experimental.set_memory_growth(self.args.gpu_list[self.args.device_idx]		,			UpperCamelCase__							)
             lowercase__			:		int       =	self.args.strategy
             if strategy is None:
                    raise ValueError('A device strategy has to be initialized before using TensorFlow.'							)
             lowercase__			:		Tuple       =	self._prepare_inference_func(UpperCamelCase__		,			UpperCamelCase__		,			UpperCamelCase__							)
             return self._measure_memory(_inference							)


      def 		_UpperCAmelCase       (   self		,			a		,			a		,			a							)       ->					Optional[Any]:
             if self.args.is_gpu:
                    tf.config.experimental.set_memory_growth(self.args.gpu_list[self.args.device_idx]		,			UpperCamelCase__							)
             lowercase__			:		Tuple       =	self.args.strategy
             if strategy is None:
                    raise ValueError('A device strategy has to be initialized before using TensorFlow.'							)

             lowercase__			:		List[Any]       =	self._prepare_train_func(UpperCamelCase__		,			UpperCamelCase__		,			UpperCamelCase__							)
             return self._measure_memory(_train							)


      def 		_UpperCAmelCase       (   self		,			a		,			a		,			a							)       ->					Tuple:
             lowercase__			:		int       =	self.config_dict[model_name]

             if self.args.fpaa:
                    raise NotImplementedError('Mixed precision is currently not supported.'							)

             lowercase__			:		List[str]       =	(
                 hasattr(UpperCamelCase__		,			'architectures'							)
                 and isinstance(config.architectures		,			UpperCamelCase__							)
                 and len(config.architectures							) > 0
             )
             if not self.args.only_pretrain_model and has_model_class_in_config:
                    try:
                           lowercase__			:		Optional[int]       =	"""TF""" + config.architectures[0]  # prepend 'TF' for tensorflow model
                           lowercase__			:		Optional[Any]       =	__import__('transformers'		,			fromlist=[model_class]							)
                           lowercase__			:		List[Any]       =	getattr(UpperCamelCase__		,			UpperCamelCase__							)
                           lowercase__			:		Optional[int]       =	model_cls(UpperCamelCase__							)
                    except ImportError:
                           raise ImportError(
                               f"""{model_class} does not exist. If you just want to test the pretrained model, you might want to"""
                               ' set `--only_pretrain_model` or `args.only_pretrain_model=True`.'							)
             else:
                    lowercase__			:		Union[str, Any]       =	TF_MODEL_MAPPING[config.__class__](UpperCamelCase__							)

             # encoder-decoder has vocab size saved differently
             lowercase__			:		int       =	config.vocab_size if hasattr(UpperCamelCase__		,			'vocab_size'							) else config.encoder.vocab_size
             lowercase__			:		int       =	random_input_ids(UpperCamelCase__		,			UpperCamelCase__		,			UpperCamelCase__							)

             @run_with_tf_optimizations(self.args.eager_mode		,			self.args.use_xla							)
             def encoder_decoder_forward():
                    return model(UpperCamelCase__		,			decoder_input_ids=UpperCamelCase__		,			training=UpperCamelCase__							)

             @run_with_tf_optimizations(self.args.eager_mode		,			self.args.use_xla							)
             def encoder_forward():
                    return model(UpperCamelCase__		,			training=UpperCamelCase__							)

             lowercase__			:		Any       =	encoder_decoder_forward if config.is_encoder_decoder else encoder_forward

             return _inference


      def 		_UpperCAmelCase       (   self		,			a		,			a		,			a							)       ->					Optional[int]:
             lowercase__			:		Tuple       =	self.config_dict[model_name]

             if self.args.eager_mode is not False:
                    raise ValueError('Training cannot be done in eager mode. Please make sure that `args.eager_mode = False`.'							)

             if self.args.fpaa:
                    raise NotImplementedError('Mixed precision is currently not supported.'							)

             lowercase__			:		Any       =	(
                 hasattr(UpperCamelCase__		,			'architectures'							)
                 and isinstance(config.architectures		,			UpperCamelCase__							)
                 and len(config.architectures							) > 0
             )
             if not self.args.only_pretrain_model and has_model_class_in_config:
                    try:
                           lowercase__			:		List[str]       =	"""TF""" + config.architectures[0]  # prepend 'TF' for tensorflow model
                           lowercase__			:		Tuple       =	__import__('transformers'		,			fromlist=[model_class]							)
                           lowercase__			:		Optional[Any]       =	getattr(UpperCamelCase__		,			UpperCamelCase__							)
                           lowercase__			:		str       =	model_cls(UpperCamelCase__							)
                    except ImportError:
                           raise ImportError(
                               f"""{model_class} does not exist. If you just want to test the pretrained model, you might want to"""
                               ' set `--only_pretrain_model` or `args.only_pretrain_model=True`.'							)
             else:
                    lowercase__			:		List[str]       =	TF_MODEL_WITH_LM_HEAD_MAPPING[config.__class__](UpperCamelCase__							)

             # encoder-decoder has vocab size saved differently
             lowercase__			:		Tuple       =	config.vocab_size if hasattr(UpperCamelCase__		,			'vocab_size'							) else config.encoder.vocab_size
             lowercase__			:		int       =	random_input_ids(UpperCamelCase__		,			UpperCamelCase__		,			UpperCamelCase__							)

             @run_with_tf_optimizations(self.args.eager_mode		,			self.args.use_xla							)
             def encoder_decoder_train():
                    lowercase__			:		int       =	model(UpperCamelCase__		,			decoder_input_ids=UpperCamelCase__		,			labels=UpperCamelCase__		,			training=UpperCamelCase__							)[0]
                    lowercase__			:		Any       =	tf.gradients(UpperCamelCase__		,			model.trainable_variables							)
                    return gradients

             @run_with_tf_optimizations(self.args.eager_mode		,			self.args.use_xla							)
             def encoder_train():
                    lowercase__			:		Dict       =	model(UpperCamelCase__		,			labels=UpperCamelCase__		,			training=UpperCamelCase__							)[0]
                    lowercase__			:		Union[str, Any]       =	tf.gradients(UpperCamelCase__		,			model.trainable_variables							)
                    return gradients

             lowercase__			:		List[Any]       =	encoder_decoder_train if config.is_encoder_decoder else encoder_train

             return _train


      def 		_UpperCAmelCase       (   self		,			a							)       ->					Optional[Any]:
             with self.args.strategy.scope():
                    try:
                           if self.args.is_tpu or self.args.use_xla:
                                  # run additional 10 times to stabilize compilation for tpu
                                  logger.info('Do inference on TPU. Running model 5 times to stabilize compilation'							)
                                  timeit.repeat(UpperCamelCase__		,			repeat=1		,			number=5							)

                           # as written in https://docs.python.org/2/library/timeit.html#timeit.Timer.repeat, min should be taken rather than the average
                           lowercase__			:		Tuple       =	timeit.repeat(
                               UpperCamelCase__		,			repeat=self.args.repeat		,			number=1_0		,			)

                           return min(UpperCamelCase__							) / 10.0
                    except ResourceExhaustedError as e:
                           self.print_fn(f"""Doesn\'t fit on GPU. {e}"""							)


      def 		_UpperCAmelCase       (   self		,			a							)       ->					List[str]:
             logger.info(
                 'Note that TensorFlow allocates more memory than '
                 'it might need to speed up computation. '
                 'The memory reported here corresponds to the memory '
                 'reported by `nvidia-smi`, which can vary depending '
                 'on total available memory on the GPU that is used.'							)
             with self.args.strategy.scope():
                    try:
                           if self.args.trace_memory_line_by_line:
                                  if not self.args.eager_mode:
                                         raise ValueError(
                                             '`args.eager_mode` is set to `False`. Make sure to run model in eager mode to measure memory'
                                             ' consumption line by line.'							)
                                  lowercase__			:		List[Any]       =	start_memory_tracing('transformers'							)

                           if self.args.is_tpu:
                                  # tpu
                                  raise NotImplementedError(
                                      'Memory Benchmarking is currently not implemented for TPU. Please disable memory benchmarking'
                                      ' with `args.memory=False`'							)
                           elif self.args.is_gpu:
                                  # gpu
                                  if not is_pyanvml_available():
                                         logger.warning(
                                             'py3nvml not installed, we won\'t log GPU memory usage. '
                                             'Install py3nvml (pip install py3nvml) to log information about GPU.'							)
                                         lowercase__			:		str       =	"""N/A"""
                                  else:
                                         logger.info(
                                             'Measuring total GPU usage on GPU device. Make sure to not have additional processes'
                                             ' running on the same GPU.'							)
                                         # init nvml
                                         nvml.nvmlInit()
                                         func()
                                         lowercase__			:		List[str]       =	nvml.nvmlDeviceGetHandleByIndex(self.args.device_idx							)
                                         lowercase__			:		int       =	nvml.nvmlDeviceGetMemoryInfo(UpperCamelCase__							)
                                         lowercase__			:		int       =	meminfo.used
                                         lowercase__			:		int       =	Memory(UpperCamelCase__							)
                                         # shutdown nvml
                                         nvml.nvmlShutdown()
                           else:
                                  # cpu
                                  if self.args.trace_memory_line_by_line:
                                         logger.info(
                                             'When enabling line by line tracing, the max peak memory for CPU is inaccurate in'
                                             ' TensorFlow.'							)
                                         lowercase__			:		List[Any]       =	None
                                  else:
                                         lowercase__			:		List[str]       =	measure_peak_memory_cpu(UpperCamelCase__							)
                                         lowercase__			:		Union[str, Any]       =	Memory(UpperCamelCase__							) if isinstance(UpperCamelCase__		,			UpperCamelCase__							) else memory_bytes
                           if self.args.trace_memory_line_by_line:
                                  lowercase__			:		Dict       =	stop_memory_tracing(UpperCamelCase__							)
                                  if memory is None:
                                         lowercase__			:		Union[str, Any]       =	summary.total
                           else:
                                  lowercase__			:		List[str]       =	None

                           return memory, summary
                    except ResourceExhaustedError as e:
                           self.print_fn(f"""Doesn\'t fit on GPU. {e}"""							)
                           return "N/A", None









'''simple docstring'''







import inspect
import unittest

from transformers import MobileNetVaConfig
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 MobileNetVaForImageClassification, MobileNetVaModel
			from transformers.models.mobilenet_va.modeling_mobilenet_va import MOBILENET_V1_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
			from PIL import Image

			from transformers import MobileNetVaImageProcessor

class _lowercase	(				_lowercase		):




							def 		lowerCamelCase_				(							self:				Any     ):
														lowerCamelCase__					:	str         =       self.config_class(**self.inputs_dict     )
														self.parent.assertTrue(hasattr(UpperCamelCase__			,							"""tf_padding"""     )     )
														self.parent.assertTrue(hasattr(UpperCamelCase__			,							"""depth_multiplier"""     )     )



class _lowercase	:




							def __init__(							self:				str			,							UpperCamelCase__:				Dict			,							UpperCamelCase__:				Tuple=13			,							UpperCamelCase__:				Optional[int]=3			,							UpperCamelCase__:				List[Any]=32			,							UpperCamelCase__:				Optional[Any]=0.25			,							UpperCamelCase__:				int=8			,							UpperCamelCase__:				Any=True			,							UpperCamelCase__:				Dict=1_024			,							UpperCamelCase__:				Optional[int]=32			,							UpperCamelCase__:				Tuple="relu6"			,							UpperCamelCase__:				int=0.1			,							UpperCamelCase__:				List[Any]=0.02			,							UpperCamelCase__:				Optional[Any]=True			,							UpperCamelCase__:				Union[str, Any]=True			,							UpperCamelCase__:				Union[str, Any]=10			,							UpperCamelCase__:				str=None			,							):
														lowerCamelCase__					:	Optional[Any]         =       parent
														lowerCamelCase__					:	List[str]         =       batch_size
														lowerCamelCase__					:	Optional[int]         =       num_channels
														lowerCamelCase__					:	Optional[int]         =       image_size
														lowerCamelCase__					:	Optional[Any]         =       depth_multiplier
														lowerCamelCase__					:	Union[str, Any]         =       min_depth
														lowerCamelCase__					:	Optional[Any]         =       tf_padding
														lowerCamelCase__					:	str         =       int(last_hidden_size * depth_multiplier     )
														lowerCamelCase__					:	Any         =       output_stride
														lowerCamelCase__					:	int         =       hidden_act
														lowerCamelCase__					:	Tuple         =       classifier_dropout_prob
														lowerCamelCase__					:	Dict         =       use_labels
														lowerCamelCase__					:	Tuple         =       is_training
														lowerCamelCase__					:	Optional[Any]         =       num_labels
														lowerCamelCase__					:	Union[str, Any]         =       initializer_range
														lowerCamelCase__					:	Optional[Any]         =       scope




							def 		lowerCamelCase_				(							self:				List[str]     ):
														lowerCamelCase__					:	Optional[Any]         =       floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]     )

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

														lowerCamelCase__					:	Dict         =       self.get_config()

														return config, pixel_values, labels, pixel_labels




							def 		lowerCamelCase_				(							self:				str     ):
														return MobileNetVaConfig(
														    num_channels=self.num_channels			,							image_size=self.image_size			,							depth_multiplier=self.depth_multiplier			,							min_depth=self.min_depth			,							tf_padding=self.tf_padding			,							hidden_act=self.hidden_act			,							classifier_dropout_prob=self.classifier_dropout_prob			,							initializer_range=self.initializer_range			,							)




							def 		lowerCamelCase_				(							self:				Tuple			,							UpperCamelCase__:				int			,							UpperCamelCase__:				str			,							UpperCamelCase__:				Any			,							UpperCamelCase__:				Optional[int]     ):
														lowerCamelCase__					:	List[str]         =       MobileNetVaModel(config=UpperCamelCase__     )
														model.to(UpperCamelCase__     )
														model.eval()
														lowerCamelCase__					:	List[str]         =       model(UpperCamelCase__     )
														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:				str			,							UpperCamelCase__:				Tuple			,							UpperCamelCase__:				Optional[int]			,							UpperCamelCase__:				List[Any]			,							UpperCamelCase__:				Union[str, Any]     ):
														lowerCamelCase__					:	List[str]         =       self.num_labels
														lowerCamelCase__					:	Optional[Any]         =       MobileNetVaForImageClassification(UpperCamelCase__     )
														model.to(UpperCamelCase__     )
														model.eval()
														lowerCamelCase__					:	List[Any]         =       model(UpperCamelCase__			,							labels=UpperCamelCase__     )
														self.parent.assertEqual(result.logits.shape			,							(self.batch_size, self.num_labels)     )




							def 		lowerCamelCase_				(							self:				Optional[Any]     ):
														lowerCamelCase__					:	str         =       self.prepare_config_and_inputs()
														lowerCamelCase__  ,		lowerCamelCase__  ,		lowerCamelCase__  ,		lowerCamelCase__					:	int         =       config_and_inputs
														lowerCamelCase__					:	Optional[int]         =       {"""pixel_values""": pixel_values}
														return config, inputs_dict



@require_torch
class _lowercase	(				_lowercase				,      _lowercase				,      unittest.TestCase		):
							a				      =       (MobileNetVaModel, MobileNetVaForImageClassification) if is_torch_available() else ()
							a				      =       (
							    {"""feature-extraction""": MobileNetVaModel, """image-classification""": MobileNetVaForImageClassification}
							    if is_torch_available()
							    else {}
							)

							a				      =       False
							a				      =       False
							a				      =       False
							a				      =       False




							def 		lowerCamelCase_				(							self:				List[str]     ):
														lowerCamelCase__					:	Optional[int]         =       MobileNetVaModelTester(self     )
														lowerCamelCase__					:	List[str]         =       MobileNetVaConfigTester(self			,							config_class=UpperCamelCase__			,							has_text_modality=UpperCamelCase__     )




							def 		lowerCamelCase_				(							self:				Union[str, Any]     ):
														self.config_tester.run_common_tests()




							@unittest.skip(reason="""MobileNetV1 does not use inputs_embeds"""     )
							def 		lowerCamelCase_				(							self:				Optional[int]     ):
														pass




							@unittest.skip(reason="""MobileNetV1 does not support input and output embeddings"""     )
							def 		lowerCamelCase_				(							self:				Optional[Any]     ):
														pass




							@unittest.skip(reason="""MobileNetV1 does not output attentions"""     )
							def 		lowerCamelCase_				(							self:				Any     ):
														pass




							def 		lowerCamelCase_				(							self:				Any     ):
														lowerCamelCase__  ,		lowerCamelCase__					:	Optional[Any]         =       self.model_tester.prepare_config_and_inputs_for_common()

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

																					lowerCamelCase__					:	Dict         =       ["""pixel_values"""]
																					self.assertListEqual(arg_names[:1]			,							UpperCamelCase__     )




							def 		lowerCamelCase_				(							self:				str     ):
														lowerCamelCase__					:	Tuple         =       self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_model(*UpperCamelCase__     )




							def 		lowerCamelCase_				(							self:				str     ):
														def check_hidden_states_output(UpperCamelCase__:				List[Any]			,							UpperCamelCase__:				Dict			,							UpperCamelCase__:				List[Any]     ):
																					lowerCamelCase__					:	str         =       model_class(UpperCamelCase__     )
																					model.to(UpperCamelCase__     )
																					model.eval()

																					with torch.no_grad():
																												lowerCamelCase__					:	Union[str, Any]         =       model(**self._prepare_for_class(UpperCamelCase__			,							UpperCamelCase__     )     )

																					lowerCamelCase__					:	List[Any]         =       outputs.hidden_states

																					lowerCamelCase__					:	Tuple         =       26
																					self.assertEqual(len(UpperCamelCase__     )			,							UpperCamelCase__     )

														lowerCamelCase__  ,		lowerCamelCase__					:	List[str]         =       self.model_tester.prepare_config_and_inputs_for_common()

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

																					# check that output_hidden_states also work using config
																					del inputs_dict["output_hidden_states"]
																					lowerCamelCase__					:	Optional[Any]         =       True

																					check_hidden_states_output(UpperCamelCase__			,							UpperCamelCase__			,							UpperCamelCase__     )




							def 		lowerCamelCase_				(							self:				Dict     ):
														lowerCamelCase__					:	int         =       self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_for_image_classification(*UpperCamelCase__     )




							@slow
							def 		lowerCamelCase_				(							self:				List[str]     ):
														for model_name in MOBILENET_V1_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																					lowerCamelCase__					:	Dict         =       MobileNetVaModel.from_pretrained(UpperCamelCase__     )
																					self.assertIsNotNone(UpperCamelCase__     )





def  SCREAMING_SNAKE_CASE_       ()      ->       Union[str, Any]:
							lowerCamelCase__					:	Optional[int]         =       Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""      )
							return image



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




							@cached_property
							def 		lowerCamelCase_				(							self:				Optional[int]     ):
														return (
														    MobileNetVaImageProcessor.from_pretrained("""google/mobilenet_v1_1.0_224"""     ) if is_vision_available() else None
														)




							@slow
							def 		lowerCamelCase_				(							self:				Dict     ):
														lowerCamelCase__					:	List[Any]         =       MobileNetVaForImageClassification.from_pretrained("""google/mobilenet_v1_1.0_224"""     ).to(UpperCamelCase__     )

														lowerCamelCase__					:	Dict         =       self.default_image_processor
														lowerCamelCase__					:	int         =       prepare_img()
														lowerCamelCase__					:	List[Any]         =       image_processor(images=UpperCamelCase__			,							return_tensors="""pt"""     ).to(UpperCamelCase__     )

														# forward pass
														with torch.no_grad():
																					lowerCamelCase__					:	str         =       model(**UpperCamelCase__     )

														# verify the logits
														lowerCamelCase__					:	List[str]         =       torch.Size((1, 1_001)     )
														self.assertEqual(outputs.logits.shape			,							UpperCamelCase__     )

														lowerCamelCase__					:	List[str]         =       torch.tensor([-4.1_739, -1.1_233, 3.1_205]     ).to(UpperCamelCase__     )

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

