Open-dLLM

pengzhangzhiApache-2.0活跃维护

开源的扩散式语言模型,专攻代码生成,一并放出预训练、评测、推理代码和模型权重,方便直接复现和二次开发。

Open diffusion language model for code generation — releasing pretraining, evaluation, inference, and checkpoints.

v1.0发布于 2026-03-01 17:35 UTC664star52fork同步于 2026-11-07 07:30 UTC

怎么上手

由 README 提炼,执行前请确认
micromamba install -c nvidia/label/cuda-12.3.0 cuda-toolkit -y
pip install torch==2.6.0 --index-url https://download.pytorch.org/whl/cu121
pip install -e .
硬件要求按 README 说明

README 未明确说明显存要求;示例代码在 CUDA 可用时用 GPU,否则回退 CPU;安装依赖 CUDA 12.3 工具链与 flash-attn,需 NVIDIA GPU。

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

开源扩散式代码生成大模型,从预训练到推理评测全流程开放

开源的扩散式语言模型,专攻代码生成,一并放出预训练、评测、推理代码和模型权重,方便直接复现和二次开发。

核心能力

  • 开源完整预训练流水线及 FineCode 代码数据集
  • 提供 HumanEval、MBPP、代码填充等评测套件
  • 发布 0.5B Open-dCoder 权重与检查点
  • 支持表征对齐将自回归模型适配为扩散模型
  • 提供采样推理脚本与可复现配置

容易踩的坑

flash-attn 需匹配特定版本 2.7.4.post1 与 CUDA 环境;推理需从 Hugging Face 下载 fredzzp/open-dcoder-0.5B 模型;评测前需单独安装 lm-evaluation-harness 和 human-eval-infilling。

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

