JonasGeiping commited on
Commit
57dbfbc
·
verified ·
1 Parent(s): 90f7630

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +244 -180
README.md CHANGED
@@ -1,199 +1,263 @@
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-0125
96
+ This is Huginn, version 01/25. This is a latent recurrent-depth model with 3.5B parameters, trained for 800B tokens on AMD MI250X machines. This is a proof-of-concept model, but surprisingly capable in reasoning and code given its training budget and size.
97
+ All details on this model can be found in the tech report: "Scaling up Test-Time Compute with Latent Reasoning: A Recurrent Depth Approach."
98
+
99
+ 8 intermediate checkpoints of the model can be found in its collection. Additional intermediate checkpoints are available upon request while we find a place to host all ~350 of them. The data used to train
100
+ this model is publicly available (entirely on Hugging Face), and scripts provided with the pretraining code at https://github.com/seal-rg/recurrent-pretraining can be used to repeat our preprocessing and our entire training run.
101
+
102
+ ## Table of Contents
103
+
104
+ 1. [How to Use](#downloading-and-using-the-model)
105
+ 2. [Advanced Usage](#advanced-features)
106
+ 3. [Model Summary](#model-summary)
107
+ 4. [Limitations](#limitations)
108
+ 5. [Technical Details](#training)
109
+ 6. [License](#license)
110
+ 7. [Citation](#citation)
111
+
112
+
113
+ ## Downloading and Using the Model
114
+ Load the model like this:
115
+ ```python
116
+ import torch
117
+ from transformers import AutoModelForCausalLM, AutoTokenizer
118
+
119
+ model = AutoModelForCausalLM.from_pretrained("tomg-group-umd/huginn-0125", torch_dtype=torch.bfloat16, trust_remote_code=True)
120
+ tokenizer = AutoTokenizer.from_pretrained("tomg-group-umd/huginn-0125")
121
+ ```
122
+ ### Modifying the Model's Depth at Test Time:
123
+ By providing the argument `num_steps`, the model will execute a forward pass with that amount of compute:
124
+ ```python
125
+ input_ids = tokenizer.encode("The capital of Westphalia is", return_tensors="pt", add_special_tokens=True).to(device)
126
+ model.eval()
127
+ model.to(device)
128
+
129
+ model(input_ids, num_steps=32)
130
+ ```
131
+ 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,
132
+ 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!
133
+ 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.
134
 
135
+ *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.
136
 
137
+ ### Inference
138
+ 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`.
139
 
140
+ ### Sampling
141
+ 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:
142
+ ```
143
+ model.eval()
144
+ config = GenerationConfig(max_length=256, stop_strings=["<|end_text|>", "<|end_turn|>"],
145
+ use_cache=True,
146
+ do_sample=False, temperature=None, top_k=None, top_p=None, min_p=None,
147
+ return_dict_in_generate=True,
148
+ eos_token_id=65505,bos_token_id=65504,pad_token_id=65509)
149
 
 
150
 
151
+ input_ids = tokenizer.encode("The capital of Westphalia is", return_tensors="pt", add_special_tokens=True).to(device)
152
+ outputs = model.generate(input_ids, config, tokenizer=tokenizer, num_steps=16)
153
+ ```
154
 
155
+ *Note*: `num_steps` and other model arguments CANNOT be included in the `GenerationConfig`, they will shadow model args at runtime.
156
 
 
157
 
158
+ ### Chat Templating
159
+
160
+ 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
161
+ ```
162
+ messages = []
163
+ messages.append({"role": "system", "content" : You are a helpful assistant."}
164
+ messages.append({"role": "user", "content" : What do you think of Goethe's Faust?"}
165
+ chat_input = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
166
+ print(chat_input)
167
+ input_ids = tokenizer.encode(chat_input, return_tensors="pt", add_special_tokens=False).to(device)
168
+
169
+ model.generate(input_ids, config, num_steps=64, tokenizer=tokenizer)
170
+ ```
171
+
172
+ ### KV-cache Details
173
+ 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.
174
+ 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:
175
+
176
+ ```python
177
+ # first step:
178
+ past_key_values = None
179
+ outputs = model(input_ids=input_ids, use_cache=True, past_key_values=past_key_values)
180
+ past_key_values = outputs.past_key_values # Should be an instance of HuginnDynamicCache
181
+ # next step
182
+ outputs = model(input_ids=input_ids, use_cache=True, past_key_values=past_key_values)
183
+ ```
184
+
185
+ ## Advanced Features
186
+
187
+ ### Per-Token Adaptive Compute
188
+ 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.
189
+ 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`.
190
+ 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`:
191
+
192
+ ```python
193
+ from transformers import TextStreamer
194
+ streamer = TextStreamer(tokenizer)
195
+
196
+ model.generate_with_adaptive_compute(input_ids, config, num_steps=64, tokenizer=tokenizer, streamer=streamer,
197
+ continuous_compute=False, criterion="kl", exit_threshold=5e-4, cache_kwargs={"lookup_strategy": "latest-m4"})
198
+
199
+ ```
200
+ Your cache strategy should be set to `"latest-m4"` if using adaptive compute.
201
+
202
+ ### KV-cache Sharing
203
+ 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
204
+ the cache argument `lookup_strategy` to include `compress-s16` (where the last number determine the size of the cache).
205
+ ```
206
+ model.generate_with_adaptive_compute(input_ids, config, num_steps=64, tokenizer=tokenizer, streamer=streamer,
207
+ continuous_compute=False, cache_kwargs={"lookup_strategy": "compress-s16"})
208
+ ```
209
+ You can combine this per-token adaptive compute. In that case your lookup strategy should be `latest-m4-compress-s16`.
210
+
211
+ ### Warmstart / Continuous CoT
212
+ At each generation step, the recurrence can be warmstarted with the final state from the previous token by setting `continuous_compute=True`, like so
213
+ ```
214
+ model.generate_with_adaptive_compute(input_ids, config, num_steps=64, tokenizer=tokenizer, streamer=streamer, continuous_compute=True)
215
+ ```
216
+
217
+
218
+
219
+ ## Model Summary
220
+ The model is primarily structured around decoder-only transformer blocks. However these blocks are structured into three functional groups, the __prelude__ \\(P\\),
221
+ 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
222
+ 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
223
+ also contains the prediction head of the model.
224
+
225
+ 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
226
+ probabilities \\(\mathbf{p} \in \mathbb{R}^{n \times |V|}\\).
227
+
228
+ $$\mathbf{e} = P(\mathbf{x})$$
229
 
230
+ $$\mathbf{s}_0 \sim \mathcal{N}(\mathbf{0}, \sigma^2 I_{n\cdot h})$$
231
 
232
+ $$\mathbf{s}_i = R(\mathbf{e}, \mathbf{s}_{i-1}) \; \textnormal{for} \; i \in \lbrace 1, \dots, r \rbrace$$
233
 
234
+ $$\mathbf{p} = R(\mathbf{s}_r)$$
235
+ 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
236
+ 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\\).
237
+ After finishing all iterations, the coda block processes the last state and produces the probabilities of the next token.
238
 
239
+ Please refer to the paper for benchmark performance on standard benchmarks.
240
+
241
+ ## Limitations
242
+ 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.
243
 
244
+ ## Technical Specifications
245
+ 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.
246
 
247
+ ## License
248
+ This model is released under the [apache-2.0](https://choosealicense.com/licenses/apache-2.0/) licence.
249
 
250
+ ## Citation
251
+ ```
252
+ @article{geiping2025scaling,
253
+ title={Scaling up Test-Time Compute with Latent Reasoning: A Recurrent Depth Approach},
254
+ 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},
255
+ year={2025},
256
+ eprint={2502.},
257
+ archivePrefix={arXiv},
258
+ primaryClass={cs.CL}
259
+ }
260
+ ```
261
+
262
+ ## Contact
263
+ Please, feel free to contact us with any questions, or open an discussion thread on Hugging Face.