tchauffi commited on
Commit
c849dce
·
verified ·
1 Parent(s): b339165

Add model card

Browse files
Files changed (1) hide show
  1. README.md +76 -0
README.md ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: pytorch
3
+ tags:
4
+ - diffusion
5
+ - language-model
6
+ - discrete-diffusion
7
+ - absorbing-state
8
+ - text-generation
9
+ - tinystories
10
+ - from-scratch
11
+ datasets:
12
+ - roneneldan/TinyStories
13
+ pipeline_tag: text-generation
14
+ ---
15
+
16
+ # diffusionlm-from-scratch — masked diffusion LM (DiT, 142M)
17
+
18
+ A masked (absorbing-state) **diffusion language model**, built and trained from
19
+ scratch on TinyStories. Instead of generating left-to-right one token at a time,
20
+ it starts from a sequence of pure `[MASK]` tokens and **denoises the whole
21
+ sequence in parallel** — committing the tokens it is most confident about first,
22
+ in whatever order the meaning falls into place.
23
+
24
+ - **Code, training & sampling:** https://github.com/tchauffi/diffusionlm-from-scratch
25
+ - **Course / write-up:** [`RESEARCH.md`](https://github.com/tchauffi/diffusionlm-from-scratch/blob/main/RESEARCH.md) — a from-scratch course on discrete/text diffusion (D3PM → absorbing-state → sampling).
26
+ - **Demo site:** animated real generations live in [`docs/`](https://github.com/tchauffi/diffusionlm-from-scratch/tree/main/docs).
27
+
28
+ ## Model
29
+
30
+ | | |
31
+ |---|---|
32
+ | Architecture | DiT (transformer denoiser), bidirectional attention, adaLN-Zero |
33
+ | Parameters | ~142M |
34
+ | Hidden size / depth / heads | 768 / 12 / 12 |
35
+ | MLP ratio | 4.0 |
36
+ | Vocab | 8,192 (byte-level BPE, trained on TinyStories) |
37
+ | Max sequence length | 256 |
38
+ | Diffusion | absorbing-state (masked) discrete diffusion |
39
+ | Training data | [TinyStories](https://huggingface.co/datasets/roneneldan/TinyStories) |
40
+ | Eval cross-entropy | **2.18** |
41
+
42
+ **Key finding:** uniform loss weighting (`w(t) = 1`), *not* the textbook ELBO
43
+ weight `1/σ(t)`, is what turned word-salad into coherent stories.
44
+
45
+ ## Files
46
+
47
+ - `final.pt` — checkpoint with two state dicts, `model` (EMA, preferred) and
48
+ `raw`, plus the `config` used to build the model.
49
+ - `tokenizer.json`, `tokenizer_config.json` — the byte-level BPE tokenizer
50
+ (`PreTrainedTokenizerFast`; special tokens `[PAD]` `[UNK]` `[MASK]`
51
+ `<|endoftext|>`).
52
+
53
+ ## Usage
54
+
55
+ Install the model code from the GitHub repo, then:
56
+
57
+ ```python
58
+ import torch
59
+ from huggingface_hub import hf_hub_download
60
+ from transformers import PreTrainedTokenizerFast
61
+ from diffusionlm_from_scratch.model import DiT, DiTConfig
62
+
63
+ repo = "tchauffi/diffusionlm-from-scratch"
64
+
65
+ ckpt_path = hf_hub_download(repo, "final.pt")
66
+ ck = torch.load(ckpt_path, map_location="cpu", weights_only=False)
67
+
68
+ model = DiT(DiTConfig(**ck["config"]))
69
+ model.load_state_dict(ck["model"]) # EMA weights ("raw" also available)
70
+ model.eval()
71
+
72
+ tokenizer = PreTrainedTokenizerFast.from_pretrained(repo)
73
+ ```
74
+
75
+ See [`scripts/capture_trajectories.py`](https://github.com/tchauffi/diffusionlm-from-scratch/blob/main/scripts/capture_trajectories.py)
76
+ in the repo for the full parallel-denoising sampling loop.