






'''simple docstring'''

import inspect

import jax
import jax.lax as lax
import jax.numpy as jnp

from ..utils import add_start_docstrings
from ..utils.logging import get_logger


SCREAMING_SNAKE_CASE__											=     get_logger(__name__)


SCREAMING_SNAKE_CASE__											=     R'\n    Args:\n        input_ids (`jnp.ndarray` of shape `(batch_size, sequence_length)`):\n            Indices of input sequence tokens in the vocabulary.\n\n            Indices can be obtained using [`PreTrainedTokenizer`]. See [`PreTrainedTokenizer.encode`] and\n            [`PreTrainedTokenizer.__call__`] for details.\n\n            [What are input IDs?](../glossary#input-ids)\n        scores (`jnp.ndarray` of shape `(batch_size, config.vocab_size)`):\n            Prediction scores of a language modeling head. These can be logits for each vocabulary when not using beam\n            search or log softmax for each vocabulary token when using beam search\n        kwargs (`Dict[str, Any]`, *optional*):\n            Additional logits processor specific kwargs.\n\n    Return:\n        `jnp.ndarray` of shape `(batch_size, config.vocab_size)`: The processed prediction scores.\n\n'






class        a_		:

    @add_start_docstrings(a_   )
    def __call__(   self    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE   )						->   List[str]:



          """simple docstring"""






          raise NotImplementedError(
              F"{self.__class__} is an abstract class. Only classes inheriting this class can be called."   )






class        a_		:

    @add_start_docstrings(a_   )
    def __call__(   self    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE   )						->   Tuple:



          """simple docstring"""






          raise NotImplementedError(
              F"{self.__class__} is an abstract class. Only classes inheriting this class can be called."   )






class        a_		(    __lowerCamelCase       ):

    @add_start_docstrings(a_   )
    def __call__(   self    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE    ,	**_SCREAMING_SNAKE_CASE   )						->   List[Any]:



          """simple docstring"""






          for processor in self:
                UpperCamelCase       						=      inspect.signature(processor.__call__   ).parameters
                if len(a_   ) > 3:
                      if not all(arg in kwargs for arg in list(function_args.keys()   )[2:]   ):
                            raise ValueError(
                                F"Make sure that all the required parameters: {list(function_args.keys()   )} for "
                                F"{processor.__class__} are passed to the logits processor."   )
                      UpperCamelCase       						=      processor(a_    ,	a_    ,	a_    ,	**a_   )
                else:
                      UpperCamelCase       						=      processor(a_    ,	a_    ,	a_   )
          return scores






class        a_		(    __lowerCamelCase       ):

    def __init__(   self    ,	_SCREAMING_SNAKE_CASE   )						->   Dict:



          """simple docstring"""






          if not isinstance(a_    ,	a_   ) or not (temperature > 0):
                raise ValueError(F"`temperature` has to be a strictly positive float, but is {temperature}"   )

          UpperCamelCase       						=      temperature


    def __call__(   self    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE   )						->   Any:



          """simple docstring"""






          UpperCamelCase       						=      scores / self.temperature
          return scores






class        a_		(    __lowerCamelCase       ):

    def __init__(   self    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE = -float("""Inf"""   )    ,	_SCREAMING_SNAKE_CASE = 1   )						->   Tuple:



          """simple docstring"""






          if not isinstance(a_    ,	a_   ) or (top_p < 0 or top_p > 1.0):
                raise ValueError(F"`top_p` has to be a float > 0 and < 1, but is {top_p}"   )
          if not isinstance(a_    ,	a_   ) or (min_tokens_to_keep < 1):
                raise ValueError(F"`min_tokens_to_keep` has to be a positive integer, but is {min_tokens_to_keep}"   )

          UpperCamelCase       						=      top_p
          UpperCamelCase       						=      filter_value
          UpperCamelCase       						=      min_tokens_to_keep


    def __call__(   self    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE   )						->   Tuple:



          """simple docstring"""






          UpperCamelCase       						=      lax.top_k(a_    ,	scores.shape[-1]   )

          UpperCamelCase       						=      jnp.full_like(a_    ,	self.filter_value   )
          UpperCamelCase       						=      jax.nn.softmax(a_    ,	axis=-1   ).cumsum(axis=-1   )
          UpperCamelCase       						=      cumulative_probs < self.top_p

          # include the token that is higher than top_p as well
          UpperCamelCase       						=      jnp.roll(a_    ,	1   )
          score_mask |= score_mask.at[:, 0].set(a_   )

          # min tokens to keep
          UpperCamelCase       						=      score_mask.at[:, : self.min_tokens_to_keep].set(a_   )

          UpperCamelCase       						=      jnp.where(a_    ,	a_    ,	a_   )
          UpperCamelCase       						=      jax.lax.sort_key_val(a_    ,	a_   )[-1]

          return next_scores






