OpenGVLab/SDLM-3B-D8
模型介绍
文件和版本
Pull Requests
讨论
分析

SDLM-3B-D8

[

📂GitHub📂 GitHub📂GitHub

](https://github.com/OpenGVLab/SDLM) [

📜技术报告📜 技术报告📜技术报告

](https://arxiv.org/abs/2509.24007) [\

🚀 项目页面\

](https://internvl.github.io/blog/2025-09-29-SDLM/) [

🤗HuggingFace🤗 HuggingFace🤗HuggingFace

](https://huggingface.co/collections/OpenGVLab/sdlm-68ac82709d7c343ad36aa552)

简介

我们提出一种顺序扩散语言模型(SDLM),以低成本激发扩散模型的并行预测能力。具体而言,SDLM 将预测范围限制在固定块长度内,以减少分布偏移,并通过最长前缀解码方法约束解码顺序,从而在保证生成质量的同时显著提升预测效率。我们的方法可视为对自回归(AR)范式的进一步推广。因此,可以直接使用预训练的 AR 权重,并仅通过极少量指令微调即可快速迁移到扩散框架。

image/png

SDLM 系列

在下表中,我们概述了 SDLM 系列。

模型名称基础模型 🤗HF 链接 🤗
SDLM-3B-D4Qwen2.5-3Bhttps://huggingface.co/OpenGVLab/SDLM-3B-D4
SDLM-3B-D8Qwen2.5-3Bhttps://huggingface.co/OpenGVLab/SDLM-3B-D8
SDLM-32B-D4Qwen2.5-32Bhttps://huggingface.co/OpenGVLab/SDLM-32B-D4

模型架构

我们提出了一种顺序块级掩码预测方法,以减少基于扩散的生成中的误差累积。该方法基于如下观察:位置索引较低的 token 的预测通常可依赖更可靠的上下文信息,因而偏差更小、准确性更高。

  • (a) 训练流程。 重排序输入支持结构化掩码,包括因果前缀(左上)、可见的跨块前缀(左下)以及块内双向注意力(右下)。
  • (b) 采样流程。 基于置信度的动态块解码,并复用 KV cache。每一步均预测一个包含 B 个 token 的块,其中 B-1 个为填充掩码。选取置信度最高的最长前缀作为动态输出。缓存的 KV 状态可实现高效解码。

image/png

性能

长文本基准测试

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

image/png

通用选择题基准测试

image/png

块大小与自推测解码

image/png

性能与速度之间的权衡

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

image/png

推理

  1. 安装依赖项

    关键包版本:

    transformers==4.37.2
    torch>=2.5.0
  2. 将模型生成脚本 sdlm_inference.py 下载到工作目录。

  3. 我们提供了使用 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}
}