


import functools
import math

import flax.linen as nn
import jax
import jax.numpy as jnp

def  lowercase_						(						_A     :       List[str]       ,   _A     :       Dict       ,   _A     :       str       ,   _A     :       int       ,   _A     :       int = 4096		):

      """simple docstring"""




      lowerCamelCase__       ,  lowerCamelCase__       ,  lowerCamelCase__						:							str       =    key.shape[-3:]
      lowerCamelCase__						:							Any       =    value.shape[-1]
      lowerCamelCase__						:							Optional[Any]       =    min(_A       ,   _A		)
      lowerCamelCase__						:							List[Any]       =    query / jnp.sqrt(_A		)

      @functools.partial(jax.checkpoint       ,   prevent_cse=_A		)
      def summarize_chunk(_A     :       List[str]       ,   _A     :       int       ,   _A     :       List[Any]		):
            lowerCamelCase__						:							List[Any]       =    jnp.einsum("...qhd,...khd->...qhk"       ,   _A       ,   _A       ,   precision=_A		)

            lowerCamelCase__						:							List[str]       =    jnp.max(_A       ,   axis=-1       ,   keepdims=_A		)
            lowerCamelCase__						:							Optional[int]       =    jax.lax.stop_gradient(_A		)
            lowerCamelCase__						:							Union[str, Any]       =    jnp.exp(attn_weights - max_score		)

            lowerCamelCase__						:							Any       =    jnp.einsum("...vhf,...qhv->...qhf"       ,   _A       ,   _A       ,   precision=_A		)
            lowerCamelCase__						:							Optional[int]       =    jnp.einsum("...qhk->...qh"       ,   _A		)

            return (exp_values, exp_weights.sum(axis=-1		), max_score)

      def chunk_scanner(_A     :       int		):
            # julienne key array
            lowerCamelCase__						:							str       =    jax.lax.dynamic_slice(
                operand=_A       ,   start_indices=[0] * (key.ndim - 3) + [chunk_idx, 0, 0]       ,   slice_sizes=list(key.shape[:-3]		) + [key_chunk_size, num_heads, k_features]       ,   )

            # julienne value array
            lowerCamelCase__						:							List[str]       =    jax.lax.dynamic_slice(
                operand=_A       ,   start_indices=[0] * (value.ndim - 3) + [chunk_idx, 0, 0]       ,   slice_sizes=list(value.shape[:-3]		) + [key_chunk_size, num_heads, v_features]       ,   )

            return summarize_chunk(_A       ,   _A       ,   _A		)

      lowerCamelCase__       ,  lowerCamelCase__       ,  lowerCamelCase__						:							Optional[int]       =    jax.lax.map(f=_A       ,   xs=jnp.arange(0       ,   _A       ,   _A		)		)

      lowerCamelCase__						:							Optional[Any]       =    jnp.max(_A       ,   axis=0       ,   keepdims=_A		)
      lowerCamelCase__						:							Optional[int]       =    jnp.exp(chunk_max - global_max		)

      chunk_values *= jnp.expand_dims(_A       ,   axis=-1		)
      chunk_weights *= max_diffs

      lowerCamelCase__						:							Optional[Any]       =    chunk_values.sum(axis=0		)
      lowerCamelCase__						:							Dict       =    jnp.expand_dims(_A       ,   -1		).sum(axis=0		)

      return all_values / all_weights

def  lowercase_						(						_A     :       str       ,   _A     :       Union[str, Any]       ,   _A     :       Dict       ,   _A     :       Optional[int]=jax.lax.Precision.HIGHEST       ,   _A     :       int = 1024       ,   _A     :       int = 4096		):

      """simple docstring"""




      lowerCamelCase__       ,  lowerCamelCase__       ,  lowerCamelCase__						:							Dict       =    query.shape[-3:]

      def chunk_scanner(_A     :       List[str]       ,   _A     :       Tuple		):
            # julienne query array
            lowerCamelCase__						:							Dict       =    jax.lax.dynamic_slice(
                operand=_A       ,   start_indices=([0] * (query.ndim - 3)) + [chunk_idx, 0, 0]       ,   slice_sizes=list(query.shape[:-3]		) + [min(_A       ,   _A		), num_heads, q_features]       ,   )

            return (
                chunk_idx + query_chunk_size,  # unused ignore it
                _query_chunk_attention(
                    query=_A       ,   key=_A       ,   value=_A       ,   precision=_A       ,   key_chunk_size=_A		),
            )

      lowerCamelCase__       ,  lowerCamelCase__						:							Union[str, Any]       =    jax.lax.scan(
          f=_A       ,   init=0       ,   xs=_A       ,   length=math.ceil(num_q / query_chunk_size		)		)

      return jnp.concatenate(_A       ,   axis=-3		)  # fuse the chunked result back







