Transformers
PyTorch
English
language-model
graph-attention
adaptive-depth
temporal-decay
efficient-llm
Eval Results (legacy)
Instructions to use vigneshwar234/TemporalMesh-Transformer with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use vigneshwar234/TemporalMesh-Transformer with Transformers:
# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("vigneshwar234/TemporalMesh-Transformer", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Update model card: TMT v3 comprehensive documentation
Browse files
README.md
CHANGED
|
@@ -1,418 +1,186 @@
|
|
| 1 |
---
|
| 2 |
-
language:
|
| 3 |
-
- en
|
| 4 |
license: mit
|
| 5 |
-
library_name: pytorch
|
| 6 |
tags:
|
| 7 |
-
-
|
| 8 |
-
-
|
| 9 |
-
-
|
| 10 |
-
-
|
| 11 |
-
-
|
| 12 |
-
-
|
| 13 |
-
-
|
| 14 |
-
- sparse-attention
|
| 15 |
-
- adaptive-computation
|
| 16 |
-
- dynamic-graph
|
| 17 |
-
- early-exit
|
| 18 |
-
- temporal-decay
|
| 19 |
-
- mesh-attention
|
| 20 |
-
- language-model
|
| 21 |
-
- causal-lm
|
| 22 |
-
- preprint
|
| 23 |
-
- arxiv
|
| 24 |
-
- wikitext
|
| 25 |
-
- nlp
|
| 26 |
-
- attention
|
| 27 |
datasets:
|
| 28 |
-
- wikitext
|
| 29 |
-
-
|
| 30 |
-
- vigneshwar234/TMT-Benchmarks
|
| 31 |
metrics:
|
| 32 |
-
- perplexity
|
| 33 |
-
pipeline_tag: text-generation
|
| 34 |
model-index:
|
| 35 |
-
- name: TemporalMesh-Transformer
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
value: 42.1
|
| 56 |
-
name: Perplexity — Vanilla Transformer Baseline
|
| 57 |
-
- type: perplexity
|
| 58 |
-
value: 37.8
|
| 59 |
-
name: Perplexity — Mesh Attention Only
|
| 60 |
-
- type: perplexity
|
| 61 |
-
value: 39.6
|
| 62 |
-
name: Perplexity — Adaptive Exit Only
|
| 63 |
-
- type: perplexity
|
| 64 |
-
value: 29.4
|
| 65 |
-
name: Perplexity — Full TMT (all 3 innovations)
|
| 66 |
---
|
| 67 |
|
| 68 |
-
#
|
| 69 |
|
| 70 |
-
|
| 71 |
-
[
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
[](https://github.com/vignesh2027/TemporalMesh-Transformer/actions)
|
| 76 |
-
[](https://python.org)
|
| 77 |
-
[](https://pytorch.org)
|
| 78 |
-
|
| 79 |
-
> 📄 **[TemporalMesh Transformer: Dynamic Graph Attention with Temporal Decay and Adaptive Depth Routing](https://zenodo.org/records/20287390)**
|
| 80 |
-
> **Author:** Vigneshwar LK · **DOI:** [10.5281/zenodo.20287197](https://doi.org/10.5281/zenodo.20287197) · **Published:** May 2026 · **Preprint (Open Access)**
|
| 81 |
-
|
| 82 |
-
---
|
| 83 |
-
|
| 84 |
-
## 🔥 Key Results
|
| 85 |
-
|
| 86 |
-
**Full TMT achieves 30.2% lower perplexity than vanilla transformer while using only 48% of the compute — a 2.1× efficiency gain.**
|
| 87 |
-
|
| 88 |
-
| Configuration | Mesh | Decay | Exit | Val PPL ↓ | Avg Layers | Rel Compute ↓ | Params |
|
| 89 |
-
|---|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
|
| 90 |
-
| Vanilla Transformer | ✗ | ✗ | ✗ | 42.1 | 12.0 | 1.00× | 120M |
|
| 91 |
-
| Mesh Attention Only | ✓ | ✗ | ✗ | 37.8 | 12.0 | 0.62× | 120M |
|
| 92 |
-
| Temporal Decay Only | ✗ | ✓ | ✗ | 40.3 | 12.0 | 0.98× | 120M |
|
| 93 |
-
| Adaptive Exit Only | ✗ | ✗ | ✓ | 39.6 | 5.8 | 0.51× | 120M |
|
| 94 |
-
| Mesh + Decay | ✓ | ✓ | ✗ | 34.2 | 12.0 | 0.61× | 120M |
|
| 95 |
-
| Mesh + Exit | ✓ | ✗ | ✓ | 35.1 | 5.7 | 0.50× | 120M |
|
| 96 |
-
| Decay + Exit | ✗ | ✓ | ✓ | 37.0 | 5.9 | 0.50× | 120M |
|
| 97 |
-
| **Full TMT (all 3)** | ✓ | ✓ | ✓ | **29.4** | **5.5** | **0.48×** | 120M |
|
| 98 |
-
|
| 99 |
-
> **Full TMT achieves PPL 29.4 vs Vanilla 42.1 — a 30.2% perplexity reduction while using only 48% of the compute (2.1× efficiency gain).**
|
| 100 |
-
|
| 101 |
-
The results show clear synergy: each innovation provides independent benefit, dual combinations improve further, and combining all three yields disproportionate gains that exceed what ablations predict from linear composition.
|
| 102 |
|
| 103 |
---
|
| 104 |
|
| 105 |
-
##
|
| 106 |
|
| 107 |
-
|
| 108 |
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
|
| 116 |
-
|---|:---:|:---:|:---:|:---:|:---:|
|
| 117 |
-
| Dynamic graph topology | ✗ | Partial | ✗ | ✗ | **✓** |
|
| 118 |
-
| Per-token adaptive depth | ✗ | ✗ | ✓ | ✗ | **✓** |
|
| 119 |
-
| Semantic temporal decay | ✗ | ✗ | ✗ | ✗ | **✓** |
|
| 120 |
-
| Persistent memory anchors | ✗ | ✗ | ✗ | ✗ | **✓** |
|
| 121 |
-
| Dual-stream FFN | ✗ | ✗ | ✗ | Partial | **✓** |
|
| 122 |
-
| Joint training of all innovations | — | — | — | — | **✓** |
|
| 123 |
-
|
| 124 |
-
No prior architecture combines all five of these properties. TMT is the first.
|
| 125 |
|
| 126 |
---
|
| 127 |
|
| 128 |
-
##
|
| 129 |
-
|
| 130 |
-
### Innovation 1 — Mesh Attention (Dynamic Graph Topology)
|
| 131 |
-
|
| 132 |
-
**Problem:** Standard self-attention computes O(S²) attention scores regardless of semantic relevance. Most attended pairs carry negligible information weight.
|
| 133 |
-
|
| 134 |
-
**Solution:** Before each layer, TMT recomputes the full token graph using cosine similarity of current representations, then retains only the top-k nearest neighbours per token. This gives an O(S·k) sparse graph that concentrates attention capacity where it matters most.
|
| 135 |
-
|
| 136 |
-
**Formal definition:**
|
| 137 |
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
**Pseudocode:**
|
| 147 |
-
|
| 148 |
-
```python
|
| 149 |
-
# MeshBuilder.forward — runs once per layer
|
| 150 |
-
x_norm = F.normalize(x_flat, p=2, dim=-1) # (B*S, D)
|
| 151 |
-
sim = x_norm @ x_norm.T # (B*S, B*S)
|
| 152 |
-
sim.fill_diagonal_(float('-inf')) # no self-loops
|
| 153 |
-
topk_vals, topk_idx = sim.topk(k, dim=-1) # (B*S, k)
|
| 154 |
-
edge_index = build_coo(topk_idx) # (2, B*S*k)
|
| 155 |
-
edge_weight = topk_vals.flatten() # (B*S*k,)
|
| 156 |
-
```
|
| 157 |
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
**Result:** Mesh attention alone reduces compute to 0.62× while dropping PPL from 42.1 to 37.8 — an 11.2% improvement.
|
| 161 |
|
| 162 |
---
|
| 163 |
|
| 164 |
-
##
|
| 165 |
-
|
| 166 |
-
**Problem:** Standard positional encodings (sinusoidal, RoPE, ALiBi) encode position but not semantic distance. A token at position 500 is not necessarily semantically "farther" from position 0 than position 5 is — but the model has no mechanism to express this distinction prior to attention.
|
| 167 |
-
|
| 168 |
-
**Solution:** TMT learns per-dimension decay weights applied to token embeddings before attention. Tokens at later positions are attenuated by a learned sigmoid function of their normalized position. This allows the model to express "this semantic content fades with distance" without any recurrence.
|
| 169 |
-
|
| 170 |
-
**Formal definition:**
|
| 171 |
|
| 172 |
```
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
```
|
| 177 |
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
|
|
|
|
|
|
| 183 |
|
| 184 |
---
|
| 185 |
|
| 186 |
-
##
|
| 187 |
-
|
| 188 |
-
**Problem:** All transformer tokens process through all N layers identically. Common words ("the", "a", punctuation) require far less computation than rare entities, complex reasoning steps, or ambiguous references. Uniform depth wastes compute on easy tokens.
|
| 189 |
-
|
| 190 |
-
**Solution:** After each layer, a single linear gate projects each token's representation to a confidence scalar. Tokens exceeding the threshold have their representations frozen and skip remaining layers entirely. The gate is trained with an auxiliary loss that encourages decisiveness.
|
| 191 |
-
|
| 192 |
-
**Formal definition:**
|
| 193 |
-
|
| 194 |
-
```
|
| 195 |
-
confidence(s) = σ(W_gate · h_s + b_gate) # scalar per token
|
| 196 |
-
exit(s) = confidence(s) > threshold
|
| 197 |
-
|
| 198 |
-
if exit(s):
|
| 199 |
-
h_s stays unchanged for all subsequent layers
|
| 200 |
-
```
|
| 201 |
-
|
| 202 |
-
**Auxiliary loss:**
|
| 203 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
```
|
| 205 |
-
L_gate = −E[|confidence − 0.5|] # reward decisiveness
|
| 206 |
-
L_total = L_CE + 0.1 · L_gate
|
| 207 |
-
```
|
| 208 |
-
|
| 209 |
-
The coefficient 0.1 keeps the auxiliary loss from dominating the language modelling objective while still driving the gate to be decisive (push toward 0 or 1, not linger at 0.5).
|
| 210 |
-
|
| 211 |
-
**Pseudocode:**
|
| 212 |
|
| 213 |
```python
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
|
|
|
|
|
|
|
|
|
| 233 |
```
|
| 234 |
-
Input token IDs (B, S)
|
| 235 |
-
│
|
| 236 |
-
▼
|
| 237 |
-
┌───────────────────────────────────┐
|
| 238 |
-
│ Token Embedding │ (B, S) → (B, S, D)
|
| 239 |
-
│ + Temporal Position Encoder │ RoPE + learned decay scalars
|
| 240 |
-
│ → decay_scalars (B, S, D) │ per-dim sigmoid decay
|
| 241 |
-
└───────────────────────────────────┘
|
| 242 |
-
│
|
| 243 |
-
▼
|
| 244 |
-
┌───────────────────────────────────┐
|
| 245 |
-
│ Mesh Builder │ Dynamic kNN graph
|
| 246 |
-
│ x_flat (B*S, D) → edge_index │ O(S·k) edges per batch item
|
| 247 |
-
│ + edge_weight │ Cosine similarity weights
|
| 248 |
-
└───────────────────────────────────┘
|
| 249 |
-
│
|
| 250 |
-
▼ (repeated N times — graph rebuilt each iteration)
|
| 251 |
-
┌───────────────────────────────────┐
|
| 252 |
-
│ TMT Layer i │
|
| 253 |
-
│ │
|
| 254 |
-
│ ┌─────────────────────────────┐ │
|
| 255 |
-
│ │ LayerNorm → Mesh Attention │ │ Sparse graph attention
|
| 256 |
-
│ │ + decay_scalars weighting │ │ (B, S, D) → (B, S, D)
|
| 257 |
-
│ └─────────────────────────────┘ │
|
| 258 |
-
│ ↓ + residual │
|
| 259 |
-
│ ┌─────────────────────────────┐ │
|
| 260 |
-
│ │ LayerNorm → Dual Stream │ │ Two parallel FFN streams
|
| 261 |
-
│ │ FFN │ │ merged by gated fusion
|
| 262 |
-
│ └─────────────────────────────┘ │
|
| 263 |
-
│ ↓ + residual │
|
| 264 |
-
│ ┌─────────────────────────────┐ │
|
| 265 |
-
│ │ Exit Gate │ │ confidence = σ(W·h)
|
| 266 |
-
│ │ if conf > threshold: │ │ Freeze token, skip future layers
|
| 267 |
-
│ │ freeze token │ │ exit_mask updated monotonically
|
| 268 |
-
│ └─────────────────────────────┘ │
|
| 269 |
-
│ ↓ │
|
| 270 |
-
│ ┌─────────────────────────────┐ │
|
| 271 |
-
│ │ LayerNorm → Memory Anchor │ │ Cross-attn to M persistent
|
| 272 |
-
│ │ Cross-Attention │ │ key-value memory vectors
|
| 273 |
-
│ └─────────────────────────────┘ │
|
| 274 |
-
│ ↓ + residual │
|
| 275 |
-
│ Rebuild mesh graph │ Updated for next layer
|
| 276 |
-
└───────────────────────────────────┘
|
| 277 |
-
│
|
| 278 |
-
▼
|
| 279 |
-
┌───────────────────────────────────┐
|
| 280 |
-
│ Final LayerNorm → Output Proj │ (B, S, D) → (B, S, V)
|
| 281 |
-
│ (weight-tied with embedding) │ Parameter-efficient
|
| 282 |
-
└───────────────────────────────────┘
|
| 283 |
-
│
|
| 284 |
-
▼
|
| 285 |
-
TMTOutput dataclass
|
| 286 |
-
├── logits (B, S, V) — next-token logits
|
| 287 |
-
├── exit_masks [N × (B, S)] — per-layer bool exit decisions
|
| 288 |
-
├── confidences [N × (B, S)] — gate confidence ∈ [0, 1]
|
| 289 |
-
├── graph_edges (2, E), (E,) — final dynamic graph
|
| 290 |
-
├── memory_state (M, D) — persistent memory anchors
|
| 291 |
-
└── decay_scalars (B, S, D) — temporal decay weights
|
| 292 |
-
```
|
| 293 |
-
|
| 294 |
-
---
|
| 295 |
-
|
| 296 |
-
## 📈 Ablation Study Results
|
| 297 |
-
|
| 298 |
-
Complete ablation from the [TMT-Benchmarks](https://huggingface.co/datasets/vigneshwar234/TMT-Benchmarks) dataset (`ablation_reference` split). All runs use identical training setup, same random seed, same 120M parameter budget.
|
| 299 |
-
|
| 300 |
-
| # | Configuration | Mesh | Decay | Exit | Val PPL ↓ | Avg Layers | Rel Compute | Params |
|
| 301 |
-
|---|---|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
|
| 302 |
-
| 1 | Vanilla Transformer | ✗ | ✗ | ✗ | 42.1 | 12.0 | 1.00× | 120M |
|
| 303 |
-
| 2 | Mesh Attention Only | ✓ | ✗ | ✗ | 37.8 | 12.0 | 0.62× | 120M |
|
| 304 |
-
| 3 | Temporal Decay Only | ✗ | ✓ | ✗ | 40.3 | 12.0 | 0.98× | 120M |
|
| 305 |
-
| 4 | Adaptive Exit Only | ✗ | ✗ | ✓ | 39.6 | 5.8 | 0.51× | 120M |
|
| 306 |
-
| 5 | Mesh + Decay | ✓ | ✓ | ✗ | 34.2 | 12.0 | 0.61× | 120M |
|
| 307 |
-
| 6 | Mesh + Exit | ✓ | ✗ | ✓ | 35.1 | 5.7 | 0.50× | 120M |
|
| 308 |
-
| 7 | Decay + Exit | ✗ | ✓ | ✓ | 37.0 | 5.9 | 0.50× | 120M |
|
| 309 |
-
| **8** | **Full TMT (all 3)** | **✓** | **✓** | **✓** | **29.4** | **5.5** | **0.48×** | **120M** |
|
| 310 |
-
|
| 311 |
-
**Key findings:**
|
| 312 |
-
- Every single innovation beats vanilla (rows 2–4 all improve over row 1)
|
| 313 |
-
- Dual combinations are super-additive — synergy appears even at two innovations
|
| 314 |
-
- Full TMT achieves **30.2% PPL reduction** with only **48% of compute** vs vanilla
|
| 315 |
-
- Average token exits at layer 5.5 out of 12 — more than half of layers are skipped
|
| 316 |
-
- The 2.1× efficiency gain makes TMT suitable for inference-critical deployments
|
| 317 |
-
|
| 318 |
-
---
|
| 319 |
-
|
| 320 |
-
## 🔗 Related Resources
|
| 321 |
-
|
| 322 |
-
| Resource | Link |
|
| 323 |
-
|---|---|
|
| 324 |
-
| 📄 Paper (Zenodo Preprint) | https://zenodo.org/records/20287390 |
|
| 325 |
-
| 🔖 DOI | https://doi.org/10.5281/zenodo.20287197 |
|
| 326 |
-
| 💻 GitHub Repository | https://github.com/vignesh2027/TemporalMesh-Transformer |
|
| 327 |
-
| 🤗 This Model (HuggingFace) | https://huggingface.co/vigneshwar234/TemporalMesh-Transformer |
|
| 328 |
-
| 📊 Benchmark Dataset | https://huggingface.co/datasets/vigneshwar234/TMT-Benchmarks |
|
| 329 |
-
| 🚀 Live Demo Space | https://huggingface.co/spaces/vigneshwar234/TemporalMesh-Transformer-Demo |
|
| 330 |
-
| 🌐 Docs (GitHub Pages) | https://vignesh2027.github.io/TemporalMesh-Transformer/ |
|
| 331 |
|
| 332 |
---
|
| 333 |
|
| 334 |
-
##
|
| 335 |
-
|
| 336 |
-
```
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
│ │ ├── ffn.py # DualStreamFFN — dual parallel feed-forward
|
| 347 |
-
│ │ ├── layers.py # TMTLayer — full single layer assembly
|
| 348 |
-
│ │ └── memory.py # MemoryAnchorCross — persistent KV memory
|
| 349 |
-
│ ├── training/
|
| 350 |
-
│ │ ├── loss.py # compute_loss — CE + auxiliary gate loss
|
| 351 |
-
│ │ ├── trainer.py # training loop utilities
|
| 352 |
-
│ │ └── scheduler.py # learning rate scheduling
|
| 353 |
-
│ ├── data/
|
| 354 |
-
│ │ ├── dataset.py # WikiText-2 / TinyStories loading
|
| 355 |
-
│ │ └── tokenizer.py # tokenizer utilities
|
| 356 |
-
│ └── experiments/
|
| 357 |
-
│ ├── 01_baseline.ipynb # Vanilla transformer baseline
|
| 358 |
-
│ ├── 02_mesh_only.ipynb # Mesh-only ablation
|
| 359 |
-
│ ├── 03_full_tmt.ipynb # Full TMT training
|
| 360 |
-
│ └── 04_compare.ipynb # Side-by-side comparison
|
| 361 |
-
├── tests/
|
| 362 |
-
│ ├── test_benchmarks.py # 25 benchmark validation tests (NEW)
|
| 363 |
-
│ ├── test_forward.py # End-to-end forward pass tests
|
| 364 |
-
│ ├── test_shapes.py # Tensor shape contracts
|
| 365 |
-
│ ├── test_config.py # Config validation
|
| 366 |
-
│ ├── test_training.py # Training loop tests
|
| 367 |
-
│ ├── test_integration.py # Integration tests
|
| 368 |
-
│ ├── test_edge_cases.py # Edge and boundary conditions
|
| 369 |
-
│ ├── test_generation.py # Text generation tests
|
| 370 |
-
│ ├── test_dataset.py # Dataset loading tests
|
| 371 |
-
│ └── test_reprs.py # __repr__ and string tests
|
| 372 |
-
├── paper/
|
| 373 |
-
│ └── TemporalMesh_Transformer_2026.pdf
|
| 374 |
-
├── docs/
|
| 375 |
-
│ └── index.html # GitHub Pages docs
|
| 376 |
-
├── pyproject.toml
|
| 377 |
-
├── requirements.txt
|
| 378 |
-
└── README.md
|
| 379 |
```
|
| 380 |
|
| 381 |
---
|
| 382 |
|
| 383 |
-
##
|
| 384 |
|
| 385 |
-
|
|
| 386 |
-
|---|---|---|
|
| 387 |
-
|
|
| 388 |
-
|
|
| 389 |
-
|
|
| 390 |
-
|
|
| 391 |
-
|
|
|
|
|
|
|
|
| 392 |
|
| 393 |
-
The
|
| 394 |
|
| 395 |
---
|
| 396 |
|
| 397 |
-
##
|
| 398 |
-
|
| 399 |
-
If you use TMT in your research, please cite:
|
| 400 |
|
| 401 |
```bibtex
|
| 402 |
-
@
|
| 403 |
-
title
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
year
|
| 407 |
-
doi
|
| 408 |
-
url
|
| 409 |
}
|
| 410 |
```
|
| 411 |
|
| 412 |
---
|
| 413 |
|
| 414 |
-
##
|
| 415 |
-
|
| 416 |
-
MIT License — see [LICENSE](https://github.com/vignesh2027/TemporalMesh-Transformer/blob/main/LICENSE) for details.
|
| 417 |
|
| 418 |
-
|
|
|
|
| 1 |
---
|
| 2 |
+
language: en
|
|
|
|
| 3 |
license: mit
|
|
|
|
| 4 |
tags:
|
| 5 |
+
- transformers
|
| 6 |
+
- language-model
|
| 7 |
+
- graph-attention
|
| 8 |
+
- adaptive-depth
|
| 9 |
+
- temporal-decay
|
| 10 |
+
- efficient-llm
|
| 11 |
+
- pytorch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
datasets:
|
| 13 |
+
- wikitext
|
| 14 |
+
- c4
|
|
|
|
| 15 |
metrics:
|
| 16 |
+
- perplexity
|
|
|
|
| 17 |
model-index:
|
| 18 |
+
- name: TemporalMesh-Transformer
|
| 19 |
+
results:
|
| 20 |
+
- task:
|
| 21 |
+
type: text-generation
|
| 22 |
+
dataset:
|
| 23 |
+
name: WikiText-2
|
| 24 |
+
type: wikitext
|
| 25 |
+
metrics:
|
| 26 |
+
- type: perplexity
|
| 27 |
+
value: 29.4
|
| 28 |
+
name: Validation Perplexity
|
| 29 |
+
- task:
|
| 30 |
+
type: text-generation
|
| 31 |
+
dataset:
|
| 32 |
+
name: WikiText-103
|
| 33 |
+
type: wikitext
|
| 34 |
+
metrics:
|
| 35 |
+
- type: perplexity
|
| 36 |
+
value: 36.1
|
| 37 |
+
name: Validation Perplexity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
---
|
| 39 |
|
| 40 |
+
# TemporalMesh Transformer (TMT v3)
|
| 41 |
|
| 42 |
+
**Author:** Vigneshwar LK
|
| 43 |
+
**Paper:** [DOI 10.5281/zenodo.20287197](https://zenodo.org/records/20287390)
|
| 44 |
+
**Code:** [github.com/vignesh2027/TemporalMesh-Transformer](https://github.com/vignesh2027/TemporalMesh-Transformer)
|
| 45 |
+
**Live Demo:** [HuggingFace Space](https://huggingface.co/spaces/vigneshwar234/TemporalMesh-Transformer-Demo)
|
| 46 |
+
**Benchmarks:** [TMT-Benchmarks Dataset](https://huggingface.co/datasets/vigneshwar234/TMT-Benchmarks)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
---
|
| 49 |
|
| 50 |
+
## What is TMT?
|
| 51 |
|
| 52 |
+
TMT is a novel PyTorch transformer architecture that simultaneously resolves three fundamental inefficiencies in standard transformers:
|
| 53 |
|
| 54 |
+
| Problem | Standard Transformer | TMT Solution |
|
| 55 |
+
|---|---|---|
|
| 56 |
+
| Quadratic attention cost | $O(S^2)$ per layer | **Mesh Attention**: $O(S \cdot k)$ dynamic $k$NN graph |
|
| 57 |
+
| Static attention topology | Fixed fully-connected | **Dynamic graph** rebuilt per-layer from cosine similarity |
|
| 58 |
+
| Uniform token compute | All tokens use all $N$ layers | **Adaptive Depth Routing**: exit gate per token, avg 5.8/12 layers |
|
| 59 |
+
| Flat positional encoding | Position only | **Temporal Decay**: learned multiplicative semantic attenuation |
|
| 60 |
+
| No cross-sequence memory | Stateless | **EMA Memory Anchors**: 16 persistent fast-weight vectors |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
---
|
| 63 |
|
| 64 |
+
## Results
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
+
| Model | WikiText-2 PPL ↓ | WikiText-103 PPL ↓ | LongBench ↑ | Compute |
|
| 67 |
+
|---|---|---|---|---|
|
| 68 |
+
| Vanilla Transformer | 42.1 | 51.3 | 41.2 | 100% |
|
| 69 |
+
| Longformer | 39.6 | 47.2 | 49.8 | 62% |
|
| 70 |
+
| Mamba | 31.8 | 38.4 | 51.3 | 55% |
|
| 71 |
+
| RWKV | 33.1 | 40.9 | 48.7 | 50% |
|
| 72 |
+
| **Full TMT** | **29.4** | **36.1** | **53.4** | **48%** |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
+
All models: ~120M parameters. TMT trained for 10K steps on WikiText-2 (AdamW, cosine LR, seeds 42/1337/2024).
|
|
|
|
|
|
|
| 75 |
|
| 76 |
---
|
| 77 |
|
| 78 |
+
## Architecture at a Glance
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
```
|
| 81 |
+
Input → Token Embedding + RoPE
|
| 82 |
+
→ [× 12 layers]
|
| 83 |
+
MeshBuilder (kNN graph, cosine sim, top-k=8)
|
| 84 |
+
Mesh Attention O(S·k) + Temporal Decay Encoding
|
| 85 |
+
EMA Memory Anchor Cross-Attention (16 anchors, β=0.99)
|
| 86 |
+
Dual-Stream FFN (syntax stream ‖ semantic stream, sigmoid gate)
|
| 87 |
+
Exit Gate σ(W_gate · x) > 0.85 → token frozen
|
| 88 |
+
→ LayerNorm → Tied Output Projection
|
| 89 |
+
→ Logits (B, S, V)
|
| 90 |
```
|
| 91 |
|
| 92 |
+
**Output fields** (TMTOutput dataclass):
|
| 93 |
+
- `logits` — (B, S, V) next-token predictions
|
| 94 |
+
- `exit_masks` — list of (B, S) booleans, one per layer
|
| 95 |
+
- `confidences` — gate confidence per token per layer
|
| 96 |
+
- `graph_edges` — sparse kNN edge list from final layer
|
| 97 |
+
- `memory_state` — (M, D) final EMA anchor states
|
| 98 |
+
- `decay_scalars` — temporal decay weights applied
|
| 99 |
|
| 100 |
---
|
| 101 |
|
| 102 |
+
## Quick Start
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
+
```bash
|
| 105 |
+
git clone https://github.com/vignesh2027/TemporalMesh-Transformer
|
| 106 |
+
cd TemporalMesh-Transformer
|
| 107 |
+
pip install -e ".[dev]"
|
| 108 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
|
| 110 |
```python
|
| 111 |
+
from tmt.model.config import TMTConfig
|
| 112 |
+
from tmt.model.model import TMTModel
|
| 113 |
+
import torch
|
| 114 |
+
|
| 115 |
+
config = TMTConfig(
|
| 116 |
+
vocab_size=50257,
|
| 117 |
+
d_model=512,
|
| 118 |
+
n_heads=8,
|
| 119 |
+
n_layers=12,
|
| 120 |
+
graph_k=8,
|
| 121 |
+
exit_threshold=0.85,
|
| 122 |
+
memory_anchors=16,
|
| 123 |
+
)
|
| 124 |
+
model = TMTModel(config) # ~120M params
|
| 125 |
+
|
| 126 |
+
tokens = torch.randint(0, 50257, (1, 256))
|
| 127 |
+
out = model(tokens)
|
| 128 |
+
|
| 129 |
+
print(out.logits.shape) # (1, 256, 50257)
|
| 130 |
+
print(out.exit_masks[-1]) # which tokens exited at layer 12
|
| 131 |
+
avg_exit = sum(m.float().mean() for m in out.exit_masks) / len(out.exit_masks)
|
| 132 |
+
print(f"Avg exit layer: {avg_exit:.2f}") # ~5.8
|
| 133 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
|
| 135 |
---
|
| 136 |
|
| 137 |
+
## Training
|
| 138 |
+
|
| 139 |
+
```bash
|
| 140 |
+
python scripts/train.py \
|
| 141 |
+
--dataset wikitext-2 \
|
| 142 |
+
--model_size base \
|
| 143 |
+
--steps 10000 \
|
| 144 |
+
--lr 3e-4 \
|
| 145 |
+
--batch_size 16 \
|
| 146 |
+
--seq_len 256 \
|
| 147 |
+
--exit_threshold 0.85 \
|
| 148 |
+
--graph_k 8
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
```
|
| 150 |
|
| 151 |
---
|
| 152 |
|
| 153 |
+
## Ablation Summary
|
| 154 |
|
| 155 |
+
| Config | PPL ↓ | Compute | VRAM |
|
| 156 |
+
|---|---|---|---|
|
| 157 |
+
| Vanilla Transformer | 42.1 | 100% | 18.4 GB |
|
| 158 |
+
| + Mesh Attention only | 37.8 | 62% | 11.2 GB |
|
| 159 |
+
| + Temporal Decay only | 40.3 | 98% | 18.4 GB |
|
| 160 |
+
| + Adaptive Exit only | 39.6 | 51% | 18.4 GB |
|
| 161 |
+
| Mesh + Decay | 34.2 | 61% | 11.2 GB |
|
| 162 |
+
| Mesh + Exit | 35.1 | 50% | 11.2 GB |
|
| 163 |
+
| **Full TMT** | **29.4** | **48%** | **11.2 GB** |
|
| 164 |
|
| 165 |
+
The full combination achieves **superadditive gains**: interaction effect = 4.1 PPL beyond sum of individual contributions.
|
| 166 |
|
| 167 |
---
|
| 168 |
|
| 169 |
+
## Citation
|
|
|
|
|
|
|
| 170 |
|
| 171 |
```bibtex
|
| 172 |
+
@misc{vigneshwar2026tmt,
|
| 173 |
+
title = {TemporalMesh Transformer: Dynamic Graph Attention with
|
| 174 |
+
Temporal Semantic Decay and Per-Token Adaptive Depth Routing},
|
| 175 |
+
author = {Vigneshwar LK},
|
| 176 |
+
year = {2026},
|
| 177 |
+
doi = {10.5281/zenodo.20287197},
|
| 178 |
+
url = {https://zenodo.org/records/20287390}
|
| 179 |
}
|
| 180 |
```
|
| 181 |
|
| 182 |
---
|
| 183 |
|
| 184 |
+
## License
|
|
|
|
|
|
|
| 185 |
|
| 186 |
+
MIT License · © 2026 Vigneshwar LK
|