class        a_		(    __lowerCamelCase       ):

    def __init__(   self    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE = -float("""Inf"""   )    ,	_SCREAMING_SNAKE_CASE = 1   )						->   List[Any]:



          """simple docstring"""






          if not isinstance(a_    ,	a_   ) or top_k <= 0:
                raise ValueError(F"`top_k` has to be a strictly positive integer, but is {top_k}"   )

          UpperCamelCase       						=      max(a_    ,	a_   )
          UpperCamelCase       						=      filter_value


    def __call__(   self    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE   )						->   Tuple:



          """simple docstring"""






          UpperCamelCase       						=      scores.shape
          UpperCamelCase       						=      jnp.full(batch_size * vocab_size    ,	self.filter_value   )

          UpperCamelCase       						=      min(self.top_k    ,	scores.shape[-1]   )  # Safety check
          UpperCamelCase       						=      lax.top_k(a_    ,	a_   )
          UpperCamelCase       						=      jnp.broadcast_to((jnp.arange(a_   ) * vocab_size)[:, None]    ,	(batch_size, topk)   ).flatten()
          UpperCamelCase       						=      topk_scores.flatten()
          UpperCamelCase       						=      topk_indices.flatten() + shift

          UpperCamelCase       						=      next_scores_flat.at[topk_indices_flat].set(a_   )
          UpperCamelCase       						=      next_scores_flat.reshape(a_    ,	a_   )
          return next_scores






class        a_		(    __lowerCamelCase       ):

    def __init__(   self    ,	_SCREAMING_SNAKE_CASE   )						->   Any:



          """simple docstring"""






          UpperCamelCase       						=      bos_token_id


    def __call__(   self    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE   )						->   Optional[int]:



          """simple docstring"""






          UpperCamelCase       						=      jnp.full(scores.shape    ,	-float("""inf"""   )   )

          UpperCamelCase       						=      1 - jnp.bool_(cur_len - 1   )

          UpperCamelCase       						=      jnp.where(a_    ,	new_scores.at[:, self.bos_token_id].set(0   )    ,	a_   )

          return scores






class        a_		(    __lowerCamelCase       ):

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



          """simple docstring"""






          UpperCamelCase       						=      max_length
          UpperCamelCase       						=      eos_token_id


    def __call__(   self    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE   )						->   Dict:



          """simple docstring"""






          UpperCamelCase       						=      jnp.full(scores.shape    ,	-float("""inf"""   )   )

          UpperCamelCase       						=      1 - jnp.bool_(cur_len - self.max_length + 1   )

          UpperCamelCase       						=      jnp.where(a_    ,	new_scores.at[:, self.eos_token_id].set(0   )    ,	a_   )

          return scores






class        a_		(    __lowerCamelCase       ):

    def __init__(   self    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE   )						->   str:



          """simple docstring"""






          if not isinstance(a_    ,	a_   ) or min_length < 0:
                raise ValueError(F"`min_length` has to be a positive integer, but is {min_length}"   )

          if not isinstance(a_    ,	a_   ) or eos_token_id < 0:
                raise ValueError(F"`eos_token_id` has to be a positive integer, but is {eos_token_id}"   )

          UpperCamelCase       						=      min_length
          UpperCamelCase       						=      eos_token_id


    def __call__(   self    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE   )						->   int:



          """simple docstring"""






          UpperCamelCase       						=      1 - jnp.clip(cur_len - self.min_length    ,	0    ,	1   )

          UpperCamelCase       						=      jnp.where(a_    ,	scores.at[:, self.eos_token_id].set(-float("""inf"""   )   )    ,	a_   )

          return scores






class        a_		(    __lowerCamelCase       ):

    def __init__(   self    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE   )						->   List[str]:



          """simple docstring"""






          UpperCamelCase       						=      list(a_   )
          UpperCamelCase       						=      begin_index


    def __call__(   self    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE   )						->   Dict:



          """simple docstring"""






          UpperCamelCase       						=      1 - jnp.bool_(cur_len - self.begin_index   )

          UpperCamelCase       						=      jnp.where(a_    ,	scores.at[:, self.begin_suppress_tokens].set(-float("""inf"""   )   )    ,	a_   )

          return scores






