
"""simple docstring"""





import collections.abc
from typing import Optional, Tuple, Union

import torch
import torch.utils.checkpoint
from torch import nn
from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss

from ...activations import ACTaFN
from ...modeling_outputs import BaseModelOutputWithNoAttention, ImageClassifierOutputWithNoAttention
from ...modeling_utils import PreTrainedModel
from ...utils import add_code_sample_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward, logging
from .configuration_poolformer import PoolFormerConfig


_a		       =							logging.get_logger(__name__)

# General docstring
_a		       =							'PoolFormerConfig'

# Base docstring
_a		       =							'sail/poolformer_s12'
_a		       =							[1, 512, 7, 7]

# Image classification docstring
_a		       =							'sail/poolformer_s12'
_a		       =							'tabby, tabby cat'

_a		       =							[
    'sail/poolformer_s12',
    # See all PoolFormer models at https://huggingface.co/models?filter=poolformer
]







def 	__a     (		__lowerCamelCase,		__lowerCamelCase = 0.0,		__lowerCamelCase = False  ):
   if drop_prob == 0.0 or not training:
      return input
   UpperCAmelCase_					:					Optional[Any]			     =    1 - drop_prob
   UpperCAmelCase_					:					Union[str, Any]			     =    (input.shape[0],) + (1,) * (input.ndim - 1)  # work with diff dim tensors, not just 2D ConvNets
   UpperCAmelCase_					:					Union[str, Any]			     =    keep_prob + torch.rand(__lowerCamelCase,		dtype=input.dtype,		device=input.device  )
   random_tensor.floor_()  # binarize
   UpperCAmelCase_					:					Optional[Any]			     =    input.div(__lowerCamelCase  ) * random_tensor
   return output


class A_	(nn.Module      ):




  '''simple docstring'''







  def __init__(		self				,   lowercase_ = None  ):

     """simple docstring"""
     super().__init__()
     UpperCAmelCase_					:					str			     =    drop_prob







  def        UpperCamelCase__					(		self				,   lowercase_  ):

     """simple docstring"""
     return drop_path(lowercase_				,   self.drop_prob				,   self.training  )







  def        UpperCamelCase__					(		self  ):

     """simple docstring"""
     return "p={}".format(self.drop_prob  )




class A_	(nn.Module      ):




  '''simple docstring'''







  def __init__(		self				,   lowercase_				,   lowercase_				,   lowercase_				,   lowercase_				,   lowercase_				,   lowercase_=None  ):

     """simple docstring"""
     super().__init__()
     UpperCAmelCase_					:					Union[str, Any]			     =    patch_size if isinstance(lowercase_				,   collections.abc.Iterable  ) else (patch_size, patch_size)
     UpperCAmelCase_					:					Dict			     =    stride if isinstance(lowercase_				,   collections.abc.Iterable  ) else (stride, stride)
     UpperCAmelCase_					:					Optional[int]			     =    padding if isinstance(lowercase_				,   collections.abc.Iterable  ) else (padding, padding)

     UpperCAmelCase_					:					Optional[Any]			     =    nn.Convad(lowercase_				,   lowercase_				,   kernel_size=lowercase_				,   stride=lowercase_				,   padding=lowercase_  )
     UpperCAmelCase_					:					Optional[int]			     =    norm_layer(lowercase_  ) if norm_layer else nn.Identity()







  def        UpperCamelCase__					(		self				,   lowercase_  ):

     """simple docstring"""
     UpperCAmelCase_					:					List[Any]			     =    self.projection(lowercase_  )
     UpperCAmelCase_					:					List[Any]			     =    self.norm(lowercase_  )
     return embeddings




class A_	(nn.GroupNorm      ):




  '''simple docstring'''







  def __init__(		self				,   lowercase_				,   **lowercase_  ):

     """simple docstring"""
     super().__init__(1				,   lowercase_				,   **lowercase_  )




