
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


__magic_name__  :  Tuple     			=   logging.get_logger(__name__)


class 							lowerCamelCase       (		nn.Module					):



  """simple docstring"""





  lowerCAmelCase_								=		42
  lowerCAmelCase_								=		jnp.floataa

  def 					lowercase_						(					self					):
      A_								=					self.config.text_config
      A_								=					self.config.vision_config

      A_								=					self.config.projection_dim
      A_								=					text_config.hidden_size
      A_								=					vision_config.hidden_size

      A_								=					FLAX_MODEL_MAPPING[self.config.text_config.__class__].module_class
      A_								=					FLAX_MODEL_MAPPING.get(self.config.vision_config.__class__						,    __UpperCamelCase					).module_class

      A_								=					text_module(__UpperCamelCase						,    dtype=self.dtype					)
      A_								=					vision_module(__UpperCamelCase						,    dtype=self.dtype					)

      A_								=					nn.Dense(
          self.projection_dim						,    dtype=self.dtype						,    kernel_init=jax.nn.initializers.normal(0.02					)						,    use_bias=__UpperCamelCase						,    )
      A_								=					nn.Dense(
          self.projection_dim						,    dtype=self.dtype						,    kernel_init=jax.nn.initializers.normal(0.02					)						,    use_bias=__UpperCamelCase						,    )
      A_								=					self.param("logit_scale"						,    jax.nn.initializers.ones						,    []					)

  def __call__(					self						,    __UpperCamelCase=None						,    __UpperCamelCase=None						,    __UpperCamelCase=None						,    __UpperCamelCase=None						,    __UpperCamelCase=None						,    __UpperCamelCase = True						,    __UpperCamelCase=None						,    __UpperCamelCase=None						,    __UpperCamelCase=None						,    ):
      A_								=					return_dict if return_dict is not None else self.config.return_dict

      A_								=					self.vision_model(
          pixel_values=__UpperCamelCase						,    deterministic=__UpperCamelCase						,    output_attentions=__UpperCamelCase						,    output_hidden_states=__UpperCamelCase						,    return_dict=__UpperCamelCase						,    )

      A_								=					self.text_model(
          input_ids=__UpperCamelCase						,    attention_mask=__UpperCamelCase						,    token_type_ids=__UpperCamelCase						,    position_ids=__UpperCamelCase						,    deterministic=__UpperCamelCase						,    output_attentions=__UpperCamelCase						,    output_hidden_states=__UpperCamelCase						,    return_dict=__UpperCamelCase						,    )

      A_								=					vision_outputs[1]
      A_								=					self.visual_projection(__UpperCamelCase					)

      A_								=					text_outputs[1]
      A_								=					self.text_projection(__UpperCamelCase					)

      # normalized features
      A_								=					image_embeds / jnp.linalg.norm(__UpperCamelCase						,    axis=-1						,    keepdims=__UpperCamelCase					)
      A_								=					text_embeds / jnp.linalg.norm(__UpperCamelCase						,    axis=-1						,    keepdims=__UpperCamelCase					)

      # cosine similarity as logits
      A_								=					jnp.exp(self.logit_scale					)
      A_								=					jnp.matmul(__UpperCamelCase						,    image_embeds.T					) * logit_scale
      A_								=					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=__UpperCamelCase						,    logits_per_text=__UpperCamelCase						,    text_embeds=__UpperCamelCase						,    image_embeds=__UpperCamelCase						,    text_model_output=__UpperCamelCase						,    vision_model_output=__UpperCamelCase						,    )