1 个版本v1.0
  1. v1.0published version with DOI最新正式版2026-03-01 · 2026-03-01 17:35 UTC

    这个版本没有写更新说明。

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    🔥 Open-dLLM: Open Diffusion Large Language Models

    🌍 Languages: English | 中文 | 日本語

    👉 TL;DR: Open-dLLM is the most open release of a diffusion-based large language model to date —
    including pretraining, evaluation, inference, and checkpoints.

    Representation Alignment

    Open-dLLM supports representation alignment for adapting autoregressive LMs into diffusion LMs with 4x speedup. This feature is based on our recent paper, Don’t Retrain—Align: Adapting Autoregressive LMs to Diffusion LMs via Representation Alignment. Check out Representation Alignment Tutorial.

    🎥 Demo


    ✨ Highlights

    • 🏋️ Pretraining pipeline + open datasets
    • ⚡ Inference scripts — easy sampling & generation
    • 📊 Evaluation suite — HumanEval, MBPP, Infilling (lm-eval-harness + custom metrics)
    • 📦 Weights + checkpoints on Hugging Face
    • 🤝 Transparent configs for full reproducibility

    Why Open-dLLM?

    Most diffusion LLM repos (e.g., LLaDA, Dream) only release inference scripts + weights, which limits reproducibility.
    Open-dLLM is the first to open-source the entire stack for diffusion LLMs.

    👉 With Open-dLLM, you can go from raw data → training → checkpoints → evaluation → inference, all in one repo.


    🔎 Transparency Comparison of Diffusion LLM Releases

    ProjectDataTraining CodeInferenceEvaluationWeights
    Open-dLLM / Open-dCoder (ours)✅✅✅✅✅
    LLaDA❌❌✅⚠️ Limited✅
    Dream❌❌✅⚠️ Limited✅
    Gemini-Diffusion❌❌❌❌❌ (API only)
    Seed Diffusion❌❌❌❌❌ (API only)
    Mercury❌❌❌❌❌ (API only)

    ✅ = fully available · ❌ = not provided · ⚠️ = partial/limited


    ⚙️ Install

    We use micromamba for environment management (feel free to adapt to conda):

    micromamba install -c nvidia/label/cuda-12.3.0 cuda-toolkit -y
    pip install ninja
    
    # install the newest torch with cu121
    pip install torch==2.6.0 --index-url https://download.pytorch.org/whl/cu121
    
    pip install "flash-attn==2.7.4.post1" \
      --extra-index-url https://github.com/Dao-AILab/flash-attention/releases/download
    
    pip install --upgrade --no-cache-dir \
      tensordict torchdata triton>=3.1.0 \
      transformers==4.54.1 accelerate datasets peft hf-transfer \
      codetiming hydra-core pandas pyarrow>=15.0.0 pylatexenc \
      wandb ninja liger-kernel==0.5.8
    # optional
    pip install pytest yapf py-spy pyext pre-commit ruff packaging
    
    pip install -e .
    pip install lm-evaluation-harness/ human-eval-infilling/
    

    🚀 Quickstart: Sampling

    from transformers import AutoTokenizer
    from veomni.models.transformers.qwen2.modeling_qwen2 import Qwen2ForCausalLM
    from veomni.models.transformers.qwen2.generation_utils import MDMGenerationConfig
    import torch
    
    model_id = "fredzzp/open-dcoder-0.5B"
    device = "cuda" if torch.cuda.is_available() else "cpu"
    
    # Load tokenizer + model
    tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
    model = Qwen2ForCausalLM.from_pretrained(
        model_id, torch_dtype=torch.bfloat16, trust_remote_code=True
    ).to(device).eval()
    
    # Prompt
    prompt = "Write a quick sort algorithm in python."
    input_ids = tokenizer(prompt, return_tensors="pt").input_ids.to(device)
    
    # Generation config
    gen_cfg = MDMGenerationConfig(max_new_tokens=128, steps=200, temperature=0.7)
    
    with torch.no_grad():
        outputs = model.diffusion_generate(inputs=input_ids, generation_config=gen_cfg)
    
    print(tokenizer.decode(outputs.sequences[0], skip_special_tokens=True))
    

    👉 For full logging, history tracking, and file output:

    python sample.py
    

    📊 Benchmarking

    We release a fully open-source evaluation suite for diffusion-based LLMs (dLLMs), covering both standard code generation tasks and code infilling tasks.

    Benchmarks include: HumanEval / HumanEval+, MBPP / MBPP+, HumanEval-Infill, SantaCoder-FIM.


    Standard Code Generation
    MethodHumanEvalHumanEval+MBPPMBPP+
    Pass@1Pass@10Pass@1Pass@10Pass@1Pass@10Pass@1Pass@10
    LLaDA (8B)35.450.030.543.338.853.452.669.1
    Dream (7B)56.759.250.053.755.456.271.572.5
    Mask DFM (1.3B)9.117.67.913.46.225.0––
    Edit Flow (1.3B)12.824.310.420.710.036.4––
    Open-dCoder (0.5B, Ours)20.838.417.635.216.738.423.953.6

    Despite being only 0.5B parameters, Open-dCoder competes with much larger dLLMs in code completion tasks.


    Code Infilling
    MethodHumanEval Infill Pass@1SantaCoder Exact Match
    LLaDA-8B48.335.1
    Dream-7B39.440.7
    DiffuCoder-7B54.838.8
    Dream-Coder-7B55.340.0
    Open-dCoder (0.5B, Ours)32.529.6
    Open-dCoder (0.5B, Ours) Oracle Length77.456.4

    We followed the average fixed length evaluation setting in DreamOn to get the results.


    🧪 Evaluation

    Install evaluation packages:

    pip install -e lm-evaluation-harness human-eval-infilling
    
    Code Completion (HumanEval, MBPP)
    cd eval/eval_completion
    bash run_eval.sh
    
    Code Infilling
    cd eval/eval_infill
    bash run_eval.sh
    

    🏋️ Pretraining

    • Data: Concise, high-quality code corpus FineCode, hosted on Hugging Face.
    • Initialization: Following Dream, continued pretraining from Qwen2.5-Coder, adapting it into the diffusion framework.
    • Loss: Masked Diffusion Model (MDM) objective — masking ratios uniformly sampled from [0,1], reconstructed with cross-entropy loss.

    Download Data

    python3 scripts/download_hf_data.py --repo_id fredzzp/fine_code --local_dir ./data
    

    Training

    export TOKENIZERS_PARALLELISM=false
    NNODES=1
    NPROC_PER_NODE=$(nvidia-smi --query-gpu=name --format=csv,noheader | wc -l)
    NODE_RANK=${NODE_RANK:=0}
    MASTER_ADDR=${MASTER_ADDR:=0.0.0.0}
    MASTER_PORT=${MASTER_PORT:=12345}
    
    
    
    torchrun --nnodes=$NNODES --nproc-per-node $NPROC_PER_NODE --node-rank $NODE_RANK \
      --master-addr=$MASTER_ADDR --master-port=$MASTER_PORT tasks/train_torch.py \
      configs/pretrain/qwen2_5_coder_500M.yaml \
      --data.train_path=data/data \
      --train.ckpt_manager=dcp \
      --train.micro_batch_size=16 \
      --train.global_batch_size=512 \
      --train.output_dir=logs/Qwen2.5-Coder-0.5B_mdm \
      --train.save_steps=10000
    

    example of multi-node training with repr alignment loss:

    
    export TOKENIZERS_PARALLELISM=false
    
    NNODES=${NNODES:=1}
    NPROC_PER_NODE=$(nvidia-smi --query-gpu=name --format=csv,noheader | wc -l)
    NODE_RANK=${NODE_RANK:=0}
    MASTER_ADDR=${MASTER_ADDR:=0.0.0.0}
    MASTER_PORT=${MASTER_PORT:=12345}
    torchrun --nnodes=$NNODES --nproc-per-node $NPROC_PER_NODE --node-rank $NODE_RANK   --master-addr=$MASTER_ADDR --master-port=$MASTER_PORT  tasks/train_torch.py \
    configs/pretrain/qwen2_5_coder_500M.yaml --data.train_path=data/data \
    --data.num_workers=0 \
    --data.prefetch_factor=1 \
    --train.ckpt_manager=dcp \
    --train.micro_batch_size=3 \
    --train.global_batch_size=240 \
    --train.repr_align_wt=10.0 \
    --model.model_path=Qwen/Qwen2.5-Coder-3B-Instruct \
    --train.save_steps=10000 \
    --train.output_dir=logs/Qwen2.5-Coder-3B-Instruct_mdm_repr_align-10
    

    Uploading Checkpoints to Hugging Face

    from huggingface_hub import HfApi
    
    REPO_ID = "fredzzp/open-dcoder-0.5B"
    LOCAL_DIR = "logs/Qwen2.5-Coder-0.5B_mdm/checkpoints/global_step_370000/hf_ckpt"
    
    api = HfApi()
    api.create_repo(repo_id=REPO_ID, repo_type="model", exist_ok=True)
    api.upload_folder(repo_id=REPO_ID, repo_type="model", folder_path=LOCAL_DIR)
    

    🙏 Appreciation

    This project builds on incredible prior work:

    We stand on the shoulders of these projects, and hope Open-dLLM contributes back to the diffusion LLM community.

    📚 Citation

    If you use Open-dLLM or Open-dCoder in your research, please cite us:

    @misc{opendllm2025,
      title        = {Open-dLLM: Open Diffusion Large Language Models},
      author       = {Fred Zhangzhi Peng, Shuibai Zhang, Alex Tong, and contributors},
      year         = {2025},
      howpublished = {\url{https://github.com/pengzhangzhi/Open-dLLM}},
      note         = {Blog: \url{https://oval-shell-31c.notion.site/Open-Diffusion-Large-Language-Model-25e03bf6136480b7a4ebe3d53be9f68a?pvs=74}, 
                      Model: \url{https://huggingface.co/fredzzp/open-dcoder-0.5B}}
    }