





'''simple docstring'''

from typing import Optional, Tuple

import jax
import jax.numpy as jnp
from flax import linen as nn
from flax.core.frozen_dict import FrozenDict
from transformers import CLIPConfig, FlaxPreTrainedModel
from transformers.models.clip.modeling_flax_clip import FlaxCLIPVisionModule

def     __magic_name__							(				__UpperCAmelCase				,						__UpperCAmelCase				,						__UpperCAmelCase=1e-1_2   )    ->       Any:

   '''simple docstring'''







   __SCREAMING_SNAKE_CASE   				=							jnp.divide(emb_a.T				,						jnp.clip(jnp.linalg.norm(__UpperCAmelCase				,						axis=1   )				,						a_min=__UpperCAmelCase   )   ).T
   __SCREAMING_SNAKE_CASE   				=							jnp.divide(emb_a.T				,						jnp.clip(jnp.linalg.norm(__UpperCAmelCase				,						axis=1   )				,						a_min=__UpperCAmelCase   )   ).T
   return jnp.matmul(__UpperCAmelCase				,						norm_emb_a.T   )







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





   def   UpperCAmelCase__  (       self					:      int     ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE   				=							FlaxCLIPVisionModule(self.config.vision_config     )
      __SCREAMING_SNAKE_CASE   				=							nn.Dense(self.config.projection_dim					,use_bias=lowerCamelCase					,dtype=self.dtype     )

      __SCREAMING_SNAKE_CASE   				=							self.param("""concept_embeds"""					,jax.nn.initializers.ones					,(17, self.config.projection_dim)     )
      __SCREAMING_SNAKE_CASE   				=							self.param(
          """special_care_embeds"""					,jax.nn.initializers.ones					,(3, self.config.projection_dim)     )

      __SCREAMING_SNAKE_CASE   				=							self.param("""concept_embeds_weights"""					,jax.nn.initializers.ones					,(17,)     )
      __SCREAMING_SNAKE_CASE   				=							self.param("""special_care_embeds_weights"""					,jax.nn.initializers.ones					,(3,)     )





   def __call__(       self					:      Union[str, Any]					,lowerCamelCase					:      Union[str, Any]     ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE   				=							self.vision_model(lowerCamelCase     )[1]
      __SCREAMING_SNAKE_CASE   				=							self.visual_projection(lowerCamelCase     )

      __SCREAMING_SNAKE_CASE   				=							jax_cosine_distance(lowerCamelCase					,self.special_care_embeds     )
      __SCREAMING_SNAKE_CASE   				=							jax_cosine_distance(lowerCamelCase					,self.concept_embeds     )

      # increase this value to create a stronger `nfsw` filter
      # at the cost of increasing the possibility of filtering benign image inputs
      __SCREAMING_SNAKE_CASE   				=							0.0

      __SCREAMING_SNAKE_CASE   				=							special_cos_dist - self.special_care_embeds_weights[None, :] + adjustment
      __SCREAMING_SNAKE_CASE   				=							jnp.round(lowerCamelCase					,3     )
      __SCREAMING_SNAKE_CASE   				=							jnp.any(special_scores > 0					,axis=1					,keepdims=lowerCamelCase     )
      # Use a lower threshold if an image has any special care concept
      __SCREAMING_SNAKE_CASE   				=							is_special_care * 0.01

      __SCREAMING_SNAKE_CASE   				=							cos_dist - self.concept_embeds_weights[None, :] + special_adjustment
      __SCREAMING_SNAKE_CASE   				=							jnp.round(lowerCamelCase					,3     )
      __SCREAMING_SNAKE_CASE   				=							jnp.any(concept_scores > 0					,axis=1     )

      return has_nsfw_concepts







class __a			( _snake_case      ):
   __UpperCamelCase :			Union[str, Any]						   =						CLIPConfig
   __UpperCamelCase :			Dict						   =						'clip_input'
   __UpperCamelCase :			Optional[Any]						   =						FlaxStableDiffusionSafetyCheckerModule





   def __init__(       self					:      Union[str, Any]					,lowerCamelCase					:      CLIPConfig					,lowerCamelCase					:      Optional[Tuple] = None					,lowerCamelCase					:      int = 0					,lowerCamelCase					:      jnp.dtype = jnp.floataa					,lowerCamelCase					:      bool = True					,**lowerCamelCase					:      str					,):

      '''simple docstring'''

      if input_shape is None:
         __SCREAMING_SNAKE_CASE   				=							(1, 224, 224, 3)
      __SCREAMING_SNAKE_CASE   				=							self.module_class(config=lowerCamelCase					,dtype=lowerCamelCase					,**lowerCamelCase     )
      super().__init__(lowerCamelCase					,lowerCamelCase					,input_shape=lowerCamelCase					,seed=lowerCamelCase					,dtype=lowerCamelCase					,_do_init=_do_init     )





   def   UpperCAmelCase__  (       self					:      str					,lowerCamelCase					:      jax.random.KeyArray					,lowerCamelCase					:      Tuple					,lowerCamelCase					:      FrozenDict = None     ):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE   				=							jax.random.normal(lowerCamelCase					,lowerCamelCase     )

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

      __SCREAMING_SNAKE_CASE   				=							self.module.init(lowerCamelCase					,lowerCamelCase     )["""params"""]

      return random_params





   def __call__(       self					:      List[str]					,lowerCamelCase					:      Optional[Any]					,lowerCamelCase					:      dict = None					,):

      '''simple docstring'''

      __SCREAMING_SNAKE_CASE   				=							jnp.transpose(lowerCamelCase					,(0, 2, 3, 1)     )

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












'''simple docstring'''

from typing import TYPE_CHECKING

# rely on isort to merge the imports
from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


a   	=    {
    "configuration_informer": [
        "INFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP",
        "InformerConfig",
    ],
}

try:
    if not is_torch_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    a   	=    [
        "INFORMER_PRETRAINED_MODEL_ARCHIVE_LIST",
        "InformerForPrediction",
        "InformerModel",
        "InformerPreTrainedModel",
    ]


if TYPE_CHECKING:
    from .configuration_informer import INFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP, InformerConfig

    try:
        if not is_torch_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_informer import (
            INFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
            InformerForPrediction,
            InformerModel,
            InformerPreTrainedModel,
        )

else:
    import sys

    a   	=    _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)





