

from typing import Optional, Tuple

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

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


_lowerCamelCase							:  str     =				logging.get_logger(__name__)





class    __UpperCAmelCase	(			nn.Module		):
   UpperCamelCase  	=	4_2
   UpperCamelCase  	=	jnp.floataa



   def 			__magic_name__       (				self				:	List[Any]		):
     UpperCAmelCase			:				Any										=					self.config.text_config
     UpperCAmelCase			:				Dict										=					self.config.vision_config

     UpperCAmelCase			:				int										=					self.config.projection_dim
     UpperCAmelCase			:				Union[str, Any]										=					text_config.hidden_size
     UpperCAmelCase			:				Optional[int]										=					vision_config.hidden_size

     UpperCAmelCase			:				str										=					FLAX_MODEL_MAPPING[self.config.text_config.__class__].module_class
     UpperCAmelCase			:				Tuple										=					FLAX_MODEL_MAPPING.get(self.config.vision_config.__class__,						__A		).module_class

     UpperCAmelCase			:				List[Any]										=					text_module(__A,						dtype=self.dtype		)
     UpperCAmelCase			:				Optional[int]										=					vision_module(__A,						dtype=self.dtype		)

     UpperCAmelCase			:				Dict										=					nn.Dense(
         self.projection_dim,						dtype=self.dtype,						kernel_init=jax.nn.initializers.normal(0.0_2		),						use_bias=__A,						)
     UpperCAmelCase			:				str										=					nn.Dense(
         self.projection_dim,						dtype=self.dtype,						kernel_init=jax.nn.initializers.normal(0.0_2		),						use_bias=__A,						)
     UpperCAmelCase			:				Tuple										=					self.param('''logit_scale''',						jax.nn.initializers.ones,						[]		)





   def __call__(				self				:	int,						__A				:	Optional[int]=None,						__A				:	Tuple=None,						__A				:	Dict=None,						__A				:	List[Any]=None,						__A				:	Union[str, Any]=None,						__A				:	bool = True,						__A				:	Any=None,						__A				:	Optional[int]=None,						__A				:	List[str]=None,						):
     UpperCAmelCase			:				Union[str, Any]										=					return_dict if return_dict is not None else self.config.return_dict

     UpperCAmelCase			:				Union[str, Any]										=					self.vision_model(
         pixel_values=__A,						deterministic=__A,						output_attentions=__A,						output_hidden_states=__A,						return_dict=__A,						)

     UpperCAmelCase			:				List[str]										=					self.text_model(
         input_ids=__A,						attention_mask=__A,						token_type_ids=__A,						position_ids=__A,						deterministic=__A,						output_attentions=__A,						output_hidden_states=__A,						return_dict=__A,						)

     UpperCAmelCase			:				List[str]										=					vision_outputs[1]
     UpperCAmelCase			:				List[Any]										=					self.visual_projection(__A		)

     UpperCAmelCase			:				List[str]										=					text_outputs[1]
     UpperCAmelCase			:				Union[str, Any]										=					self.text_projection(__A		)

     # normalized features
     UpperCAmelCase			:				Any										=					image_embeds / jnp.linalg.norm(__A,						axis=-1,						keepdims=__A		)
     UpperCAmelCase			:				int										=					text_embeds / jnp.linalg.norm(__A,						axis=-1,						keepdims=__A		)

     # cosine similarity as logits
     UpperCAmelCase			:				Optional[int]										=					jnp.exp(self.logit_scale		)
     UpperCAmelCase			:				Optional[Any]										=					jnp.matmul(__A,						image_embeds.T		) * logit_scale
     UpperCAmelCase			:				Tuple										=					logits_per_text.T

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

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






