File size: 3,604 Bytes
deda58d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1504cba
1
2
3
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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
104
105
106
107
108
109
# UltraSparse

**UltraSparse — CPU adaptive causal language model**

A small, reproducible PyTorch language model designed for CPU experimentation. The model combines:

1. a ~10M-parameter Transformer,
2. SentencePiece BPE tokenization,
3. adaptive depth at inference,
4. a current-token difficulty head,
5. a short-horizon future-demand head,
6. a persistent computation ledger across autoregressive decoding,
7. strict zero-debt compute control,
8. matched-budget benchmarking and quality gates.

### Important positioning

This is an experimental/educational language model, not a state-of-the-art LLM and not instruction tuned. The persistent computation ledger is a project design feature; do not describe it as novel without a formal literature review.

## Build

```powershell

python -m pip install -r requirements.txt



python train_tokenizer.py `

  --text data\corpus.txt `

  --out artifacts\tokenizer `

  --vocab-size 1024



python train.py `

  --text data\corpus.txt `

  --tokenizer artifacts\tokenizer.model `

  --steps 20000 `

  --batch-size 2 `

  --seq-len 256 `

  --threads 8 `

  --out results\ultrasparse_v4_10m.pt

```

### First do a smoke test

```powershell

python train.py --steps 20 --batch-size 1 --seq-len 64 --threads 4 `

  --out results\smoke_v4.pt



python -m pytest -q

```

Do not start a 20k-step CPU run until the smoke test passes.

## Evaluate

```powershell

python evaluate.py `

  --checkpoint results\ultrasparse_v4_10m.pt `

  --text data\corpus.txt



python quality_gate.py `

  --checkpoint results\ultrasparse_v4_10m.pt

```

## Generate

```powershell

python generate.py `

  --checkpoint results\ultrasparse_v4_10m.pt `

  --prompt "It was a beautiful morning" `

  --tokens 150 `

  --policy predictive_ledger `

  --temperature 0.8 `

  --top-k 40 `

  --top-p 0.9

```

## Benchmark

```powershell

python benchmark.py `

  --checkpoint results\ultrasparse_v4_10m.pt `

  --tokens 128 `

  --threads 8

```

Benchmark every policy at the same budget. Report quality and compute together; never claim a speed improvement from a single timing run.

## Release checklist

- [ ] tokenizer artifact committed
- [ ] checkpoint loads from a clean environment
- [ ] tests pass
- [ ] quality gate passes
- [ ] train/validation/test split documented
- [ ] benchmark JSON committed
- [ ] parameter count measured
- [ ] CPU hardware and thread count recorded
- [ ] training corpus provenance recorded
- [ ] model card states limitations
- [ ] no API keys or secrets in repository

\n## Senior-engineering design decisions\n\n
- **RoPE instead of a learned absolute position table:** avoids the old positional-index failure mode when context is clipped and keeps positional parameters out of the model.
- **Pre-normalized residual blocks:** stable training and clean layer-prefix execution.
- **Tied input/output embeddings:** reduces parameters and keeps the small model focused on transformer capacity.
- **First-block probe + continuation:** the adaptive inference path does not intentionally execute the first block twice.
- **Zero-debt ledger:** a policy cannot borrow future compute; overspend attempts are counted and forced down to the highest legal depth.
- **Separate v3 baseline:** the old byte-token model remains useful as a historical baseline; v4 is trained from scratch because changing tokenization changes the embedding/output shapes.
- **Reproducibility first:** fixed seeds, saved tokenizer, config, optimizer/scheduler state, benchmark JSON, and quality gate.