code: import numpy as np
  import torch
  import torch.nn as nn
  from transformers import CLIPConfig, CLIPVisionModel, PreTrainedModel
  
  from ...utils import logging
  
  
  UpperCAmelCase     :   List[str]					=				logging.get_logger(__name__)
  
  
  def SCREAMING_SNAKE_CASE				(     lowercase_:	Any		,						lowercase_:	List[Any]				):
         _UpperCamelCase     :       Optional[int]  						=  nn.functional.normalize(lowercase_				)
         _UpperCamelCase     :       Tuple  						=  nn.functional.normalize(lowercase_				)
         return torch.mm(lowercase_		,						normalized_text_embeds.t()				)
  
  
  
  
  
  class    __lowerCAmelCase  (       A__						):
  
  
  
   '''simple docstring'''
   _lowerCamelCase						:	str				    = CLIPConfig
  
   _lowerCamelCase						:	Optional[int]				    = ['CLIPEncoderLayer']
  
   def __init__(			self       :		List[str]       ,			lowerCamelCase       :		CLIPConfig  ) ->							Any:
          super().__init__(_lowerCAmelCase  )
  
          _UpperCamelCase     :       Tuple  						=  CLIPVisionModel(config.vision_config  )
          _UpperCamelCase     :       Dict  						=  nn.Linear(config.vision_config.hidden_size       ,			config.projection_dim       ,			bias=_lowerCAmelCase  )
  
          _UpperCamelCase     :       Tuple  						=  nn.Parameter(torch.ones(1_7       ,			config.projection_dim  )       ,			requires_grad=_lowerCAmelCase  )
          _UpperCamelCase     :       Dict  						=  nn.Parameter(torch.ones(3       ,			config.projection_dim  )       ,			requires_grad=_lowerCAmelCase  )
  
          _UpperCamelCase     :       int  						=  nn.Parameter(torch.ones(1_7  )       ,			requires_grad=_lowerCAmelCase  )
          _UpperCamelCase     :       Union[str, Any]  						=  nn.Parameter(torch.ones(3  )       ,			requires_grad=_lowerCAmelCase  )
  
   @torch.no_grad()
   def 					__snake_case					(			self       :		Optional[Any]       ,			lowerCamelCase       :		int       ,			lowerCamelCase       :		Dict  ) ->							Tuple:
          _UpperCamelCase     :       Tuple  						=  self.vision_model(_lowerCAmelCase  )[1]  # pooled_output
          _UpperCamelCase     :       Tuple  						=  self.visual_projection(_lowerCAmelCase  )
  
          # we always cast to float32 as this does not cause significant overhead and is compatible with bfloat16
          _UpperCamelCase     :       Union[str, Any]  						=  cosine_distance(_lowerCAmelCase       ,			self.special_care_embeds  ).cpu().float().numpy()
          _UpperCamelCase     :       Any  						=  cosine_distance(_lowerCAmelCase       ,			self.concept_embeds  ).cpu().float().numpy()
  
          _UpperCamelCase     :       List[str]  						=  []
          _UpperCamelCase     :       Optional[Any]  						=  image_embeds.shape[0]
          for i in range(_lowerCAmelCase  ):
                 _UpperCamelCase     :       Optional[int]  						=  {'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
                 _UpperCamelCase     :       int  						=  0.0
  
                 for concept_idx in range(len(special_cos_dist[0]  )  ):
                        _UpperCamelCase     :       Tuple  						=  special_cos_dist[i][concept_idx]
                        _UpperCamelCase     :       List[Any]  						=  self.special_care_embeds_weights[concept_idx].item()
                        _UpperCamelCase     :       str  						=  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]}  )
                               _UpperCamelCase     :       Tuple  						=  0.0_1
  
                 for concept_idx in range(len(cos_dist[0]  )  ):
                        _UpperCamelCase     :       Tuple  						=  cos_dist[i][concept_idx]
                        _UpperCamelCase     :       List[Any]  						=  self.concept_embeds_weights[concept_idx].item()
                        _UpperCamelCase     :       Dict  						=  round(concept_cos - concept_threshold + adjustment       ,			3  )
                        if result_img["concept_scores"][concept_idx] > 0:
                               result_img["bad_concepts"].append(_lowerCAmelCase  )
  
                 result.append(_lowerCAmelCase  )
  
          _UpperCamelCase     :       str  						=  [len(res['bad_concepts']  ) > 0 for res in result]
  
          for idx, has_nsfw_concept in enumerate(_lowerCAmelCase  ):
                 if has_nsfw_concept:
                        if torch.is_tensor(_lowerCAmelCase  ) or torch.is_tensor(images[0]  ):
                               _UpperCamelCase     :       str  						=  torch.zeros_like(images[idx]  )  # black image
                        else:
                               _UpperCamelCase     :       str  						=  np.zeros(images[idx].shape  )  # black image
  
          if any(_lowerCAmelCase  ):
                 logger.warning(
                     'Potential NSFW content was detected in one or more images. A black image will be returned instead.'
                     ' Try again with a different prompt and/or seed.'  )
  
          return images, has_nsfw_concepts
  
   @torch.no_grad()
   def 					__snake_case					(			self       :		Tuple       ,			lowerCamelCase       :		torch.FloatTensor       ,			lowerCamelCase       :		torch.FloatTensor  ) ->							List[str]:
          _UpperCamelCase     :       List[Any]  						=  self.vision_model(_lowerCAmelCase  )[1]  # pooled_output
          _UpperCamelCase     :       List[Any]  						=  self.visual_projection(_lowerCAmelCase  )
  
          _UpperCamelCase     :       Dict  						=  cosine_distance(_lowerCAmelCase       ,			self.special_care_embeds  )
          _UpperCamelCase     :       Optional[Any]  						=  cosine_distance(_lowerCAmelCase       ,			self.concept_embeds  )
  
          # increase this value to create a stronger `nsfw` filter
          # at the cost of increasing the possibility of filtering benign images
          _UpperCamelCase     :       Optional[int]  						=  0.0
  
          _UpperCamelCase     :       List[Any]  						=  special_cos_dist - self.special_care_embeds_weights + adjustment
          # special_scores = special_scores.round(decimals=3)
          _UpperCamelCase     :       Optional[Any]  						=  torch.any(special_scores > 0       ,			dim=1  )
          _UpperCamelCase     :       Union[str, Any]  						=  special_care * 0.0_1
          _UpperCamelCase     :       int  						=  special_adjustment.unsqueeze(1  ).expand(-1       ,			cos_dist.shape[1]  )
  
          _UpperCamelCase     :       int  						=  (cos_dist - self.concept_embeds_weights) + special_adjustment
          # concept_scores = concept_scores.round(decimals=3)
          _UpperCamelCase     :       str  						=  torch.any(concept_scores > 0       ,			dim=1  )
  
          _UpperCamelCase     :       str  						=  0.0  # black image
  
          return images, has_nsfw_concepts
  
  
  
  
