






from typing import Optional, Tuple

import flax.linen as nn
import jax
import jax.numpy as jnp
from configuration_hybrid_clip import HybridCLIPConfig
from flax.core.frozen_dict import FrozenDict

from transformers import FLAX_MODEL_MAPPING, FlaxCLIPVisionModel
from transformers.modeling_flax_utils import FlaxPreTrainedModel
from transformers.models.clip.modeling_flax_clip import FlaxCLIPOutput
from transformers.utils import logging


__snake_case			:			Optional[Any]			   =   logging.get_logger(__name__)


class 			__SCREAMING_SNAKE_CASE    (      nn.Module):
						_SCREAMING_SNAKE_CASE		:				HybridCLIPConfig
						_SCREAMING_SNAKE_CASE		:				jnp.dtype            =    jnp.floataa






						def 					UpperCamelCase__					(		self      ):






												"""simple docstring"""
												lowerCAmelCase__			  =  self.config.text_config
												lowerCAmelCase__			  =  self.config.vision_config

												lowerCAmelCase__			  =  self.config.projection_dim
												lowerCAmelCase__			  =  text_config.hidden_size
												lowerCAmelCase__			  =  vision_config.hidden_size

												lowerCAmelCase__			  =  FLAX_MODEL_MAPPING[self.config.text_config.__class__].module_class
												lowerCAmelCase__			  =  FLAX_MODEL_MAPPING.get(self.config.vision_config.__class__   ,  _UpperCamelCase      ).module_class

												lowerCAmelCase__			  =  text_module(_UpperCamelCase   ,  dtype=self.dtype      )
												lowerCAmelCase__			  =  vision_module(_UpperCamelCase   ,  dtype=self.dtype      )

												lowerCAmelCase__			  =  nn.Dense(
												    self.projection_dim   ,  dtype=self.dtype   ,  kernel_init=jax.nn.initializers.normal(0.02      )   ,  use_bias=_UpperCamelCase   ,  )
												lowerCAmelCase__			  =  nn.Dense(
												    self.projection_dim   ,  dtype=self.dtype   ,  kernel_init=jax.nn.initializers.normal(0.02      )   ,  use_bias=_UpperCamelCase   ,  )
												lowerCAmelCase__			  =  self.param('logit_scale'   ,  jax.nn.initializers.ones   ,  []      )







						def __call__(		self   ,  _UpperCamelCase=None   ,  _UpperCamelCase=None   ,  _UpperCamelCase=None   ,  _UpperCamelCase=None   ,  _UpperCamelCase=None   ,  _UpperCamelCase = True   ,  _UpperCamelCase=None   ,  _UpperCamelCase=None   ,  _UpperCamelCase=None   ,  ):






												"""simple docstring"""
												lowerCAmelCase__			  =  return_dict if return_dict is not None else self.config.return_dict

												lowerCAmelCase__			  =  self.vision_model(
												    pixel_values=_UpperCamelCase   ,  deterministic=_UpperCamelCase   ,  output_attentions=_UpperCamelCase   ,  output_hidden_states=_UpperCamelCase   ,  return_dict=_UpperCamelCase   ,  )

												lowerCAmelCase__			  =  self.text_model(
												    input_ids=_UpperCamelCase   ,  attention_mask=_UpperCamelCase   ,  token_type_ids=_UpperCamelCase   ,  position_ids=_UpperCamelCase   ,  deterministic=_UpperCamelCase   ,  output_attentions=_UpperCamelCase   ,  output_hidden_states=_UpperCamelCase   ,  return_dict=_UpperCamelCase   ,  )

												lowerCAmelCase__			  =  vision_outputs[1]
												lowerCAmelCase__			  =  self.visual_projection(_UpperCamelCase      )

												lowerCAmelCase__			  =  text_outputs[1]
												lowerCAmelCase__			  =  self.text_projection(_UpperCamelCase      )

												# normalized features
												lowerCAmelCase__			  =  image_embeds / jnp.linalg.norm(_UpperCamelCase   ,  axis=-1   ,  keepdims=_UpperCamelCase      )
												lowerCAmelCase__			  =  text_embeds / jnp.linalg.norm(_UpperCamelCase   ,  axis=-1   ,  keepdims=_UpperCamelCase      )

												# cosine similarity as logits
												lowerCAmelCase__			  =  jnp.exp(self.logit_scale      )
												lowerCAmelCase__			  =  jnp.matmul(_UpperCamelCase   ,  image_embeds.T      ) * logit_scale
												lowerCAmelCase__			  =  logits_per_text.T

												if not return_dict:
																		return (logits_per_image, logits_per_text, text_embeds, image_embeds, text_outputs, vision_outputs)

												return FlaxCLIPOutput(
												    logits_per_image=_UpperCamelCase   ,  logits_per_text=_UpperCamelCase   ,  text_embeds=_UpperCamelCase   ,  image_embeds=_UpperCamelCase   ,  text_model_output=_UpperCamelCase   ,  vision_model_output=_UpperCamelCase   ,  )




