UniLiP: Adapting CLIP for Unified Multimodal Understanding, Generation and Editing

Paper: arXiv:2507.23278 Code: nnnth/UniLIP Code reference: main @ 937ee739 (2026-01-26)

1. Motivation(研究动机)

现有 unified multimodal model 的核心矛盾是:理解模型喜欢 CLIP / SigLIP 这样的语义特征,生成模型却需要可重建、细节充分、与像素空间稳定对齐的特征。如果直接用 VQ/VAE token 做统一表示,重建和生成容易做,但理解性能通常弱于 CLIP;如果直接用 CLIP 特征做生成条件,语义很好,但 CLIP 为对比学习而训练,天然丢掉部分像素细节,导致重建不一致、编辑时参考图身份/纹理/局部布局容易漂移。

Figure 1 解读:论文把 CLIP-based unified tokenizer 的三条路线放在一起比较:(a) VILA-U/TokenFlow 类方法量化 CLIP 特征,保住部分重建能力但会损失语义;(b) Emu2 类方法冻结 CLIP、另接 diffusion decoder,能维持语义但因为 CLIP 原特征缺少像素细节,重建会出现数量、位置不一致;(c) UniLiP 让 CLIP 自身学会可重建,同时用 self-distillation 约束它不要偏离原始 CLIP 分布。

本文要解决的具体问题是:把 CLIP 改造成同一个视觉编码器,既服务于 MLLM understanding,又能作为 generation/editing 的 image tokenizer / condition,不再依赖理解编码器与生成编码器的双轨系统。这个问题重要在于,一旦 unified representation 同时具备语义对齐和像素可重建性,模型就可以用更少 image tokens、更少参数、更少 diffusion steps,把理解、生成和编辑接到同一套视觉特征上,并降低双编码器之间的 feature misalignment。

2. Idea(核心思想)

UniLiP 的核心 insight 是:CLIP 并不是完全没有像素信息,而是这些信息太弱、没有被 reconstruction objective 放大;如果先固定 CLIP 训练 pixel decoder,再轻微 finetune CLIP 并用原始 CLIP 作为 teacher 约束 feature drift,就能把“可重建性”注入 CLIP,同时保留理解能力。因此 UniLiP 不把 CLIP 离散化,也不只把 CLIP 当 diffusion condition,而是把 CLIP 变成可直接解码的连续统一表示。

第二个关键创新是 dual-condition architecture:MetaQuery/DreamLLM 式 learnable query embeddings 能承载 MLLM 的推理结果,适合 text-to-image;但 editing 还需要 reference image 的大量局部细节,固定长度 query 会形成 bottleneck。UniLiP 同时把 MLLM 的 multimodal hidden states 和 query embeddings 送给 connector/DiT:hidden states 保留 reference image 细节,query embeddings 提供语言推理和世界知识。

它与 BAGEL、Show-o2、Janus-Pro 等统一模型的差别不是只换 backbone,而是把“视觉表示统一”放在第一位:CLIP/InternViT 经 reconstruction training 后同时作为 understanding encoder、generation target representation 和 editing reference/target encoder;相比 UniWorld-V1 仍依赖 SigLIP + VAE 的分工,UniLiP 更少依赖 heterogeneous encoders。

3. Method(方法)

3.1 Overall framework:先把 CLIP 训练成可重建 tokenizer,再接入 MLLM + DiT

整体流程分两层:第一层是 UniLiP tokenizer,把 InternVL3 的 InternViT/CLIP 通过两阶段 reconstruction training 改造成能被 lightweight pixel decoder 直接解码的视觉表示;第二层是 unified generation/editing model,把 UniLiP 视觉 token 接到 InternVL3 MLLM 和 SANA DiT,中间通过 LLM connector 和 learnable queries 建立 cross-attention condition。

Figure 3 解读:Stage 1 冻结 CLIP,只训练 projection 和 pixel decoder ,让 decoder 先学会从原始 CLIP 的弱像素线索中重建;Stage 2 解冻 CLIP,但加入 frozen CLIP teacher 的 feature self-distillation,使 finetuned CLIP 增强像素细节而不破坏原先的语义分布。图中省略了 projection,但 released code 中对应 mlp1/down_blocks/down_mlp 等特征适配逻辑。

