




"""simple docstring"""

import torch
import torch.nn as nn
from transformers import CLIPConfig, CLIPVisionModel, PreTrainedModel

from ...utils import logging


_lowerCamelCase  :			List[str]        =       logging.get_logger(__name__)

def 		lowercase_      (		_UpperCAmelCase  ,      _UpperCAmelCase	):




	"""simple docstring"""






	A_  :				str	   =		nn.functional.normalize(_UpperCAmelCase	)
	A_  :				str	   =		nn.functional.normalize(_UpperCAmelCase	)
	return torch.mm(_UpperCAmelCase  ,      normalized_text_embeds.t()	)

class        lowercase      (    __UpperCAmelCase):
				__lowerCAmelCase    :    Optional[int]         =   CLIPConfig

				__lowerCAmelCase    :    Optional[int]         =   ["""CLIPEncoderLayer"""]







				def __init__(							self   :					List[Any]      ,     _lowerCamelCase   :					CLIPConfig       ):



					"""simple docstring"""

					super().__init__(_lowerCamelCase       )

					A_  :				Tuple	   =		CLIPVisionModel(config.vision_config       )
					A_  :				Optional[Any]	   =		nn.Linear(config.vision_config.hidden_size      ,     config.projection_dim      ,     bias=_lowerCamelCase       )

					A_  :				int	   =		nn.Parameter(torch.ones(17      ,     config.projection_dim       )      ,     requires_grad=_lowerCamelCase       )
					A_  :				Optional[int]	   =		nn.Parameter(torch.ones(3      ,     config.projection_dim       )      ,     requires_grad=_lowerCamelCase       )

					A_  :				Any	   =		nn.Parameter(torch.ones(17       )      ,     requires_grad=_lowerCamelCase       )
					A_  :				List[str]	   =		nn.Parameter(torch.ones(3       )      ,     requires_grad=_lowerCamelCase       )







				@torch.no_grad()
				def 					a_  (							self   :					List[Any]      ,     _lowerCamelCase   :					Optional[Any]      ,     _lowerCamelCase   :					Optional[Any]       ):



					"""simple docstring"""

					A_  :				Union[str, Any]	   =		self.vision_model(_lowerCamelCase       )[1]  # pooled_output
					A_  :				Any	   =		self.visual_projection(_lowerCamelCase       )

					# we always cast to float32 as this does not cause significant overhead and is compatible with bfloat16
					A_  :				Union[str, Any]	   =		cosine_distance(_lowerCamelCase      ,     self.special_care_embeds       ).cpu().float().numpy()
					A_  :				List[str]	   =		cosine_distance(_lowerCamelCase      ,     self.concept_embeds       ).cpu().float().numpy()

					A_  :				int	   =		[]
					A_  :				Union[str, Any]	   =		image_embeds.shape[0]
					for i in range(_lowerCamelCase       ):
						A_  :				str	   =		{'''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
						A_  :				Optional[int]	   =		0.0

						for concept_idx in range(len(special_cos_dist[0]       )       ):
							A_  :				Union[str, Any]	   =		special_cos_dist[i][concept_idx]
							A_  :				Optional[Any]	   =		self.special_care_embeds_weights[concept_idx].item()
							A_  :				List[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]}       )
								A_  :				str	   =		0.01

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

						result.append(_lowerCamelCase       )

					A_  :				Union[str, Any]	   =		[len(res['''bad_concepts''']       ) > 0 for res in result]

					return images, has_nsfw_concepts







				@torch.no_grad()
				def 					a_  (							self   :					Union[str, Any]      ,     _lowerCamelCase   :					torch.FloatTensor      ,     _lowerCamelCase   :					torch.FloatTensor       ):



					"""simple docstring"""

					A_  :				str	   =		self.vision_model(_lowerCamelCase       )[1]  # pooled_output
					A_  :				Tuple	   =		self.visual_projection(_lowerCamelCase       )

					A_  :				Optional[Any]	   =		cosine_distance(_lowerCamelCase      ,     self.special_care_embeds       )
					A_  :				Optional[int]	   =		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
					A_  :				Optional[Any]	   =		0.0

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

					A_  :				Optional[Any]	   =		(cos_dist - self.concept_embeds_weights) + special_adjustment
					# concept_scores = concept_scores.round(decimals=3)
					A_  :				int	   =		torch.any(concept_scores > 0      ,     dim=1       )

					return images, has_nsfw_concepts












"""simple docstring"""

import random

from .binary_exp_mod import bin_exp_mod

def 		lowercase_      (		_UpperCAmelCase  ,      _UpperCAmelCase=1000	):




	"""simple docstring"""






	if n < 2:
		return False

	if n % 2 == 0:
		return n == 2

	# this means n is odd
	A_  :				List[Any]	   =		n - 1
	A_  :				Dict	   =		0
	while d % 2 == 0:
		d /= 2
		exp += 1

	# n - 1=d*(2**exp)
	A_  :				Optional[Any]	   =		0
	while count < prec:
		A_  :				Optional[int]	   =		random.randint(2  ,      n - 1	)
		A_  :				Any	   =		bin_exp_mod(_UpperCAmelCase  ,      _UpperCAmelCase  ,      _UpperCAmelCase	)
		if b != 1:
			A_  :				Dict	   =		True
			for _ in range(_UpperCAmelCase	):
				if b == n - 1:
					A_  :				Optional[int]	   =		False
					break
				A_  :				Any	   =		b * b
				b %= n
			if flag:
				return False
			count += 1
	return True


if __name__ == "__main__":
		_lowerCamelCase  :			List[str]        =       abs(int(input('Enter bound : ').strip()))
		print('Here\'s the list of primes:')
		print(', '.join(str(i) for i in range(n + 1) if is_prime_big(i)))





