



"""simple docstring"""






from __future__ import annotations

import collections
import tempfile
import unittest

import numpy as np

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

from ...test_modeling_tf_common import floats_tensor, ids_tensor, random_attention_mask
from ..bert.test_modeling_tf_bert import TFBertModelTester
from ..clip.test_modeling_tf_clip import TFCLIPVisionModelTester
from ..deit.test_modeling_tf_deit import TFDeiTModelTester
from ..roberta.test_modeling_tf_roberta import TFRobertaModelTester
from ..vit.test_modeling_tf_vit import TFViTModelTester


if is_tf_available():
	from transformers import (
	    TFBertModel,
	    TFCLIPVisionModel,
	    TFDeiTModel,
	    TFRobertaModel,
	    TFVisionTextDualEncoderModel,
	    TFViTModel,
	    VisionTextDualEncoderConfig,
	)

if is_vision_available():
	from PIL import Image

	from transformers import VisionTextDualEncoderProcessor


def     _lowercase       (						__snake_case			)		->     Optional[int]:







			if isinstance(__snake_case      ,collections.abc.Iterable			):
						return x
			return (x, x)



@require_tf
class     A__     :




	'''simple docstring'''





	def 							_SCREAMING_SNAKE_CASE     (  self:	List[Any] ,    _SCREAMING_SNAKE_CASE:	str ,    _SCREAMING_SNAKE_CASE:	Optional[Any])       -> Union[str, Any]:

				"""simple docstring"""

				pass

	def 							_SCREAMING_SNAKE_CASE     (  self:	Dict)       -> Optional[int]:

				"""simple docstring"""

				pass

	def 							_SCREAMING_SNAKE_CASE     (  self:	Any)       -> Optional[Any]:

				"""simple docstring"""

				pass

	def 							_SCREAMING_SNAKE_CASE     (  self:	int ,    _SCREAMING_SNAKE_CASE:	Optional[int] ,    _SCREAMING_SNAKE_CASE:	Any ,    _SCREAMING_SNAKE_CASE:	Any ,    _SCREAMING_SNAKE_CASE:	Optional[Any] ,    _SCREAMING_SNAKE_CASE:	Dict=None ,    **_SCREAMING_SNAKE_CASE:	int)       -> str:

				"""simple docstring"""

				__lowerCAmelCase   :						int				= VisionTextDualEncoderConfig.from_vision_text_configs(_lowerCAmelCase ,    _lowerCAmelCase)

				__lowerCAmelCase   :						Any				= TFVisionTextDualEncoderModel(_lowerCAmelCase)

				__lowerCAmelCase   :						Any				= model(input_ids=_lowerCAmelCase ,    pixel_values=_lowerCAmelCase ,    attention_mask=_lowerCAmelCase)

				self.assertEqual(output["text_embeds"].shape ,    (input_ids.shape[0], config.projection_dim))
				self.assertEqual(output["image_embeds"].shape ,    (pixel_values.shape[0], config.projection_dim))

	def 							_SCREAMING_SNAKE_CASE     (  self:	str ,    _SCREAMING_SNAKE_CASE:	Tuple ,    _SCREAMING_SNAKE_CASE:	str ,    _SCREAMING_SNAKE_CASE:	List[Any] ,    _SCREAMING_SNAKE_CASE:	List[str] ,    _SCREAMING_SNAKE_CASE:	int=None ,    **_SCREAMING_SNAKE_CASE:	Dict)       -> Tuple:

				"""simple docstring"""

				__lowerCAmelCase		,			__lowerCAmelCase   :						List[str]				= self.get_vision_text_model(_lowerCAmelCase ,    _lowerCAmelCase)
				__lowerCAmelCase   :						Union[str, Any]				= TFVisionTextDualEncoderModel(vision_model=_lowerCAmelCase ,    text_model=_lowerCAmelCase)

				__lowerCAmelCase   :						Optional[int]				= model(input_ids=_lowerCAmelCase ,    pixel_values=_lowerCAmelCase ,    attention_mask=_lowerCAmelCase)

				self.assertEqual(output["text_embeds"].shape ,    (input_ids.shape[0], model.config.projection_dim))
				self.assertEqual(output["image_embeds"].shape ,    (pixel_values.shape[0], model.config.projection_dim))

	def 							_SCREAMING_SNAKE_CASE     (  self:	Optional[Any] ,    _SCREAMING_SNAKE_CASE:	List[Any] ,    _SCREAMING_SNAKE_CASE:	Any ,    _SCREAMING_SNAKE_CASE:	Dict ,    _SCREAMING_SNAKE_CASE:	str ,    _SCREAMING_SNAKE_CASE:	Any=None ,    **_SCREAMING_SNAKE_CASE:	str)       -> Tuple:

				"""simple docstring"""

				__lowerCAmelCase		,			__lowerCAmelCase   :						Union[str, Any]				= self.get_vision_text_model(_lowerCAmelCase ,    _lowerCAmelCase)
				__lowerCAmelCase   :						Any				= {"vision_model": vision_model, "text_model": text_model}
				__lowerCAmelCase   :						List[Any]				= TFVisionTextDualEncoderModel.from_vision_text_pretrained(**_lowerCAmelCase)

				__lowerCAmelCase   :						List[str]				= model(input_ids=_lowerCAmelCase ,    pixel_values=_lowerCAmelCase ,    attention_mask=_lowerCAmelCase)

				self.assertEqual(output["text_embeds"].shape ,    (input_ids.shape[0], model.config.projection_dim))
				self.assertEqual(output["image_embeds"].shape ,    (pixel_values.shape[0], model.config.projection_dim))

	def 							_SCREAMING_SNAKE_CASE     (  self:	Dict ,    _SCREAMING_SNAKE_CASE:	Union[str, Any] ,    _SCREAMING_SNAKE_CASE:	List[str] ,    _SCREAMING_SNAKE_CASE:	Tuple ,    _SCREAMING_SNAKE_CASE:	Optional[int] ,    _SCREAMING_SNAKE_CASE:	List[Any]=None ,    **_SCREAMING_SNAKE_CASE:	Any)       -> Optional[int]:

				"""simple docstring"""

				__lowerCAmelCase		,			__lowerCAmelCase   :						Optional[Any]				= self.get_vision_text_model(_lowerCAmelCase ,    _lowerCAmelCase)
				__lowerCAmelCase   :						str				= TFVisionTextDualEncoderModel(vision_model=_lowerCAmelCase ,    text_model=_lowerCAmelCase)

				__lowerCAmelCase   :						List[Any]				= model(input_ids=_lowerCAmelCase ,    pixel_values=_lowerCAmelCase ,    attention_mask=_lowerCAmelCase)
				__lowerCAmelCase   :						str				= output[0].numpy()

				with tempfile.TemporaryDirectory() as tmpdirname:
							model.save_pretrained(_lowerCAmelCase)
							__lowerCAmelCase   :						Optional[int]				= TFVisionTextDualEncoderModel.from_pretrained(_lowerCAmelCase)

							__lowerCAmelCase   :						Optional[int]				= model(input_ids=_lowerCAmelCase ,    pixel_values=_lowerCAmelCase ,    attention_mask=_lowerCAmelCase)
							__lowerCAmelCase   :						Any				= after_output[0].numpy()
							__lowerCAmelCase   :						Optional[Any]				= np.amax(np.abs(out_a - out_a))
							self.assertLessEqual(_lowerCAmelCase ,    1e-5)

	def 							_SCREAMING_SNAKE_CASE     (  self:	int ,    _SCREAMING_SNAKE_CASE:	Any ,    _SCREAMING_SNAKE_CASE:	Optional[int] ,    _SCREAMING_SNAKE_CASE:	str ,    _SCREAMING_SNAKE_CASE:	Optional[int] ,    _SCREAMING_SNAKE_CASE:	Optional[int]=None ,    **_SCREAMING_SNAKE_CASE:	Optional[int])       -> List[Any]:

				"""simple docstring"""

				__lowerCAmelCase		,			__lowerCAmelCase   :						str				= self.get_vision_text_model(_lowerCAmelCase ,    _lowerCAmelCase)
				__lowerCAmelCase   :						str				= TFVisionTextDualEncoderModel(vision_model=_lowerCAmelCase ,    text_model=_lowerCAmelCase)

				__lowerCAmelCase   :						str				= model(
				    input_ids=_lowerCAmelCase ,    pixel_values=_lowerCAmelCase ,    attention_mask=_lowerCAmelCase ,    output_attentions=_lowerCAmelCase)

				__lowerCAmelCase   :						Dict				= output.vision_model_output.attentions
				self.assertEqual(len(_lowerCAmelCase) ,    vision_config.num_hidden_layers)

				# in ViT, the seq_len equals the number of patches + 1 (we add 1 for the [CLS] token)
				__lowerCAmelCase   :						Optional[Any]				= to_atuple(vision_model.config.image_size)
				__lowerCAmelCase   :						Union[str, Any]				= to_atuple(vision_model.config.patch_size)
				__lowerCAmelCase   :						Union[str, Any]				= (image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])
				__lowerCAmelCase   :						str				= num_patches + 1
				self.assertEqual(vision_attentions[0].shape[-3:] ,    (vision_config.num_attention_heads, seq_len, seq_len))

				__lowerCAmelCase   :						List[str]				= output.text_model_output.attentions
				self.assertEqual(len(_lowerCAmelCase) ,    text_config.num_hidden_layers)

				self.assertEqual(
				    text_attentions[0].shape[-3:] ,    (text_config.num_attention_heads, input_ids.shape[-1], input_ids.shape[-1]) ,    )

	def 							_SCREAMING_SNAKE_CASE     (  self:	List[Any] ,    _SCREAMING_SNAKE_CASE:	np.ndarray ,    _SCREAMING_SNAKE_CASE:	np.ndarray ,    _SCREAMING_SNAKE_CASE:	float)       -> Optional[int]:

				"""simple docstring"""

				__lowerCAmelCase   :						int				= np.abs((a - b)).max()
				self.assertLessEqual(_lowerCAmelCase ,    _lowerCAmelCase ,    F"""Difference between torch and flax is {diff} (>= {tol}).""")

	def 							_SCREAMING_SNAKE_CASE     (  self:	List[Any])       -> List[Any]:

				"""simple docstring"""

				__lowerCAmelCase   :						Union[str, Any]				= self.prepare_config_and_inputs()
				self.check_vision_text_dual_encoder_model(**_lowerCAmelCase)

	def 							_SCREAMING_SNAKE_CASE     (  self:	int)       -> List[Any]:

				"""simple docstring"""

				__lowerCAmelCase   :						Tuple				= self.prepare_config_and_inputs()
				self.check_model_from_pretrained_configs(**_lowerCAmelCase)

	def 							_SCREAMING_SNAKE_CASE     (  self:	Union[str, Any])       -> int:

				"""simple docstring"""

				__lowerCAmelCase   :						Tuple				= self.prepare_config_and_inputs()
				self.check_vision_text_dual_encoder_from_pretrained(**_lowerCAmelCase)

	def 							_SCREAMING_SNAKE_CASE     (  self:	List[str])       -> str:

				"""simple docstring"""

				__lowerCAmelCase   :						Any				= self.prepare_config_and_inputs()
				self.check_save_load(**_lowerCAmelCase)

	def 							_SCREAMING_SNAKE_CASE     (  self:	Dict)       -> Union[str, Any]:

				"""simple docstring"""

				__lowerCAmelCase   :						str				= self.prepare_config_and_inputs()
				self.check_vision_text_output_attention(**_lowerCAmelCase)







	@slow
	def 							_SCREAMING_SNAKE_CASE     (  self:	Optional[int])       -> Optional[Any]:

				"""simple docstring"""

				__lowerCAmelCase		,			__lowerCAmelCase   :						Union[str, Any]				= self.get_pretrained_model_and_inputs()

				__lowerCAmelCase   :						List[Any]				= model_a(**_lowerCAmelCase)
				__lowerCAmelCase   :						int				= outputs[0].numpy()

				with tempfile.TemporaryDirectory() as tmp_dirname:
							model_a.save_pretrained(_lowerCAmelCase)
							__lowerCAmelCase   :						List[str]				= TFVisionTextDualEncoderModel.from_pretrained(_lowerCAmelCase)

							__lowerCAmelCase   :						Any				= model_a(**_lowerCAmelCase)
							__lowerCAmelCase   :						Any				= after_outputs[0].numpy()
							__lowerCAmelCase   :						Tuple				= np.amax(np.abs(out_a - out_a))
							self.assertLessEqual(_lowerCAmelCase ,    1e-5)






