AndreiRabau commited on
Commit
61e8fe9
·
verified ·
1 Parent(s): d3b85f8

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +191 -1
README.md CHANGED
@@ -12,4 +12,194 @@ tags:
12
  - gpt2
13
  - research
14
  pipeline_tag: text-generation
15
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  - gpt2
13
  - research
14
  pipeline_tag: text-generation
15
+ ---
16
+
17
+ # Diffusion-LLM
18
+
19
+ > **A small, experimental discrete diffusion language model built on GPT-2.**
20
+
21
+ This repository contains checkpoints from an experiment in iterative text
22
+ denoising. Instead of predicting only the next token from a left-to-right
23
+ context, the model receives a corrupted sequence and predicts the original
24
+ tokens across the whole sequence with bidirectional attention.
25
+
26
+ The checkpoints are intended for research and reproducibility. They are not
27
+ drop-in `transformers` causal language models and should not be treated as
28
+ production-ready text generators.
29
+
30
+ ## What is inside?
31
+
32
+ The model starts from [`openai-community/gpt2`](https://huggingface.co/openai-community/gpt2)
33
+ and adapts its Transformer backbone for discrete diffusion-style denoising:
34
+
35
+ - GPT-2 embeddings and Transformer blocks are retained.
36
+ - Causal attention is replaced with bidirectional attention.
37
+ - A learned diffusion-timestep embedding is added to every token embedding.
38
+ - The language-model head predicts the clean token at each position.
39
+ - Denoising is performed by repeatedly updating corrupted positions.
40
+
41
+ The training code adds two special tokens to the GPT-2 tokenizer:
42
+ `<|pad|>` and `<|mask|>`. The vocabulary is resized before training, so the
43
+ same tokenizer construction is required when loading a checkpoint.
44
+
45
+ ## Checkpoints
46
+
47
+ The uploaded weights follow this layout:
48
+
49
+ | Path | Training corruption | Refinement steps during training |
50
+ | --- | --- | ---: |
51
+ | `default.pt` | Initial/reference checkpoint | — |
52
+ | `1_step/similar_100.pt` | Semantically similar replacements | 1 |
53
+ | `1_step/mask_100.pt` | Mask-token corruption | 1 |
54
+ | `1_step/random_100.pt` | Random-token replacement | 1 |
55
+ | `1_step/mix_30_30_40.pt` | 30 training epochs similar → 30 mask → 40 random | 1 |
56
+ | `4_step/similar_100_4_steps.pt` | Semantically similar replacements | 4 |
57
+ | `4_step/mask_100_4_steps.pt` | Mask-token corruption | 4 |
58
+ | `4_step/random_100_4_steps.pt` | Random-token replacement | 4 |
59
+ | `4_step/mix_30_30_40_4_steps.pt` | 30 training epochs similar → 30 mask → 40 random | 4 |
60
+
61
+ All listed experimental runs use the same main setup: GPT-2, 100 diffusion
62
+ timesteps, maximum sequence length 64, learning rate `1e-5`, and WikiText-2
63
+ (`Salesforce/wikitext`, `wikitext-2-raw-v1`). The 4-step runs use a rollout
64
+ loss decay of `0.5`.
65
+
66
+ ## Corruption strategies
67
+
68
+ The training pipeline supports three discrete corruption operators:
69
+
70
+ 1. **Similar** — replaces tokens with nearby tokens in the GPT-2 embedding
71
+ space. This creates difficult, semantically close mistakes.
72
+ 2. **Mask** — replaces tokens with `<|mask|>`, the classic masked-denoising
73
+ condition.
74
+ 3. **Random** — replaces tokens with random vocabulary entries.
75
+
76
+ The mixed checkpoints use these methods as a sequential training curriculum:
77
+ **30 epochs of similar-token corruption, 30 epochs of masking, and 40 epochs
78
+ of random replacement**. Corruption probability is sampled between `0.01` and
79
+ `0.95`; the similar-token operator uses 20 nearest neighbours.
80
+
81
+ ## Quick start
82
+
83
+ Clone this repository so that the model wrapper and corruption utilities are
84
+ available alongside the downloaded checkpoint:
85
+
86
+ ```bash
87
+ git clone https://huggingface.co/AndreiRabau/diffusion-llm
88
+ cd diffusion-llm
89
+ pip install torch transformers
90
+ ```
91
+
92
+ The following example loads the 4-step mixed checkpoint and denoises a
93
+ sequence containing mask tokens:
94
+
95
+ ```python
96
+ from pathlib import Path
97
+
98
+ import torch
99
+ from transformers import AutoTokenizer
100
+
101
+ from model_wrappers import GPT2DiffusionTransformer
102
+
103
+
104
+ MODEL_NAME = "openai-community/gpt2"
105
+ CHECKPOINT = Path("4_step/mix_30_30_40_4_steps.pt")
106
+
107
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
108
+ tokenizer.add_special_tokens({
109
+ "pad_token": "<|pad|>",
110
+ "mask_token": "<|mask|>",
111
+ })
112
+
113
+ model = GPT2DiffusionTransformer.from_file_path(
114
+ file_path=CHECKPOINT,
115
+ model_name=MODEL_NAME,
116
+ num_diffusion_steps=100,
117
+ vocabulary_size=len(tokenizer),
118
+ device="cpu",
119
+ ).eval()
120
+
121
+ text = "Diffusion models can refine [MASK] sequences over several steps."
122
+ inputs = tokenizer(text, return_tensors="pt")
123
+
124
+ # For a real masked input, create the sequence with tokenizer.mask_token_id.
125
+ # Here we replace one token to keep the example self-contained.
126
+ corrupted_ids = inputs["input_ids"].clone()
127
+ corrupted_positions = torch.zeros_like(corrupted_ids, dtype=torch.bool)
128
+ corrupted_ids[0, 4] = tokenizer.mask_token_id
129
+ corrupted_positions[0, 4] = True
130
+
131
+ reconstructed_ids = model.denoise(
132
+ corrupted_ids=corrupted_ids,
133
+ attention_mask=inputs["attention_mask"],
134
+ corrupted_positions=corrupted_positions,
135
+ num_iterations=4,
136
+ )
137
+
138
+ print(tokenizer.decode(reconstructed_ids[0], skip_special_tokens=True))
139
+ ```
140
+
141
+ The `.pt` files contain a PyTorch `state_dict`. Loading them therefore
142
+ requires the repository's `GPT2DiffusionTransformer` implementation and the
143
+ same model configuration used during training (`num_diffusion_steps=100` and
144
+ the resized tokenizer vocabulary).
145
+
146
+ ## Training and evaluation details
147
+
148
+ Training uses cross-entropy only on corrupted, non-padding positions. For
149
+ multi-step training, each step feeds the model's predictions back into the
150
+ next step, exposing the model to its own errors. At evaluation time, the
151
+ denoiser uses confidence-guided refinement: the most confident corrupted
152
+ positions are updated first, while less certain positions remain available for
153
+ later iterations. This difference is intentional.
154
+
155
+ The included experiments evaluate on the `test` split of
156
+ [`cimec/lambada`](https://huggingface.co/datasets/cimec/lambada) with
157
+ corruption rates from 25% to 95% and 2, 4, 5, 8, 10, 20, or 50 denoising
158
+ iterations, depending on the run. Evaluation artifacts are stored in
159
+ `results/eval/` in the source project.
160
+
161
+ ## Intended use
162
+
163
+ This release is useful for:
164
+
165
+ - studying corruption policies for discrete diffusion language models;
166
+ - comparing one-step and iterative denoising rollouts;
167
+ - experimenting with confidence-based token refinement;
168
+ - reproducing the accompanying small-scale WikiText-2 experiments.
169
+
170
+ It is **not** intended for factual question answering, safety-critical
171
+ generation, deployment, or direct comparison with large-scale diffusion LMs.
172
+ The checkpoints inherit the limitations of GPT-2 and the small experimental
173
+ training setup, including potential memorization, bias, and unstable outputs.
174
+
175
+ ## Limitations and open questions
176
+
177
+ - These are research checkpoints rather than a fully packaged inference
178
+ pipeline.
179
+ - The `.pt` format stores weights only; configuration and tokenizer files are
180
+ reconstructed by the loader.
181
+ - The model was trained on short sequences (maximum length 64), so longer
182
+ contexts are outside the validated setup.
183
+ - The corruption curriculum and the semantic-neighbour operator have not been
184
+ established as generally superior to standard masked or random corruption.
185
+ - Reported results should be interpreted as exploratory measurements, not as
186
+ a leaderboard claim.
187
+
188
+ ## Citation
189
+
190
+ If you use these checkpoints or the training setup, please cite this
191
+ repository and the upstream GPT-2 work:
192
+
193
+ ```bibtex
194
+ @misc{diffusion_llm_experiment,
195
+ title = {Diffusion-LLM: Experimental GPT-2 Discrete Denoising Checkpoints},
196
+ author = {Andrei Rabau},
197
+ year = {2026},
198
+ url = {https://huggingface.co/AndreiRabau/diffusion-llm}
199
+ }
200
+ ```
201
+
202
+ The implementation and experiment configurations are available in the source
203
+ repository, including [`model_wrappers/gpt2_diffusion_transformer_wrapper.py`](model_wrappers/gpt2_diffusion_transformer_wrapper.py),
204
+ [`train_utils/train.py`](train_utils/train.py), and the files under
205
+ [`experiments/`](experiments/).