class 			__SCREAMING_SNAKE_CASE    (      __lowercase):
						_SCREAMING_SNAKE_CASE		:				Any            =    HybridCLIPConfig
						_SCREAMING_SNAKE_CASE		:				int            =    FlaxHybridCLIPModule






						def __init__(		self   ,  _UpperCamelCase   ,  _UpperCamelCase = None   ,  _UpperCamelCase = 0   ,  _UpperCamelCase = jnp.floataa   ,  **_UpperCamelCase   ,  ):






												"""simple docstring"""
												if input_shape is None:
																		lowerCAmelCase__			  =  ((1, 1), (1, config.vision_config.image_size, config.vision_config.image_size, 3))

												lowerCAmelCase__			  =  self.module_class(config=_UpperCamelCase   ,  dtype=_UpperCamelCase   ,  **_UpperCamelCase      )
												super().__init__(_UpperCamelCase   ,  _UpperCamelCase   ,  input_shape=_UpperCamelCase   ,  seed=_UpperCamelCase   ,  dtype=_UpperCamelCase      )






						def 					UpperCamelCase__					(		self   ,  _UpperCamelCase   ,  _UpperCamelCase   ,  _UpperCamelCase = None      ):






												"""simple docstring"""
												# init input tensor
												lowerCAmelCase__			  =  jnp.zeros(input_shape[0]   ,  dtype='i4'      )
												lowerCAmelCase__			  =  jnp.broadcast_to(jnp.arange(jnp.atleast_ad(_UpperCamelCase      ).shape[-1]      )   ,  input_shape[0]      )
												lowerCAmelCase__			  =  jnp.ones_like(_UpperCamelCase      )
												lowerCAmelCase__			  =  jnp.ones_like(_UpperCamelCase      )

												lowerCAmelCase__			  =  jax.random.normal(_UpperCamelCase   ,  input_shape[1]      )

												lowerCAmelCase__  ,				lowerCAmelCase__			  =  jax.random.split(_UpperCamelCase      )
												lowerCAmelCase__			  =  {'params': params_rng, 'dropout': dropout_rng}

												return self.module.init(_UpperCamelCase   ,  _UpperCamelCase   ,  _UpperCamelCase   ,  _UpperCamelCase   ,  _UpperCamelCase   ,  _UpperCamelCase      )["params"]






						def __call__(		self   ,  _UpperCamelCase   ,  _UpperCamelCase   ,  _UpperCamelCase=None   ,  _UpperCamelCase=None   ,  _UpperCamelCase=None   ,  _UpperCamelCase = None   ,  _UpperCamelCase = None   ,  _UpperCamelCase = False   ,  _UpperCamelCase = None   ,  _UpperCamelCase = None   ,  _UpperCamelCase = None   ,  ):






												"""simple docstring"""
												lowerCAmelCase__			  =  output_attentions if output_attentions is not None else self.config.output_attentions
												lowerCAmelCase__			  =  (
												    output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
												)
												lowerCAmelCase__			  =  return_dict if return_dict is not None else self.config.return_dict

												if position_ids is None:
																		lowerCAmelCase__			  =  jnp.broadcast_to(jnp.arange(jnp.atleast_ad(_UpperCamelCase      ).shape[-1]      )   ,  input_ids.shape      )

												if token_type_ids is None:
																		lowerCAmelCase__			  =  jnp.zeros_like(_UpperCamelCase      )

												if attention_mask is None:
																		lowerCAmelCase__			  =  jnp.ones_like(_UpperCamelCase      )

												# Handle any PRNG if needed
												lowerCAmelCase__			  =  {}
												if dropout_rng is not None:
																		lowerCAmelCase__			  =  dropout_rng

												return self.module.apply(
												    {'params': params or self.params}   ,  jnp.array(_UpperCamelCase   ,  dtype='i4'      )   ,  jnp.array(_UpperCamelCase   ,  dtype=jnp.floataa      )   ,  jnp.array(_UpperCamelCase   ,  dtype='i4'      )   ,  jnp.array(_UpperCamelCase   ,  dtype='i4'      )   ,  jnp.array(_UpperCamelCase   ,  dtype='i4'      )   ,  not train   ,  _UpperCamelCase   ,  _UpperCamelCase   ,  _UpperCamelCase   ,  rngs=_UpperCamelCase   ,  )






						def 					UpperCamelCase__					(		self   ,  _UpperCamelCase   ,  _UpperCamelCase=None   ,  _UpperCamelCase=None   ,  _UpperCamelCase=None   ,  _UpperCamelCase = None   ,  _UpperCamelCase = None   ,  _UpperCamelCase=False   ,  ):






												"""simple docstring"""
												if position_ids is None:
																		lowerCAmelCase__			  =  jnp.broadcast_to(jnp.arange(jnp.atleast_ad(_UpperCamelCase      ).shape[-1]      )   ,  input_ids.shape      )

												if token_type_ids is None:
																		lowerCAmelCase__			  =  jnp.zeros_like(_UpperCamelCase      )

												if attention_mask is None:
																		lowerCAmelCase__			  =  jnp.ones_like(_UpperCamelCase      )

												# Handle any PRNG if needed
												lowerCAmelCase__			  =  {}
												if dropout_rng is not None:
																		lowerCAmelCase__			  =  dropout_rng

												def _get_features(_UpperCamelCase   ,  _UpperCamelCase   ,  _UpperCamelCase   ,  _UpperCamelCase   ,  _UpperCamelCase   ,  _UpperCamelCase      ):
																		lowerCAmelCase__			  =  module.text_model(
																		    input_ids=_UpperCamelCase   ,  attention_mask=_UpperCamelCase   ,  position_ids=_UpperCamelCase   ,  token_type_ids=_UpperCamelCase   ,  deterministic=_UpperCamelCase   ,  )
																		lowerCAmelCase__			  =  text_outputs[1]
																		lowerCAmelCase__			  =  module.text_projection(_UpperCamelCase      )
																		return text_features

												return self.module.apply(
												    {'params': params or self.params}   ,  jnp.array(_UpperCamelCase   ,  dtype='i4'      )   ,  jnp.array(_UpperCamelCase   ,  dtype='i4'      )   ,  jnp.array(_UpperCamelCase   ,  dtype='i4'      )   ,  jnp.array(_UpperCamelCase   ,  dtype='i4'      )   ,  not train   ,  method=_get_features   ,  rngs=_UpperCamelCase   ,  )






						def 					UpperCamelCase__					(		self   ,  _UpperCamelCase   ,  _UpperCamelCase = None   ,  _UpperCamelCase = None   ,  _UpperCamelCase=False      ):






												"""simple docstring"""
												lowerCAmelCase__			  =  {}
												if dropout_rng is not None:
																		lowerCAmelCase__			  =  dropout_rng

												def _get_features(_UpperCamelCase   ,  _UpperCamelCase   ,  _UpperCamelCase      ):
																		lowerCAmelCase__			  =  module.vision_model(pixel_values=_UpperCamelCase   ,  deterministic=_UpperCamelCase      )
																		lowerCAmelCase__			  =  vision_outputs[1]  # pooled_output
																		lowerCAmelCase__			  =  module.visual_projection(_UpperCamelCase      )
																		return image_features

												return self.module.apply(
												    {'params': params or self.params}   ,  jnp.array(_UpperCamelCase   ,  dtype=jnp.floataa      )   ,  not train   ,  method=_get_features   ,  rngs=_UpperCamelCase   ,  )







						@classmethod
						def 					UpperCamelCase__					(		cls   ,  _UpperCamelCase = None   ,  _UpperCamelCase = None   ,  *_UpperCamelCase   ,  **_UpperCamelCase   ,  ):






												"""simple docstring"""
												lowerCAmelCase__			  =  {
												    argument[len('text_'      ) :]: value for argument, value in kwargs.items() if argument.startswith('text_'      )
												}

												lowerCAmelCase__			  =  {
												    argument[len('vision_'      ) :]: value for argument, value in kwargs.items() if argument.startswith('vision_'      )
												}

												# remove text, vision kwargs from kwargs
												for key in kwargs_text.keys():
																		del kwargs["text_" + key]
												for key in kwargs_vision.keys():
																		del kwargs["vision_" + key]

												# Load and initialize the text and vision model
												lowerCAmelCase__			  =  kwargs_text.pop('model'   ,  _UpperCamelCase      )
												if text_model is None:
																		assert (
																		    text_model_name_or_path is not None
																		), "If `model` is not defined as an argument, a `text_model_name_or_path` has to be defined"
																		from transformers import FlaxAutoModel

																		if "config" not in kwargs_text:
																								from transformers import AutoConfig

																								lowerCAmelCase__			  =  AutoConfig.from_pretrained(_UpperCamelCase      )
																								lowerCAmelCase__			  =  text_config

																		lowerCAmelCase__			  =  FlaxAutoModel.from_pretrained(_UpperCamelCase   ,  *_UpperCamelCase   ,  **_UpperCamelCase      )

												lowerCAmelCase__			  =  kwargs_vision.pop('model'   ,  _UpperCamelCase      )
												if vision_model is None:
																		assert (
																		    vision_model_name_or_path is not None
																		), "If `model` is not defined as an argument, a `vision_model_name_or_path` has to be defined"
																		from transformers import FlaxAutoModel

																		if "config" not in kwargs_vision:
																								from transformers import AutoConfig

																								lowerCAmelCase__			  =  AutoConfig.from_pretrained(_UpperCamelCase      )
																								lowerCAmelCase__			  =  vision_config

																		lowerCAmelCase__			  =  FlaxAutoModel.from_pretrained(_UpperCamelCase   ,  *_UpperCamelCase   ,  **_UpperCamelCase      )

												# instantiate config with corresponding kwargs
												lowerCAmelCase__			  =  kwargs.pop('dtype'   ,  jnp.floataa      )
												lowerCAmelCase__			  =  HybridCLIPConfig.from_text_vision_configs(text_model.config   ,  vision_model.config   ,  **_UpperCamelCase      )

												# init model
												lowerCAmelCase__			  =  cls(_UpperCamelCase   ,  *_UpperCamelCase   ,  dtype=_UpperCamelCase   ,  **_UpperCamelCase      )

												if vision_config.model_type == "clip":
																		lowerCAmelCase__			  =  vision_model.params['vision_model']
																		lowerCAmelCase__			  =  vision_model.params['visual_projection']['kernel']
												else:
																		lowerCAmelCase__			  =  vision_model.params

												lowerCAmelCase__			  =  text_model.params

												return model













