davda54 commited on
Commit
6ba147e
·
verified ·
1 Parent(s): 35372db

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +325 -3
README.md CHANGED
@@ -1,3 +1,325 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ license: apache-2.0
5
+ library_name: transformers
6
+ tags:
7
+ - language-model
8
+ - dual-objective
9
+ - autoregressive
10
+ - masked-diffusion
11
+ - causal-lm
12
+ - masked-lm
13
+ datasets:
14
+ - HPLT/HPLT2.0_cleaned
15
+ model-index:
16
+ - name: dual-lm-470m
17
+ results:
18
+ - task:
19
+ type: text-generation
20
+ dataset:
21
+ type: ai2_arc
22
+ name: ARC-Easy
23
+ split: test
24
+ metrics:
25
+ - type: accuracy_norm
26
+ value: 28.6
27
+ name: Normalized Accuracy
28
+ - task:
29
+ type: text-generation
30
+ dataset:
31
+ type: ai2_arc
32
+ name: ARC-Challenge
33
+ split: test
34
+ metrics:
35
+ - type: accuracy_norm
36
+ value: 5.7
37
+ name: Normalized Accuracy
38
+ - task:
39
+ type: text-generation
40
+ dataset:
41
+ type: hellaswag
42
+ name: HellaSwag
43
+ split: validation
44
+ metrics:
45
+ - type: accuracy_norm
46
+ value: 31.1
47
+ name: Normalized Accuracy
48
+ - task:
49
+ type: text-generation
50
+ dataset:
51
+ type: piqa
52
+ name: PIQA
53
+ split: validation
54
+ metrics:
55
+ - type: accuracy_norm
56
+ value: 40.9
57
+ name: Normalized Accuracy
58
+ ---
59
+
60
+ # Dual-objective Language Model (470M)
61
+
62
+ This is the model repository for the paper **[Dual-Objective Language Models: Training Efficiency Without Overfitting](https://arxiv.org/abs/2512.14549)**, published at **ICLR 2026**.
63
+
64
+ The dual-objective approach combines **autoregressive** and **masked-diffusion** training objectives within a single standard transformer — no architectural changes required. The resulting model can be used as a causal language model, a masked (MNTP) language model, or with prefix attention at inference time.
65
+
66
+ | | |
67
+ |---|---|
68
+ | **Authors** | David Samuel and Lucas Georges Gabriel Charpentier |
69
+ | **Paper** | [arXiv:2512.14549](https://arxiv.org/abs/2512.14549) |
70
+ | **Code** | [github.com/ltgoslo/dual-language-models](https://github.com/ltgoslo/dual-language-models) |
71
+ | **License** | Apache 2.0 |
72
+
73
+ ## Model Overview
74
+
75
+ - **Parameters**: 470M total (360M non-embedding)
76
+ - **Layers**: 24
77
+ - **Hidden size**: 1024
78
+ - **Attention heads**: 16 (head dim = 64)
79
+ - **Intermediate size**: 3554 (SwiGLU)
80
+ - **Vocabulary**: 51,200 BPE tokens
81
+ - **Context length**: 2,048 tokens
82
+ - **Training tokens**: 32 billion
83
+ - **Positional encoding**: RoPE (θ = 160,000)
84
+ - **Normalization**: RMSNorm (pre-norm, ε = 1e-7)
85
+
86
+ ## Main Branch
87
+
88
+ The main branch contains the model trained with the **recommended configuration for regular data settings** (Remark 1 in the paper):
89
+
90
+ | Setting | Value |
91
+ |---|---|
92
+ | α (autoregressive weight) | 63/64 (0.984375) |
93
+ | Data repetitions | 1× (32B total tokens) |
94
+ | Training objective | 98.4% autoregressive + 1.6% masked-diffusion |
95
+
96
+ This configuration achieves strong autoregressive performance while gaining bidirectional capabilities essentially for free.
97
+
98
+ ## All Trained Models
99
+
100
+ All 50 models from the paper are available as branches. Each branch is named `alpha_{α:.3f}_n-reps={R}`:
101
+
102
+ <details>
103
+ <summary><b>Click to expand full list of branches</b></summary>
104
+
105
+ The models span:
106
+ - **Repetitions (R)**: 1, 2, 4, 8, 16, 32, 64, 128, 256
107
+ - **Alpha (α)**: 0 (pure masked-diffusion) to 1 (pure autoregressive), with values at 0, 1/256, 1/64, 1/16, 1/4, 1/2, 3/4, 15/16, 63/64, 255/256, 1
108
+
109
+ For example:
110
+ - `alpha_0.750_n-reps=32` — dual model (α=3/4) trained with 32 data repetitions
111
+ - `alpha_0.125_n-reps=128` — dual model (α=1/8) trained with 128 data repetitions
112
+ - `alpha_1.000_n-reps=1` — pure autoregressive baseline with 1 repetition
113
+ - `alpha_0.000_n-reps=128` — pure masked-diffusion with 128 repetitions
114
+
115
+ </details>
116
+
117
+ ### Recommended Configurations
118
+
119
+ | Regime | Repetitions | Recommended α | Branch |
120
+ |---|---|---|---|
121
+ | **Regular data** (≤16 reps) | 1× | 63/64 (0.984375) | `main` |
122
+ | **Data-constrained** (32 reps) | 32× | 3/4 (0.75) | `alpha_0.750_n-reps=32` |
123
+ | **Data-constrained** (128 reps) | 128× | 1/8 (0.125) | `alpha_0.125_n-reps=128` |
124
+
125
+ ## Usage
126
+
127
+ This model uses a **LLaMA-backbone-based implementation** (`LlamaModel` from transformers) with a custom GELU projection head. All model classes require `trust_remote_code=True`.
128
+
129
+ ### Loading the Model
130
+
131
+ ```python
132
+ from transformers import AutoTokenizer, LlamaConfig
133
+ from hf_model_llama.modeling_dlm_llama import DLMLlamaForCausalLM
134
+
135
+ model_id = "ltg/dual-lm-470m"
136
+
137
+ tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
138
+ config = LlamaConfig.from_pretrained(model_id)
139
+ model = DLMLlamaForCausalLM.from_pretrained(model_id, config=config, trust_remote_code=True)
140
+ ```
141
+
142
+ ### Text Generation (Autoregressive)
143
+
144
+ ```python
145
+ import torch
146
+ from transformers import AutoTokenizer, LlamaConfig
147
+ from hf_model_llama.modeling_dlm_llama import DLMLlamaForCausalLM
148
+
149
+ model_id = "ltg/dual-lm-470m"
150
+ tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
151
+ config = LlamaConfig.from_pretrained(model_id)
152
+ model = DLMLlamaForCausalLM.from_pretrained(model_id, config=config, trust_remote_code=True)
153
+ model.eval()
154
+
155
+ prompt = "The history of artificial intelligence begins with"
156
+ inputs = tokenizer(prompt, return_tensors="pt")
157
+
158
+ with torch.no_grad():
159
+ outputs = model.generate(
160
+ **inputs,
161
+ max_new_tokens=100,
162
+ do_sample=True,
163
+ top_p=0.95,
164
+ temperature=0.8,
165
+ )
166
+
167
+ print(tokenizer.decode(outputs[0], skip_special_tokens=True))
168
+ ```
169
+
170
+ ### Masked Language Model (Bidirectional / MNTP)
171
+
172
+ The model can also be used bidirectionally by loading it as `DLMLlamaForMaskedLM`. This uses full (non-causal) attention, enabling the model to attend to all positions.
173
+
174
+ ```python
175
+ import torch
176
+ from transformers import AutoTokenizer, LlamaConfig
177
+ from hf_model_llama.modeling_dlm_llama import DLMLlamaForMaskedLM
178
+
179
+ model_id = "ltg/dual-lm-470m"
180
+ tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
181
+ config = LlamaConfig.from_pretrained(model_id)
182
+ model = DLMLlamaForMaskedLM.from_pretrained(model_id, config=config, trust_remote_code=True)
183
+ model.eval()
184
+
185
+ # Mask token id
186
+ mask_id = tokenizer.convert_tokens_to_ids("<mask>")
187
+
188
+ # Predict masked tokens with bidirectional context
189
+ text = "The capital of <mask> is Paris"
190
+ inputs = tokenizer(text, return_tensors="pt")
191
+
192
+ with torch.no_grad():
193
+ outputs = model(**inputs)
194
+
195
+ # The model uses MNTP: prediction at position i is for token i+1
196
+ # Find the mask position and get the prediction from position before it
197
+ mask_pos = (inputs["input_ids"] == mask_id).nonzero(as_tuple=True)[1].item()
198
+ predicted_id = outputs.logits[0, mask_pos - 1].argmax(dim=-1)
199
+ print(f"Predicted: {tokenizer.decode(predicted_id)}")
200
+ ```
201
+
202
+ ### Perplexity / Log-Likelihood Scoring
203
+
204
+ ```python
205
+ import torch
206
+ import torch.nn.functional as F
207
+ from transformers import AutoTokenizer, LlamaConfig
208
+ from hf_model_llama.modeling_dlm_llama import DLMLlamaForCausalLM
209
+
210
+ model_id = "ltg/dual-lm-470m"
211
+ tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
212
+ config = LlamaConfig.from_pretrained(model_id)
213
+ model = DLMLlamaForCausalLM.from_pretrained(model_id, config=config, trust_remote_code=True)
214
+ model.eval()
215
+
216
+ text = "Language models predict the next token in a sequence."
217
+ inputs = tokenizer(text, return_tensors="pt")
218
+
219
+ with torch.no_grad():
220
+ outputs = model(**inputs, labels=inputs["input_ids"])
221
+
222
+ print(f"Loss (NLL per token): {outputs.loss.item():.4f}")
223
+ print(f"Perplexity: {torch.exp(outputs.loss).item():.2f}")
224
+ ```
225
+
226
+ ### Loading a Specific Branch
227
+
228
+ ```python
229
+ from transformers import LlamaConfig
230
+ from hf_model_llama.modeling_dlm_llama import DLMLlamaForCausalLM
231
+
232
+ # Load the data-constrained model (α=3/4, 32 repetitions)
233
+ model_id = "ltg/dual-lm-470m"
234
+ config = LlamaConfig.from_pretrained(model_id, revision="alpha_0.750_n-reps=32")
235
+ model = DLMLlamaForCausalLM.from_pretrained(
236
+ model_id,
237
+ revision="alpha_0.750_n-reps=32",
238
+ config=config,
239
+ trust_remote_code=True,
240
+ )
241
+ ```
242
+
243
+ ### Available Model Classes
244
+
245
+ | Task | Class |
246
+ |---|---|
247
+ | Causal LM (generation) | `DLMLlamaForCausalLM` |
248
+ | Masked LM (bidirectional) | `DLMLlamaForMaskedLM` |
249
+ | Sequence Classification | `DLMLlamaForSequenceClassification` |
250
+ | Token Classification | `DLMLlamaForTokenClassification` |
251
+ | Question Answering | `DLMLlamaForQuestionAnswering` |
252
+
253
+ All classes are in `hf_model_llama.modeling_dlm_llama`.
254
+
255
+ ## Architecture
256
+
257
+ The model follows the standard modern transformer recipe with no modifications:
258
+
259
+ - **Pre-normalization** with RMSNorm (with learnable scale)
260
+ - **Rotary Positional Embeddings** (RoPE) with θ = 160,000
261
+ - **SwiGLU** feed-forward layers
262
+ - **Classifier head**: RMSNorm → Linear + GELU(tanh) → LM head (with bias)
263
+ - **No tied embeddings** (`tie_weights = false`)
264
+
265
+ The only difference between autoregressive and masked-diffusion modes is the **input** (original vs. partially masked tokens) and the **attention mask** (causal vs. bidirectional). Both modes predict the next token at each position.
266
+
267
+ ## Training Details
268
+
269
+ | Hyperparameter | Value |
270
+ |---|---|
271
+ | Optimizer | Muon ([Liu et al., 2025](https://arxiv.org/abs/2502.16982)) |
272
+ | Learning rate | 0.007 |
273
+ | LR schedule | Warmup-Stable-Decay (no warmup, 2,048 decay steps) |
274
+ | Total steps | 8,192 |
275
+ | Batch size | 4M tokens (global) |
276
+ | Sequence length | 2,048 |
277
+ | Weight decay | 0.1 |
278
+ | Z-loss | 1e-4 |
279
+ | Precision | bfloat16 |
280
+ | Hardware | 128× AMD MI250X GPUs (256 logical devices) |
281
+ | Training corpus | [HPLT v2](https://hplt-project.org/) (English subset) |
282
+
283
+ The α parameter controls the split of GPUs between objectives: with 256 logical devices, α = 63/64 means 252 devices run autoregressive and 4 run masked-diffusion.
284
+
285
+ ## Evaluation Results
286
+
287
+ ### Autoregressive (Unidirectional) Performance
288
+
289
+ Normalized scores where 0% = random baseline, 100% = perfect.
290
+
291
+ | Model | ARC-C | ARC-E | BLiMP | CSQA | HSwag | MMLU | OBQA | PIQA | SIQA | **Avg** |
292
+ |---|---|---|---|---|---|---|---|---|---|---|
293
+ | **Dual (α=63/64, 1 rep)** | 5.7 | 28.6 | **63.7** | **35.1** | 31.1 | **4.9** | **17.6** | **40.9** | 14.3 | **26.9** |
294
+ | AR-only (α=1, 1 rep) | **5.9** | **30.3** | 61.3 | 33.5 | **31.7** | 3.8 | 13.6 | 39.4 | **15.2** | 26.1 |
295
+ | **Dual (α=3/4, 32 reps)** | 3.3 | **28.0** | **57.9** | **31.1** | **26.4** | 3.6 | **14.4** | **36.1** | **14.6** | **23.9** |
296
+ | AR-only (α=1, 32 reps) | **5.0** | 24.9 | 53.3 | 28.5 | 25.4 | **3.8** | 9.9 | 33.3 | 14.2 | 22.0 |
297
+ | **Dual (α=1/8, 128 reps)** | **1.7** | **23.6** | **56.1** | **24.8** | **14.2** | **1.6** | **8.5** | **28.1** | **13.3** | **19.1** |
298
+ | AR-only (α=1, 128 reps) | -1.0 | 12.3 | 33.2 | 6.8 | 8.1 | 1.1 | -0.5 | 15.8 | 8.9 | 9.4 |
299
+
300
+ ### Key Findings
301
+
302
+ 1. **Regular data (≤16 reps)**: A small amount of masked-diffusion (α ≈ 63/64) improves bidirectional performance without losing any autoregressive quality.
303
+ 2. **Data-constrained (>32 reps)**: Choose α so the autoregressive objective sees ~16 effective repetitions. The dual model dramatically outperforms pure autoregressive (19.1 vs 9.4 at 128 reps).
304
+ 3. **Prefix attention**: Dual-objective models reliably gain ~1+ percentage points by processing the context bidirectionally at inference time — no additional training needed.
305
+
306
+ ## Practical Recommendations from the Paper
307
+
308
+ > **Remark 1** *(Regular data settings)*: Train with α ≈ 63/64 to gain strong bidirectional performance without losing autoregressive quality.
309
+
310
+ > **Remark 2** *(Data-constrained settings)*: Choose α that exposes the autoregressive objective to roughly 16 repetitions of the training data.
311
+
312
+ > **Remark 3** *(Prefix language modeling)*: At inference time, process the conditional part of the prompt fully bidirectionally for improved autoregressive performance.
313
+
314
+ ## Citation
315
+
316
+ ```bibtex
317
+ @inproceedings{
318
+ samuel2026dualobjective,
319
+ title={Dual-objective Language Models: Training Efficiency Without Overfitting},
320
+ author={David Samuel and Lucas Georges Gabriel Charpentier},
321
+ booktitle={The Fourteenth International Conference on Learning Representations},
322
+ year={2026},
323
+ url={https://openreview.net/forum?id=BrPt0GFgOM}
324
+ }
325
+ ```