inclusionAI/LLaDA2.0-Uni

LLaDA2.0-Uni: Understanding and Generation the World.

LLaDA2.0‑Uni – 用于多模态理解与生成的统一扩散大型语言模型

简介 – LLaDA2.0‑Uni 是一款大规模多模态模型,结合了基于扩散的大型语言模型 (dLLM) 与专家混合 (MoE) 主干。它通过单一的 遮罩标记预测 (mask‑token prediction) 接口处理 文字、图像与图像编辑指令。该模型将视觉数据转换为离散语义标记 (通过 SigLIP‑VQ 标记器),随后使用快速扩散解码器 (8 步蒸馏推理) 进行解码。

主要功能

  • 文字转图像生成 – 高质量 1024×1024 图像,可选的“思考”模式可显示模型的内部推理步骤。
  • 图像理解 – 使用相同的基于标记的接口进行视觉问答与文档理解。
  • 指令引导图像编辑 – 支持单一或多参考编辑,在应用请求变更的同时保留细节。
  • 交错生成与推理 – 统一的标记表示让模型能在同一个提示中切换图像生成与推理。
  • SPRINT 加速 – 一种缓存重用与自适应去遮罩方案,可缩短推理时间 (使用 decoder‑turbo 解码速度提升高达约 10 倍)。
  • 整合挂钩 – 为 ComfyUI、Diffusers 与 SGLang‑Omni 提供现成节点,实现高吞吐量服务。

模型架构

  • 统一的 dLLM‑MoE 主干,基于 LLaDA 2.0 构建。
  • 离散语义标记器 (SigLIP‑VQ),将图像转换为标记序列。
  • 高效扩散解码器 (标准 50 步 ODE 或蒸馏 8 步“turbo”)。

如何开始

# Clone & create environment
git clone https://github.com/inclusionAI/LLaDA2-Uni && cd LLaDA2-Uni
conda create -n llada2_uni python=3.10 -y && conda activate llada2_uni

# Install PyTorch (CUDA 12.4) and FlashAttention 2
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu124
pip install flash-attn --no-build-isolation

# Install the rest of the dependencies
pip install -r requirements.txt

Python 快速入门 – 生成图像

from transformers import AutoModelForCausalLM, AutoTokenizer
from decoder import decode_vq_tokens

model_path = "inclusionAI/LLaDA2.0-Uni"
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
    model_path, device_map="cuda", torch_dtype="bfloat16", trust_remote_code=True
).eval()
model.tokenizer = tokenizer

result = model.generate_image(
    "A modern Scandinavian kitchen with white cabinetry, marble countertops, and a single orchid on the island.",
    image_h=1024, image_w=1024, steps=8, cfg_scale=2.0,
)
# Decode (8‑step turbo decoder for speed)
image = decode_vq_tokens(
    result["token_ids"], result["h"], result["w"], model_path, "cuda",
    num_steps=8, decode_mode="decoder-turbo",
)
image.save("kitchen.png")

图像理解示例

from encoder.image_tokenizer import ImageTokenizer
from decoder.smart_img_process import smart_resize_images

image_tokenizer = ImageTokenizer(model_path=model_path, device="cuda")
pil = smart_resize_images(["./assets/understanding_example.png"])[0]
info = image_tokenizer.encode_with_info(pil)
image_tokens = [t + model.config.image_token_offset for t in info["token_ids"]]
_, h, w = info["grid_thw"]

response = model.understand_image(
    image_tokens, h, w,
    question="Describe this image in detail.",
    steps=32, gen_length=2048,
)
print(response)

图像编辑示例

# Same tokenisation as above, then:
result = model.edit_image(
    image_tokens, h, w,
    instruction="Change the background to a beach.",
    steps=8, cfg_text_scale=4.0,
)
edited = decode_vq_tokens(
    result["token_ids"], result["h"], result["w"], model_path, "cuda",
    num_steps=8, decode_mode="decoder-turbo",
)
edited.save("beach.png")

ComfyUI 整合 – 克隆仓库后,将 apps/comfyui 文件夹链接至您的 ComfyUI custom_nodes 目录 (或执行提供的 install.sh)。该套件增加了用于加载模型、文字转图像、图像理解、图像编辑与标记解码的节点。

SGLang 服务 – 请参阅链接的 SGLang‑Omni 食谱,以获取可处理多个并发请求且具有相同低延迟推理路径的即用型服务器。

模型检查点 – 可在 HuggingFace 与 ModelScope 上获取,包含全精度与 FP8 量化版本。

授权 – Apache 2.0。

引用

@article{LLaDA2Uni,
  title   = {LLaDA2.0‑Uni: Unifying Multimodal Understanding and Generation with Diffusion Large Language Model},
  author  = {Tiwei Bie and Haoxing Chen and Tieyuan Chen and Zhenglin Cheng and Long Cui and Kai Gan and Zhicheng Huang and Zhenzhong Lan and Haoquan Li and Jianguo Li and Tao Lin and Qi Qin and Hongjun Wang and Xiaomei Wang and Haoyuan Wu and Yi Xin and Junbo Zhao},
  journal = {arXiv preprint arXiv:2604.20796},
  year    = {2026}
}

LLaDA2.0‑Uni 将多模态感知与基于扩散的生成整合在单一标记预测模型下,为需要高质量图像合成、视觉推理或指令驱动编辑的开发者提供了一个多功能的工具箱,并具备快速、缓存加速的推理能力。

相关

  • 项目
  • 项目
  • 项目
  • 项目