



'''simple docstring'''




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__ :			int												=				logging.get_logger(__name__)






class 		_UpperCamelCase						:


			'''simple docstring'''

			def __init__(							self  :				Dict							,  lowerCAmelCase__  :				str = None							,  lowerCAmelCase__  :				uuid.UUID = None							,  lowerCAmelCase__  :				int=None							,  lowerCAmelCase__  :				int=None		):





					"""simple docstring"""






					if not conversation_id:
							__SCREAMING_SNAKE_CASE :	int					 =	uuid.uuida()
					if past_user_inputs is None:
							__SCREAMING_SNAKE_CASE :	Optional[Any]					 =	[]
					if generated_responses is None:
							__SCREAMING_SNAKE_CASE :	List[str]					 =	[]

					__SCREAMING_SNAKE_CASE :	uuid.UUID					 =	conversation_id
					__SCREAMING_SNAKE_CASE :	List[str]					 =	past_user_inputs
					__SCREAMING_SNAKE_CASE :	List[str]					 =	generated_responses
					__SCREAMING_SNAKE_CASE :	Optional[str]					 =	text

			def __eq__(							self  :				List[str]							,  lowerCAmelCase__  :				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 UpperCamelCase__      (							self  :				Optional[Any]							,  lowerCAmelCase__  :				str							,  lowerCAmelCase__  :				bool = False		):





					"""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}\"."		)
									__SCREAMING_SNAKE_CASE :	Optional[Any]					 =	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:
							__SCREAMING_SNAKE_CASE :	str					 =	text

			def UpperCamelCase__      (							self  :				int		):





					"""simple docstring"""






					if self.new_user_input:
							self.past_user_inputs.append(self.new_user_input		)
					__SCREAMING_SNAKE_CASE :	str					 =	None

			def UpperCamelCase__      (							self  :				List[str]							,  lowerCAmelCase__  :				str		):





					"""simple docstring"""






					self.generated_responses.append(lowerCAmelCase__		)

			def UpperCamelCase__      (							self  :				Dict		):





					"""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  :				int		):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE :	List[str]					 =	F"Conversation id: {self.uuid} \n"
					for is_user, text in self.iter_texts():
							__SCREAMING_SNAKE_CASE :	Union[str, Any]					 =	"""user""" if is_user else """bot"""
							output += F"{name} >> {text} \n"
					return output






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


			'''simple docstring'''

			def __init__(							self  :				Dict							,  *lowerCAmelCase__  :				Union[str, Any]							,  **lowerCAmelCase__  :				str		):





					"""simple docstring"""






					super().__init__(*lowerCAmelCase__							,  **lowerCAmelCase__		)
					if self.tokenizer.pad_token_id is None:
							__SCREAMING_SNAKE_CASE :	Tuple					 =	self.tokenizer.eos_token

			def UpperCamelCase__      (							self  :				Optional[int]							,  lowerCAmelCase__  :				Tuple=None							,  lowerCAmelCase__  :				Any=None							,  lowerCAmelCase__  :				Dict=None							,  **lowerCAmelCase__  :				Union[str, Any]		):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE :	Tuple					 =	{}
					__SCREAMING_SNAKE_CASE :	Tuple					 =	{}
					__SCREAMING_SNAKE_CASE :	List[str]					 =	{}

					if min_length_for_response is not None:
							__SCREAMING_SNAKE_CASE :	int					 =	min_length_for_response
					if minimum_tokens is not None:
							__SCREAMING_SNAKE_CASE :	List[Any]					 =	minimum_tokens

					if "max_length" in generate_kwargs:
							__SCREAMING_SNAKE_CASE :	Tuple					 =	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:
							__SCREAMING_SNAKE_CASE :	str					 =	clean_up_tokenization_spaces

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

			def __call__(							self  :				Union[str, Any]							,  lowerCAmelCase__  :				Union[Conversation, List[Conversation]]							,  lowerCAmelCase__  :				Optional[Any]=0							,  **lowerCAmelCase__  :				List[Any]		):





					"""simple docstring"""






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

			def UpperCamelCase__      (							self  :				List[Any]							,  lowerCAmelCase__  :				Conversation							,  lowerCAmelCase__  :				str=3_2		):





					"""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"""		):
							__SCREAMING_SNAKE_CASE :	Optional[int]					 =	self.tokenizer._build_conversation_input_ids(lowerCAmelCase__		)
					else:
							# If the tokenizer cannot handle conversations, we default to only the old version
							__SCREAMING_SNAKE_CASE :	Any					 =	self._legacy_parse_and_tokenize(lowerCAmelCase__		)

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

			def UpperCamelCase__      (							self  :				List[Any]							,  lowerCAmelCase__  :				int							,  lowerCAmelCase__  :				Tuple=1_0							,  **lowerCAmelCase__  :				Union[str, Any]		):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE :	List[Any]					 =	generate_kwargs.get("""max_length"""							,  self.model.config.max_length		)

					__SCREAMING_SNAKE_CASE :	Any					 =	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})"		)
							__SCREAMING_SNAKE_CASE :	Tuple					 =	max_length - minimum_tokens
							__SCREAMING_SNAKE_CASE :	Any					 =	model_inputs["""input_ids"""][:, -trim:]
							if "attention_mask" in model_inputs:
									__SCREAMING_SNAKE_CASE :	List[str]					 =	model_inputs["""attention_mask"""][:, -trim:]
					__SCREAMING_SNAKE_CASE :	Optional[int]					 =	model_inputs.pop("""conversation"""		)
					__SCREAMING_SNAKE_CASE :	Optional[int]					 =	max_length
					__SCREAMING_SNAKE_CASE :	Union[str, Any]					 =	self.model.generate(**lowerCAmelCase__							,  **lowerCAmelCase__		)
					if self.model.config.is_encoder_decoder:
							__SCREAMING_SNAKE_CASE :	Union[str, Any]					 =	1
					else:
							__SCREAMING_SNAKE_CASE :	Tuple					 =	n
					return {"output_ids": output_ids[:, start_position:], "conversation": conversation}

			def UpperCamelCase__      (							self  :				Optional[int]							,  lowerCAmelCase__  :				Optional[Any]							,  lowerCAmelCase__  :				int=True		):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE :	Optional[int]					 =	model_outputs["""output_ids"""]
					__SCREAMING_SNAKE_CASE :	str					 =	self.tokenizer.decode(
					    output_ids[0]							,  skip_special_tokens=lowerCAmelCase__							,  clean_up_tokenization_spaces=lowerCAmelCase__							,  )
					__SCREAMING_SNAKE_CASE :	Union[str, Any]					 =	model_outputs["""conversation"""]
					conversation.mark_processed()
					conversation.append_response(lowerCAmelCase__		)
					return conversation



			def UpperCamelCase__      (							self  :				str							,  lowerCAmelCase__  :				Conversation		):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE :	int					 =	self.tokenizer.eos_token_id
					__SCREAMING_SNAKE_CASE :	Any					 =	[]
					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:
							__SCREAMING_SNAKE_CASE :	Any					 =	input_ids[-self.tokenizer.model_max_length :]
					return input_ids