import inspect
import unittest

from transformers import is_torch_available, is_vision_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, slow, torch_device

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 MODEL_MAPPING, PoolFormerConfig, PoolFormerForImageClassification, PoolFormerModel
					from transformers.models.poolformer.modeling_poolformer import POOLFORMER_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
					from PIL import Image

					from transformers import PoolFormerImageProcessor


class 			__SCREAMING_SNAKE_CASE    (      __lowercase):






						def 					UpperCamelCase__					(		self      ):






												"""simple docstring"""
												lowerCAmelCase__			  =  self.config_class(**self.inputs_dict      )
												self.parent.assertTrue(hasattr(_UpperCamelCase   ,  'hidden_sizes'      )      )
												self.parent.assertTrue(hasattr(_UpperCamelCase   ,  'num_encoder_blocks'      )      )




class 			__SCREAMING_SNAKE_CASE    :






						def __init__(		self   ,  _UpperCamelCase   ,  _UpperCamelCase=13   ,  _UpperCamelCase=64   ,  _UpperCamelCase=3   ,  _UpperCamelCase=4   ,  _UpperCamelCase=[2, 2, 2, 2]   ,  _UpperCamelCase=[8, 4, 2, 1]   ,  _UpperCamelCase=[16, 32, 64, 1_28]   ,  _UpperCamelCase=[1, 4, 8, 16]   ,  _UpperCamelCase=False   ,  _UpperCamelCase=True   ,  _UpperCamelCase="gelu"   ,  _UpperCamelCase=0.1   ,  _UpperCamelCase=0.02   ,  _UpperCamelCase=3   ,  _UpperCamelCase=None   ,  ):






												"""simple docstring"""
												lowerCAmelCase__			  =  parent
												lowerCAmelCase__			  =  batch_size
												lowerCAmelCase__			  =  image_size
												lowerCAmelCase__			  =  num_channels
												lowerCAmelCase__			  =  num_encoder_blocks
												lowerCAmelCase__			  =  sr_ratios
												lowerCAmelCase__			  =  depths
												lowerCAmelCase__			  =  hidden_sizes
												lowerCAmelCase__			  =  downsampling_rates
												lowerCAmelCase__			  =  is_training
												lowerCAmelCase__			  =  use_labels
												lowerCAmelCase__			  =  hidden_act
												lowerCAmelCase__			  =  hidden_dropout_prob
												lowerCAmelCase__			  =  initializer_range
												lowerCAmelCase__			  =  num_labels
												lowerCAmelCase__			  =  scope






						def 					UpperCamelCase__					(		self      ):






												"""simple docstring"""
												lowerCAmelCase__			  =  floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]      )

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

												lowerCAmelCase__			  =  PoolFormerConfig(
												    image_size=self.image_size   ,  num_channels=self.num_channels   ,  num_encoder_blocks=self.num_encoder_blocks   ,  depths=self.depths   ,  hidden_sizes=self.hidden_sizes   ,  hidden_act=self.hidden_act   ,  hidden_dropout_prob=self.hidden_dropout_prob   ,  initializer_range=self.initializer_range   ,  )

												return config, pixel_values, labels






						def 					UpperCamelCase__					(		self   ,  _UpperCamelCase   ,  _UpperCamelCase   ,  _UpperCamelCase      ):






												"""simple docstring"""
												lowerCAmelCase__			  =  PoolFormerModel(config=_UpperCamelCase      )
												model.to(_UpperCamelCase      )
												model.eval()
												lowerCAmelCase__			  =  model(_UpperCamelCase      )
												lowerCAmelCase__			  =  lowerCAmelCase__			  =  self.image_size // 32.0
												self.parent.assertEqual(
												    result.last_hidden_state.shape   ,  (self.batch_size, self.hidden_sizes[-1], expected_height, expected_width)      )







						def 					UpperCamelCase__					(		self      ):






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




