JonasGeiping commited on
Commit
1558acf
·
verified ·
1 Parent(s): b93dc0f

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +235 -178
README.md CHANGED
@@ -1,199 +1,256 @@
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
+ license: apache-2.0
7
+ language:
8
+ - en
9
+ pipeline_tag: text-generation
10
+ # datasets: # cannot order these nicely
11
+ # - HuggingFaceTB/smollm-corpus
12
+ # - jon-tow/starcoderdata-python-edu
13
+ # - ubaada/booksum-complete-cleaned
14
+ # - euirim/goodwiki
15
+ # - togethercomputer/RedPajama-Data-1T
16
+ # - allenai/dolma
17
+ # - bigcode/the-stack-v2-train-smol-ids
18
+ # - bigcode/starcoderdata
19
+ # - m-a-p/Matrix
20
+ # - cerebras/SlimPajama-627B
21
+ # - open-phi/textbooks
22
+ # - open-phi/textbooks_grounded
23
+ # - open-phi/programming_books_llama
24
+ # - nampdn-ai/tiny-strange-textbooks
25
+ # - nampdn-ai/tiny-textbooks
26
+ # - nampdn-ai/tiny-code-textbooks
27
+ # - nampdn-ai/tiny-orca-textbooks
28
+ # - SciPhi/textbooks-are-all-you-need-lite
29
+ # - vikp/textbook_quality_programming
30
+ # - EleutherAI/proof-pile-2
31
+ # - open-web-math/open-web-math
32
+ # - biglam/blbooks-parquet
33
+ # - storytracer/LoC-PD-Books
34
+ # - GAIR/MathPile
35
+ # - tomg-group-umd/CLRS-Text-train
36
+ # - math-ai/AutoMathText
37
+ # - bigcode/commitpackft
38
+ # - bigcode/stack-dedup-python-fns
39
+ # - vikp/python_code_instructions_filtered
40
+ # - mlabonne/chessllm
41
+ # - Waterhorse/chess_data
42
+ # - EleutherAI/lichess-puzzles
43
+ # - chargoddard/WebInstructSub-prometheus
44
+ # - Locutusque/hercules-v5.0
45
+ # - nvidia/OpenMathInstruct-1
46
+ # - meta-math/MetaMathQA
47
+ # - m-a-p/CodeFeedback-Filtered-Instruction
48
+ # - nvidia/Daring-Anteater
49
+ # - nvidia/sft_datablend_v1
50
+ # - BAAI/Infinity-Instruct
51
+ # - anthracite-org/Stheno-Data-Filtered
52
+ # - Nopm/Opus_WritingStruct
53
+ # - xinlai/Math-Step-DPO-10K
54
+ # - bigcode/self-oss-instruct-sc2-exec-filter-50k
55
+ # - HuggingFaceTB/everyday-conversations
56
+ # - hkust-nlp/gsm8k-fix
57
+ # - HuggingFaceH4/no_robots
58
+ # - THUDM/LongWriter-6k
59
+ # - THUDM/webglm-qa
60
+ # - AlgorithmicResearchGroup/ArXivDLInstruct
61
+ # - allenai/tulu-v2-sft-mixture-olmo-4096
62
+ # - bigscience/P3
63
+ # - Gryphe/Sonnet3.5-SlimOrcaDedupCleaned
64
+ # - Gryphe/Opus-WritingPrompts
65
+ # - nothingiisreal/Reddit-Dirty-And-WritingPrompts
66
+ # - nothingiisreal/Kalomaze-Opus-Instruct-25k-filtered
67
+ # - internlm/Lean-Github
68
+ # - pkuAI4M/LeanWorkbook
69
+ # - casey-martin/multilingual-mathematical-autoformalization
70
+ # - AI4M/leandojo-informalized
71
+ # - casey-martin/oa_cpp_annotate_gen
72
+ # - l3lab/ntp-mathlib-instruct-st
73
+ # - ajibawa-2023/Maths-College
74
+ # - ajibawa-2023/Maths-Grade-School
75
+ # - ajibawa-2023/General-Stories-Collection
76
+ # - XinyaoHu/AMPS_mathematica
77
+ # - XinyaoHu/AMPS_khan
78
+ # - Magpie-Align/Magpie-Pro-MT-300K-v0.1
79
+ # - Magpie-Align/Magpie-Reasoning-150K
80
+ # - gair-prox/FineWeb-pro
81
+ # - gair-prox/c4-pro
82
+ # - gair-prox/RedPajama-pro
83
+ # - gair-prox/open-web-math-pro
84
+ # - togethercomputer/Long-Data-Collections
85
+ # - emozilla/pg19
86
+ # - MathGenie/MathCode-Pile
87
+ # - KingNish/reasoning-base-20k
88
+ # - nvidia/OpenMathInstruct-2
89
+ # - LLM360/TxT360
90
+ # - neuralwork/arxiver
91
  ---