Figure 4 解读:editing 时输入包含文本和 reference image;UniLiP 提供 image tokens,LLM 产生 multimodal hidden states,同时 learnable query embeddings 经过 LLM/connector 形成推理型 condition。DiT 不只看固定 query,也看 hidden states,因此既有“要生成什么”的语义推理,也有“参考图细节是什么”的高带宽视觉信息。text-to-image generation 可移除 reference image 分支。

3.2 Finetuning CLIP for Image Reconstruction

Autoencoder 形式

给定输入图像 ,CLIP 提取连续特征 ,projection 对齐到 pixel decoder 所需维度,输出重建图像: 这里 是 downsample ratio,UniLiP 最终报告了 compression ratio。直觉上,Stage 1 的作用不是让 frozen CLIP 完美重建,而是先让 decoder 与 CLIP feature manifold 对齐,避免 Stage 2 一开始同时更新 CLIP 和随机 projection/decoder 导致梯度不稳定。

Stage 1:冻结 CLIP,只对齐 pixel decoder

Stage 1 固定 CLIP,训练 ,目标为: 论文实现中,pixel decoder 初始化自 DC-AE,projection 随机初始化。released code 的 reconstruction loss 位于 tokenizer/modeling/modules/losses.py,其中 reconstruction_loss 可为 L1/L2;感知损失由 PerceptualLoss 封装 LPIPS / ConvNeXt-S。训练循环位于 tokenizer/utils/train_utils_stage1.py::train_one_epoch,调用 model 得到 reconstructed_images 后传入 loss module。

Stage 2:解冻 CLIP,并用 self-distillation 限制分布漂移

Stage 2 允许 CLIP 更新,但加入 teacher-student feature constraint: 其中 来自 frozen original CLIP, 来自 finetuned CLIP,论文默认 。released code 中 tokenizer/modeling/modules/distill_loss.py 对 reference ViT 做 no-grad forward,然后以 F.mse_loss(out_feat, target_feat) 形成 distillation loss;tokenizer/utils/train_utils_stage2.py 额外记录 train/distill_loss。论文还把 CLIP 学习率设为 global LR 的 ,主文 Table 6 称 Lr Decay 为 CLIP LR 1e-5

Figure 2 解读:frozen CLIP 的重建图会漏掉边缘蛋糕或字母细节,导致同一个视觉问题回答错误;UniLiP 重建后保留更多局部细节,理解任务也随之改善。这是本文“生成/重建能力反过来帮助理解”的直接证据:Table 1 中 UniLiP 相比 Frozen CLIP 的 MMVP 从 67.3 到 68.7,AI2D 从 69.4 到 70.7,TextVQA 从 74.1 到 74.7。

PyTorch-style pseudocode:two-stage reconstruction

import torch
import torch.nn.functional as F
 
 
def stage1_reconstruction_step(clip, projector, pixel_decoder, batch):
    # CLIP is frozen: only projector and pixel_decoder are optimized.
    image = batch["image"]
    with torch.no_grad():
        clip_feat = clip(image)                      # F_clip
    z = projector(clip_feat)                         # h_phi(F_clip)
    recon = pixel_decoder(z)                         # D_pix(...)
    loss_mse = F.mse_loss(recon, image)
    loss_lpips = lpips_loss(recon, image)
    loss = loss_mse + loss_lpips
    loss.backward()
    return {"loss": loss, "recon": recon}
 
 
def stage2_reconstruction_step(student_clip, teacher_clip, projector, pixel_decoder, batch, lambda_distill=1.0):
    image = batch["image"]
    with torch.no_grad():
        teacher_feat = teacher_clip(image)            # F_orig, frozen CLIP distribution
    student_feat = student_clip(image)                # F_ft, trainable but low LR
    z = projector(student_feat)
    recon = pixel_decoder(z)
    loss_recon = F.mse_loss(recon, image) + lpips_loss(recon, image)
    loss_distill = F.mse_loss(student_feat, teacher_feat)
    loss = loss_recon + lambda_distill * loss_distill
    loss.backward()
    return {"loss": loss, "recon": recon, "distill_loss": loss_distill}

3.3 Dual-condition architecture:用 hidden states 补 query bottleneck