class A_	(nn.Module      ):




  '''simple docstring'''







  def __init__(		self				,   lowercase_  ):

     """simple docstring"""
     super().__init__()
     UpperCAmelCase_					:					Optional[Any]			     =    nn.AvgPoolad(lowercase_				,   stride=1				,   padding=pool_size // 2				,   count_include_pad=lowercase_  )







  def        UpperCamelCase__					(		self				,   lowercase_  ):

     """simple docstring"""
     return self.pool(lowercase_  ) - hidden_states




class A_	(nn.Module      ):




  '''simple docstring'''







  def __init__(		self				,   lowercase_				,   lowercase_				,   lowercase_				,   lowercase_  ):

     """simple docstring"""
     super().__init__()
     UpperCAmelCase_					:					Union[str, Any]			     =    nn.Convad(lowercase_				,   lowercase_				,   1  )
     UpperCAmelCase_					:					Any			     =    nn.Convad(lowercase_				,   lowercase_				,   1  )
     UpperCAmelCase_					:					Union[str, Any]			     =    PoolFormerDropPath(lowercase_  )
     if isinstance(config.hidden_act				,   lowercase_  ):
        UpperCAmelCase_					:					List[str]			     =    ACTaFN[config.hidden_act]
     else:
        UpperCAmelCase_					:					str			     =    config.hidden_act







  def        UpperCamelCase__					(		self				,   lowercase_  ):

     """simple docstring"""
     UpperCAmelCase_					:					Tuple			     =    self.conva(lowercase_  )
     UpperCAmelCase_					:					List[Any]			     =    self.act_fn(lowercase_  )
     UpperCAmelCase_					:					Union[str, Any]			     =    self.drop(lowercase_  )
     UpperCAmelCase_					:					Dict			     =    self.conva(lowercase_  )
     UpperCAmelCase_					:					Tuple			     =    self.drop(lowercase_  )

     return hidden_states




class A_	(nn.Module      ):




  '''simple docstring'''







  def __init__(		self				,   lowercase_				,   lowercase_				,   lowercase_				,   lowercase_				,   lowercase_				,   lowercase_  ):

     """simple docstring"""
     super().__init__()
     UpperCAmelCase_					:					str			     =    PoolFormerPooling(lowercase_  )
     UpperCAmelCase_					:					Dict			     =    PoolFormerOutput(lowercase_				,   lowercase_				,   lowercase_				,   lowercase_  )
     UpperCAmelCase_					:					List[str]			     =    PoolFormerGroupNorm(lowercase_  )
     UpperCAmelCase_					:					Optional[int]			     =    PoolFormerGroupNorm(lowercase_  )

     # Useful for training neural nets
     UpperCAmelCase_					:					Optional[Any]			     =    PoolFormerDropPath(lowercase_  ) if drop_path > 0.0 else nn.Identity()
     UpperCAmelCase_					:					str			     =    config.use_layer_scale
     if config.use_layer_scale:
        UpperCAmelCase_					:					Union[str, Any]			     =    nn.Parameter(
            config.layer_scale_init_value * torch.ones((lowercase_)  )				,   requires_grad=lowercase_  )
        UpperCAmelCase_					:					Union[str, Any]			     =    nn.Parameter(
            config.layer_scale_init_value * torch.ones((lowercase_)  )				,   requires_grad=lowercase_  )







  def        UpperCamelCase__					(		self				,   lowercase_  ):

     """simple docstring"""
     if self.use_layer_scale:
        UpperCAmelCase_					:					Union[str, Any]			     =    self.pooling(self.before_norm(lowercase_  )  )
        UpperCAmelCase_					:					Tuple			     =    self.layer_scale_a.unsqueeze(-1  ).unsqueeze(-1  ) * pooling_output
        # First residual connection
        UpperCAmelCase_					:					Optional[int]			     =    hidden_states + self.drop_path(lowercase_  )
        UpperCAmelCase_					:					List[str]			     =    ()

        UpperCAmelCase_					:					Union[str, Any]			     =    self.output(self.after_norm(lowercase_  )  )
        UpperCAmelCase_					:					Optional[Any]			     =    self.layer_scale_a.unsqueeze(-1  ).unsqueeze(-1  ) * layer_output
        # Second residual connection
        UpperCAmelCase_					:					List[Any]			     =    hidden_states + self.drop_path(lowercase_  )

        UpperCAmelCase_					:					List[Any]			     =    (output,) + outputs
        return outputs

     else:
        UpperCAmelCase_					:					Optional[int]			     =    self.drop_path(self.pooling(self.before_norm(lowercase_  )  )  )
        # First residual connection
        UpperCAmelCase_					:					Optional[int]			     =    pooling_output + hidden_states
        UpperCAmelCase_					:					Union[str, Any]			     =    ()

        # Second residual connection inside the PoolFormerOutput block
        UpperCAmelCase_					:					Optional[Any]			     =    self.drop_path(self.output(self.after_norm(lowercase_  )  )  )
        UpperCAmelCase_					:					Optional[int]			     =    hidden_states + layer_output

        UpperCAmelCase_					:					Tuple			     =    (output,) + outputs
        return outputs




class A_	(nn.Module      ):




  '''simple docstring'''







  def __init__(		self				,   lowercase_  ):

     """simple docstring"""
     super().__init__()
     UpperCAmelCase_					:					Optional[int]			     =    config
     # stochastic depth decay rule
     UpperCAmelCase_					:					Union[str, Any]			     =    [x.item() for x in torch.linspace(0				,   config.drop_path_rate				,   sum(config.depths  )  )]

     # patch embeddings
     UpperCAmelCase_					:					List[str]			     =    []
     for i in range(config.num_encoder_blocks  ):
        embeddings.append(
            PoolFormerEmbeddings(
                patch_size=config.patch_sizes[i]				,   stride=config.strides[i]				,   padding=config.padding[i]				,   num_channels=config.num_channels if i == 0 else config.hidden_sizes[i - 1]				,   hidden_size=config.hidden_sizes[i]				,   )  )
     UpperCAmelCase_					:					int			     =    nn.ModuleList(lowercase_  )

     # Transformer blocks
     UpperCAmelCase_					:					List[str]			     =    []
     UpperCAmelCase_					:					Dict			     =    0
     for i in range(config.num_encoder_blocks  ):
        # each block consists of layers
        UpperCAmelCase_					:					str			     =    []
        if i != 0:
           cur += config.depths[i - 1]
        for j in range(config.depths[i]  ):
           layers.append(
               PoolFormerLayer(
                   lowercase_				,   num_channels=config.hidden_sizes[i]				,   pool_size=config.pool_size				,   hidden_size=config.hidden_sizes[i]				,   intermediate_size=int(config.hidden_sizes[i] * config.mlp_ratio  )				,   drop_path=dpr[cur + j]				,   )  )
        blocks.append(nn.ModuleList(lowercase_  )  )

     UpperCAmelCase_					:					int			     =    nn.ModuleList(lowercase_  )







  def        UpperCamelCase__					(		self				,   lowercase_				,   lowercase_=False				,   lowercase_=True  ):

     """simple docstring"""
     UpperCAmelCase_					:					int			     =    () if output_hidden_states else None

     UpperCAmelCase_					:					int			     =    pixel_values
     for idx, layers in enumerate(zip(self.patch_embeddings				,   self.block  )  ):
        UpperCAmelCase_     ,   UpperCAmelCase_					:					Tuple			     =    layers
        # Get patch embeddings from hidden_states
        UpperCAmelCase_					:					List[str]			     =    embedding_layer(lowercase_  )
        # Send the embeddings through the blocks
        for _, blk in enumerate(lowercase_  ):
           UpperCAmelCase_					:					Tuple			     =    blk(lowercase_  )
           UpperCAmelCase_					:					int			     =    layer_outputs[0]

        if output_hidden_states:
           UpperCAmelCase_					:					List[Any]			     =    all_hidden_states + (hidden_states,)

     if not return_dict:
        return tuple(v for v in [hidden_states, all_hidden_states] if v is not None  )

     return BaseModelOutputWithNoAttention(last_hidden_state=lowercase_				,   hidden_states=lowercase_  )




class A_	(lowercase__      ):




  '''simple docstring'''
  SCREAMING_SNAKE_CASE__			:						str       =		PoolFormerConfig
  SCREAMING_SNAKE_CASE__			:						Optional[Any]       =		"""poolformer"""
  SCREAMING_SNAKE_CASE__			:						Optional[Any]       =		"""pixel_values"""
  SCREAMING_SNAKE_CASE__			:						Union[str, Any]       =		True







  def        UpperCamelCase__					(		self				,   lowercase_  ):

     """simple docstring"""
     if isinstance(lowercase_				,   (nn.Linear, nn.Convad)  ):
        module.weight.data.normal_(mean=0.0				,   std=self.config.initializer_range  )
        if module.bias is not None:
           module.bias.data.zero_()
     elif isinstance(lowercase_				,   nn.LayerNorm  ):
        module.bias.data.zero_()
        module.weight.data.fill_(1.0  )







  def        UpperCamelCase__					(		self				,   lowercase_				,   lowercase_=False  ):

     """simple docstring"""
     if isinstance(lowercase_				,   lowercase_  ):
        UpperCAmelCase_					:					List[Any]			     =    value




_a		       =							R'\n    This model is a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) sub-class. Use\n    it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and\n    behavior.\n\n    Parameters:\n        config ([`PoolFormerConfig`]): Model configuration class with all the parameters of the model.\n            Initializing with a config file does not load the weights associated with the model, only the\n            configuration. Check out the [`~PreTrainedModel.from_pretrained`] method to load the model weights.\n'

_a		       =							R'\n    Args:\n        pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, height, width)`):\n            Pixel values. Pixel values can be obtained using [`AutoImageProcessor`]. See\n            [`PoolFormerImageProcessor.__call__`] for details.\n'


@add_start_docstrings(
    """The bare PoolFormer Model transformer outputting raw hidden-states without any specific head on top."""				,lowercase__				,)
class A_	(lowercase__      ):




  '''simple docstring'''







  def __init__(		self				,   lowercase_  ):

     """simple docstring"""
     super().__init__(lowercase_  )
     UpperCAmelCase_					:					Tuple			     =    config

     UpperCAmelCase_					:					Dict			     =    PoolFormerEncoder(lowercase_  )

     # Initialize weights and apply final processing
     self.post_init()







  def        UpperCamelCase__					(		self  ):

     """simple docstring"""
     return self.embeddings.patch_embeddings







  @add_start_docstrings_to_model_forward(lowercase_  )
  @add_code_sample_docstrings(
      checkpoint=_CHECKPOINT_FOR_DOC				,   output_type=lowercase_				,   config_class=_CONFIG_FOR_DOC				,   modality="vision"				,   expected_output=_EXPECTED_OUTPUT_SHAPE				,   )
  def        UpperCamelCase__					(		self				,   lowercase_ = None				,   lowercase_ = None				,   lowercase_ = None				,   ):

     """simple docstring"""
     UpperCAmelCase_					:					str			     =    (
         output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
     )
     UpperCAmelCase_					:					int			     =    return_dict if return_dict is not None else self.config.use_return_dict

     if pixel_values is None:
        raise ValueError("You have to specify pixel_values"  )

     UpperCAmelCase_					:					Optional[Any]			     =    self.encoder(
         lowercase_				,   output_hidden_states=lowercase_				,   return_dict=lowercase_				,   )
     UpperCAmelCase_					:					Union[str, Any]			     =    encoder_outputs[0]

     if not return_dict:
        return (sequence_output, None) + encoder_outputs[1:]

     return BaseModelOutputWithNoAttention(
         last_hidden_state=lowercase_				,   hidden_states=encoder_outputs.hidden_states				,   )




class A_	(nn.Module      ):




  '''simple docstring'''







  def __init__(		self				,   lowercase_  ):

     """simple docstring"""
     super().__init__()
     UpperCAmelCase_					:					List[str]			     =    nn.Linear(config.hidden_size				,   config.hidden_size  )







  def        UpperCamelCase__					(		self				,   lowercase_  ):

     """simple docstring"""
     UpperCAmelCase_					:					Union[str, Any]			     =    self.dense(lowercase_  )
     return output




@add_start_docstrings(
    """
    PoolFormer Model transformer with an image classification head on top
    """				,lowercase__				,)
class A_	(lowercase__      ):




  '''simple docstring'''







  def __init__(		self				,   lowercase_  ):

     """simple docstring"""
     super().__init__(lowercase_  )
     UpperCAmelCase_					:					Tuple			     =    config.num_labels
     UpperCAmelCase_					:					List[Any]			     =    PoolFormerModel(lowercase_  )

     # Final norm
     UpperCAmelCase_					:					Union[str, Any]			     =    PoolFormerGroupNorm(config.hidden_sizes[-1]  )
     # Classifier head
     UpperCAmelCase_					:					Optional[Any]			     =    (
         nn.Linear(config.hidden_sizes[-1]				,   config.num_labels  ) if config.num_labels > 0 else nn.Identity()
     )

     # Initialize weights and apply final processing
     self.post_init()







  @add_start_docstrings_to_model_forward(lowercase_  )
  @add_code_sample_docstrings(
      checkpoint=_IMAGE_CLASS_CHECKPOINT				,   output_type=lowercase_				,   config_class=_CONFIG_FOR_DOC				,   expected_output=_IMAGE_CLASS_EXPECTED_OUTPUT				,   )
  def        UpperCamelCase__					(		self				,   lowercase_ = None				,   lowercase_ = None				,   lowercase_ = None				,   lowercase_ = None				,   ):

     """simple docstring"""
     UpperCAmelCase_					:					Optional[Any]			     =    return_dict if return_dict is not None else self.config.use_return_dict

     UpperCAmelCase_					:					Optional[int]			     =    self.poolformer(
         lowercase_				,   output_hidden_states=lowercase_				,   return_dict=lowercase_				,   )

     UpperCAmelCase_					:					Union[str, Any]			     =    outputs[0]

     UpperCAmelCase_					:					Union[str, Any]			     =    self.classifier(self.norm(lowercase_  ).mean([-2, -1]  )  )

     UpperCAmelCase_					:					str			     =    None
     if labels is not None:
        if self.config.problem_type is None:
           if self.num_labels == 1:
              UpperCAmelCase_					:					Dict			     =    "regression"
           elif self.num_labels > 1 and (labels.dtype == torch.long or labels.dtype == torch.int):
              UpperCAmelCase_					:					Optional[Any]			     =    "single_label_classification"
           else:
              UpperCAmelCase_					:					List[str]			     =    "multi_label_classification"

        if self.config.problem_type == "regression":
           UpperCAmelCase_					:					List[Any]			     =    MSELoss()
           if self.num_labels == 1:
              UpperCAmelCase_					:					Tuple			     =    loss_fct(logits.squeeze()				,   labels.squeeze()  )
           else:
              UpperCAmelCase_					:					Optional[int]			     =    loss_fct(lowercase_				,   lowercase_  )
        elif self.config.problem_type == "single_label_classification":
           UpperCAmelCase_					:					Optional[Any]			     =    CrossEntropyLoss()
           UpperCAmelCase_					:					Optional[Any]			     =    loss_fct(logits.view(-1				,   self.num_labels  )				,   labels.view(-1  )  )
        elif self.config.problem_type == "multi_label_classification":
           UpperCAmelCase_					:					Tuple			     =    BCEWithLogitsLoss()
           UpperCAmelCase_					:					str			     =    loss_fct(lowercase_				,   lowercase_  )

     if not return_dict:
        UpperCAmelCase_					:					Optional[Any]			     =    (logits,) + outputs[2:]
        return ((loss,) + output) if loss is not None else output

     return ImageClassifierOutputWithNoAttention(loss=lowercase_				,   logits=lowercase_				,   hidden_states=outputs.hidden_states  )




"""simple docstring"""





import inspect
import unittest

import numpy as np

from transformers import ViTConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor


if is_flax_available():
    import jax

    from transformers.models.vit.modeling_flax_vit import FlaxViTForImageClassification, FlaxViTModel


class A_	(unittest.TestCase      ):




  '''simple docstring'''







  def __init__(		self				,   lowercase_				,   lowercase_=13				,   lowercase_=30				,   lowercase_=2				,   lowercase_=3				,   lowercase_=True				,   lowercase_=True				,   lowercase_=32				,   lowercase_=5				,   lowercase_=4				,   lowercase_=37				,   lowercase_="gelu"				,   lowercase_=0.1				,   lowercase_=0.1				,   lowercase_=10				,   lowercase_=0.02				,   ):

     """simple docstring"""
     UpperCAmelCase_					:					Tuple			     =    parent
     UpperCAmelCase_					:					List[str]			     =    batch_size
     UpperCAmelCase_					:					Union[str, Any]			     =    image_size
     UpperCAmelCase_					:					List[str]			     =    patch_size
     UpperCAmelCase_					:					Union[str, Any]			     =    num_channels
     UpperCAmelCase_					:					Optional[int]			     =    is_training
     UpperCAmelCase_					:					Dict			     =    use_labels
     UpperCAmelCase_					:					Any			     =    hidden_size
     UpperCAmelCase_					:					Optional[Any]			     =    num_hidden_layers
     UpperCAmelCase_					:					Optional[Any]			     =    num_attention_heads
     UpperCAmelCase_					:					Dict			     =    intermediate_size
     UpperCAmelCase_					:					Optional[Any]			     =    hidden_act
     UpperCAmelCase_					:					Optional[Any]			     =    hidden_dropout_prob
     UpperCAmelCase_					:					Tuple			     =    attention_probs_dropout_prob
     UpperCAmelCase_					:					Dict			     =    type_sequence_label_size
     UpperCAmelCase_					:					Optional[Any]			     =    initializer_range

     # in ViT, the seq length equals the number of patches + 1 (we add 1 for the [CLS] token)
     UpperCAmelCase_					:					Any			     =    (image_size // patch_size) ** 2
     UpperCAmelCase_					:					List[str]			     =    num_patches + 1







  def        UpperCamelCase__					(		self  ):

     """simple docstring"""
     UpperCAmelCase_					:					Optional[Any]			     =    floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]  )

     UpperCAmelCase_					:					Dict			     =    ViTConfig(
         image_size=self.image_size				,   patch_size=self.patch_size				,   num_channels=self.num_channels				,   hidden_size=self.hidden_size				,   num_hidden_layers=self.num_hidden_layers				,   num_attention_heads=self.num_attention_heads				,   intermediate_size=self.intermediate_size				,   hidden_act=self.hidden_act				,   hidden_dropout_prob=self.hidden_dropout_prob				,   attention_probs_dropout_prob=self.attention_probs_dropout_prob				,   is_decoder=lowercase_				,   initializer_range=self.initializer_range				,   )

     return config, pixel_values







  def        UpperCamelCase__					(		self				,   lowercase_				,   lowercase_  ):

     """simple docstring"""
     UpperCAmelCase_					:					List[str]			     =    FlaxViTModel(config=lowercase_  )
     UpperCAmelCase_					:					int			     =    model(lowercase_  )
     # expected sequence length = num_patches + 1 (we add 1 for the [CLS] token)
     UpperCAmelCase_					:					Optional[Any]			     =    (self.image_size, self.image_size)
     UpperCAmelCase_					:					List[Any]			     =    (self.patch_size, self.patch_size)
     UpperCAmelCase_					:					str			     =    (image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])
     self.parent.assertEqual(result.last_hidden_state.shape				,   (self.batch_size, num_patches + 1, self.hidden_size)  )







  def        UpperCamelCase__					(		self				,   lowercase_				,   lowercase_  ):

     """simple docstring"""
     UpperCAmelCase_					:					Tuple			     =    self.type_sequence_label_size
     UpperCAmelCase_					:					Tuple			     =    FlaxViTForImageClassification(config=lowercase_  )
     UpperCAmelCase_					:					str			     =    model(lowercase_  )
     self.parent.assertEqual(result.logits.shape				,   (self.batch_size, self.type_sequence_label_size)  )

     # test greyscale images
     UpperCAmelCase_					:					Any			     =    1
     UpperCAmelCase_					:					Optional[int]			     =    FlaxViTForImageClassification(lowercase_  )

     UpperCAmelCase_					:					List[Any]			     =    floats_tensor([self.batch_size, 1, self.image_size, self.image_size]  )
     UpperCAmelCase_					:					List[Any]			     =    model(lowercase_  )







  def        UpperCamelCase__					(		self  ):

     """simple docstring"""
     UpperCAmelCase_					:					List[Any]			     =    self.prepare_config_and_inputs()
     (
         (
         UpperCAmelCase_
     )     ,   (
         UpperCAmelCase_
     )     ,   
     )					:					Tuple			     =    config_and_inputs
     UpperCAmelCase_					:					Union[str, Any]			     =    {"pixel_values": pixel_values}
     return config, inputs_dict




