





import torch
from torch import nn
from transformers import CLIPPreTrainedModel, CLIPVisionModel

from ...models.attention import BasicTransformerBlock
from ...utils import logging


__UpperCamelCase:	Dict = logging.get_logger(__name__)  # pylint: disable=invalid-name


class       __lowerCAmelCase					(       _UpperCamelCase      ):


	'''simple docstring'''





	def __init__(						self:						Optional[int],					lowerCamelCase_:						Optional[int],					lowerCamelCase_:						Union[str, Any]=768			):
			super().__init__(lowerCamelCase_			)
			lowercase__					:      Dict      =		proj_size

			lowercase__					:      List[Any]      =		CLIPVisionModel(lowerCamelCase_			)
			lowercase__					:      List[str]      =		PaintByExampleMapper(lowerCamelCase_			)
			lowercase__					:      Dict      =		nn.LayerNorm(config.hidden_size			)
			lowercase__					:      Dict      =		nn.Linear(config.hidden_size,					self.proj_size			)

			# uncondition for scaling
			lowercase__					:      Union[str, Any]      =		nn.Parameter(torch.randn((1, 1, self.proj_size)			)			)





	def    snake_case__(						self:						str,					lowerCamelCase_:						Optional[Any],					lowerCamelCase_:						Optional[Any]=False			):
			lowercase__					:      Union[str, Any]      =		self.model(pixel_values=lowerCamelCase_			)
			lowercase__					:      List[Any]      =		clip_output.pooler_output
			lowercase__					:      str      =		self.mapper(latent_states[:, None]			)
			lowercase__					:      Union[str, Any]      =		self.final_layer_norm(lowerCamelCase_			)
			lowercase__					:      int      =		self.proj_out(lowerCamelCase_			)
			if return_uncond_vector:
					return latent_states, self.uncond_vector

			return latent_states


class       __lowerCAmelCase					(       nn.Module      ):


	'''simple docstring'''





	def __init__(						self:						List[Any],					lowerCamelCase_:						int			):
			super().__init__()
			lowercase__					:      str      =		(config.num_hidden_layers + 1) // 5
			lowercase__					:      int      =		config.hidden_size
			lowercase__					:      List[Any]      =		1
			lowercase__					:      Optional[int]      =		nn.ModuleList(
			    [
			        BasicTransformerBlock(lowerCamelCase_,					lowerCamelCase_,					lowerCamelCase_,					activation_fn='gelu',					attention_bias=lowerCamelCase_			)
			        for _ in range(lowerCamelCase_			)
			    ]			)





	def    snake_case__(						self:						List[Any],					lowerCamelCase_:						Dict			):
			for block in self.blocks:
					lowercase__					:      Dict      =		block(lowerCamelCase_			)

			return hidden_states









from dataclasses import dataclass
from enum import Enum
from typing import List, Optional, Union

import numpy as np
import PIL
from PIL import Image

from ...utils import BaseOutput, is_torch_available, is_transformers_available


@dataclass
class       __lowerCAmelCase					(       _UpperCamelCase      ):


	'''simple docstring'''





	_A													=				42
	_A													=				42


if is_transformers_available() and is_torch_available():
			from .pipeline_semantic_stable_diffusion import SemanticStableDiffusionPipeline