@require_tf
class     A__     (						_lowerCAmelCase						,	unittest.TestCase							):




	'''simple docstring'''





	def 							_SCREAMING_SNAKE_CASE     (  self:	Optional[int])       -> List[str]:

				"""simple docstring"""

				__lowerCAmelCase   :						Dict				= TFVisionTextDualEncoderModel.from_vision_text_pretrained(
				    "hf-internal-testing/tiny-random-vit" ,    "hf-internal-testing/tiny-random-bert")
				__lowerCAmelCase   :						Optional[Any]				= 13
				__lowerCAmelCase   :						int				= floats_tensor(
				    [
				        batch_size,
				        model.vision_model.config.num_channels,
				        model.vision_model.config.image_size,
				        model.vision_model.config.image_size,
				    ])
				__lowerCAmelCase   :						Optional[int]				= ids_tensor([batch_size, 4] ,    model.text_model.config.vocab_size)
				__lowerCAmelCase   :						Dict				= random_attention_mask([batch_size, 4])
				__lowerCAmelCase   :						Optional[int]				= {"pixel_values": pixel_values, "input_ids": input_ids, "attention_mask": attention_mask}

				return model, inputs

	def 							_SCREAMING_SNAKE_CASE     (  self:	Tuple ,    _SCREAMING_SNAKE_CASE:	Tuple ,    _SCREAMING_SNAKE_CASE:	List[str])       -> List[str]:

				"""simple docstring"""

				__lowerCAmelCase   :						List[str]				= TFViTModel(_lowerCAmelCase ,    name="vision_model")
				__lowerCAmelCase   :						Optional[Any]				= TFBertModel(_lowerCAmelCase ,    name="text_model")
				return vision_model, text_model







	def 							_SCREAMING_SNAKE_CASE     (  self:	Dict)       -> Optional[Any]:

				"""simple docstring"""

				__lowerCAmelCase   :						Tuple				= TFViTModelTester(self)
				__lowerCAmelCase   :						Dict				= TFBertModelTester(self)
				__lowerCAmelCase   :						List[str]				= vit_model_tester.prepare_config_and_inputs()
				__lowerCAmelCase   :						Union[str, Any]				= bert_model_tester.prepare_config_and_inputs()

				__lowerCAmelCase		,			__lowerCAmelCase		,			__lowerCAmelCase   :						int				= vision_config_and_inputs

				(
				    (
				    __lowerCAmelCase						
				)		,			(
				    __lowerCAmelCase						
				)		,			(
				    __lowerCAmelCase						
				)		,			(
				    __lowerCAmelCase						
				)		,			(
				    __lowerCAmelCase						
				)		,			(
				    __lowerCAmelCase						
				)		,			(
				    __lowerCAmelCase						
				)		,									
				)   :						Tuple				= text_config_and_inputs

				return {
				    "text_config": text_config,
				    "vision_config": vision_config,
				    "pixel_values": pixel_values,
				    "attention_mask": input_mask,
				    "input_ids": input_ids,
				    "text_token_type_ids": token_type_ids,
				    "text_sequence_labels": sequence_labels,
				    "text_token_labels": token_labels,
				    "text_choice_labels": choice_labels,
				}