class      _lowercase					(				nn.Module):


       """simple docstring"""




       A__   		=     42
       A__   		=     8
       A__   		=     64
       A__   		=     0.0
       A__   		=     False
       A__   		=     jnp.floataa





       def 		lowerCAmelCase	(  self				:     Union[str, Any]			):


             '''simple docstring'''



             lowerCamelCase__						:							List[Any]       =    self.dim_head * self.heads
             lowerCamelCase__						:							Dict       =    self.dim_head**-0.5

             # Weights were exported with old names {to_q, to_k, to_v, to_out}
             lowerCamelCase__						:							Any       =    nn.Dense(__lowerCamelCase   , use_bias=__lowerCamelCase   , dtype=self.dtype   , name="to_q"			)
             lowerCamelCase__						:							Union[str, Any]       =    nn.Dense(__lowerCamelCase   , use_bias=__lowerCamelCase   , dtype=self.dtype   , name="to_k"			)
             lowerCamelCase__						:							Optional[Any]       =    nn.Dense(__lowerCamelCase   , use_bias=__lowerCamelCase   , dtype=self.dtype   , name="to_v"			)

             lowerCamelCase__						:							List[Any]       =    nn.Dense(self.query_dim   , dtype=self.dtype   , name="to_out_0"			)
             lowerCamelCase__						:							List[Any]       =    nn.Dropout(rate=self.dropout			)





       def 		lowerCAmelCase	(  self				:     str   , __lowerCamelCase				:     Dict			):


             '''simple docstring'''



             lowerCamelCase__       ,  lowerCamelCase__       ,  lowerCamelCase__						:							Tuple       =    tensor.shape
             lowerCamelCase__						:							Dict       =    self.heads
             lowerCamelCase__						:							Any       =    tensor.reshape(__lowerCamelCase   , __lowerCamelCase   , __lowerCamelCase   , dim // head_size			)
             lowerCamelCase__						:							Optional[int]       =    jnp.transpose(__lowerCamelCase   , (0, 2, 1, 3)			)
             lowerCamelCase__						:							Tuple       =    tensor.reshape(batch_size * head_size   , __lowerCamelCase   , dim // head_size			)
             return tensor





       def 		lowerCAmelCase	(  self				:     Optional[int]   , __lowerCamelCase				:     Optional[Any]			):


             '''simple docstring'''



             lowerCamelCase__       ,  lowerCamelCase__       ,  lowerCamelCase__						:							int       =    tensor.shape
             lowerCamelCase__						:							int       =    self.heads
             lowerCamelCase__						:							Optional[Any]       =    tensor.reshape(batch_size // head_size   , __lowerCamelCase   , __lowerCamelCase   , __lowerCamelCase			)
             lowerCamelCase__						:							List[Any]       =    jnp.transpose(__lowerCamelCase   , (0, 2, 1, 3)			)
             lowerCamelCase__						:							Union[str, Any]       =    tensor.reshape(batch_size // head_size   , __lowerCamelCase   , dim * head_size			)
             return tensor





       def __call__(  self				:     List[Any]   , __lowerCamelCase				:     Union[str, Any]   , __lowerCamelCase				:     int=None   , __lowerCamelCase				:     str=True			):


             '''simple docstring'''



             lowerCamelCase__						:							Union[str, Any]       =    hidden_states if context is None else context

             lowerCamelCase__						:							List[str]       =    self.query(__lowerCamelCase			)
             lowerCamelCase__						:							Optional[int]       =    self.key(__lowerCamelCase			)
             lowerCamelCase__						:							int       =    self.value(__lowerCamelCase			)

             lowerCamelCase__						:							Union[str, Any]       =    self.reshape_heads_to_batch_dim(__lowerCamelCase			)
             lowerCamelCase__						:							str       =    self.reshape_heads_to_batch_dim(__lowerCamelCase			)
             lowerCamelCase__						:							int       =    self.reshape_heads_to_batch_dim(__lowerCamelCase			)

             if self.use_memory_efficient_attention:
                   lowerCamelCase__						:							int       =    query_states.transpose(1   , 0   , 2			)
                   lowerCamelCase__						:							int       =    key_states.transpose(1   , 0   , 2			)
                   lowerCamelCase__						:							str       =    value_states.transpose(1   , 0   , 2			)

                   # this if statement create a chunk size for each layer of the unet
                   # the chunk size is equal to the query_length dimension of the deepest layer of the unet

                   lowerCamelCase__						:							List[str]       =    query_states.shape[-3]
                   if flatten_latent_dim % 64 == 0:
                         lowerCamelCase__						:							List[str]       =    int(flatten_latent_dim / 64			)
                   elif flatten_latent_dim % 16 == 0:
                         lowerCamelCase__						:							Optional[int]       =    int(flatten_latent_dim / 16			)
                   elif flatten_latent_dim % 4 == 0:
                         lowerCamelCase__						:							Optional[int]       =    int(flatten_latent_dim / 4			)
                   else:
                         lowerCamelCase__						:							List[Any]       =    int(__lowerCamelCase			)

                   lowerCamelCase__						:							Union[str, Any]       =    jax_memory_efficient_attention(
                       __lowerCamelCase   , __lowerCamelCase   , __lowerCamelCase   , query_chunk_size=__lowerCamelCase   , key_chunk_size=4096 * 4			)

                   lowerCamelCase__						:							Optional[int]       =    hidden_states.transpose(1   , 0   , 2			)
             else:
                   # compute attentions
                   lowerCamelCase__						:							List[str]       =    jnp.einsum("b i d, b j d->b i j"   , __lowerCamelCase   , __lowerCamelCase			)
                   lowerCamelCase__						:							List[str]       =    attention_scores * self.scale
                   lowerCamelCase__						:							Tuple       =    nn.softmax(__lowerCamelCase   , axis=2			)

                   # attend to values
                   lowerCamelCase__						:							Any       =    jnp.einsum("b i j, b j d -> b i d"   , __lowerCamelCase   , __lowerCamelCase			)

             lowerCamelCase__						:							Tuple       =    self.reshape_batch_dim_to_heads(__lowerCamelCase			)
             lowerCamelCase__						:							List[str]       =    self.proj_attn(__lowerCamelCase			)
             return self.dropout_layer(__lowerCamelCase   , deterministic=__lowerCamelCase			)







class      _lowercase					(				nn.Module):


       """simple docstring"""




       A__   		=     42
       A__   		=     42
       A__   		=     42
       A__   		=     0.0
       A__   		=     False
       A__   		=     jnp.floataa
       A__   		=     False





       def 		lowerCAmelCase	(  self				:     Any			):


             '''simple docstring'''



             lowerCamelCase__						:							Union[str, Any]       =    FlaxAttention(
                 self.dim   , self.n_heads   , self.d_head   , self.dropout   , self.use_memory_efficient_attention   , dtype=self.dtype			)
             # cross attention
             lowerCamelCase__						:							List[str]       =    FlaxAttention(
                 self.dim   , self.n_heads   , self.d_head   , self.dropout   , self.use_memory_efficient_attention   , dtype=self.dtype			)
             lowerCamelCase__						:							Dict       =    FlaxFeedForward(dim=self.dim   , dropout=self.dropout   , dtype=self.dtype			)
             lowerCamelCase__						:							Tuple       =    nn.LayerNorm(epsilon=1E-5   , dtype=self.dtype			)
             lowerCamelCase__						:							Union[str, Any]       =    nn.LayerNorm(epsilon=1E-5   , dtype=self.dtype			)
             lowerCamelCase__						:							Any       =    nn.LayerNorm(epsilon=1E-5   , dtype=self.dtype			)
             lowerCamelCase__						:							Dict       =    nn.Dropout(rate=self.dropout			)





       def __call__(  self				:     List[str]   , __lowerCamelCase				:     Dict   , __lowerCamelCase				:     Optional[Any]   , __lowerCamelCase				:     Any=True			):


             '''simple docstring'''



             lowerCamelCase__						:							Optional[Any]       =    hidden_states
             if self.only_cross_attention:
                   lowerCamelCase__						:							Any       =    self.attna(self.norma(__lowerCamelCase			)   , __lowerCamelCase   , deterministic=__lowerCamelCase			)
             else:
                   lowerCamelCase__						:							Union[str, Any]       =    self.attna(self.norma(__lowerCamelCase			)   , deterministic=__lowerCamelCase			)
             lowerCamelCase__						:							List[Any]       =    hidden_states + residual

             # cross attention
             lowerCamelCase__						:							str       =    hidden_states
             lowerCamelCase__						:							Optional[int]       =    self.attna(self.norma(__lowerCamelCase			)   , __lowerCamelCase   , deterministic=__lowerCamelCase			)
             lowerCamelCase__						:							Optional[Any]       =    hidden_states + residual

             # feed forward
             lowerCamelCase__						:							Union[str, Any]       =    hidden_states
             lowerCamelCase__						:							int       =    self.ff(self.norma(__lowerCamelCase			)   , deterministic=__lowerCamelCase			)
             lowerCamelCase__						:							int       =    hidden_states + residual

             return self.dropout_layer(__lowerCamelCase   , deterministic=__lowerCamelCase			)







class      _lowercase					(				nn.Module):


       """simple docstring"""




       A__   		=     42
       A__   		=     42
       A__   		=     42
       A__   		=     1
       A__   		=     0.0
       A__   		=     False
       A__   		=     False
       A__   		=     jnp.floataa
       A__   		=     False





       def 		lowerCAmelCase	(  self				:     Optional[Any]			):


             '''simple docstring'''



             lowerCamelCase__						:							Dict       =    nn.GroupNorm(num_groups=32   , epsilon=1E-5			)

             lowerCamelCase__						:							List[str]       =    self.n_heads * self.d_head
             if self.use_linear_projection:
                   lowerCamelCase__						:							int       =    nn.Dense(__lowerCamelCase   , dtype=self.dtype			)
             else:
                   lowerCamelCase__						:							List[str]       =    nn.Conv(
                       __lowerCamelCase   , kernel_size=(1, 1)   , strides=(1, 1)   , padding="VALID"   , dtype=self.dtype   , )

             lowerCamelCase__						:							Dict       =    [
                 FlaxBasicTransformerBlock(
                     __lowerCamelCase   , self.n_heads   , self.d_head   , dropout=self.dropout   , only_cross_attention=self.only_cross_attention   , dtype=self.dtype   , use_memory_efficient_attention=self.use_memory_efficient_attention   , )
                 for _ in range(self.depth			)
             ]

             if self.use_linear_projection:
                   lowerCamelCase__						:							List[str]       =    nn.Dense(__lowerCamelCase   , dtype=self.dtype			)
             else:
                   lowerCamelCase__						:							Optional[Any]       =    nn.Conv(
                       __lowerCamelCase   , kernel_size=(1, 1)   , strides=(1, 1)   , padding="VALID"   , dtype=self.dtype   , )

             lowerCamelCase__						:							List[Any]       =    nn.Dropout(rate=self.dropout			)





       def __call__(  self				:     str   , __lowerCamelCase				:     Union[str, Any]   , __lowerCamelCase				:     Any   , __lowerCamelCase				:     Optional[int]=True			):


             '''simple docstring'''



             lowerCamelCase__       ,  lowerCamelCase__       ,  lowerCamelCase__       ,  lowerCamelCase__						:							List[str]       =    hidden_states.shape
             lowerCamelCase__						:							List[str]       =    hidden_states
             lowerCamelCase__						:							int       =    self.norm(__lowerCamelCase			)
             if self.use_linear_projection:
                   lowerCamelCase__						:							Optional[Any]       =    hidden_states.reshape(__lowerCamelCase   , height * width   , __lowerCamelCase			)
                   lowerCamelCase__						:							List[str]       =    self.proj_in(__lowerCamelCase			)
             else:
                   lowerCamelCase__						:							int       =    self.proj_in(__lowerCamelCase			)
                   lowerCamelCase__						:							Optional[int]       =    hidden_states.reshape(__lowerCamelCase   , height * width   , __lowerCamelCase			)

             for transformer_block in self.transformer_blocks:
                   lowerCamelCase__						:							Dict       =    transformer_block(__lowerCamelCase   , __lowerCamelCase   , deterministic=__lowerCamelCase			)

             if self.use_linear_projection:
                   lowerCamelCase__						:							Union[str, Any]       =    self.proj_out(__lowerCamelCase			)
                   lowerCamelCase__						:							str       =    hidden_states.reshape(__lowerCamelCase   , __lowerCamelCase   , __lowerCamelCase   , __lowerCamelCase			)
             else:
                   lowerCamelCase__						:							Dict       =    hidden_states.reshape(__lowerCamelCase   , __lowerCamelCase   , __lowerCamelCase   , __lowerCamelCase			)
                   lowerCamelCase__						:							Dict       =    self.proj_out(__lowerCamelCase			)

             lowerCamelCase__						:							Tuple       =    hidden_states + residual
             return self.dropout_layer(__lowerCamelCase   , deterministic=__lowerCamelCase			)







class      _lowercase					(				nn.Module):


       """simple docstring"""




       A__   		=     42
       A__   		=     0.0
       A__   		=     jnp.floataa





       def 		lowerCAmelCase	(  self				:     str			):


             '''simple docstring'''



             lowerCamelCase__						:							Any       =    FlaxGEGLU(self.dim   , self.dropout   , self.dtype			)
             lowerCamelCase__						:							Optional[int]       =    nn.Dense(self.dim   , dtype=self.dtype			)





       def __call__(  self				:     int   , __lowerCamelCase				:     Any   , __lowerCamelCase				:     List[Any]=True			):


             '''simple docstring'''



             lowerCamelCase__						:							Optional[Any]       =    self.net_a(__lowerCamelCase   , deterministic=__lowerCamelCase			)
             lowerCamelCase__						:							str       =    self.net_a(__lowerCamelCase			)
             return hidden_states







class      _lowercase					(				nn.Module):


       """simple docstring"""




       A__   		=     42
       A__   		=     0.0
       A__   		=     jnp.floataa





       def 		lowerCAmelCase	(  self				:     List[str]			):


             '''simple docstring'''



             lowerCamelCase__						:							Any       =    self.dim * 4
             lowerCamelCase__						:							int       =    nn.Dense(inner_dim * 2   , dtype=self.dtype			)
             lowerCamelCase__						:							str       =    nn.Dropout(rate=self.dropout			)





       def __call__(  self				:     Dict   , __lowerCamelCase				:     Optional[Any]   , __lowerCamelCase				:     Dict=True			):


             '''simple docstring'''



             lowerCamelCase__						:							Any       =    self.proj(__lowerCamelCase			)
             lowerCamelCase__       ,  lowerCamelCase__						:							Union[str, Any]       =    jnp.split(__lowerCamelCase   , 2   , axis=2			)
             return self.dropout_layer(hidden_linear * nn.gelu(__lowerCamelCase			)   , deterministic=__lowerCamelCase			)






import inspect
import unittest

from transformers import ResNetConfig, is_flax_available
from transformers.testing_utils import require_flax, slow
from transformers.utils import cached_property, is_vision_available

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


if is_flax_available():
    import jax
    import jax.numpy as jnp

    from transformers.models.resnet.modeling_flax_resnet import FlaxResNetForImageClassification, FlaxResNetModel

if is_vision_available():
    from PIL import Image

    from transformers import AutoImageProcessor







class      _lowercase					(				unittest.TestCase):


       """simple docstring"""




       def __init__(  self				:     Dict   , __lowerCamelCase				:     int   , __lowerCamelCase				:     List[Any]=3   , __lowerCamelCase				:     Dict=32   , __lowerCamelCase				:     Optional[Any]=3   , __lowerCamelCase				:     List[str]=10   , __lowerCamelCase				:     List[str]=[10, 20, 30, 40]   , __lowerCamelCase				:     List[Any]=[1, 1, 2, 1]   , __lowerCamelCase				:     Any=True   , __lowerCamelCase				:     Optional[int]=True   , __lowerCamelCase				:     int="relu"   , __lowerCamelCase				:     List[str]=3   , __lowerCamelCase				:     Any=None   , ):


             '''simple docstring'''



             lowerCamelCase__						:							int       =    parent
             lowerCamelCase__						:							Optional[int]       =    batch_size
             lowerCamelCase__						:							List[Any]       =    image_size
             lowerCamelCase__						:							Union[str, Any]       =    num_channels
             lowerCamelCase__						:							Any       =    embeddings_size
             lowerCamelCase__						:							Tuple       =    hidden_sizes
             lowerCamelCase__						:							Tuple       =    depths
             lowerCamelCase__						:							List[str]       =    is_training
             lowerCamelCase__						:							Optional[Any]       =    use_labels
             lowerCamelCase__						:							str       =    hidden_act
             lowerCamelCase__						:							Any       =    num_labels
             lowerCamelCase__						:							List[str]       =    scope
             lowerCamelCase__						:							Any       =    len(__lowerCamelCase			)





       def 		lowerCAmelCase	(  self				:     List[str]			):


             '''simple docstring'''



             lowerCamelCase__						:							Any       =    floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]			)

             lowerCamelCase__						:							Any       =    self.get_config()

             return config, pixel_values





       def 		lowerCAmelCase	(  self				:     Optional[int]			):


             '''simple docstring'''



             return ResNetConfig(
                 num_channels=self.num_channels   , embeddings_size=self.embeddings_size   , hidden_sizes=self.hidden_sizes   , depths=self.depths   , hidden_act=self.hidden_act   , num_labels=self.num_labels   , image_size=self.image_size   , )





       def 		lowerCAmelCase	(  self				:     str   , __lowerCamelCase				:     List[Any]   , __lowerCamelCase				:     Tuple			):


             '''simple docstring'''



             lowerCamelCase__						:							Any       =    FlaxResNetModel(config=__lowerCamelCase			)
             lowerCamelCase__						:							str       =    model(__lowerCamelCase			)

             # Output shape (b, c, h, w)
             self.parent.assertEqual(
                 result.last_hidden_state.shape   , (self.batch_size, self.hidden_sizes[-1], self.image_size // 32, self.image_size // 32)   , )





       def 		lowerCAmelCase	(  self				:     int   , __lowerCamelCase				:     Optional[Any]   , __lowerCamelCase				:     List[str]			):


             '''simple docstring'''



             lowerCamelCase__						:							Optional[Any]       =    self.num_labels
             lowerCamelCase__						:							int       =    FlaxResNetForImageClassification(config=__lowerCamelCase			)
             lowerCamelCase__						:							Optional[int]       =    model(__lowerCamelCase			)
             self.parent.assertEqual(result.logits.shape   , (self.batch_size, self.num_labels)			)





       def 		lowerCAmelCase	(  self				:     Dict			):


             '''simple docstring'''



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







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


       """simple docstring"""




       A__   		=     (FlaxResNetModel, FlaxResNetForImageClassification) if is_flax_available() else ()

       A__   		=     False
       A__   		=     False
       A__   		=     False





       def 		lowerCAmelCase	(  self				:     List[str]			):


             '''simple docstring'''



             lowerCamelCase__						:							List[str]       =    FlaxResNetModelTester(self			)
             lowerCamelCase__						:							Dict       =    ConfigTester(self   , config_class=__lowerCamelCase   , has_text_modality=__lowerCamelCase			)





       def 		lowerCAmelCase	(  self				:     Optional[Any]			):


             '''simple docstring'''



             self.create_and_test_config_common_properties()
             self.config_tester.create_and_test_config_to_json_string()
             self.config_tester.create_and_test_config_to_json_file()
             self.config_tester.create_and_test_config_from_and_save_pretrained()
             self.config_tester.create_and_test_config_with_num_labels()
             self.config_tester.check_config_can_be_init_without_params()
             self.config_tester.check_config_arguments_init()





       def 		lowerCAmelCase	(  self				:     Dict			):


             '''simple docstring'''



             return





       def 		lowerCAmelCase	(  self				:     Dict			):


             '''simple docstring'''



             lowerCamelCase__						:							str       =    self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_model(*__lowerCamelCase			)





       def 		lowerCAmelCase	(  self				:     List[Any]			):


             '''simple docstring'''



             lowerCamelCase__						:							str       =    self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_image_classification(*__lowerCamelCase			)





       @unittest.skip(reason="ResNet does not use inputs_embeds"			)
       def 		lowerCAmelCase	(  self				:     Dict			):


             '''simple docstring'''



             pass





       @unittest.skip(reason="ResNet does not support input and output embeddings"			)
       def 		lowerCAmelCase	(  self				:     int			):


             '''simple docstring'''



             pass





       def 		lowerCAmelCase	(  self				:     Any			):


             '''simple docstring'''



             lowerCamelCase__       ,  lowerCamelCase__						:							Tuple       =    self.model_tester.prepare_config_and_inputs_for_common()

             for model_class in self.all_model_classes:
                   lowerCamelCase__						:							Tuple       =    model_class(__lowerCamelCase			)
                   lowerCamelCase__						:							Tuple       =    inspect.signature(model.__call__			)
                   # signature.parameters is an OrderedDict => so arg_names order is deterministic
                   lowerCamelCase__						:							Optional[Any]       =    [*signature.parameters.keys()]

                   lowerCamelCase__						:							List[Any]       =    ["pixel_values"]
                   self.assertListEqual(arg_names[:1]   , __lowerCamelCase			)





       def 		lowerCAmelCase	(  self				:     Any			):


             '''simple docstring'''



             def check_hidden_states_output(__lowerCamelCase				:     List[str]   , __lowerCamelCase				:     Optional[int]   , __lowerCamelCase				:     str			):
                   lowerCamelCase__						:							Any       =    model_class(__lowerCamelCase			)

                   lowerCamelCase__						:							Dict       =    model(**self._prepare_for_class(__lowerCamelCase   , __lowerCamelCase			)			)

                   lowerCamelCase__						:							str       =    outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

                   lowerCamelCase__						:							Tuple       =    self.model_tester.num_stages
                   self.assertEqual(len(__lowerCamelCase			)   , expected_num_stages + 1			)





       @unittest.skip(reason="ResNet does not use feedforward chunking"			)
       def 		lowerCAmelCase	(  self				:     Any			):


             '''simple docstring'''



             pass





       def 		lowerCAmelCase	(  self				:     int			):


             '''simple docstring'''



             lowerCamelCase__       ,  lowerCamelCase__						:							Dict       =    self.model_tester.prepare_config_and_inputs_for_common()

             for model_class in self.all_model_classes:
                   with self.subTest(model_class.__name__			):
                         lowerCamelCase__						:							Any       =    self._prepare_for_class(__lowerCamelCase   , __lowerCamelCase			)
                         lowerCamelCase__						:							Optional[int]       =    model_class(__lowerCamelCase			)

                         @jax.jit
                         def model_jitted(__lowerCamelCase				:     Optional[Any]   , **__lowerCamelCase				:     List[Any]			):
                               return model(pixel_values=__lowerCamelCase   , **__lowerCamelCase			)

                         with self.subTest("JIT Enabled"			):
                               lowerCamelCase__						:							Any       =    model_jitted(**__lowerCamelCase			).to_tuple()

                         with self.subTest("JIT Disabled"			):
                               with jax.disable_jit():
                                     lowerCamelCase__						:							Union[str, Any]       =    model_jitted(**__lowerCamelCase			).to_tuple()

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



def  lowercase_						(						):

      """simple docstring"""




      lowerCamelCase__						:							Optional[Any]       =    Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"		)
      return image







@require_flax
class      _lowercase					(				unittest.TestCase):


       """simple docstring"""




       @cached_property
       def 		lowerCAmelCase	(  self				:     Tuple			):


             '''simple docstring'''



             return AutoImageProcessor.from_pretrained("microsoft/resnet-50"			) if is_vision_available() else None





       @slow
       def 		lowerCAmelCase	(  self				:     List[str]			):


             '''simple docstring'''



             lowerCamelCase__						:							List[Any]       =    FlaxResNetForImageClassification.from_pretrained("microsoft/resnet-50"			)

             lowerCamelCase__						:							List[str]       =    self.default_image_processor
             lowerCamelCase__						:							Optional[Any]       =    prepare_img()
             lowerCamelCase__						:							str       =    image_processor(images=__lowerCamelCase   , return_tensors="np"			)

             lowerCamelCase__						:							str       =    model(**__lowerCamelCase			)

             # verify the logits
             lowerCamelCase__						:							int       =    (1, 1000)
             self.assertEqual(outputs.logits.shape   , __lowerCamelCase			)

             lowerCamelCase__						:							Optional[int]       =    jnp.array([-1_1.1_0_6_9, -9.7_8_7_7, -8.3_7_7_7]			)

             self.assertTrue(jnp.allclose(outputs.logits[0, :3]   , __lowerCamelCase   , atol=1E-4			)			)


