






"""simple docstring"""







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

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


lowerCAmelCase_	:    Optional[int]            =      logging.get_logger(__name__)  # pylint: disable=invalid-name





class   UpperCamelCase_ (       a_  ):



  def __init__(      self ,		snake_case__ ,		snake_case__=7_68				)			->			List[Any]:



         """simple docstring"""





         super().__init__(snake_case__				)
         UpperCAmelCase	    =			proj_size

         UpperCAmelCase	    =			CLIPVisionModel(snake_case__				)
         UpperCAmelCase	    =			PaintByExampleMapper(snake_case__				)
         UpperCAmelCase	    =			nn.LayerNorm(config.hidden_size				)
         UpperCAmelCase	    =			nn.Linear(config.hidden_size ,		self.proj_size				)

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



  def 		UpperCamelCase_				(      self ,		snake_case__ ,		snake_case__=False				)			->			int:



         """simple docstring"""





         UpperCAmelCase	    =			self.model(pixel_values=snake_case__				)
         UpperCAmelCase	    =			clip_output.pooler_output
         UpperCAmelCase	    =			self.mapper(latent_states[:, None]				)
         UpperCAmelCase	    =			self.final_layer_norm(snake_case__				)
         UpperCAmelCase	    =			self.proj_out(snake_case__				)
         if return_uncond_vector:
                return latent_states, self.uncond_vector

         return latent_states





class   UpperCamelCase_ (       nn.Module  ):



  def __init__(      self ,		snake_case__				)			->			Any:



         """simple docstring"""





         super().__init__()
         UpperCAmelCase	    =			(config.num_hidden_layers + 1) // 5
         UpperCAmelCase	    =			config.hidden_size
         UpperCAmelCase	    =			1
         UpperCAmelCase	    =			nn.ModuleList(
             [
                 BasicTransformerBlock(snake_case__ ,		snake_case__ ,		snake_case__ ,		activation_fn="""gelu""" ,		attention_bias=snake_case__				)
                 for _ in range(snake_case__				)
             ]				)



  def 		UpperCamelCase_				(      self ,		snake_case__				)			->			Any:



         """simple docstring"""





         for block in self.blocks:
                UpperCAmelCase	    =			block(snake_case__				)

         return hidden_states








"""simple docstring"""







def       _lowerCAmelCase       (      lowerCAmelCase		):







       '''simple docstring'''
       if not isinstance(lowerCAmelCase	,      lowerCAmelCase		):
              UpperCAmelCase	    =			F'''Input value of [number={number}] must be an integer'''
              raise TypeError(lowerCAmelCase		)
       if number < 0:
              return False
       UpperCAmelCase	    =			number * number
       while number > 0:
              if number % 10 != number_square % 10:
                     return False
              number //= 10
              number_square //= 10
       return True


if __name__ == "__main__":
 import doctest

 doctest.testmod()