@require_tf
class     A__     (						_lowerCAmelCase						,	unittest.TestCase							):




	'''simple docstring'''





	def 							_SCREAMING_SNAKE_CASE     (  self:	Tuple)       -> Any:

				"""simple docstring"""

				__lowerCAmelCase   :						int				= TFVisionTextDualEncoderModel.from_vision_text_pretrained(
				    "Rocketknight1/tiny-random-deit-tf" ,    "hf-internal-testing/tiny-random-roberta")
				__lowerCAmelCase   :						Optional[Any]				= 13
				__lowerCAmelCase   :						List[Any]				= floats_tensor(
				    [
				        batch_size,
				        model.vision_model.config.num_channels,
				        model.vision_model.config.image_size,
				        model.vision_model.config.image_size,
				    ])
				__lowerCAmelCase   :						int				= ids_tensor([batch_size, 4] ,    model.text_model.config.vocab_size)
				__lowerCAmelCase   :						Tuple				= random_attention_mask([batch_size, 4])
				__lowerCAmelCase   :						str				= {"pixel_values": pixel_values, "input_ids": input_ids, "attention_mask": attention_mask}

				return model, inputs

	def 							_SCREAMING_SNAKE_CASE     (  self:	Optional[Any] ,    _SCREAMING_SNAKE_CASE:	Union[str, Any] ,    _SCREAMING_SNAKE_CASE:	str ,    _SCREAMING_SNAKE_CASE:	int ,    _SCREAMING_SNAKE_CASE:	Tuple ,    _SCREAMING_SNAKE_CASE:	int=None ,    **_SCREAMING_SNAKE_CASE:	Tuple)       -> Dict:

				"""simple docstring"""

				__lowerCAmelCase		,			__lowerCAmelCase   :						Optional[int]				= self.get_vision_text_model(_lowerCAmelCase ,    _lowerCAmelCase)
				__lowerCAmelCase   :						Optional[Any]				= TFVisionTextDualEncoderModel(vision_model=_lowerCAmelCase ,    text_model=_lowerCAmelCase)

				__lowerCAmelCase   :						Any				= model(
				    input_ids=_lowerCAmelCase ,    pixel_values=_lowerCAmelCase ,    attention_mask=_lowerCAmelCase ,    output_attentions=_lowerCAmelCase)

				__lowerCAmelCase   :						Optional[int]				= output.vision_model_output.attentions
				self.assertEqual(len(_lowerCAmelCase) ,    vision_config.num_hidden_layers)

				# in DEiT, the seq_len equals the number of patches + 2 (we add 2 for the [CLS] and distillation tokens)
				__lowerCAmelCase   :						str				= to_atuple(vision_model.config.image_size)
				__lowerCAmelCase   :						Any				= to_atuple(vision_model.config.patch_size)
				__lowerCAmelCase   :						str				= (image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])
				__lowerCAmelCase   :						Optional[int]				= num_patches + 2
				self.assertEqual(vision_attentions[0].shape[-3:] ,    (vision_config.num_attention_heads, seq_len, seq_len))

				__lowerCAmelCase   :						str				= output.text_model_output.attentions
				self.assertEqual(len(_lowerCAmelCase) ,    text_config.num_hidden_layers)

				self.assertEqual(
				    text_attentions[0].shape[-3:] ,    (text_config.num_attention_heads, input_ids.shape[-1], input_ids.shape[-1]) ,    )

	def 							_SCREAMING_SNAKE_CASE     (  self:	Tuple ,    _SCREAMING_SNAKE_CASE:	List[str] ,    _SCREAMING_SNAKE_CASE:	Dict)       -> int:

				"""simple docstring"""

				__lowerCAmelCase   :						Union[str, Any]				= TFDeiTModel(_lowerCAmelCase ,    name="vision_model")
				__lowerCAmelCase   :						int				= TFRobertaModel(_lowerCAmelCase ,    name="text_model")
				return vision_model, text_model







	def 							_SCREAMING_SNAKE_CASE     (  self:	Tuple)       -> str:

				"""simple docstring"""

				__lowerCAmelCase   :						Union[str, Any]				= TFDeiTModelTester(self)
				__lowerCAmelCase   :						List[Any]				= TFRobertaModelTester(self)
				__lowerCAmelCase   :						Tuple				= vit_model_tester.prepare_config_and_inputs()
				__lowerCAmelCase   :						Dict				= bert_model_tester.prepare_config_and_inputs()

				__lowerCAmelCase		,			__lowerCAmelCase		,			__lowerCAmelCase   :						List[Any]				= vision_config_and_inputs

				(
				    (
				    __lowerCAmelCase						
				)		,			(
				    __lowerCAmelCase						
				)		,			(
				    __lowerCAmelCase						
				)		,			(
				    __lowerCAmelCase						
				)		,			(
				    __lowerCAmelCase						
				)		,			(
				    __lowerCAmelCase						
				)		,			(
				    __lowerCAmelCase						
				)		,									
				)   :						Tuple				= text_config_and_inputs

				return {
				    "text_config": text_config,
				    "vision_config": vision_config,
				    "pixel_values": pixel_values,
				    "attention_mask": input_mask,
				    "input_ids": input_ids,
				    "text_token_type_ids": token_type_ids,
				    "text_sequence_labels": sequence_labels,
				    "text_token_labels": token_labels,
				    "text_choice_labels": choice_labels,
				}