DreamLLM/MetaQuery 类方法让 MLLM 通过 learnable query embeddings 产出 diffusion condition。这个设计在 text-to-image 上有效,因为文本 prompt 较短,LLM 容易压缩成若干 query;但 editing 需要保留 reference image 的身份、纹理、未编辑区域、局部位置等信息,固定数量 query 会损失细节。UniLiP 的解决方式是把 generation/editing 分解成两个互补子任务:MLLM 负责抽取上下文和推理目标,DiT 负责在双重 condition 下合成图像。

released code 中,unilip/model/unilip_internvl.py 初始化 latent_queries = nn.Parameter(torch.randn(1, config.n_query, hidden_size)),加载 SANA DiT,并把 InternVL language model 的后若干层 deepcopy 成 llm_connector,再通过 projector = nn.Linear(llm_hidden_size, dit.config.caption_channels) 对齐 DiT condition channel。prepare_inputs_labels_for_multimodal 中,生成位置会被 latent queries 替换,理解图像位置会填入视觉 embedding;同时 target_image_embeds 由 UniLiP/pixel-decoder 路径生成并乘以 unilip_factor

def prepare_dual_condition(input_ids, labels, ref_image, target_image, model):
    # UniLIP is shared by understanding and generation/editing.
    if ref_image is not None:
        ref_tokens = model.unilip_encode(ref_image)       # multimodal hidden-state path
        ref_tokens = model.vae_decoder.clip_down(ref_tokens)
    else:
        ref_tokens = None
 
    target_tokens = model.unilip_encode(target_image).detach()
    query = model.latent_queries.repeat(input_ids.size(0), 1, 1)
    text_embeds = model.llm.embed_tokens(input_ids).clone()
 
    # Replace output image placeholders with learnable query embeddings.
    text_embeds[is_output_image_token(input_ids, labels)] = query.reshape(-1, query.size(-1))
 
    # Replace input reference image placeholders with UniLiP hidden states.
    if ref_tokens is not None:
        text_embeds[is_input_image_token(input_ids, labels)] = ref_tokens.flatten(0, 1)
 
    mm_hidden_states = model.llm_connector(inputs_embeds=text_embeds, bidirectional_mask=True)
    condition = model.projector(mm_hidden_states)
    return condition, target_tokens

3.4 Three-stage generation/editing training

在 reconstruction tokenizer 训练完成后,UniLiP 的 unified model 还有三个训练阶段:

  • Stage 1 Connector Training:冻结 MLLM 和 DiT,仅训练 connector,让 MLLM output features 对齐 DiT 原始 condition space;只用 generation data。
  • Stage 2 Unified Generation and Editing Training:用大规模 generation + editing 数据训练 connector 和 DiT;MLLM 仍冻结,因此无需再做 expensive understanding training。
  • Stage 3 SFT:用高质量 instruction tuning 数据提升 prompt alignment、generation fidelity 与 editing fidelity;继续优化 connector 和 DiT,MLLM 保持冻结。

released launch scripts 与论文数字的关系:主文报告 generation/editing 三阶段分别训练 50k / 200k / 30k steps,batch size 512,cosine LR 从 1e-41e-5;仓库脚本 scripts/run_unilip_1b_stage{1,2,3}.sh / run_unilip_2b_stage{1,2,3}.sh 使用 torchrun --nproc_per_node=8--per_device_train_batch_size 32--gradient_accumulation_steps 1--learning_rate 1e-4--lr_scheduler_type cosine_with_min_lr--lr_scheduler_kwargs '{"min_lr":1e-5}',并用 --gen_repeat / --edit_repeat 调整 generation/editing sampling balance。论文 step 数没有在 launch script 中直接 hard-code,而依赖数据规模与 epoch/repeat 设置推导。

def train_generation_editing(stage, model, batch):
    # stage 1: train connector only; stage 2/3: train connector + DiT; LLM frozen.
    cond, target_tokens = model.prepare_inputs_labels_for_multimodal(
        batch.input_ids,
        batch.position_ids,
        batch.attention_mask,
        past_key_values=None,
        labels=batch.labels,
        gen_images=batch.target_images,
        und_images=batch.reference_images,
        grid_thw=batch.grid_thw,
        i_s_pos=batch.image_positions,
    )
    noise = torch.randn_like(target_tokens)
    t = sample_diffusion_timestep()
    noised = add_noise(target_tokens, noise, t)
    pred = model.dit(noised, timestep=t, encoder_hidden_states=cond)
    loss = diffusion_loss(pred, noise)
    loss.backward()
    return loss

