






"""simple docstring"""
import torch
import torch.nn as nn
from transformers import CLIPConfig, CLIPVisionModel, PreTrainedModel

from ...utils import logging


snake_case : List[Any]     		=		logging.get_logger(__name__)


def 							A						(				__snake_case: List[Any] ,     __snake_case: str  )    ->		List[str]:

       """simple docstring"""





       __magic_name__      				=    nn.functional.normalize(__snake_case  )
       __magic_name__      				=    nn.functional.normalize(__snake_case  )
       return torch.mm(__snake_case ,     normalized_text_embeds.t()  )






class        UpperCamelCase__ (				a_):







    """simple docstring"""
    __UpperCAmelCase           = CLIPConfig

    __UpperCAmelCase           = ["""CLIPEncoderLayer"""]







    def __init__(		self :	Union[str, Any]				,    UpperCamelCase_ :	CLIPConfig ):





           '''simple docstring'''

           super().__init__(UpperCamelCase_ )

           __magic_name__      				=    CLIPVisionModel(config.vision_config )
           __magic_name__      				=    nn.Linear(config.vision_config.hidden_size				,    config.projection_dim				,    bias=UpperCamelCase_ )

           __magic_name__      				=    nn.Parameter(torch.ones(1_7				,    config.projection_dim )				,    requires_grad=UpperCamelCase_ )
           __magic_name__      				=    nn.Parameter(torch.ones(3				,    config.projection_dim )				,    requires_grad=UpperCamelCase_ )

           __magic_name__      				=    nn.Parameter(torch.ones(1_7 )				,    requires_grad=UpperCamelCase_ )
           __magic_name__      				=    nn.Parameter(torch.ones(3 )				,    requires_grad=UpperCamelCase_ )







    @torch.no_grad()
    def 				a__			(		self :	int				,    UpperCamelCase_ :	int				,    UpperCamelCase_ :	List[str] ):





           '''simple docstring'''

           __magic_name__      				=    self.vision_model(UpperCamelCase_ )[1]  # pooled_output
           __magic_name__      				=    self.visual_projection(UpperCamelCase_ )

           # we always cast to float32 as this does not cause significant overhead and is compatible with bfloat16
           __magic_name__      				=    cosine_distance(UpperCamelCase_				,    self.special_care_embeds ).cpu().float().numpy()
           __magic_name__      				=    cosine_distance(UpperCamelCase_				,    self.concept_embeds ).cpu().float().numpy()

           __magic_name__      				=    []
           __magic_name__      				=    image_embeds.shape[0]
           for i in range(UpperCamelCase_ ):
                  __magic_name__      				=    {'special_scores': {}, 'special_care': [], 'concept_scores': {}, 'bad_concepts': []}

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

                  for concept_idx in range(len(special_cos_dist[0] ) ):
                         __magic_name__      				=    special_cos_dist[i][concept_idx]
                         __magic_name__      				=    self.special_care_embeds_weights[concept_idx].item()
                         __magic_name__      				=    round(concept_cos - concept_threshold + adjustment				,    3 )
                         if result_img["special_scores"][concept_idx] > 0:
                                result_img["special_care"].append({concept_idx, result_img['special_scores'][concept_idx]} )
                                __magic_name__      				=    0.01

                  for concept_idx in range(len(cos_dist[0] ) ):
                         __magic_name__      				=    cos_dist[i][concept_idx]
                         __magic_name__      				=    self.concept_embeds_weights[concept_idx].item()
                         __magic_name__      				=    round(concept_cos - concept_threshold + adjustment				,    3 )
                         if result_img["concept_scores"][concept_idx] > 0:
                                result_img["bad_concepts"].append(UpperCamelCase_ )

                  result.append(UpperCamelCase_ )

           __magic_name__      				=    [len(res['bad_concepts'] ) > 0 for res in result]

           return images, has_nsfw_concepts







    @torch.no_grad()
    def 				a__			(		self :	List[Any]				,    UpperCamelCase_ :	torch.FloatTensor				,    UpperCamelCase_ :	torch.FloatTensor ):





           '''simple docstring'''

           __magic_name__      				=    self.vision_model(UpperCamelCase_ )[1]  # pooled_output
           __magic_name__      				=    self.visual_projection(UpperCamelCase_ )

           __magic_name__      				=    cosine_distance(UpperCamelCase_				,    self.special_care_embeds )
           __magic_name__      				=    cosine_distance(UpperCamelCase_				,    self.concept_embeds )

           # increase this value to create a stronger `nsfw` filter
           # at the cost of increasing the possibility of filtering benign images
           __magic_name__      				=    0.0

           __magic_name__      				=    special_cos_dist - self.special_care_embeds_weights + adjustment
           # special_scores = special_scores.round(decimals=3)
           __magic_name__      				=    torch.any(special_scores > 0				,    dim=1 )
           __magic_name__      				=    special_care * 0.01
           __magic_name__      				=    special_adjustment.unsqueeze(1 ).expand(-1				,    cos_dist.shape[1] )

           __magic_name__      				=    (cos_dist - self.concept_embeds_weights) + special_adjustment
           # concept_scores = concept_scores.round(decimals=3)
           __magic_name__      				=    torch.any(concept_scores > 0				,    dim=1 )

           return images, has_nsfw_concepts







"""simple docstring"""
def 							A						(				__snake_case: int  )    ->		int:

       """simple docstring"""





       if divisor % 5 == 0 or divisor % 2 == 0:
              return 0
       __magic_name__      				=    1
       __magic_name__      				=    1
       while repunit:
              __magic_name__      				=    (1_0 * repunit + 1) % divisor
              repunit_index += 1
       return repunit_index


def 							A						(				__snake_case: int = 1_0_0_0_0_0_0  )    ->		int:

       """simple docstring"""





       __magic_name__      				=    limit - 1
       if divisor % 2 == 0:
              divisor += 1
       while least_divisible_repunit(__snake_case  ) <= limit:
              divisor += 2
       return divisor


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