'''simple docstring'''




import inspect
import unittest
from math import floor

from transformers import CvtConfig
from transformers.file_utils import cached_property, is_torch_available, is_vision_available
from transformers.testing_utils import require_torch, require_vision, 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 CvtForImageClassification, CvtModel
						from transformers.models.cvt.modeling_cvt import CVT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
						from PIL import Image

						from transformers import AutoImageProcessor






class 		_UpperCamelCase						(							lowerCamelCase__					):


			'''simple docstring'''

			def UpperCamelCase__      (							self  :				Any		):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE :	int					 =	self.config_class(**self.inputs_dict		)
					self.parent.assertTrue(hasattr(lowerCAmelCase__							,  """embed_dim"""		)		)
					self.parent.assertTrue(hasattr(lowerCAmelCase__							,  """num_heads"""		)		)






class 		_UpperCamelCase						:


			'''simple docstring'''

			def __init__(							self  :				str							,  lowerCAmelCase__  :				int							,  lowerCAmelCase__  :				int=1_3							,  lowerCAmelCase__  :				Union[str, Any]=6_4							,  lowerCAmelCase__  :				Optional[Any]=3							,  lowerCAmelCase__  :				str=[1_6, 4_8, 9_6]							,  lowerCAmelCase__  :				Any=[1, 3, 6]							,  lowerCAmelCase__  :				Any=[1, 2, 1_0]							,  lowerCAmelCase__  :				Union[str, Any]=[7, 3, 3]							,  lowerCAmelCase__  :				Tuple=[4, 2, 2]							,  lowerCAmelCase__  :				Union[str, Any]=[2, 1, 1]							,  lowerCAmelCase__  :				Dict=[2, 2, 2]							,  lowerCAmelCase__  :				Optional[int]=[False, False, True]							,  lowerCAmelCase__  :				List[Any]=[0.0, 0.0, 0.0]							,  lowerCAmelCase__  :				List[Any]=0.02							,  lowerCAmelCase__  :				List[str]=1E-12							,  lowerCAmelCase__  :				Any=True							,  lowerCAmelCase__  :				Union[str, Any]=True							,  lowerCAmelCase__  :				Optional[Any]=2							,  ):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE :	int					 =	parent
					__SCREAMING_SNAKE_CASE :	Optional[Any]					 =	batch_size
					__SCREAMING_SNAKE_CASE :	List[Any]					 =	image_size
					__SCREAMING_SNAKE_CASE :	Any					 =	patch_sizes
					__SCREAMING_SNAKE_CASE :	List[Any]					 =	patch_stride
					__SCREAMING_SNAKE_CASE :	List[Any]					 =	patch_padding
					__SCREAMING_SNAKE_CASE :	Union[str, Any]					 =	is_training
					__SCREAMING_SNAKE_CASE :	Dict					 =	use_labels
					__SCREAMING_SNAKE_CASE :	int					 =	num_labels
					__SCREAMING_SNAKE_CASE :	Optional[int]					 =	num_channels
					__SCREAMING_SNAKE_CASE :	List[str]					 =	embed_dim
					__SCREAMING_SNAKE_CASE :	Optional[Any]					 =	num_heads
					__SCREAMING_SNAKE_CASE :	Optional[int]					 =	stride_kv
					__SCREAMING_SNAKE_CASE :	Union[str, Any]					 =	depth
					__SCREAMING_SNAKE_CASE :	Optional[Any]					 =	cls_token
					__SCREAMING_SNAKE_CASE :	List[Any]					 =	attention_drop_rate
					__SCREAMING_SNAKE_CASE :	str					 =	initializer_range
					__SCREAMING_SNAKE_CASE :	List[Any]					 =	layer_norm_eps

			def UpperCamelCase__      (							self  :				Dict		):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE :	Union[str, Any]					 =	floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]		)

					__SCREAMING_SNAKE_CASE :	Dict					 =	None
					if self.use_labels:
							__SCREAMING_SNAKE_CASE :	int					 =	ids_tensor([self.batch_size]							,  self.num_labels		)

					__SCREAMING_SNAKE_CASE :	Any					 =	self.get_config()
					return config, pixel_values, labels

			def UpperCamelCase__      (							self  :				str		):





					"""simple docstring"""






					return CvtConfig(
					    image_size=self.image_size							,  num_labels=self.num_labels							,  num_channels=self.num_channels							,  embed_dim=self.embed_dim							,  num_heads=self.num_heads							,  patch_sizes=self.patch_sizes							,  patch_padding=self.patch_padding							,  patch_stride=self.patch_stride							,  stride_kv=self.stride_kv							,  depth=self.depth							,  cls_token=self.cls_token							,  attention_drop_rate=self.attention_drop_rate							,  initializer_range=self.initializer_range							,  )

			def UpperCamelCase__      (							self  :				Union[str, Any]							,  lowerCAmelCase__  :				int							,  lowerCAmelCase__  :				str							,  lowerCAmelCase__  :				Optional[int]		):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE :	Union[str, Any]					 =	CvtModel(config=lowerCAmelCase__		)
					model.to(lowerCAmelCase__		)
					model.eval()
					__SCREAMING_SNAKE_CASE :	int					 =	model(lowerCAmelCase__		)
					__SCREAMING_SNAKE_CASE :	Optional[Any]					 =	(self.image_size, self.image_size)
					__SCREAMING_SNAKE_CASE ,		__SCREAMING_SNAKE_CASE :	Optional[int]					 =	image_size[0], image_size[1]
					for i in range(len(self.depth		)		):
							__SCREAMING_SNAKE_CASE :	Optional[Any]					 =	floor(((height + 2 * self.patch_padding[i] - self.patch_sizes[i]) / self.patch_stride[i]) + 1		)
							__SCREAMING_SNAKE_CASE :	Any					 =	floor(((width + 2 * self.patch_padding[i] - self.patch_sizes[i]) / self.patch_stride[i]) + 1		)
					self.parent.assertEqual(result.last_hidden_state.shape							,  (self.batch_size, self.embed_dim[-1], height, width)		)

			def UpperCamelCase__      (							self  :				int							,  lowerCAmelCase__  :				str							,  lowerCAmelCase__  :				Tuple							,  lowerCAmelCase__  :				Any		):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE :	Union[str, Any]					 =	self.num_labels
					__SCREAMING_SNAKE_CASE :	Optional[int]					 =	CvtForImageClassification(lowerCAmelCase__		)
					model.to(lowerCAmelCase__		)
					model.eval()
					__SCREAMING_SNAKE_CASE :	str					 =	model(lowerCAmelCase__							,  labels=lowerCAmelCase__		)
					self.parent.assertEqual(result.logits.shape							,  (self.batch_size, self.num_labels)		)



			def UpperCamelCase__      (							self  :				Tuple		):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE :	Optional[Any]					 =	self.prepare_config_and_inputs()
					__SCREAMING_SNAKE_CASE ,		__SCREAMING_SNAKE_CASE ,		__SCREAMING_SNAKE_CASE :	Any					 =	config_and_inputs
					__SCREAMING_SNAKE_CASE :	Optional[Any]					 =	{"""pixel_values""": pixel_values}
					return config, inputs_dict






