





'''simple docstring'''







import inspect
from typing import Callable, List, Optional, Set, Tuple, Union

import torch
from packaging import version
from safetensors.torch import storage_ptr, storage_size
from torch import nn

from .utils import logging


snake_case_       :    str          =					[nn.LayerNorm]

snake_case_       :    str          =					logging.get_logger(__name__)

snake_case_       :    List[Any]          =					version.parse(version.parse(torch.__version__).base_version)

snake_case_       :    Dict          =					parsed_torch_version_base >= version.parse("2.0")
snake_case_       :    int          =					parsed_torch_version_base >= version.parse("1.12")
snake_case_       :    Optional[int]          =					parsed_torch_version_base >= version.parse("1.11")
snake_case_       :    int          =					parsed_torch_version_base < version.parse("1.11")





def     lowerCamelCase_ (					SCREAMING_SNAKE_CASE__ :     Any,     SCREAMING_SNAKE_CASE__ :     Tuple,     SCREAMING_SNAKE_CASE__ :     Dict,     SCREAMING_SNAKE_CASE__ :     Any,     self :     Optional[Any]				)	->		Union[str, Any]:
						from torch import _softmax_backward_data

						if is_torch_less_than_1_11:
												return _softmax_backward_data(snake_case__,     snake_case__,     parent.dim,     self				)
						else:
												return _softmax_backward_data(snake_case__,     snake_case__,     parent.dim,     self.dtype				)





def     lowerCamelCase_ (					SCREAMING_SNAKE_CASE__ :     Tuple,     SCREAMING_SNAKE_CASE__ :     str,     SCREAMING_SNAKE_CASE__ :     Any = 0				)	->		nn.Linear:
						UpperCAmelCase_     : List[Any]         =					index.to(layer.weight.device				)
						UpperCAmelCase_     : Dict         =					layer.weight.index_select(snake_case__,     snake_case__				).clone().detach()
						if layer.bias is not None:
												if dim == 1:
																		UpperCAmelCase_     : Dict         =					layer.bias.clone().detach()
												else:
																		UpperCAmelCase_     : List[Any]         =					layer.bias[index].clone().detach()
						UpperCAmelCase_     : Dict         =					list(layer.weight.size()				)
						UpperCAmelCase_     : int         =					len(snake_case__				)
						UpperCAmelCase_     : int         =					nn.Linear(new_size[1],     new_size[0],     bias=layer.bias is not None				).to(layer.weight.device				)
						UpperCAmelCase_     : Dict         =					False
						new_layer.weight.copy_(W.contiguous()				)
						UpperCAmelCase_     : List[str]         =					True
						if layer.bias is not None:
												UpperCAmelCase_     : Dict         =					False
												new_layer.bias.copy_(b.contiguous()				)
												UpperCAmelCase_     : Any         =					True
						return new_layer


class    __a (nn.Module       ):

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







													"""simple docstring"""
													super().__init__()
													UpperCAmelCase_     : List[Any]         =					nf
													UpperCAmelCase_     : List[str]         =					nn.Parameter(torch.empty(__SCREAMING_SNAKE_CASE    ,       __SCREAMING_SNAKE_CASE				)				)
													UpperCAmelCase_     : List[Any]         =					nn.Parameter(torch.zeros(__SCREAMING_SNAKE_CASE				)				)
													nn.init.normal_(self.weight    ,       std=0.0_2				)



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







													"""simple docstring"""
													UpperCAmelCase_     : Optional[Any]         =					x.size()[:-1] + (self.nf,)
													UpperCAmelCase_     : str         =					torch.addmm(self.bias    ,       x.view(-1    ,       x.size(-1				)				)    ,       self.weight				)
													UpperCAmelCase_     : Any         =					x.view(__SCREAMING_SNAKE_CASE				)
													return x