@require_torch
class 			__SCREAMING_SNAKE_CASE    (      __lowercase						,    __lowercase						,    unittest.TestCase):
						_SCREAMING_SNAKE_CASE		:				List[Any]            =    (PoolFormerModel, PoolFormerForImageClassification) if is_torch_available() else ()
						_SCREAMING_SNAKE_CASE		:				Optional[int]            =    (
						    {'''feature-extraction''': PoolFormerModel, '''image-classification''': PoolFormerForImageClassification}
						    if is_torch_available()
						    else {}
						)

						_SCREAMING_SNAKE_CASE		:				List[str]            =    False
						_SCREAMING_SNAKE_CASE		:				Optional[int]            =    False
						_SCREAMING_SNAKE_CASE		:				Optional[Any]            =    False
						_SCREAMING_SNAKE_CASE		:				str            =    False
						_SCREAMING_SNAKE_CASE		:				List[Any]            =    False






						def 					UpperCamelCase__					(		self      ):






												"""simple docstring"""
												lowerCAmelCase__			  =  PoolFormerModelTester(self      )
												lowerCAmelCase__			  =  PoolFormerConfigTester(self   ,  config_class=_UpperCamelCase      )






						def 					UpperCamelCase__					(		self      ):






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






						def 					UpperCamelCase__					(		self      ):






												"""simple docstring"""
												lowerCAmelCase__			  =  self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_model(*_UpperCamelCase      )






						@unittest.skip('PoolFormer does not use inputs_embeds'      )
						def 					UpperCamelCase__					(		self      ):






												"""simple docstring"""
												pass






						@unittest.skip('PoolFormer does not have get_input_embeddings method and get_output_embeddings methods'      )
						def 					UpperCamelCase__					(		self      ):






												"""simple docstring"""
												pass






						def 					UpperCamelCase__					(		self      ):






												"""simple docstring"""
												def check_hidden_states_output(_UpperCamelCase   ,  _UpperCamelCase   ,  _UpperCamelCase      ):
																		lowerCAmelCase__			  =  model_class(_UpperCamelCase      )
																		model.to(_UpperCamelCase      )
																		model.eval()

																		with torch.no_grad():
																								lowerCAmelCase__			  =  model(**self._prepare_for_class(_UpperCamelCase   ,  _UpperCamelCase      )      )

																		lowerCAmelCase__			  =  outputs.hidden_states

																		lowerCAmelCase__			  =  self.model_tester.num_encoder_blocks
																		self.assertEqual(len(_UpperCamelCase      )   ,  _UpperCamelCase      )

																		# verify the first hidden states (first block)
																		self.assertListEqual(
																		    list(hidden_states[0].shape[-3:]      )   ,  [
																		        self.model_tester.hidden_sizes[0],
																		        self.model_tester.image_size // 4,
																		        self.model_tester.image_size // 4,
																		    ]   ,  )

												lowerCAmelCase__  ,				lowerCAmelCase__			  =  self.model_tester.prepare_config_and_inputs_for_common()

												for model_class in self.all_model_classes:
																		lowerCAmelCase__			  =  True
																		check_hidden_states_output(_UpperCamelCase   ,  _UpperCamelCase   ,  _UpperCamelCase      )

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

																		check_hidden_states_output(_UpperCamelCase   ,  _UpperCamelCase   ,  _UpperCamelCase      )






						def 					UpperCamelCase__					(		self      ):






												"""simple docstring"""
												if not self.model_tester.is_training:
																		return

												lowerCAmelCase__  ,				lowerCAmelCase__			  =  self.model_tester.prepare_config_and_inputs_for_common()
												lowerCAmelCase__			  =  True

												for model_class in self.all_model_classes:
																		if model_class in get_values(_UpperCamelCase      ):
																								continue
																		lowerCAmelCase__			  =  model_class(_UpperCamelCase      )
																		model.to(_UpperCamelCase      )
																		model.train()
																		lowerCAmelCase__			  =  self._prepare_for_class(_UpperCamelCase   ,  _UpperCamelCase   ,  return_labels=_UpperCamelCase      )
																		lowerCAmelCase__			  =  model(**_UpperCamelCase      ).loss
																		loss.backward()






						def 					UpperCamelCase__					(		self      ):






												"""simple docstring"""
												lowerCAmelCase__  ,				lowerCAmelCase__			  =  self.model_tester.prepare_config_and_inputs_for_common()

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

																		lowerCAmelCase__			  =  ['pixel_values']
																		self.assertListEqual(arg_names[:1]   ,  _UpperCamelCase      )







						@slow
						def 					UpperCamelCase__					(		self      ):






												"""simple docstring"""
												for model_name in POOLFORMER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																		lowerCAmelCase__			  =  PoolFormerModel.from_pretrained(_UpperCamelCase      )
																		self.assertIsNotNone(_UpperCamelCase      )







