






'''simple docstring'''



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

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


__UpperCamelCase      :       Union[str, Any]      			=      logging.get_logger(__name__)  # pylint: disable=invalid-name
class 							__SCREAMING_SNAKE_CASE       (							_lowerCAmelCase     ):




      def __init__(  self ,   lowerCamelCase ,   lowerCamelCase=768      )							->Dict:



         '''simple docstring'''
         super().__init__(lowerCamelCase      )
         __a				     =    proj_size

         __a				     =    CLIPVisionModel(lowerCamelCase      )
         __a				     =    PaintByExampleMapper(lowerCamelCase      )
         __a				     =    nn.LayerNorm(config.hidden_size      )
         __a				     =    nn.Linear(config.hidden_size ,   self.proj_size      )

         # uncondition for scaling
         __a				     =    nn.Parameter(torch.randn((1, 1, self.proj_size)      )      )






      def  __UpperCamelCase							(  self ,   lowerCamelCase ,   lowerCamelCase=False      )							->List[Any]:



         '''simple docstring'''
         __a				     =    self.model(pixel_values=lowerCamelCase      )
         __a				     =    clip_output.pooler_output
         __a				     =    self.mapper(latent_states[:, None]      )
         __a				     =    self.final_layer_norm(lowerCamelCase      )
         __a				     =    self.proj_out(lowerCamelCase      )
         if return_uncond_vector:
            return latent_states, self.uncond_vector

         return latent_states







class 							__SCREAMING_SNAKE_CASE       (							nn.Module     ):




      def __init__(  self ,   lowerCamelCase      )							->Tuple:



         '''simple docstring'''
         super().__init__()
         __a				     =    (config.num_hidden_layers + 1) // 5
         __a				     =    config.hidden_size
         __a				     =    1
         __a				     =    nn.ModuleList(
             [
                 BasicTransformerBlock(lowerCamelCase ,   lowerCamelCase ,   lowerCamelCase ,   activation_fn='gelu' ,   attention_bias=lowerCamelCase      )
                 for _ in range(lowerCamelCase      )
             ]      )






      def  __UpperCamelCase							(  self ,   lowerCamelCase      )							->List[str]:



         '''simple docstring'''
         for block in self.blocks:
            __a				     =    block(lowerCamelCase      )

         return hidden_states







'''simple docstring'''



__UpperCamelCase      :       Optional[Any]      			=      [
    """DownloadConfig""",
    """DownloadManager""",
    """DownloadMode""",
    """StreamingDownloadManager""",
]

from .download_config import DownloadConfig
from .download_manager import DownloadManager, DownloadMode
from .streaming_download_manager import StreamingDownloadManager