3.5 Code-to-paper mapping

Code reference: main @ 937ee739 (2026-01-26) — pseudocode and mapping based on this commit

Paper ConceptSource FileKey Class/Function
Stage-1 reconstruction tokenizer trainingtokenizer/scripts/train_stage1.py, tokenizer/utils/train_utils_stage1.pytrain_one_epoch, create_model_and_loss_module
Stage-2 self-distillation tokenizer trainingtokenizer/scripts/train_stage2.py, tokenizer/utils/train_utils_stage2.pytrain_one_epoch, distill_loss logging
UniLiP visual encoder / pixel decoder pathtokenizer/modeling/dc_ae_vit_stage2_pad.pyDC_AE_ViT_Stage2_Pad.encode, decode, forward
Reconstruction / perceptual / GAN losstokenizer/modeling/modules/losses.py, perceptual_loss.pyVQLPIPSWithDiscriminator._forward_generator, PerceptualLoss
Feature self-distillationtokenizer/modeling/modules/distill_loss.pyDistillLoss.forward uses frozen reference ViT + F.mse_loss
Dual-condition MLLM + DiT modelunilip/model/unilip_internvl.pyUniLIP_InternVL_MetaModel.initialize_vision_modules, prepare_inputs_labels_for_multimodal
SANA DiT / VAE loadingunilip/model/sana.py, unilip/model/unilip_internvl.pybuild_sana, DCAE_Decoder
Generation/editing data mixingunilip/train/train_stage1.py, train_stage2.py, train_stage3.pyLazySupervisedMixDataset.load_gen, load_edit, DataCollatorForSupervisedDataset
Inference pipelinesunilip/pipeline_gen.py, unilip/pipeline_edit.pygeneration/editing pipeline wrappers
Launch configs for released experimentsscripts/run_unilip_1b_stage*.sh, scripts/run_unilip_2b_stage*.shmodel paths, n_query, unilip_factor, LR/batch/repeat settings

4. Experimental Setup(实验设置)

Datasets

  • Reconstruction / tokenizer training:使用 BLIP3-o pretraining data;论文还在 ImageNet 50k validation set 上评估 reconstruction。
  • Generation pretraining:BLIP3-o image generation data,包含 27M Qwen2.5-VL-7B recaptioned samples、5M CC12M samples、4M JourneyDB synthesized images,共 36M;instruction tuning 使用 GPT-4o 生成的 60K high-quality image-text pairs。
  • Editing pretraining / SFT:pretraining 使用 GPT-Image-Edit-1.5M;instruction tuning 使用 ShareGPT-4o-Image 的 46K editing samples。
  • Understanding eval:MME-P、MMBench、MMMU、MM-Vet、SEED-Bench Img、AI2D、MMVP、TextVQA;论文强调由于 LLM frozen,不需要额外 understanding training data。

Model / hardware / hyperparameters

  • Architecture:UniLiP-1B = InternVL3-1B + SANA-0.6B;UniLiP-3B = InternVL3-2B + SANA-1.6B;视觉侧采用 InternVL3 的 InternViT,pixel decoder 采用 DC-AE;connector 为 6 layers,结构和维度与 InternVL3 LLM 保持一致;learnable query length
  • Reconstruction training:4 A100 GPUs,batch size 64,LR 1e-4;Stage 1 在 训练 300k steps;Stage 2 先 训练 400k steps,再 训练 100k steps;Stage 2 在 200k steps 后启用 adversarial training;CLIP LR 为 1e-5
  • Generation/editing training:三阶段 50k / 200k / 30k steps,batch size 512,cosine LR decay from 1e-4 to 1e-5。released scripts 使用 8 processes/node、per-device batch 32、gradient accumulation 1。
  • Metrics:reconstruction 用 rFID / PSNR / SSIM;generation 用 GenEval 和 WISE;editing 用 ImgEdit-Bench 与 RISE;understanding 使用各 benchmark 原指标。

5. Experimental Results(实验结果)

5.1 Reconstruction and understanding:重建能力没有牺牲理解,局部还提升

