






import uuid
from typing import Any, Dict, List, Optional, Union

from ..utils import add_end_docstrings, is_tf_available, is_torch_available, logging
from .base import PIPELINE_INIT_ARGS, Pipeline


if is_tf_available():
						import tensorflow as tf

if is_torch_available():
						import torch


__UpperCamelCase   :   Dict      =    logging.get_logger(__name__)


class 							__UpperCamelCase     :







	def __init__(	self   :				List[str]							,					_lowerCAmelCase   :				str = None							,					_lowerCAmelCase   :				uuid.UUID = None							,					_lowerCAmelCase   :				Optional[int]=None							,					_lowerCAmelCase   :				Optional[Any]=None      )		->			List[str]:
		"""simple docstring"""







		if not conversation_id:
			__lowercase   							=	uuid.uuida()
		if past_user_inputs is None:
			__lowercase   							=	[]
		if generated_responses is None:
			__lowercase   							=	[]

		__lowercase   							=	conversation_id
		__lowercase   							=	past_user_inputs
		__lowercase   							=	generated_responses
		__lowercase   							=	text







	def __eq__(	self   :				List[str]							,					_lowerCAmelCase   :				str      )		->			List[str]:
		"""simple docstring"""







		if not isinstance(_lowerCAmelCase							,					_lowerCAmelCase      ):
			return False
		if self.uuid == other.uuid:
			return True
		return (
		    self.new_user_input == other.new_user_input
		    and self.past_user_inputs == other.past_user_inputs
		    and self.generated_responses == other.generated_responses
		)







	def 			_a (	self   :				Dict							,					_lowerCAmelCase   :				str							,					_lowerCAmelCase   :				bool = False      )		->			Tuple:
		"""simple docstring"""







		if self.new_user_input:
			if overwrite:
				logger.warning(
				    F'User input added while unprocessed input was existing: "{self.new_user_input}" was overwritten '
				    F'with: "{text}".'      )
				__lowercase   							=	text
			else:
				logger.warning(
				    F'User input added while unprocessed input was existing: "{self.new_user_input}" new input '
				    F'ignored: "{text}". Set `overwrite` to True to overwrite unprocessed user input'      )
		else:
			__lowercase   							=	text







	def 			_a (	self   :				Tuple      )		->			str:
		"""simple docstring"""







		if self.new_user_input:
			self.past_user_inputs.append(self.new_user_input      )
		__lowercase   							=	None







	def 			_a (	self   :				Dict							,					_lowerCAmelCase   :				str      )		->			List[Any]:
		"""simple docstring"""







		self.generated_responses.append(_lowerCAmelCase      )







	def 			_a (	self   :				Optional[int]      )		->			Any:
		"""simple docstring"""







		for user_input, generated_response in zip(self.past_user_inputs							,					self.generated_responses      ):
			yield True, user_input
			yield False, generated_response
		if self.new_user_input:
			yield True, self.new_user_input







	def __repr__(	self   :				Dict      )		->			Any:
		"""simple docstring"""







		__lowercase   							=	F'Conversation id: {self.uuid} \n'
		for is_user, text in self.iter_texts():
			__lowercase   							=	"""user""" if is_user else """bot"""
			output += F'{name} >> {text} \n'
		return output


@add_end_docstrings(
    _lowerCAmelCase ,      R'\n        min_length_for_response (`int`, *optional*, defaults to 32):\n            The minimum length (in number of tokens) for a response.\n        minimum_tokens (`int`, *optional*, defaults to 10):\n            The minimum length of tokens to leave for a response.\n    ' ,      )
