AsemLLM
Small language models written from scratch in Common Lisp (SBCL) and trained on one laptop CPU. No deep-learning framework was used. The transformer, backpropagation, the Adam optimizer, the BPE tokenizer and the FineWeb-Edu data pipeline are all hand-written Lisp; Apple Accelerate is used only for matrix products.
This repository holds the current release, AsemLLM-97M: the weights (model.safetensors), config.json, the
tokenizer (tokenizer.bpe) and a NumPy reference implementation (asemllm.py), so the model runs without Lisp. The
previous release, AsemLLM-27M, is kept in previous/AsemLLM-27M/.
This is a research model, not an assistant. It writes fluent-looking English that is often not meaningful or true, and it was not instruction-tuned or safety-tuned. Do not use it where correct or safe output matters.
Model details
| Developed by | Asem Qaffaf |
| Model type | decoder-only transformer language model, trained from scratch (no base model) |
| Language | English |
| License | Apache-2.0 |
| Release | AsemLLM-97M, 2026-11-25: the 97.64M base model of the project's Stage-3 Exp 5b |
| Previous release | AsemLLM-27M (2026-11-23), in previous/AsemLLM-27M/ |
| Raw artifacts and experiment records | asemqaffaf/AsemLLM-runs |
Architecture
| Parameters | 97,636,225 (85,053,313 without the token embedding and the output matrix) |
| Layers, width, heads | 12 layers, width 768, 12 heads of size 64 |
| Block | pre-RMSNorm (ε 1e-5) → causal self-attention → residual; pre-RMSNorm → MLP 768 → 3,072 → 768 with ReLU → residual. Linear layers have no biases |
| Positions | learned absolute position embeddings, plus learned relative-position attention biases for distances 0–7 (one per distance, head and layer) |
| Output head | final RMSNorm, then logits = h·W_head + g·h·E_tokᵀ: an untied output matrix plus a tied "copy" path through the token embeddings, scaled by one learned scalar g |
| Context | 128 tokens |
| Tokenizer | byte-level BPE with 8,192 tokens: id 0 = `< |
| Precision | FP32 weights; asemllm.py computes in FP64 by default |
Uses
Direct use. Studying how small language models behave and how training choices affect them; teaching and reading a complete, framework-free implementation; a baseline for other from-scratch or CPU-only training work.
Out of scope. Anything that relies on correct, safe or factual output: question answering, advice, summaries of real content, any user-facing product. The model also cannot follow instructions or hold a conversation.
Bias, risks and limitations
- Small and undertrained: 97.6M parameters trained on 1.77 tokens per parameter. Compute-optimal training would use about 20 tokens per parameter.
- Often not meaningful: text is often incoherent, and statements are often false. On a 90-question four-option test it scores 38.89%, above chance (25%) but far from reliable.
- Narrow data: English educational web text only (FineWeb-Edu, filtered by an educational-quality classifier), so it reflects that source's topics, style and biases. Other languages tokenize correctly but were barely seen.
- No safety tuning: nothing stops it from producing offensive or harmful text present in web data.
- Short context: 128 tokens.
How to get started
pip install numpy huggingface_hub
huggingface-cli download asemqaffaf/AsemLLM --local-dir AsemLLM --exclude "previous/*"
cd AsemLLM
python asemllm.py --prompt "The history of science" --max-new-tokens 40 --seed 1
from asemllm import AsemLLM
m = AsemLLM(".") # loads config.json, model.safetensors, tokenizer.bpe
print(m.generate("The history of science", max_new_tokens=40, temperature=0.8, top_k=40, seed=1))
ids = m.tokenizer.encode("Hello world") # list of token ids
logits = m.logits(ids) # NumPy array, (len(ids), 8192)
asemllm.py needs only NumPy. The architecture is custom, so the model does not load in transformers,
llama.cpp, Ollama or LM Studio. The previous release runs the same way: AsemLLM("previous/AsemLLM-27M").
Sample output of the command above (40 new tokens, temperature 0.8, top-k 40, seed 1), shown as it is:
The history of science is changing, says Wong. The work was funded by the National Science Foundation. Remote sensing is the first technology to be developed for use on a wide variety of
Training details
Training data
FineWeb-Edu: the project's Stage-2 documents followed by
new documents from FineWeb-Edu sample/100BT, filtered by the project's own Lisp pipeline:
| Filters | educational score ≥ 4.0, language score ≥ 0.95, exact and near-duplicate removal |
| Documents | 189,886 read, 149,724 kept (32,422 exact duplicates, 7,198 near-duplicates and 542 others removed) |
| Training split | 182,797,952 tokens |
| Held out | validation 968,651 tokens and test 915,534 tokens (0.5% of documents each) |
The Stage-2 training, validation and test splits (used for AsemLLM-27M) are exact prefixes of these splits, so the validation split of the headline result is the one AsemLLM-27M was scored on.
Training procedure
| Steps | 42,250 steps × 32 sequences × 128 tokens = 173,056,000 tokens (0.95 epoch) |
| Optimizer | Adam (β₁ 0.9, β₂ 0.95, ε 1e-8), no weight decay |
| Learning rate | peak 4e-4, 400 linear warmup steps, cosine decay to 10% of peak |
| Other | gradient clipping at norm 1.0, seed 1, 4 worker threads |
| Precision | FP32. The FP32 engine is generated from the FP64 source code by a Lisp program |
| Checkpoint | best.ckpt, the checkpoint the experiment's verifier scored. The lowest in-training validation loss was at the last step, so it holds the same weights as last.ckpt (step 42,250) |
The experiment ran under a protocol frozen before the run, with its files pinned by SHA-256, and with stop rules for
instability registered in advance; none fired. A first attempt at a learning rate of 1e-3 (Exp 5) was unstable
(gradient norm up to 86) and was stopped at step 5,300; this run changed only the learning rate. Two engine speed-ups
made during the run were proved bit-identical before use. The run was paused and resumed several times and once
restarted from a saved state; every resume reproduced the original losses exactly. The protocol, amendments, scorecard
and completion record are in AsemLLM-runs under docs/results/stage3/exp5b-pretrain-100m-lr4e-4-20261122/.
Speed and size
| Training time | about 48.5 h of computation (62.8 h from start to end, including 14.2 h of pauses) |
| Throughput | about 990 tokens/s while running (3.4–3.6 s per step on an otherwise idle machine) |
| Peak memory | 4.3 GiB (operating-system maximum resident set size) |
| Checkpoint size | 391 MB |
Evaluation
| metric | data | result |
|---|---|---|
| Cross-entropy | full Stage-2 FineWeb-Edu validation split (269,696 tokens) | 3.2936 nats/token |
| Perplexity | same | 26.94 |
| Cross-entropy / perplexity | full validation split of this run's corpus (968,576 tokens) | 3.3310 / 27.97 |
| Accuracy | asem_eval_90: 90 four-option questions (30 fact, 30 reading, 30 reasoning); chance 25% |
38.89% (35 of 90): fact 36.7%, reading 50.0%, reasoning 30.0% |
| In-context copying | C5 probe: repeated random token sequences, four token pools (U / E / BASE / T) | 9.6 / 8.7 / 16.6 / 38.8% |
The question score is above chance (95% Wilson interval 29.5–49.2%; one-sided binomial p = 0.0025 against 25%, computed after the run, not a pre-registered test), but 90 questions is a small test.
Compared with AsemLLM-27M
| AsemLLM-27M | AsemLLM-97M | |
|---|---|---|
| Validation loss / perplexity (same 269,696-token split) | 4.2718 / 71.65 | 3.2936 / 26.94 |
asem_eval_90 |
27.78% | 38.89% |
| C5 copying, U / E / BASE / T | about 0 / 0 / 0.02 / 0.06% | 9.6 / 8.7 / 16.6 / 38.8% |
The experiment's pre-registered verdict is improved (threshold: validation loss ≤ 4.1718). The difference is not due to size alone: the learning rate (2e-3 → 4e-4), warmup (200 → 400), head size (48 → 64) and the amount of data (48.9M → 173.1M training tokens) also changed. It is one run with one seed.
Verification of this release
asemllm.py re-implements the model in NumPy, so it was checked against the Lisp engine that trained it. Anyone can
re-run the check with NumPy alone:
huggingface-cli download asemqaffaf/AsemLLM --local-dir AsemLLM --exclude "previous/*" && cd AsemLLM
python verify/check.py . verify/reference-97m.json
| check | result |
|---|---|
| Tokenizer on 4 texts (English; whitespace, digits and punctuation; accented Latin; Greek and Japanese) | token ids identical to the Lisp tokenizer; decoding returns each text exactly |
| Logits at all 17 positions of a 17-token sentence, 8,192 tokens each | maximum relative difference 2.9e-15 (FP64 on both sides); same top token at every position |
| Weights | model.safetensors SHA-256 9adadeb73e036d4105b329cf18670541ec0354280202e83b9e961557c27e2f9e, exported from data/runs/stage3/exp5-100m/exp5b/run/best.ckpt in AsemLLM-runs (SHA-256 8b5be33cfc74a6d53ba00a1ac879ba92239811fde9f5e85a46d19eeb07386763) |
The same check for the previous release: python verify/check.py previous/AsemLLM-27M verify/reference-27m.json
(result 4.9e-15). verify/lisp_reference.lisp is the Lisp program that wrote both reference files.
tools/export_safetensors.py converts the trainer's .ckpt files (one JSON header line, then FP32 little-endian
tensors) to this format.
Environmental impact
| Hardware | one Apple M1 Pro laptop (8 performance + 2 efficiency cores, 16 GB), CPU only; 4 worker threads |
| Training time | about 48.5 hours of computation |
| Energy | about 1.5–2 kWh (estimate: 48.5 h at about 30–40 W for the whole laptop; not measured) |
| Cloud | none |
Technical specifications
| Software | SBCL 2.6.10 (Common Lisp) on macOS; Apple Accelerate (BLAS) for matrix products; no Python in training |
| Inference | asemllm.py: Python 3 + NumPy |
| file | contents |
|---|---|
model.safetensors |
weights, 102 FP32 tensors, 391 MB |
config.json |
architecture and provenance (source checkpoint SHA-256, training step, data version) |
tokenizer.bpe |
BPE merges (format asem-bpe 1) |
asemllm.py |
NumPy reference implementation: tokenizer, forward pass, sampling |
verify/ |
the Lisp-vs-NumPy check: check.py, reference-97m.json, reference-27m.json, lisp_reference.lisp |
tools/export_safetensors.py |
.ckpt → safetensors converter |
previous/AsemLLM-27M/ |
the previous release: model.safetensors (110 MB), config.json, tokenizer.bpe |
The AsemLLM project
| stage | what | main result |
|---|---|---|
| Stage 1 | 1.16M, 2.90M and 10.52M models pretrained on the same 29.9M FineWeb-Edu tokens | test perplexity 112.4, 87.8, 80.8; none above chance on the 90 questions |
| Stage 2 | the 10.52M model fine-tuned for passage QA (R7) | 45.8% (229/500) on a four-option development set; a word-overlap rule scores 62.0% |
| Stage 2, Exp1–22 | what fine-tuning breaks | fine-tuning destroys in-context copying for tokens absent from the fine-tuning data (97% → 0%); a row gate on Adam's steps, early learning-rate decay and an L2 anchor recover about 93% |
| Stage 3 | scaling the base model | 27.58M base (AsemLLM-27M); copy and QA phases on it end below R7 (Dev QA 29.2%); 97.64M at lr 1e-3 was unstable and stopped; 97.64M at lr 4e-4 (this release): validation perplexity 26.94 |
| Stage 3, Exp 6 | copy phases and QA chain on the 97.64M base (a research checkpoint, not this release) | Dev QA 59.4% (297/500), above R7's 45.8% and below the 62.0% word-overlap rule; ordinary language modelling is lost |
Every experiment has a frozen protocol, pinned hashes, gate records and a completion record. They are all in
AsemLLM-runs under docs/, next to the raw data. The QA test set
has never been used to score a model; its generator was publicly downloadable from that repository until 2026-11-27, so
the set can no longer be assumed unseen by others.
Related repositories
| repository | contents |
|---|---|
| asemqaffaf/AsemLLM (this one) | the current release and the previous one |
| asemqaffaf/AsemLLM-runs | every checkpoint (including R7), log, probe and evaluation output, the pretraining data, and the experiment records under docs/ |
| asemqaffaf/AsemLLM-erlang-archive | the original Erlang AsemLLM (archived) |
History of this repository: until 2026-11-23 it hosted the original Erlang AsemLLM, whose files are now in AsemLLM-erlang-archive; the Erlang commits remain in this repository's history. Downloads and likes from before that date are of the Erlang model. AsemLLM-27M was the release from 2026-11-23 to 2026-11-25.
Citation
@misc{qaffaf2026asemllm,
author = {Asem Qaffaf},
title = {AsemLLM: small language models written from scratch in Common Lisp},
year = {2026},
howpublished = {\url{https://huggingface.co/asemqaffaf/AsemLLM}}
}
Model card contact
Asem Qaffaf, through this repository's Community tab.
License
Apache-2.0.