JonasGeiping commited on
Commit
23e2702
·
verified ·
1 Parent(s): 61bf7ff

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +229 -168
README.md CHANGED
@@ -1,199 +1,260 @@
1
  ---
2
  library_name: transformers
3
- tags: []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  ---
5
 
6
- # Model Card for Model ID
 
 
7
 
8
- <!-- Provide a quick summary of what the model is/does. -->
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
- ## Model Details
13
 
14
- ### Model Description
 
15
 
16
- <!-- Provide a longer summary of what this model is. -->
 
 
 
 
 
 
 
 
17
 
18
- This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
19
 
20
- - **Developed by:** [More Information Needed]
21
- - **Funded by [optional]:** [More Information Needed]
22
- - **Shared by [optional]:** [More Information Needed]
23
- - **Model type:** [More Information Needed]
24
- - **Language(s) (NLP):** [More Information Needed]
25
- - **License:** [More Information Needed]
26
- - **Finetuned from model [optional]:** [More Information Needed]
27
 
28
- ### Model Sources [optional]
29
 
30
- <!-- Provide the basic links for the model. -->
31
 
32
- - **Repository:** [More Information Needed]
33
- - **Paper [optional]:** [More Information Needed]
34
- - **Demo [optional]:** [More Information Needed]
35
 
36
- ## Uses
 
 
 
 
 
 
 
37
 
38
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
 
39
 
40
- ### Direct Use
 
 
41
 
42
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
 
 
 
 
 
 
 
43
 
44
- [More Information Needed]
45
 
46
- ### Downstream Use [optional]
 
 
 
47
 
48
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
 
 
49
 
50
- [More Information Needed]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
 
52
- ### Out-of-Scope Use
53
 
54
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
55
 
56
- [More Information Needed]
57
 
58
- ## Bias, Risks, and Limitations
 
 
 
59
 
60
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
 
 
 
61
 
62
- [More Information Needed]
 
63
 
64
- ### Recommendations
 
65
 
66
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
67
-
68
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
69
-
70
- ## How to Get Started with the Model
71
-
72
- Use the code below to get started with the model.
73
-
74
- [More Information Needed]
75
-
76
- ## Training Details
77
-
78
- ### Training Data
79
-
80
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
81
-
82
- [More Information Needed]
83
-
84
- ### Training Procedure
85
-
86
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
87
-
88
- #### Preprocessing [optional]
89
-
90
- [More Information Needed]
91
-
92
-
93
- #### Training Hyperparameters
94
-
95
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
96
-
97
- #### Speeds, Sizes, Times [optional]
98
-
99
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
100
-
101
- [More Information Needed]
102
-
103
- ## Evaluation
104
-
105
- <!-- This section describes the evaluation protocols and provides the results. -->
106
-
107
- ### Testing Data, Factors & Metrics
108
-
109
- #### Testing Data
110
-
111
- <!-- This should link to a Dataset Card if possible. -->
112
-
113
- [More Information Needed]
114
-
115
- #### Factors
116
-
117
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
118
-
119
- [More Information Needed]
120
-
121
- #### Metrics
122
-
123
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
124
-
125
- [More Information Needed]
126
-
127
- ### Results
128
-
129
- [More Information Needed]
130
-
131
- #### Summary
132
-
133
-
134
-
135
- ## Model Examination [optional]
136
-
137
- <!-- Relevant interpretability work for the model goes here -->
138
-
139
- [More Information Needed]
140
-
141
- ## Environmental Impact
142
-
143
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
144
-
145
- Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
146
-
147
- - **Hardware Type:** [More Information Needed]
148
- - **Hours used:** [More Information Needed]
149
- - **Cloud Provider:** [More Information Needed]
150
- - **Compute Region:** [More Information Needed]
151
- - **Carbon Emitted:** [More Information Needed]
152
-
153
- ## Technical Specifications [optional]
154
-
155
- ### Model Architecture and Objective
156
-
157
- [More Information Needed]
158
-
159
- ### Compute Infrastructure
160
-
161
- [More Information Needed]
162
-
163
- #### Hardware
164
-
165
- [More Information Needed]
166
-
167
- #### Software
168
-
169
- [More Information Needed]
170
-
171
- ## Citation [optional]
172
-
173
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
174
-
175
- **BibTeX:**
176
-
177
- [More Information Needed]
178
-
179
- **APA:**
180
-
181
- [More Information Needed]
182
-
183
- ## Glossary [optional]
184
-
185
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
186
-
187
- [More Information Needed]
188
-
189
- ## More Information [optional]
190
-
191
- [More Information Needed]
192
-
193
- ## Model Card Authors [optional]
194
-
195
- [More Information Needed]
196
-
197
- ## Model Card Contact
198
-
199
- [More Information Needed]
 