@require_tf
class     A__     (						_lowerCAmelCase						,	unittest.TestCase							):




	'''simple docstring'''





	def 							_SCREAMING_SNAKE_CASE     (  self:	int)       -> Union[str, Any]:

				"""simple docstring"""

				__lowerCAmelCase   :						List[str]				= TFVisionTextDualEncoderModel.from_vision_text_pretrained(
				    "Rocketknight1/tiny-random-clip-tf" ,    "hf-internal-testing/tiny-random-bert")
				__lowerCAmelCase   :						str				= 13
				__lowerCAmelCase   :						Optional[Any]				= floats_tensor(
				    [
				        batch_size,
				        model.vision_model.config.num_channels,
				        model.vision_model.config.image_size,
				        model.vision_model.config.image_size,
				    ])
				__lowerCAmelCase   :						Optional[Any]				= ids_tensor([batch_size, 4] ,    model.text_model.config.vocab_size)
				__lowerCAmelCase   :						str				= random_attention_mask([batch_size, 4])
				__lowerCAmelCase   :						List[Any]				= {"pixel_values": pixel_values, "input_ids": input_ids, "attention_mask": attention_mask}

				return model, inputs

	def 							_SCREAMING_SNAKE_CASE     (  self:	Optional[int] ,    _SCREAMING_SNAKE_CASE:	Dict ,    _SCREAMING_SNAKE_CASE:	Union[str, Any])       -> Dict:

				"""simple docstring"""

				__lowerCAmelCase   :						Any				= TFCLIPVisionModel(_lowerCAmelCase ,    name="vision_model")
				__lowerCAmelCase   :						Dict				= TFBertModel(_lowerCAmelCase ,    name="text_model")
				return vision_model, text_model







	def 							_SCREAMING_SNAKE_CASE     (  self:	Union[str, Any])       -> Optional[int]:

				"""simple docstring"""

				__lowerCAmelCase   :						str				= TFCLIPVisionModelTester(self)
				__lowerCAmelCase   :						List[str]				= TFBertModelTester(self)
				__lowerCAmelCase   :						int				= clip_model_tester.prepare_config_and_inputs()
				__lowerCAmelCase   :						str				= bert_model_tester.prepare_config_and_inputs()

				__lowerCAmelCase		,			__lowerCAmelCase   :						str				= vision_config_and_inputs

				(
				    (
				    __lowerCAmelCase						
				)		,			(
				    __lowerCAmelCase						
				)		,			(
				    __lowerCAmelCase						
				)		,			(
				    __lowerCAmelCase						
				)		,			(
				    __lowerCAmelCase						
				)		,			(
				    __lowerCAmelCase						
				)		,			(
				    __lowerCAmelCase						
				)		,									
				)   :						List[Any]				= text_config_and_inputs

				return {
				    "text_config": text_config,
				    "vision_config": vision_config,
				    "pixel_values": pixel_values,
				    "attention_mask": input_mask,
				    "input_ids": input_ids,
				    "text_token_type_ids": token_type_ids,
				    "text_sequence_labels": sequence_labels,
				    "text_token_labels": token_labels,
				    "text_choice_labels": choice_labels,
				}






