'''simple docstring'''




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

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


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






class 		__A       (__magic_name__   ):






       def __init__(      self				,     UpperCamelCase_				,     UpperCamelCase_=7_68      ):
              super().__init__(UpperCamelCase_      )
              __UpperCAmelCase  :				Optional[Any]       				=		proj_size

              __UpperCAmelCase  :				Any       				=		CLIPVisionModel(UpperCamelCase_      )
              __UpperCAmelCase  :				Union[str, Any]       				=		PaintByExampleMapper(UpperCamelCase_      )
              __UpperCAmelCase  :				Tuple       				=		nn.LayerNorm(config.hidden_size      )
              __UpperCAmelCase  :				Optional[int]       				=		nn.Linear(config.hidden_size				,     self.proj_size      )

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







       def 			_snake_case						(      self				,     UpperCamelCase_				,     UpperCamelCase_=False      ):
              __UpperCAmelCase  :				List[str]       				=		self.model(pixel_values=UpperCamelCase_      )
              __UpperCAmelCase  :				str       				=		clip_output.pooler_output
              __UpperCAmelCase  :				Any       				=		self.mapper(latent_states[:, None]      )
              __UpperCAmelCase  :				str       				=		self.final_layer_norm(UpperCamelCase_      )
              __UpperCAmelCase  :				List[Any]       				=		self.proj_out(UpperCamelCase_      )
              if return_uncond_vector:
                     return latent_states, self.uncond_vector

              return latent_states






class 		__A       (nn.Module   ):






       def __init__(      self				,     UpperCamelCase_      ):
              super().__init__()
              __UpperCAmelCase  :				Optional[Any]       				=		(config.num_hidden_layers + 1) // 5
              __UpperCAmelCase  :				Dict       				=		config.hidden_size
              __UpperCAmelCase  :				Any       				=		1
              __UpperCAmelCase  :				Tuple       				=		nn.ModuleList(
                  [
                      BasicTransformerBlock(UpperCamelCase_				,     UpperCamelCase_				,     UpperCamelCase_				,     activation_fn="gelu"				,     attention_bias=UpperCamelCase_      )
                      for _ in range(UpperCamelCase_      )
                  ]      )







       def 			_snake_case						(      self				,     UpperCamelCase_      ):
              for block in self.blocks:
                     __UpperCAmelCase  :				Optional[Any]       				=		block(UpperCamelCase_      )

              return hidden_states







'''simple docstring'''




def _lowercase	(      lowerCamelCase__							,    lowerCamelCase__						)					->       float:





       """simple docstring"""


       if discount_rate < 0:
              raise ValueError("Discount rate cannot be negative"						)
       if not cash_flows:
              raise ValueError("Cash flows list cannot be empty"						)
       __UpperCAmelCase  :				Tuple       				=		sum(
           cash_flow / ((1 + discount_rate) ** i) for i, cash_flow in enumerate(lowerCamelCase__						)						)
       return round(lowerCamelCase__							,    ndigits=2						)


if __name__ == "__main__":
   import doctest

   doctest.testmod()