def     lowerCamelCase_ (					SCREAMING_SNAKE_CASE__ :     Union[str, Any],     SCREAMING_SNAKE_CASE__ :     Union[str, Any],     SCREAMING_SNAKE_CASE__ :     List[Any] = 1				)	->		ConvaD:
						UpperCAmelCase_     : Optional[Any]         =					index.to(layer.weight.device				)
						UpperCAmelCase_     : List[str]         =					layer.weight.index_select(snake_case__,     snake_case__				).clone().detach()
						if dim == 0:
												UpperCAmelCase_     : List[str]         =					layer.bias.clone().detach()
						else:
												UpperCAmelCase_     : str         =					layer.bias[index].clone().detach()
						UpperCAmelCase_     : str         =					list(layer.weight.size()				)
						UpperCAmelCase_     : Union[str, Any]         =					len(snake_case__				)
						UpperCAmelCase_     : Dict         =					ConvaD(new_size[1],     new_size[0]				).to(layer.weight.device				)
						UpperCAmelCase_     : List[Any]         =					False
						new_layer.weight.copy_(W.contiguous()				)
						UpperCAmelCase_     : Any         =					True
						UpperCAmelCase_     : List[str]         =					False
						new_layer.bias.copy_(b.contiguous()				)
						UpperCAmelCase_     : Union[str, Any]         =					True
						return new_layer





def     lowerCamelCase_ (					SCREAMING_SNAKE_CASE__ :     Tuple,     SCREAMING_SNAKE_CASE__ :     List[str],     SCREAMING_SNAKE_CASE__ :     Optional[Any] = None				)	->		Union[nn.Linear, ConvaD]:
						if isinstance(snake_case__,     nn.Linear				):
												return prune_linear_layer(snake_case__,     snake_case__,     dim=0 if dim is None else dim				)
						elif isinstance(snake_case__,     snake_case__				):
												return prune_convad_layer(snake_case__,     snake_case__,     dim=1 if dim is None else dim				)
						else:
												raise ValueError(F"""Can't prune layer of class {layer.__class__}"""				)





def     lowerCamelCase_ (					SCREAMING_SNAKE_CASE__ :     Optional[int],     SCREAMING_SNAKE_CASE__ :     List[Any],     SCREAMING_SNAKE_CASE__ :     Tuple,     *SCREAMING_SNAKE_CASE__ :     Optional[int]				)	->		torch.Tensor:
						assert len(snake_case__				) > 0, F"""{input_tensors} has to be a tuple/list of tensors"""

						# inspect.signature exist since python 3.5 and is a python method -> no problem with backward compatibility
						UpperCAmelCase_     : Tuple         =					len(inspect.signature(snake_case__				).parameters				)
						if num_args_in_forward_chunk_fn != len(snake_case__				):
												raise ValueError(
												    F"""forward_chunk_fn expects {num_args_in_forward_chunk_fn} arguments, but only {len(snake_case__				)} input """
												    '''tensors are given'''				)

						if chunk_size > 0:
												UpperCAmelCase_     : Tuple         =					input_tensors[0].shape[chunk_dim]
												for input_tensor in input_tensors:
																		if input_tensor.shape[chunk_dim] != tensor_shape:
																								raise ValueError(
																								    F"""All input tenors have to be of the same shape: {tensor_shape}, """
																								    F"""found shape {input_tensor.shape[chunk_dim]}"""				)

												if input_tensors[0].shape[chunk_dim] % chunk_size != 0:
																		raise ValueError(
																		    F"""The dimension to be chunked {input_tensors[0].shape[chunk_dim]} has to be a multiple of the chunk """
																		    F"""size {chunk_size}"""				)

												UpperCAmelCase_     : str         =					input_tensors[0].shape[chunk_dim] // chunk_size

												# chunk input tensor into tuples
												UpperCAmelCase_     : int         =					tuple(input_tensor.chunk(snake_case__,     dim=snake_case__				) for input_tensor in input_tensors				)
												# apply forward fn to every tuple
												UpperCAmelCase_     : int         =					tuple(forward_fn(*snake_case__				) for input_tensors_chunk in zip(*snake_case__				)				)
												# concatenate output at same dimension
												return torch.cat(snake_case__,     dim=snake_case__				)

						return forward_fn(*snake_case__				)





def     lowerCamelCase_ (					SCREAMING_SNAKE_CASE__ :     int,     SCREAMING_SNAKE_CASE__ :     Dict,     SCREAMING_SNAKE_CASE__ :     Dict,     SCREAMING_SNAKE_CASE__ :     Union[str, Any]				)	->		Tuple[Set[int], torch.LongTensor]:
						UpperCAmelCase_     : Tuple         =					torch.ones(snake_case__,     snake_case__				)
						UpperCAmelCase_     : int         =					set(snake_case__				) - already_pruned_heads  # Convert to set and remove already pruned heads
						for head in heads:
												# Compute how many pruned heads are before the head and move the index accordingly
												UpperCAmelCase_     : Tuple         =					head - sum(1 if h < head else 0 for h in already_pruned_heads				)
												UpperCAmelCase_     : List[Any]         =					0
						UpperCAmelCase_     : Optional[Any]         =					mask.view(-1				).contiguous().eq(1				)
						UpperCAmelCase_     : Optional[int]         =					torch.arange(len(snake_case__				)				)[mask].long()
						return heads, index