def 		_UpperCamelCase      (			)     ->      Optional[int]:

						"""simple docstring"""



						lowerCAmelCase__			  =  Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'						)
						return image


@require_torch
class 			__SCREAMING_SNAKE_CASE    (      unittest.TestCase):






						@slow
						def 					UpperCamelCase__					(		self      ):






												"""simple docstring"""
												lowerCAmelCase__			  =  PoolFormerImageProcessor()
												lowerCAmelCase__			  =  PoolFormerForImageClassification.from_pretrained('sail/poolformer_s12'      ).to(_UpperCamelCase      )

												lowerCAmelCase__			  =  image_processor(images=prepare_img()   ,  return_tensors='pt'      ).to(_UpperCamelCase      )

												# forward pass
												with torch.no_grad():
																		lowerCAmelCase__			  =  model(**_UpperCamelCase      )

												# verify the logits
												lowerCAmelCase__			  =  torch.Size((1, 10_00)      )
												self.assertEqual(outputs.logits.shape   ,  _UpperCamelCase      )

												lowerCAmelCase__			  =  torch.tensor([-0.61_13, 0.16_85, -0.04_92]      ).to(_UpperCamelCase      )
												self.assertTrue(torch.allclose(outputs.logits[0, :3]   ,  _UpperCamelCase   ,  atol=1E-4      )      )





