Update README.md
Browse files
README.md
CHANGED
|
@@ -1,60 +1,126 @@
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
|
|
|
|
|
|
| 3 |
tags:
|
| 4 |
- text-generation
|
| 5 |
- causal-lm
|
| 6 |
-
- cosmicfish
|
| 7 |
-
- hrm
|
| 8 |
- adaptive-reasoning
|
|
|
|
|
|
|
| 9 |
- custom-architecture
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
---
|
| 13 |
|
| 14 |
# CosmicFish-HRM
|
| 15 |
|
| 16 |
-
CosmicFish-HRM
|
| 17 |
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
## Architecture
|
| 21 |
|
|
|
|
|
|
|
| 22 |
```
|
| 23 |
Input Blocks (Transformer) -> HRM Core (H + L levels, variable steps) -> Output Blocks (Transformer) -> LM Head
|
| 24 |
```
|
| 25 |
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|---|---|
|
| 28 |
-
|
|
| 29 |
| Embedding dimension | 448 |
|
| 30 |
| Vocabulary size | 50,304 |
|
| 31 |
| Context length | 512 |
|
| 32 |
-
| Input layers | 6 |
|
| 33 |
-
| Output layers | 6 |
|
| 34 |
-
| Attention heads | 8 (4 KV, GQA) |
|
| 35 |
| HRM H-layers | 4 |
|
| 36 |
| HRM L-layers | 4 |
|
| 37 |
| Max HRM steps | 16 |
|
|
|
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
## Usage
|
| 47 |
|
| 48 |
-
This model uses a custom architecture
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
```python
|
| 51 |
import torch
|
| 52 |
import json
|
| 53 |
import tiktoken
|
| 54 |
from safetensors.torch import load_file
|
|
|
|
| 55 |
from modeling_hrm_cosmicfish import HRMCosmicFish, HRMCosmicFishConfig
|
| 56 |
|
| 57 |
-
|
|
|
|
|
|
|
| 58 |
cfg = json.load(f)
|
| 59 |
|
| 60 |
config = HRMCosmicFishConfig(
|
|
@@ -73,38 +139,22 @@ config = HRMCosmicFishConfig(
|
|
| 73 |
dropout=0.0,
|
| 74 |
)
|
| 75 |
|
| 76 |
-
state_dict = load_file("model.safetensors")
|
| 77 |
model = HRMCosmicFish(config)
|
| 78 |
model.load_state_dict(state_dict)
|
| 79 |
model.eval()
|
| 80 |
|
| 81 |
tokenizer = tiktoken.get_encoding("gpt2")
|
| 82 |
-
|
| 83 |
prompt = "Artificial intelligence is"
|
| 84 |
tokens = tokenizer.encode(prompt)
|
| 85 |
idx = torch.tensor(tokens, dtype=torch.long).unsqueeze(0)
|
| 86 |
|
| 87 |
with torch.no_grad():
|
| 88 |
-
output = model.generate(idx, max_new_tokens=
|
| 89 |
|
| 90 |
print(tokenizer.decode(output[0].tolist()))
|
| 91 |
```
|
| 92 |
|
| 93 |
-
## Training
|
| 94 |
-
|
| 95 |
-
CosmicFish-HRM was trained on the 10B-token CosmicSet dataset spanning web text, Wikipedia, code, mathematics, and research papers. Training used cosine LR decay with linear warmup, bfloat16 mixed precision, and gradient clipping.
|
| 96 |
-
|
| 97 |
-
## Citation
|
| 98 |
-
|
| 99 |
-
```bibtex
|
| 100 |
-
@misc{cosmicfish-hrm,
|
| 101 |
-
title={CosmicFish-HRM: Adaptive Reasoning via Hierarchical Recurrent Mechanisms in Compact Language Models},
|
| 102 |
-
author={Venkat Akhil Lakkapragada},
|
| 103 |
-
year={2026},
|
| 104 |
-
howpublished={\url{https://huggingface.co/MistyozAI/CosmicFish-HRM}}
|
| 105 |
-
}
|
| 106 |
-
```
|
| 107 |
-
|
| 108 |
---
|
| 109 |
|
| 110 |
-
Mistyoz AI, Hyderabad
|
|
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
tags:
|
| 6 |
- text-generation
|
| 7 |
- causal-lm
|
|
|
|
|
|
|
| 8 |
- adaptive-reasoning
|
| 9 |
+
- hierarchical-reasoning
|
| 10 |
+
- hrm
|
| 11 |
- custom-architecture
|
| 12 |
+
- compact-model
|
| 13 |
+
datasets:
|
| 14 |
+
- HuggingFaceFW/fineweb
|
| 15 |
+
- wikipedia
|
| 16 |
+
- openwebtext
|
| 17 |
+
- c4
|
| 18 |
+
arxiv: 2605.28919
|
| 19 |
---
|
| 20 |
|
| 21 |
# CosmicFish-HRM
|
| 22 |
|
| 23 |
+
**Paper:** [CosmicFish-HRM: Adaptive Reasoning via Hierarchical Recurrent Mechanisms in Compact Language Models](https://arxiv.org/abs/2605.28919)
|
| 24 |
|
| 25 |
+
**GitHub:** [MistyozAI/CosmicFish-HRM](https://github.com/MistyozAI/CosmicFish-HRM)
|
| 26 |
+
|
| 27 |
+
CosmicFish-HRM is a compact 82.77M parameter causal language model built around a Hierarchical Reasoning Module (HRM) that dynamically allocates reasoning compute during inference. Rather than applying a fixed number of forward-pass layers to every input, the model iterates through high-level and low-level reasoning cycles and uses a learned halting head to decide when to stop. Harder inputs trigger deeper reasoning trajectories while simpler ones halt early.
|
| 28 |
+
|
| 29 |
+
Built at Mistyoz AI, Hyderabad.
|
| 30 |
+
|
| 31 |
+
---
|
| 32 |
|
| 33 |
## Architecture
|
| 34 |
|
| 35 |
+

|
| 36 |
+
|
| 37 |
```
|
| 38 |
Input Blocks (Transformer) -> HRM Core (H + L levels, variable steps) -> Output Blocks (Transformer) -> LM Head
|
| 39 |
```
|
| 40 |
|
| 41 |
+
The HRM core maintains two interacting recurrent states operating at different abstraction levels. The high-level module captures slower, more abstract reasoning while the low-level module handles finer-grained local computation. After each reasoning step a lightweight halting head decides whether to continue or stop, conditioned on the mean-pooled high-level state.
|
| 42 |
+
|
| 43 |
+
**Key components:**
|
| 44 |
+
|
| 45 |
+
- Grouped-Query Attention (GQA) with 8 query heads and 4 KV heads
|
| 46 |
+
- Rotary Positional Embeddings (RoPE)
|
| 47 |
+
- SwiGLU feedforward layers
|
| 48 |
+
- RMSNorm (pre-norm for I/O blocks, post-norm inside HRM)
|
| 49 |
+
- Learned halt/continue Q-head controlling per-input reasoning depth
|
| 50 |
+
- Step penalty in the training loss encouraging efficient halting
|
| 51 |
+
|
| 52 |
+
## Model Specs
|
| 53 |
+
|
| 54 |
+
| Parameter | Value |
|
| 55 |
|---|---|
|
| 56 |
+
| Total parameters | 82.77M |
|
| 57 |
| Embedding dimension | 448 |
|
| 58 |
| Vocabulary size | 50,304 |
|
| 59 |
| Context length | 512 |
|
| 60 |
+
| Input transformer layers | 6 |
|
| 61 |
+
| Output transformer layers | 6 |
|
|
|
|
| 62 |
| HRM H-layers | 4 |
|
| 63 |
| HRM L-layers | 4 |
|
| 64 |
| Max HRM steps | 16 |
|
| 65 |
+
| Attention heads | 8 (4 KV, GQA) |
|
| 66 |
|
| 67 |
+
## Evaluation
|
| 68 |
+
|
| 69 |
+
Zero-shot benchmark results:
|
| 70 |
+
|
| 71 |
+
| Model | HellaSwag | PIQA | WinoGrande |
|
| 72 |
+
|---|---|---|---|
|
| 73 |
+
| CosmicFish-HRM (82M) | 26.2 | 58.1 | 50.7 |
|
| 74 |
+
| GPT-2 Small (117M) | 29.7 | 62.5 | 50.7 |
|
| 75 |
+
| OPT-125M | 30.6 | 62.6 | 52.9 |
|
| 76 |
+
| Pythia-160M | 29.4 | 62.1 | 52.8 |
|
| 77 |
+
|
| 78 |
+
At compact scale a portion of the parameter budget is allocated to the HRM reasoning infrastructure rather than raw language modeling capacity, which accounts for the gap versus fixed-depth baselines of similar size. The paper argues this tradeoff becomes more favorable as model scale increases.
|
| 79 |
+
|
| 80 |
+
## Adaptive Reasoning Behavior
|
| 81 |
+
|
| 82 |
+
The primary contribution of CosmicFish-HRM is not benchmark accuracy but adaptive compute allocation. The model uses different numbers of reasoning steps depending on input complexity:
|
| 83 |
+
|
| 84 |
+
| Prompt | Mean HRM Steps |
|
| 85 |
+
|---|---|
|
| 86 |
+
| "The capital of France is" | 2.78 |
|
| 87 |
+
| "Photosynthesis is the process by which plants" | 4.77 |
|
| 88 |
+
| "If all roses are flowers and some flowers fade quickly..." | 7.03 |
|
| 89 |
+
| "A bat and a ball cost $1.10 in total..." | 8.40 |
|
| 90 |
+
|
| 91 |
+
Average steps across benchmarks stay well below the 16-step maximum, with high variance across samples, confirming the halting mechanism is input-sensitive rather than collapsing to a fixed depth.
|
| 92 |
+
|
| 93 |
+
| Benchmark | Mean Steps | Std Dev |
|
| 94 |
+
|---|---|---|
|
| 95 |
+
| HellaSwag | 3.03 | 6.26 |
|
| 96 |
+
| PIQA | 1.87 | 5.13 |
|
| 97 |
+
| WinoGrande | 0.95 | 3.78 |
|
| 98 |
+
| Overall | 2.68 | 5.95 |
|
| 99 |
|
| 100 |
## Usage
|
| 101 |
|
| 102 |
+
This model uses a custom architecture. The model code is included in this repo as `modeling_hrm_cosmicfish.py`.
|
| 103 |
+
|
| 104 |
+
**Standalone chat script (downloads automatically):**
|
| 105 |
+
|
| 106 |
+
```bash
|
| 107 |
+
pip install torch safetensors huggingface-hub transformers termcolor
|
| 108 |
+
python chat_hf.py
|
| 109 |
+
```
|
| 110 |
+
|
| 111 |
+
**Load manually:**
|
| 112 |
|
| 113 |
```python
|
| 114 |
import torch
|
| 115 |
import json
|
| 116 |
import tiktoken
|
| 117 |
from safetensors.torch import load_file
|
| 118 |
+
from huggingface_hub import snapshot_download
|
| 119 |
from modeling_hrm_cosmicfish import HRMCosmicFish, HRMCosmicFishConfig
|
| 120 |
|
| 121 |
+
cache_dir = snapshot_download("MistyozAI/CosmicFish-HRM")
|
| 122 |
+
|
| 123 |
+
with open(f"{cache_dir}/config.json") as f:
|
| 124 |
cfg = json.load(f)
|
| 125 |
|
| 126 |
config = HRMCosmicFishConfig(
|
|
|
|
| 139 |
dropout=0.0,
|
| 140 |
)
|
| 141 |
|
| 142 |
+
state_dict = load_file(f"{cache_dir}/model.safetensors")
|
| 143 |
model = HRMCosmicFish(config)
|
| 144 |
model.load_state_dict(state_dict)
|
| 145 |
model.eval()
|
| 146 |
|
| 147 |
tokenizer = tiktoken.get_encoding("gpt2")
|
|
|
|
| 148 |
prompt = "Artificial intelligence is"
|
| 149 |
tokens = tokenizer.encode(prompt)
|
| 150 |
idx = torch.tensor(tokens, dtype=torch.long).unsqueeze(0)
|
| 151 |
|
| 152 |
with torch.no_grad():
|
| 153 |
+
output = model.generate(idx, max_new_tokens=100, temperature=0.7, top_k=40)
|
| 154 |
|
| 155 |
print(tokenizer.decode(output[0].tolist()))
|
| 156 |
```
|
| 157 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
---
|
| 159 |
|
| 160 |
+
Mistyoz AI, Hyderabad
|