TMT is a novel PyTorch transformer architecture that simultaneously resolves three fundamental inefficiencies in standard transformers:
All models: ~120M parameters. TMT trained for 10K steps on WikiText-2 (AdamW, cosine LR, seeds 42/1337/2024).
Input → Token Embedding + RoPE
→ [× 12 layers]
MeshBuilder (kNN graph, cosine sim, top-k=8)
Mesh Attention O(S·k) + Temporal Decay Encoding
EMA Memory Anchor Cross-Attention (16 anchors, β=0.99)
Dual-Stream FFN (syntax stream ‖ semantic stream, sigmoid gate)
Exit Gate σ(W_gate · x) > 0.85 → token frozen
→ LayerNorm → Tied Output Projection
→ Logits (B, S, V)
1git clone https://github.com/vignesh2027/TemporalMesh-Transformer
2cd TemporalMesh-Transformer
3pip install -e ".[dev]"
1from tmt.model.config import TMTConfig
2from tmt.model.model import TMTModel
3import torch
4
5config = TMTConfig(
6 vocab_size=50257,
7 d_model=512,
8 n_heads=8,
9 n_layers=12,
10 graph_k=8,
11 exit_threshold=0.85,
12 memory_anchors=16,
13)
14model = TMTModel(config) # ~120M params
15
16tokens = torch.randint(0, 50257, (1, 256))
17out = model(tokens)
18
19print(out.logits.shape) # (1, 256, 50257)
20print(out.exit_masks[-1]) # which tokens exited at layer 12
21avg_exit = sum(m.float().mean() for m in out.exit_masks) / len(out.exit_masks)
22print(f"Avg exit layer: {avg_exit:.2f}") # ~5.8
1python scripts/train.py \
2 --dataset wikitext-2 \
3 --model_size base \
4 --steps 10000 \
5 --lr 3e-4 \
6 --batch_size 16 \
7 --seq_len 256 \
8 --exit_threshold 0.85 \
9 --graph_k 8
1@misc{vigneshwar2026tmt,
2 title = {TemporalMesh Transformer: Dynamic Graph Attention with
3 Temporal Semantic Decay and Per-Token Adaptive Depth Routing},
4 author = {Vigneshwar LK},
5 year = {2026},
6 doi = {10.5281/zenodo.20287197},
7 url = {https://zenodo.org/records/20287390}
8}