class        a_		(    __lowerCamelCase       ):

    def __init__(   self    ,	_SCREAMING_SNAKE_CASE   )						->   str:



          """simple docstring"""






          UpperCamelCase       						=      list(a_   )


    def __call__(   self    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE   )						->   Dict:



          """simple docstring"""






          UpperCamelCase       						=      scores.at[..., self.suppress_tokens].set(-float("""inf"""   )   )

          return scores






class        a_		(    __lowerCamelCase       ):

    def __init__(   self    ,	_SCREAMING_SNAKE_CASE   )						->   Optional[int]:



          """simple docstring"""






          UpperCamelCase       						=      dict(a_   )
          # Converts the dictionary of format {index: token} containing the tokens to be forced to an array, where the
          # index of the array corresponds to the index of the token to be forced, for XLA compatibility.
          # Indexes without forced tokens will have a negative value.
          UpperCamelCase       						=      jnp.ones((max(force_token_map.keys()   ) + 1)    ,	dtype=jnp.intaa   ) * -1
          for index, token in force_token_map.items():
                if token is not None:
                      UpperCamelCase       						=      force_token_array.at[index].set(a_   )
          UpperCamelCase       						=      jnp.intaa(a_   )


    def __call__(   self    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE   )						->   Optional[Any]:



          """simple docstring"""






          def _force_token(_SCREAMING_SNAKE_CASE   ):
                UpperCamelCase       						=      scores.shape[0]
                UpperCamelCase       						=      self.force_token_array[generation_idx]

                UpperCamelCase       						=      jnp.ones_like(a_    ,	dtype=scores.dtype   ) * -float("""inf"""   )
                UpperCamelCase       						=      jnp.zeros((batch_size, 1)    ,	dtype=scores.dtype   )
                UpperCamelCase       						=      lax.dynamic_update_slice(a_    ,	a_    ,	(0, current_token)   )
                return new_scores

          UpperCamelCase       						=      lax.cond(
              cur_len >= self.force_token_array.shape[0]    ,	lambda: scores    ,	lambda: lax.cond(
                  self.force_token_array[cur_len] >= 0    ,	lambda: _force_token(a_   )    ,	lambda: scores    ,	)    ,	)
          return scores






class        a_		(    __lowerCamelCase       ):

    def __init__(   self    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE   )						->   Optional[int]:



          """simple docstring"""






          UpperCamelCase       						=      generate_config.eos_token_id
          UpperCamelCase       						=      generate_config.no_timestamps_token_id
          UpperCamelCase       						=      generate_config.no_timestamps_token_id + 1

          UpperCamelCase       						=      decoder_input_length + 1

          if generate_config.is_multilingual:
                # room for language token and task token
                self.begin_index += 2
          if hasattr(a_    ,	"""max_initial_timestamp_index"""   ):
                UpperCamelCase       						=      generate_config.max_initial_timestamp_index
          else:
                UpperCamelCase       						=      model_config.vocab_size
          if self.max_initial_timestamp_index is None:
                UpperCamelCase       						=      model_config.vocab_size


    def __call__(   self    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE   )						->   List[Any]:



          """simple docstring"""






          UpperCamelCase       						=      scores.at[:, self.no_timestamps_token_id].set(-float("""inf"""   )   )

          def handle_pairs(_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE   ):
                UpperCamelCase       						=      jnp.where((cur_len - self.begin_index) >= 1    ,	a_    ,	a_   )
                UpperCamelCase       						=      jnp.where(
                    input_ids_k[cur_len - 1] >= self.timestamp_begin    ,	True and last_was_timestamp    ,	a_    ,	)

                UpperCamelCase       						=      jnp.where((cur_len - self.begin_index) < 2    ,	a_    ,	a_   )
                UpperCamelCase       						=      jnp.where(
                    input_ids_k[cur_len - 2] >= self.timestamp_begin    ,	a_    ,	a_    ,	)

                return jnp.where(
                    a_    ,	jnp.where(
                        penultimate_was_timestamp > 0    ,	scores_k.at[self.timestamp_begin :].set(-float("""inf"""   )   )    ,	scores_k.at[: self.eos_token_id].set(-float("""inf"""   )   )    ,	)    ,	a_    ,	)

          UpperCamelCase       						=      jax.vmap(a_   )(a_    ,	a_   )

          UpperCamelCase       						=      jnp.where(cur_len == self.begin_index    ,	a_    ,	a_   )
          UpperCamelCase       						=      jnp.where(
              self.max_initial_timestamp_index is not None    ,	True and apply_max_initial_timestamp    ,	a_    ,	)

          UpperCamelCase       						=      self.timestamp_begin + self.max_initial_timestamp_index

          UpperCamelCase       						=      jnp.where(
              a_    ,	scores.at[:, last_allowed + 1 :].set(-float("""inf"""   )   )    ,	a_    ,	)

          # if sum of probability over timestamps is above any other token, sample timestamp
          UpperCamelCase       						=      jax.nn.log_softmax(a_    ,	axis=-1   )

          def handle_cumulative_probs(_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE   ):
                UpperCamelCase       						=      jax.nn.logsumexp(logprobs_k[self.timestamp_begin :]    ,	axis=-1   )
                UpperCamelCase       						=      jnp.max(logprobs_k[: self.timestamp_begin]   )
                return jnp.where(
                    timestamp_logprob > max_text_token_logprob    ,	scores_k.at[: self.timestamp_begin].set(-float("""inf"""   )   )    ,	a_    ,	)

          UpperCamelCase       						=      jax.vmap(a_   )(a_    ,	a_   )

          return scores