class 							__UpperCamelCase     (  _lowerCAmelCase ):







	def __init__(	self   :				List[Any]							,					*_lowerCAmelCase   :				Tuple							,					**_lowerCAmelCase   :				Optional[Any]      )		->			str:
		"""simple docstring"""







		super().__init__(*_lowerCAmelCase							,					**_lowerCAmelCase      )
		if self.tokenizer.pad_token_id is None:
			__lowercase   							=	self.tokenizer.eos_token







	def 			_a (	self   :				Tuple							,					_lowerCAmelCase   :				Dict=None							,					_lowerCAmelCase   :				Tuple=None							,					_lowerCAmelCase   :				List[Any]=None							,					**_lowerCAmelCase   :				Dict      )		->			str:
		"""simple docstring"""







		__lowercase   							=	{}
		__lowercase   							=	{}
		__lowercase   							=	{}

		if min_length_for_response is not None:
			__lowercase   							=	min_length_for_response
		if minimum_tokens is not None:
			__lowercase   							=	minimum_tokens

		if "max_length" in generate_kwargs:
			__lowercase   							=	generate_kwargs["""max_length"""]
			# self.max_length = generate_kwargs.get("max_length", self.model.config.max_length)
		if clean_up_tokenization_spaces is not None:
			__lowercase   							=	clean_up_tokenization_spaces

		if generate_kwargs:
			forward_params.update(_lowerCAmelCase      )
		return preprocess_params, forward_params, postprocess_params







	def __call__(	self   :				Tuple							,					_lowerCAmelCase   :				Union[Conversation, List[Conversation]]							,					_lowerCAmelCase   :				str=0							,					**_lowerCAmelCase   :				Dict      )		->			Optional[int]:
		"""simple docstring"""







		__lowercase   							=	super().__call__(_lowerCAmelCase							,					num_workers=_lowerCAmelCase							,					**_lowerCAmelCase      )
		if isinstance(_lowerCAmelCase							,					_lowerCAmelCase      ) and len(_lowerCAmelCase      ) == 1:
			return outputs[0]
		return outputs







	def 			_a (	self   :				List[str]							,					_lowerCAmelCase   :				Conversation							,					_lowerCAmelCase   :				Optional[int]=32      )		->			Dict[str, Any]:
		"""simple docstring"""







		if not isinstance(_lowerCAmelCase							,					_lowerCAmelCase      ):
			raise ValueError("""ConversationalPipeline, expects Conversation as inputs"""      )
		if conversation.new_user_input is None:
			raise ValueError(
			    F'Conversation with UUID {type(conversation.uuid      )} does not contain new user input to process. '
			    """Add user inputs with the conversation's `add_user_input` method"""      )
		if hasattr(self.tokenizer							,					"""_build_conversation_input_ids"""      ):
			__lowercase   							=	self.tokenizer._build_conversation_input_ids(_lowerCAmelCase      )
		else:
			# If the tokenizer cannot handle conversations, we default to only the old version
			__lowercase   							=	self._legacy_parse_and_tokenize(_lowerCAmelCase      )

		if self.framework == "pt":
			__lowercase   							=	torch.LongTensor([input_ids]      )
		elif self.framework == "tf":
			__lowercase   							=	tf.constant([input_ids]      )
		return {"input_ids": input_ids, "conversation": conversation}







	def 			_a (	self   :				str							,					_lowerCAmelCase   :				Tuple							,					_lowerCAmelCase   :				Union[str, Any]=10							,					**_lowerCAmelCase   :				int      )		->			Dict:
		"""simple docstring"""







		__lowercase   							=	generate_kwargs.get("""max_length"""							,					self.model.config.max_length      )

		__lowercase   							=	model_inputs["""input_ids"""].shape[1]
		if max_length - minimum_tokens < n:
			logger.warning(F'Conversation input is to long ({n}), trimming it to ({max_length} - {minimum_tokens})'      )
			__lowercase   							=	max_length - minimum_tokens
			__lowercase   							=	model_inputs["""input_ids"""][:, -trim:]
			if "attention_mask" in model_inputs:
				__lowercase   							=	model_inputs["""attention_mask"""][:, -trim:]
		__lowercase   							=	model_inputs.pop("""conversation"""      )
		__lowercase   							=	max_length
		__lowercase   							=	self.model.generate(**_lowerCAmelCase							,					**_lowerCAmelCase      )
		if self.model.config.is_encoder_decoder:
			__lowercase   							=	1
		else:
			__lowercase   							=	n
		return {"output_ids": output_ids[:, start_position:], "conversation": conversation}







	def 			_a (	self   :				Optional[Any]							,					_lowerCAmelCase   :				Any							,					_lowerCAmelCase   :				Optional[int]=True      )		->			List[Any]:
		"""simple docstring"""







		__lowercase   							=	model_outputs["""output_ids"""]
		__lowercase   							=	self.tokenizer.decode(
		    output_ids[0]							,					skip_special_tokens=_lowerCAmelCase							,					clean_up_tokenization_spaces=_lowerCAmelCase							,					)
		__lowercase   							=	model_outputs["""conversation"""]
		conversation.mark_processed()
		conversation.append_response(_lowerCAmelCase      )
		return conversation







	def 			_a (	self   :				Optional[int]							,					_lowerCAmelCase   :				Conversation      )		->			Dict:
		"""simple docstring"""







		__lowercase   							=	self.tokenizer.eos_token_id
		__lowercase   							=	[]
		for is_user, text in conversation.iter_texts():
			if eos_token_id is not None:
				input_ids.extend(self.tokenizer.encode(_lowerCAmelCase							,					add_special_tokens=_lowerCAmelCase      ) + [eos_token_id]      )
			else:
				input_ids.extend(self.tokenizer.encode(_lowerCAmelCase							,					add_special_tokens=_lowerCAmelCase      )      )

		if len(_lowerCAmelCase      ) > self.tokenizer.model_max_length:
			__lowercase   							=	input_ids[-self.tokenizer.model_max_length :]
		return input_ids