@require_vision
@require_tf
class     A__     (						unittest.TestCase							):




	'''simple docstring'''





	@slow
	def 							_SCREAMING_SNAKE_CASE     (  self:	int)       -> Tuple:

				"""simple docstring"""

				__lowerCAmelCase   :						Optional[int]				= TFVisionTextDualEncoderModel.from_pretrained(
				    "clip-italian/clip-italian" ,    logit_scale_init_value=1.0 ,    from_pt=_lowerCAmelCase)
				__lowerCAmelCase   :						Dict				= VisionTextDualEncoderProcessor.from_pretrained("clip-italian/clip-italian")

				__lowerCAmelCase   :						str				= Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png")
				__lowerCAmelCase   :						List[str]				= processor(
				    text=["una foto di un gatto", "una foto di un cane"] ,    images=_lowerCAmelCase ,    padding=_lowerCAmelCase ,    return_tensors="np")

				__lowerCAmelCase   :						List[str]				= model(**_lowerCAmelCase)

				# verify the logits
				self.assertEqual(outputs.logits_per_image.shape ,    (inputs.pixel_values.shape[0], inputs.input_ids.shape[0]))
				self.assertEqual(
				    outputs.logits_per_text.shape ,    (inputs.input_ids.shape[0], inputs.pixel_values.shape[0]) ,    )

				__lowerCAmelCase   :						Optional[int]				= np.array([[1.228_4727, 0.310_4122]])

				self.assertTrue(np.allclose(outputs.logits_per_image.numpy() ,    _lowerCAmelCase ,    atol=1e-3))