1
  ---
2
  library_name: transformers
3
+ tags:
4
+ - code
5
+ - math
6
+ - reasoning
7
+ - llm
8
+ license: apache-2.0
9
+ language:
10
+ - en
11
+ pipeline_tag: text-generation
12
+ # datasets: # cannot order these nicely
13
+ # - HuggingFaceTB/smollm-corpus
14
+ # - jon-tow/starcoderdata-python-edu
15
+ # - ubaada/booksum-complete-cleaned
16
+ # - euirim/goodwiki
17
+ # - togethercomputer/RedPajama-Data-1T
18
+ # - allenai/dolma
19
+ # - bigcode/the-stack-v2-train-smol-ids
20
+ # - bigcode/starcoderdata
21
+ # - m-a-p/Matrix
22
+ # - cerebras/SlimPajama-627B
23
+ # - open-phi/textbooks
24
+ # - open-phi/textbooks_grounded
25
+ # - open-phi/programming_books_llama
26
+ # - nampdn-ai/tiny-strange-textbooks
27
+ # - nampdn-ai/tiny-textbooks
28
+ # - nampdn-ai/tiny-code-textbooks
29
+ # - nampdn-ai/tiny-orca-textbooks
30
+ # - SciPhi/textbooks-are-all-you-need-lite
31
+ # - vikp/textbook_quality_programming
32
+ # - EleutherAI/proof-pile-2
33
+ # - open-web-math/open-web-math
34
+ # - biglam/blbooks-parquet
35
+ # - storytracer/LoC-PD-Books
36
+ # - GAIR/MathPile
37
+ # - tomg-group-umd/CLRS-Text-train
38
+ # - math-ai/AutoMathText
39
+ # - bigcode/commitpackft
40
+ # - bigcode/stack-dedup-python-fns
41
+ # - vikp/python_code_instructions_filtered
42
+ # - mlabonne/chessllm
43
+ # - Waterhorse/chess_data
44
+ # - EleutherAI/lichess-puzzles
45
+ # - chargoddard/WebInstructSub-prometheus
46
+ # - Locutusque/hercules-v5.0
47
+ # - nvidia/OpenMathInstruct-1
48
+ # - meta-math/MetaMathQA
49
+ # - m-a-p/CodeFeedback-Filtered-Instruction
50
+ # - nvidia/Daring-Anteater
51
+ # - nvidia/sft_datablend_v1
52
+ # - BAAI/Infinity-Instruct
53
+ # - anthracite-org/Stheno-Data-Filtered
54
+ # - Nopm/Opus_WritingStruct
55
+ # - xinlai/Math-Step-DPO-10K
56
+ # - bigcode/self-oss-instruct-sc2-exec-filter-50k
57
+ # - HuggingFaceTB/everyday-conversations
58
+ # - hkust-nlp/gsm8k-fix
59
+ # - HuggingFaceH4/no_robots
60
+ # - THUDM/LongWriter-6k
61
+ # - THUDM/webglm-qa
62
+ # - AlgorithmicResearchGroup/ArXivDLInstruct
63
+ # - allenai/tulu-v2-sft-mixture-olmo-4096
64
+ # - bigscience/P3
65
+ # - Gryphe/Sonnet3.5-SlimOrcaDedupCleaned
66
+ # - Gryphe/Opus-WritingPrompts
67
+ # - nothingiisreal/Reddit-Dirty-And-WritingPrompts
68
+ # - nothingiisreal/Kalomaze-Opus-Instruct-25k-filtered
69
+ # - internlm/Lean-Github
70
+ # - pkuAI4M/LeanWorkbook
71
+ # - casey-martin/multilingual-mathematical-autoformalization
72
+ # - AI4M/leandojo-informalized
73
+ # - casey-martin/oa_cpp_annotate_gen
74
+ # - l3lab/ntp-mathlib-instruct-st
75
+ # - ajibawa-2023/Maths-College
76
+ # - ajibawa-2023/Maths-Grade-School
77
+ # - ajibawa-2023/General-Stories-Collection
78
+ # - XinyaoHu/AMPS_mathematica
79
+ # - XinyaoHu/AMPS_khan
80
+ # - Magpie-Align/Magpie-Pro-MT-300K-v0.1
81
+ # - Magpie-Align/Magpie-Reasoning-150K
82
+ # - gair-prox/FineWeb-pro
83
+ # - gair-prox/c4-pro
84
+ # - gair-prox/RedPajama-pro
85
+ # - gair-prox/open-web-math-pro
86
+ # - togethercomputer/Long-Data-Collections
87
+ # - emozilla/pg19
88
+ # - MathGenie/MathCode-Pile
89
+ # - KingNish/reasoning-base-20k
90
+ # - nvidia/OpenMathInstruct-2
91
+ # - LLM360/TxT360
92
+ # - neuralwork/arxiver
93
  ---
