--- license: apache-2.0 language: - en pipeline_tag: text-generation datasets: - HuggingFaceFW/fineweb-edu tags: - text-generation - causal-lm - decoder-only - transformer - from-scratch - common-lisp - sbcl - cpu-training - apple-silicon - small-language-model - research model-index: - name: AsemLLM-27M results: - task: type: text-generation name: Language modeling dataset: name: FineWeb-Edu (filtered, held-out validation split, 269,696 tokens) type: HuggingFaceFW/fineweb-edu split: validation metrics: - type: perplexity value: 71.65 name: Validation perplexity - type: loss value: 4.2718 name: Validation cross-entropy (nats per token) --- # 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-27M**: the weights (`model.safetensors`), `config.json`, the tokenizer (`tokenizer.bpe`) and a NumPy reference implementation (`asemllm.py`), so the model runs without Lisp. > **This is a research model, not an assistant.** It writes English that looks fluent but is mostly not meaningful, > 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-27M, 2026-11-23: the 27.58M base model of the project's Stage-3 Exp 2 | | Next release | a 97.64M base model (Stage-3 Exp 5b) is training; it will replace this release if it passes its verifier | | Raw artifacts and experiment records | [asemqaffaf/AsemLLM-runs](https://huggingface.co/asemqaffaf/AsemLLM-runs) | ### Architecture | | | |---|---| | Parameters | 27,584,641 (21,293,441 non-embedding) | | Layers, width, heads | 12 layers, width 384, 8 heads of size 48 | | Block | pre-RMSNorm (ε 1e-5) → causal self-attention → residual; pre-RMSNorm → MLP 384 → 1,536 → 384 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 = `<|endoftext|>`, ids 1–256 = raw bytes, 257–8,191 = merges. Any UTF-8 text round-trips exactly. Learned on the project's Stage-1 FineWeb-Edu corpus | | 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:** 27.6M parameters trained on 1.8 tokens per parameter. Compute-optimal training would use about 20 tokens per parameter. - **Mostly not meaningful:** text is often incoherent, and statements are often false. On a 90-question four-option test it scores 27.78%, close to chance (25%). - **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 ```bash pip install numpy huggingface_hub huggingface-cli download asemqaffaf/AsemLLM --local-dir AsemLLM cd AsemLLM python asemllm.py --prompt "The history of science" --max-new-tokens 40 --seed 1 ``` ```python 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. **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 and astronomy, including the “song with a single” and “first-subjections” and then created that > the most important feature of the ancient scientific method has to be used. ## Training details ### Training data [FineWeb-Edu](https://huggingface.co/datasets/HuggingFaceFW/fineweb-edu), filtered by the project's own Lisp pipeline: | | | |---|---| | Filters | educational score ≥ 4.0, language score ≥ 0.95, near-duplicate removal | | Training split | 40,425 documents, 48,893,176 tokens | | Held out | validation 269,807 tokens and test 234,621 tokens (0.5% of documents each) | ### Training procedure | | | |---|---| | Steps | 11,936 steps × 32 sequences × 128 tokens = 48,889,856 tokens (one epoch) | | Optimizer | Adam (β₁ 0.9, β₂ 0.95, ε 1e-8), no weight decay | | Learning rate | peak 2e-3, 200 linear warmup steps, cosine decay to 10% of peak | | Other | gradient clipping at norm 1.0, seed 1 | | Precision | FP32. The FP32 engine is generated from the FP64 source code by a Lisp program | | Checkpoint | the last step (`last.ckpt`); this is the checkpoint the experiment's verifier scored | The experiment ran under a protocol frozen before the run, with its files pinned by SHA-256. The protocol, gate records and scorecard are in AsemLLM-runs under `docs/results/stage3/exp2-pretrain-25m-20261120/`. ### Speed and size | | | |---|---| | Wall time | 19,723 s (5.5 h) | | Throughput | 2,479 tokens/s | | Peak memory | 1.8 GB | | Checkpoint size | 110 MB | ## Evaluation | metric | data | result | |---|---|---| | Cross-entropy | full FineWeb-Edu validation split (269,696 tokens) | **4.2718 nats/token** | | Perplexity | same | **71.65** | | Accuracy | `asem_eval_90`: 90 four-option questions (30 fact, 30 reading, 30 reasoning); chance 25% | 27.78% (25 of 90): fact 23.3%, reading 33.3%, reasoning 26.7% | | In-context copying | C5 probe: repeated random token sequences | about 0% | The question score is close to chance: at this size and data budget the model has not learned to answer questions. The copy probe fails too: the base model does not copy arbitrary token sequences from its context. ## 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: ```bash huggingface-cli download asemqaffaf/AsemLLM --local-dir AsemLLM && cd AsemLLM python verify/check.py . verify/reference-27m.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 4.9e-15 (FP64 on both sides); same top token at every position | | Weights | `model.safetensors` SHA-256 `b9468467b9c0f81e88507ecd7c038180a990d4a575acbea50bff542e6632cf1d`, exported from `data/runs/stage3/exp2-25m/run-s1/last.ckpt` in AsemLLM-runs (SHA-256 `38a247a1d35aa822f7e4e8301f8c3b39b71a6b85031666df5ad7956d7e7fccb2`) | `verify/lisp_reference.lisp` is the Lisp program that wrote `verify/reference-27m.json`. `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; 8 worker threads | | Training time | 5.5 hours | | Energy | about 0.2 kWh (estimate: 5.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, 110 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-27m.json`, `lisp_reference.lisp` | | `tools/export_safetensors.py` | `.ckpt` → safetensors converter | ## 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 (this release); 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 is training | Every experiment has a frozen protocol, pinned hashes, gate records and a completion record. They are all in [AsemLLM-runs](https://huggingface.co/asemqaffaf/AsemLLM-runs) under `docs/`, next to the raw data. The QA test set has never been used to score a model. ## Related repositories | repository | contents | |---|---| | [asemqaffaf/AsemLLM](https://huggingface.co/asemqaffaf/AsemLLM) (this one) | the current release | | [asemqaffaf/AsemLLM-runs](https://huggingface.co/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](https://huggingface.co/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. ## Citation ```bibtex @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.