DiffuRefill-1B base: weights, code, evaluation, technical report
Browse files- .gitattributes +1 -0
- README.md +138 -0
- config.json +21 -0
- eval/bench_ar.py +16 -0
- eval/bench_speed.py +70 -0
- eval/dlm_lmeval.py +152 -0
- eval/results.json +28 -0
- model.safetensors +3 -0
- modeling_diffurefill.py +142 -0
- paper/DiffuRefill-1B-technical-report.pdf +3 -0
- paper/diffurefill.typ +199 -0
- paper/refs.yml +84 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
paper/DiffuRefill-1B-technical-report.pdf filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
+
license: apache-2.0
|
| 5 |
+
library_name: pytorch
|
| 6 |
+
pipeline_tag: text-generation
|
| 7 |
+
tags:
|
| 8 |
+
- diffusion
|
| 9 |
+
- masked-diffusion
|
| 10 |
+
- mdlm
|
| 11 |
+
- dllm
|
| 12 |
+
- diloco
|
| 13 |
+
- pretraining
|
| 14 |
+
datasets:
|
| 15 |
+
- openbmb/Ultra-FineWeb-L3
|
| 16 |
+
- allenai/dolma3_dolmino_mix-100B-1125
|
| 17 |
+
- nvidia/Nemotron-Pretraining-Specialized-v1
|
| 18 |
+
- nvidia/Nemotron-Pretraining-Specialized-v1.2
|
| 19 |
+
- nvidia/Nemotron-CC-Math-v1
|
| 20 |
+
- openbmb/UltraData-Code
|
| 21 |
+
- openbmb/UltraData-Math
|
| 22 |
+
- OpenCoder-LLM/opc-annealing-corpus
|
| 23 |
+
---
|
| 24 |
+
|
| 25 |
+
# DiffuRefill-1B (base)
|
| 26 |
+
|
| 27 |
+
**A 1.08B-parameter masked-diffusion language model, pretrained from scratch for $0 on free, preemptible notebook GPUs.**
|
| 28 |
+
|
| 29 |
+
- 200,000 steps, **92.8B tokens**, 21 days (2026-09-10 → 2026-10-01)
|
| 30 |
+
- ~200 worker launches on free RTX PRO 6000 notebooks that are reclaimed without warning; the whole fleet was lost and rebuilt many times
|
| 31 |
+
- The only shared state was this Hub: workers train 150 steps alone, upload, and a restartable merger averages them (DiLoCo)
|
| 32 |
+
- 📄 **Technical report:** [`paper/DiffuRefill-1B-technical-report.pdf`](paper/DiffuRefill-1B-technical-report.pdf)
|
| 33 |
+
|
| 34 |
+
This is a **base model**: no instruction tuning, no safety tuning. It writes fluent English and often gets facts wrong.
|
| 35 |
+
|
| 36 |
+
## What it is
|
| 37 |
+
|
| 38 |
+
DiffuRefill is a bidirectional transformer trained with the masked-diffusion (MDLM) objective: random tokens are replaced by `[MASK]` and the model learns to fill them in from both sides. Instead of writing text strictly left to right, it starts from a row of masks and fills it in over several passes, and it can commit several tokens per pass.
|
| 39 |
+
|
| 40 |
+
| | |
|
| 41 |
+
|---|---|
|
| 42 |
+
| Parameters | 1.08B (tied embeddings) |
|
| 43 |
+
| Layers / width / heads | 18 / 2048 / 16 |
|
| 44 |
+
| FFN | SwiGLU, 5632 |
|
| 45 |
+
| Positions / norm | RoPE / RMSNorm (pre-norm) |
|
| 46 |
+
| Context | 2048 |
|
| 47 |
+
| Tokenizer | [`openbmb/MiniCPM4-0.5B`](https://huggingface.co/openbmb/MiniCPM4-0.5B) |
|
| 48 |
+
| Weights | uniform average of the last 130 merged models (steps ~181k–200k) |
|
| 49 |
+
|
| 50 |
+
## Usage
|
| 51 |
+
|
| 52 |
+
```python
|
| 53 |
+
# pip install torch transformers safetensors huggingface_hub
|
| 54 |
+
from huggingface_hub import hf_hub_download
|
| 55 |
+
import importlib.util, torch
|
| 56 |
+
|
| 57 |
+
path = hf_hub_download("Asilarkness/DiffuRefill-1B-base", "modeling_diffurefill.py")
|
| 58 |
+
spec = importlib.util.spec_from_file_location("modeling_diffurefill", path)
|
| 59 |
+
mod = importlib.util.module_from_spec(spec); spec.loader.exec_module(mod)
|
| 60 |
+
|
| 61 |
+
model = mod.DiffuRefill.from_pretrained("Asilarkness/DiffuRefill-1B-base").cuda()
|
| 62 |
+
|
| 63 |
+
# one token per pass: slowest, most coherent
|
| 64 |
+
print(model.generate("The theory of relativity states that", max_new_tokens=64))
|
| 65 |
+
# 4 tokens per pass: ~4x fewer passes, some quality loss
|
| 66 |
+
print(model.generate("The theory of relativity states that", max_new_tokens=64, per_pass=4))
|
| 67 |
+
|
| 68 |
+
# scoring: log p(continuation | context), the scorer used for the benchmarks
|
| 69 |
+
print(model.loglikelihood("The capital of France is", " Paris.")) # -2.03
|
| 70 |
+
print(model.loglikelihood("The capital of France is", " Berlin.")) # -8.11
|
| 71 |
+
```
|
| 72 |
+
|
| 73 |
+
## Benchmarks
|
| 74 |
+
|
| 75 |
+
Zero-shot, [lm-evaluation-harness](https://github.com/EleutherAI/lm-evaluation-harness), every model run by us with the same harness and settings. Our model is plugged into the harness with a left-to-right chain-rule scorer ([`eval/dlm_lmeval.py`](eval/dlm_lmeval.py)). A Monte-Carlo ELBO estimator, as used by LLaDA, scored slightly *lower* (HellaSwag 40.8 vs 42.5 on 1000 items), so the scorer does not understate the model.
|
| 76 |
+
|
| 77 |
+
| Model | Type | Params | Tokens | Train FLOPs | HellaSwag | ARC-e | ARC-c | PIQA | WinoGr. | OBQA | SciQ | LAMBADA | MMLU |
|
| 78 |
+
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
| 79 |
+
| **DiffuRefill-1B** | diffusion | 1.08B | **0.09T** | **6.0e20** | 34.8 | 52.4 | 25.0 | 62.7 | 50.6 | 27.4 | **89.5** | 34.0 | 26.9 |
|
| 80 |
+
| Pythia-1B | AR | 1.0B | 0.3T | 1.8e21 | 47.2 | 56.9 | 27.0 | 69.4 | 54.1 | 31.2 | 83.4 | 55.8 | 23.1 |
|
| 81 |
+
| SmolLM2-360M | AR | 0.36B | 4T | 8.6e21 | 56.3 | 70.3 | 38.1 | 71.5 | 58.9 | 37.8 | 91.1 | 53.4 | 25.5 |
|
| 82 |
+
| Qwen2.5-0.5B | AR | 0.49B | 18T | 5.3e22 | 52.2 | 64.9 | 31.8 | 69.9 | 56.1 | 35.0 | 93.0 | 52.0 | 47.5 |
|
| 83 |
+
| SmolLM2-1.7B | AR | 1.7B | 11T | 1.1e23 | 71.2 | 77.8 | 47.1 | 77.6 | 65.9 | 44.0 | 93.3 | 67.5 | 48.5 |
|
| 84 |
+
| Qwen2.5-1.5B | AR | 1.5B | 18T | 1.7e23 | 67.8 | 75.5 | 45.0 | 75.9 | 63.5 | 40.6 | 94.3 | 62.2 | 59.7 |
|
| 85 |
+
|
| 86 |
+
HellaSwag, ARC-c, PIQA, OBQA: length-normalised accuracy; the rest: accuracy. FLOPs ≈ 6·params·tokens.
|
| 87 |
+
|
| 88 |
+
**Read this honestly.** DiffuRefill-1B is clearly behind autoregressive models of its size. Every one of them used 3× (Pythia) to 280× (Qwen2.5-1.5B) more training compute, and masked diffusion is known to need much more compute than autoregression for the same likelihood (≈16× by [Nie et al., 2025](https://arxiv.org/abs/2410.18514)). It is relatively strong on SciQ (science facts, matching the fact-heavy anneal) and weakest on LAMBADA and WinoGrande (at chance). TinyLlama and OLMo-1B were also run but load incorrectly under the current `transformers` (e.g. OLMo LAMBADA 0%), so they are left out. All raw numbers are in [`eval/results.json`](eval/results.json).
|
| 89 |
+
|
| 90 |
+
## Speed
|
| 91 |
+
|
| 92 |
+
Greedy generation of 256 tokens after a 32-token prompt, one RTX PRO 6000 (96 GB), bf16. Autoregressive models use Hugging Face `generate()` with a KV cache; DiffuRefill uses no cache and re-reads the whole row each pass.
|
| 93 |
+
|
| 94 |
+
| tokens / s | DiffuRefill-1B | SmolLM2-1.7B | Qwen2.5-1.5B |
|
| 95 |
+
|---|---|---|---|
|
| 96 |
+
| batch 1, 1 token per pass | **193** | 101 | 82 |
|
| 97 |
+
| batch 1, 8 tokens per pass | **1536** | – | – |
|
| 98 |
+
| batch 32, 1 token per pass | 431 | **3119** | 2612 |
|
| 99 |
+
| batch 32, 8 tokens per pass | **3449** | – | – |
|
| 100 |
+
|
| 101 |
+
At batch 1 (latency) diffusion wins: 1.9× at the same quality setting and 15× at 8 tokens per pass. At batch 32 (throughput) the KV cache wins unless diffusion commits 8 tokens per pass. More tokens per pass costs quality, and optimised AR servers such as vLLM are much faster than HF `generate()`.
|
| 102 |
+
|
| 103 |
+
## How it was trained
|
| 104 |
+
|
| 105 |
+
| | |
|
| 106 |
+
|---|---|
|
| 107 |
+
| Objective | MDLM masked diffusion, independent token masking; document-masked attention; salient span masking on 25% of rows; 10% of micro-batches as 128-token rows |
|
| 108 |
+
| Optimiser | AdamW (0.9, 0.95), wd 0.1, clip 1.0; per-worker batch 64×2048 = 131k tokens |
|
| 109 |
+
| Distributed | DiLoCo over the Hub: 150 local steps, plain averaging (outer lr 1, no momentum), 2–8 workers |
|
| 110 |
+
| LR | warm-up 500 → 3e-4 (halved to 1.5e-4 early), cosine to 10%, then linear to zero from step 180k |
|
| 111 |
+
| Data, steps 0–158.8k | Ultra-FineWeb-L3 (English Multi-Style and QA synthetic), later with 5% generated fact sentences |
|
| 112 |
+
| Data, steps 158.8k–200k | anneal mix: Dolmino (OLMo 3 stage 2) 20%, Nemotron Fact-Seeking 15%, Wiki-Rewrite 15%, Ultra-FineWeb-L3 18%, Nemotron-CC-Math 8%, UltraData-Code L3 7%, OpenCoder annealing 8%, UltraData-Math exercises 4%, generated facts 5% |
|
| 113 |
+
| Hardware | free RTX PRO 6000 Blackwell (96 GB) notebooks, ~35k tokens/s per GPU |
|
| 114 |
+
|
| 115 |
+
### Lessons (details in the report)
|
| 116 |
+
|
| 117 |
+
- ✅ Adopt the merged model by **replacement**. Keeping local drift made 60 of 63 merges worse.
|
| 118 |
+
- ✅ **Halve the LR for the merge interval.** Local drift fell 6× and a 1.3B-token plateau ended.
|
| 119 |
+
- ✅ **Document masking** and **10% short rows** helped. Uniform weight averaging was the best final checkpoint.
|
| 120 |
+
- ❌ Outer **Nesterov** momentum, a **mid-run switch to Muon**, **span/PMI masking**, **phrase tokens** and **cautious AdamW** did not help this run.
|
| 121 |
+
- 🔬 On a small test model, writing a chain of thought first and then filling the answer **in one parallel pass** lifted a multi-step arithmetic task from 45% to 100%. That is the plan for the reasoning stage.
|
| 122 |
+
|
| 123 |
+
## Limitations
|
| 124 |
+
|
| 125 |
+
This is one run, and interventions were chosen on small probes and a 38M test model. The fact probe overlaps with the Wikipedia-derived anneal data. The model is English only and has no safety tuning, so do not use it for anything that matters without further training.
|
| 126 |
+
|
| 127 |
+
## Citation
|
| 128 |
+
|
| 129 |
+
```bibtex
|
| 130 |
+
@misc{diffurefill2026,
|
| 131 |
+
title = {DiffuRefill-1B: Pretraining a Masked Diffusion Language Model on Free, Preemptible Notebook GPUs},
|
| 132 |
+
author = {Asilarkness},
|
| 133 |
+
year = {2026},
|
| 134 |
+
url = {https://huggingface.co/Asilarkness/DiffuRefill-1B-base}
|
| 135 |
+
}
|
| 136 |
+
```
|
| 137 |
+
|
| 138 |
+
Compute was provided free by molab notebooks. Engineering was done with Claude Code (Anthropic) as an assistant. The training run's working repository, with intermediate checkpoints and logs, is [Asilarkness/DiffuRefill-1B](https://huggingface.co/Asilarkness/DiffuRefill-1B).
|
config.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"model_type": "diffurefill",
|
| 3 |
+
"architecture": "bidirectional transformer, masked diffusion (MDLM objective)",
|
| 4 |
+
"vocab_size": 73760,
|
| 5 |
+
"dim": 2048,
|
| 6 |
+
"layers": 18,
|
| 7 |
+
"heads": 16,
|
| 8 |
+
"ff": 5632,
|
| 9 |
+
"max_len": 2048,
|
| 10 |
+
"activation": "swiglu",
|
| 11 |
+
"norm": "rmsnorm (pre-norm)",
|
| 12 |
+
"position": "rope (base 10000)",
|
| 13 |
+
"tied_embeddings": true,
|
| 14 |
+
"mask_token_id": 73759,
|
| 15 |
+
"pad_token_id": 73758,
|
| 16 |
+
"tokenizer": "openbmb/MiniCPM4-0.5B",
|
| 17 |
+
"parameters": 1076000000,
|
| 18 |
+
"training_tokens": 92841363200,
|
| 19 |
+
"training_steps": 200000,
|
| 20 |
+
"weights": "uniform average (SWA) of the 130 merged globals from round 752 to 881 (steps ~181k-200k)"
|
| 21 |
+
}
|
eval/bench_ar.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Autoregressive baselines on the same lm-eval tasks, zero-shot, one task at a time."""
|
| 2 |
+
import os, json, lm_eval
|
| 3 |
+
tasks = os.environ.get("EV_TASKS", "hellaswag,arc_easy,arc_challenge,piqa,winogrande,openbookqa,sciq,lambada_openai,mmlu").split(",")
|
| 4 |
+
name = os.environ["EV_MODEL"]
|
| 5 |
+
out = os.environ.get("EV_OUT", "/tmp/bench_ar.json")
|
| 6 |
+
res = {}
|
| 7 |
+
for t in tasks:
|
| 8 |
+
try:
|
| 9 |
+
r = lm_eval.simple_evaluate(model="hf", model_args="pretrained=%s,dtype=bfloat16" % name, tasks=[t],
|
| 10 |
+
num_fewshot=0, batch_size="auto", bootstrap_iters=0)
|
| 11 |
+
res.update(r["results"])
|
| 12 |
+
print("RESULT", t, json.dumps(r["results"].get(t, {})), flush=True)
|
| 13 |
+
except Exception as e:
|
| 14 |
+
print("TASKFAIL", t, str(e)[:200], flush=True)
|
| 15 |
+
json.dump(res, open(out, "w"))
|
| 16 |
+
print("BENCH DONE", flush=True)
|
eval/bench_speed.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Generation speed on one GPU: DiffuRefill-1B vs autoregressive baselines.
|
| 2 |
+
|
| 3 |
+
Same job for every model: a 32-token prompt, 256 new tokens, greedy, batch 1 and
|
| 4 |
+
batch 32, bf16; tokens/s counts only new tokens, after a warm-up run.
|
| 5 |
+
|
| 6 |
+
ours K tokens committed per forward pass (the K most confident masked
|
| 7 |
+
positions, left to right within a 32-token block). K=1 is the
|
| 8 |
+
one-token-per-pass order that keeps text coherent; larger K trades
|
| 9 |
+
quality for passes. No KV cache: every pass re-reads the full row.
|
| 10 |
+
AR Hugging Face generate() with its KV cache.
|
| 11 |
+
"""
|
| 12 |
+
import os, sys, time, json
|
| 13 |
+
import torch
|
| 14 |
+
import torch.nn.functional as F
|
| 15 |
+
|
| 16 |
+
MODE = os.environ.get("SP_MODE", "ours")
|
| 17 |
+
NEW, PROMPT = 256, 32
|
| 18 |
+
OUT = os.environ.get("SP_OUT", "/tmp/speed.json")
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def timed(fn):
|
| 22 |
+
torch.cuda.synchronize(); t = time.perf_counter(); fn(); torch.cuda.synchronize()
|
| 23 |
+
return time.perf_counter() - t
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
res = {}
|
| 27 |
+
if MODE == "ours":
|
| 28 |
+
os.environ.setdefault("BG_DOCMASK", "0")
|
| 29 |
+
sys.path.insert(0, "/tmp")
|
| 30 |
+
from big_common import Net, MASK_ID, VOCAB
|
| 31 |
+
from huggingface_hub import hf_hub_download
|
| 32 |
+
g = torch.load(hf_hub_download("Asilarkness/DiffuRefill-1B", "final/DiffuRefill-1B-200k-swa.pt", local_dir="/tmp/dlm"),
|
| 33 |
+
map_location="cpu", weights_only=False)
|
| 34 |
+
net = Net(); net.load_state_dict({k: v.float() for k, v in g["model"].items()})
|
| 35 |
+
net = net.cuda().to(torch.bfloat16).eval()
|
| 36 |
+
|
| 37 |
+
@torch.no_grad()
|
| 38 |
+
def gen(B, K, block=32):
|
| 39 |
+
x = torch.randint(0, 50000, (B, PROMPT + NEW), device="cuda")
|
| 40 |
+
x[:, PROMPT:] = MASK_ID
|
| 41 |
+
for b0 in range(PROMPT, PROMPT + NEW, block):
|
| 42 |
+
for _ in range(block // K):
|
| 43 |
+
lg = net(x)[:, b0:b0 + block, :VOCAB - 2].float()
|
| 44 |
+
conf, tok = F.softmax(lg, -1).max(-1)
|
| 45 |
+
masked = x[:, b0:b0 + block] == MASK_ID
|
| 46 |
+
conf = torch.where(masked, conf, torch.full_like(conf, -1))
|
| 47 |
+
idx = conf.topk(K, -1).indices
|
| 48 |
+
blk = x[:, b0:b0 + block]
|
| 49 |
+
blk.scatter_(1, idx, tok.gather(1, idx))
|
| 50 |
+
return x
|
| 51 |
+
|
| 52 |
+
for B in (1, 32):
|
| 53 |
+
for K in (1, 2, 4, 8):
|
| 54 |
+
gen(B, K)
|
| 55 |
+
t = timed(lambda: gen(B, K))
|
| 56 |
+
res["ours B%d K%d" % (B, K)] = B * NEW / t
|
| 57 |
+
print("SPEED ours B=%d K=%d: %.0f tok/s (%.2fs)" % (B, K, B * NEW / t, t), flush=True)
|
| 58 |
+
else:
|
| 59 |
+
from transformers import AutoModelForCausalLM
|
| 60 |
+
m = AutoModelForCausalLM.from_pretrained(MODE, torch_dtype=torch.bfloat16).cuda().eval()
|
| 61 |
+
for B in (1, 32):
|
| 62 |
+
ids = torch.randint(100, 20000, (B, PROMPT), device="cuda")
|
| 63 |
+
kw = dict(max_new_tokens=NEW, min_new_tokens=NEW, do_sample=False, pad_token_id=0)
|
| 64 |
+
with torch.no_grad():
|
| 65 |
+
m.generate(ids, **kw)
|
| 66 |
+
t = timed(lambda: m.generate(ids, **kw))
|
| 67 |
+
res["%s B%d" % (MODE, B)] = B * NEW / t
|
| 68 |
+
print("SPEED %s B=%d: %.0f tok/s (%.2fs)" % (MODE, B, B * NEW / t, t), flush=True)
|
| 69 |
+
json.dump(res, open(OUT, "w"))
|
| 70 |
+
print("SPEED DONE", flush=True)
|
eval/dlm_lmeval.py
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""DiffuRefill-1B as an lm-eval-harness model, so it is scored on exactly the
|
| 2 |
+
tasks, prompts and metrics the autoregressive baselines are.
|
| 3 |
+
|
| 4 |
+
A masked-diffusion model has no left-to-right likelihood of its own; it scores a
|
| 5 |
+
continuation by the chain rule in left-to-right order. For a continuation
|
| 6 |
+
x_1..x_n after context c, row i is
|
| 7 |
+
|
| 8 |
+
<bos> c x_1 .. x_{i-1} [MASK] * (n - i + 1)
|
| 9 |
+
|
| 10 |
+
and log p(x_i | c, x_<i) is read at the first masked position. The model knows
|
| 11 |
+
the continuation's length (the masks are there) but sees none of its later
|
| 12 |
+
tokens, so the sum over i is a proper likelihood of x under the decoding order
|
| 13 |
+
the model is later sampled in. The same chain gives `is_greedy`: every x_i is
|
| 14 |
+
the argmax at its own step.
|
| 15 |
+
|
| 16 |
+
Rows are grouped by exact length, so no padding is ever attended to (attention
|
| 17 |
+
is bidirectional), and only the scored position goes through the 73k-way head.
|
| 18 |
+
"""
|
| 19 |
+
import os, sys, time, collections
|
| 20 |
+
import torch
|
| 21 |
+
import torch.nn.functional as F
|
| 22 |
+
|
| 23 |
+
os.environ.setdefault("BG_DOCMASK", "0")
|
| 24 |
+
sys.path.insert(0, "/tmp")
|
| 25 |
+
from big_common import Net, MASK_ID, VOCAB, SEQ
|
| 26 |
+
from lm_eval.api.model import LM
|
| 27 |
+
|
| 28 |
+
REPO = "Asilarkness/DiffuRefill-1B"
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class DLM(LM):
|
| 32 |
+
def __init__(self, ckpt="final/DiffuRefill-1B-200k-swa.pt", budget=65536, device="cuda"):
|
| 33 |
+
super().__init__()
|
| 34 |
+
from huggingface_hub import hf_hub_download
|
| 35 |
+
from transformers import AutoTokenizer
|
| 36 |
+
self.tk = AutoTokenizer.from_pretrained("openbmb/MiniCPM4-0.5B", trust_remote_code=True)
|
| 37 |
+
self.bos = self.tk.bos_token_id if self.tk.bos_token_id is not None else 1
|
| 38 |
+
p = ckpt if ckpt.startswith("/") else hf_hub_download(REPO, ckpt, local_dir="/tmp/dlm")
|
| 39 |
+
g = torch.load(p, map_location="cpu", weights_only=False)
|
| 40 |
+
net = Net()
|
| 41 |
+
net.load_state_dict({k: v.float() for k, v in g["model"].items()})
|
| 42 |
+
self.net = net.to(device, torch.bfloat16).eval()
|
| 43 |
+
self.dev, self.budget = device, budget
|
| 44 |
+
|
| 45 |
+
def _enc(self, s):
|
| 46 |
+
return [i for i in self.tk(s, add_special_tokens=False).input_ids if i < VOCAB - 2]
|
| 47 |
+
|
| 48 |
+
def _pair(self, ctx, cont):
|
| 49 |
+
# as lm-eval's HF model: trailing context whitespace belongs to the continuation
|
| 50 |
+
n = len(ctx) - len(ctx.rstrip())
|
| 51 |
+
if n:
|
| 52 |
+
cont, ctx = ctx[-n:] + cont, ctx[:-n]
|
| 53 |
+
whole = self._enc(ctx + cont)
|
| 54 |
+
c = self._enc(ctx)
|
| 55 |
+
x = whole[len(c):]
|
| 56 |
+
if not x or whole[:len(c)] != c: # tokenisation merged across the boundary
|
| 57 |
+
x = self._enc(cont)
|
| 58 |
+
c = [self.bos] + c
|
| 59 |
+
c = c[-(SEQ - len(x)):] # keep the end of a long context
|
| 60 |
+
return c, x
|
| 61 |
+
|
| 62 |
+
@torch.no_grad()
|
| 63 |
+
def _score_rows(self, rows):
|
| 64 |
+
"""rows: list of (ids, pos, target); all ids the same length. -> logp, argmax"""
|
| 65 |
+
ids = torch.tensor([r[0] for r in rows], device=self.dev)
|
| 66 |
+
pos = torch.tensor([r[1] for r in rows], device=self.dev)
|
| 67 |
+
tgt = torch.tensor([r[2] for r in rows], device=self.dev)
|
| 68 |
+
h = self.net.body(ids)[torch.arange(len(rows), device=self.dev), pos]
|
| 69 |
+
lp = F.log_softmax(self.net.head(h).float()[:, :VOCAB - 2], -1)
|
| 70 |
+
return lp.gather(1, tgt[:, None])[:, 0].tolist(), (lp.argmax(-1) == tgt).tolist()
|
| 71 |
+
|
| 72 |
+
def loglikelihood(self, requests, disable_tqdm=False):
|
| 73 |
+
if os.environ.get("EV_SCORER", "chain") == "elbo":
|
| 74 |
+
return self._elbo(requests)
|
| 75 |
+
jobs = collections.defaultdict(list) # length -> rows (req, ids, pos, tgt)
|
| 76 |
+
for k, r in enumerate(requests):
|
| 77 |
+
c, x = self._pair(*r.args)
|
| 78 |
+
n = len(x)
|
| 79 |
+
for i in range(n):
|
| 80 |
+
ids = c + x[:i] + [MASK_ID] * (n - i)
|
| 81 |
+
jobs[len(ids)].append((k, ids, len(c) + i, x[i]))
|
| 82 |
+
lp = [0.0] * len(requests)
|
| 83 |
+
greedy = [True] * len(requests)
|
| 84 |
+
t0, done, total = time.time(), 0, sum(len(v) for v in jobs.values())
|
| 85 |
+
for L in sorted(jobs):
|
| 86 |
+
rows = jobs[L]
|
| 87 |
+
B = max(1, self.budget // L)
|
| 88 |
+
for s in range(0, len(rows), B):
|
| 89 |
+
part = rows[s:s + B]
|
| 90 |
+
with torch.autocast("cuda", torch.bfloat16):
|
| 91 |
+
l, g = self._score_rows([(r[1], r[2], r[3]) for r in part])
|
| 92 |
+
for r, a, b in zip(part, l, g):
|
| 93 |
+
lp[r[0]] += a
|
| 94 |
+
greedy[r[0]] &= b
|
| 95 |
+
done += len(part)
|
| 96 |
+
print(" ll rows %d/%d (%.0fs)" % (done, total, time.time() - t0), flush=True)
|
| 97 |
+
return list(zip(lp, greedy))
|
| 98 |
+
|
| 99 |
+
@torch.no_grad()
|
| 100 |
+
def _elbo(self, requests, N=int(os.environ.get("EV_ELBO_N", "32"))):
|
| 101 |
+
"""LLaDA's conditional estimator: mask l of the n continuation tokens
|
| 102 |
+
(l stratified over 1..n, positions random), score (n/l) * sum of the
|
| 103 |
+
masked log-probs, average over N draws. A lower bound on log p(x|c);
|
| 104 |
+
used only as a cross-check of the chain-rule numbers."""
|
| 105 |
+
import random
|
| 106 |
+
rng = random.Random(0)
|
| 107 |
+
lp = [0.0] * len(requests)
|
| 108 |
+
jobs = collections.defaultdict(list) # length -> (req, ids, mask positions, targets, weight)
|
| 109 |
+
for k, r in enumerate(requests):
|
| 110 |
+
c, x = self._pair(*r.args)
|
| 111 |
+
n = len(x)
|
| 112 |
+
for j in range(N):
|
| 113 |
+
l = 1 + min(n - 1, int((j + rng.random()) / N * n))
|
| 114 |
+
pos = rng.sample(range(n), l)
|
| 115 |
+
ids = c + [MASK_ID if i in pos else t for i, t in enumerate(x)]
|
| 116 |
+
jobs[len(ids)].append((k, ids, [len(c) + i for i in pos], [x[i] for i in pos], n / l / N))
|
| 117 |
+
for L in sorted(jobs):
|
| 118 |
+
rows = jobs[L]
|
| 119 |
+
B = max(1, self.budget // L)
|
| 120 |
+
for s in range(0, len(rows), B):
|
| 121 |
+
part = rows[s:s + B]
|
| 122 |
+
ids = torch.tensor([r[1] for r in part], device=self.dev)
|
| 123 |
+
with torch.autocast("cuda", torch.bfloat16):
|
| 124 |
+
h = self.net.body(ids)
|
| 125 |
+
for b, r in enumerate(part):
|
| 126 |
+
q = F.log_softmax(self.net.head(h[b, r[2]]).float()[:, :VOCAB - 2], -1)
|
| 127 |
+
lp[r[0]] += r[4] * float(q.gather(1, torch.tensor(r[3], device=self.dev)[:, None]).sum())
|
| 128 |
+
return [(v, False) for v in lp]
|
| 129 |
+
|
| 130 |
+
def loglikelihood_rolling(self, requests, disable_tqdm=False):
|
| 131 |
+
raise NotImplementedError("perplexity tasks are not used")
|
| 132 |
+
|
| 133 |
+
def generate_until(self, requests, disable_tqdm=False):
|
| 134 |
+
raise NotImplementedError("generation tasks are not used")
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
if __name__ == "__main__":
|
| 138 |
+
import json, lm_eval
|
| 139 |
+
tasks = os.environ.get("EV_TASKS", "hellaswag,arc_easy,arc_challenge,piqa,winogrande,openbookqa,sciq,lambada_openai,mmlu").split(",")
|
| 140 |
+
out = os.environ.get("EV_OUT", "/tmp/bench_dlm.json")
|
| 141 |
+
m = DLM(os.environ.get("EV_CKPT", "final/DiffuRefill-1B-200k-swa.pt"))
|
| 142 |
+
res = {}
|
| 143 |
+
for t in tasks: # one at a time: a broken task must not sink the rest
|
| 144 |
+
try:
|
| 145 |
+
lim = int(os.environ["EV_LIMIT"]) if os.environ.get("EV_LIMIT") else None
|
| 146 |
+
r = lm_eval.simple_evaluate(model=m, tasks=[t], num_fewshot=0, bootstrap_iters=0, limit=lim)
|
| 147 |
+
res.update({k: v for k, v in r["results"].items()})
|
| 148 |
+
print("RESULT", t, json.dumps(r["results"].get(t, {})), flush=True)
|
| 149 |
+
except Exception as e:
|
| 150 |
+
print("TASKFAIL", t, str(e)[:200], flush=True)
|
| 151 |
+
json.dump(res, open(out, "w"))
|
| 152 |
+
print("BENCH DONE", flush=True)
|
eval/results.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"harness": "lm-evaluation-harness >=0.4.5, zero-shot, bootstrap off. Metrics: hellaswag/arc_challenge/piqa/openbookqa acc_norm; arc_easy/winogrande/sciq/lambada_openai/mmlu acc.",
|
| 3 |
+
"scorer_ours": "left-to-right chain rule over continuation tokens, later continuation tokens masked (dlm_lmeval.py)",
|
| 4 |
+
"models": {
|
| 5 |
+
"DiffuRefill-1B (ours)": {"params_B": 1.08, "tokens_T": 0.093, "hellaswag": 34.8, "arc_easy": 52.4, "arc_challenge": 25.0, "piqa": 62.7, "winogrande": 50.6, "openbookqa": 27.4, "sciq": 89.5, "lambada_openai": 34.0, "mmlu": 26.9},
|
| 6 |
+
"EleutherAI/pythia-1b": {"params_B": 1.01, "tokens_T": 0.3, "hellaswag": 47.2, "arc_easy": 56.9, "arc_challenge": 27.0, "piqa": 69.4, "winogrande": 54.1, "openbookqa": 31.2, "sciq": 83.4, "lambada_openai": 55.8, "mmlu": 23.1},
|
| 7 |
+
"HuggingFaceTB/SmolLM2-360M": {"params_B": 0.36, "tokens_T": 4, "hellaswag": 56.3, "arc_easy": 70.3, "arc_challenge": 38.1, "piqa": 71.5, "winogrande": 58.9, "openbookqa": 37.8, "sciq": 91.1, "lambada_openai": 53.4, "mmlu": 25.5},
|
| 8 |
+
"Qwen/Qwen2.5-0.5B": {"params_B": 0.49, "tokens_T": 18, "hellaswag": 52.2, "arc_easy": 64.9, "arc_challenge": 31.8, "piqa": 69.9, "winogrande": 56.1, "openbookqa": 35.0, "sciq": 93.0, "lambada_openai": 52.0, "mmlu": 47.5},
|
| 9 |
+
"HuggingFaceTB/SmolLM2-1.7B": {"params_B": 1.71, "tokens_T": 11, "hellaswag": 71.2, "arc_easy": 77.8, "arc_challenge": 47.1, "piqa": 77.6, "winogrande": 65.9, "openbookqa": 44.0, "sciq": 93.3, "lambada_openai": 67.5, "mmlu": 48.5},
|
| 10 |
+
"Qwen/Qwen2.5-1.5B": {"params_B": 1.54, "tokens_T": 18, "hellaswag": 67.8, "arc_easy": 75.5, "arc_challenge": 45.0, "piqa": 75.9, "winogrande": 63.5, "openbookqa": 40.6, "sciq": 94.3, "lambada_openai": 62.2, "mmlu": 59.7}
|
| 11 |
+
},
|
| 12 |
+
"excluded": "TinyLlama/TinyLlama_v1.1 and allenai/OLMo-1B-hf were run but load incorrectly under the current transformers (OLMo: LAMBADA 0%, SciQ 4%; TinyLlama: WinoGrande 49.7%), so they are not reported.",
|
| 13 |
+
"scorer_crosscheck": {"subset": "first 1000 docs", "hellaswag_acc_norm": {"chain": 42.5, "elbo_32": 40.8}, "winogrande_acc": {"chain": 50.3, "elbo_32": 51.3}},
|
| 14 |
+
"speed_tok_per_s": {
|
| 15 |
+
"setup": "one RTX PRO 6000 Blackwell 96GB, bf16, 32-token prompt, 256 new tokens, greedy. AR models: HF generate() with KV cache. Ours: no KV cache, block 32, K tokens committed per pass.",
|
| 16 |
+
"DiffuRefill-1B": {"B1_K1": 193, "B1_K2": 384, "B1_K4": 771, "B1_K8": 1536, "B32_K1": 431, "B32_K2": 863, "B32_K4": 1725, "B32_K8": 3449},
|
| 17 |
+
"SmolLM2-1.7B": {"B1": 101, "B32": 3119},
|
| 18 |
+
"Qwen2.5-1.5B": {"B1": 82, "B32": 2612}
|
| 19 |
+
},
|
| 20 |
+
"training_probes_final": {
|
| 21 |
+
"note": "fixed held-out masked CE (mask rates .3/.6/.9), wiki and code CE, PopQA fact probe (1050 facts)",
|
| 22 |
+
"global": {"heldout": 2.9503, "wiki": 3.5397, "code": 1.6668, "fact_mc": 0.558, "fact_nll": 5.899, "fact_em": 0.096},
|
| 23 |
+
"ema_0.9": {"heldout": 2.9503, "wiki": 3.5397, "code": 1.6667, "fact_mc": 0.558, "fact_nll": 5.899, "fact_em": 0.096},
|
| 24 |
+
"swa": {"heldout": 2.9501, "wiki": 3.5393, "code": 1.6639, "fact_mc": 0.561, "fact_nll": 5.894, "fact_em": 0.096},
|
| 25 |
+
"avg_last3_snapshots": {"heldout": 2.9502, "wiki": 3.5398, "code": 1.6656, "fact_mc": 0.557, "fact_nll": 5.900, "fact_em": 0.097},
|
| 26 |
+
"avg_last5_snapshots": {"heldout": 2.9503, "wiki": 3.5394, "code": 1.6641, "fact_mc": 0.559, "fact_nll": 5.895, "fact_em": 0.095}
|
| 27 |
+
}
|
| 28 |
+
}
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:52dac80dfcb0e182ae9d970a31b1bdad181f8dc67390bf1a5b641e0d2b14a9bf
|
| 3 |
+
size 2151972712
|
modeling_diffurefill.py
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""DiffuRefill-1B: a 1.08B-parameter masked-diffusion language model.
|
| 2 |
+
|
| 3 |
+
Standalone inference code: no dependency on the training stack.
|
| 4 |
+
|
| 5 |
+
from modeling_diffurefill import DiffuRefill
|
| 6 |
+
m = DiffuRefill.from_pretrained("Asilarkness/DiffuRefill-1B-base").cuda()
|
| 7 |
+
print(m.generate("The capital of France is", max_new_tokens=32))
|
| 8 |
+
|
| 9 |
+
The network is a bidirectional transformer (no causal mask) trained to fill in
|
| 10 |
+
[MASK] tokens (MDLM objective). Text is generated by starting from a row of
|
| 11 |
+
masks after the prompt and committing tokens over several passes.
|
| 12 |
+
"""
|
| 13 |
+
import json, math
|
| 14 |
+
import torch
|
| 15 |
+
import torch.nn as nn
|
| 16 |
+
import torch.nn.functional as F
|
| 17 |
+
|
| 18 |
+
TOKENIZER = "openbmb/MiniCPM4-0.5B"
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def _rope_cache(T, dh, device, base=10000.0):
|
| 22 |
+
inv = 1.0 / (base ** (torch.arange(0, dh, 2, device=device).float() / dh))
|
| 23 |
+
f = torch.outer(torch.arange(T, device=device).float(), inv)
|
| 24 |
+
return torch.cos(f)[None, None], torch.sin(f)[None, None]
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def _rope(x, cos, sin):
|
| 28 |
+
x1, x2 = x[..., ::2], x[..., 1::2]
|
| 29 |
+
return torch.stack([x1 * cos - x2 * sin, x1 * sin + x2 * cos], -1).flatten(-2)
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
class Block(nn.Module):
|
| 33 |
+
def __init__(self, dim, heads, ff):
|
| 34 |
+
super().__init__()
|
| 35 |
+
self.dim, self.heads = dim, heads
|
| 36 |
+
self.n1 = nn.RMSNorm(dim)
|
| 37 |
+
self.qkv = nn.Linear(dim, 3 * dim, bias=False)
|
| 38 |
+
self.o = nn.Linear(dim, dim, bias=False)
|
| 39 |
+
self.n2 = nn.RMSNorm(dim)
|
| 40 |
+
self.w1 = nn.Linear(dim, ff, bias=False)
|
| 41 |
+
self.w3 = nn.Linear(dim, ff, bias=False)
|
| 42 |
+
self.w2 = nn.Linear(ff, dim, bias=False)
|
| 43 |
+
|
| 44 |
+
def forward(self, x, cos, sin):
|
| 45 |
+
B, T, D = x.shape
|
| 46 |
+
H, dh = self.heads, D // self.heads
|
| 47 |
+
q, k, v = self.qkv(self.n1(x)).split(D, -1)
|
| 48 |
+
q = _rope(q.view(B, T, H, dh).transpose(1, 2), cos, sin)
|
| 49 |
+
k = _rope(k.view(B, T, H, dh).transpose(1, 2), cos, sin)
|
| 50 |
+
v = v.view(B, T, H, dh).transpose(1, 2)
|
| 51 |
+
a = F.scaled_dot_product_attention(q, k, v) # bidirectional
|
| 52 |
+
x = x + self.o(a.transpose(1, 2).reshape(B, T, D))
|
| 53 |
+
h = self.n2(x)
|
| 54 |
+
return x + self.w2(F.silu(self.w1(h)) * self.w3(h))
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
class DiffuRefill(nn.Module):
|
| 58 |
+
def __init__(self, vocab_size=73760, dim=2048, layers=18, heads=16, ff=5632, max_len=2048):
|
| 59 |
+
super().__init__()
|
| 60 |
+
self.cfg = dict(vocab_size=vocab_size, dim=dim, layers=layers, heads=heads, ff=ff, max_len=max_len)
|
| 61 |
+
self.mask_id, self.pad_id = vocab_size - 1, vocab_size - 2
|
| 62 |
+
self.tok = nn.Embedding(vocab_size, dim)
|
| 63 |
+
self.blocks = nn.ModuleList([Block(dim, heads, ff) for _ in range(layers)])
|
| 64 |
+
self.nf = nn.RMSNorm(dim)
|
| 65 |
+
self._tk = None
|
| 66 |
+
|
| 67 |
+
# ------------------------------------------------------------------ io
|
| 68 |
+
@classmethod
|
| 69 |
+
def from_pretrained(cls, repo="Asilarkness/DiffuRefill-1B-base", dtype=torch.bfloat16):
|
| 70 |
+
from huggingface_hub import hf_hub_download
|
| 71 |
+
from safetensors.torch import load_file
|
| 72 |
+
cfg = json.load(open(hf_hub_download(repo, "config.json")))
|
| 73 |
+
m = cls(**{k: cfg[k] for k in ("vocab_size", "dim", "layers", "heads", "ff", "max_len")})
|
| 74 |
+
m.load_state_dict(load_file(hf_hub_download(repo, "model.safetensors")))
|
| 75 |
+
return m.to(dtype).eval()
|
| 76 |
+
|
| 77 |
+
@property
|
| 78 |
+
def tokenizer(self):
|
| 79 |
+
if self._tk is None:
|
| 80 |
+
from transformers import AutoTokenizer
|
| 81 |
+
self._tk = AutoTokenizer.from_pretrained(TOKENIZER, trust_remote_code=True)
|
| 82 |
+
return self._tk
|
| 83 |
+
|
| 84 |
+
# ------------------------------------------------------------- network
|
| 85 |
+
def forward(self, ids):
|
| 86 |
+
"""ids (B, T) -> logits (B, T, vocab). The output head is tied to the embedding."""
|
| 87 |
+
T = ids.shape[1]
|
| 88 |
+
cos, sin = _rope_cache(T, self.cfg["dim"] // self.cfg["heads"], ids.device)
|
| 89 |
+
x = self.tok(ids)
|
| 90 |
+
for b in self.blocks:
|
| 91 |
+
x = b(x, cos.to(x.dtype), sin.to(x.dtype))
|
| 92 |
+
return F.linear(self.nf(x), self.tok.weight)
|
| 93 |
+
|
| 94 |
+
# ------------------------------------------------------------ sampling
|
| 95 |
+
@torch.no_grad()
|
| 96 |
+
def generate(self, prompt, max_new_tokens=64, per_pass=1, block=32, temperature=0.0, return_ids=False):
|
| 97 |
+
"""Fill `max_new_tokens` masks after the prompt.
|
| 98 |
+
|
| 99 |
+
Blocks of `block` positions are decoded left to right; inside a block,
|
| 100 |
+
each pass commits the `per_pass` most confident masked positions.
|
| 101 |
+
per_pass=1 is the slowest and the most coherent setting (one token per
|
| 102 |
+
pass; it removes the repetition loops that parallel commits cause);
|
| 103 |
+
larger values trade quality for speed.
|
| 104 |
+
"""
|
| 105 |
+
tk = self.tokenizer
|
| 106 |
+
dev = self.tok.weight.device
|
| 107 |
+
bos = tk.bos_token_id if tk.bos_token_id is not None else 1
|
| 108 |
+
p = [bos] + [i for i in tk(prompt, add_special_tokens=False).input_ids if i < self.pad_id]
|
| 109 |
+
x = torch.tensor([p + [self.mask_id] * max_new_tokens], device=dev)
|
| 110 |
+
P = len(p)
|
| 111 |
+
for b0 in range(P, P + max_new_tokens, block):
|
| 112 |
+
b1 = min(b0 + block, P + max_new_tokens)
|
| 113 |
+
while (x[0, b0:b1] == self.mask_id).any():
|
| 114 |
+
lg = self(x)[0, b0:b1, :self.pad_id].float()
|
| 115 |
+
if temperature > 0:
|
| 116 |
+
probs = F.softmax(lg / temperature, -1)
|
| 117 |
+
tok = torch.multinomial(probs, 1)[:, 0]
|
| 118 |
+
conf = probs.gather(1, tok[:, None])[:, 0]
|
| 119 |
+
else:
|
| 120 |
+
conf, tok = F.softmax(lg, -1).max(-1)
|
| 121 |
+
masked = x[0, b0:b1] == self.mask_id
|
| 122 |
+
conf = torch.where(masked, conf, torch.full_like(conf, -1.0))
|
| 123 |
+
k = min(per_pass, int(masked.sum()))
|
| 124 |
+
idx = conf.topk(k).indices
|
| 125 |
+
x[0, b0 + idx] = tok[idx]
|
| 126 |
+
out = x[0, P:].tolist()
|
| 127 |
+
return out if return_ids else tk.decode(out, skip_special_tokens=True)
|
| 128 |
+
|
| 129 |
+
@torch.no_grad()
|
| 130 |
+
def loglikelihood(self, context, continuation):
|
| 131 |
+
"""log p(continuation | context) by the left-to-right chain rule:
|
| 132 |
+
token i is predicted with tokens < i visible and tokens >= i masked.
|
| 133 |
+
This is the scorer used for the reported benchmark numbers."""
|
| 134 |
+
tk = self.tokenizer
|
| 135 |
+
dev = self.tok.weight.device
|
| 136 |
+
bos = tk.bos_token_id if tk.bos_token_id is not None else 1
|
| 137 |
+
c = [bos] + tk(context, add_special_tokens=False).input_ids
|
| 138 |
+
x = tk(continuation, add_special_tokens=False).input_ids
|
| 139 |
+
n = len(x)
|
| 140 |
+
rows = torch.tensor([c + x[:i] + [self.mask_id] * (n - i) for i in range(n)], device=dev)
|
| 141 |
+
lg = self(rows)[torch.arange(n, device=dev), torch.arange(len(c), len(c) + n, device=dev), :self.pad_id]
|
| 142 |
+
return float(F.log_softmax(lg.float(), -1).gather(1, torch.tensor(x, device=dev)[:, None]).sum())
|
paper/DiffuRefill-1B-technical-report.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:804d523f5144a4ca05aab49922e58ef9142857ccf7c3f5a2338cc8a20b7100ac
|
| 3 |
+
size 171488
|
paper/diffurefill.typ
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#set document(title: "DiffuRefill-1B: Pretraining a Masked Diffusion Language Model on Free, Preemptible Notebook GPUs", author: "Asilarkness")
|
| 2 |
+
#set page(paper: "a4", margin: (x: 2.1cm, y: 2.2cm), numbering: "1")
|
| 3 |
+
#set text(font: ("New Computer Modern", "Libertinus Serif"), size: 10pt)
|
| 4 |
+
#set par(justify: true, leading: 0.62em)
|
| 5 |
+
#set heading(numbering: "1.1")
|
| 6 |
+
#show heading.where(level: 1): it => block(above: 1.3em, below: 0.7em, text(size: 12pt, weight: "bold", it))
|
| 7 |
+
#show heading.where(level: 2): it => block(above: 1.0em, below: 0.5em, text(size: 10.5pt, weight: "bold", it))
|
| 8 |
+
#show table: set text(size: 8.6pt)
|
| 9 |
+
#show figure.caption: set text(size: 8.8pt)
|
| 10 |
+
|
| 11 |
+
#align(center)[
|
| 12 |
+
#text(size: 15pt, weight: "bold")[DiffuRefill-1B: Pretraining a Masked Diffusion\ Language Model on Free, Preemptible Notebook GPUs]
|
| 13 |
+
#v(0.6em)
|
| 14 |
+
#text(size: 11pt)[Asilarkness]
|
| 15 |
+
#v(0.2em)
|
| 16 |
+
#text(size: 9pt)[Technical report · October 2026 · #link("https://huggingface.co/Asilarkness/DiffuRefill-1B-base")[huggingface.co/Asilarkness/DiffuRefill-1B-base]]
|
| 17 |
+
]
|
| 18 |
+
#v(0.8em)
|
| 19 |
+
|
| 20 |
+
#block(inset: (x: 1.2cm))[
|
| 21 |
+
#text(weight: "bold")[Abstract.]
|
| 22 |
+
We pretrain DiffuRefill-1B, a 1.08B-parameter masked-diffusion language model, for 200,000 steps on 92.8B tokens without paying for any compute. Training ran for 21 days on free notebook GPUs that are reclaimed without warning, often several at once, and typically live for hours. The only state shared between machines is a public model repository on the Hugging Face Hub: workers take 150 local AdamW steps, push their weights, and a merger that can itself be killed and restarted anywhere averages them into the next global model (DiLoCo with plain replacement averaging). We describe the design that made this survive about 200 worker launches and repeated loss of the whole fleet, and we report the measurements that shaped the run, including the negative ones: keeping local drift at merge time, outer Nesterov momentum, a mid-run switch to Muon, span and PMI masking, phrase tokens and cautious AdamW all failed to help, while halving the learning rate for the merge interval, document masking, short rows and weight averaging did. On standard zero-shot benchmarks the model is weaker than autoregressive models trained with 3-280x more compute (HellaSwag 34.8, ARC-Easy 52.4, PIQA 62.7, SciQ 89.5), which we report as it is. As a diffusion model it generates 1.9x faster than comparable autoregressive models at batch size 1 when committing one token per pass, and up to 15x faster when committing eight. Weights, code and evaluation scripts are released.
|
| 23 |
+
]
|
| 24 |
+
|
| 25 |
+
= Introduction
|
| 26 |
+
|
| 27 |
+
Pretraining even a small language model is usually taken to require a budget: thousands of GPU-hours on machines that stay up. This report asks what a single person can do with none. The resource we had was free notebook GPUs (RTX PRO 6000 Blackwell, 96 GB, on the molab service), which come with two constraints that rule out ordinary data-parallel training: a box can be reclaimed at any moment, without notice, and boxes cannot talk to each other. In practice most boxes lived from one to a few hours, whole fleets of eight disappeared within the same minute several times, and new boxes arrived only when a person opened new notebooks.
|
| 28 |
+
|
| 29 |
+
We therefore built training around the one thing that persists: a public model repository on the Hugging Face Hub. Each worker trains on its own for a fixed number of steps, uploads its weights, and downloads the next average. This is DiLoCo @diloco with the Hub as parameter server and with every component, including the merger, allowed to die.
|
| 30 |
+
|
| 31 |
+
We chose a *masked diffusion* language model (MDLM @mdlm, @smdm) rather than an autoregressive one. Diffusion models predict any subset of positions from bidirectional context, can commit several tokens per forward pass, and are a natural fit for our longer-term goal: a model that first writes out its reasoning and then fills in an answer in parallel (§8). The price, known from prior work @smdm, is lower compute efficiency on likelihood-style benchmarks.
|
| 32 |
+
|
| 33 |
+
Our contributions are:
|
| 34 |
+
- *A fault-tolerant training recipe* for preemptible, mutually unreachable GPUs, using only a model hub for coordination (§3).
|
| 35 |
+
- *DiffuRefill-1B*, a 1.08B masked diffusion LM trained to 200k steps on 92.8B tokens at zero monetary cost, released with code (§4).
|
| 36 |
+
- *A record of measured interventions*, positive and negative, at 38M-parameter "stand" scale and at 1B (§5).
|
| 37 |
+
- *An honest evaluation* against autoregressive models on the same harness, and a generation-speed comparison (§6).
|
| 38 |
+
|
| 39 |
+
= Model
|
| 40 |
+
|
| 41 |
+
DiffuRefill-1B is a pre-norm transformer with bidirectional attention (Table 1). It is trained with the MDLM objective @mdlm: for each row a mask rate $t tilde U(0, 1)$ is drawn, each token is replaced by `[MASK]` with probability $t$, and the model is trained with cross entropy on the masked positions.
|
| 42 |
+
|
| 43 |
+
#figure(
|
| 44 |
+
table(columns: 2, align: (left, left), stroke: 0.4pt,
|
| 45 |
+
[Parameters], [1.08B (embedding tied to the output head)],
|
| 46 |
+
[Layers / width / heads], [18 / 2048 / 16 (head dim 128)],
|
| 47 |
+
[FFN], [SwiGLU, 5632],
|
| 48 |
+
[Normalisation, positions], [RMSNorm, RoPE (base $10^4$)],
|
| 49 |
+
[Context], [2048 tokens],
|
| 50 |
+
[Tokenizer], [MiniCPM4 (73,440 pieces; model vocabulary 73,760 incl. `[MASK]`)],
|
| 51 |
+
[Objective], [MDLM masked diffusion, independent token masking],
|
| 52 |
+
),
|
| 53 |
+
caption: [Architecture.],
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
Three data-side choices changed the objective in ways we measured (§5):
|
| 57 |
+
*Document masking.* Rows are packed documents, and with bidirectional attention a masked position can be filled from an unrelated neighbouring document. We restrict attention to the token's own document with FlexAttention block masks, which was also faster than full attention (13.2 ms vs 17.5 ms per call at the training shape) because blocks between documents are skipped.
|
| 58 |
+
*Salient span masking.* On 25% of rows, capitalised words that do not start a sentence, and numbers, are masked as whole spans, so that a name must be recalled from the sentence rather than completed from its visible half.
|
| 59 |
+
*Short rows.* 10% of micro-batches are reshaped into rows of 128 tokens, so the model also sees short contexts that begin at a document start.
|
| 60 |
+
|
| 61 |
+
= Training system
|
| 62 |
+
|
| 63 |
+
#figure(
|
| 64 |
+
table(columns: 2, align: (left, left), stroke: 0.4pt,
|
| 65 |
+
[Worker], [loads the latest global, trains $H=150$ local AdamW steps (batch 64 × 2048 tokens, 131k tokens per step), uploads `ckpt_wNN.pt` with its round tag and a small log],
|
| 66 |
+
[Merger], [waits until at least $N$ fresh checkpoints carry the current round tag (normally $N=2$; $N=1$ when one worker is left), allows a 150 s grace for stragglers, averages them, publishes `global_b.pt` and a new round tag],
|
| 67 |
+
[Outer step], [plain replacement: the new global is the mean of the workers (outer learning rate 1, no momentum)],
|
| 68 |
+
[Side averages], [the merger also keeps an EMA ($beta = 0.9$) of globals and, in the final stretch, a uniform average (SWA) and periodic snapshots],
|
| 69 |
+
[Recovery], [a lost merger is restarted on any surviving box; it first merges leftover checkpoints of dead workers ($N=1$), then waits for new workers; workers seed from the last global],
|
| 70 |
+
),
|
| 71 |
+
caption: [The hub-synchronised DiLoCo loop. The Hub repository is the only shared state.],
|
| 72 |
+
)
|
| 73 |
+
|
| 74 |
+
A round takes about 9.5 minutes regardless of how many workers take part, because every worker runs the same 150 steps; more workers add tokens per round, not rounds per hour. About 26% of wall time was spent waiting at synchronisation. A worker processes about 35k tokens/s on one RTX PRO 6000 with `torch.compile` per block (17% faster than eager; FP8 via torchao gave no further gain on this GPU).
|
| 75 |
+
|
| 76 |
+
*Failure handling.* Three rules carried the run through about 200 worker launches. (i) Liveness is read from the logs workers push, not from whether a notebook answers: endpoints drop connections in bursts, and a reachability check twice declared a healthy fleet dead. (ii) After a total fleet loss, the merger is started before any worker is seeded, so that checkpoints already uploaded by dead workers are merged rather than overwritten. (iii) A rollback is published under a new round number: a stale worker checkpoint carrying the same round tag as a re-published global was once merged into it. The repository history is periodically squashed to stay within storage limits.
|
| 77 |
+
|
| 78 |
+
= Data and schedule
|
| 79 |
+
|
| 80 |
+
For the first 158.8k steps the data was Ultra-FineWeb-L3 @ultrafineweb (English, the Multi-Style and QA synthetic rewrites of filtered web text), later with 5% of fact sentences generated by an open model. For the final 41k steps we annealed on a higher-quality mix (Table 3), streamed directly from the Hub with a custom reader that keeps memory bounded (the largest sources store up to 2.5 GB per decoded Parquet row group, which killed the first attempt).
|
| 81 |
+
|
| 82 |
+
#figure(
|
| 83 |
+
table(columns: 3, align: (left, right, left), stroke: 0.4pt,
|
| 84 |
+
[*Source*], [*Share*], [*Content*],
|
| 85 |
+
[Ultra-FineWeb-L3 (continuation)], [18%], [rewritten web text],
|
| 86 |
+
[Dolmino mix (OLMo 3 stage 2) @olmo3], [20%], [math, code, QA, science, high-quality web],
|
| 87 |
+
[Nemotron Pretraining Specialized: Fact-Seeking], [15%], [fact Q&A from Wikipedia],
|
| 88 |
+
[Nemotron Pretraining Specialized: Wiki-Rewrite], [15%], [rewritten Wikipedia],
|
| 89 |
+
[Nemotron-CC-Math (4+)], [8%], [math web pages],
|
| 90 |
+
[UltraData-Code L3], [7%], [code with explanations],
|
| 91 |
+
[OpenCoder annealing corpus], [8%], [algorithmic corpus, synthetic snippets],
|
| 92 |
+
[UltraData-Math textbook exercises], [4%], [synthetic exercises],
|
| 93 |
+
[Generated fact sentences], [5%], [our own, open-model generated],
|
| 94 |
+
),
|
| 95 |
+
caption: [Anneal mix for steps 158.8k-200k.],
|
| 96 |
+
)
|
| 97 |
+
|
| 98 |
+
The learning rate warmed up over 500 steps to $3 dot 10^(-4)$ and followed a cosine to 10% over 200k steps. It was halved to $1.5 dot 10^(-4)$ early in the run (§5.1). From step 180k it decayed linearly to zero at 200k @d2z, and the released weights are the uniform average of the 130 merged globals from step $approx$181k to 200k. AdamW used $beta = (0.9, 0.95)$, weight decay 0.1 and gradient clipping at 1.0. In total the model saw 92.8B tokens (summed over workers), about $6.0 dot 10^20$ training FLOPs by the $6 N D$ rule.
|
| 99 |
+
|
| 100 |
+
= What we measured
|
| 101 |
+
|
| 102 |
+
All 1B measurements below use a fixed held-out batch scored with fixed masks at rates 0.3/0.6/0.9, so the difference between two checkpoints carries no sampling noise. Training loss alone was misleading more than once: it stayed flat while held-out quality got worse (§5.1). Stand experiments use a 38M-parameter model with identical seeds per arm.
|
| 103 |
+
|
| 104 |
+
== Distributed optimisation
|
| 105 |
+
|
| 106 |
+
*Replacement beats keeping local drift.* We tried adopting the global as $theta arrow.l theta + (g - theta_"pushed")$, which keeps each worker's progress since its last push. Adoption then made the model worse in 60 of 63 probes (mean +0.079 CE) and the merged model drifted from 4.41 to 4.60 over 16 rounds; plain replacement improved it by 0.08-0.10 per round. Averaging works because the components the workers disagree on are divided by $N$; keeping local drift puts them back.
|
| 107 |
+
|
| 108 |
+
*The learning rate must fit the merge interval.* At $3 dot 10^(-4)$ the merged model sat at 4.33 for about 1.3B tokens. The probe showed why: 150 local steps raised held-out CE by 0.076 and the merge exactly undid it. Halving the rate cut local drift to 0.013 and the plateau ended.
|
| 109 |
+
|
| 110 |
+
*Outer Nesterov hurts here.* With momentum 0.5 (outer step 1.6x plain averaging), the global rose three rounds running, 2.9657 to 2.9721, and stopped rising the round it was switched off.
|
| 111 |
+
|
| 112 |
+
*EMA helps for evaluation, not for training.* An EMA of globals was at or below the global at every round once it held 4+ globals (2.9533 vs 2.9555 at $n=20$). Re-seeding the fleet from it gave the gain back within a round.
|
| 113 |
+
|
| 114 |
+
== Objective and data
|
| 115 |
+
|
| 116 |
+
#figure(
|
| 117 |
+
table(columns: 3, align: (left, left, left), stroke: 0.4pt,
|
| 118 |
+
[*Intervention*], [*Scale*], [*Result*],
|
| 119 |
+
[Span masking on half of the batches], [38M], [worse than independent masking: CE 3.748 vs 3.651; adopted earlier on weak evidence, then removed],
|
| 120 |
+
[PMI (collocation) masking], [38M], [worse than independent masking at every coverage],
|
| 121 |
+
[Phrase tokens (PMI word pairs merged into the vocabulary)], [30M], [faster early, worse at equal FLOPs: 1.891 vs 1.860 bits/byte],
|
| 122 |
+
[Short rows (10% of micro-batches at 128 tokens)], [1B], [better on long CE (-0.004), short-context CE (-0.021) and fact probe; adopted],
|
| 123 |
+
[Document masking], [1B], [adopted; also faster],
|
| 124 |
+
[Self-conditioning], [38M / 1B], [-0.038 / -0.008 CE, but +27% step cost and no fact gain; not adopted],
|
| 125 |
+
[N-gram (Engram) memory], [1B mid-run], [early fact edge faded within 1000 steps; CE slightly worse],
|
| 126 |
+
[Product-key memory (v2, query BN, slow keys)], [1B mid-run], [fact probe slightly better at every eval, CE flat; not adopted],
|
| 127 |
+
),
|
| 128 |
+
caption: [Objective, tokenisation and architecture interventions.],
|
| 129 |
+
)
|
| 130 |
+
|
| 131 |
+
== Optimisers
|
| 132 |
+
|
| 133 |
+
*Muon* @muon beat AdamW from scratch on the stand by a wide margin (held-out CE 3.748 to 3.177, reaching AdamW's final loss in under half the steps). Switched onto the 1B at step 84k, it raised one worker's loss monotonically for a thousand steps (3.16 to 3.32) while an AdamW worker beside it held 3.13-3.15; re-tested on the stand with RMS-matched updates @moonlight, the mid-run switch gained nothing (+0.0085). *Cautious AdamW* @cautious improved the stand by 0.197 CE but changed the 1B by $+0.0001 plus.minus 0.0012$. *Outer orthogonalisation* (replacing the averaged update by its polar factor) helped on a 4-worker stand run (held-out CE 3.750 vs 4.005 for plain averaging after 60 rounds, against 3.407 for synchronous training with the same total batch), but was not tried on the 1B and needs more seeds.
|
| 134 |
+
|
| 135 |
+
== The final stretch
|
| 136 |
+
|
| 137 |
+
Linear decay to zero from step 180k and the four weight averages we kept were compared at step 200k on the same probes (Table 5). All five are within 0.0004 CE; the uniform average is best on every probe and is released. We also note that the EMA at step 183k already scored 2.9495, i.e. the last 17k steps did not move these probes, even though the learning rate went to zero.
|
| 138 |
+
|
| 139 |
+
#figure(
|
| 140 |
+
table(columns: 7, align: (left, right, right, right, right, right, right), stroke: 0.4pt,
|
| 141 |
+
[*Weights*], [*held-out*], [*wiki*], [*code*], [*fact mc*], [*fact nll*], [*fact EM*],
|
| 142 |
+
[global (step 200k)], [2.9503], [3.5397], [1.6668], [.558], [5.899], [9.6%],
|
| 143 |
+
[EMA, $beta=0.9$], [2.9503], [3.5397], [1.6667], [.558], [5.899], [9.6%],
|
| 144 |
+
[*uniform average, 130 globals*], [*2.9501*], [*3.5393*], [*1.6639*], [*.561*], [*5.894*], [9.6%],
|
| 145 |
+
[average of last 3 snapshots], [2.9502], [3.5398], [1.6656], [.557], [5.900], [9.7%],
|
| 146 |
+
[average of last 5 snapshots], [2.9503], [3.5394], [1.6641], [.559], [5.895], [9.5%],
|
| 147 |
+
),
|
| 148 |
+
caption: [Candidates for the released weights (masked CE; PopQA fact probe of 1050 facts).],
|
| 149 |
+
)
|
| 150 |
+
|
| 151 |
+
= Evaluation
|
| 152 |
+
|
| 153 |
+
== Zero-shot benchmarks
|
| 154 |
+
|
| 155 |
+
All models are scored with lm-evaluation-harness @lmeval, zero-shot, on the same tasks. For autoregressive models we use the standard HF backend. Our model is plugged into the same harness: the log-likelihood of a continuation is computed by the left-to-right chain rule, predicting token $i$ with tokens before it visible and tokens from $i$ on masked. On 1000 HellaSwag items this scorer gave 42.5 against 40.8 for the Monte Carlo ELBO estimator of LLaDA @llada (32 samples), so it does not understate the model. TinyLlama and OLMo-1B were also run but load incorrectly under the current `transformers` (e.g. OLMo: LAMBADA 0%) and are omitted.
|
| 156 |
+
|
| 157 |
+
#figure(
|
| 158 |
+
table(columns: 12, align: (left,) + (right,) * 11, stroke: 0.4pt,
|
| 159 |
+
[*Model*], [*Params*], [*Tokens*], [*FLOPs*], [*HS*], [*ARC-e*], [*ARC-c*], [*PIQA*], [*WG*], [*OBQA*], [*SciQ*], [*LAMB*],
|
| 160 |
+
[*DiffuRefill-1B (ours)*], [1.08B], [0.09T], [$6.0 dot 10^20$], [34.8], [52.4], [25.0], [62.7], [50.6], [27.4], [*89.5*], [34.0],
|
| 161 |
+
[Pythia-1B @pythia], [1.0B], [0.3T], [$1.8 dot 10^21$], [47.2], [56.9], [27.0], [69.4], [54.1], [31.2], [83.4], [55.8],
|
| 162 |
+
[SmolLM2-360M @smollm2], [0.36B], [4T], [$8.6 dot 10^21$], [56.3], [70.3], [38.1], [71.5], [58.9], [37.8], [91.1], [53.4],
|
| 163 |
+
[Qwen2.5-0.5B @qwen25], [0.49B], [18T], [$5.3 dot 10^22$], [52.2], [64.9], [31.8], [69.9], [56.1], [35.0], [93.0], [52.0],
|
| 164 |
+
[SmolLM2-1.7B @smollm2], [1.7B], [11T], [$1.1 dot 10^23$], [71.2], [77.8], [47.1], [77.6], [65.9], [44.0], [93.3], [67.5],
|
| 165 |
+
[Qwen2.5-1.5B @qwen25], [1.5B], [18T], [$1.7 dot 10^23$], [67.8], [75.5], [45.0], [75.9], [63.5], [40.6], [94.3], [62.2],
|
| 166 |
+
),
|
| 167 |
+
caption: [Zero-shot accuracy (%). HS, ARC-c, PIQA, OBQA: length-normalised accuracy; others: accuracy. FLOPs by $6 N D$. MMLU, zero-shot: ours 26.9, Pythia-1B 23.1, SmolLM2-360M 25.5, Qwen2.5-0.5B 47.5, SmolLM2-1.7B 48.5, Qwen2.5-1.5B 59.7.],
|
| 168 |
+
)
|
| 169 |
+
|
| 170 |
+
The model is clearly weaker than autoregressive models of similar size, all of which were trained with 3x (Pythia) to 280x (Qwen2.5-1.5B) more compute. Two factors are expected to account for most of the gap: the token budget, and the known compute inefficiency of masked diffusion on likelihood benchmarks (Nie et al. @smdm estimate that a masked diffusion model needs about 16x the compute of an autoregressive one for the same validation loss). For reference, their 1.1B diffusion model trained with $3.3 dot 10^21$ FLOPs (5.5x ours) reports HellaSwag 51.8, ARC-e 48.7, PIQA 69.5 and LAMBADA 52.7, with unsupervised classifier-free guidance at evaluation. Our model is relatively strong on SciQ (above Pythia-1B and SmolLM2-360M), which matches the fact-heavy anneal, and weakest on LAMBADA and WinoGrande; WinoGrande is at chance under both scorers.
|
| 171 |
+
|
| 172 |
+
== Generation speed
|
| 173 |
+
|
| 174 |
+
#figure(
|
| 175 |
+
table(columns: 4, align: (left, right, right, right), stroke: 0.4pt,
|
| 176 |
+
[*Setting (tokens/s, 256 new tokens)*], [*DiffuRefill-1B*], [*SmolLM2-1.7B*], [*Qwen2.5-1.5B*],
|
| 177 |
+
[batch 1, one token per pass], [*193*], [101], [82],
|
| 178 |
+
[batch 1, 8 tokens per pass], [*1536*], [-], [-],
|
| 179 |
+
[batch 32, one token per pass], [431], [*3119*], [2612],
|
| 180 |
+
[batch 32, 8 tokens per pass], [*3449*], [-], [-],
|
| 181 |
+
),
|
| 182 |
+
caption: [Greedy generation on one RTX PRO 6000, bf16. Autoregressive models use HF `generate()` with a KV cache; ours uses no cache and re-reads the 288-token row every pass.],
|
| 183 |
+
)
|
| 184 |
+
|
| 185 |
+
At batch size 1, where latency is set by the number of sequential passes, the diffusion model is about twice as fast even when it commits one token per pass, and 15x faster at eight. At batch 32 the autoregressive models are compute-efficient thanks to the KV cache and our model only catches up at eight tokens per pass. Committing several tokens per pass costs quality: on the stand, committing tokens one at a time in left-to-right order raised distinct-bigram diversity of samples from 0.65 to 0.93 and removed repetition loops, while spacing parallel commits apart cut judge perplexity from 48.0 to 35.1. Optimised AR serving (vLLM and similar) would be considerably faster than HF `generate()`.
|
| 186 |
+
|
| 187 |
+
= Limitations
|
| 188 |
+
|
| 189 |
+
This is one run, with interventions decided on small held-out probes and a 38M stand rather than full 1B ablations; several stand wins (Muon, cautious AdamW) did not transfer, and the converse may also hold. The fact probe overlaps with the Wikipedia-derived anneal data. Baselines were evaluated by us with one harness version and default settings and may differ from their published numbers. The model is English-only, is a base model with no instruction tuning or safety training, and generates fluent but often wrong facts.
|
| 190 |
+
|
| 191 |
+
= Outlook: reasoning
|
| 192 |
+
|
| 193 |
+
Our goal for the next stage is reasoning. On the stand, a diffusion model that first writes an autoregressive chain of thought and then fills in a computed four-digit answer *in a single parallel pass* went from 45% to 100% accuracy on a multi-step arithmetic task, while the same model without the reasoning trace stayed at 45%. This suggests a natural division of labour for diffusion LMs: sequential reasoning, parallel answering. A recurrent-depth variant (a looped core block) matched an 8-block model's pointer-chasing depth with half the parameters but did not extrapolate with more loops. The next steps are supervised fine-tuning on reasoning traces and reinforcement learning with verifiable rewards.
|
| 194 |
+
|
| 195 |
+
= Acknowledgements
|
| 196 |
+
|
| 197 |
+
Compute was provided free of charge by molab notebooks. Storage and coordination ran on the Hugging Face Hub. We thank the authors of Ultra-FineWeb, Nemotron Pretraining Specialized, Dolmino, OpenCoder and UltraData for open data. Engineering, experiments and the drafting of this report were carried out with the help of Claude Code (Anthropic) as a programming assistant.
|
| 198 |
+
|
| 199 |
+
#bibliography("refs.yml", style: "ieee")
|
paper/refs.yml
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
diloco:
|
| 2 |
+
type: article
|
| 3 |
+
title: "DiLoCo: Distributed Low-Communication Training of Language Models"
|
| 4 |
+
author: ["Douillard, Arthur"]
|
| 5 |
+
date: 2023
|
| 6 |
+
url: https://arxiv.org/abs/2311.08105
|
| 7 |
+
mdlm:
|
| 8 |
+
type: article
|
| 9 |
+
title: Simple and Effective Masked Diffusion Language Models
|
| 10 |
+
author: ["Sahoo, Subham Sekhar"]
|
| 11 |
+
date: 2024
|
| 12 |
+
url: https://arxiv.org/abs/2406.07524
|
| 13 |
+
smdm:
|
| 14 |
+
type: article
|
| 15 |
+
title: Scaling up Masked Diffusion Models on Text
|
| 16 |
+
author: ["Nie, Shen"]
|
| 17 |
+
date: 2025
|
| 18 |
+
url: https://arxiv.org/abs/2410.18514
|
| 19 |
+
llada:
|
| 20 |
+
type: article
|
| 21 |
+
title: Large Language Diffusion Models
|
| 22 |
+
author: ["Nie, Shen"]
|
| 23 |
+
date: 2025
|
| 24 |
+
url: https://arxiv.org/abs/2502.09992
|
| 25 |
+
ultrafineweb:
|
| 26 |
+
type: article
|
| 27 |
+
title: "Ultra-FineWeb: Efficient Data Filtering and Verification for High-Quality LLM Training Data"
|
| 28 |
+
author: ["Wang, Yudong"]
|
| 29 |
+
date: 2025
|
| 30 |
+
url: https://arxiv.org/abs/2505.05427
|
| 31 |
+
olmo3:
|
| 32 |
+
type: web
|
| 33 |
+
title: "OLMo 3 stage-2 mid-training mix (dolma3_dolmino_mix-100B-1125)"
|
| 34 |
+
author: ["Team OLMo"]
|
| 35 |
+
date: 2025
|
| 36 |
+
url: https://huggingface.co/datasets/allenai/dolma3_dolmino_mix-100B-1125
|
| 37 |
+
d2z:
|
| 38 |
+
type: article
|
| 39 |
+
title: "Straight to Zero: Why Linearly Decaying the Learning Rate to Zero Works Best for LLMs"
|
| 40 |
+
author: ["Bergsma, Shane"]
|
| 41 |
+
date: 2025
|
| 42 |
+
url: https://arxiv.org/abs/2502.15938
|
| 43 |
+
muon:
|
| 44 |
+
type: web
|
| 45 |
+
title: "Muon: An optimizer for hidden layers in neural networks"
|
| 46 |
+
author: ["Jordan, Keller"]
|
| 47 |
+
date: 2024
|
| 48 |
+
url: https://kellerjordan.github.io/posts/muon/
|
| 49 |
+
moonlight:
|
| 50 |
+
type: article
|
| 51 |
+
title: Muon is Scalable for LLM Training
|
| 52 |
+
author: ["Liu, Jingyuan"]
|
| 53 |
+
date: 2025
|
| 54 |
+
url: https://arxiv.org/abs/2502.16982
|
| 55 |
+
cautious:
|
| 56 |
+
type: article
|
| 57 |
+
title: "Cautious Optimizers: Improving Training with One Line of Code"
|
| 58 |
+
author: ["Liang, Kaizhao"]
|
| 59 |
+
date: 2024
|
| 60 |
+
url: https://arxiv.org/abs/2411.16085
|
| 61 |
+
lmeval:
|
| 62 |
+
type: web
|
| 63 |
+
title: A framework for few-shot language model evaluation (lm-evaluation-harness)
|
| 64 |
+
author: ["Gao, Leo"]
|
| 65 |
+
date: 2024
|
| 66 |
+
url: https://github.com/EleutherAI/lm-evaluation-harness
|
| 67 |
+
pythia:
|
| 68 |
+
type: article
|
| 69 |
+
title: "Pythia: A Suite for Analyzing Large Language Models Across Training and Scaling"
|
| 70 |
+
author: ["Biderman, Stella"]
|
| 71 |
+
date: 2023
|
| 72 |
+
url: https://arxiv.org/abs/2304.01373
|
| 73 |
+
smollm2:
|
| 74 |
+
type: article
|
| 75 |
+
title: "SmolLM2: When Smol Goes Big - Data-Centric Training of a Small Language Model"
|
| 76 |
+
author: ["Ben Allal, Loubna"]
|
| 77 |
+
date: 2025
|
| 78 |
+
url: https://arxiv.org/abs/2502.02737
|
| 79 |
+
qwen25:
|
| 80 |
+
type: article
|
| 81 |
+
title: Qwen2.5 Technical Report
|
| 82 |
+
author: ["Qwen Team"]
|
| 83 |
+
date: 2024
|
| 84 |
+
url: https://arxiv.org/abs/2412.15115
|