@require_flax
class A_	(lowercase__				,unittest.TestCase      ):




  '''simple docstring'''
  SCREAMING_SNAKE_CASE__			:						Any       =		(FlaxViTModel, FlaxViTForImageClassification) if is_flax_available() else ()







  def        UpperCamelCase__					(		self  ):

     """simple docstring"""
     UpperCAmelCase_					:					List[Any]			     =    FlaxViTModelTester(self  )
     UpperCAmelCase_					:					Dict			     =    ConfigTester(self				,   config_class=lowercase_				,   has_text_modality=lowercase_				,   hidden_size=37  )







  def        UpperCamelCase__					(		self  ):

     """simple docstring"""
     self.config_tester.run_common_tests()







  def        UpperCamelCase__					(		self  ):

     """simple docstring"""
     UpperCAmelCase_					:					List[Any]			     =    self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_model(*lowercase_  )







  def        UpperCamelCase__					(		self  ):

     """simple docstring"""
     UpperCAmelCase_					:					Optional[Any]			     =    self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_image_classification(*lowercase_  )







  def        UpperCamelCase__					(		self  ):

     """simple docstring"""
     UpperCAmelCase_     ,   UpperCAmelCase_					:					List[str]			     =    self.model_tester.prepare_config_and_inputs_for_common()

     for model_class in self.all_model_classes:
        UpperCAmelCase_					:					Optional[Any]			     =    model_class(lowercase_  )
        UpperCAmelCase_					:					Optional[int]			     =    inspect.signature(model.__call__  )
        # signature.parameters is an OrderedDict => so arg_names order is deterministic
        UpperCAmelCase_					:					List[str]			     =    [*signature.parameters.keys()]

        UpperCAmelCase_					:					List[str]			     =    ["pixel_values"]
        self.assertListEqual(arg_names[:1]				,   lowercase_  )







  def        UpperCamelCase__					(		self  ):

     """simple docstring"""
     UpperCAmelCase_     ,   UpperCAmelCase_					:					Tuple			     =    self.model_tester.prepare_config_and_inputs_for_common()

     for model_class in self.all_model_classes:
        with self.subTest(model_class.__name__  ):
           UpperCAmelCase_					:					Union[str, Any]			     =    self._prepare_for_class(lowercase_				,   lowercase_  )
           UpperCAmelCase_					:					Tuple			     =    model_class(lowercase_  )

           @jax.jit
           def model_jitted(lowercase_				,   **lowercase_  ):
              return model(pixel_values=lowercase_				,   **lowercase_  )

           with self.subTest("JIT Enabled"  ):
              UpperCAmelCase_					:					Union[str, Any]			     =    model_jitted(**lowercase_  ).to_tuple()

           with self.subTest("JIT Disabled"  ):
              with jax.disable_jit():
                 UpperCAmelCase_					:					Tuple			     =    model_jitted(**lowercase_  ).to_tuple()

           self.assertEqual(len(lowercase_  )				,   len(lowercase_  )  )
           for jitted_output, output in zip(lowercase_				,   lowercase_  ):
              self.assertEqual(jitted_output.shape				,   output.shape  )







  @slow
  def        UpperCamelCase__					(		self  ):

     """simple docstring"""
     for model_class_name in self.all_model_classes:
        UpperCAmelCase_					:					Union[str, Any]			     =    model_class_name.from_pretrained("google/vit-base-patch16-224"  )
        UpperCAmelCase_					:					List[str]			     =    model(np.ones((1, 3, 224, 224)  )  )
        self.assertIsNotNone(lowercase_  )