def     lowerCamelCase_ (					*SCREAMING_SNAKE_CASE__ :     Union[str, Any],     SCREAMING_SNAKE_CASE__ :     List[Any] = None				)	->		Tuple[torch.Tensor, ...]:
						return torch.meshgrid(*snake_case__,     indexing=snake_case__				)





def     lowerCamelCase_ (					SCREAMING_SNAKE_CASE__ :     Optional[int]				)	->		Tuple[torch.device, int, int]:
						return tensor.device, storage_ptr(snake_case__				), storage_size(snake_case__				)












'''simple docstring'''







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


snake_case_       :    int          =					logging.get_logger(__name__)


class    __a (nn.Module       ):
							__a   :				HybridCLIPConfig
							__a   :				jnp.dtype       =    jnp.floataa

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







													"""simple docstring"""
													UpperCAmelCase_     : Dict         =					self.config.text_config
													UpperCAmelCase_     : Dict         =					self.config.vision_config

													UpperCAmelCase_     : Tuple         =					self.config.projection_dim
													UpperCAmelCase_     : str         =					text_config.hidden_size
													UpperCAmelCase_     : List[Any]         =					vision_config.hidden_size

													UpperCAmelCase_     : int         =					FLAX_MODEL_MAPPING[self.config.text_config.__class__].module_class
													UpperCAmelCase_     : int         =					FLAX_MODEL_MAPPING.get(self.config.vision_config.__class__    ,       __magic_name__				).module_class

													UpperCAmelCase_     : str         =					text_module(__magic_name__    ,       dtype=self.dtype				)
													UpperCAmelCase_     : List[Any]         =					vision_module(__magic_name__    ,       dtype=self.dtype				)

													UpperCAmelCase_     : int         =					nn.Dense(
													    self.projection_dim    ,       dtype=self.dtype    ,       kernel_init=jax.nn.initializers.normal(0.0_2				)    ,       use_bias=__magic_name__    ,       )
													UpperCAmelCase_     : Union[str, Any]         =					nn.Dense(
													    self.projection_dim    ,       dtype=self.dtype    ,       kernel_init=jax.nn.initializers.normal(0.0_2				)    ,       use_bias=__magic_name__    ,       )
													UpperCAmelCase_     : Tuple         =					self.param('''logit_scale'''    ,       jax.nn.initializers.ones    ,       []				)



							def __call__(							self							:       Tuple    ,       __magic_name__							:       Optional[Any]=None    ,       __magic_name__							:       List[Any]=None    ,       __magic_name__							:       Union[str, Any]=None    ,       __magic_name__							:       str=None    ,       __magic_name__							:       List[Any]=None    ,       __magic_name__							:       bool = True    ,       __magic_name__							:       List[str]=None    ,       __magic_name__							:       Optional[int]=None    ,       __magic_name__							:       Any=None    ,       )   ->    Optional[Any]:







													"""simple docstring"""
													UpperCAmelCase_     : int         =					return_dict if return_dict is not None else self.config.return_dict

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

													UpperCAmelCase_     : str         =					self.text_model(
													    input_ids=__magic_name__    ,       attention_mask=__magic_name__    ,       token_type_ids=__magic_name__    ,       position_ids=__magic_name__    ,       deterministic=__magic_name__    ,       output_attentions=__magic_name__    ,       output_hidden_states=__magic_name__    ,       return_dict=__magic_name__    ,       )

													UpperCAmelCase_     : List[str]         =					vision_outputs[1]
													UpperCAmelCase_     : Union[str, Any]         =					self.visual_projection(__magic_name__				)

													UpperCAmelCase_     : List[Any]         =					text_outputs[1]
													UpperCAmelCase_     : Optional[Any]         =					self.text_projection(__magic_name__				)

													# normalized features
													UpperCAmelCase_     : int         =					image_embeds / jnp.linalg.norm(__magic_name__    ,       axis=-1    ,       keepdims=__magic_name__				)
													UpperCAmelCase_     : List[str]         =					text_embeds / jnp.linalg.norm(__magic_name__    ,       axis=-1    ,       keepdims=__magic_name__				)

													# cosine similarity as logits
													UpperCAmelCase_     : str         =					jnp.exp(self.logit_scale				)
													UpperCAmelCase_     : Optional[int]         =					jnp.matmul(__magic_name__    ,       image_embeds.T				) * logit_scale
													UpperCAmelCase_     : int         =					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=__magic_name__    ,       logits_per_text=__magic_name__    ,       text_embeds=__magic_name__    ,       image_embeds=__magic_name__    ,       text_model_output=__magic_name__    ,       vision_model_output=__magic_name__    ,       )





