from ...configuration_utils import PretrainedConfig
from ...utils import logging


__magic_name__								=logging.get_logger(__name__)

__magic_name__								={
    '''unc-nlp/lxmert-base-uncased''': '''https://huggingface.co/unc-nlp/lxmert-base-uncased/resolve/main/config.json''',
}



class     _A   (    __UpperCamelCase							):
  SCREAMING_SNAKE_CASE_	:	Optional[Any]						="lxmert"
  SCREAMING_SNAKE_CASE_	:	Dict						={}






  def __init__(self   ,				SCREAMING_SNAKE_CASE_=3_0522   ,				SCREAMING_SNAKE_CASE_=768   ,				SCREAMING_SNAKE_CASE_=12   ,				SCREAMING_SNAKE_CASE_=9500   ,				SCREAMING_SNAKE_CASE_=1600   ,				SCREAMING_SNAKE_CASE_=400   ,				SCREAMING_SNAKE_CASE_=3072   ,				SCREAMING_SNAKE_CASE_="gelu"   ,				SCREAMING_SNAKE_CASE_=0.1   ,				SCREAMING_SNAKE_CASE_=0.1   ,				SCREAMING_SNAKE_CASE_=512   ,				SCREAMING_SNAKE_CASE_=2   ,				SCREAMING_SNAKE_CASE_=0.02   ,				SCREAMING_SNAKE_CASE_=1E-12   ,				SCREAMING_SNAKE_CASE_=9   ,				SCREAMING_SNAKE_CASE_=5   ,				SCREAMING_SNAKE_CASE_=5   ,				SCREAMING_SNAKE_CASE_=2048   ,				SCREAMING_SNAKE_CASE_=4   ,				SCREAMING_SNAKE_CASE_=6.67   ,				SCREAMING_SNAKE_CASE_=True   ,				SCREAMING_SNAKE_CASE_=True   ,				SCREAMING_SNAKE_CASE_=True   ,				SCREAMING_SNAKE_CASE_=True   ,				SCREAMING_SNAKE_CASE_=True   ,				SCREAMING_SNAKE_CASE_=True   ,				SCREAMING_SNAKE_CASE_=True   ,				**SCREAMING_SNAKE_CASE_   ,				)		->      Union[str, Any]:





       '''simple docstring'''





       UpperCamelCase__										=      vocab_size
       UpperCamelCase__										=      hidden_size
       UpperCamelCase__										=      num_attention_heads
       UpperCamelCase__										=      hidden_act
       UpperCamelCase__										=      intermediate_size
       UpperCamelCase__										=      hidden_dropout_prob
       UpperCamelCase__										=      attention_probs_dropout_prob
       UpperCamelCase__										=      max_position_embeddings
       UpperCamelCase__										=      type_vocab_size
       UpperCamelCase__										=      initializer_range
       UpperCamelCase__										=      layer_norm_eps
       UpperCamelCase__										=      num_qa_labels
       UpperCamelCase__										=      num_object_labels
       UpperCamelCase__										=      num_attr_labels
       UpperCamelCase__										=      l_layers
       UpperCamelCase__										=      x_layers
       UpperCamelCase__										=      r_layers
       UpperCamelCase__										=      visual_feat_dim
       UpperCamelCase__										=      visual_pos_dim
       UpperCamelCase__										=      visual_loss_normalizer
       UpperCamelCase__										=      task_matched
       UpperCamelCase__										=      task_mask_lm
       UpperCamelCase__										=      task_obj_predict
       UpperCamelCase__										=      task_qa
       UpperCamelCase__										=      visual_obj_loss
       UpperCamelCase__										=      visual_attr_loss
       UpperCamelCase__										=      visual_feat_loss
       UpperCamelCase__										=      {'''vision''': r_layers, '''cross_encoder''': x_layers, '''language''': l_layers}
       super().__init__(**SCREAMING_SNAKE_CASE_	)




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

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


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



class     _A   (    __UpperCamelCase							):






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





       '''simple docstring'''





       super().__init__(SCREAMING_SNAKE_CASE_	)
       UpperCamelCase__										=      proj_size

       UpperCamelCase__										=      CLIPVisionModel(SCREAMING_SNAKE_CASE_	)
       UpperCamelCase__										=      PaintByExampleMapper(SCREAMING_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 		_a					(self   ,				SCREAMING_SNAKE_CASE_   ,				SCREAMING_SNAKE_CASE_=False	)		->      List[str]:





       '''simple docstring'''





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

       return latent_states



class     _A   (    nn.Module							):






  def __init__(self   ,				SCREAMING_SNAKE_CASE_	)		->      int:





       '''simple docstring'''





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






  def 		_a					(self   ,				SCREAMING_SNAKE_CASE_	)		->      str:





       '''simple docstring'''





       for block in self.blocks:
            UpperCamelCase__										=      block(SCREAMING_SNAKE_CASE_	)

       return hidden_states



