



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

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


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



class       UpperCAmelCase__(							lowerCamelCase	):

   '''simple docstring'''




   def __init__(						self  :			str			,				lowerCAmelCase  :			str			,				lowerCAmelCase  :			int=7_68)	->				Dict:




         """simple docstring"""

         super().__init__(lowerCAmelCase)
         lowercase__     =  proj_size

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

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



   def 			UpperCAmelCase		(						self  :			Any			,				lowerCAmelCase  :			Optional[Any]			,				lowerCAmelCase  :			int=False)	->				Optional[int]:




         """simple docstring"""

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

         return latent_states



class       UpperCAmelCase__(							nn.Module	):

   '''simple docstring'''




   def __init__(						self  :			Optional[Any]			,				lowerCAmelCase  :			List[Any])	->				str:




         """simple docstring"""

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



   def 			UpperCAmelCase		(						self  :			Any			,				lowerCAmelCase  :			Union[str, Any])	->				str:




         """simple docstring"""

         for block in self.blocks:
               lowercase__     =  block(lowerCAmelCase)

         return hidden_states





def   _lowerCAmelCase   (						A__						,  A__						,  A__	):
      if principal <= 0:
            raise Exception('Principal borrowed must be > 0'	)
      if rate_per_annum < 0:
            raise Exception('Rate of interest must be >= 0'	)
      if years_to_repay <= 0 or not isinstance(A__						,  A__	):
            raise Exception('Years to repay must be an integer > 0'	)

      # Yearly rate is divided by 12 to get monthly rate
      lowercase__     =  rate_per_annum / 12

      # Years to repay is multiplied by 12 to get number of payments as payment is monthly
      lowercase__     =  years_to_repay * 12

      return (
          principal
          * rate_per_month
          * (1 + rate_per_month) ** number_of_payments
          / ((1 + rate_per_month) ** number_of_payments - 1)
      )


if __name__ == "__main__":
       import doctest

       doctest.testmod()