94
 
95
+ # Huginn - Baseline Checkpoint
96
+ This is the last checkpoint from our baseline (non-recurrent!) large-scale comparison training run. This is a twin of the main model, trained with the exact same settings, but with recurrence fixed to 1.
97
+
98
 
99
+ ## Table of Contents
100
 
101
+ 1. [How to Use](#downloading-and-using-the-model)
102
+ 2. [Advanced Usage](#advanced-features)
103
+ 3. [Model Summary](#model-summary)
104
+ 4. [Limitations](#limitations)
105
+ 5. [Technical Details](#training)
106
+ 6. [License](#license)
107
+ 7. [Citation](#citation)
108
+
109
+
110
+ ## Downloading and Using the Model
111
+ Load the model like this:
112
+ ```python
113
+ import torch
114
+ from transformers import AutoModelForCausalLM, AutoTokenizer
115
 
116
+ model = AutoModelForCausalLM.from_pretrained("tomg-group-umd/huginn-0125", torch_dtype=torch.bfloat16, trust_remote_code=True)
117
+ tokenizer = AutoTokenizer.from_pretrained("tomg-group-umd/huginn-0125")
118
+ ```
119
+ ### Modifying the Model's Depth at Test Time:
120
+ By providing the argument `num_steps`, the model will execute a forward pass with that amount of compute:
121
+ ```python
122
+ input_ids = tokenizer.encode("The capital of Westphalia is", return_tensors="pt", add_special_tokens=True).to(device)
123
+ model.eval()
124
+ model.to(device)
125
+
126
+ model(input_ids, num_steps=32)
127
+ ```
128
+ The model has about 1.5B parameters in non-recurrent code, 0.5B parameters in the embedding, and 1.5B recurrent parameters, so, as a guideline,
129
+ the number of materialized parameters is `num_steps * 1.5B + 2B`. Playing with this parameter is what makes this model interesting, and different from fixed-depth transformers!
130
+ The model is trained to accept an arbitrary number of steps. However, using fewer than 4 steps will result in very coarse answers. If given enough context to reason about, benchmarks show the model improving up to around `num_steps=64`. Beyond that, more steps generally do not hurt, but we see no further improvements.
131
 
132
+ *Note*: Due to an upload issue the model is currently stored on HF with 2 copies of the tied embedding, instead of just one. This will be fixed in a future release.
133
 
134
+ ### Inference
135
+ The model was trained with bfloat16-mixed precision, so we recommend using `bfloat16` to run inference (or AMP bfloat16-mixed precision, if you really want). All benchmarks were evaluated in pure `bfloat16`.
136
 
137
+ ### Sampling
138
+ The model can be used like a normal HF model to generate text with KV-caching working as expected. You can provide `num_steps` directly to the `generate` call, for example:
139
+ ```
140
+ model.eval()
141
+ config = GenerationConfig(max_length=256, stop_strings=["<|end_text|>", "<|end_turn|>"],
142
+ use_cache=True,
143
+ do_sample=False, temperature=None, top_k=None, top_p=None, min_p=None,
144
+ return_dict_in_generate=True,
145
+ eos_token_id=65505,bos_token_id=65504,pad_token_id=65509)
146
 
 
147
 
148
+ input_ids = tokenizer.encode("The capital of Westphalia is", return_tensors="pt", add_special_tokens=True).to(device)
149
+ outputs = model.generate(input_ids, config, tokenizer=tokenizer, num_steps=16)
150
+ ```
 
 
 
 
151
 
152
+ *Note*: `num_steps` and other model arguments CANNOT be included in the `GenerationConfig`, they will shadow model args at runtime.
153
 
 
154
 
155
+ ### Chat Templating
 
 
156
 
157
+ The model was not finetuned or post-trained, but due to inclusion of instruction data during pretraining, natively understand its chat template. You can chat with the model like so
158
+ ```
159
+ messages = []
160
+ messages.append({"role": "system", "content" : You are a helpful assistant."}
161
+ messages.append({"role": "user", "content" : What do you think of Goethe's Faust?"}
162
+ chat_input = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
163
+ print(chat_input)
164
+ input_ids = tokenizer.encode(chat_input, return_tensors="pt", add_special_tokens=False).to(device)
165
 
166
+ model.generate(input_ids, config, num_steps=64, tokenizer=tokenizer)
167
+ ```
168
 
169
+ ### KV-cache Details
170
+ The model requires its own KV-cache implementation `HuginnDynamicCache`, otherwise the KV-caches of later calls to the recurrent block will overwrite the earlier ones.
171
+ The current implementation will always try to inject this Cache implementation, but that may break with huggingface updates. If you do not use generate, but implement your own generation, use a pattern like this:
172
 
173
+ ```python
174
+ # first step:
175
+ past_key_values = None
176
+ outputs = model(input_ids=input_ids, use_cache=True, past_key_values=past_key_values)
177
+ past_key_values = outputs.past_key_values # Should be an instance of HuginnDynamicCache
178
+ # next step
179
+ outputs = model(input_ids=input_ids, use_cache=True, past_key_values=past_key_values)
180
+ ```
181
 
182
+ ## Advanced Features
183
 
184
+ ### Per-Token Adaptive Compute
185
+ When generating, you can also a variable amount of compute per-token. The model is not trained for this, so this is a proof-of-concept, that can do this task zero-shot.
186
+ You can pick between a few sane stopping rules, `entropy-diff`, `latent-diff`,`kl` and `argmax-stability`, via `criterion=kl`. The exit threshold can be modified via `exit_threshold=5e-4`.
187
+ We suggest using `kl` for interesting exits and `argmax-stability` for conservative exits. Note that using these variables overrides the default generation function. Not all arguments that are valid for the normal `generate` call are valid here. To make this more explicit, you can also directly call `generate_with_adaptive_compute`:
188
 
189
+ ```python
190
+ from transformers import TextStreamer
191
+ streamer = TextStreamer(tokenizer)
192
 
193
+ model.generate_with_adaptive_compute(input_ids, config, num_steps=64, tokenizer=tokenizer, streamer=streamer,
194
+ continuous_compute=False, criterion="kl", exit_threshold=5e-4, cache_kwargs={"lookup_strategy": "latest-m4"})
195
+
196
+ ```
197
+ Your cache strategy should be set to `"latest-m4"` if using adaptive compute.
198
+
199
+ ### KV-cache Sharing
200
+ To reduce KV cache memory requirements, the model can be run with fewer KV-caches, with later iterations in the recurrence overwriting earlier caches. To use this feature, set
201
+ the cache argument `lookup_strategy` to include `compress-s16` (where the last number determine the size of the cache).
202
+ ```
203
+ model.generate_with_adaptive_compute(input_ids, config, num_steps=64, tokenizer=tokenizer, streamer=streamer,
204
+ continuous_compute=False, cache_kwargs={"lookup_strategy": "compress-s16"})
205
+ ```
206
+ You can combine this per-token adaptive compute. In that case your lookup strategy should be `latest-m4-compress-s16`.
207
+
208
+ ### Warmstart / Continuous CoT
209
+ At each generation step, the recurrence can be warmstarted with the final state from the previous token by setting `continuous_compute=True`, like so
210
+ ```
211
+ model.generate_with_adaptive_compute(input_ids, config, num_steps=64, tokenizer=tokenizer, streamer=streamer, continuous_compute=True)
212
+ ```
213
+
214
+
215
+
216
+ ## Model Summary
217
+ The model is primarily structured around decoder-only transformer blocks. However these blocks are structured into three functional groups, the __prelude__ \\(P\\),
218
+ which embeds the input data into a latent space using multiple transformer layers, then the core __recurrent block__ \\(R\\), which is the central unit of recurrent
219
+ computation modifying states \\(\mathbf{s} \in \mathbb{R}^{n \times h }\\), and finally the __coda__ \\(C\\), which un-embeds from latent space using several layers and
220
+ also contains the prediction head of the model.
221
+
222
+ Given a number of recurrent iterations \\(r\\), and a sequence of input tokens \\(\mathbf{x} \in V^n\\) these groups are used in the following way to produce output
223
+ probabilities \\(\mathbf{p} \in \mathbb{R}^{n \times |V|}\\).
224
 
225
+ $$\mathbf{e} = P(\mathbf{x})$$
226
 
227
+ $$\mathbf{s}_0 \sim \mathcal{N}(\mathbf{0}, \sigma^2 I_{n\cdot h})$$
228
 
229
+ $$\mathbf{s}_i = R(\mathbf{e}, \mathbf{s}_{i-1}) \; \textnormal{for} \; i \in \lbrace 1, \dots, r \rbrace$$
230
 
231
+ $$\mathbf{p} = R(\mathbf{s}_r)$$
232
+ where \\(\sigma\\) is the standard deviation of the initial random state. Given an init random state \\(\mathbf{s}_0\\), the model repeatedly applies the core
233
+ block \\(R\\), which accepts the latent state \\(\mathbf{s}_{i-1}\\) and the embedded input \\(\mathbf{e}\\) and outputs a new latent state \\(\mathbf{s}_i\\).
234
+ After finishing all iterations, the coda block processes the last state and produces the probabilities of the next token.
235
 
236
+ Please refer to the paper for benchmark performance on standard benchmarks.
237
+
238
+ ## Limitations
239
+ Our checkpoint is trained for only 47000 steps on a broadly untested data mixture with a constant learning rate. As an academic project, the model is trained only on publicly available data and the 800B token count, while large in comparison to older fully open-source models such as the Pythia series, is small in comparison to modern open-source efforts such as OLMo, and tiny in comparison to the datasets used to train industrial open-weight models.
240
 
241
+ ## Technical Specifications
242
+ This model was trained on 21 segments of 4096 AMD MI-250X GPUs on the OLCF Frontier Supercomputer in early December 2024. The model was trained using ROCM 6.2.0, and PyTorch 2.6 nightly pre-release 24/11/02. The code used to train the model can be found at https://github.com/seal-rg/recurrent-pretraining.
243
 
244
+ ## License
245
+ This model is released under the [apache-2.0](https://choosealicense.com/licenses/apache-2.0/) licence.
246
 
247
+ ## Citation
248
+ ```
249
+ @article{geiping2025scaling,
250
+ title={Scaling up Test-Time Compute with Latent Reasoning: A Recurrent Depth Approach},
251
+ author={Jonas Geiping and Sean McLeish and Neel Jain and John Kirchenbauer and Siddharth Singh and Brian R. Bartoldson and Bhavya Kailkhura and Abhinav Bhatele and Tom Goldstein},
252
+ year={2025},
253
+ eprint={2502.},
254
+ archivePrefix={arXiv},
255
+ primaryClass={cs.CL}
256
+ }
257
+ ```
258
+
259
+ ## Contact
260
+ Please, feel free to contact us with any questions, or open an discussion thread on Hugging Face.