[
](https://github.com/OpenGVLab/SDLM) [
](https://arxiv.org/abs/2509.24007) [\
🚀 项目页面\
](https://internvl.github.io/blog/2025-09-29-SDLM/) [
](https://huggingface.co/collections/OpenGVLab/sdlm-68ac82709d7c343ad36aa552)
我们提出一种顺序扩散语言模型(SDLM),以低成本激发扩散模型的并行预测能力。具体而言,SDLM 将预测范围限制在固定块长度内,以减少分布偏移,并通过最长前缀解码方法约束解码顺序,从而在保证生成质量的同时显著提升预测效率。我们的方法可视为对自回归(AR)范式的进一步推广。因此,可以直接使用预训练的 AR 权重,并仅通过极少量指令微调即可快速迁移到扩散框架。

在下表中,我们概述了 SDLM 系列。
| 模型名称 | 基础模型 🤗 | HF 链接 🤗 |
|---|---|---|
| SDLM-3B-D4 | Qwen2.5-3B | https://huggingface.co/OpenGVLab/SDLM-3B-D4 |
| SDLM-3B-D8 | Qwen2.5-3B | https://huggingface.co/OpenGVLab/SDLM-3B-D8 |
| SDLM-32B-D4 | Qwen2.5-32B | https://huggingface.co/OpenGVLab/SDLM-32B-D4 |
我们提出了一种顺序块级掩码预测方法,以减少基于扩散的生成中的误差累积。该方法基于如下观察:位置索引较低的 token 的预测通常可依赖更可靠的上下文信息,因而偏差更小、准确性更高。

SDLM 在显著提升解码速度的同时展现出强劲性能。与同级别自回归模型相比,其运行速度约快 2 倍,且准确率相当;根据 MATH-500 基准测试结果,相较于其他扩散语言模型,它最高可实现 5 倍加速。



SDLM-3B(B=4)与 SDLM-3B(B=8)在不同置信度阈值 τ 下性能与速度的权衡关系。通过调整 τ,可实现速度与性能之间的可控权衡。SpeedUp 表示每次前向传播平均输出的 token 数量。

安装依赖项
关键包版本:
transformers==4.37.2
torch>=2.5.0将模型生成脚本 sdlm_inference.py 下载到工作目录。
我们提供了使用 transformers 运行 SDLM-3B-D8 的示例代码。
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from sdlm_inference import SDLM_generate
if __name__ == "__main__":
ckpt_hf = 'OpenGVLab/SDLM-3B-D8'
model = AutoModelForCausalLM.from_pretrained(
ckpt_hf,
attn_implementation="eager",
trust_remote_code=True
).to(dtype=torch.float16)
tokenizer = AutoTokenizer.from_pretrained(ckpt_hf)
prompt = 'Write a Fibonacci function in Python.'
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": prompt}
]
text = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True
)
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
response, history = SDLM_generate(
model,
tokenizer,
model_inputs,
max_gen_len = 1024,
temperature = 0,
threshold = 0.5,
n_future_tokens = 8,
alg = 'prob_conf', # prob_conf | entropy_conf | self_speculative
save_history = True,
use_cache = True
)
print('response: ', response[0])
print('=======histroy')
for item in history:
print('cur total token ', item[1])
print(item[0][0])
print('--------')如果您觉得本项目在您的研究中很有帮助,请考虑引用:
@article{liu2025sdlm,
title={Sequential Diffusion Language Models},
author={Liu, Yangzhou and Cao, Yue and Li, Hao and Luo, Gen and Chen, Zhe and Wang, Weiyun and Liang, Xiaobo and Qi, Biqing and Wu, Lijun and Tian, Changyao and Zhang, Yanting and Li, Yuqiang and Lu, Tong and Qiao, Yu and Dai, Jifeng and Wang, Wenhai},
journal={arXiv preprint arXiv:2509.24007},
year={2025}
}