Downloads Β· 30 days
38
3% of all-time downloads
brianschwabauer/latent-space-language-diffusion-model
latent-space-language-diffusion-model is a text generation model from brianschwabauer. Use it when you need the model to write or continue text. It is set up for safetensors. The card lists the license as mit.
keywords: masked diffusion language model, MDLM, parallel text generation, diffusion model, non-autoregressive generation, bidirectional transformer, AR oracle validation, speculative decoding, Qwen3, SplatsDB, open wβ¦
Downloads Β· 30 days
38
3% of all-time downloads
All-time downloads
1.3K
Public
Parameters
183M
2.3 GB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors1.5 GB Β· 100%
From the Hugging Face model README
π» Full source code, experiments, benchmarks, and research lineage on GitHub β 8 phases of experiments, training scripts, ablation studies, and honest negative results.
Open weights. Open code. Fully reproducible.
A 201M parameter masked diffusion language model that generates text by predicting all tokens in parallel. Validated by an autoregressive oracle (Qwen3-0.6B). Trained on a single consumer GPU (RTX 3090) in ~7 hours.
| Metric | Value | Context |
|---|---|---|
| Parameters | 201,258,768 (201.3M) | d_model=1024, 10 layers, 16 heads |
| Training data | 272M tokens (1M docs) | Ultra-FineWeb |
| Perplexity (held-out) | 102.6 | vs Qwen3-0.6B: ~15-20 |
| Forward throughput (batch=32) | 57,759 TPS | vs Qwen3: 32,023 (1.8Γ faster) |
| Generation speed (full-parallel) | 31.2 tok/s | All tokens simultaneously |
| Generation speed (hybrid validated) | 15.6 tok/s | With Qwen3 segment correction |
| Repetition score | 0.99 | With adaptive guidance (baseline: 0.79) |
| Training time | 6h 45min | Single RTX 3090 |
| File | Description | Size |
|---|---|---|
model.safetensors | Full model weights (201M params, fp32) | 805 MB |
config.json | Architecture + full training metadata | 2.6 KB |
tokenizer.json | BPE tokenizer (16K vocab) | 666 KB |
modeling_mdlm.py | Full model code (architecture + sampling) | 23 KB |
logit_guidance.py | Guidance module (frequency/rep/n-gram/top-p) | 14 KB |
hrm_refiner.py | Repetition reviewer (geometric, 0 params) | 11 KB |
train.py | Full training script (reproduce from scratch) | 11 KB |
No black boxes. Every line of model code, training code, and inference code is included. The checkpoint is the exact state after 49,779 optimizer steps β nothing hidden, no cherry-picking.
MDLM-BPE v3 (201M params)
βββ Token embedding: 16K BPE vocab β 1024 dims
βββ 10Γ Transformer blocks
β βββ RoPE positional encoding (non-learned)
β βββ AdaLN timestep conditioning (FiLM-style)
β βββ Flash attention (non-causal / bidirectional)
βββ LayerNorm + output projection (weight-tied)
βββ Full-parallel unmasking (all positions simultaneously)
Design philosophy: Unlike autoregressive models that generate tokens left-to-right (one at a time), this model predicts ALL positions simultaneously via iterative diffusion. This enables 1.8-3.9Γ faster forward passes and 2.4Γ faster generation.
1. MDLM full-parallel diffusion (32 steps)
All masked positions predicted simultaneously each step
2. Adaptive guidance (during generation):
β’ Frequency penalty (0.4): penalize overused tokens
β’ Repetition penalty (1.3): reduce already-used token logits
β’ No-repeat bigram: hard ban on repeated 2-grams
β’ Top-p (0.95): nucleus sampling, filter tail noise
3. Qwen3-0.6B validation (optional, 1 forward pass):
Teacher-forcing score per segment
4. Segment regeneration (optional):
Bad segments regenerated by Qwen3 AR model
| Parameter | Value |
|---|---|
| Optimizer | AdamW |
| Peak learning rate | 3e-4 |
| LR schedule | Cosine with warmup |
| Warmup steps | 1,000 |
| Weight decay | 0.01 |
| Epochs | 3 |
| Batch size | 32 |
| Gradient accumulation | 4 (effective batch = 128) |
| Sequence length | 128 |
| Precision | bf16 |
| Gradient clipping | 1.0 |
| Total optimizer steps | 49,779 |
Step 0: loss=7.97 PPL=1341 (random init)
Step 1000: loss=7.20 PPL=711 (learning structure)
Step 23000: loss=5.00 PPL=137.6 (coherent phrases)
Step 38000: loss=4.84 PPL=126.7 (refining)
Step 44000: loss=4.63 PPL=102.6 β BEST checkpoint
Step 49779: loss=4.80 PPL=112.6 (final, cosine decay end)
All metrics measured on RTX 3090. Oracle log-prob = mean per-token log-probability under Qwen3-0.6B teacher forcing (higher = more coherent).
| Method | Oracle LP | Rep Score | TPS | Latency |
|---|---|---|---|---|
| Full-parallel + guidance | -4.58 | 1.00 | 31.2 | 1.8s |
| Full-parallel + guidance + Qwen3 | -3.55 | 0.95 | 15.6 | 3.3s |
| Semi-AR + guidance | -4.61 | 1.00 | 13.0 | 4.9s |
| Semi-AR + guidance + Qwen3 | -3.72 | 0.98 | 10.0 | 5.1s |
| Qwen3-0.6B (pure AR reference) | -1.18 | 0.95 | 17.1 | 3.8s |
| Batch | This Model (201M) | Qwen3-0.6B (596M) | Speedup |
|---|---|---|---|
| 1 | 8,443 TPS | 2,152 TPS | 3.9Γ |
| 8 | 50,440 TPS | 17,009 TPS | 3.0Γ |
| 32 | 57,759 TPS | 32,023 TPS | 1.8Γ |
This model is a research artifact, not a production system. The quality gap vs production models is real:
| This Model | Qwen3-0.6B | Ratio | |
|---|---|---|---|
| Parameters | 201M | 596M | 0.34Γ |
| Training tokens | 272M | ~trillions | ~0.0003Γ |
| Perplexity | 102.6 | ~15-20 | ~5Γ worse |
| Oracle log-prob | -3.55 | -1.18 | β |
The quality gap is driven by scale (parameters + data), not architecture. This model was trained on 272M tokens on one GPU in 7 hours. Production models train on trillions of tokens across clusters. The throughput advantage (1.8-3.9Γ faster) is architecture-level and would compound at scale.
import torch
from safetensors.torch import load_file
from modeling_mdlm import MDLMConfig, MDLMBPEV3, BPETokenizer, sample_semi_ar
# Load model
config = MDLMConfig(d_model=1024, n_heads=16, n_layers=10, vocab_size=16000)
model = MDLMBPEV3(config)
state_dict = load_file("model.safetensors")
model.load_state_dict(state_dict)
model.eval().cuda()
# Load tokenizer
tokenizer = BPETokenizer("tokenizer.json")
# Generate
prompt_ids = tokenizer.encode("The future of artificial intelligence", add_special=False)
result = sample_semi_ar(
model, tokenizer,
prompt_ids=prompt_ids,
seq_len=64,
block_size=4,
temperature=0.7,
)
print(result[0])
from logit_guidance import sample_with_guidance
result = sample_with_guidance(
model, tokenizer,
prompt_ids=tokenizer.encode("Climate change is", add_special=False),
seq_len=64,
repetition_penalty=1.3,
no_repeat_ngram=2,
frequency_penalty=0.4,
)
print(result[0])
# All code is in this repo. To train from scratch:
# 1. Download data
python -c "from datasets import load_dataset; ..."
# 2. Train (see train.py for full args)
python train.py --epochs 3 --batch-size 32 --seq-len 128
# Expected: ~7 hours on RTX 3090, PPL ~100-110
@misc{schwabauer2026latentspace,
title={Latent Space Language Diffusion Model: Parallel Text Generation via Masked Diffusion with AR-Oracle Validation},
author={Schwabauer, Brian Tomas},
year={2026},
publisher={HuggingFace},
url={https://huggingface.co/brianschwabauer/latent-space-language-diffusion-model}
}
MIT β Full open source. Use, modify, distribute freely.