





"""simple docstring"""





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

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


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

class 		lowercase					(					_UpperCAmelCase					):





      def __init__(       self      ,						lowercase      ,						lowercase=768 )		->     int:
            super().__init__(lowercase )
            lowerCAmelCase  						=       proj_size

            lowerCAmelCase  						=       CLIPVisionModel(lowercase )
            lowerCAmelCase  						=       PaintByExampleMapper(lowercase )
            lowerCAmelCase  						=       nn.LayerNorm(config.hidden_size )
            lowerCAmelCase  						=       nn.Linear(config.hidden_size      ,						self.proj_size )

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





      def     _snake_case			(       self      ,						lowercase      ,						lowercase=False )		->     Optional[Any]:
            lowerCAmelCase  						=       self.model(pixel_values=lowercase )
            lowerCAmelCase  						=       clip_output.pooler_output
            lowerCAmelCase  						=       self.mapper(latent_states[:, None] )
            lowerCAmelCase  						=       self.final_layer_norm(lowercase )
            lowerCAmelCase  						=       self.proj_out(lowercase )
            if return_uncond_vector:
                  return latent_states, self.uncond_vector

            return latent_states







class 		lowercase					(					nn.Module					):





      def __init__(       self      ,						lowercase )		->     str:
            super().__init__()
            lowerCAmelCase  						=       (config.num_hidden_layers + 1) // 5
            lowerCAmelCase  						=       config.hidden_size
            lowerCAmelCase  						=       1
            lowerCAmelCase  						=       nn.ModuleList(
                [
                    BasicTransformerBlock(lowercase      ,						lowercase      ,						lowercase      ,						activation_fn="""gelu"""      ,						attention_bias=lowercase )
                    for _ in range(lowercase )
                ] )





      def     _snake_case			(       self      ,						lowercase )		->     Optional[int]:
            for block in self.blocks:
                  lowerCAmelCase  						=       block(lowercase )

            return hidden_states











def 		UpperCamelCase	(   snake_case__       :    int       ,     snake_case__       :    int	)	->     int:
   return int(input_a == input_a == 0	)
def 		UpperCamelCase	(   )	->     None:
   print('Truth Table of NOR Gate:'	)
   print('|   Input 1   |  Input 2  | Output |'	)
   print(F"""|      0      |    0      |  {nor_gate(0       ,     0	)}     |"""	)
   print(F"""|      0      |    1      |  {nor_gate(0       ,     1	)}     |"""	)
   print(F"""|      1      |    0      |  {nor_gate(1       ,     0	)}     |"""	)
   print(F"""|      1      |    1      |  {nor_gate(1       ,     1	)}     |"""	)


if __name__ == "__main__":
    import doctest

    doctest.testmod()
    main()