Table 1 直接比较 Frozen CLIP 与 UniLiP:Frozen CLIP 在 reconstruction 上 rFID 6.14、PSNR 16.26、SSIM 0.572;UniLiP 达到 rFID 0.31、PSNR 24.62、SSIM 0.788。理解侧 UniLiP 也没有退化:MME-P 1492→1499,MMVP 67.3→68.7,AI2D 69.4→70.7,TextVQA 74.1→74.7,MMBench 持平 72.6。

Table 2 对 CLIP-based tokenizers:在 ,UniLiP 的 rFID 0.79、PSNR 22.99、SSIM 0.747,优于 VILA-U rFID 1.80、TokenFlow rFID 1.37、DualViTok rFID 1.37;在 ,UniLiP rFID 0.31、PSNR 24.62、SSIM 0.788,而 Emu2 为 rFID 3.27、PSNR 13.49、SSIM 0.423。作者强调 UniLiP 比 Emu2 rFID 好 2.96、PSNR 高 11.13。

Figure 9 解读:定性重建中,frozen CLIP + decoder 输出偏模糊;Emu2 虽更清晰但容易改动钟表数字等关键细节;TokenFlow 受量化损失影响,脸和文字仍有模糊;UniLiP 的连续特征与 reconstruction training 使重建接近 DC-AE,同时保留 CLIP 语义。

5.2 Multimodal understanding:小模型达到 unified model 中的强理解

主表 Table 3 中,UniLiP-1B 达到 MME-P 1499、MMB 72.6、MMMU 43.3、MM-Vet 59.4、SEED 71.0、AI2D 70.7、MMVP 68.7;UniLiP-3B 达到 MME-P 1636、MMB 80.7、MMMU 48.7、MM-Vet 62.2、SEED 75.0、AI2D 78.6、MMVP 73.0。相比 Tar 7B 的 MMB 74.4、MMMU 39.0、SEED 73.0,以及 BAGEL 3B 的 MME-P 1610、MMB 79.2、MMMU 43.2、MM-Vet 48.2,UniLiP-3B 在多项理解指标上更强。

5.3 Text-to-image generation:GenEval 0.90,WISE 0.63

Table 4 主结果:UniLiP-1B 在 GenEval Counting/Position/Overall 为 0.83/0.83/0.88,WISE Cultural/Biology/Overall 为 0.54/0.50/0.56;UniLiP-3B 为 GenEval 0.84/0.86/0.90,WISE 0.66/0.60/0.63。对比同类 unified models,BAGEL 7B+7B 为 GenEval Overall 0.82、WISE Overall 0.52,OpenUni-L 为 0.85/0.52,Show-o2 为 0.76/0.39,Tar 为 0.84(WISE 未报)。

Figure 5 解读:上半部分展示 text-to-image generation,下半部分展示 editing。它不是单纯美观样例,而是对应 ImgEdit/GenEval 中的对象替换、文字替换、背景/风格修改等类别,说明 UniLiP 的语义 alignment 与 reference detail retention 能同时起作用。

Figure 10 解读:作者指出 UniLiP 在位置关系、人脸清晰度、世界知识语义和艺术风格上更稳定;例如“fastest land animal”这种需要世界知识推断的 prompt,query embeddings 能把 LLM 的知识激活结果转成 DiT 可用 condition。

5.4 Image editing:ImgEdit 3.94,dual-condition 是关键

Table 5 / Table 20 中,UniLiP-1B 的 ImgEdit Overall 为 3.81,UniLiP-3B 为 3.94;UniLiP-3B 在 Add/Adjust/Replace/Remove/Background/Style/Overall 为 4.29/3.90/4.44/4.10/4.14/4.80/3.94。对比 OmniGen2 3.44、BAGEL 3.20、UniWorld-V1 3.26、Janus-4o 3.26,UniLiP 在编辑任务上明显领先,但仍低于 GPT-4o 的 Overall 4.20。

Figure 11 解读:定性编辑中,UniLiP 更能在完成 instruction 的同时保留非编辑区域一致性。作者举例说在抽取 motorcycle 或擦除汽车区域时,其他模型会回退、擦除错误对象或产生明显 blur,UniLiP 的背景补全更自然。

