Update README.md
Browse files
README.md
CHANGED
|
@@ -1,199 +1,191 @@
|
|
| 1 |
---
|
| 2 |
library_name: transformers
|
| 3 |
-
tags:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
---
|
| 5 |
|
| 6 |
-
#
|
| 7 |
|
| 8 |
-
|
| 9 |
|
|
|
|
| 10 |
|
|
|
|
| 11 |
|
| 12 |
-
|
| 13 |
|
| 14 |
-
|
| 15 |
|
| 16 |
-
|
| 17 |
|
| 18 |
-
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
-
###
|
| 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 |
-
[More Information Needed]
|
| 57 |
|
| 58 |
-
## Bias, Risks, and Limitations
|
| 59 |
|
| 60 |
-
|
| 61 |
|
| 62 |
-
|
|
|
|
|
|
|
| 63 |
|
| 64 |
-
|
|
|
|
| 65 |
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
-
|
| 69 |
|
| 70 |
-
|
| 71 |
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
-
##
|
| 77 |
|
| 78 |
-
|
| 79 |
|
| 80 |
-
|
| 81 |
|
| 82 |
-
|
| 83 |
|
| 84 |
-
##
|
| 85 |
|
| 86 |
-
|
| 87 |
|
| 88 |
-
|
|
|
|
|
|
|
| 89 |
|
| 90 |
-
|
| 91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
-
##
|
| 94 |
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
-
##
|
| 98 |
|
| 99 |
-
|
| 100 |
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
## Evaluation
|
| 104 |
-
|
| 105 |
-
<!-- This section describes the evaluation protocols and provides the results. -->
|
| 106 |
-
|
| 107 |
-
### Testing Data, Factors & Metrics
|
| 108 |
-
|
| 109 |
-
#### Testing Data
|
| 110 |
-
|
| 111 |
-
<!-- This should link to a Dataset Card if possible. -->
|
| 112 |
-
|
| 113 |
-
[More Information Needed]
|
| 114 |
-
|
| 115 |
-
#### Factors
|
| 116 |
-
|
| 117 |
-
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
| 118 |
-
|
| 119 |
-
[More Information Needed]
|
| 120 |
-
|
| 121 |
-
#### Metrics
|
| 122 |
-
|
| 123 |
-
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
| 124 |
-
|
| 125 |
-
[More Information Needed]
|
| 126 |
-
|
| 127 |
-
### Results
|
| 128 |
-
|
| 129 |
-
[More Information Needed]
|
| 130 |
-
|
| 131 |
-
#### Summary
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
## Model Examination [optional]
|
| 136 |
-
|
| 137 |
-
<!-- Relevant interpretability work for the model goes here -->
|
| 138 |
-
|
| 139 |
-
[More Information Needed]
|
| 140 |
-
|
| 141 |
-
## Environmental Impact
|
| 142 |
-
|
| 143 |
-
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
| 144 |
-
|
| 145 |
-
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
|
| 146 |
-
|
| 147 |
-
- **Hardware Type:** [More Information Needed]
|
| 148 |
-
- **Hours used:** [More Information Needed]
|
| 149 |
-
- **Cloud Provider:** [More Information Needed]
|
| 150 |
-
- **Compute Region:** [More Information Needed]
|
| 151 |
-
- **Carbon Emitted:** [More Information Needed]
|
| 152 |
-
|
| 153 |
-
## Technical Specifications [optional]
|
| 154 |
-
|
| 155 |
-
### Model Architecture and Objective
|
| 156 |
-
|
| 157 |
-
[More Information Needed]
|
| 158 |
-
|
| 159 |
-
### Compute Infrastructure
|
| 160 |
-
|
| 161 |
-
[More Information Needed]
|
| 162 |
-
|
| 163 |
-
#### Hardware
|
| 164 |
-
|
| 165 |
-
[More Information Needed]
|
| 166 |
-
|
| 167 |
-
#### Software
|
| 168 |
-
|
| 169 |
-
[More Information Needed]
|
| 170 |
-
|
| 171 |
-
## Citation [optional]
|
| 172 |
-
|
| 173 |
-
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
| 174 |
-
|
| 175 |
-
**BibTeX:**
|
| 176 |
-
|
| 177 |
-
[More Information Needed]
|
| 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 |
-
[More Information Needed]
|
|
|
|
| 1 |
---
|
| 2 |
library_name: transformers
|
| 3 |
+
tags:
|
| 4 |
+
- trl
|
| 5 |
+
- sft
|
| 6 |
+
- metric-attention
|
| 7 |
+
- mixture-of-attentions
|
| 8 |
+
- triangle-inequality
|
| 9 |
+
- blackhole-rope
|
| 10 |
+
- discrepancy-calculus
|
| 11 |
+
- discover
|
| 12 |
+
license: cc
|
| 13 |
+
datasets:
|
| 14 |
+
- nohurry/Opus-4.6-Reasoning-3000x-filtered
|
| 15 |
+
- openbmb/UltraData-Math
|
| 16 |
+
- yahma/alpaca-cleaned
|
| 17 |
+
language:
|
| 18 |
+
- en
|
| 19 |
+
pipeline_tag: text-generation
|
| 20 |
---
|
| 21 |
|
| 22 |
+
# DiscoverLM-70M-Base
|
| 23 |
|
| 24 |
+
A 70M parameter causal language model built on the **Mixture-of-Attentions (MoA)** architecture — distance-based metric attention that respects the triangle inequality by construction, not approximation.
|
| 25 |
|
| 26 |
+
Every attention head operates in a proper metric space. The geometry is enforced, not hoped for.
|
| 27 |
|
| 28 |
+
## What Makes This Different
|
| 29 |
|
| 30 |
+
Standard transformers compute attention as a dot product: Q·Kᵀ. This has no geometric meaning — it's a bilinear form, not a distance. Two tokens can be "close" by dot product while violating basic metric properties.
|
| 31 |
|
| 32 |
+
MoA replaces this with **negative squared distance** under a learned diagonal Mahalanobis metric, then enforces the triangle inequality through a regularizer over random triples sampled during training. The result: attention weights reflect actual geometric proximity in a space where d(a,c) ≤ d(a,b) + d(b,c) holds.
|
| 33 |
|
| 34 |
+
This isn't a constraint that fights the model. It's structure the model uses.
|
| 35 |
|
| 36 |
+
## Architecture
|
| 37 |
|
| 38 |
+
```
|
| 39 |
+
Input → Token Embedding (48K vocab, custom tokenizer)
|
| 40 |
+
│
|
| 41 |
+
▼
|
| 42 |
+
┌──────────────────────────────────────────────────┐
|
| 43 |
+
│ MoA Block × 4 │
|
| 44 |
+
│ │
|
| 45 |
+
│ ┌─────────┐ ┌──────────┐ ┌────────┐ ┌────────┐ │
|
| 46 |
+
│ │ Local │ │ Global │ │Channel │ │ MQA │ │
|
| 47 |
+
│ │ Conv │ │ Metric │ │ Mix │ │ Metric │ │
|
| 48 |
+
│ │ │ │ (64 heads)│ │ │ │(64 Q) │ │
|
| 49 |
+
│ └────┬────┘ └────┬─────┘ └───┬────┘ └───┬────┘ │
|
| 50 |
+
│ └──────┬────┴───────────┴───────────┘ │
|
| 51 |
+
│ ▼ │
|
| 52 |
+
│ Feature Gates + Token Router (top-2) │
|
| 53 |
+
│ ▼ │
|
| 54 |
+
│ Residual + DropPath │
|
| 55 |
+
└──────────────────────┬───────────────────────────┘
|
| 56 |
+
▼
|
| 57 |
+
HyperFFN (SwiGLU + CausalConv + LowRank)
|
| 58 |
+
▼
|
| 59 |
+
LayerNorm
|
| 60 |
+
▼
|
| 61 |
+
┌──────────────────────────────────────────────────┐
|
| 62 |
+
│ MoA Language Model Head │
|
| 63 |
+
│ (same 4-path mixture → SwiGLU → tied vocab) │
|
| 64 |
+
└──────────────────────┬───────────────────────────┘
|
| 65 |
+
▼
|
| 66 |
+
Logits (48,000)
|
| 67 |
+
```
|
| 68 |
|
| 69 |
+
### Core Components
|
| 70 |
|
| 71 |
+
**Metric Attention.** Queries attend to keys via learned Mahalanobis distance. Each of 64 heads has an 8-dimensional head space with its own diagonal scaling, learnable ball origin, and adaptive radius for sparse pruning. Pairs outside the ball are masked before softmax.
|
| 72 |
|
| 73 |
+
**Mixture-of-Attentions Routing.** Four parallel paths per token — local depthwise convolution, full multi-head metric attention, gated channel mixing, and multi-query metric attention. A learned router selects top-2 paths per token position. Feature gates scale each path's output before mixing.
|
|
|
|
|
|
|
| 74 |
|
| 75 |
+
**BlackHoleRoPE.** Rotary position encoding with learned phase perturbations from a compact Fourier basis. Q/K rotations stay unitary. V amplitudes get bounded energy gating clamped to [0.5, 2.0] with optional discrepancy-state modulation.
|
| 76 |
|
| 77 |
+
**HyperFFN.** Three-branch feedforward: SwiGLU channel MLP, causal depthwise separable convolution, and gated low-rank bottleneck — routed per-token with top-2 sparse selection.
|
| 78 |
|
| 79 |
+
**MoA LM Head.** The vocabulary projection runs its own mixture-of-attentions (32 heads, head_dim=16) before projecting to logits through a SwiGLU transform. Weight-tied to the input embedding.
|
| 80 |
|
| 81 |
+
## Parameter Budget
|
| 82 |
|
| 83 |
+
| Component | Parameters | % |
|
| 84 |
+
|---|---|---|
|
| 85 |
+
| Token embedding (tied) | 24.6M | 35.5% |
|
| 86 |
+
| MoA blocks × 4 | 28.9M | 41.8% |
|
| 87 |
+
| HyperFFN (shared) | 4.2M | 6.1% |
|
| 88 |
+
| MoA LM head | 10.8M | 15.6% |
|
| 89 |
+
| RoPE + norms | 0.6M | 0.9% |
|
| 90 |
+
| **Total** | **69.1M** | |
|
| 91 |
|
| 92 |
+
## vs Standard Transformers
|
| 93 |
|
| 94 |
+
| | Transformer | MoA |
|
| 95 |
+
|---|---|---|
|
| 96 |
+
| Attention scoring | Dot product (Q·Kᵀ) | Negative Mahalanobis distance |
|
| 97 |
+
| Geometric guarantee | None | Triangle inequality regularized |
|
| 98 |
+
| Position encoding | RoPE | BlackHoleRoPE (learned phase + bounded V energy) |
|
| 99 |
+
| Attention sparsity | Causal mask only | Ball pruning + top-k routing |
|
| 100 |
+
| Head combination | Concatenation | Per-token routed mixture of 4 path types |
|
| 101 |
+
| FFN | Single MLP | 3-branch routed (SwiGLU + CausalConv + LowRank) |
|
| 102 |
+
| LM head | Linear projection | Full MoA mixture → SwiGLU → tied projection |
|
| 103 |
|
| 104 |
+
## Training
|
| 105 |
|
| 106 |
+
### Data
|
| 107 |
|
| 108 |
+
| Dataset | Domain |
|
| 109 |
+
|---|---|
|
| 110 |
+
| [Opus-4.6-Reasoning-3000x-filtered](https://huggingface.co/datasets/nohurry/Opus-4.6-Reasoning-3000x-filtered) | Multi-step reasoning |
|
| 111 |
+
| [UltraData-Math](https://huggingface.co/datasets/openbmb/UltraData-Math) | Mathematical problem solving |
|
| 112 |
+
| [alpaca-cleaned](https://huggingface.co/datasets/yahma/alpaca-cleaned) | General instruction following |
|
| 113 |
|
|
|
|
| 114 |
|
|
|
|
| 115 |
|
| 116 |
+
## Usage
|
| 117 |
|
| 118 |
+
```python
|
| 119 |
+
from transformers import AutoTokenizer
|
| 120 |
+
from MoA import MoAMetricLM, MoAMetricConfig
|
| 121 |
|
| 122 |
+
tokenizer = AutoTokenizer.from_pretrained("reaperdoesntknow/DiscoverLM-70M")
|
| 123 |
+
model = MoAMetricLM.from_pretrained("reaperdoesntknow/DiscoverLM-70M")
|
| 124 |
|
| 125 |
+
inputs = tokenizer("The triangle inequality guarantees that", return_tensors="pt")
|
| 126 |
+
outputs = model.generate(**inputs, max_new_tokens=128)
|
| 127 |
+
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
| 128 |
+
```
|
| 129 |
|
| 130 |
+
### Chat Format
|
| 131 |
|
| 132 |
+
The tokenizer includes built-in special tokens for structured generation:
|
| 133 |
|
| 134 |
+
| Token | Role |
|
| 135 |
+
|---|---|
|
| 136 |
+
| `<\|system\|>` | System prompt boundary |
|
| 137 |
+
| `<\|user\|>` | User turn boundary |
|
| 138 |
+
| `<\|assistant\|>` | Assistant turn boundary |
|
| 139 |
+
| `<\|think\|>` | Internal reasoning start |
|
| 140 |
+
| `<\|reasoning\|>` | Reasoning chain marker |
|
| 141 |
+
| `<\|bos\|>` | Beginning of sequence |
|
| 142 |
+
| `<\|eos\|>` | End of sequence |
|
| 143 |
+
| `<\|pad\|>` | Padding |
|
| 144 |
|
| 145 |
+
```python
|
| 146 |
+
# Chat-style prompting
|
| 147 |
+
prompt = "<|system|>You are DiscoverLM, a small language model with metric attention.<|user|>What is the triangle inequality?<|assistant|><|think|><|reasoning|>"
|
| 148 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
| 149 |
+
outputs = model.generate(**inputs, max_new_tokens=256)
|
| 150 |
+
```
|
| 151 |
|
| 152 |
+
## Mathematical Foundation
|
| 153 |
|
| 154 |
+
The metric attention mechanism is grounded in the Discrepancy Calculus (DISC), a measure-theoretic framework for singularity analysis developed by the author. The triangle inequality regularizer enforces that the learned attention geometry satisfies d(a,c) ≤ d(a,b) + d(b,c) across sampled triples, ensuring the distance function used for attention scoring is a proper metric — not merely a similarity function.
|
| 155 |
|
| 156 |
+
The ball pruning mechanism (learnable per-head origins and radii) creates adaptive sparse attention patterns that emerge from the geometry itself rather than from fixed masking heuristics.
|
| 157 |
|
| 158 |
+
BlackHoleRoPE extends standard rotary position encoding with learned phase perturbations synthesized from a Fourier basis, maintaining the unitary property on Q/K while adding bounded amplitude modulation on V — ensuring position-dependent energy gating stays within Lyapunov-stable bounds.
|
| 159 |
|
| 160 |
+
## Lineage
|
| 161 |
|
| 162 |
+
This architecture derives from research in metric-native neural computation:
|
| 163 |
|
| 164 |
+
- **DISC** — Discrepancy Calculus: measure-theoretic singularity analysis (Colca, 2025)
|
| 165 |
+
- **MoA** — Mixture-of-Attentions with triangle inequality enforcement
|
| 166 |
+
- **BlackHoleRoPE** — Learned rotary position encoding with bounded energy gating
|
| 167 |
|
| 168 |
+
## Limitations
|
| 169 |
|
| 170 |
+
- Trained on 262K tokens — the architecture works, but this is a proof-of-concept scale. Generalization to unseen distributions is not yet validated.
|
| 171 |
+
- No eval split was used; training metrics only.
|
| 172 |
+
- 8 epochs over 64 batches means the model has seen each example multiple times. Overfitting is likely at this data scale.
|
| 173 |
+
- fp32 training only — bf16/fp16 behavior untested.
|
| 174 |
|
| 175 |
+
## Citation
|
| 176 |
|
| 177 |
+
```bibtex
|
| 178 |
+
@misc{CILLC2026discoverLM,
|
| 179 |
+
author = {Convergent Intelligence LLC: Research Division},
|
| 180 |
+
title = {DiscoverLM-70M: Metric-Attention Mixture of Attentions with Triangle Inequality Enforcement},
|
| 181 |
+
year = {2026},
|
| 182 |
+
publisher = {HuggingFace},
|
| 183 |
+
url = {https://huggingface.co/reaperdoesntknow/DiscoverLM-70M}
|
| 184 |
+
}
|
| 185 |
+
```
|
| 186 |
|
| 187 |
+
## Author
|
| 188 |
|
| 189 |
+
Roy Colca Jr. — [Convergent Intelligence LLC](https://convergentintel.com)
|
| 190 |
|
| 191 |
+
HuggingFace: [reaperdoesntknow](https://huggingface.co/reaperdoesntknow)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|