hakanssonjesper meridianal commited on
Commit
3ee0f36
·
0 Parent(s):

Duplicate from meridianal/FinAI

Browse files

Co-authored-by: Meridian <meridianal@users.noreply.huggingface.co>

.gitattributes ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ checkpoint/tokenizer.json filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,422 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Meridian.AI — Continual-Learning Finance LLM
2
+
3
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
4
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
5
+ [![Architecture](https://img.shields.io/badge/Architecture-Sparse_MoE-success.svg)](https://huggingface.co/meridianal/FinAI)
6
+ [![Training](https://img.shields.io/badge/Training-Hourly_CI-orange.svg)](https://github.com/MeridianAlgo/FinAI/actions)
7
+ [![HuggingFace](https://img.shields.io/badge/HuggingFace-meridianal%2FFinAI-yellow.svg)](https://huggingface.co/meridianal/FinAI)
8
+ [![Version](https://img.shields.io/badge/version-5.1.0-blueviolet.svg)]()
9
+
10
+ Meridian.AI is a finance-specialized language model that trains itself continuously, every hour, entirely on free GitHub Actions infrastructure. It uses a **Sparse Mixture-of-Experts (SMoE)** architecture with a **Qwen2.5-0.5B** backbone fine-tuned via **Elastic Weight Consolidation (EWC)** to prevent catastrophic forgetting across training sessions.
11
+
12
+ **Model checkpoints:** [huggingface.co/meridianal/FinAI](https://huggingface.co/meridianal/FinAI)
13
+
14
+ ---
15
+
16
+ ## Table of Contents
17
+
18
+ - [Why Meridian.AI](#why-meridianai)
19
+ - [Key Technical Innovations](#key-technical-innovations)
20
+ - [Architecture](#architecture)
21
+ - [Quick Start](#quick-start)
22
+ - [Inference](#inference)
23
+ - [Local Training](#local-training)
24
+ - [Environment Variables Reference](#environment-variables-reference)
25
+ - [CI/CD Training Pipeline](#cicd-training-pipeline)
26
+ - [Dataset Curriculum](#dataset-curriculum)
27
+ - [Repository Structure](#repository-structure)
28
+ - [Troubleshooting](#troubleshooting)
29
+ - [Disclaimer](#disclaimer)
30
+
31
+ ---
32
+
33
+ ## Why Meridian.AI
34
+
35
+ Standard LLMs have a static knowledge cutoff. For finance — where earnings reports, Fed decisions, and market conditions change daily — this is a critical limitation.
36
+
37
+ Meridian.AI solves this with an **automated continuous training pipeline**: every hour, GitHub Actions pulls the latest checkpoint from HuggingFace, trains on fresh financial data, and pushes the updated checkpoint back. No GPUs. No cloud bills. No manual intervention.
38
+
39
+ Key constraints this design respects:
40
+ - **16 GB RAM** ceiling of free GitHub Actions ubuntu-latest runners
41
+ - **2000 CI minutes/month** free tier (public repos: unlimited)
42
+ - **No persistent storage** between runs — all state is round-tripped through HuggingFace Hub
43
+
44
+ ---
45
+
46
+ ## Key Technical Innovations
47
+
48
+ ### 1. Sparse Mixture-of-Experts (SMoE)
49
+ Each MoE layer contains 8 expert feed-forward networks. For each input token, a learned router selects the top-2 most relevant experts. Only those 2 run — the other 6 are skipped. This gives a large total parameter count (~479M) with a much smaller active compute cost (~283M parameters per forward pass).
50
+
51
+ A load-balancing auxiliary loss (Switch Transformer style) ensures experts are used evenly and no single expert dominates routing.
52
+
53
+ ### 2. Elastic Weight Consolidation (EWC)
54
+ After each hourly training run, the model computes the diagonal Fisher Information Matrix — a measure of which parameters were most important for tasks learned so far. The next run adds a regularization penalty for changing those parameters. This prevents the model from "forgetting" financial knowledge from earlier training sessions while absorbing new data.
55
+
56
+ ### 3. Financial Numeracy Encoding
57
+ Standard tokenizers treat numbers as arbitrary tokens. Meridian.AI adds a 64-dimensional learned embedding specifically allocated to encode numeric magnitude signals, giving the model dedicated capacity to reason about quantities like prices, percentages, and financial ratios.
58
+
59
+ ### 4. Memory-Safe CPU Training
60
+ Every component is designed around the 16 GB RAM constraint:
61
+ - **AdaFactor** optimizer: eliminates the 2×-parameter-size optimizer state of Adam
62
+ - **Gradient checkpointing**: trades compute for activation memory
63
+ - **Soft RAM throttle**: dynamically truncates sequence length when memory pressure rises
64
+ - **Hard RAM guard**: emergency checkpoint + clean exit before OOM
65
+ - **Fisher threshold pruning**: only stores EWC state for parameters with significant Fisher values
66
+
67
+ ---
68
+
69
+ ## Architecture
70
+
71
+ | Specification | Value |
72
+ |:---|:---|
73
+ | Base Model | Qwen2.5-0.5B (continually fine-tuned) |
74
+ | Custom Arch Module | Sparse MoE Transformer (meridian/) |
75
+ | Layers | 14 (alternating Dense ↔ MoE) |
76
+ | Attention | Grouped Query Attention: 12 Q heads, 4 KV heads |
77
+ | Position Encoding | RoPE (theta=500,000) |
78
+ | Feed-Forward | SwiGLU |
79
+ | Normalization | RMSNorm |
80
+ | MoE Experts | 8 per layer, top-2 active per token |
81
+ | Vocabulary | 151,665 tokens (Qwen2.5 tokenizer) |
82
+ | Context Window | 2,048 tokens |
83
+ | Total Parameters | ~479M (tied) / ~283M unique |
84
+ | Active per Token | ~283M |
85
+ | Continual Learning | Elastic Weight Consolidation (EWC) |
86
+
87
+ Layer alternation pattern (0-indexed):
88
+ ```
89
+ Layer 0: Dense FFN
90
+ Layer 1: Sparse MoE (8 experts)
91
+ Layer 2: Dense FFN
92
+ Layer 3: Sparse MoE (8 experts)
93
+ ... (alternates for all 14 layers)
94
+ ```
95
+
96
+ For full architectural detail, see [docs/architecture.md](docs/architecture.md).
97
+
98
+ ---
99
+
100
+ ## Quick Start
101
+
102
+ ### Prerequisites
103
+ - Python 3.10+
104
+ - Git
105
+ - ~2 GB disk (for model weights)
106
+
107
+ ### Installation
108
+
109
+ ```bash
110
+ git clone https://github.com/MeridianAlgo/FinAI.git
111
+ cd FinAI
112
+ pip install -r requirements.txt
113
+ ```
114
+
115
+ ### Verify Installation (Smoke Test)
116
+
117
+ Runs a tiny in-memory model to confirm the architecture works without downloading anything:
118
+
119
+ ```bash
120
+ SMOKE_TEST=1 FAST_MODE=1 python train.py
121
+ ```
122
+
123
+ Expected output: `[OK] Smoke test passed!`
124
+
125
+ ---
126
+
127
+ ## Inference
128
+
129
+ ### From HuggingFace Hub
130
+
131
+ ```python
132
+ import torch
133
+ from transformers import AutoModelForCausalLM, AutoTokenizer
134
+
135
+ repo_id = "meridianal/FinAI"
136
+
137
+ tokenizer = AutoTokenizer.from_pretrained(repo_id, subfolder="checkpoint")
138
+ model = AutoModelForCausalLM.from_pretrained(
139
+ repo_id,
140
+ subfolder="checkpoint",
141
+ trust_remote_code=True,
142
+ torch_dtype=torch.float32,
143
+ low_cpu_mem_usage=True,
144
+ )
145
+ model.eval()
146
+
147
+ prompt = """### Instruction:
148
+ Explain the difference between a bond's yield to maturity and its coupon rate.
149
+
150
+ ### Response:
151
+ """
152
+
153
+ inputs = tokenizer(prompt, return_tensors="pt")
154
+
155
+ with torch.no_grad():
156
+ output = model.generate(
157
+ **inputs,
158
+ max_new_tokens=200,
159
+ do_sample=True,
160
+ temperature=0.8,
161
+ top_p=0.92,
162
+ repetition_penalty=1.3,
163
+ no_repeat_ngram_size=3,
164
+ pad_token_id=tokenizer.pad_token_id,
165
+ eos_token_id=tokenizer.eos_token_id,
166
+ )
167
+
168
+ print(tokenizer.decode(output[0], skip_special_tokens=True))
169
+ ```
170
+
171
+ ### From Local Checkpoint
172
+
173
+ If you have trained locally and have a `./checkpoint` directory:
174
+
175
+ ```python
176
+ from transformers import AutoModelForCausalLM, AutoTokenizer
177
+
178
+ tokenizer = AutoTokenizer.from_pretrained("./checkpoint")
179
+ model = AutoModelForCausalLM.from_pretrained("./checkpoint")
180
+ ```
181
+
182
+ See [docs/examples/01_inference.py](docs/examples/01_inference.py) for a complete, annotated script.
183
+
184
+ ---
185
+
186
+ ## Local Training
187
+
188
+ ### Full Training Run
189
+
190
+ ```bash
191
+ export HF_TOKEN=your_huggingface_token
192
+ python train.py
193
+ ```
194
+
195
+ The script will:
196
+ 1. Pull the latest checkpoint from HuggingFace (if `HF_TOKEN` is set)
197
+ 2. Load the Qwen2.5-0.5B base model (or resume from checkpoint)
198
+ 3. Stream finance datasets and train for `MAX_STEPS` steps
199
+ 4. Save checkpoint locally (and upload if token is present)
200
+
201
+ ### Fast Debugging Mode
202
+
203
+ Runs with minimal settings (no dataset streaming, 5 steps, tiny sequences):
204
+
205
+ ```bash
206
+ FAST_MODE=1 python train.py
207
+ ```
208
+
209
+ ### Custom Step Count
210
+
211
+ ```bash
212
+ MAX_STEPS=300 BATCH_SIZE=1 python train.py
213
+ ```
214
+
215
+ ---
216
+
217
+ ## Environment Variables Reference
218
+
219
+ All variables are optional. CI defaults are shown in `train.yml`.
220
+
221
+ ### Core Training
222
+
223
+ | Variable | CI Default | Description |
224
+ |:---|:---|:---|
225
+ | `MAX_STEPS` | `150` | Gradient update steps per run |
226
+ | `TOTAL_STEPS` | `100000` | Cumulative steps across all runs (for LR schedule) |
227
+ | `BATCH_SIZE` | `1` | Samples per micro-step |
228
+ | `GRAD_ACCUM` | `8` | Micro-steps before each optimizer update |
229
+ | `LEARNING_RATE` | `5e-5` | Peak learning rate |
230
+ | `BLOCK_SIZE` | `256` | Token sequence length |
231
+ | `DTYPE` | `bfloat16` | Model dtype (`bfloat16` or `float32`) |
232
+ | `OPTIMIZER` | `adafactor` | Optimizer (`adafactor` or `adamw`) |
233
+
234
+ ### Memory Management
235
+
236
+ | Variable | CI Default | Description |
237
+ |:---|:---|:---|
238
+ | `HARD_RAM_GUARD` | `1` | Enable emergency save + stop at RAM ceiling |
239
+ | `MAX_RAM_GB` | `14.5` | Hard RAM limit in GB |
240
+ | `SOFT_RAM_GB` | `12.5` | Soft limit — begins sequence truncation |
241
+ | `SOFT_RAM_PCT` | `80` | Soft limit as % of total RAM |
242
+ | `MIN_THROTTLE_SEQ_LEN` | `64` | Minimum sequence length during throttle |
243
+ | `GRADIENT_CHECKPOINTING` | `1` | Trade compute for activation memory |
244
+ | `SKIP_OPTIMIZER_SAVE` | `1` | Omit 2GB+ optimizer state from checkpoint |
245
+
246
+ ### Dataset
247
+
248
+ | Variable | CI Default | Description |
249
+ |:---|:---|:---|
250
+ | `MAX_BYTES` | `15728640` (15 MB) | Max training data per run |
251
+ | `USE_LIGHT_DATASETS` | `0` | Restrict to small/fast datasets only |
252
+
253
+ ### EWC (Continual Learning)
254
+
255
+ | Variable | CI Default | Description |
256
+ |:---|:---|:---|
257
+ | `USE_EWC` | `1` | Enable Elastic Weight Consolidation |
258
+ | `EWC_LAMBDA` | `500.0` | EWC regularization strength |
259
+ | `EWC_SAMPLES` | `5` | Batches used to estimate Fisher matrix |
260
+ | `SKIP_FISHER` | `0` | Skip Fisher computation (disables EWC next run) |
261
+ | `FREE_OPTIMIZER_BEFORE_FISHER` | `1` | Free optimizer RAM before Fisher computation |
262
+ | `FISHER_SEQ_LEN` | `64` | Sequence length used during Fisher estimation |
263
+ | `FISHER_THRESHOLD` | `1e-6` | Drop Fisher entries below this value |
264
+
265
+ ### Paths & Misc
266
+
267
+ | Variable | Default | Description |
268
+ |:---|:---|:---|
269
+ | `CHECKPOINT_PATH` | `./checkpoint` | Local checkpoint directory |
270
+ | `TOKENIZER_ID` | `Qwen/Qwen2.5-0.5B` | HuggingFace tokenizer ID |
271
+ | `FAST_MODE` | `0` | Minimal config for quick local debugging |
272
+ | `SMOKE_TEST` | `0` | Run tiny in-memory architecture test |
273
+ | `GC_EVERY_STEPS` | `5` | Python GC frequency (steps) |
274
+ | `DEBUG_STEPS` | `0` | Print verbose per-step debug info |
275
+ | `COMET_API_KEY` | *(unset)* | Comet ML experiment tracking key |
276
+
277
+ ---
278
+
279
+ ## CI/CD Training Pipeline
280
+
281
+ ```
282
+ Every hour (GitHub Actions cron: '0 * * * *')
283
+ │
284
+ ├── Pull checkpoint from HuggingFace Hub
285
+ │ meridianal/FinAI → ./checkpoint/
286
+ │
287
+ ├── Train (timeout: 90 minutes)
288
+ │ • Load Qwen2.5-0.5B (or resume checkpoint)
289
+ │ • Stream finance datasets (weighted curriculum mix)
290
+ │ • 150 AdaFactor steps with gradient checkpointing
291
+ │ • EWC regularization (prevent forgetting)
292
+ │ • Auto-throttle sequence length if RAM > 12.5 GB
293
+ │ • Emergency save + exit if RAM > 14.5 GB
294
+ │
295
+ ├── Upload checkpoint to HuggingFace Hub
296
+ │ ./checkpoint/ → meridianal/FinAI/checkpoint/
297
+ │
298
+ └── Sync dataset state to git
299
+ dataset_state.json → main branch
300
+ ```
301
+
302
+ ### Failure Handling
303
+ If training encounters >50 `[ERROR]` lines or any fatal pattern (OOM, NaN explosion), the CI workflow automatically opens a GitHub Issue with the error details and a diagnostic checklist.
304
+
305
+ ### Triggering a Manual Run
306
+ From the GitHub Actions tab, click **Meridian.AI Train** → **Run workflow**. You can override `MAX_STEPS` at dispatch time.
307
+
308
+ ### Force Reset (Nuke & Seed)
309
+ To wipe the HuggingFace checkpoint and restart training from a fresh Qwen2.5-0.5B:
310
+
311
+ Run workflow with **force_seed: true**. This runs `scripts/seed_hf_repo.py` before training.
312
+
313
+ ---
314
+
315
+ ## Dataset Curriculum
316
+
317
+ Training data is a weighted mix of finance-focused HuggingFace datasets, streamed in real-time (no full downloads):
318
+
319
+ | Dataset | Weight | Focus |
320
+ |:---|:---|:---|
321
+ | `gbharti/finance-alpaca` | 30% | Financial Q&A instructions |
322
+ | `nvidia/OpenMathInstruct-2` | 25% | Math reasoning (critical for quantitative finance) |
323
+ | `HuggingFaceFW/fineweb-edu` | 20% | General knowledge foundation |
324
+ | `FinanceMTEB/financial_phrasebank` | 1% | Sentiment classification |
325
+ | `FinanceMTEB/FinQA` | 1% | Financial QA pairs |
326
+ | `FinanceMTEB/TATQA` | 1% | Table-and-text QA |
327
+ | `FinanceMTEB/FOMC` | 0.8% | FOMC meeting transcripts |
328
+ | Various FinanceMTEB | ~20% | Sentiment, ESG, fraud, FLS, events, and more |
329
+
330
+ All text is formatted into the `### Instruction: / ### Response:` template before tokenization.
331
+
332
+ See [docs/training_pipeline.md](docs/training_pipeline.md) for full dataset details.
333
+
334
+ ---
335
+
336
+ ## Repository Structure
337
+
338
+ ```
339
+ FinAI/
340
+ ├── meridian/
341
+ │ ├── model/
342
+ │ │ ├── configuration.py # MeridianConfig (HF PretrainedConfig)
343
+ │ │ └── modeling.py # Full model: RMSNorm, RoPE, GQA, SwiGLU, SMoE
344
+ │ ├── data/
345
+ │ │ └── pipeline.py # Streaming dataset curriculum + DataLoader
346
+ │ └── training/
347
+ │ ├── trainer.py # MeridianTrainer (AdaFactor, EWC, RAM guards)
348
+ │ └── ewc.py # Elastic Weight Consolidation
349
+ │
350
+ ├── scripts/
351
+ │ ├── seed_hf_repo.py # Nuke & reseed HuggingFace repo
352
+ │ ├── evaluate_model.py # Evaluation utilities
353
+ │ ├── hf_download_and_test.py # Download checkpoint and run test generation
354
+ │ └── count_params.py # Parameter counting utility
355
+ │
356
+ ├── docs/
357
+ │ ├── architecture.md # Detailed architecture specification
358
+ │ ├── training_pipeline.md # Pipeline, env vars, memory management
359
+ │ ├── setup_and_usage.md # Setup guide and inference examples
360
+ │ └── examples/
361
+ │ ├── 01_inference.py # HuggingFace inference example
362
+ │ ├── 02_dataset_pipeline.py # Dataset streaming walkthrough
363
+ │ └── 03_model_config.py # Direct architecture instantiation
364
+ │
365
+ ├── tests/
366
+ │ ├── test_model.py # Architecture unit tests
367
+ │ └── test_training.py # Trainer and EWC tests
368
+ │
369
+ ├── .github/
370
+ │ └── workflows/
371
+ │ ├── train.yml # Hourly training CI
372
+ │ ├── lint.yml # Ruff + Black linting
373
+ │ └── dependency-cache.yml
374
+ │
375
+ ├── train.py # Main training entry point
376
+ ├── requirements.txt # Python dependencies
377
+ └── pyproject.toml # Ruff + Black + mypy config
378
+ ```
379
+
380
+ ---
381
+
382
+ ## Troubleshooting
383
+
384
+ ### `trust_remote_code=True` warning
385
+ Meridian.AI uses a custom model architecture registered with HuggingFace. Passing `trust_remote_code=True` is required when loading with `AutoModelForCausalLM`. This is safe — it executes code from the repo you explicitly specify.
386
+
387
+ ### `OOM / RuntimeError: [enforce fail]` during training
388
+ Reduce memory usage:
389
+ ```bash
390
+ BATCH_SIZE=1 GRAD_ACCUM=8 BLOCK_SIZE=128 SOFT_RAM_GB=10.0 python train.py
391
+ ```
392
+
393
+ ### Checkpoint architecture mismatch warning
394
+ If you see `[WARN] Checkpoint architecture mismatch (old model)`, the saved `config.json` has `model_type` that doesn't match Qwen2/Llama. The checkpoint will be discarded and training restarts from the base model. This is expected when switching base architectures.
395
+
396
+ ### EWC shape mismatch warning
397
+ `[WARN] EWC: Dropped N params due to shape/name mismatch` appears when the model architecture changed between runs. EWC state for mismatched layers is safely dropped; valid parameters are kept. Training continues normally.
398
+
399
+ ### NaN loss
400
+ Usually caused by extreme learning rates or corrupted data batches. The trainer automatically skips batches with NaN loss or NaN gradients. If persistent, try:
401
+ ```bash
402
+ LEARNING_RATE=1e-5 USE_EWC=0 python train.py
403
+ ```
404
+
405
+ ### Slow training on CPU
406
+ Expected — these are CPU-only GitHub runners. With `BATCH_SIZE=1 BLOCK_SIZE=256 MAX_STEPS=150`, expect ~30–60 minutes per run. This fits the 90-minute CI timeout.
407
+
408
+ ---
409
+
410
+ ## Contributing
411
+
412
+ 1. Run the test suite before submitting: `pytest tests/ -v`
413
+ 2. Format with black: `black .`
414
+ 3. Lint with ruff: `ruff check . --fix`
415
+ 4. Keep all code pure Python — no unnecessary system dependencies
416
+ 5. Submit PRs against `main` with clear commit messages following conventional commits format
417
+
418
+ ---
419
+
420
+ ## Disclaimer
421
+
422
+ Meridian.AI is an experimental research project on continual learning for financial NLP. All model outputs are strictly for academic and research purposes. **Nothing generated by this model constitutes financial advice. Do not use outputs to make real financial decisions or execute trades.**
checkpoint/added_tokens.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "</tool_call>": 151658,
3
+ "<tool_call>": 151657,
4
+ "<|box_end|>": 151649,
5
+ "<|box_start|>": 151648,
6
+ "<|endoftext|>": 151643,
7
+ "<|file_sep|>": 151664,
8
+ "<|fim_middle|>": 151660,
9
+ "<|fim_pad|>": 151662,
10
+ "<|fim_prefix|>": 151659,
11
+ "<|fim_suffix|>": 151661,
12
+ "<|im_end|>": 151645,
13
+ "<|im_start|>": 151644,
14
+ "<|image_pad|>": 151655,
15
+ "<|object_ref_end|>": 151647,
16
+ "<|object_ref_start|>": 151646,
17
+ "<|quad_end|>": 151651,
18
+ "<|quad_start|>": 151650,
19
+ "<|repo_name|>": 151663,
20
+ "<|video_pad|>": 151656,
21
+ "<|vision_end|>": 151653,
22
+ "<|vision_pad|>": 151654,
23
+ "<|vision_start|>": 151652
24
+ }
checkpoint/chat_template.jinja ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {%- if tools %}
2
+ {{- '<|im_start|>system\n' }}
3
+ {%- if messages[0]['role'] == 'system' %}
4
+ {{- messages[0]['content'] }}
5
+ {%- else %}
6
+ {{- 'You are a helpful assistant.' }}
7
+ {%- endif %}
8
+ {{- "\n\n# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }}
9
+ {%- for tool in tools %}
10
+ {{- "\n" }}
11
+ {{- tool | tojson }}
12
+ {%- endfor %}
13
+ {{- "\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call><|im_end|>\n" }}
14
+ {%- else %}
15
+ {%- if messages[0]['role'] == 'system' %}
16
+ {{- '<|im_start|>system\n' + messages[0]['content'] + '<|im_end|>\n' }}
17
+ {%- else %}
18
+ {{- '<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n' }}
19
+ {%- endif %}
20
+ {%- endif %}
21
+ {%- for message in messages %}
22
+ {%- if (message.role == "user") or (message.role == "system" and not loop.first) or (message.role == "assistant" and not message.tool_calls) %}
23
+ {{- '<|im_start|>' + message.role + '\n' + message.content + '<|im_end|>' + '\n' }}
24
+ {%- elif message.role == "assistant" %}
25
+ {{- '<|im_start|>' + message.role }}
26
+ {%- if message.content %}
27
+ {{- '\n' + message.content }}
28
+ {%- endif %}
29
+ {%- for tool_call in message.tool_calls %}
30
+ {%- if tool_call.function is defined %}
31
+ {%- set tool_call = tool_call.function %}
32
+ {%- endif %}
33
+ {{- '\n<tool_call>\n{"name": "' }}
34
+ {{- tool_call.name }}
35
+ {{- '", "arguments": ' }}
36
+ {{- tool_call.arguments | tojson }}
37
+ {{- '}\n</tool_call>' }}
38
+ {%- endfor %}
39
+ {{- '<|im_end|>\n' }}
40
+ {%- elif message.role == "tool" %}
41
+ {%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != "tool") %}
42
+ {{- '<|im_start|>user' }}
43
+ {%- endif %}
44
+ {{- '\n<tool_response>\n' }}
45
+ {{- message.content }}
46
+ {{- '\n</tool_response>' }}
47
+ {%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
48
+ {{- '<|im_end|>\n' }}
49
+ {%- endif %}
50
+ {%- endif %}
51
+ {%- endfor %}
52
+ {%- if add_generation_prompt %}
53
+ {{- '<|im_start|>assistant\n' }}
54
+ {%- endif %}
checkpoint/config.json ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "Qwen2ForCausalLM"
4
+ ],
5
+ "attention_dropout": 0.0,
6
+ "bos_token_id": 151643,
7
+ "dtype": "bfloat16",
8
+ "eos_token_id": 151643,
9
+ "hidden_act": "silu",
10
+ "hidden_size": 896,
11
+ "initializer_range": 0.02,
12
+ "intermediate_size": 4864,
13
+ "layer_types": [
14
+ "full_attention",
15
+ "full_attention",
16
+ "full_attention",
17
+ "full_attention",
18
+ "full_attention",
19
+ "full_attention",
20
+ "full_attention",
21
+ "full_attention",
22
+ "full_attention",
23
+ "full_attention",
24
+ "full_attention",
25
+ "full_attention",
26
+ "full_attention",
27
+ "full_attention",
28
+ "full_attention",
29
+ "full_attention",
30
+ "full_attention",
31
+ "full_attention",
32
+ "full_attention",
33
+ "full_attention",
34
+ "full_attention",
35
+ "full_attention",
36
+ "full_attention",
37
+ "full_attention"
38
+ ],
39
+ "max_position_embeddings": 32768,
40
+ "max_window_layers": 24,
41
+ "model_type": "qwen2",
42
+ "num_attention_heads": 14,
43
+ "num_hidden_layers": 24,
44
+ "num_key_value_heads": 2,
45
+ "pad_token_id": null,
46
+ "rms_norm_eps": 1e-06,
47
+ "rope_parameters": {
48
+ "rope_theta": 1000000.0,
49
+ "rope_type": "default"
50
+ },
51
+ "sliding_window": null,
52
+ "tie_word_embeddings": true,
53
+ "transformers_version": "5.7.0",
54
+ "use_cache": false,
55
+ "use_mrope": false,
56
+ "use_sliding_window": false,
57
+ "vocab_size": 151936
58
+ }
checkpoint/dataset_state.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"processed_items": 46640}
checkpoint/ewc_state.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6bc9d9ba29fb11732fad0fb6e91d09dc707d149c75f09e9e03948b1396e40d20
3
+ size 1976241163
checkpoint/generation_config.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token_id": 151643,
3
+ "do_sample": false,
4
+ "eos_token_id": 151643,
5
+ "max_new_tokens": 2048,
6
+ "transformers_version": "5.7.0"
7
+ }
checkpoint/merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
checkpoint/model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:aae7487291eb95a6a08a4f6cb04d4b2efe882c4d8b6543161d9378457025a75c
3
+ size 988097824
checkpoint/pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b7af2c292bbd3a110ba528662bcc2a969a5b2dcfe83a42bd69fdc9c9c55a29f0
3
+ size 988158930
checkpoint/special_tokens_map.json ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "additional_special_tokens": [
3
+ "<|im_start|>",
4
+ "<|im_end|>",
5
+ "<|object_ref_start|>",
6
+ "<|object_ref_end|>",
7
+ "<|box_start|>",
8
+ "<|box_end|>",
9
+ "<|quad_start|>",
10
+ "<|quad_end|>",
11
+ "<|vision_start|>",
12
+ "<|vision_end|>",
13
+ "<|vision_pad|>",
14
+ "<|image_pad|>",
15
+ "<|video_pad|>"
16
+ ],
17
+ "eos_token": {
18
+ "content": "<|endoftext|>",
19
+ "lstrip": false,
20
+ "normalized": false,
21
+ "rstrip": false,
22
+ "single_word": false
23
+ },
24
+ "pad_token": {
25
+ "content": "<|endoftext|>",
26
+ "lstrip": false,
27
+ "normalized": false,
28
+ "rstrip": false,
29
+ "single_word": false
30
+ }
31
+ }
checkpoint/tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:716ec13e363ec927a345aa1d39bb8ed88a0ce7fadcdef14509b1f2afd64a8bee
3
+ size 11421990
checkpoint/tokenizer_config.json ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "backend": "tokenizers",
4
+ "bos_token": null,
5
+ "clean_up_tokenization_spaces": false,
6
+ "eos_token": "<|endoftext|>",
7
+ "errors": "replace",
8
+ "extra_special_tokens": {},
9
+ "is_local": false,
10
+ "local_files_only": false,
11
+ "model_max_length": 131072,
12
+ "pad_token": "<|endoftext|>",
13
+ "split_special_tokens": false,
14
+ "tokenizer_class": "Qwen2Tokenizer",
15
+ "unk_token": null
16
+ }
checkpoint/trainer_state.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:44a36b07cbc7aef1d2ee99e5fe7ba6f784fa5a5b5966634e88b32c949e883de4
3
+ size 1361
checkpoint/vocab.json ADDED
The diff for this file is too large to render. See raw diff