dreamwar commited on
Commit
9a9b9a8
Β·
verified Β·
1 Parent(s): 32ee9e7

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +193 -125
README.md CHANGED
@@ -1,199 +1,267 @@
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
+ # HRM-Text1: Hierarchical Reasoning Model for Text Generation
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
+ [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1c4exU-zMt4SuT1kRlwQQXlLPaiazEDCf?usp=sharing)
4
 
5
+ A large-scale transformer model with Hierarchical Reasoning Module (HRM) architecture trained on multiple high-quality text datasets. This model features adaptive computation with pondering mechanisms for improved text generation quality.
 
 
6
 
7
+ ## Model Architecture
8
 
9
+ **HRM-Text1** implements a novel hierarchical reasoning architecture with the following key components:
10
 
11
+ - **Model Size**: 99M parameters (Large variant)
12
+ - **Architecture**: Hierarchical Reasoning Module with dual-stream processing
13
+ - **Embeddings**: 1024 dimensions
14
+ - **Attention Heads**: 16 heads
15
+ - **Feed-Forward**: 4096 dimensions
16
+ - **Context Length**: 512 tokens
17
+ - **Vocabulary**: 32,128 tokens (T5 tokenizer)
18
 
19
+ ### Key Features
20
 
21
+ - **Adaptive Computation**: Pondering mechanism with halt probabilities
22
+ - **Dual-Stream Processing**: High-level (H) and Low-level (L) reasoning modules
23
+ - **SwiGLU Activation**: Enhanced non-linear transformations
24
+ - **RMSNorm**: Improved normalization for stable training
25
+ - **Mixed Precision**: BF16 training support for NVIDIA Ampere+ GPUs
26
 
27
+ ## Training Configuration
28
 
29
+ ### Datasets
30
 
31
+ The model supports training on multiple high-quality datasets:
32
 
33
+ - **C4 Multilingual**: Common Crawl web text (multilingual)
34
+ - **OpenWebText**: English web content dataset
35
+ - **The Pile**: Diverse text from EleutherAI
36
+ - **SlimPajama**: 627B token dataset (filtered variants available)
37
+ - **FineWeb**: High-quality web content
38
+ - **Spanish**: Spanish language subset from C4
39
 
40
+ ### Mixed Dataset Training
41
 
42
+ The training script supports custom dataset mixing ratios:
43
 
44
+ ```python
45
+ CUSTOM_MIX_RATIOS = {
46
+ "high_quality": {
47
+ "slimpajama_en": 0.5, # 50% SlimPajama English
48
+ "pile": 0.3, # 30% The Pile
49
+ "openwebtext": 0.2 # 20% OpenWebText
50
+ }
51
+ }
52
+ ```
53
 
54
+ ### Training Hyperparameters
55
 
56
+ - **Learning Rate**: 3e-4 (max) β†’ 1e-5 (min) with cosine annealing
57
+ - **Batch Size**: 40 (with gradient accumulation steps: 2)
58
+ - **Weight Decay**: 0.05
59
+ - **Optimizer**: AdamW with β₁=0.9, Ξ²β‚‚=0.95
60
+ - **Epochs**: 2
61
+ - **Mixed Precision**: Enabled for compatible hardware
62
 
63
+ ## Model Components
64
 
65
+ ### HRMBlock Architecture
66
 
67
+ ```python
68
+ class HRMBlock(nn.Module):
69
+ def __init__(self, n_embd, n_head, d_ff, dropout=0.1):
70
+ super().__init__()
71
+ self.norm1 = RMSNorm(n_embd)
72
+ self.attn = nn.MultiheadAttention(n_embd, n_head, dropout=dropout, batch_first=True)
73
+ self.norm2 = RMSNorm(n_embd)
74
+ self.mlp = SwiGLUMuchPelu(n_embd, d_ff, dropout)
75
+ self.dropout = nn.Dropout(dropout)
76
+ ```
77
 
78
+ ### Pondering Mechanism
79
 
80
+ The model implements adaptive computation through a halt probability mechanism:
81
 
82
+ - **Max Steps**: 8 reasoning steps
83
+ - **Halt Bias**: -2.2 (initial)
84
+ - **Ponder Loss Weight**: 1e-2
85
 
86
+ ## Usage
87
 
88
+ ### Quick Start
89
 
90
+ ```python
91
+ from transformers import T5Tokenizer
92
+ from modeling_hrm_text1 import HRMText1
93
 
94
+ # Load model and tokenizer
95
+ model = HRMText1.from_pretrained("dreamwar/HRM-Text1-{DATASET}-large")
96
+ tokenizer = T5Tokenizer.from_pretrained("t5-small")
97
 
98
+ # Generate text
99
+ prompt = "The future of artificial intelligence"
100
+ inputs = tokenizer(prompt, return_tensors="pt")
101
+ outputs = model.generate(**inputs, max_new_tokens=50, temperature=0.7)
102
+ text = tokenizer.decode(outputs[0], skip_special_tokens=True)
103
+ ```
104
 
105
+ ### Training from Scratch
106
 
107
+ **Option 1: Google Colab (Recommended)**
108
+ ```bash
109
+ # Open the Colab notebook
110
+ https://colab.research.google.com/drive/1c4exU-zMt4SuT1kRlwQQXlLPaiazEDCf?usp=sharing
111
+ ```
112
 
113
+ **Option 2: Local Training**
114
+ ```bash
115
+ # Set environment variables
116
+ export HRM_OUTPUT_BASE="/path/to/output"
117
+ export HF_TOKEN="your_huggingface_token"
118
 
119
+ # Run training
120
+ python hrm_llm_training_c4_b.py
121
+ ```
122
 
