reaperdoesntknow commited on
Commit
3398b2e
·
verified ·
1 Parent(s): 1140b72

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +172 -133
README.md CHANGED
@@ -1,199 +1,238 @@
1
  ---
2
  library_name: transformers
3
- tags: []
 
 
 
4
  ---
5
 
6
- # Model Card for Model ID
7
 
8
- <!-- Provide a quick summary of what the model is/does. -->
9
 
 
 
 
10
 
 
11
 
12
- ## Model Details
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
- ### Model Description
15
 
16
- <!-- Provide a longer summary of what this model is. -->
17
 
18
- This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
 
 
 
 
 
 
 
 
 
 
19
 
20
- - **Developed by:** [More Information Needed]
21
- - **Funded by [optional]:** [More Information Needed]
22
- - **Shared by [optional]:** [More Information Needed]
23
- - **Model type:** [More Information Needed]
24
- - **Language(s) (NLP):** [More Information Needed]
25
- - **License:** [More Information Needed]
26
- - **Finetuned from model [optional]:** [More Information Needed]
27
 
28
- ### Model Sources [optional]
29
 
30
- <!-- Provide the basic links for the model. -->
31
 
32
- - **Repository:** [More Information Needed]
33
- - **Paper [optional]:** [More Information Needed]
34
- - **Demo [optional]:** [More Information Needed]
35
 
36
- ## Uses
37
 
38
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
 
40
- ### Direct Use
 
 
41
 
42
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
43
 
44
- [More Information Needed]
 
 
45
 
46
- ### Downstream Use [optional]
47
 
48
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
49
 
50
- [More Information Needed]
51
 
52
- ### Out-of-Scope Use
53
 
54
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
 
55
 
56
- [More Information Needed]
57
 
58
- ## Bias, Risks, and Limitations
 
 
 
59
 
60
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
 
61
 
62
- [More Information Needed]
 
 
 
 
 
 
 
 
63
 
64
- ### Recommendations
65
 
66
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
67
 
68
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
 
 
 
 
 
 
 
 
 
69
 
70
- ## How to Get Started with the Model
 
71
 
72
- Use the code below to get started with the model.
73
 
74
- [More Information Needed]
 
 
 
 
 
 
75
 
76
- ## Training Details
 
77
 
78
- ### Training Data
 
 
 
79
 
80
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
 
 
 
81
 
82
- [More Information Needed]
 
83
 
84
- ### Training Procedure
85
 
86
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
 
 
 
 
 
87
 
88
- #### Preprocessing [optional]
89
 
90
- [More Information Needed]
91
 
 
92
 
93
- #### Training Hyperparameters
 
 
 
94
 
95
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
96
 
97
- #### Speeds, Sizes, Times [optional]
98
 
99
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
 
 
 
100
 
101
- [More Information Needed]
 
 
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
+ datasets:
4
+ - HuggingFaceH4/MATH-500
5
+ - akoksal/LongForm
6
+ pipeline_tag: text-generation
7
  ---
8
 
9
+ # MoA-Metric-LM-400M (Convergent)
10
 
11
+ A compact-but-capable ≈400M parameter causal LM that replaces dot-product attention with metric-native attention and augments sequence geometry with BlackHoleRoPE (a learnable, stable RoPE variant). Designed to train and run on modest hardware (CPU-first friendly) while staying fully compatible with 🤗 Transformers.
12
 
13
+ Tags: Convergent · MoA · Conversational · Research
14
+ Datasets: yzhuang/Agentic-Long-Context-Understanding-QA, HuggingFaceH4/MATH-500
15
+ License: Apache-2.0
16
 
17
+
18
 
19
+ # Why this model?
20
+ • Distance scores, not dot products. Heads score with L2, cosine, or diag-Mahalanobis distances. This gives direct control over geometry, often stabilizes training, and can be more sample-efficient.
21
+ • BlackHoleRoPE positional encoding.
22
+ • Q/K: pure unit-modulus rotation (unitary → numerically stable).
23
+ • V: bounded-energy gating (Penrose-inspired), optionally modulated by a discrepancy signal.
24
+ • Parameters synthesized from a tiny Fourier basis → extrapolable and cache-friendly, with low memory.
25
+ • MoA (Mixture-of-Architectures) block. Token-wise router softly blends four heads per block:
26
+ 1. LocalConv (depthwise token-local conv)
27
+ 2. MetricMHAttention (multi-head metric attention)
28
+ 3. ChannelMix (MLP)
29
+ 4. MetricMQA (multi-query, shared K/V)
30
+ • Triangle-Inequality (TI) regularizer. Keeps metric heads honest by penalizing violations over random triples.
31
+ • Runs on CPUs. Implemented to behave well in FP32 on AVX2/AVX-512 machines.
32
 