class    __UpperCAmelCase	(			lowercase__		):
   UpperCamelCase  	=	HybridCLIPConfig
   UpperCamelCase  	=	FlaxHybridCLIPModule



   def __init__(				self				:	Any,						__A				:	HybridCLIPConfig,						__A				:	Optional[Tuple] = None,						__A				:	int = 0,						__A				:	jnp.dtype = jnp.floataa,						**__A				:	str,						):
     if input_shape is None:
       UpperCAmelCase			:				Any										=					((1, 1), (1, config.vision_config.image_size, config.vision_config.image_size, 3))

     UpperCAmelCase			:				List[Any]										=					self.module_class(config=__A,						dtype=__A,						**__A		)
     super().__init__(__A,						__A,						input_shape=__A,						seed=__A,						dtype=__A		)



   def 			__magic_name__       (				self				:	int,						__A				:	jax.random.PRNGKey,						__A				:	Tuple,						__A				:	FrozenDict = None		):
     # init input tensor
     UpperCAmelCase			:				Tuple										=					jnp.zeros(input_shape[0],						dtype='''i4'''		)
     UpperCAmelCase			:				Union[str, Any]										=					jnp.broadcast_to(jnp.arange(jnp.atleast_ad(__A		).shape[-1]		),						input_shape[0]		)
     UpperCAmelCase			:				str										=					jnp.ones_like(__A		)
     UpperCAmelCase			:				Tuple										=					jnp.ones_like(__A		)

     UpperCAmelCase			:				Dict										=					jax.random.normal(__A,						input_shape[1]		)

     UpperCAmelCase			:				Any										=					jax.random.split(__A		)
     UpperCAmelCase			:				Optional[Any]										=					{"params": params_rng, "dropout": dropout_rng}

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



   def __call__(				self				:	Tuple,						__A				:	Dict,						__A				:	str,						__A				:	Any=None,						__A				:	Union[str, Any]=None,						__A				:	Union[str, Any]=None,						__A				:	dict = None,						__A				:	jax.random.PRNGKey = None,						__A				:	bool = False,						__A				:	Optional[bool] = None,						__A				:	Optional[bool] = None,						__A				:	Optional[bool] = None,						):
     UpperCAmelCase			:				str										=					output_attentions if output_attentions is not None else self.config.output_attentions
     UpperCAmelCase			:				List[Any]										=					(
         output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
     )
     UpperCAmelCase			:				Any										=					return_dict if return_dict is not None else self.config.return_dict

     if position_ids is None:
       UpperCAmelCase			:				List[Any]										=					jnp.broadcast_to(jnp.arange(jnp.atleast_ad(__A		).shape[-1]		),						input_ids.shape		)

     if token_type_ids is None:
       UpperCAmelCase			:				int										=					jnp.zeros_like(__A		)

     if attention_mask is None:
       UpperCAmelCase			:				List[str]										=					jnp.ones_like(__A		)

     # Handle any PRNG if needed
     UpperCAmelCase			:				Tuple										=					{}
     if dropout_rng is not None:
       UpperCAmelCase			:				int										=					dropout_rng

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



   def 			__magic_name__       (				self				:	List[str],						__A				:	Optional[int],						__A				:	Tuple=None,						__A				:	Optional[int]=None,						__A				:	Union[str, Any]=None,						__A				:	dict = None,						__A				:	jax.random.PRNGKey = None,						__A				:	List[Any]=False,						):
     if position_ids is None:
       UpperCAmelCase			:				List[Any]										=					jnp.broadcast_to(jnp.arange(jnp.atleast_ad(__A		).shape[-1]		),						input_ids.shape		)

     if token_type_ids is None:
       UpperCAmelCase			:				Tuple										=					jnp.zeros_like(__A		)

     if attention_mask is None:
       UpperCAmelCase			:				Optional[int]										=					jnp.ones_like(__A		)

     # Handle any PRNG if needed
     UpperCAmelCase			:				int										=					{}
     if dropout_rng is not None:
       UpperCAmelCase			:				Any										=					dropout_rng

     def _get_features(__A				:	Dict,						__A				:	Optional[int],						__A				:	Dict,						__A				:	Tuple,						__A				:	Optional[int],						__A				:	List[Any]		):
       UpperCAmelCase			:				Union[str, Any]										=					module.text_model(
           input_ids=__A,						attention_mask=__A,						position_ids=__A,						token_type_ids=__A,						deterministic=__A,						)
       UpperCAmelCase			:				Optional[Any]										=					text_outputs[1]
       UpperCAmelCase			:				Optional[Any]										=					module.text_projection(__A		)
       return text_features

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



   def 			__magic_name__       (				self				:	Tuple,						__A				:	Tuple,						__A				:	dict = None,						__A				:	jax.random.PRNGKey = None,						__A				:	int=False		):
     UpperCAmelCase			:				int										=					{}
     if dropout_rng is not None:
       UpperCAmelCase			:				str										=					dropout_rng

     def _get_features(__A				:	Dict,						__A				:	List[Any],						__A				:	List[str]		):
       UpperCAmelCase			:				str										=					module.vision_model(pixel_values=__A,						deterministic=__A		)
       UpperCAmelCase			:				str										=					vision_outputs[1]  # pooled_output
       UpperCAmelCase			:				str										=					module.visual_projection(__A		)
       return image_features

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





   @classmethod
   def 			__magic_name__       (				cls				:	Any,						__A				:	str = None,						__A				:	str = None,						*__A				:	Optional[int],						**__A				:	Any,						):
     UpperCAmelCase			:				List[Any]										=					{
         argument[len('''text_'''		) :]: value for argument, value in kwargs.items() if argument.startswith('''text_'''		)
     }

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

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

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

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

         UpperCAmelCase			:				Tuple										=					AutoConfig.from_pretrained(__A		)
         UpperCAmelCase			:				Dict										=					text_config

       UpperCAmelCase			:				Dict										=					FlaxAutoModel.from_pretrained(__A,						*__A,						**__A		)

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

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

         UpperCAmelCase			:				Optional[int]										=					AutoConfig.from_pretrained(__A		)
         UpperCAmelCase			:				List[Any]										=					vision_config

       UpperCAmelCase			:				Dict										=					FlaxAutoModel.from_pretrained(__A,						*__A,						**__A		)

     # instantiate config with corresponding kwargs
     UpperCAmelCase			:				Dict										=					kwargs.pop('''dtype''',						jnp.floataa		)
     UpperCAmelCase			:				List[str]										=					HybridCLIPConfig.from_text_vision_configs(text_model.config,						vision_model.config,						**__A		)

     # init model
     UpperCAmelCase			:				Any										=					cls(__A,						*__A,						dtype=__A,						**__A		)

     if vision_config.model_type == "clip":
       UpperCAmelCase			:				List[Any]										=					vision_model.params["vision_model"]
       UpperCAmelCase			:				Optional[int]										=					vision_model.params["visual_projection"]["kernel"]
     else:
       UpperCAmelCase			:				Dict										=					vision_model.params

     UpperCAmelCase			:				List[Any]										=					text_model.params

     return model












from itertools import combinations_with_replacement







def    UpperCAmelCase				(  _lowerCamelCase   :	int = 100  ):





						'''simple docstring'''


						SCREAMING_SNAKE_CASE__  :					list[int] =       [*list(range(1      , 21  )  ), 25]
						SCREAMING_SNAKE_CASE__  :					list[int] =       [2 * x for x in range(1      , 21  )] + [50]
						SCREAMING_SNAKE_CASE__  :					list[int] =       [3 * x for x in range(1      , 21  )]
						SCREAMING_SNAKE_CASE__  :					list[int] =       singles + doubles + triples + [0]

						SCREAMING_SNAKE_CASE__  :					int =       0
						SCREAMING_SNAKE_CASE__  :					int
						SCREAMING_SNAKE_CASE__  :					int
						SCREAMING_SNAKE_CASE__  :					int
						SCREAMING_SNAKE_CASE__  :					int

						for double in doubles:
												for throwa, throwa in combinations_with_replacement(_lowerCamelCase      , 2  ):
																		SCREAMING_SNAKE_CASE__  :					int =       double + throwa + throwa
																		if checkout_total < limit:
																								num_checkouts += 1

						return num_checkouts


if __name__ == "__main__":
				print(f"{solution() = }")