


'''simple docstring'''
import numpy as np
import torch
import torch.nn as nn
from transformers import CLIPConfig, CLIPVisionModelWithProjection, PreTrainedModel

from ...utils import logging


__snake_case							      =     logging.get_logger(__name__)
class    lowercase	(							A__					):

		"""simple docstring"""

		_a     =				CLIPConfig

		_a     =				['CLIPEncoderLayer']




		def __init__(		self    ,   UpperCamelCase_							):

							'''simple docstring'''


							super().__init__(UpperCamelCase_							)

							UpperCamelCase__   :Union[str, Any]												= CLIPVisionModelWithProjection(config.vision_config							)

							UpperCamelCase__   :Union[str, Any]												= nn.Linear(config.vision_config.projection_dim    ,   1							)
							UpperCamelCase__   :int												= nn.Linear(config.vision_config.projection_dim    ,   1							)




		@torch.no_grad()
		def     lowerCAmelCase__				(		self    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_=0.5    ,   UpperCamelCase_=0.5							):

							'''simple docstring'''


							UpperCamelCase__   :Optional[Any]												= self.vision_model(UpperCamelCase_							)[0]

							UpperCamelCase__   :List[Any]												= self.p_head(UpperCamelCase_							)
							UpperCamelCase__   :Optional[int]												= nsfw_detected.flatten()
							UpperCamelCase__   :str												= nsfw_detected > p_threshold
							UpperCamelCase__   :List[Any]												= nsfw_detected.tolist()

							if any(UpperCamelCase_							):
												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.'''							)

							for idx, nsfw_detected_ in enumerate(UpperCamelCase_							):
												if nsfw_detected_:
																	UpperCamelCase__   :Tuple												= np.zeros(images[idx].shape							)

							UpperCamelCase__   :Optional[Any]												= self.w_head(UpperCamelCase_							)
							UpperCamelCase__   :Optional[Any]												= watermark_detected.flatten()
							UpperCamelCase__   :Dict												= watermark_detected > w_threshold
							UpperCamelCase__   :int												= watermark_detected.tolist()

							if any(UpperCamelCase_							):
												logger.warning(
												    '''Potential watermarked content was detected in one or more images. A black image will be returned instead.'''
												    ''' Try again with a different prompt and/or seed.'''							)

							for idx, watermark_detected_ in enumerate(UpperCamelCase_							):
												if watermark_detected_:
																	UpperCamelCase__   :Dict												= np.zeros(images[idx].shape							)

							return images, nsfw_detected, watermark_detected



'''simple docstring'''
from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


__snake_case							      =     logging.get_logger(__name__)

__snake_case							      =     {
    '''camembert-base''': '''https://huggingface.co/camembert-base/resolve/main/config.json''',
    '''umberto-commoncrawl-cased-v1''': (
        '''https://huggingface.co/Musixmatch/umberto-commoncrawl-cased-v1/resolve/main/config.json'''
    ),
    '''umberto-wikipedia-uncased-v1''': (
        '''https://huggingface.co/Musixmatch/umberto-wikipedia-uncased-v1/resolve/main/config.json'''
    ),
}
class    lowercase	(							A__					):

		"""simple docstring"""

		_a     =				'camembert'




		def __init__(		self    ,   UpperCamelCase_=30522    ,   UpperCamelCase_=768    ,   UpperCamelCase_=12    ,   UpperCamelCase_=12    ,   UpperCamelCase_=3072    ,   UpperCamelCase_="gelu"    ,   UpperCamelCase_=0.1    ,   UpperCamelCase_=0.1    ,   UpperCamelCase_=512    ,   UpperCamelCase_=2    ,   UpperCamelCase_=0.02    ,   UpperCamelCase_=1e-12    ,   UpperCamelCase_=1    ,   UpperCamelCase_=0    ,   UpperCamelCase_=2    ,   UpperCamelCase_="absolute"    ,   UpperCamelCase_=True    ,   UpperCamelCase_=None    ,   **UpperCamelCase_    ,   ):

							'''simple docstring'''


							super().__init__(pad_token_id=UpperCamelCase_    ,   bos_token_id=UpperCamelCase_    ,   eos_token_id=UpperCamelCase_    ,   **UpperCamelCase_							)

							UpperCamelCase__   :int												= vocab_size
							UpperCamelCase__   :Optional[int]												= hidden_size
							UpperCamelCase__   :Optional[int]												= num_hidden_layers
							UpperCamelCase__   :List[Any]												= num_attention_heads
							UpperCamelCase__   :Union[str, Any]												= hidden_act
							UpperCamelCase__   :List[Any]												= intermediate_size
							UpperCamelCase__   :int												= hidden_dropout_prob
							UpperCamelCase__   :Tuple												= attention_probs_dropout_prob
							UpperCamelCase__   :Union[str, Any]												= max_position_embeddings
							UpperCamelCase__   :Tuple												= type_vocab_size
							UpperCamelCase__   :int												= initializer_range
							UpperCamelCase__   :List[str]												= layer_norm_eps
							UpperCamelCase__   :int												= position_embedding_type
							UpperCamelCase__   :Any												= use_cache
							UpperCamelCase__   :Any												= classifier_dropout



class    lowercase	(							A__					):

		"""simple docstring"""

		@property
		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							if self.task == "multiple-choice":
												UpperCamelCase__   :List[str]												= {0: '''batch''', 1: '''choice''', 2: '''sequence'''}
							else:
												UpperCamelCase__   :Tuple												= {0: '''batch''', 1: '''sequence'''}
							return OrderedDict(
							    [
							        ('''input_ids''', dynamic_axis),
							        ('''attention_mask''', dynamic_axis),
							    ]							)