"""simple docstring"""






import unittest

from knapsack import knapsack as k



class     A__     (						unittest.TestCase							):




	'''simple docstring'''





	def 							_SCREAMING_SNAKE_CASE     (  self:	Optional[int])       -> List[Any]:

				"""simple docstring"""

				__lowerCAmelCase   :						List[Any]				= 0
				__lowerCAmelCase   :						str				= [0]
				__lowerCAmelCase   :						Union[str, Any]				= [0]
				__lowerCAmelCase   :						List[Any]				= len(_SCREAMING_SNAKE_CASE)
				self.assertEqual(k.knapsack(_SCREAMING_SNAKE_CASE ,    _SCREAMING_SNAKE_CASE ,    _SCREAMING_SNAKE_CASE ,    _SCREAMING_SNAKE_CASE) ,    0)

				__lowerCAmelCase   :						Dict				= [60]
				__lowerCAmelCase   :						Optional[int]				= [10]
				__lowerCAmelCase   :						Tuple				= len(_SCREAMING_SNAKE_CASE)
				self.assertEqual(k.knapsack(_SCREAMING_SNAKE_CASE ,    _SCREAMING_SNAKE_CASE ,    _SCREAMING_SNAKE_CASE ,    _SCREAMING_SNAKE_CASE) ,    0)

	def 							_SCREAMING_SNAKE_CASE     (  self:	Any)       -> int:

				"""simple docstring"""

				__lowerCAmelCase   :						Dict				= 3
				__lowerCAmelCase   :						Dict				= [1, 2, 3]
				__lowerCAmelCase   :						str				= [3, 2, 1]
				__lowerCAmelCase   :						Optional[int]				= len(_SCREAMING_SNAKE_CASE)
				self.assertEqual(k.knapsack(_SCREAMING_SNAKE_CASE ,    _SCREAMING_SNAKE_CASE ,    _SCREAMING_SNAKE_CASE ,    _SCREAMING_SNAKE_CASE) ,    5)







	def 							_SCREAMING_SNAKE_CASE     (  self:	Optional[int])       -> Optional[Any]:

				"""simple docstring"""

				__lowerCAmelCase   :						List[str]				= 50
				__lowerCAmelCase   :						Dict				= [60, 100, 120]
				__lowerCAmelCase   :						List[Any]				= [10, 20, 30]
				__lowerCAmelCase   :						int				= len(_SCREAMING_SNAKE_CASE)
				self.assertEqual(k.knapsack(_SCREAMING_SNAKE_CASE ,    _SCREAMING_SNAKE_CASE ,    _SCREAMING_SNAKE_CASE ,    _SCREAMING_SNAKE_CASE) ,    220)


if __name__ == "__main__":
	unittest.main()