





import collections
import tempfile
import unittest

import numpy as np

from transformers.testing_utils import (
    is_pt_flax_cross_test,
    require_flax,
    require_torch,
    require_vision,
    slow,
    torch_device,
)
from transformers.utils import is_flax_available, is_torch_available, is_vision_available

from ...test_modeling_flax_common import floats_tensor, ids_tensor, random_attention_mask
from ..bert.test_modeling_flax_bert import FlaxBertModelTester
from ..clip.test_modeling_flax_clip import FlaxCLIPVisionModelTester
from ..vit.test_modeling_flax_vit import FlaxViTModelTester


if is_flax_available():
		from transformers import (
		    FlaxBertModel,
		    FlaxCLIPVisionModel,
		    FlaxVisionTextDualEncoderModel,
		    FlaxViTModel,
		    VisionTextDualEncoderConfig,
		    VisionTextDualEncoderProcessor,
		)
		from transformers.modeling_flax_pytorch_utils import (
		    convert_pytorch_state_dict_to_flax,
		    load_flax_weights_in_pytorch_model,
		)


if is_torch_available():
		import torch

		from transformers import VisionTextDualEncoderModel

if is_vision_available():
		from PIL import Image




def _a (  SCREAMING_SNAKE_CASE__      :  Optional[int]       )	->    List[Any]:

							'''simple docstring'''






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