'''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        a_		(    lowerCamelCase       ):

  def 						A__		(   self   )						->   int:



        """simple docstring"""






        UpperCamelCase       						=      self.config_class(**self.inputs_dict   )
        self.parent.assertTrue(hasattr(_SCREAMING_SNAKE_CASE    ,	"""tf_padding"""   )   )
        self.parent.assertTrue(hasattr(_SCREAMING_SNAKE_CASE    ,	"""depth_multiplier"""   )   )






class        a_		:

  def __init__(   self    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE=13    ,	_SCREAMING_SNAKE_CASE=3    ,	_SCREAMING_SNAKE_CASE=32    ,	_SCREAMING_SNAKE_CASE=0.2_5    ,	_SCREAMING_SNAKE_CASE=8    ,	_SCREAMING_SNAKE_CASE=True    ,	_SCREAMING_SNAKE_CASE=1024    ,	_SCREAMING_SNAKE_CASE=32    ,	_SCREAMING_SNAKE_CASE="relu6"    ,	_SCREAMING_SNAKE_CASE=0.1    ,	_SCREAMING_SNAKE_CASE=0.0_2    ,	_SCREAMING_SNAKE_CASE=True    ,	_SCREAMING_SNAKE_CASE=True    ,	_SCREAMING_SNAKE_CASE=10    ,	_SCREAMING_SNAKE_CASE=None    ,	)						->   List[str]:



        """simple docstring"""






        UpperCamelCase       						=      parent
        UpperCamelCase       						=      batch_size
        UpperCamelCase       						=      num_channels
        UpperCamelCase       						=      image_size
        UpperCamelCase       						=      depth_multiplier
        UpperCamelCase       						=      min_depth
        UpperCamelCase       						=      tf_padding
        UpperCamelCase       						=      int(last_hidden_size * depth_multiplier   )
        UpperCamelCase       						=      output_stride
        UpperCamelCase       						=      hidden_act
        UpperCamelCase       						=      classifier_dropout_prob
        UpperCamelCase       						=      use_labels
        UpperCamelCase       						=      is_training
        UpperCamelCase       						=      num_labels
        UpperCamelCase       						=      initializer_range
        UpperCamelCase       						=      scope

  def 						A__		(   self   )						->   int:



        """simple docstring"""






        UpperCamelCase       						=      floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]   )

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

        UpperCamelCase       						=      self.get_config()

        return config, pixel_values, labels, pixel_labels

  def 						A__		(   self   )						->   Optional[Any]:



        """simple docstring"""






        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 						A__		(   self    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE   )						->   int:



        """simple docstring"""






        UpperCamelCase       						=      MobileNetVaModel(config=_SCREAMING_SNAKE_CASE   )
        model.to(_SCREAMING_SNAKE_CASE   )
        model.eval()
        UpperCamelCase       						=      model(_SCREAMING_SNAKE_CASE   )
        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 						A__		(   self    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE   )						->   List[Any]:



        """simple docstring"""






        UpperCamelCase       						=      self.num_labels
        UpperCamelCase       						=      MobileNetVaForImageClassification(_SCREAMING_SNAKE_CASE   )
        model.to(_SCREAMING_SNAKE_CASE   )
        model.eval()
        UpperCamelCase       						=      model(_SCREAMING_SNAKE_CASE    ,	labels=_SCREAMING_SNAKE_CASE   )
        self.parent.assertEqual(result.logits.shape    ,	(self.batch_size, self.num_labels)   )


  def 						A__		(   self   )						->   Any:



        """simple docstring"""






        UpperCamelCase       						=      self.prepare_config_and_inputs()
        UpperCamelCase						,UpperCamelCase						,UpperCamelCase						,UpperCamelCase       						=      config_and_inputs
        UpperCamelCase       						=      {"""pixel_values""": pixel_values}
        return config, inputs_dict






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

  lowercase  	=   False
  lowercase  	=   False
  lowercase  	=   False
  lowercase  	=   False

  def 						A__		(   self   )						->   int:



        """simple docstring"""






        UpperCamelCase       						=      MobileNetVaModelTester(self   )
        UpperCamelCase       						=      MobileNetVaConfigTester(self    ,	config_class=_SCREAMING_SNAKE_CASE    ,	has_text_modality=_SCREAMING_SNAKE_CASE   )

  def 						A__		(   self   )						->   Optional[Any]:



        """simple docstring"""






        self.config_tester.run_common_tests()

  @unittest.skip(reason="""MobileNetV1 does not use inputs_embeds"""   )
  def 						A__		(   self   )						->   int:



        """simple docstring"""






        pass

  @unittest.skip(reason="""MobileNetV1 does not support input and output embeddings"""   )
  def 						A__		(   self   )						->   int:



        """simple docstring"""






        pass

  @unittest.skip(reason="""MobileNetV1 does not output attentions"""   )
  def 						A__		(   self   )						->   Dict:



        """simple docstring"""






        pass

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



        """simple docstring"""






        UpperCamelCase						,UpperCamelCase       						=      self.model_tester.prepare_config_and_inputs_for_common()

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

              UpperCamelCase       						=      ["""pixel_values"""]
              self.assertListEqual(arg_names[:1]    ,	_SCREAMING_SNAKE_CASE   )

  def 						A__		(   self   )						->   str:



        """simple docstring"""






        UpperCamelCase       						=      self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*_SCREAMING_SNAKE_CASE   )

  def 						A__		(   self   )						->   int:



        """simple docstring"""






        def check_hidden_states_output(_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE   ):
              UpperCamelCase       						=      model_class(_SCREAMING_SNAKE_CASE   )
              model.to(_SCREAMING_SNAKE_CASE   )
              model.eval()

              with torch.no_grad():
                    UpperCamelCase       						=      model(**self._prepare_for_class(_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE   )   )

              UpperCamelCase       						=      outputs.hidden_states

              UpperCamelCase       						=      26
              self.assertEqual(len(_SCREAMING_SNAKE_CASE   )    ,	_SCREAMING_SNAKE_CASE   )

        UpperCamelCase						,UpperCamelCase       						=      self.model_tester.prepare_config_and_inputs_for_common()

        for model_class in self.all_model_classes:
              UpperCamelCase       						=      True
              check_hidden_states_output(_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE   )

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

              check_hidden_states_output(_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE   )

  def 						A__		(   self   )						->   str:



        """simple docstring"""






        UpperCamelCase       						=      self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_image_classification(*_SCREAMING_SNAKE_CASE   )


  @slow
  def 						A__		(   self   )						->   Dict:



        """simple docstring"""






        for model_name in MOBILENET_V1_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
              UpperCamelCase       						=      MobileNetVaModel.from_pretrained(_SCREAMING_SNAKE_CASE   )
              self.assertIsNotNone(_SCREAMING_SNAKE_CASE   )







def 					lowercase__				(   )->				Optional[Any]:
      UpperCamelCase       						=      Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""					)
      return image






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

  @cached_property
  def 						A__		(   self   )						->   Dict:



        """simple docstring"""






        return (
            MobileNetVaImageProcessor.from_pretrained("""google/mobilenet_v1_1.0_224"""   ) if is_vision_available() else None
        )


  @slow
  def 						A__		(   self   )						->   Union[str, Any]:



        """simple docstring"""






        UpperCamelCase       						=      MobileNetVaForImageClassification.from_pretrained("""google/mobilenet_v1_1.0_224"""   ).to(_SCREAMING_SNAKE_CASE   )

        UpperCamelCase       						=      self.default_image_processor
        UpperCamelCase       						=      prepare_img()
        UpperCamelCase       						=      image_processor(images=_SCREAMING_SNAKE_CASE    ,	return_tensors="""pt"""   ).to(_SCREAMING_SNAKE_CASE   )

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

        # verify the logits
        UpperCamelCase       						=      torch.Size((1, 1001)   )
        self.assertEqual(outputs.logits.shape    ,	_SCREAMING_SNAKE_CASE   )

        UpperCamelCase       						=      torch.tensor([-4.1_7_3_9, -1.1_2_3_3, 3.1_2_0_5]   ).to(_SCREAMING_SNAKE_CASE   )

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