33
+
34
 
35
+ ## Model at a glance
36
 
37
+ Property Value
38
+ Parameters ~400 M (exact count depends on vocab; see config.json)
39
+ Layers 12–24 depending on variant (MoA blocks)
40
+ Hidden size ≥ 1024 in the 400 M variant (head dim divisible by #heads)
41
+ Attention Metric-native (L2 / cosine / diag-Mahalanobis), plus MetricMQA
42
+ Positional BlackHoleRoPE per-head (rope_global for MH-Attn, rope_mqa for MQA)
43
+ Router Token-wise soft mixture across the four heads (+ optional bias gate)
44
+ FFN HyperFFN = SwiGLU MLP + SepConv1d + Low-Rank path (router-mixed)
45
+ Context Trained primarily at 512–1024 tokens; config allows up to 2048
46
+ Precision Training FP32 (CPU-friendly); inference FP32/BF16/FP16 supported
47
+ License Apache-2.0
48
 
49
+ Note on context: training emphasized 512–1024; BlackHoleRoPE is extrapolable, but throughput and quality beyond training lengths depend on your hardware and data.
 
 
 
 
 
 
50
 
51
+
52
 
53
+ Intended use & limitations
54
 
55
+ Intended: compact assistants, long-context reading/QA, math-style step reasoning, research on distance-based attention and geometric inductive biases.
 
 
56
 
57
+ Not intended: safety-critical use, heavy factual QA at web scale, or domains requiring guaranteed accuracy. Evaluate carefully before deployment.
58
 
59
+
60
 
61
+ ## Datasets
62
+ • Agentic-Long-Context-Understanding-QA — long-range reading/retrieval questions to exercise context tracking. ~256000 tokens
63
+ • MATH-500 — small curated math prompts for stepwise reasoning. ~256000 tokens
64
 
65
+ Training used modest token budgets (hundreds of thousands). Reported training logs showed healthy loss descent on both 512 and 1024 sequence lengths on CPU runs. Exact metrics will vary with tokenizer, preprocessing, and optimizer settings.
66
 
67
+
68
+ ```python
69
+ Installation
70
 
71
+ pip install transformers accelerate sentencepiece
72
 
 
73
 
74
+
75
 
76
+ Quick start
77
 
78
+ from transformers import AutoTokenizer, AutoModelForCausalLM
79
+ import torch
80
 
81
+ repo = "reaperdoesntknow/MoA-400M" # replace with your repo id
82
 
83
+ tok = AutoTokenizer.from_pretrained(repo)
84
+ model = AutoModelForCausalLM.from_pretrained(
85
+ repo, torch_dtype=torch.float32, device_map="cpu"
86
+ ).eval()
87
 
88
+ prompt = "Read and answer: If 3x + 2 = 17, what is x?\nReasoning:"
89
+ inputs = tok(prompt, return_tensors="pt")
90
 
91
+ with torch.no_grad():
92
+ out = model.generate(
93
+ **inputs,
94
+ max_length=256,
95
+ do_sample=True,
96
+ top_p=0.9,
97
+ temperature=0.8,
98
+ pad_token_id=tok.eos_token_id,
99
+ )
100
 
101
+ print(tok.decode(out[0], skip_special_tokens=True))
102
 
103
+ Pipeline usage
104
 
105
+ from transformers import pipeline
106
+ repo = "reaperdoesntknow/MoA-400M"
107
+ pipe = pipeline("text-generation", model=repo, device_map="cpu")
108
+ print(
109
+ pipe(
110
+ "Question: Who wrote 'The Selfish Gene'?\nAnswer:",
111
+ max_length=128,
112
+ do_sample=False,
113
+ )[0]["generated_text"]
114
+ )
115
 
116
+ ```
117
+
118
 
119
+ ## Architecture details
120
 
121
+ Metric attention (MH)
122
+ • Scores:
123
+ • L2: -||q-k||² / sqrt(d)
124
+ • Cosine: normalized dot → scaled
125
+ • diag-Mahalanobis: per-head diagonal scale on dimensions
126
+ • Stability: logits scaled by a learnable α; optional radius-based pruning mask for efficiency.
127
+ • Value path: post-attention Up/Down projector (gated) for expressive value mixing.
128
 
129
+ Metric MQA (shared K/V)
130
+ • K and V are shared (single projection) and broadcast; queries remain multi-head. Useful for throughput and memory.
131
 
132
+ ## BlackHoleRoPE
133
+ • Q/K rotation only (unit modulus) → preserves norms; avoids value blow-ups.
134
+ • V receives bounded-energy amplification (energy_min..energy_max) with optional discrepancy modulation.
135
+ • Parameters synthesized from a small Fourier basis; reduces cache size and improves length generalization.
136
 
137
+ Routing & gates
138
+ • TokenRouter: per-token weights over {LocalConv, MetricMH, ChannelMix, MetricMQA}.
139
+ • Feature gates: per-head multiplicative scales in (0, 2) around 1.0.
140
+ • Optional router bias adds signed offsets before softmax.
141
 
142
+ Triangle-Inequality regularizer
143
+ • Lightweight penalty on random triples to discourage degenerate metric geometry.
144
 
145
+
146
 
147
+ Training recipe (reference)
148
+ • Device: CPU (AVX2/AVX-512 recommended).
149
+ • Precision: FP32.
150
+ • Optimizer: AdamW or Adam (β₁=0.9, β₂=0.95–0.999 work); cosine LR or linear warmup.
151
+ • Batch/seq: [batch, seq] = [2–4, 512–1024].
152
+ • Regularization: modest dropout in attention/value paths; optional TI penalty.
153
 
154
+ If you see NaN/Inf during sampling, ensure masks are additive 0/-inf, clamp logits when rows are fully masked, and set a pad_token_id in .generate().
155
 
156
+
157
 
158
+ Evaluation notes
159
 
160
+ The model targets behavioral quality per FLOP rather than leaderboard chasing. On held-out long-context QA and small math checks, it shows:
161
+ • Robust token-to-token coherence at 512–1024.
162
+ • Stable generation on CPU with FP32.
163
+ • Competitive loss trends versus dot-product baselines trained under the same compute.
164
 
165
+ Please share issues/benchmarks via the repo so results can be tracked.
166
 
167
+
168
 
169
+ How to fine-tune
170
+ ```python
171
+ from transformers import AutoTokenizer, AutoModelForCausalLM, TrainingArguments, Trainer
172
+ from datasets import load_dataset
173
 
174
+ repo = "reaperdoesntknow/MoA-400M"
175
+ tok = AutoTokenizer.from_pretrained(repo)
176
+ model = AutoModelForCausalLM.from_pretrained(repo)
177
 
178
+ ds = load_dataset("yzhuang/Agentic-Long-Context-Understanding-QA", split="train[:2%]")
179
 
180
+ def tok_fn(ex):
181
+ x = tok(
182
+ ex["question"] + "\n" + ex["context"] + "\nAnswer:",
183
+ truncation=True,
184
+ max_length=1024,
185
+ )
186
+ x["labels"] = x["input_ids"].copy()
187
+ return x
188
 
189
+ tds = ds.map(tok_fn, remove_columns=ds.column_names)
190
 
191
+ args = TrainingArguments(
192
+ output_dir="./moa400m-finetune",
193
+ per_device_train_batch_size=2,
194
+ gradient_accumulation_steps=1,
195
+ num_train_epochs=1,
196
+ learning_rate=5e-4,
197
+ weight_decay=0.0,
198
+ warmup_steps=100,
199
+ logging_steps=10,
200
+ save_steps=200,
201
+ fp16=False,
202
+ bf16=False,
203
+ )
204
 
205
+ trainer = Trainer(model=model, args=args, train_dataset=tds)
206
+ trainer.train()
207
 
208
+ ```
209
+
210
 
211
+ Known behaviors / tips
212
+ • Context > 1024: works, but CPU throughput drops; BlackHoleRoPE helps stability, not throughput.
213
+ • Sampling: always pass pad_token_id (often eos_token_id) to .generate(); avoid temperature > 1.2 on small models.
214
+ • KV cache: supported; for CPU you may prefer smaller beams and greedy/small-temperature sampling.
215
 
216
+
217
 
218
+ Safety & responsibility
219
 
220
+ This is a research model. It was trained on public datasets and may produce incorrect or biased content. Do not rely on it for advice or sensitive decisions.
221
 
222
+
223
 
224
+ Citation
225
 
226
+ @software{moa_metric_lm_400m,
227
+ title = {MoA-Metric-LM-400M: Distance-based attention with BlackHoleRoPE},
228
+ author = {reaperdoesntknow},
229
+ year = {2025},
230
+ url = {https://huggingface.co/reaperdoesntknow/MoA-400M}
231
+ }
232
 
 
233
 
234
+
235
 
236
+ Acknowledgements
237
 
238
+ Built with 🤗 Transformers and a metric-first rethinking of attention. BlackHoleRoPE draws inspiration from symplectic/rotational encodings and bounded-energy dynamics.