class 							lowerCamelCase       (		__snake_case					):



  """simple docstring"""





  lowerCAmelCase_								=		HybridCLIPConfig
  lowerCAmelCase_								=		FlaxHybridCLIPModule

  def __init__(					self						,    __UpperCamelCase						,    __UpperCamelCase = None						,    __UpperCamelCase = 0						,    __UpperCamelCase = jnp.floataa						,    **__UpperCamelCase						,    ):
      if input_shape is None:
          A_								=					((1, 1), (1, config.vision_config.image_size, config.vision_config.image_size, 3))

      A_								=					self.module_class(config=__UpperCamelCase						,    dtype=__UpperCamelCase						,    **__UpperCamelCase					)
      super().__init__(__UpperCamelCase						,    __UpperCamelCase						,    input_shape=__UpperCamelCase						,    seed=__UpperCamelCase						,    dtype=__UpperCamelCase					)

  def 					lowercase_						(					self						,    __UpperCamelCase						,    __UpperCamelCase						,    __UpperCamelCase = None					):
      # init input tensor
      A_								=					jnp.zeros(input_shape[0]						,    dtype="i4"					)
      A_								=					jnp.broadcast_to(jnp.arange(jnp.atleast_ad(__UpperCamelCase					).shape[-1]					)						,    input_shape[0]					)
      A_								=					jnp.ones_like(__UpperCamelCase					)
      A_								=					jnp.ones_like(__UpperCamelCase					)

      A_								=					jax.random.normal(__UpperCamelCase						,    input_shape[1]					)

      A_	,	A_								=					jax.random.split(__UpperCamelCase					)
      A_								=					{"params": params_rng, "dropout": dropout_rng}

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

  def __call__(					self						,    __UpperCamelCase						,    __UpperCamelCase						,    __UpperCamelCase=None						,    __UpperCamelCase=None						,    __UpperCamelCase=None						,    __UpperCamelCase = None						,    __UpperCamelCase = None						,    __UpperCamelCase = False						,    __UpperCamelCase = None						,    __UpperCamelCase = None						,    __UpperCamelCase = None						,    ):
      A_								=					output_attentions if output_attentions is not None else self.config.output_attentions
      A_								=					(
          output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
      )
      A_								=					return_dict if return_dict is not None else self.config.return_dict

      if position_ids is None:
          A_								=					jnp.broadcast_to(jnp.arange(jnp.atleast_ad(__UpperCamelCase					).shape[-1]					)						,    input_ids.shape					)

      if token_type_ids is None:
          A_								=					jnp.zeros_like(__UpperCamelCase					)

      if attention_mask is None:
          A_								=					jnp.ones_like(__UpperCamelCase					)

      # Handle any PRNG if needed
      A_								=					{}
      if dropout_rng is not None:
          A_								=					dropout_rng

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

  def 					lowercase_						(					self						,    __UpperCamelCase						,    __UpperCamelCase=None						,    __UpperCamelCase=None						,    __UpperCamelCase=None						,    __UpperCamelCase = None						,    __UpperCamelCase = None						,    __UpperCamelCase=False						,    ):
      if position_ids is None:
          A_								=					jnp.broadcast_to(jnp.arange(jnp.atleast_ad(__UpperCamelCase					).shape[-1]					)						,    input_ids.shape					)

      if token_type_ids is None:
          A_								=					jnp.zeros_like(__UpperCamelCase					)

      if attention_mask is None:
          A_								=					jnp.ones_like(__UpperCamelCase					)

      # Handle any PRNG if needed
      A_								=					{}
      if dropout_rng is not None:
          A_								=					dropout_rng

      def _get_features(__UpperCamelCase						,    __UpperCamelCase						,    __UpperCamelCase						,    __UpperCamelCase						,    __UpperCamelCase						,    __UpperCamelCase					):
          A_								=					module.text_model(
              input_ids=__UpperCamelCase						,    attention_mask=__UpperCamelCase						,    position_ids=__UpperCamelCase						,    token_type_ids=__UpperCamelCase						,    deterministic=__UpperCamelCase						,    )
          A_								=					text_outputs[1]
          A_								=					module.text_projection(__UpperCamelCase					)
          return text_features

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

  def 					lowercase_						(					self						,    __UpperCamelCase						,    __UpperCamelCase = None						,    __UpperCamelCase = None						,    __UpperCamelCase=False					):
      A_								=					{}
      if dropout_rng is not None:
          A_								=					dropout_rng

      def _get_features(__UpperCamelCase						,    __UpperCamelCase						,    __UpperCamelCase					):
          A_								=					module.vision_model(pixel_values=__UpperCamelCase						,    deterministic=__UpperCamelCase					)
          A_								=					vision_outputs[1]  # pooled_output
          A_								=					module.visual_projection(__UpperCamelCase					)
          return image_features

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

  @classmethod
  def 					lowercase_						(					cls						,    __UpperCamelCase = None						,    __UpperCamelCase = None						,    *__UpperCamelCase						,    **__UpperCamelCase						,    ):
      A_								=					{
          argument[len("text_"					) :]: value for argument, value in kwargs.items() if argument.startswith("text_"					)
      }

      A_								=					{
          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
      A_								=					kwargs_text.pop("model"						,    __UpperCamelCase					)
      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

              A_								=					AutoConfig.from_pretrained(__UpperCamelCase					)
              A_								=					text_config

          A_								=					FlaxAutoModel.from_pretrained(__UpperCamelCase						,    *__UpperCamelCase						,    **__UpperCamelCase					)

      A_								=					kwargs_vision.pop("model"						,    __UpperCamelCase					)
      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

              A_								=					AutoConfig.from_pretrained(__UpperCamelCase					)
              A_								=					vision_config

          A_								=					FlaxAutoModel.from_pretrained(__UpperCamelCase						,    *__UpperCamelCase						,    **__UpperCamelCase					)

      # instantiate config with corresponding kwargs
      A_								=					kwargs.pop("dtype"						,    jnp.floataa					)
      A_								=					HybridCLIPConfig.from_text_vision_configs(text_model.config						,    vision_model.config						,    **__UpperCamelCase					)

      # init model
      A_								=					cls(__UpperCamelCase						,    *__UpperCamelCase						,    dtype=__UpperCamelCase						,    **__UpperCamelCase					)

      if vision_config.model_type == "clip":
          A_								=					vision_model.params["vision_model"]
          A_								=					vision_model.params["visual_projection"]["kernel"]
      else:
          A_								=					vision_model.params

      A_								=					text_model.params

      return model








import sys

sys.set_int_max_str_digits(0)  # type: ignore





def        lowerCAmelCase       (				snake_case__   :      int )->			bool:
    A_								=					[0] * 11
    A_								=					[0] * 11

    # mark last 9 numbers
    for _ in range(9 ):
        A_								=					1
        A_								=					number // 10
    # flag
    A_								=					True

    # check last 9 numbers for pandigitality

    for x in range(9 ):
        if not check_last[x + 1]:
            A_								=					False
    if not f:
        return f

    # mark first 9 numbers
    A_								=					int(str(snake_case__ )[:9] )

    for _ in range(9 ):
        A_								=					1
        A_								=					number // 10

    # check first 9 numbers for pandigitality

    for x in range(9 ):
        if not check_front[x + 1]:
            A_								=					False
    return f





def        lowerCAmelCase       (				snake_case__   :      int )->			bool:
    A_								=					[0] * 11

    # mark last 9 numbers
    for _ in range(9 ):
        A_								=					1
        A_								=					number // 10
    # flag
    A_								=					True

    # check last 9 numbers for pandigitality

    for x in range(9 ):
        if not check_last[x + 1]:
            A_								=					False
    return f





def        lowerCAmelCase       (				)->			int:
    A_								=					1
    A_								=					1
    A_								=					2
    # temporary Fibonacci numbers

    A_								=					1
    A_								=					1
    A_								=					2
    # temporary Fibonacci numbers mod 1e9

    # mod m=1e9, done for fast optimisation
    A_								=					[0] * 1000000
    A_								=					1000000000

    for x in range(1000000 ):
        A_								=					(aa + ba) % m
        A_								=					ba % m
        A_								=					ca % m
        if checka(snake_case__ ):
            A_								=					1

    for x in range(1000000 ):
        A_								=					a + b
        A_								=					b
        A_								=					c
        # perform check only if in tocheck
        if tocheck[x + 3] and check(snake_case__ ):
            return x + 3  # first 2 already done
    return -1


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