123
+ ### Configuration Options
124
 
125
+ The training script supports extensive configuration:
126
 
127
+ ```python
128
+ # Dataset selection
129
+ ACTIVE_DATASET = "mixed" # Options: "c4", "openwebtext", "pile", "spanish", "mixed"
130
 
131
+ # Dataset subset percentage
132
+ DATASET_SUBSET_PERCENT = 5 # 1-100%
133
 
134
+ # Custom output path
135
+ CUSTOM_BASE_PATH = "/your/custom/path"
136
 
137
+ # Model parameters (large variant)
138
+ MODEL_PARAMS = {
139
+ "n_embd": 1024,
140
+ "n_head": 16,
141
+ "d_ff": 4096,
142
+ "dropout": 0.1,
143
+ "halt_max_steps": 8,
144
+ "ponder_loss_weight": 1e-2,
145
+ "halt_bias_init": -2.2
146
+ }
147
+ ```
148
 
149
+ ## Features
150
 
151
+ ### Multi-Dataset Support
152
 
153
+ - **Individual Datasets**: Train on single datasets (C4, OpenWebText, Pile, etc.)
154
+ - **Mixed Training**: Combine multiple datasets with custom ratios
155
+ - **Language Filtering**: Optional language detection and filtering
156
+ - **Streaming**: Memory-efficient streaming for large datasets
157
 
158
+ ### Training Optimizations
159
 
160
+ - **Checkpointing**: Automatic checkpoint saving and resuming
161
+ - **Early Stopping**: Validation-based early stopping (patience: 2)
162
+ - **Gradient Clipping**: Norm clipping at 1.0
163
+ - **Mixed Precision**: BF16 for memory efficiency
164
+ - **Model Compilation**: PyTorch 2.0 compilation support
165
 
166
+ ### Hardware Support
167
 
168
+ - **CUDA**: GPU acceleration with TF32 precision on Ampere+
169
+ - **Multi-Platform**: Linux, macOS, Windows support
170
+ - **Google Colab**: Full compatibility with free and pro tiers
171
+ - **Memory Management**: Automatic DataLoader worker detection
172
 
173
+ ## Output Structure
174
 
175
+ ```
176
+ HRM_Models/
177
+ β”œβ”€β”€ hrm_text1_{dataset}_output-large/
178
+ β”‚ β”œβ”€β”€ config.json
179
+ β”‚ β”œβ”€β”€ pytorch_model.bin
180
+ β”‚ β”œβ”€β”€ tokenizer.json
181
+ β”‚ β”œβ”€β”€ best_model.bin
182
+ β”‚ └── checkpoint.pth
183
+ ```
184
 
185
+ ## Environment Setup
186
 
187
+ ### Quick Start with Google Colab
188
 
189
+ Click the Colab badge above to get started immediately with a pre-configured environment including all dependencies.
190
 
191
+ ### Local Installation
192
 
193
+ ```bash
194
+ pip install torch transformers datasets tqdm huggingface_hub
195
+ pip install langdetect # Optional: for language filtering
196
+ ```
197
 
198
+ ### Environment Variables
199
 
200
+ ```bash
201
+ # Required for model upload
202
+ export HF_TOKEN="your_huggingface_token"
203
 
204
+ # Optional: custom output path
205
+ export HRM_OUTPUT_BASE="/your/custom/path"
206
+ ```
207
 
208
+ ## Model Variants
209
 
210
+ The training script produces several model variants:
211
 
212
+ - **HRM-Text1-C4-large**: Trained on C4 multilingual
213
+ - **HRM-Text1-Mixed-large**: Trained on balanced dataset mixture
214
+ - **HRM-Text1-Spanish-large**: Spanish language variant
215
+ - **HRM-Text1-Custom-{name}-large**: Custom mixture variants
216
 
217
+ ## Performance
218
 
219
+ ### Model Specifications
220
 
221
+ - **Parameters**: ~1B trainable parameters
222
+ - **Memory Usage**: ~4-6GB VRAM for inference
223
+ - **Training Time**: Varies by dataset size and hardware
224
+ - **Context Length**: 512 tokens
 
225
 
226
+ ### Generation Quality
227
 
228
+ The model implements sophisticated reasoning through:
229
 
230
+ - Hierarchical processing of information
231
+ - Adaptive computation based on input complexity
232
+ - Pondering mechanism for quality-vs-speed trade-offs
233
 
234
+ ## License
235
 
236
+ This model and training code are released under the Apache 2.0 License.
237
 
238
+ ## Citation
239
 
240
+ ```bibtex
241
+ @misc{hrm-text1-2024,
242
+ title={HRM-Text1: Hierarchical Reasoning Model for Text Generation},
243
+ author={DreamWar},
244
+ year={2024},
245
+ url={https://huggingface.co/dreamwar/HRM-Text1}
246
+ }
247
+ ```
248
 
249
+ ## Troubleshooting
250
 
251
+ ### Common Issues
252
 
253
+ 1. **Memory Errors**: Reduce batch size or enable gradient checkpointing
254
+ 2. **Dataset Loading**: Ensure stable internet connection for streaming
255
+ 3. **CUDA Errors**: Update PyTorch and CUDA drivers
256
+ 4. **Language Detection**: Install `langdetect` for language filtering
257
 
258
+ ### Support
259
 
260
+ For issues and questions:
261
+ - Check the training script comments for detailed configuration
262
+ - Review error messages for specific guidance
263
+ - Ensure proper environment setup and dependencies
264
 
265
+ ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
266
 
267
+ *This model was trained using the HRM (Hierarchical Reasoning Module) architecture with adaptive computation for improved text generation capabilities.*