Corning commited on
Commit
48c835f
·
verified ·
1 Parent(s): 543ea09

Initial LEDOM-2B release (step 66079, val_bpb 0.6334)

Browse files
Files changed (5) hide show
  1. README.md +191 -3
  2. meta_066079.json +59 -0
  3. model_066079.pt +3 -0
  4. token_bytes.pt +3 -0
  5. tokenizer.pkl +3 -0
README.md CHANGED
@@ -1,3 +1,191 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ language:
4
+ - en
5
+ library_name: ledom
6
+ tags:
7
+ - reverse-language-model
8
+ - ledom
9
+ - text-generation
10
+ - pretrained
11
+ - math-reasoning
12
+ pipeline_tag: text-generation
13
+ ---
14
+
15
+ # LEDOM-2B: Reverse Language Model
16
+
17
+ > ⚠️ **This is NOT a Hugging Face `transformers` model.** It is a custom decoder-only
18
+ > Transformer trained right-to-left, and it cannot be loaded with
19
+ > `AutoModelForCausalLM.from_pretrained(...)`. You need this repo's loader:
20
+ > <https://github.com/your-org/ledom>. See "How to use" below.
21
+
22
+ LEDOM-2B is a purely **reverse autoregressive** language model from the paper
23
+ [LEDOM: Reverse Language Model](https://arxiv.org/abs/2507.01335)
24
+ (Yin et al., 2025). Where a normal Forward LM (FLM) factorizes
25
+ `P(x) = ∏_t P(x_t | x_<t)`, LEDOM trains the same decoder-only Transformer on
26
+ **token-reversed documents** so it learns the complementary factorization
27
+ `P(x) = ∏_t P(x_t | x_>t)` — predicting each token from its **future** context.
28
+
29
+ The two main applications:
30
+
31
+ 1. **Generate the past from the future**: type a sentence, LEDOM produces text
32
+ that plausibly *precedes* it. (Backward storytelling, abductive reasoning,
33
+ mathematical work-backward derivations.)
34
+ 2. **Reverse Reward verification**: combine a forward LM's `P(y|x)` with
35
+ LEDOM's posterior `P(x|y)` to rerank or beam-search candidate solutions.
36
+ This implements noisy-channel decoding and yields **+6.6 % AIME 2024**,
37
+ **+15 % AMC 2023** in the paper, across DeepSeekMath / QwenMath / OpenMath2.
38
+
39
+ ## Model details
40
+
41
+ | | |
42
+ |---|---|
43
+ | Parameters | ~2 B |
44
+ | Architecture | decoder-only Transformer, RMSNorm, RoPE, ReLU² MLP (modified-nanoGPT lineage) |
45
+ | Layers | 34 |
46
+ | Hidden dim (`n_embd`) | 2176 |
47
+ | Attention heads | 17 (full attention; `n_kv_head=17`) |
48
+ | Sequence length | 2048 |
49
+ | Vocabulary | 32 768 (rustbpe / tiktoken-compatible) |
50
+ | Window pattern | `SSSL` (sliding window: 3 short + 1 full per repeat) |
51
+ | Precision | BF16 master weights stored as FP32 in checkpoint |
52
+ | Training tokens | ≈140 B (66 079 steps × 2 097 152 tokens) |
53
+ | Final val BPB | 0.6334 |
54
+ | Training data | DCLM-Baseline-derived ClimbMix-400B (CommonCrawl) |
55
+
56
+ The depth-34 / d2176 configuration is computed by this repo's standard scaling
57
+ recipe (`model_dim = depth * aspect_ratio` with `aspect_ratio=64`); FLOPs and
58
+ batch size are auto-derived from the depth.
59
+
60
+ ## Files in this repo
61
+
62
+ | File | Purpose |
63
+ |---|---|
64
+ | `model_066079.pt` | Final model state dict (~10 GB, FP32 master weights) |
65
+ | `meta_066079.json` | Training metadata: model config, hyperparameters, dataloader state |
66
+ | `tokenizer.pkl` | tiktoken `Encoding` (rustbpe-trained, vocab 32768) |
67
+ | `token_bytes.pt` | Per-token byte counts (used for bits-per-byte evaluation) |
68
+ | `README.md` | This file |
69
+
70
+ Drop these into `$LEDOM_BASE_DIR/rlm_checkpoints/LEDOM-2B/` and `$LEDOM_BASE_DIR/tokenizer/`
71
+ respectively (see below).
72
+
73
+ ## How to use
74
+
75
+ ### 1. Install the LEDOM repo
76
+
77
+ ```bash
78
+ git clone https://github.com/your-org/ledom # ← replace with the actual URL
79
+ cd ledom
80
+ uv sync --extra gpu # CUDA (or --extra cpu for laptop testing)
81
+ source .venv/bin/activate
82
+ ```
83
+
84
+ ### 2. Download the checkpoint
85
+
86
+ ```python
87
+ from huggingface_hub import snapshot_download
88
+ import os
89
+
90
+ # Pulls all files into $LEDOM_BASE_DIR/rlm_checkpoints/LEDOM-2B/
91
+ local = snapshot_download(
92
+ repo_id="Corning/LEDOM-2B",
93
+ local_dir=os.path.expanduser("~/.cache/ledom/rlm_checkpoints/LEDOM-2B"),
94
+ )
95
+ ```
96
+
97
+ Then move the tokenizer files to the location the loader expects:
98
+
99
+ ```bash
100
+ mkdir -p ~/.cache/ledom/tokenizer
101
+ mv ~/.cache/ledom/rlm_checkpoints/LEDOM-2B/tokenizer.pkl ~/.cache/ledom/tokenizer/
102
+ mv ~/.cache/ledom/rlm_checkpoints/LEDOM-2B/token_bytes.pt ~/.cache/ledom/tokenizer/
103
+ ```
104
+
105
+ ### 3. Generate the past from the future (interactive)
106
+
107
+ LEDOM treats your input as the **ending** and produces text that comes
108
+ **before** it.
109
+
110
+ ```bash
111
+ python -m scripts.rlm_chat --model-tag LEDOM-2B
112
+ # Ending: ...and that is why I never trust raccoons again.
113
+ # >>> [it generates a backstory ending in your sentence]
114
+ ```
115
+
116
+ Or programmatically — the trick is that LEDOM is a normal causal Transformer
117
+ that just happens to have been trained on reversed token streams:
118
+
119
+ ```python
120
+ import torch
121
+ from ledom.common import compute_init, autodetect_device_type
122
+ from ledom.checkpoint_manager import load_model
123
+
124
+ _, _, _, _, device = compute_init(autodetect_device_type())
125
+ model, tokenizer, _ = load_model("rlm", device, phase="eval", model_tag="LEDOM-2B")
126
+ bos = tokenizer.get_bos_token_id()
127
+
128
+ ending = "and that is why I never trust raccoons again."
129
+
130
+ # Tokenize and reverse — feed the "ending" in reverse order.
131
+ tokens = tokenizer.encode(ending)
132
+ input_ids = torch.tensor([[bos] + tokens[::-1]], device=device)
133
+
134
+ # Generate up to N reversed tokens (causal autoregression as usual).
135
+ with torch.inference_mode():
136
+ for _ in range(80):
137
+ next_id = model(input_ids)[:, -1, :].argmax(-1, keepdim=True)
138
+ if next_id.item() == bos:
139
+ break
140
+ input_ids = torch.cat([input_ids, next_id], dim=1)
141
+
142
+ # Reverse the (prompt + generation) back to natural reading order.
143
+ all_reversed = input_ids[0, 1:].tolist() # drop BOS
144
+ print(tokenizer.decode(list(reversed(all_reversed))))
145
+ ```
146
+
147
+ ### 4. Use LEDOM as a Reverse Reward verifier
148
+
149
+ To rerank an FLM's candidate answers with LEDOM's posterior `P(x|y)`:
150
+
151
+ ```bash
152
+ python -m scripts.reverse_reward \
153
+ --flm-tag <your-FLM> --rlm-tag LEDOM-2B \
154
+ --benchmark gsm8k --strategy best_of_n \
155
+ --n 32 --lambda 0.4 --temperature 0.7
156
+ ```
157
+
158
+ The bidirectional score is
159
+ `(1-λ)·log P_F(y|x) + λ·log P_R(x|y)` (paper Eq. 7). Empirically `λ ∈ [0.3, 0.5]`
160
+ works best for math reasoning. Step-wise beam search is available via
161
+ `--strategy beam --k 4 --n 3`.
162
+
163
+ ## Behaviors to expect
164
+
165
+ LEDOM **inherits its strengths from the reverse factorization** and
166
+ **inherits its weaknesses for the same reason**. From the paper's evaluation:
167
+
168
+ - ✔ Excels at abductive inference, question synthesis from answers,
169
+ inverse-relation completion, and naturally avoids the "reversal curse".
170
+ - ✔ As a posterior verifier, consistently improves Best-of-N on math
171
+ reasoning across forward models spanning 42 %–96 % greedy accuracy.
172
+ - ✘ Underperforms forward LMs on forward-causal tasks (incremental code
173
+ generation, factual recall like NQ-Open / TriviaQA).
174
+ - ⚠ **Safety asymmetry**: forward-trained safety mechanisms do *not* transfer
175
+ to reverse generation. Treat outputs accordingly; do not deploy untuned for
176
+ user-facing content.
177
+
178
+ ## License
179
+
180
+ MIT (matches the upstream code repository).
181
+
182
+ ## Citation
183
+
184
+ ```bibtex
185
+ @article{yin2025ledom,
186
+ title={LEDOM: Reverse Language Model},
187
+ author={Yin, Xunjian and Cheng, Sitao and Xie, Yuxi and Hu, Xinyu and Lin, Li and Wang, Xinyi and Pan, Liangming and Wang, William Yang and Wan, Xiaojun},
188
+ journal={arXiv preprint arXiv:2507.01335},
189
+ year={2025}
190
+ }
191
+ ```
meta_066079.json ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "step": 66079,
3
+ "val_bpb": 0.633447598427493,
4
+ "model_config": {
5
+ "sequence_len": 2048,
6
+ "vocab_size": 32768,
7
+ "n_layer": 34,
8
+ "n_head": 17,
9
+ "n_kv_head": 17,
10
+ "n_embd": 2176,
11
+ "window_pattern": "SSSL"
12
+ },
13
+ "user_config": {
14
+ "run": "rlm-d34",
15
+ "device_type": "",
16
+ "fp8": false,
17
+ "fp8_recipe": "tensorwise",
18
+ "depth": 34,
19
+ "aspect_ratio": 64,
20
+ "head_dim": 128,
21
+ "max_seq_len": 2048,
22
+ "window_pattern": "SSSL",
23
+ "num_iterations": 66079,
24
+ "target_flops": -1.0,
25
+ "target_param_data_ratio": 12,
26
+ "device_batch_size": 8,
27
+ "total_batch_size": -1,
28
+ "embedding_lr": 0.3,
29
+ "unembedding_lr": 0.008,
30
+ "weight_decay": 0.28,
31
+ "matrix_lr": 0.02,
32
+ "scalar_lr": 0.5,
33
+ "warmup_steps": 40,
34
+ "warmdown_ratio": 0.65,
35
+ "final_lr_frac": 0.05,
36
+ "resume_from_step": 40000,
37
+ "eval_every": 250,
38
+ "eval_tokens": 41943040,
39
+ "core_metric_every": -1,
40
+ "core_metric_max_per_task": 500,
41
+ "sample_every": -1,
42
+ "save_every": 5000,
43
+ "model_tag": null,
44
+ "reverse": true
45
+ },
46
+ "device_batch_size": 8,
47
+ "max_seq_len": 2048,
48
+ "total_batch_size": 2097152,
49
+ "dataloader_state_dict": {
50
+ "pq_idx": 2728,
51
+ "rg_idx": 32,
52
+ "epoch": 1
53
+ },
54
+ "loop_state": {
55
+ "min_val_bpb": 0.633447598427493,
56
+ "smooth_train_loss": 2.131854949718678,
57
+ "total_training_time": 410485.1199762821
58
+ }
59
+ }
model_066079.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4ff7a66639824fd26bb2d1a844f3d38c263d5f694334033a0aa4bc7e423a6fab
3
+ size 10579720944
token_bytes.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:398732dad177888c6f884c3abb76168a6b54fd7c3f011b2d38371587faca54b7
3
+ size 132649
tokenizer.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:387cfc082b0bee45467774fd6f1310a922ad170886a58ccddcb468f275e06a6c
3
+ size 412105