class    __a (lowerCamelCase       ):
							__a   :				int       =    HybridCLIPConfig
							__a   :				Optional[Any]       =    FlaxHybridCLIPModule

							def __init__(							self							:       Dict    ,       __magic_name__							:       HybridCLIPConfig    ,       __magic_name__							:       Optional[Tuple] = None    ,       __magic_name__							:       int = 0    ,       __magic_name__							:       jnp.dtype = jnp.floataa    ,       **__magic_name__							:       Optional[Any]    ,       )   ->    str:







													"""simple docstring"""
													if input_shape is None:
																			UpperCAmelCase_     : Optional[Any]         =					((1, 1), (1, config.vision_config.image_size, config.vision_config.image_size, 3))

													UpperCAmelCase_     : Any         =					self.module_class(config=__magic_name__    ,       dtype=__magic_name__    ,       **__magic_name__				)
													super().__init__(__magic_name__    ,       __magic_name__    ,       input_shape=__magic_name__    ,       seed=__magic_name__    ,       dtype=__magic_name__				)

							def       UpperCAmelCase__		(							self							:       List[Any]    ,       __magic_name__							:       jax.random.PRNGKey    ,       __magic_name__							:       Tuple    ,       __magic_name__							:       FrozenDict = None				)   ->    FrozenDict:







													"""simple docstring"""
													# init input tensor
													UpperCAmelCase_     : List[Any]         =					jnp.zeros(input_shape[0]    ,       dtype='''i4'''				)
													UpperCAmelCase_     : List[Any]         =					jnp.broadcast_to(jnp.arange(jnp.atleast_ad(__magic_name__				).shape[-1]				)    ,       input_shape[0]				)
													UpperCAmelCase_     : Optional[int]         =					jnp.ones_like(__magic_name__				)
													UpperCAmelCase_     : str         =					jnp.ones_like(__magic_name__				)

													UpperCAmelCase_     : Optional[int]         =					jax.random.normal(__magic_name__    ,       input_shape[1]				)

													UpperCAmelCase_  ,    UpperCAmelCase_     : Optional[int]         =					jax.random.split(__magic_name__				)
													UpperCAmelCase_     : List[Any]         =					{'''params''': params_rng, '''dropout''': dropout_rng}

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

							def __call__(							self							:       Optional[Any]    ,       __magic_name__							:       List[str]    ,       __magic_name__							:       int    ,       __magic_name__							:       List[str]=None    ,       __magic_name__							:       Union[str, Any]=None    ,       __magic_name__							:       List[str]=None    ,       __magic_name__							:       dict = None    ,       __magic_name__							:       jax.random.PRNGKey = None    ,       __magic_name__							:       bool = False    ,       __magic_name__							:       Optional[bool] = None    ,       __magic_name__							:       Optional[bool] = None    ,       __magic_name__							:       Optional[bool] = None    ,       )   ->    List[Any]:







													"""simple docstring"""
													UpperCAmelCase_     : List[Any]         =					output_attentions if output_attentions is not None else self.config.output_attentions
													UpperCAmelCase_     : List[str]         =					(
													    output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
													)
													UpperCAmelCase_     : List[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(__magic_name__				).shape[-1]				)    ,       input_ids.shape				)

													if token_type_ids is None:
																			UpperCAmelCase_     : Optional[Any]         =					jnp.zeros_like(__magic_name__				)

													if attention_mask is None:
																			UpperCAmelCase_     : Tuple         =					jnp.ones_like(__magic_name__				)

													# Handle any PRNG if needed
													UpperCAmelCase_     : Dict         =					{}
													if dropout_rng is not None:
																			UpperCAmelCase_     : Any         =					dropout_rng

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

							def       UpperCAmelCase__		(							self							:       str    ,       __magic_name__							:       Union[str, Any]    ,       __magic_name__							:       int=None    ,       __magic_name__							:       List[str]=None    ,       __magic_name__							:       int=None    ,       __magic_name__							:       dict = None    ,       __magic_name__							:       jax.random.PRNGKey = None    ,       __magic_name__							:       Tuple=False    ,       )   ->    Tuple:







													"""simple docstring"""
													if position_ids is None:
																			UpperCAmelCase_     : Optional[int]         =					jnp.broadcast_to(jnp.arange(jnp.atleast_ad(__magic_name__				).shape[-1]				)    ,       input_ids.shape				)

													if token_type_ids is None:
																			UpperCAmelCase_     : Tuple         =					jnp.zeros_like(__magic_name__				)

													if attention_mask is None:
																			UpperCAmelCase_     : Tuple         =					jnp.ones_like(__magic_name__				)

													# Handle any PRNG if needed
													UpperCAmelCase_     : List[str]         =					{}
													if dropout_rng is not None:
																			UpperCAmelCase_     : str         =					dropout_rng

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

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

							def       UpperCAmelCase__		(							self							:       List[Any]    ,       __magic_name__							:       str    ,       __magic_name__							:       dict = None    ,       __magic_name__							:       jax.random.PRNGKey = None    ,       __magic_name__							:       Dict=False				)   ->    Optional[Any]:







													"""simple docstring"""
													UpperCAmelCase_     : List[str]         =					{}
													if dropout_rng is not None:
																			UpperCAmelCase_     : Union[str, Any]         =					dropout_rng

													def _get_features(__magic_name__							:       List[str]    ,       __magic_name__							:       List[Any]    ,       __magic_name__							:       List[Any]				):
																			UpperCAmelCase_     : Optional[int]         =					module.vision_model(pixel_values=__magic_name__    ,       deterministic=__magic_name__				)
																			UpperCAmelCase_     : Tuple         =					vision_outputs[1]  # pooled_output
																			UpperCAmelCase_     : List[Any]         =					module.visual_projection(__magic_name__				)
																			return image_features

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



							@classmethod
							def       UpperCAmelCase__		(							cls							:       Tuple    ,       __magic_name__							:       str = None    ,       __magic_name__							:       str = None    ,       *__magic_name__							:       Union[str, Any]    ,       **__magic_name__							:       Union[str, Any]    ,       )   ->    FlaxPreTrainedModel:







													"""simple docstring"""
													UpperCAmelCase_     : Union[str, Any]         =					{
													    argument[len('''text_'''				) :]: value for argument, value in kwargs.items() if argument.startswith('''text_'''				)
													}

													UpperCAmelCase_     : List[Any]         =					{
													    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_     : List[str]         =					kwargs_text.pop('''model'''    ,       __magic_name__				)
													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_     : Optional[int]         =					AutoConfig.from_pretrained(__magic_name__				)
																									UpperCAmelCase_     : Optional[int]         =					text_config

																			UpperCAmelCase_     : Dict         =					FlaxAutoModel.from_pretrained(__magic_name__    ,       *__magic_name__    ,       **__magic_name__				)

													UpperCAmelCase_     : Union[str, Any]         =					kwargs_vision.pop('''model'''    ,       __magic_name__				)
													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_     : Tuple         =					AutoConfig.from_pretrained(__magic_name__				)
																									UpperCAmelCase_     : Union[str, Any]         =					vision_config

																			UpperCAmelCase_     : Union[str, Any]         =					FlaxAutoModel.from_pretrained(__magic_name__    ,       *__magic_name__    ,       **__magic_name__				)

													# instantiate config with corresponding kwargs
													UpperCAmelCase_     : Union[str, Any]         =					kwargs.pop('''dtype'''    ,       jnp.floataa				)
													UpperCAmelCase_     : Tuple         =					HybridCLIPConfig.from_text_vision_configs(text_model.config    ,       vision_model.config    ,       **__magic_name__				)

													# init model
													UpperCAmelCase_     : Union[str, Any]         =					cls(__magic_name__    ,       *__magic_name__    ,       dtype=__magic_name__    ,       **__magic_name__				)

													if vision_config.model_type == "clip":
																			UpperCAmelCase_     : Union[str, Any]         =					vision_model.params['''vision_model''']
																			UpperCAmelCase_     : Tuple         =					vision_model.params['''visual_projection''']['''kernel''']
													else:
																			UpperCAmelCase_     : Union[str, Any]         =					vision_model.params

													UpperCAmelCase_     : Optional[Any]         =					text_model.params

													return model





