


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

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


lowerCAmelCase__			:      Optional[int]								=logging.get_logger(__name__)  # pylint: disable=invalid-name







class 	__lowercase    (__SCREAMING_SNAKE_CASE  ):





							"""simple docstring"""







							def __init__(      self			,						lowerCAmelCase__			,						lowerCAmelCase__=7_6_8       ):





										"""simple docstring"""




										super().__init__(lowerCAmelCase__       )
										SCREAMING_SNAKE_CASE_		:     Tuple					=					proj_size

										SCREAMING_SNAKE_CASE_		:     int					=					CLIPVisionModel(lowerCAmelCase__       )
										SCREAMING_SNAKE_CASE_		:     str					=					PaintByExampleMapper(lowerCAmelCase__       )
										SCREAMING_SNAKE_CASE_		:     Union[str, Any]					=					nn.LayerNorm(config.hidden_size       )
										SCREAMING_SNAKE_CASE_		:     Union[str, Any]					=					nn.Linear(config.hidden_size			,						self.proj_size       )

										# uncondition for scaling
										SCREAMING_SNAKE_CASE_		:     List[Any]					=					nn.Parameter(torch.randn((1, 1, self.proj_size)       )       )






							def 					UpperCamelCase__     (      self			,						lowerCAmelCase__			,						lowerCAmelCase__=False       ):





										"""simple docstring"""




										SCREAMING_SNAKE_CASE_		:     str					=					self.model(pixel_values=lowerCAmelCase__       )
										SCREAMING_SNAKE_CASE_		:     List[str]					=					clip_output.pooler_output
										SCREAMING_SNAKE_CASE_		:     Dict					=					self.mapper(latent_states[:, None]       )
										SCREAMING_SNAKE_CASE_		:     Optional[Any]					=					self.final_layer_norm(lowerCAmelCase__       )
										SCREAMING_SNAKE_CASE_		:     Tuple					=					self.proj_out(lowerCAmelCase__       )
										if return_uncond_vector:
													return latent_states, self.uncond_vector

										return latent_states







class 	__lowercase    (nn.Module  ):





							"""simple docstring"""







							def __init__(      self			,						lowerCAmelCase__       ):





										"""simple docstring"""




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






							def 					UpperCamelCase__     (      self			,						lowerCAmelCase__       ):





										"""simple docstring"""




										for block in self.blocks:
													SCREAMING_SNAKE_CASE_		:     Optional[Any]					=					block(lowerCAmelCase__       )

										return hidden_states









from . import (
    albert,
    align,
    altclip,
    audio_spectrogram_transformer,
    auto,
    autoformer,
    bark,
    bart,
    barthez,
    bartpho,
    beit,
    bert,
    bert_generation,
    bert_japanese,
    bertweet,
    big_bird,
    bigbird_pegasus,
    biogpt,
    bit,
    blenderbot,
    blenderbot_small,
    blip,
    blip_a,
    bloom,
    bridgetower,
    byta,
    camembert,
    canine,
    chinese_clip,
    clap,
    clip,
    clipseg,
    codegen,
    conditional_detr,
    convbert,
    convnext,
    convnextva,
    cpm,
    cpmant,
    ctrl,
    cvt,
    dataavec,
    deberta,
    deberta_va,
    decision_transformer,
    deformable_detr,
    deit,
    deprecated,
    deta,
    detr,
    dialogpt,
    dinat,
    distilbert,
    dit,
    donut,
    dpr,
    dpt,
    efficientformer,
    efficientnet,
    electra,
    encodec,
    encoder_decoder,
    ernie,
    ernie_m,
    esm,
    falcon,
    flaubert,
    flava,
    fnet,
    focalnet,
    fsmt,
    funnel,
    git,
    glpn,
    gpta,
    gpt_bigcode,
    gpt_neo,
    gpt_neox,
    gpt_neox_japanese,
    gpt_swa,
    gptj,
    gptsan_japanese,
    graphormer,
    groupvit,
    herbert,
    hubert,
    ibert,
    imagegpt,
    informer,
    instructblip,
    jukebox,
    layoutlm,
    layoutlmva,
    layoutlmva,
    layoutxlm,
    led,
    levit,
    lilt,
    llama,
    longformer,
    longta,
    luke,
    lxmert,
    mam_aaa,
    marian,
    markuplm,
    maskaformer,
    maskformer,
    mbart,
    mbartaa,
    mega,
    megatron_bert,
    megatron_gpta,
    mgp_str,
    mluke,
    mobilebert,
    mobilenet_va,
    mobilenet_va,
    mobilevit,
    mobilevitva,
    mpnet,
    mra,
    mta,
    musicgen,
    mvp,
    nat,
    nezha,
    nllb,
    nllb_moe,
    nystromformer,
    oneformer,
    open_llama,
    openai,
    opt,
    owlvit,
    pegasus,
    pegasus_x,
    perceiver,
    phobert,
    pixastruct,
    plbart,
    poolformer,
    prophetnet,
    qdqbert,
    rag,
    realm,
    reformer,
    regnet,
    rembert,
    resnet,
    roberta,
    roberta_prelayernorm,
    roc_bert,
    roformer,
    rwkv,
    sam,
    segformer,
    sew,
    sew_d,
    speech_encoder_decoder,
    speech_to_text,
    speech_to_text_a,
    speechta,
    splinter,
    squeezebert,
    swiftformer,
    swin,
    swinasr,
    swinva,
    switch_transformers,
    ta,
    table_transformer,
    tapas,
    time_series_transformer,
    timesformer,
    timm_backbone,
    transfo_xl,
    trocr,
    tvlt,
    umta,
    unispeech,
    unispeech_sat,
    upernet,
    videomae,
    vilt,
    vision_encoder_decoder,
    vision_text_dual_encoder,
    visual_bert,
    vit,
    vit_hybrid,
    vit_mae,
    vit_msn,
    vivit,
    wavaveca,
    wavaveca_conformer,
    wavaveca_phoneme,
    wavaveca_with_lm,
    wavlm,
    whisper,
    x_clip,
    xglm,
    xlm,
    xlm_prophetnet,
    xlm_roberta,
    xlm_roberta_xl,
    xlnet,
    xmod,
    yolos,
    yoso,
)