@require_torch
class 		_UpperCamelCase						(							lowerCamelCase__					,      lowerCamelCase__					,      unittest.TestCase					):


			'''simple docstring'''

			_A   :	Optional[int]    					=	(CvtModel, CvtForImageClassification) if is_torch_available() else ()
			_A   :	Optional[Any]    					=	(
			    {'''feature-extraction''': CvtModel, '''image-classification''': CvtForImageClassification}
			    if is_torch_available()
			    else {}
			)

			_A   :	Dict    					=	False
			_A   :	Union[str, Any]    					=	False
			_A   :	str    					=	False
			_A   :	List[str]    					=	False
			_A   :	Optional[int]    					=	False

			def UpperCamelCase__      (							self  :				Dict		):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE :	str					 =	CvtModelTester(self		)
					__SCREAMING_SNAKE_CASE :	Optional[Any]					 =	ConfigTester(self							,  config_class=lowerCAmelCase__							,  has_text_modality=lowerCAmelCase__							,  hidden_size=3_7		)

			def UpperCamelCase__      (							self  :				Union[str, 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 UpperCamelCase__      (							self  :				Dict		):





					"""simple docstring"""






					return

			@unittest.skip(reason="""Cvt does not output attentions"""		)
			def UpperCamelCase__      (							self  :				str		):





					"""simple docstring"""






					pass

			@unittest.skip(reason="""Cvt does not use inputs_embeds"""		)
			def UpperCamelCase__      (							self  :				Union[str, Any]		):





					"""simple docstring"""






					pass

			@unittest.skip(reason="""Cvt does not support input and output embeddings"""		)
			def UpperCamelCase__      (							self  :				Optional[Any]		):





					"""simple docstring"""






					pass

			def UpperCamelCase__      (							self  :				Dict		):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE ,		__SCREAMING_SNAKE_CASE :	Optional[int]					 =	self.model_tester.prepare_config_and_inputs_for_common()

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

							__SCREAMING_SNAKE_CASE :	str					 =	["""pixel_values"""]
							self.assertListEqual(arg_names[:1]							,  lowerCAmelCase__		)

			def UpperCamelCase__      (							self  :				List[Any]		):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE :	Tuple					 =	self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_model(*lowerCAmelCase__		)

			def UpperCamelCase__      (							self  :				Dict		):





					"""simple docstring"""






					def check_hidden_states_output(lowerCAmelCase__  :				Any							,  lowerCAmelCase__  :				Any							,  lowerCAmelCase__  :				Union[str, Any]		):
							__SCREAMING_SNAKE_CASE :	List[str]					 =	model_class(lowerCAmelCase__		)
							model.to(lowerCAmelCase__		)
							model.eval()

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

							__SCREAMING_SNAKE_CASE :	Optional[int]					 =	outputs.hidden_states

							__SCREAMING_SNAKE_CASE :	Optional[Any]					 =	len(self.model_tester.depth		)
							self.assertEqual(len(lowerCAmelCase__		)							,  lowerCAmelCase__		)

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

					__SCREAMING_SNAKE_CASE ,		__SCREAMING_SNAKE_CASE :	Optional[int]					 =	self.model_tester.prepare_config_and_inputs_for_common()

					for model_class in self.all_model_classes:
							__SCREAMING_SNAKE_CASE :	List[Any]					 =	True
							check_hidden_states_output(lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__		)

							# check that output_hidden_states also work using config
							del inputs_dict["output_hidden_states"]
							__SCREAMING_SNAKE_CASE :	Optional[Any]					 =	True

							check_hidden_states_output(lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__		)

			def UpperCamelCase__      (							self  :				Optional[int]		):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE :	str					 =	self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_image_classification(*lowerCAmelCase__		)

			@unittest.skip("""Will be fixed soon by reducing the size of the model used for common tests."""		)
			def UpperCamelCase__      (							self  :				Tuple		):





					"""simple docstring"""






					pass



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





					"""simple docstring"""






					for model_name in CVT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
							__SCREAMING_SNAKE_CASE :	Optional[Any]					 =	CvtModel.from_pretrained(lowerCAmelCase__		)
							self.assertIsNotNone(lowerCAmelCase__		)


def        lowerCAmelCase_     (			):
		__SCREAMING_SNAKE_CASE :	str					 =	Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""      )
		return image






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


			'''simple docstring'''

			@cached_property
			def UpperCamelCase__      (							self  :				List[Any]		):





					"""simple docstring"""






					return AutoImageProcessor.from_pretrained(CVT_PRETRAINED_MODEL_ARCHIVE_LIST[0]		)



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





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE :	int					 =	CvtForImageClassification.from_pretrained(CVT_PRETRAINED_MODEL_ARCHIVE_LIST[0]		).to(lowerCAmelCase__		)

					__SCREAMING_SNAKE_CASE :	List[Any]					 =	self.default_image_processor
					__SCREAMING_SNAKE_CASE :	List[Any]					 =	prepare_img()
					__SCREAMING_SNAKE_CASE :	int					 =	image_processor(images=lowerCAmelCase__							,  return_tensors="""pt"""		).to(lowerCAmelCase__		)

					# forward pass
					with torch.no_grad():
							__SCREAMING_SNAKE_CASE :	Optional[int]					 =	model(**lowerCAmelCase__		)

					# verify the logits
					__SCREAMING_SNAKE_CASE :	str					 =	torch.Size((1, 1_0_0_0)		)
					self.assertEqual(outputs.logits.shape							,  lowerCAmelCase__		)

					__SCREAMING_SNAKE_CASE :	Optional[Any]					 =	torch.tensor([0.92_85, 0.90_15, -0.31_50]		).to(lowerCAmelCase__		)

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