Flilax commited on
Commit
3a4a043
Β·
verified Β·
1 Parent(s): 4786222

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +159 -0
README.md CHANGED
@@ -16,3 +16,162 @@ tags:
16
  - hierarchical-radial-transformer
17
  - sub-quadratic
18
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  - hierarchical-radial-transformer
17
  - sub-quadratic
18
  ---
19
+
20
+ # HRT-v7 (Hierarchical Radial Transformer) β€” 148M Base
21
+
22
+ **HRT (Hierarchical Radial Transformer)** is an experimental, tokenizer-free, sub-quadratic neural network architecture designed for ultra-long context modeling (up to **128k context**) with extreme memory efficiency on consumer-grade hardware.
23
+
24
+ This checkpoint is the **Base Pretrained Model (~148M parameters)** trained on ~2.5 billion raw UTF-8 bytes using a multi-stream balanced curriculum of web text, synthetic textbooks, code, and mathematics.
25
+
26
+ ---
27
+
28
+ ## ⚑ Key Highlights
29
+ * **Native Byte-Level Processing:** Operates directly on raw UTF-8 bytes (vocab_size = 257: 0–255 bytes + EOS 256). No BPE/WordPiece tokenizers.
30
+ * **128k Native Context:** Pretrained directly with sequence length T = 131,072 bytes.
31
+ * **Sub-Quadratic Scaling (T β†’ K β†’ K β†’ T):** Replaces dense O(TΒ²) self-attention with radial latent compression (K = 512 outer latents, 16 center latents), yielding linear/sub-quadratic compute and memory footprint.
32
+ * **Deep Equilibrium Core (JFB):** Features an implicit reasoning core trained with **Jacobi-Free Backpropagation (JFB)** for constant O(1) backpropagation memory overhead.
33
+ * **Hardware-Aware Quantization:** Built-in TurboQuantizer using random orthogonal QR rotation matrices to suppress outliers during INT8 KV caching.
34
+
35
+ ---
36
+
37
+ ## πŸ“Š Training Details & Hyperparameters
38
+
39
+ The model was pretrained on NVIDIA Blackwell / Hopper hardware in bfloat16 mixed precision.
40
+
41
+ ### Model Configuration (ModelConfig)
42
+ | Hyperparameter | Value | Description |
43
+ | :--- | :--- | :--- |
44
+ | **Parameters** | ~148M | Active trainable weights |
45
+ | **Context Length (seq_len)** | **131,072** (128k bytes) | Native training window length |
46
+ | **Vocab Size** | 257 | 256 bytes + 1 EOS token |
47
+ | **Model Dimension (d_model)** | 768 | Hidden representation size |
48
+ | **FFN Dimension (d_ff)** | 3072 | SwiGLU projection dimension |
49
+ | **Outer Latents (K)** | 512 | Compressed outer working memory |
50
+ | **Center Latents** | 16 | Deep reasoning core latents |
51
+ | **Routing Top-K** | 64 | Sparse attention routing threshold |
52
+ | **Attention Heads** | 12 | Outer, Inner, and Latent heads |
53
+ | **Outer / Inner Cycles** | 6 / 8 | Hierarchical gather/reasoning loops |
54
+ | **Local Conv Kernel** | 7 | Causal dual-dilated local token mixer |
55
+ | **Positional Bias** | HARP | Hierarchical Adaptive Relational Positioning |
56
+ | **Implicit Core** | Enabled | 3 internalization steps with JFB |
57
+ | **Auxiliary Losses** | Enabled | SVD-based low-rank compaction loss + JFB loss |
58
+
59
+ ### Pretraining Optimization & Setup
60
+ * **Optimizer:** AdamW (beta1 = 0.9, beta2 = 0.95, weight_decay = 0.01)
61
+ * **Precision:** Native bfloat16 with Gradient Checkpointing
62
+ * **Effective Batch Size:** 8 sequences Γ— 131,072 = **1,048,576 bytes per step** (Batch Size 4 Γ— Gradient Accumulation 2)
63
+ * **Gradient Clipping:** 1.0
64
+ * **Learning Rate Schedule:** Cosine Annealing cooldown down to LR_min = 1e-5
65
+
66
+ ---
67
+
68
+ ## Dataset Mixture
69
+
70
+ The model was trained on a dynamically balanced 5-stream multiplexer with streaming packing:
71
+
72
+ ```
73
+ FastMultiStream Distribution:
74
+ 25% β€” HuggingFaceTB/smollm-corpus (Cosmopedia v2 - synthetic textbooks & stories)
75
+ 25% β€” HuggingFaceFW/fineweb (sample-10BT - general web crawl)
76
+ 20% β€” HuggingFaceFW/fineweb-edu (sample-10BT - educational & academic web text)
77
+ 20% β€” bigcode/starcoderdata (Python subsets - structured code & AST logic)
78
+ 10% β€” HuggingFaceTB/finemath (finemath-3plus - math reasoning & LaTeX)
79
+ ```
80
+
81
+ Documents were packed into continuous 131,072-byte buffers with unique segment IDs (segment_ids) and EOS separators to ensure segment-aware causal attention boundaries.
82
+
83
+ ---
84
+
85
+ ## Quickstart / How to Use
86
+
87
+ ### 1. Installation
88
+ Clone the repository and install the HRT package:
89
+
90
+ ```bash
91
+ git clone https://github.com/5bridge/HRT.git
92
+ cd HRT
93
+ pip install -e .
94
+ ```
95
+
96
+ ### 2. Running Inference (Next-Byte Completion)
97
+ Because this is a **Base Pretrained Model** (not an instruction/chat tuned model), it functions as an autoregressive text/code completion engine.
98
+
99
+ ```python
100
+ import torch
101
+ import torch.nn.functional as F
102
+ from hrt import ModelConfig, HierarchicalRadialTransformerV7
103
+
104
+ device = "cuda" if torch.cuda.is_available() else "cpu"
105
+
106
+ # 1. Initialize Configuration matching training
107
+ cfg = ModelConfig(
108
+ d_model=768,
109
+ d_ff=3072,
110
+ n_outer_latents=512,
111
+ n_outer_cycles=6,
112
+ n_inner_cycles=8,
113
+ n_center_latents=16,
114
+ routing_k=64,
115
+ n_outer_heads=12,
116
+ n_inner_heads=12,
117
+ n_latent_heads=12,
118
+ vocab_size=257,
119
+ max_seq_len=131072,
120
+ use_qk_norm=True,
121
+ use_rezero=True,
122
+ use_compaction=True,
123
+ use_internalization=True,
124
+ use_jfb=True,
125
+ use_q_cache=True,
126
+ )
127
+
128
+ # 2. Load model & weights
129
+ model = HierarchicalRadialTransformerV7(cfg).to(device)
130
+ weights = torch.load("hrt_v7_148m_weights.pt", map_location=device)
131
+ model.load_state_dict(weights["model"] if "model" in weights else weights)
132
+ model.eval()
133
+
134
+ # 3. Autoregressive Byte-level Generation
135
+ def generate(prompt: str, max_new_bytes: int = 120, temp: float = 0.5, top_k: int = 5):
136
+ prompt_bytes = list(prompt.encode("utf-8"))
137
+ prompt_ids = torch.tensor([prompt_bytes], dtype=torch.long, device=device)
138
+
139
+ with torch.no_grad():
140
+ prompt_emb = model.tok_emb(prompt_ids)
141
+ logits, cache = model._init_generation_cache(prompt_emb)
142
+ out_bytes = list(prompt_bytes)
143
+
144
+ for _ in range(max_new_bytes):
145
+ l = logits / max(temp, 1e-5)
146
+ if top_k > 0:
147
+ v, _ = torch.topk(l, min(top_k, l.size(-1)))
148
+ l[l < v[:, [-1]]] = float("-inf")
149
+
150
+ nxt = torch.multinomial(F.softmax(l, dim=-1), num_samples=1)
151
+ nxt_id = nxt.item()
152
+ if nxt_id == 256: # EOS
153
+ break
154
+
155
+ out_bytes.append(nxt_id)
156
+ nxt_emb = model.tok_emb(nxt)
157
+ logits = model.step_generation(nxt_emb, cache)
158
+
159
+ return bytes(out_bytes).decode("utf-8", errors="replace")
160
+
161
+ # Test completion
162
+ print(generate("def", max_new_bytes=100))
163
+ ```
164
+
165
+ ---
166
+
167
+ ## ⚠️ Limitations & Intended Use
168
+ * **Base Model Nature:** This model has not undergone Supervised Fine-Tuning (SFT) or RLHF/DPO. It will not behave as a conversational assistant by default and may loop if prompted with chat-like templates without a stopping token.
169
+ * **Proof-of-Concept Scale:** Trained on ~2.5B bytes as a compute-limited validation run. It exhibits strong syntactic comprehension (LaTeX, Python, Markdown, JSON AST schemas), but requires further scale for complex factual recall and deep semantic reasoning.
170
+ * **Information Bottleneck:** The T to K compression naturally trades off lossless, needle-in-a-haystack memorization for bounded sub-quadratic memory footprint.
171
+
172
+ ---
173
+
174
+ ## License
175
+ This model and its code are released under the **Apache 2.0 License**.
176
+
177
+ https://github.com/5bridge/HRT