Figure 12 解读:该图专门比较 CLIP 与 UniLiP 作为 reference image encoder。CLIP 能跟随编辑指令,但保留 subject identity、纹理和背景细节较弱;UniLiP 因为 reconstruction training 增强了像素细节,所以 reference fidelity 更好。

5.5 Ablations:互相帮助的证据

Figure 6 解读:two-stage 训练使 Stage 2 更稳定;single-stage 的初始 distillation loss spike 接近 two-stage 的两倍(0.0939 vs. 0.0497),收敛到低 loss 需要约 iterations,恢复 understanding performance 需要约 iterations。这说明不是“重建训练越强越好”,而是需要先 decoder pre-alignment,再有限更新 CLIP。

Table 6 给出重建训练策略消融:直接 finetune CLIP(无 two-stage、无 self-distillation、无 LR decay)虽有最好 PSNR 26.01,但 MME-P 只有 124,MMBench/TextVQA 降到 0;完整 UniLiP 得到 rFID 0.31、PSNR 24.62、SSIM 0.788,同时 MME-P 1499、MMBench 72.6、MMVP 68.7、AI2D 70.7、TextVQA 74.7。去掉 self-distillation 时 MMBench 只有 18.4,作者指出相当于下降 54.2 points。

Figure 7 解读:Stage 2 训练早期 distillation loss 上升,表示 CLIP 开始偏离原始理解分布;随后 distillation loss 下降,understanding performance 恢复,同时 reconstruction rFID 降低。作者解释为像素细节所需信息容量其实不高,适度调整 CLIP feature 就能提升重建而不破坏语义。

Table 7 证明 dual-condition 的互补性:只用 multimodal hidden states 时 WISE 0.47、ImgEdit 3.62;只用 query embeddings 时 WISE 0.52、ImgEdit 3.38;两者同时使用得到 WISE 0.56、ImgEdit 3.81。换言之,query 更帮助知识型 generation,hidden states 更帮助 reference-preserving editing。

Figure 8 解读:作者把 query embeddings decode 成文本,发现它们会显式包含 prompt 所需的知识词,如 Thanksgiving → turkey、ancient Egypt burial place → pyramid、desert hump animal → camel。这解释了为什么 query length 增大能提升 WISE:query 像额外的 inference budget,把 LLM 的世界知识转成 DiT 条件。

Table 8 说明 unified visual encoder 优于双编码器组合:Reference/Target 都用 UniLiP 时 GenEval 0.88、WISE 0.56、ImgEdit 3.81;Reference 用 CLIP、Target 用 UniLiP 时 ImgEdit 降到 3.42;Target 用 VAE 时 WISE 降到 0.48、ImgEdit 3.70。Appendix 的 JanusFlow 对比也支持这一点:UniLiP-JanusFlow 用 576 unified tokens 替代 SigLIP+SDXL-VAE 的 1152 tokens,GenEval 0.73→0.75、WISE 0.31→0.36、ImgEdit 2.95→3.09。

Table 15 是“生成帮助编辑”的直接实验:只用 editing data 的 Edit Only Overall 为 3.67,Joint Training(大规模 generation data + editing data)为 3.81;作者认为 1.5M editing data 相对 36M generation data 更容易过拟合,而 generation data 提供更稳健的 image distribution,所以编辑质量提升。

5.6 Efficiency and limitations

Table 9 报告 inference latency:Janus-Pro-1B AR 384 resolution / 576 steps / 8.5s;Harmon-1.5B MAR 448 / 64 steps / 46.1s;BLIP3-o-4B diffusion 448 / 30+50 steps / 5.1s;UniLiP-1B diffusion 448 / 20 steps / 1.4s;UniLiP-3B 448 / 20 steps / 1.7s。速度优势来自 continuous UniLiP features + lightweight decoder,避免 BLIP3-o 的两阶段 diffusion decoding。

局限性:论文明确说 UniLiP 当前最大到 3B,小于 Step1X-Edit 19B 和 Qwen-Image 28B;并且目前只支持 分辨率,导致文字渲染和部分编辑任务仍弱于更大/更高分辨率模型。released code caveat:训练脚本已公开,但主文中的 exact step schedule 与公开 shell scripts 的 epoch/repeat 设置并非一一 hard-coded 对应,复现实验时需要根据数据规模推导实际 steps。