Code for the paper Scaling and Distilling Text Embeddings for Better Diffusibility.
Continuous diffusion language models (DLMs) are a promising alternative to autoregressive models, and they are latent diffusion on text embeddings. Which text embedding makes the best latent space for them, i.e. the most diffusible one? We fix the DLM to the recent ELF framework and change only the embedding:
- Scaling. Replacing the T5-small encoder of ELF with T5Gemma-2 lowers the generative perplexity (Gen. PPL) by about 40% at the same entropy.
- Distilling. Distilling the T5Gemma-2 encoder into a student improves diffusibility further, reducing Gen. PPL from 19.3 to 17.8 at real-text entropy and sampling more stably.
We distill the student to fit the soft labels obtained from the teacher, which are the predicted probabilities that the teacher decoder outputs:
This repository offers the sampling code and the checkpoints to reproduce the results of the paper, and also the code to distill and train your own models. It is adapted from ELF-pytorch, a PyTorch reproduction of ELF on OpenWebText.
pip install -r requirements.txtYou do not need a Hugging Face login for sampling and evaluation. But you would need one to use
T5Gemma-2 when you distill and train DLMs: accept the terms on its model page
and run hf auth login first.
python sample.py --ckpt ELF-M-T5Gemma2distilled --out samples.json --n 1024 --sc 3 --nfe 512 # generate and store samples
python evaluate.py --samples samples.json # report Gen. PPL and entropy--ckpt takes the name of a released checkpoint (auto-downloaded from Hugging Face), or
your own model.pt; --sc is the self-conditioning guidance scale and --nfe is the number of
sampling steps.1 Expected results, as the mean over 3 seeds with 1024 samples each:2
--ckpt |
--sc |
--nfe |
Gen. PPL | Entropy |
|---|---|---|---|---|
ELF-B-T5Gemma2 |
1 | 64 | 38.5 | 5.41 |
ELF-B-T5Gemma2distilled |
1 | 256 | 31.2 | 5.44 |
ELF-M-T5Gemma2 |
2 | 256 | 19.3 | 5.44 |
ELF-M-T5Gemma2distilled |
3 | 512 | 17.8 | 5.45 |
| real text | 15.4 | 5.43 |
examples/ stores 16 generated sequences per model at these settings for previewing.
To reproduce the real-text row and MAUVE w.r.t. held-out OpenWebText:
python data.py --out data/owt --heldout-only # data/owt_heldout
python evaluate.py --real data/owt_heldout --n 256 # real-text row
python evaluate.py --samples samples.json --mauve data/owt_heldout # adds MAUVEThe commands below are the full distillation and diffusion-training pipeline, as in the paper (8 H100 GPUs). You can also skip step 2 and directly load our released student (T5Gemma-2-270M-OWTdistilled), which is the default --encoder.
## 1. Tokenize OpenWebText into ~9.0M sequences of up to 1024 tokens, and use the last ~0.2M documents for the held-out set
python data.py --out data/owt
## 2. Distillation. 50,000 steps at a global batchsize of 256 (8 x 32); best held-out checkpoint in runs/student/best.pt
torchrun --standalone --nproc_per_node=8 distill.py --data data/owt --out runs/student
## 3. Train ELF for 5 epochs at a global batchsize of 512.
torchrun --standalone --nproc_per_node=8 train.py --data data/owt --out runs/student_elf_m \
--encoder runs/student/best.pt --model ELF-M --batch-size 8 --accum 8
## This commented command loads the released student encoder by default, as there's no --encoder argument.
# torchrun --standalone --nproc_per_node=8 train.py --data data/owt --out runs/student_elf_m --model ELF-M --batch-size 8 --accum 8
## 4. Sample and evaluate
python sample.py --ckpt runs/student_elf_m/model.pt --out samples.json --n 1024 --sc 3 --nfe 512Change the --model argument to train different sizes of ELF models, and other flags for the other models of the paper as below.
# ELF-B
torchrun --standalone --nproc_per_node=8 train.py --data data/owt --out runs/student_elf_b \
--encoder runs/student/best.pt --model ELF-B --batch-size 16 --accum 4
# Use T5Gemma-2 as the encoder instead of the student
torchrun --standalone --nproc_per_node=8 train.py --data data/owt --out runs/t5gemma2_elf_m \
--encoder google/t5gemma-2-270m-270m --model ELF-M --batch-size 8 --accum 8
# distillation ablations: hard labels, and regressing the teacher's embeddings
torchrun --standalone --nproc_per_node=8 distill.py --data data/owt --out runs/student_ce --objective ce
torchrun --standalone --nproc_per_node=8 distill.py --data data/owt --out runs/student_mse --objective mse--batch-size is per GPU and --accum is the number of gradient accumulation steps; change them
together to keep the global batch at 512. Use --resume <out>/checkpoint.pt to pick up and continue an interrupted run.
| File | Content |
|---|---|
data.py |
OpenWebText token cache and held-out split |
encoders.py |
frozen encoder (T5Gemma-2 or the student), embedding normalization, checkpoint download |
distill.py |
distillation of the student |
train.py |
ELF-B / ELF-M training on a chosen embedding |
sample.py |
sampling and decoding to text |
evaluate.py |
Gen. PPL, unigram entropy, MAUVE |
elf/ |
the ELF model, flow matching losses, sampler, Muon optimizer |
docs/ |
source of the project page (docker compose up in it for a local preview) |
examples/ |
16 generated sequences per released model |
The files in elf/ and the metrics in evaluate.py are derived from
ELF-pytorch (MIT License; its notice is kept in
LICENSE), and the data format in data.py follows ELF.
@article{zhang2026scaling,
title={Scaling and Distilling Text Embeddings for Better Diffusibility},
author={Zhang, Zekai and Tian, Yunjie and He, Yanjin and Zhang, Xiaoyan and Zhao, Dongdi and Qu, Qing and Fu, Di},
journal={arXiv preprint arXiv:2610.01016},
year={2026}
}Footnotes
-
The SDE sampler with churn 1.5 and noise scale 2.0. Sampling needs only the ELF checkpoint and the tokenizer: ELF decodes its embeddings with its own head, so the encoder is never loaded. It fits in 16 GB of GPU memory at the default
--batch-size 64. ↩ -
T5Gemma-2 with ELF-B never reaches the entropy of real text on our sampling grid, so its row is the setting with the highest entropy. ↩