import inspect
import unittest
from typing import List

import numpy as np

from transformers import EfficientFormerConfig
from transformers.testing_utils import require_tf, require_vision, slow
from transformers.utils import cached_property, is_tf_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
	import tensorflow as tf

	from transformers import (
	    TFEfficientFormerForImageClassification,
	    TFEfficientFormerForImageClassificationWithTeacher,
	    TFEfficientFormerModel,
	)
	from transformers.models.efficientformer.modeling_tf_efficientformer import (
	    TF_EFFICIENTFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
	)


if is_vision_available():
	from PIL import Image

	from transformers import EfficientFormerImageProcessor


class 	__snake_case   :
		def __init__(							self    ,a_    ,a_ = 13    ,a_ = 64    ,a_ = 2    ,a_ = 3    ,a_ = 3    ,a_ = True    ,a_ = True    ,a_ = 128    ,a_=[16, 32, 64, 128]    ,a_ = 7    ,a_ = 4    ,a_ = 37    ,a_ = "gelu"    ,a_ = 0.1    ,a_ = 0.1    ,a_ = 10    ,a_ = 0.02    ,a_ = 2    ,a_ = 1    ,a_ = 128    ,a_ = [2, 2, 2, 2]    ,a_ = 2    ,a_ = 2    ,):







						"""simple docstring"""
						lowerCAmelCase__		  =  parent
						lowerCAmelCase__		  =  batch_size
						lowerCAmelCase__		  =  image_size
						lowerCAmelCase__		  =  patch_size
						lowerCAmelCase__		  =  num_channels
						lowerCAmelCase__		  =  is_training
						lowerCAmelCase__		  =  use_labels
						lowerCAmelCase__		  =  hidden_size
						lowerCAmelCase__		  =  num_hidden_layers
						lowerCAmelCase__		  =  num_attention_heads
						lowerCAmelCase__		  =  intermediate_size
						lowerCAmelCase__		  =  hidden_act
						lowerCAmelCase__		  =  hidden_dropout_prob
						lowerCAmelCase__		  =  attention_probs_dropout_prob
						lowerCAmelCase__		  =  type_sequence_label_size
						lowerCAmelCase__		  =  initializer_range
						lowerCAmelCase__		  =  encoder_stride
						lowerCAmelCase__		  =  num_attention_outputs
						lowerCAmelCase__		  =  embed_dim
						lowerCAmelCase__		  =  embed_dim + 1
						lowerCAmelCase__		  =  resolution
						lowerCAmelCase__		  =  depths
						lowerCAmelCase__		  =  hidden_sizes
						lowerCAmelCase__		  =  dim
						lowerCAmelCase__		  =  mlp_expansion_ratio
		def 						SCREAMING_SNAKE_CASE_					(							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.type_sequence_label_size						)

						lowerCAmelCase__		  =  self.get_config()

						return config, pixel_values, labels
		def 						SCREAMING_SNAKE_CASE_					(							self						):







						"""simple docstring"""
						return EfficientFormerConfig(
						    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=a_    ,initializer_range=self.initializer_range    ,encoder_stride=self.encoder_stride    ,resolution=self.resolution    ,depths=self.depths    ,hidden_sizes=self.hidden_sizes    ,dim=self.dim    ,mlp_expansion_ratio=self.mlp_expansion_ratio    ,)
		def 						SCREAMING_SNAKE_CASE_					(							self    ,a_    ,a_    ,a_						):







						"""simple docstring"""
						lowerCAmelCase__		  =  TFEfficientFormerModel(config=a_						)
						lowerCAmelCase__		  =  model(a_    ,training=a_						)
						self.parent.assertEqual(result.last_hidden_state.shape    ,(self.batch_size, self.seq_length, self.hidden_size)						)
		def 						SCREAMING_SNAKE_CASE_					(							self    ,a_    ,a_    ,a_						):







						"""simple docstring"""
						lowerCAmelCase__		  =  self.type_sequence_label_size
						lowerCAmelCase__		  =  TFEfficientFormerForImageClassification(a_						)
						lowerCAmelCase__		  =  model(a_    ,labels=a_    ,training=a_						)
						self.parent.assertEqual(result.logits.shape    ,(self.batch_size, self.type_sequence_label_size)						)

						# test greyscale images
						lowerCAmelCase__		  =  1
						lowerCAmelCase__		  =  TFEfficientFormerForImageClassification(a_						)

						lowerCAmelCase__		  =  floats_tensor([self.batch_size, 1, self.image_size, self.image_size]						)
						lowerCAmelCase__		  =  model(a_    ,labels=a_						)
						self.parent.assertEqual(result.logits.shape    ,(self.batch_size, self.type_sequence_label_size)						)



		def 						SCREAMING_SNAKE_CASE_					(							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_tf
class 	__snake_case   ( SCREAMING_SNAKE_CASE							, SCREAMING_SNAKE_CASE							, unittest.TestCase ):
		SCREAMING_SNAKE_CASE__								=	(
		    (
		        TFEfficientFormerModel,
		        TFEfficientFormerForImageClassificationWithTeacher,
		        TFEfficientFormerForImageClassification,
		    )
		    if is_tf_available()
		    else ()
		)
		SCREAMING_SNAKE_CASE__								=	(
		    {
		        'feature-extraction': TFEfficientFormerModel,
		        'image-classification': (
		            TFEfficientFormerForImageClassification,
		            TFEfficientFormerForImageClassificationWithTeacher,
		        ),
		    }
		    if is_tf_available()
		    else {}
		)

		SCREAMING_SNAKE_CASE__								=	False

		SCREAMING_SNAKE_CASE__								=	False
		SCREAMING_SNAKE_CASE__								=	False
		SCREAMING_SNAKE_CASE__								=	False
		SCREAMING_SNAKE_CASE__								=	False
		def 						SCREAMING_SNAKE_CASE_					(							self						):







						"""simple docstring"""
						lowerCAmelCase__		  =  TFEfficientFormerModelTester(self						)
						lowerCAmelCase__		  =  ConfigTester(
						    self    ,config_class=a_    ,has_text_modality=a_    ,hidden_size=37						)
		def 						SCREAMING_SNAKE_CASE_					(							self						):







						"""simple docstring"""
						self.config_tester.run_common_tests()
		@unittest.skip(reason='EfficientFormer does not use inputs_embeds'						)
		def 						SCREAMING_SNAKE_CASE_					(							self						):







						"""simple docstring"""
						pass
		@unittest.skip(reason='EfficientFormer does not support input and output embeddings'						)
		def 						SCREAMING_SNAKE_CASE_					(							self						):







						"""simple docstring"""
						pass
		def 						SCREAMING_SNAKE_CASE_					(							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(a_						)
										lowerCAmelCase__		  =  inspect.signature(model.call						)
										# signature.parameters is an OrderedDict => so arg_names order is deterministic
										lowerCAmelCase__		  =  [*signature.parameters.keys()]

										lowerCAmelCase__		  =  ['pixel_values']
										self.assertListEqual(arg_names[:1]    ,a_						)
		def 						SCREAMING_SNAKE_CASE_					(							self						):







						"""simple docstring"""
						def check_hidden_states_output(a_    ,a_    ,a_						):
										lowerCAmelCase__		  =  model_class(a_						)

										lowerCAmelCase__		  =  model(**self._prepare_for_class(a_    ,a_						)    ,training=a_						)
										lowerCAmelCase__		  =  outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

										lowerCAmelCase__		  =  getattr(
										    self.model_tester    ,'expected_num_hidden_layers'    ,self.model_tester.num_hidden_layers + 1						)
										self.assertEqual(len(a_						)    ,a_						)

										if hasattr(self.model_tester    ,'encoder_seq_length'						):
														lowerCAmelCase__		  =  self.model_tester.encoder_seq_length
														if hasattr(self.model_tester    ,'chunk_length'						) and self.model_tester.chunk_length > 1:
																		lowerCAmelCase__		  =  seq_length * self.model_tester.chunk_length
										else:
														lowerCAmelCase__		  =  self.model_tester.seq_length

										self.assertListEqual(
										    list(hidden_states[-1].shape[-2:]						)    ,[seq_length, self.model_tester.hidden_size]    ,)

										if config.is_encoder_decoder:
														lowerCAmelCase__		  =  outputs.decoder_hidden_states

														self.asseretIsInstance(a_    ,(list, tuple)						)
														self.assertEqual(len(a_						)    ,a_						)
														lowerCAmelCase__		  =  getattr(self.model_tester    ,'seq_length'    ,a_						)
														lowerCAmelCase__		  =  getattr(self.model_tester    ,'decoder_seq_length'    ,a_						)

														self.assertListEqual(
														    list(hidden_states[-1].shape[-2:]						)    ,[decoder_seq_length, self.model_tester.hidden_size]    ,)

						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(a_    ,a_    ,a_						)

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

										check_hidden_states_output(a_    ,a_    ,a_						)
		def 						SCREAMING_SNAKE_CASE_					(							self    ,a_    ,a_    ,a_=False						):







						"""simple docstring"""
						lowerCAmelCase__		  =  super()._prepare_for_class(a_    ,a_    ,return_labels=a_						)

						if return_labels:
										if model_class.__name__ == "TFEfficientFormerForImageClassificationWithTeacher":
														del inputs_dict["labels"]

						return inputs_dict
		def 						SCREAMING_SNAKE_CASE_					(							self						):







						"""simple docstring"""
						lowerCAmelCase__		  =  self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_model(*a_						)
		@unittest.skip(reason='EfficientFormer does not implement masked image modeling yet'						)
		def 						SCREAMING_SNAKE_CASE_					(							self						):







						"""simple docstring"""
						lowerCAmelCase__		  =  self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_masked_image_modeling(*a_						)
		def 						SCREAMING_SNAKE_CASE_					(							self						):







						"""simple docstring"""
						lowerCAmelCase__		  =  self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_image_classification(*a_						)
		@slow
		def 						SCREAMING_SNAKE_CASE_					(							self						):







						"""simple docstring"""
						for model_name in TF_EFFICIENTFORMER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
										lowerCAmelCase__		  =  TFEfficientFormerModel.from_pretrained(a_						)
										self.assertIsNotNone(a_						)
		def 						SCREAMING_SNAKE_CASE_					(							self						):







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

						lowerCAmelCase__		  =  getattr(self.model_tester    ,'seq_length'    ,a_						)
						lowerCAmelCase__		  =  getattr(self.model_tester    ,'encoder_seq_length'    ,a_						)
						lowerCAmelCase__		  =  getattr(self.model_tester    ,'key_length'    ,a_						)
						lowerCAmelCase__		  =  getattr(self.model_tester    ,'chunk_length'    ,a_						)

						if chunk_length is not None and hasattr(self.model_tester    ,'num_hashes'						):
										lowerCAmelCase__		  =  encoder_seq_length * self.model_tester.num_hashes

						for model_class in self.all_model_classes:
										lowerCAmelCase__		  =  True
										lowerCAmelCase__		  =  False
										lowerCAmelCase__		  =  True
										lowerCAmelCase__		  =  model_class(a_						)

										lowerCAmelCase__		  =  model(**self._prepare_for_class(a_    ,a_						)    ,training=a_						)
										lowerCAmelCase__		  =  outputs.encoder_attentions if config.is_encoder_decoder else outputs.attentions
										self.assertEqual(len(a_						)    ,self.model_tester.num_attention_outputs						)

										# check that output_attentions also work using config
										del inputs_dict["output_attentions"]
										lowerCAmelCase__		  =  True
										lowerCAmelCase__		  =  model_class(a_						)
										lowerCAmelCase__		  =  model(**self._prepare_for_class(a_    ,a_						)    ,training=a_						)

										lowerCAmelCase__		  =  outputs.encoder_attentions if config.is_encoder_decoder else outputs.attentions
										self.assertEqual(len(a_						)    ,self.model_tester.num_attention_outputs						)

										if chunk_length is not None:
														self.assertListEqual(
														    list(attentions[0].shape[-4:]						)    ,[self.model_tester.num_attention_heads, encoder_seq_length, chunk_length, encoder_key_length]    ,)
										else:
														self.assertListEqual(
														    list(attentions[0].shape[-3:]						)    ,[self.model_tester.num_attention_heads, encoder_seq_length, encoder_key_length]    ,)



		def 						SCREAMING_SNAKE_CASE_					(							self						):







						"""simple docstring"""
						# We use a simplified version of this test for EfficientFormer because it requires training=False
						# and Keras refuses to let us force that during functional construction
						lowerCAmelCase__  ,   lowerCAmelCase__		  =  self.model_tester.prepare_config_and_inputs_for_common()

						for model_class in self.all_model_classes:
										# Prepare our model
										lowerCAmelCase__		  =  model_class(a_						)
										# These are maximally general inputs for the model, with multiple None dimensions
										# Hopefully this will catch any conditionals that fail for flexible shapes
										lowerCAmelCase__		  =  {
										    key: tf.keras.Input(shape=val.shape[1:]    ,dtype=val.dtype    ,name=a_						)
										    for key, val in model.input_signature.items()
										    if key in model.dummy_inputs
										}
										lowerCAmelCase__		  =  model(a_						)
										self.assertTrue(outputs_dict is not None						)







def     UpperCAmelCase_		(					)	->     List[str]:



				"""simple docstring"""





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


@require_tf
@require_vision
class 	__snake_case   ( unittest.TestCase ):
		@cached_property
		def 						SCREAMING_SNAKE_CASE_					(							self						):







						"""simple docstring"""
						return (
						    EfficientFormerImageProcessor.from_pretrained('snap-research/efficientformer-l1-300'						)
						    if is_vision_available()
						    else None
						)
		@slow
		def 						SCREAMING_SNAKE_CASE_					(							self						):







						"""simple docstring"""
						lowerCAmelCase__		  =  TFEfficientFormerForImageClassification.from_pretrained('snap-research/efficientformer-l1-300'						)
						lowerCAmelCase__		  =  self.default_image_processor
						lowerCAmelCase__		  =  prepare_img()
						lowerCAmelCase__		  =  image_processor(images=a_    ,return_tensors='tf'						)
						# forward pass
						lowerCAmelCase__		  =  model(**a_    ,training=a_						)
						# verify the logits
						lowerCAmelCase__		  =  tf.TensorShape((1, 1000)						)
						self.assertEqual(outputs.logits.shape    ,a_						)
						lowerCAmelCase__		  =  tf.constant([-0.0555, 0.4825, -0.0852]						)
						self.assertTrue(np.allclose(outputs.logits[0, :3]    ,a_    ,atol=1e-4						)						)



		@slow
		def 						SCREAMING_SNAKE_CASE_					(							self						):







						"""simple docstring"""
						lowerCAmelCase__		  =  TFEfficientFormerForImageClassificationWithTeacher.from_pretrained(
						    'snap-research/efficientformer-l1-300'						)
						lowerCAmelCase__		  =  self.default_image_processor
						lowerCAmelCase__		  =  prepare_img()
						lowerCAmelCase__		  =  image_processor(images=a_    ,return_tensors='tf'						)
						# forward pass
						lowerCAmelCase__		  =  model(**a_    ,training=a_						)
						# verify the logits
						lowerCAmelCase__		  =  tf.TensorShape((1, 1000)						)
						self.assertEqual(outputs.logits.shape    ,a_						)
						lowerCAmelCase__		  =  tf.constant([-0.1312, 0.4353, -1.0499]						)
						self.assertTrue(np.allclose(outputs.logits[0, :3]    ,a_    ,atol=1e-4						)						)