@require_flax
class 						lowerCamelCase       :







							"""simple docstring"""




							def  A_     ( self     :					Optional[Any],			_UpperCAmelCase     :					Optional[Any],			_UpperCAmelCase     :					Tuple						)				->			Union[str, Any]:





														"""simple docstring"""
														pass






							def  A_     ( self     :					List[Any]						)				->			List[str]:





														"""simple docstring"""
														pass






							def  A_     ( self     :					Optional[Any]						)				->			Tuple:





														"""simple docstring"""
														pass






							def  A_     ( self     :					Optional[Any],			_UpperCAmelCase     :					np.ndarray,			_UpperCAmelCase     :					np.ndarray,			_UpperCAmelCase     :					float						)				->			str:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      Dict     =						np.abs((a - b)						).max()
														self.assertLessEqual(_UpperCAmelCase,			_UpperCAmelCase,			F'''Difference between torch and flax is {diff} (>= {tol}).'''						)






							def  A_     ( self     :					Tuple,			_UpperCAmelCase     :					List[str],			_UpperCAmelCase     :					List[Any],			_UpperCAmelCase     :					List[Any],			_UpperCAmelCase     :					Union[str, Any],			_UpperCAmelCase     :					Tuple=None,			**_UpperCAmelCase     :					Union[str, Any]						)				->			Any:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      Optional[int]     =						VisionTextDualEncoderConfig.from_vision_text_configs(_UpperCAmelCase,			_UpperCAmelCase						)

														SCREAMING_SNAKE_CASE__       :      Tuple     =						FlaxVisionTextDualEncoderModel(_UpperCAmelCase						)

														SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						model(input_ids=_UpperCAmelCase,			pixel_values=_UpperCAmelCase,			attention_mask=_UpperCAmelCase						)

														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  A_     ( self     :					Optional[int],			_UpperCAmelCase     :					Dict,			_UpperCAmelCase     :					Union[str, Any],			_UpperCAmelCase     :					Tuple,			_UpperCAmelCase     :					Union[str, Any],			_UpperCAmelCase     :					Optional[int]=None,			**_UpperCAmelCase     :					Union[str, Any]						)				->			Optional[int]:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__       :      Dict     =						self.get_vision_text_model(_UpperCAmelCase,			_UpperCAmelCase						)
														SCREAMING_SNAKE_CASE__       :      Any     =						{"vision_model": vision_model, "text_model": text_model}
														SCREAMING_SNAKE_CASE__       :      Tuple     =						FlaxVisionTextDualEncoderModel.from_vision_text_pretrained(**_UpperCAmelCase						)

														SCREAMING_SNAKE_CASE__       :      List[str]     =						model(input_ids=_UpperCAmelCase,			pixel_values=_UpperCAmelCase,			attention_mask=_UpperCAmelCase						)

														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  A_     ( self     :					Union[str, Any],			_UpperCAmelCase     :					List[str],			_UpperCAmelCase     :					Tuple,			_UpperCAmelCase     :					List[Any],			_UpperCAmelCase     :					int,			_UpperCAmelCase     :					int=None,			**_UpperCAmelCase     :					Optional[int]						)				->			Any:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__       :      Tuple     =						self.get_vision_text_model(_UpperCAmelCase,			_UpperCAmelCase						)
														SCREAMING_SNAKE_CASE__       :      Optional[int]     =						{"vision_model": vision_model, "text_model": text_model}
														SCREAMING_SNAKE_CASE__       :      List[Any]     =						FlaxVisionTextDualEncoderModel.from_vision_text_pretrained(**_UpperCAmelCase						)

														SCREAMING_SNAKE_CASE__       :      Any     =						model(input_ids=_UpperCAmelCase,			pixel_values=_UpperCAmelCase,			attention_mask=_UpperCAmelCase						)
														SCREAMING_SNAKE_CASE__       :      int     =						output[0]

														with tempfile.TemporaryDirectory() as tmpdirname:
																					model.save_pretrained(_UpperCAmelCase						)
																					SCREAMING_SNAKE_CASE__       :      List[str]     =						FlaxVisionTextDualEncoderModel.from_pretrained(_UpperCAmelCase						)

																					SCREAMING_SNAKE_CASE__       :      List[Any]     =						model(input_ids=_UpperCAmelCase,			pixel_values=_UpperCAmelCase,			attention_mask=_UpperCAmelCase						)
																					SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						after_output[0]
																					SCREAMING_SNAKE_CASE__       :      List[Any]     =						np.amax(np.abs(out_a - out_a						)						)
																					self.assertLessEqual(_UpperCAmelCase,			1E-3						)






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





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						self.get_vision_text_model(_UpperCAmelCase,			_UpperCAmelCase						)
														SCREAMING_SNAKE_CASE__       :      Dict     =						{"vision_model": vision_model, "text_model": text_model}
														SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						FlaxVisionTextDualEncoderModel.from_vision_text_pretrained(**_UpperCAmelCase						)

														SCREAMING_SNAKE_CASE__       :      int     =						model(
														    input_ids=_UpperCAmelCase,			pixel_values=_UpperCAmelCase,			attention_mask=_UpperCAmelCase,			output_attentions=_UpperCAmelCase						)

														SCREAMING_SNAKE_CASE__       :      Dict     =						output.vision_model_output.attentions
														self.assertEqual(len(_UpperCAmelCase						),			vision_config.num_hidden_layers						)

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

														SCREAMING_SNAKE_CASE__       :      Dict     =						output.text_model_output.attentions
														self.assertEqual(len(_UpperCAmelCase						),			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  A_     ( self     :					Tuple,			_UpperCAmelCase     :					List[str],			_UpperCAmelCase     :					Tuple,			_UpperCAmelCase     :					str						)				->			Any:





														"""simple docstring"""
														pt_model.to(_UpperCAmelCase						)
														pt_model.eval()

														# prepare inputs
														SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						inputs_dict
														SCREAMING_SNAKE_CASE__       :      List[str]     =						{k: torch.tensor(v.tolist()						) for k, v in flax_inputs.items()}

														with torch.no_grad():
																					SCREAMING_SNAKE_CASE__       :      Optional[int]     =						pt_model(**_UpperCAmelCase						).to_tuple()

														SCREAMING_SNAKE_CASE__       :      Tuple     =						fx_model(**_UpperCAmelCase						).to_tuple()
														self.assertEqual(len(_UpperCAmelCase						),			len(_UpperCAmelCase						),			"Output lengths differ between Flax and PyTorch"						)
														for fx_output, pt_output in zip(fx_outputs[:4],			pt_outputs[:4]						):
																					self.assert_almost_equals(_UpperCAmelCase,			pt_output.numpy(),			4E-2						)

														# PT -> Flax
														with tempfile.TemporaryDirectory() as tmpdirname:
																					pt_model.save_pretrained(_UpperCAmelCase						)
																					SCREAMING_SNAKE_CASE__       :      Dict     =						FlaxVisionTextDualEncoderModel.from_pretrained(_UpperCAmelCase,			from_pt=_UpperCAmelCase						)

														SCREAMING_SNAKE_CASE__       :      List[Any]     =						fx_model_loaded(**_UpperCAmelCase						).to_tuple()
														self.assertEqual(len(_UpperCAmelCase						),			len(_UpperCAmelCase						),			"Output lengths differ between Flax and PyTorch"						)
														for fx_output_loaded, pt_output in zip(fx_outputs_loaded[:4],			pt_outputs[:4]						):
																					self.assert_almost_equals(_UpperCAmelCase,			pt_output.numpy(),			4E-2						)

														# Flax -> PT
														with tempfile.TemporaryDirectory() as tmpdirname:
																					fx_model.save_pretrained(_UpperCAmelCase						)
																					SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						VisionTextDualEncoderModel.from_pretrained(_UpperCAmelCase,			from_flax=_UpperCAmelCase						)

														pt_model_loaded.to(_UpperCAmelCase						)
														pt_model_loaded.eval()

														with torch.no_grad():
																					SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						pt_model_loaded(**_UpperCAmelCase						).to_tuple()

														self.assertEqual(len(_UpperCAmelCase						),			len(_UpperCAmelCase						),			"Output lengths differ between Flax and PyTorch"						)
														for fx_output, pt_output_loaded in zip(fx_outputs[:4],			pt_outputs_loaded[:4]						):
																					self.assert_almost_equals(_UpperCAmelCase,			pt_output_loaded.numpy(),			4E-2						)






							def  A_     ( self     :					Union[str, Any],			_UpperCAmelCase     :					List[Any],			_UpperCAmelCase     :					Optional[Any],			_UpperCAmelCase     :					List[Any]						)				->			Optional[int]:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      List[str]     =						VisionTextDualEncoderConfig.from_vision_text_configs(_UpperCAmelCase,			_UpperCAmelCase						)

														SCREAMING_SNAKE_CASE__       :      Dict     =						VisionTextDualEncoderModel(_UpperCAmelCase						)
														SCREAMING_SNAKE_CASE__       :      List[Any]     =						FlaxVisionTextDualEncoderModel(_UpperCAmelCase						)

														SCREAMING_SNAKE_CASE__       :      Any     =						convert_pytorch_state_dict_to_flax(pt_model.state_dict(),			_UpperCAmelCase						)
														SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						fx_state

														self.check_pt_flax_equivalence(_UpperCAmelCase,			_UpperCAmelCase,			_UpperCAmelCase						)






							def  A_     ( self     :					Optional[int],			_UpperCAmelCase     :					Tuple,			_UpperCAmelCase     :					Optional[int],			_UpperCAmelCase     :					Dict						)				->			Tuple:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      Any     =						VisionTextDualEncoderConfig.from_vision_text_configs(_UpperCAmelCase,			_UpperCAmelCase						)

														SCREAMING_SNAKE_CASE__       :      Any     =						VisionTextDualEncoderModel(_UpperCAmelCase						)
														SCREAMING_SNAKE_CASE__       :      int     =						FlaxVisionTextDualEncoderModel(_UpperCAmelCase						)

														SCREAMING_SNAKE_CASE__       :      Tuple     =						load_flax_weights_in_pytorch_model(_UpperCAmelCase,			fx_model.params						)

														self.check_pt_flax_equivalence(_UpperCAmelCase,			_UpperCAmelCase,			_UpperCAmelCase						)






							def  A_     ( self     :					Tuple						)				->			Union[str, Any]:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      List[str]     =						self.prepare_config_and_inputs()
														self.check_model_from_pretrained_configs(**_UpperCAmelCase						)






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





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      Tuple     =						self.prepare_config_and_inputs()
														self.check_vision_text_dual_encoder_from_pretrained(**_UpperCAmelCase						)






							def  A_     ( self     :					Dict						)				->			Any:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      Any     =						self.prepare_config_and_inputs()
														self.check_save_load(**_UpperCAmelCase						)






							def  A_     ( self     :					Tuple						)				->			str:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      Optional[int]     =						self.prepare_config_and_inputs()
														self.check_vision_text_output_attention(**_UpperCAmelCase						)






							@is_pt_flax_cross_test
							def  A_     ( self     :					Union[str, Any]						)				->			List[Any]:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      Tuple     =						self.prepare_config_and_inputs()
														SCREAMING_SNAKE_CASE__       :      Optional[int]     =						config_inputs_dict.pop("vision_config"						)
														SCREAMING_SNAKE_CASE__       :      Optional[int]     =						config_inputs_dict.pop("text_config"						)

														SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						config_inputs_dict

														self.check_equivalence_pt_to_flax(_UpperCAmelCase,			_UpperCAmelCase,			_UpperCAmelCase						)
														self.check_equivalence_flax_to_pt(_UpperCAmelCase,			_UpperCAmelCase,			_UpperCAmelCase						)






							@slow
							def  A_     ( self     :					str						)				->			Any:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__       :      Any     =						self.get_pretrained_model_and_inputs()

														SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						model_a(**_UpperCAmelCase						)
														SCREAMING_SNAKE_CASE__       :      int     =						outputs[0]

														with tempfile.TemporaryDirectory() as tmp_dirname:
																					model_a.save_pretrained(_UpperCAmelCase						)
																					SCREAMING_SNAKE_CASE__       :      int     =						FlaxVisionTextDualEncoderModel.from_pretrained(_UpperCAmelCase						)

																					SCREAMING_SNAKE_CASE__       :      Any     =						model_a(**_UpperCAmelCase						)
																					SCREAMING_SNAKE_CASE__       :      Optional[int]     =						after_outputs[0]
																					SCREAMING_SNAKE_CASE__       :      List[str]     =						np.amax(np.abs(out_a - out_a						)						)
																					self.assertLessEqual(_UpperCAmelCase,			1E-5						)


@require_flax
class 						lowerCamelCase       (__lowerCamelCase							,     unittest.TestCase      ):







							"""simple docstring"""




							def  A_     ( self     :					Dict						)				->			Any:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      Tuple     =						FlaxVisionTextDualEncoderModel.from_vision_text_pretrained(
														    "hf-internal-testing/tiny-random-vit",			"hf-internal-testing/tiny-bert",			vision_from_pt=_UpperCAmelCase,			text_from_pt=_UpperCAmelCase,			)
														SCREAMING_SNAKE_CASE__       :      Any     =						1_3
														SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						floats_tensor(
														    [
														        batch_size,
														        model.config.vision_config.num_channels,
														        model.config.vision_config.image_size,
														        model.config.vision_config.image_size,
														    ]						)
														SCREAMING_SNAKE_CASE__       :      Tuple     =						ids_tensor([batch_size, 4],			model.config.text_config.vocab_size						)
														SCREAMING_SNAKE_CASE__       :      List[str]     =						random_attention_mask([batch_size, 4]						)
														SCREAMING_SNAKE_CASE__       :      str     =						{"pixel_values": pixel_values, "input_ids": input_ids, "attention_mask": attention_mask}

														return model, inputs






							def  A_     ( self     :					List[Any],			_UpperCAmelCase     :					List[Any],			_UpperCAmelCase     :					int						)				->			Union[str, Any]:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						FlaxViTModel(_UpperCAmelCase						)
														SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						FlaxBertModel(_UpperCAmelCase						)
														return vision_model, text_model






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





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      List[str]     =						FlaxViTModelTester(self						)
														SCREAMING_SNAKE_CASE__       :      List[Any]     =						FlaxBertModelTester(self						)
														SCREAMING_SNAKE_CASE__       :      int     =						vit_model_tester.prepare_config_and_inputs()
														SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						bert_model_tester.prepare_config_and_inputs()

														SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						vision_config_and_inputs

														SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__       :      int     =						text_config_and_inputs

														# make sure that cross attention layers are added
														return {
														    "text_config": text_config,
														    "vision_config": vision_config,
														    "pixel_values": pixel_values,
														    "attention_mask": attention_mask,
														    "input_ids": input_ids,
														    "token_type_ids": token_type_ids,
														}


@require_torch
class 						lowerCamelCase       (__lowerCamelCase							,     unittest.TestCase      ):







							"""simple docstring"""




							def  A_     ( self     :					Optional[int]						)				->			int:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      Dict     =						FlaxVisionTextDualEncoderModel.from_vision_text_pretrained(
														    "hf-internal-testing/tiny-random-clip",			"hf-internal-testing/tiny-bert",			vision_from_pt=_UpperCAmelCase,			text_from_pt=_UpperCAmelCase,			)
														SCREAMING_SNAKE_CASE__       :      Dict     =						1_3
														SCREAMING_SNAKE_CASE__       :      Tuple     =						floats_tensor(
														    [
														        batch_size,
														        model.config.vision_config.num_channels,
														        model.config.vision_config.image_size,
														        model.config.vision_config.image_size,
														    ]						)
														SCREAMING_SNAKE_CASE__       :      Any     =						ids_tensor([batch_size, 4],			model.config.text_config.vocab_size						)
														SCREAMING_SNAKE_CASE__       :      Dict     =						random_attention_mask([batch_size, 4]						)
														SCREAMING_SNAKE_CASE__       :      List[Any]     =						{"pixel_values": pixel_values, "input_ids": input_ids, "attention_mask": attention_mask}

														return model, inputs






							def  A_     ( self     :					Optional[Any],			_UpperCAmelCase     :					int,			_UpperCAmelCase     :					str						)				->			int:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      Any     =						FlaxCLIPVisionModel(_UpperCAmelCase						)
														SCREAMING_SNAKE_CASE__       :      Dict     =						FlaxBertModel(_UpperCAmelCase						)
														return vision_model, text_model






							def  A_     ( self     :					Optional[int]						)				->			Optional[int]:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      Optional[int]     =						FlaxCLIPVisionModelTester(self						)
														SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						FlaxBertModelTester(self						)
														SCREAMING_SNAKE_CASE__       :      Tuple     =						clip_model_tester.prepare_config_and_inputs()
														SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						bert_model_tester.prepare_config_and_inputs()

														SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__       :      Dict     =						vision_config_and_inputs

														SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						text_config_and_inputs

														# make sure that cross attention layers are added
														return {
														    "text_config": text_config,
														    "vision_config": vision_config,
														    "pixel_values": pixel_values,
														    "attention_mask": attention_mask,
														    "input_ids": input_ids,
														    "token_type_ids": token_type_ids,
														}


@require_flax
@require_vision
class 						lowerCamelCase       (unittest.TestCase      ):







							"""simple docstring"""




							@slow
							def  A_     ( self     :					Optional[Any]						)				->			str:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      Dict     =						FlaxVisionTextDualEncoderModel.from_pretrained("clip-italian/clip-italian",			logit_scale_init_value=1.0						)
														SCREAMING_SNAKE_CASE__       :      str     =						VisionTextDualEncoderProcessor.from_pretrained("clip-italian/clip-italian"						)

														SCREAMING_SNAKE_CASE__       :      Optional[int]     =						Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"						)
														SCREAMING_SNAKE_CASE__       :      List[Any]     =						processor(
														    text=["una foto di un gatto", "una foto di un cane"],			images=_UpperCAmelCase,			padding=_UpperCAmelCase,			return_tensors="np"						)

														SCREAMING_SNAKE_CASE__       :      List[str]     =						model(**_UpperCAmelCase						)

														# 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]),			)

														SCREAMING_SNAKE_CASE__       :      List[str]     =						np.array([[1.2284727, 0.3104122]]						)

														self.assertTrue(np.allclose(outputs.logits_per_image,			_UpperCAmelCase,			atol=1E-3						)						)













_lowerCamelCase :    dict[tuple[int, int, int], int]  							= {}




def _a (  SCREAMING_SNAKE_CASE__      :  int			,				SCREAMING_SNAKE_CASE__      :  int			,				SCREAMING_SNAKE_CASE__      :  int       )	->    int:

							'''simple docstring'''






							if late == 3 or absent == 2:
														return 0

							# if we have no days left, and have not failed any other rules,
							# we have a prize string
							if days == 0:
														return 1

							# No easy solution, so now we need to do the recursive calculation

							# First, check if the combination is already in the cache, and
							# if yes, return the stored value from there since we already
							# know the number of possible prize strings from this point on
							SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						(days, absent, late)
							if key in cache:
														return cache[key]

							# now we calculate the three possible ways that can unfold from
							# this point on, depending on our attendance today

							# 1) if we are late (but not absent), the "absent" counter stays as
							# it is, but the "late" counter increases by one
							SCREAMING_SNAKE_CASE__       :      Tuple     =						_calculate(days - 1			,				SCREAMING_SNAKE_CASE__			,				late + 1       )

							# 2) if we are absent, the "absent" counter increases by 1, and the
							# "late" counter resets to 0
							SCREAMING_SNAKE_CASE__       :      Dict     =						_calculate(days - 1			,				absent + 1			,				0       )

							# 3) if we are on time, this resets the "late" counter and keeps the
							# absent counter
							SCREAMING_SNAKE_CASE__       :      Any     =						_calculate(days - 1			,				SCREAMING_SNAKE_CASE__			,				0       )

							SCREAMING_SNAKE_CASE__       :      str     =						state_late + state_absent + state_ontime

							SCREAMING_SNAKE_CASE__       :      Optional[int]     =						prizestrings
							return prizestrings




def _a (  SCREAMING_SNAKE_CASE__      :  int = 30       )	->    int:

							'''simple docstring'''






							return _calculate(SCREAMING_SNAKE_CASE__			,				absent=0			,				late=0       )


if __name__ == "__main__":
		print(solution())