style_context: import math
  from collections.abc import Generator
  
  
  def SCREAMING_SNAKE_CASE				(     lowercase_:	int				):
         _UpperCamelCase     :       Generator  						=  (i for i in range(1		,						(max_n + 1)				))
         for i in (n for n in numbers if n > 1):
                for j in range(2		,						lowercase_				):
                       if (i % j) == 0:
                              break
                else:
                       yield i
  
  
  def SCREAMING_SNAKE_CASE				(     lowercase_:	int				):
         _UpperCamelCase     :       Generator  						=  (i for i in range(1		,						(max_n + 1)				))
         for i in (n for n in numbers if n > 1):
                # only need to check for factors up to sqrt(i)
                _UpperCamelCase     :       Any  						=  int(math.sqrt(lowercase_				)				) + 1
                for j in range(2		,						lowercase_				):
                       if (i % j) == 0:
                              break
                else:
                       yield i
  
  
  def SCREAMING_SNAKE_CASE				(     lowercase_:	int				):
         _UpperCamelCase     :       Generator  						=  (i for i in range(1		,						(max_n + 1)		,						2				))
         # It's useless to test even numbers as they will not be prime
         if max_n > 2:
                yield 2  # Because 2 will not be tested, it's necessary to yield it now
         for i in (n for n in numbers if n > 1):
                _UpperCamelCase     :       Tuple  						=  int(math.sqrt(lowercase_				)				) + 1
                for j in range(3		,						lowercase_		,						2				):
                       # As we removed the even numbers, we don't need them now
                       if (i % j) == 0:
                              break
                else:
                       yield i
  
  
  def SCREAMING_SNAKE_CASE				(     ):
         from timeit import timeit
  
         _UpperCamelCase     :       Optional[Any]  						=  'from __main__ import slow_primes, primes, fast_primes'
         print(timeit('slow_primes(1_000_000_000_000)'		,						setup=lowercase_		,						number=1000000				)				)
         print(timeit('primes(1_000_000_000_000)'		,						setup=lowercase_		,						number=1000000				)				)
         print(timeit('fast_primes(1_000_000_000_000)'		,						setup=lowercase_		,						number=1000000				)				)
  
  
  if __name__ == "__main__":
   UpperCAmelCase					=				int(input('''Calculate primes up to:\n>> ''').strip())
   for ret in primes(number):
    print(ret)
   benchmark()
  
  
  
  