



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

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


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



class  __lowerCAmelCase     (	_a   ):




 def __init__(						self	,				__UpperCAmelCase	,				__UpperCAmelCase=768				):



    '''simple docstring'''
    super().__init__(_A				)
    __lowerCamelCase													=    proj_size

    __lowerCamelCase													=    CLIPVisionModel(_A				)
    __lowerCamelCase													=    PaintByExampleMapper(_A				)
    __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        lowerCamelCase      (						self	,				__UpperCAmelCase	,				__UpperCAmelCase=False				):



    '''simple docstring'''
    __lowerCamelCase													=    self.model(pixel_values=_A				)
    __lowerCamelCase													=    clip_output.pooler_output
    __lowerCamelCase													=    self.mapper(latent_states[:, None]				)
    __lowerCamelCase													=    self.final_layer_norm(_A				)
    __lowerCamelCase													=    self.proj_out(_A				)
    if return_uncond_vector:
       return latent_states, self.uncond_vector

    return latent_states



class  __lowerCAmelCase     (	nn.Module   ):




 def __init__(						self	,				__UpperCAmelCase				):



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




 def        lowerCamelCase      (						self	,				__UpperCAmelCase				):



    '''simple docstring'''
    for block in self.blocks:
       __lowerCamelCase													=    block(_A				)

    return hidden_states




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


a_			=					logging.get_logger(__name__)

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



class  __lowerCAmelCase     (	lowerCAmelCase__   ):
 lowerCAmelCase__       					=  """lxmert"""
 lowerCAmelCase__       					=  {}




 def __init__(						self	,				__UpperCAmelCase=30522	,				__UpperCAmelCase=768	,				__UpperCAmelCase=12	,				__UpperCAmelCase=9500	,				__UpperCAmelCase=1600	,				__UpperCAmelCase=400	,				__UpperCAmelCase=3072	,				__UpperCAmelCase="gelu"	,				__UpperCAmelCase=0.1	,				__UpperCAmelCase=0.1	,				__UpperCAmelCase=512	,				__UpperCAmelCase=2	,				__UpperCAmelCase=0.02	,				__UpperCAmelCase=1E-1_2	,				__UpperCAmelCase=9	,				__UpperCAmelCase=5	,				__UpperCAmelCase=5	,				__UpperCAmelCase=2048	,				__UpperCAmelCase=4	,				__UpperCAmelCase=6.67	,				__UpperCAmelCase=True	,				__UpperCAmelCase=True	,				__UpperCAmelCase=True	,				__UpperCAmelCase=True	,				__UpperCAmelCase=True	,				__UpperCAmelCase=True	,				__UpperCAmelCase=True	,				**__UpperCAmelCase	,				):



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