92
 
93
+ # Huginn_swa_75_7_ema_0.9_merge
94
+ This is `tomg-group-umd/huginn_swa_75_7_ema_0.9_merge` a weight-averaged checkpoint our base model that improves on GSM8k performance. All other details are as the main model.
95
+
96
+ ## Table of Contents
97
+
98
+ 1. [How to Use](#downloading-and-using-the-model)
99
+ 2. [Advanced Usage](#advanced-features)
100
+ 3. [Model Summary](#model-summary)
101
+ 4. [Limitations](#limitations)
102
+ 5. [Technical Details](#training)
103
+ 6. [License](#license)
104
+ 7. [Citation](#citation)
105
+
106
+
107
+ ## Downloading and Using the Model
108
+ Load the model like this:
109
+ ```python
110
+ import torch
111
+ from transformers import AutoModelForCausalLM, AutoTokenizer
112
+
113
+ model = AutoModelForCausalLM.from_pretrained("tomg-group-umd/huginn-0125", torch_dtype=torch.bfloat16, trust_remote_code=True)
114
+ tokenizer = AutoTokenizer.from_pretrained("tomg-group-umd/huginn-0125")
115
+ ```
116
+ ### Modifying the Model's Depth at Test Time:
117
+ By providing the argument `num_steps`, the model will execute a forward pass with that amount of compute:
118
+ ```python
119
+ input_ids = tokenizer.encode("The capital of Westphalia is", return_tensors="pt", add_special_tokens=True).to(device)
120
+ model.eval()
121
+ model.to(device)
122
 
123
+ model(input_ids, num_steps=32)
124
+ ```
125
+ 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,
126
+ 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!
127
+ 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.
128
 
129
 
130
+ ### Inference
131
+ 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`.
132
 
133
+ ### Sampling
134
+ 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:
135
+ ```
136
+ model.eval()
137
+ config = GenerationConfig(max_length=256, stop_strings=["<|end_text|>", "<|end_turn|>"],
138
+ use_cache=True,
139
+ do_sample=False, temperature=None, top_k=None, top_p=None, min_p=None,
140
+ return_dict_in_generate=True,
141
+ eos_token_id=65505,bos_token_id=65504,pad_token_id=65509)
142
 
 
143
 
144
+ input_ids = tokenizer.encode("The capital of Westphalia is", return_tensors="pt", add_special_tokens=True).to(device)
145
+ outputs = model.generate(input_ids, config, tokenizer=tokenizer, num_steps=16)
146
+ ```
147
 
148
+ *Note*: `num_steps` and other model arguments CANNOT be included in the `GenerationConfig`, they will shadow model args at runtime.
149
 
 
 
 
 
 
 
 
150
 
151
+ ### Chat Templating
152
+
153
+ 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
154
+ ```
155
+ messages = []
156
+ messages.append({"role": "system", "content" : You are a helpful assistant."}
157
+ messages.append({"role": "user", "content" : What do you think of Goethe's Faust?"}
158
+ chat_input = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
159
+ print(chat_input)
160
+ input_ids = tokenizer.encode(chat_input, return_tensors="pt", add_special_tokens=False).to(device)
161
+
162
+ model.generate(input_ids, config, num_steps=64, tokenizer=tokenizer)
163
+ ```
164
+
165
+ ### KV-cache Details
166
+ 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.
167
+ 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:
168
+
169
+ ```python
170
+ # first step:
171
+ past_key_values = None
172
+ outputs = model(input_ids=input_ids, use_cache=True, past_key_values=past_key_values)
173
+ past_key_values = outputs.past_key_values # Should be an instance of HuginnDynamicCache
174
+ # next step
175
+ outputs = model(input_ids=input_ids, use_cache=True, past_key_values=past_key_values)
176
+ ```
177
+
178
+ ## Advanced Features
179
+
180
+ ### Per-Token Adaptive Compute
181
+ 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.
182
+ 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`.
183
+ 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`:
184
+
185
+ ```python
186
+ from transformers import TextStreamer
187
+ streamer = TextStreamer(tokenizer)
188
+
189
+ model.generate_with_adaptive_compute(input_ids, config, num_steps=64, tokenizer=tokenizer, streamer=streamer,
190
+ continuous_compute=False, criterion="kl", exit_threshold=5e-4, cache_kwargs={"lookup_strategy": "latest-m4"})
191
+
192
+ ```
193
+ Your cache strategy should be set to `"latest-m4"` if using adaptive compute.
194
+
195
+ ### KV-cache Sharing
196
+ 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
197
+ the cache argument `lookup_strategy` to include `compress-s16` (where the last number determine the size of the cache).
198
+ ```
199
+ model.generate_with_adaptive_compute(input_ids, config, num_steps=64, tokenizer=tokenizer, streamer=streamer,
200
+ continuous_compute=False, cache_kwargs={"lookup_strategy": "compress-s16"})
201
+ ```
202
+ You can combine this per-token adaptive compute. In that case your lookup strategy should be `latest-m4-compress-s16`.
203
+
204
+ ### Warmstart / Continuous CoT
205
+ At each generation step, the recurrence can be warmstarted with the final state from the previous token by setting `continuous_compute=True`, like so
206
+ ```
207
+ model.generate_with_adaptive_compute(input_ids, config, num_steps=64, tokenizer=tokenizer, streamer=streamer, continuous_compute=True)
208
+ ```
209
+
210
+
211
+
212
+ ## Model Summary
213
+ The model is primarily structured around decoder-only transformer blocks. However these blocks are structured into three functional groups, the __prelude__ \\(P\\),
214
+ 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
215
+ 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
216
+ also contains the prediction head of the model.
217
+
218
+ 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
219
+ probabilities \\(\mathbf{p} \in \mathbb{R}^{n \times |V|}\\).
220
 
221
+ $$\mathbf{e} = P(\mathbf{x})$$
222
 
223
+ $$\mathbf{s}_0 \sim \mathcal{N}(\mathbf{0}, \sigma^2 I_{n\cdot h})$$
 
 
224
 
225
+ $$\mathbf{s}_i = R(\mathbf{e}, \mathbf{s}_{i-1}) \; \textnormal{for} \; i \in \lbrace 1, \dots, r \rbrace$$
226
 
227
+ $$\mathbf{p} = R(\mathbf{s}_r)$$
228
+ 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
229
+ 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\\).
230
+ After finishing all iterations, the coda block processes the last state and produces the probabilities of the next token.
231
 
232
+ Please refer to the paper for benchmark performance on standard benchmarks.
233
+
234
+ ## Limitations
235
+ 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.
236
 
237
+ ## Technical Specifications
238
+ 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.
239
 
240
+ ## License
241
+ This model is released under the [apache-2.0](https://choosealicense.com/licenses/apache-2.0/) licence.
242
 
243
+ ## Citation
244
+ ```
245
+ @article{geiping2025scaling,
246
+ title={Scaling up Test-Time Compute with Latent Reasoning: A Recurrent Depth Approach},
247
+ 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},
248
+ year={2025},
249
+ eprint={2502.},
250
+ archivePrefix={arXiv},
251
+ primaryClass={cs.CL}
252
+ }
253
+ ```
254
+
255
+ ## Contact
256
+ Please, feel free to contact us with any questions, or open an discussion thread on Hugging Face.