Update README.md
Browse files
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 |
-
|
| 31 |
|
| 32 |
-
-
|
| 33 |
-
- **Paper [optional]:** [More Information Needed]
|
| 34 |
-
- **Demo [optional]:** [More Information Needed]
|
| 35 |
|
| 36 |
-
##
|
| 37 |
|
| 38 |
-
|
| 39 |
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
-
|
| 43 |
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
-
|
| 47 |
|
| 48 |
-
|
| 49 |
|
| 50 |
-
|
| 51 |
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
-
|
| 55 |
|
| 56 |
-
|
| 57 |
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
| 125 |
-
|
| 126 |
|
| 127 |
-
|
| 128 |
|
| 129 |
-
|
| 130 |
|
| 131 |
-
|
|
|
|
|
|
|
|
|
|
| 132 |
|
|
|
|
| 133 |
|
|
|
|
|
|
|
|
|
|
| 134 |
|
| 135 |
-
|
|
|
|
|
|
|
| 136 |
|
| 137 |
-
|
| 138 |
|
| 139 |
-
|
| 140 |
|
| 141 |
-
|
|
|
|
|
|
|
|
|
|
| 142 |
|
| 143 |
-
|
| 144 |
|
| 145 |
-
|
| 146 |
|
| 147 |
-
- **
|
| 148 |
-
- **
|
| 149 |
-
- **
|
| 150 |
-
- **
|
| 151 |
-
- **Carbon Emitted:** [More Information Needed]
|
| 152 |
|
| 153 |
-
|
| 154 |
|
| 155 |
-
|
| 156 |
|
| 157 |
-
|
|
|
|
|
|
|
| 158 |
|
| 159 |
-
|
| 160 |
|
| 161 |
-
|
| 162 |
|
| 163 |
-
|
| 164 |
|
| 165 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
|
| 167 |
-
|
| 168 |
|
| 169 |
-
|
| 170 |
|
| 171 |
-
|
|
|
|
|
|
|
|
|
|
| 172 |
|
| 173 |
-
|
| 174 |
|
| 175 |
-
|
|
|
|
|
|
|
|
|
|
| 176 |
|
| 177 |
-
|
| 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 |
-
|
|
|
|
| 1 |
+
# HRM-Text1: Hierarchical Reasoning Model for Text Generation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
[](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.*
|