Oracle is a small language model written entirely in Twill. Twill is the language and the loom; Oracle is the cloth woven on it. The model, the tokenizer, the training loop, and the sampler are all Twill source. The from-scratch model uses no Python, no C++, and no external weights: you train it and run it with the single twill binary.
Oracle also runs real pretrained open models through runtimes written in the same Twill. The headline one is a Qwen2.5-Coder-0.5B runtime: a lightweight, instruction-following engineering assistant that runs on a laptop CPU. It writes working code, and it also answers everyday engineering questions across programming, physics, mathematics, and mechanical, electrical and CAD design. See The Qwen coder. There is also a GPT-2 124M runtime that writes coherent English, kept as the simpler first example. Those weights are the open Qwen (Apache-2.0) and GPT-2 releases, not trained here; only the runtimes are Twill.
So Oracle is a small model you can train from scratch and read end to end, a GPT-2 runtime, and a self-hosted engineering assistant that fits on a laptop, helps with day-to-day engineering, and can read a codebase to answer questions about it, all in Twill.
- Three model runtimes, all in Twill. A from-scratch transformer you train yourself, a GPT-2 124M runtime, and a config-driven Qwen2.5-Coder runtime (0.5B to 3B, 1.5B by default) that answers engineering questions and writes working code on a laptop CPU.
- An engineering assistant CLI.
oracle code,explain,review,fix,tests,sh,commitandchat, each streaming its answer, reading files or piped stdin. It answers programming, physics, math and CAD questions as well as writing code. See Working with your code. - Understands your codebase, and answers general questions too.
oracle askfinds the passages of a repository relevant to a question and answers from them with line-anchored citations, using semantic retrieval through a MiniLM sentence encoder also written in Twill and a persistent incremental index. When a question is not about the code, it answers from general engineering knowledge instead. - A live-model server and web console.
oracle serveholds the model loaded, streams over the browser or the CLI, switches models, and hosts the encoder too. - Acts on your computer, efficiently.
oracle agentworks in text, not screenshots: it proposes one shell command at a time, you confirm it, and the model reads the command's output, a few tokens rather than a thousand-token image, and continues. - Honest about scale. Qwen-0.5B is a capable small assistant, not a frontier model; every claim here is measured, and the limits are stated plainly.
Everything runs on the single twill binary plus, for the pretrained runtimes, a one-time weight download. Jump to the Quickstart to try it in a few commands.
oracle code "<prompt>" answers a plain-English request with real code, running Qwen2.5-Coder-Instruct entirely through a Twill runtime (src/qwen.tw, src/qwen_tok.tw). It is a faithful Qwen2 implementation: RMSNorm, rotary embeddings at theta 1,000,000, grouped-query attention, a SwiGLU feed-forward, and a tied head. The runtime is config-driven, so it loads any size unchanged; the weights fit in a laptop's memory as int8, rebuilt into the int8 kernel by twill's quantize_packed. The tokenizer reproduces Qwen's token ids exactly, and the prompt is wrapped in Qwen's ChatML template, which is what turns raw completion into instruction following. (The numbers below describe the 0.5B model concretely: 24 layers, hidden 896, grouped-query attention with 14 query heads over 2 key/value heads, about 475 MB int8.)
oracle fetch-qwen # one time: 1.5B by default, needs python3 with numpy
oracle code "Write a Python function that returns True if a number is prime."
oracle fetch-qwen installs the 1.5B model by default: the recommended size, with noticeably better answers than 0.5B while still running on a laptop CPU (about 1.4 GB int8, a handful of tokens per second). For the smallest, fastest option run oracle fetch-qwen 0.5B. Sizes coexist in their own directories, and oracle uses the most capable one you have installed unless you pass --model.
Give it a file as context to ask about real code: oracle code "what bug could this have?" --file mycode.py. Or start oracle chat and use /file <path> to load one or more files into a running conversation, then ask about them. Pass --file more than once to give it several files, or pipe one in: cat mycode.py | oracle code "add tests".
For common tasks there are shortcuts: oracle explain --file x.py, oracle review --file x.py, and git diff --staged | oracle commit to draft a commit message. All read a file or piped stdin and take --model.
Real output, unedited:
Here's a simple Python function to check if a number is prime:
def is_prime(n):
# Check if the number is less than 2
if n < 2:
return False
# Check for factors from 2 up to the square root of n
for i in range(2, int(n**0.5) + 1):
...Honest scope: even the 1.5B default is a small model. It is a capable lightweight engineering assistant: it writes and explains code, follows instructions, and gives sensible first-pass answers on physics, mathematics and mechanical or CAD questions, but it is not a frontier model and will make mistakes on hard problems, so treat it as a fast local helper rather than an authority. The two laptop sizes trade speed for depth: 0.5B runs at about sixteen tokens per second on an Apple laptop CPU (a short answer in a few seconds) and is the fast, tiny option, while the default 1.5B answers noticeably better at a handful of tokens per second. That speed comes from the twill 1.18.4 int8 kernel, which parallelises a single-token step across every core, from projecting only the last position for the first token, and from twill 1.18.5's sampler, which selects the top-k and the nucleus without sorting the whole 150,000-token vocabulary each step (that sort alone had been costing as much as the model itself). The runtime is config-driven, so oracle fetch-qwen 3B drops a larger model in unchanged for more capability at proportionally more memory and time. Select a size per command with oracle code --model 0.5B "..."; sizes live in their own directories and coexist. The weights are Qwen's open Apache-2.0 release; oracle fetch-qwen downloads and converts them once and does not commit them to git.
oracle ask answers a question about a codebase without you finding the files
first. It searches the repository you are currently in (or --repo <dir>) for the
passages most relevant to the question, using BM25 keyword relevance with
camelCase and snake_case split so "get user" finds getUser, and hands those to
the model as context. No model, embedding, or index is used for the search, and
nothing is written to disk. A bare quoted question is shorthand for ask, so from
inside a project you can just write oracle "how is retry handled here?".
oracle ask "how does the server keep the model loaded?"
oracle ask "where is retry handled?" --repo ~/code/api --k 8
oracle ask "why does a heavier flywheel store more energy at the same RPM?"
ask is the single entrypoint for day-to-day questions. When the semantic search
finds passages that are actually relevant, it grounds the answer in them and cites
them; when the question is not about the repository (the third example), the
passages score below a relevance gate, none are used, and it answers from the
model's own engineering knowledge instead. Tune the gate with --min-score (or
ORACLE_MIN_SCORE); the default keeps grounding when a question is genuinely
about the code and steps aside when it is not.
Every answer ends with a Sources: list of the exact path:line-range passages
it was given, numbered [1], [2], so you can jump straight to the code the
answer came from. The list is built from the retrieved passages, not written by
the model, so the line ranges are always right even when the model's prose is
not; the model is asked to cite those numbers inline as well.
--repo points at the repository (the current directory by default), --k caps
how many passages are included, and --budget caps their total size.
For meaning, not just keywords, fetch the encoder once with oracle fetch-embed.
After that, ask reranks the candidates with a sentence-embedding model
(all-MiniLM-L6-v2) run entirely through a Twill runtime (src/embed.tw): it
turns the question and each passage into a 384-dim vector and ranks by cosine
similarity, so a passage about the same thing under different words rises even
with no shared keyword. BM25 still runs first for recall; the encoder reorders
its candidates for precision. The MiniLM weights are the open sentence-transformers
release (Apache-2.0); only the runtime is Twill, and the tokenizer plus reference
match to six decimal places. Use --no-semantic to force keyword-only ranking,
and --model 1.5B to reason over the retrieved context with a bigger model.
For a large repository, build a persistent index once so ask embeds only the
question each time, and ranks the whole repository rather than reranking keyword
candidates:
oracle index # embed every chunk once, cache the vectors
oracle ask "where is retry handled?" # now searches the whole repo by meaning
The index is a cache under ~/.cache/oracle/index, keyed by the repository path,
so it never writes into the repository being searched. Re-running oracle index
re-embeds only the files whose size or modification time changed, so keeping it
current after edits is fast. Without an index, ask still works by reranking the
keyword candidates on the fly.
oracle serve also holds the encoder live: with ORACLE_SERVER set, ask and
oracle index embed against the server's loaded encoder over an /embed
endpoint instead of starting one each time, so a query embeds in a few
milliseconds rather than paying the model load. The encoder host starts on the
first embedding request, so a server used only for the coder never loads it, and
it falls back to a local encoder if the server has none.
The coder reads real code, from a file, several files, or piped stdin, and there are shortcuts for the common tasks:
oracle code "add type hints and a docstring" --file util.py
oracle explain --file parser.py
oracle review --file server.py
oracle fix --file parser.py "IndexError on empty input"
oracle tests --file util.py
oracle sh "find every TODO under src and show the file and line"
git diff --staged | oracle commit
cat a.py b.py | oracle code "how do these interact?"
oracle fix diagnoses a bug and returns corrected code; add the error message or
a description as trailing words and it uses that to locate the problem. oracle tests writes unit tests for a file, and oracle sh turns a plain request into a
single shell command. Every task also takes trailing words as extra guidance, so
oracle review --file server.py "focus on error handling" narrows the review.
For a session that keeps context, oracle chat is an interactive workspace: type a question, watch the reply stream, and use /file <path> to load code into the conversation, /reset to clear it, /help for the list. Start it with oracle chat --repo . (or /repo <dir> in the session) to talk about a codebase: each question retrieves the relevant passages and answers from them with a sources line, exactly as oracle ask does, while general questions in the same session are still answered from general knowledge. The model is loaded once for the whole session, so follow-ups are immediate.
If you would rather point and click, oracle serve opens a small web console at http://127.0.0.1:8080. It is a streaming chat that keeps its context, with a row of tools (ask the codebase, write code, explain, review, fix, tests, shell, commit). The Ask repo tool answers a question about the project the server was started in, retrieving the relevant passages with the live encoder and citing them, the same as oracle ask on the command line; a general question is answered from general knowledge. The model is loaded once and held live in a Twill host process (serve.tw), so replies stream in token by token and every message after the first pays no load cost. The bridge (scripts/serve.py) uses only the Python standard library, binds to localhost, and exposes only the fixed set of tasks.
oracle serve # http://127.0.0.1:8080, Ask repo searches the current directory
oracle serve --repo ~/code/api # point the Ask tool at a specific project
oracle serve --port 9000 --model 1.5B
The server is also a model host for the command line. Each oracle code or
oracle fix normally starts twill and loads the weights again, about two seconds
before it even begins (more for a bigger model). Point the CLI at a running
server and it hands the work there instead, so the model is loaded once for the
server's life and repeated calls skip the reload:
oracle serve & # once, in the background
export ORACLE_SERVER=http://127.0.0.1:8080
oracle fix --file parser.py "IndexError" # answered by the live model
git diff --staged | oracle commit
It streams the same way, and falls back to running locally if the server is not
up, so it is safe to leave ORACLE_SERVER set. Set it per command with
--server URL instead of the environment variable if you prefer. The console has
Style and Length controls, and --temp and --steps carry through to the server
too, so each request can set its own creativity and reply length. When more than
one model size is installed, a selector in the console switches between them live,
loading the chosen weights without restarting the server.
oracle agent "<task>" lets the model act on your machine, the efficient way. A
screenshot is worth a thousand tokens, so instead of looking at pixels the agent
works in text: it proposes one shell command, you approve it, it runs in the
directory you started from, and the model sees the command's text output, a few
tokens rather than an image, and decides the next step. The model is loaded once
for the whole loop, so it is fast, and the commands do real work with none of the
overhead of a screen.
oracle agent "show the ten largest files under this directory"
oracle agent "make a Python venv here and install requests"
Every command is confirmed before it runs (the default is no), and the loop stops
at a step limit, so nothing happens on your computer without your say-so. An
obviously destructive command (a recursive or forced remove, dd, mkfs,
sudo, a fork bomb) is flagged and needs the whole word yes, not a reflexive
y, so the friction lands where it matters. It is a small model, so treat it as
an assistant that drafts the commands, not an autonomous operator: read each one
before you approve it. --model 1.5B proposes better commands; --steps N sets
the loop's cap. With ORACLE_SERVER set, the agent generates on a running
oracle serve rather than loading a second copy of the model, so a server you
already have up for chat or ask powers the agent too.
It is a from-scratch, decoder-only transformer of about 3.4 million parameters over a byte-level BPE vocabulary. It is small on purpose: it trains on a laptop CPU in about half an hour, and everything about it is meant to be read and understood rather than treated as a black box. It is not GPT. It learns the token-by-token shape of its training text and continues a prompt in that hand. At this scale the output is text-like and often word-like, with real words, speaker labels, and the cadence of the source, not fluent English. That is the honest ceiling of a model this size, and watching it reach that ceiling is the point.
The tokenizer is byte-level Byte Pair Encoding: it starts from the 256 byte values, so every input encodes with no unknown token and every id decodes back to exact bytes, and it learns merges by pair frequency up to a target vocabulary. Because BPE packs several characters into each token, a token context covers far more text than a character context did, which is the main quality lift in this release.
Position is carried by rotary embeddings (RoPE), not a learned table, so there is no fixed context cap: a long prompt and a long generation run past the 256-token training context, and the KV-cache runs past it too.
Get the toolchain and the repository. The from-scratch checkpoints ship with the repo, so you can generate before you train anything:
go install github.com/twill-lang/twill/cmd/[email protected] # get the toolchain
git clone [email protected]:martin-k-m/oracle.git
cd oracle
bin/oracle generate "To be, or not to be" # sample the shipped checkpoint
For the assistant, fetch the Qwen weights once (python3 with numpy needed for
the conversion), then ask it for code, about a file, or about the whole
repository:
bin/oracle fetch-qwen # one time: 1.5B, the recommended default
bin/oracle code "write a Python function that reverses a string"
bin/oracle ask "why does a heavier flywheel store more energy at the same RPM?"
bin/oracle explain --file bin/oracle
bin/oracle fetch-embed && bin/oracle index # optional: semantic repo search
bin/oracle ask "how does the persistent index reuse unchanged files?"
fetch-qwen downloads the 1.5B model by default (about 3 GB, roughly 1.4 GB once
converted to int8): the best answers that still run comfortably on a laptop. For
the smallest, fastest option run bin/oracle fetch-qwen 0.5B instead; sizes live
in their own directories and coexist, and Oracle uses the most capable one you
have installed unless you pass --model.
If twill is not on your PATH after the install, either add your GOBIN to PATH or point the CLI straight at the binary with TWILL=/path/to/twill bin/oracle generate "...".
bin/oracle is one entrypoint over the whole workflow. It finds the twill binary (from $TWILL, your PATH, or the Go install path) and finds the repository from its own location, so it runs from any directory.
The code assistant (Qwen), after oracle fetch-qwen:
| Command | What it does |
|---|---|
oracle code "<prompt>" [--file F ...] |
write code from a request, with files or piped stdin as context |
oracle explain / review / fix / tests [--file F] |
explain, review, fix a bug in, or write tests for code |
oracle sh "<request>" |
turn a plain request into one shell command |
git diff --staged | oracle commit |
draft a commit message from a diff |
oracle chat [--repo D] |
an interactive streaming session that keeps context, and can answer from a codebase |
oracle agent "<task>" |
act on your computer with confirmed shell commands, text not screenshots |
oracle serve |
a live-model web console and HTTP server (/embed, model switching) |
Repo-aware question answering (add oracle fetch-embed and oracle index for semantic search):
| Command | What it does |
|---|---|
oracle ask "<question>" [--repo D] |
answer a question about a whole repository, with citations |
oracle fetch-embed |
download the MiniLM sentence encoder |
oracle index [--repo D] |
build/update the persistent semantic index |
The from-scratch model and tooling:
| Command | What it does |
|---|---|
oracle train / generate "<prompt>" / quantize / bench |
train, sample, pack to int8, and measure |
oracle fetch-gpt2 / gpt2 "<prompt>" |
fetch and run the GPT-2 124M runtime |
oracle check / test / test-py |
shape-check every .tw file, run the tokenizer tests, run the Python tests |
Most coder and ask commands take --model 1.5B (a bigger Qwen) and the decoding
flags --steps, --temp, --topk, --topp, --rep, --seed. Set
ORACLE_SERVER to route the coder and the encoder through a running
oracle serve instead of loading the model each call.
Oracle's own model is small and honest about it. To show what the same Twill can do with real weights, Oracle also implements a faithful GPT-2 124M inference engine, in src/gpt2.tw and src/gpt2_tok.tw. It is the full modern decoder architecture: learned token and position embeddings, twelve pre-norm blocks of causal multi-head attention and a gelu feed-forward, a bias on every projection, and a tied output head. The byte-level BPE tokenizer reproduces GPT-2's token ids exactly, checked against the reference encoder, so the pipeline is Twill end to end: encode, forward, decode, with no Python at run time.
The weights are OpenAI's open GPT-2 release. They are downloaded and converted to a Twill tensor tree once, on your machine, by a one-line command; they are not committed to this repository and they are not trained here.
oracle fetch-gpt2 # one time: ~500 MB download, needs python3 with numpy
oracle gpt2 "Dear team, I wanted to update you on the timeline."
Real output, unedited:
Dear team, I wanted to update you on the project timeline. Our plan is that we will be working in conjunction with our community partners and their organizations until January of 2019 (when a full transition period begins). We believe this needs your help
That is genuine, fluent English from a prompt, running on a CPU. What it is honest about: GPT-2 small writes coherent short prose and email-shaped text, and it is weak at code. Asked to continue def fibonacci(n): it produces Python-shaped but wrong output, because GPT-2 predates the code-heavy training that makes today's models good at programming. It has no instruction following and no facts you should trust. It is a 2019 model at the smallest size, run at home for the interest of running it.
Requirements and cost, measured on an Apple laptop CPU: the converted fp64 weights are about 1 GB on disk, generation uses roughly 2.3 GB of RAM, and it produces about 1.8 tokens per second with the key/value cache. oracle fetch-gpt2 needs curl and a Python 3 with numpy for the one-time conversion; the conversion is data prep, not the runtime.
There is an int8 path (oracle quantize-gpt2, then oracle gpt2 --int8), and it is honest about a tradeoff rather than a free win. It cuts the weights from about 1 GB to 126 MB on disk, a 7.5x reduction, and generation stays coherent with a small memory saving. But in twill 1.18.4 it runs about six times slower than fp64, because the int8 kernels are reconstructed from the packed codes at load and that reconstruction is linear in the model's 124 million parameters. So fp64 is the default for the GPT-2 runtime, and int8 is there for when disk or bandwidth matters more than speed. The real fix is a native twill builtin that reads packed codes straight into the int8 kernel, which is a change to twill itself, not to Oracle.
The architecture is the standard decoder-only transformer, defined in src/model.tw:
- A token embedding table. Position is not a table: it enters through rotary embeddings (RoPE) applied to the query and key projections inside attention, so it has no length limit.
- A stack of pre-norm blocks, each with masked multi-head self-attention and a gelu feed-forward.
- A final layernorm.
- A tied output head: the logits come from reading the token-embedding table a second time, so the map from a token to its vector and back is one relationship learned once.
The default configuration:
| Setting | Value |
|---|---|
| Vocabulary | 1024 BPE tokens (256 byte tokens + 768 learned merges) |
| Model width (d_model) | 256 |
| Attention heads | 8 |
| Decoder blocks | 4 |
| Training context | 256 BPE tokens (RoPE, so not a runtime cap) |
| Parameters | 3,417,600 (about 3.42 million) |
Oracle builds on Twill's standard library for the low-level pieces (embedding, layernorm, causal attention with RoPE, gelu, dense layers, Adam, cross-entropy, and the sampling filters including top-k and top-p), but the block, the stacked model, the loss, the KV-cache, the repetition penalty, and the generation loop are Oracle's own code in src/model.tw. The byte-level BPE tokenizer, including its merge trainer, its encoder and decoder, and its save/load, is Oracle's own code in src/tokenizer.tw.
src/tokenizer.tw is byte-level Byte Pair Encoding, and it is built so the encode/decode machinery is separable from where the merges come from. train_from_corpus learns a merge table on Oracle's corpus by iterated most-frequent-pair merging; from_merges builds the identical tokenizer record from any ordered list of id pairs. The encoder pre-tokenizes text into whitespace-attached chunks so a token never spans two words, then applies the merges greedily; the decoder expands each id to its bytes and joins them, which is exact because every id ultimately expands to byte tokens. That separation is deliberate: the next release ships an open-weights GPT-2 runtime, and GPT-2's tokenizer is byte-level BPE with an externally supplied vocab and merges, so a loader that parses GPT-2's tables into id pairs reuses this file's encoder and decoder unchanged. tests/tokenizer_test.tw (oracle test) checks the round-trip identity, save/load, and the from_merges reuse path.
Training uses a public-domain text: the full "tiny shakespeare" file, about 1.1 MB (the works of William Shakespeare are public domain). It is committed in full at data/corpus.txt so training works offline and is reproducible, and scripts/fetch_corpus.sh regenerates that exact file from the source, so the derivation is not magic.
Learning BPE merges over the whole 1.1 MB file in the interpreter is slow, so train.tw reads a deterministic prefix (TRAIN_CHARS, 250,000 characters by default) to learn the merges and to train on, which keeps the wall clock inside the budget. The prefix is a fixed function of the committed file, so the run stays reproducible, and the tokenizer itself is deterministic (ties broken by the lowest pair key), so its 768 merges reproduce too. Raise TRAIN_CHARS for a longer, slower run. The corpus is deliberately far larger than the model, so what Oracle learns is the structure of the text rather than a memorized copy of it.
- The Twill toolchain, version 1.18.5. Install a released build with
go install github.com/twill-lang/twill/cmd/[email protected]and put yourGOBINonPATH, then confirmtwill --versionprints1.18.5.
From the repository root:
make train
or directly:
twill run train.tw
This reads the corpus prefix, learns the byte-level BPE tokenizer and saves it to models/oracle-tok.bin, encodes the corpus to token ids, trains with Adam over random windows, prints the loss as it goes, and saves the weights and the config to models/oracle.bin. The tokenizer and the checkpoint are two files that load together. Training is a pure function of two fixed seeds, so a second run reproduces the first. The default run (learning 768 merges, then 360 Adam steps at batch 6) took about 34 minutes on this laptop CPU (measured 2026-09-22, 2,027 seconds wall clock) and reached a training-batch cross-entropy around 4.45 over the 1024-token vocabulary. That is inside the roughly 35-minute budget the hyperparameters are tuned for; raise STEPS or TRAIN_CHARS for a longer, slower, better run.
make generate PROMPT="To be, or not to be"
or directly:
twill run generate.tw "To be, or not to be"
This loads models/oracle.bin and the tokenizer from models/oracle-tok.bin, encodes the prompt, and samples a continuation. Decoding combines temperature, top-k, top-p (nucleus), and a repetition penalty, all with sensible defaults and all overridable as flags:
bin/oracle generate "To be, or not to be" --temp 0.7 --topk 40 --topp 0.95 --rep 1.15 --steps 200
--steps now counts BPE tokens, not characters, so a token is roughly three characters and the default 200 tokens is a longer sample than the old 300 characters. Sampling is seeded (--seed, default 42), so a given prompt and settings give the same continuation every run. Because position is rotary, a long prompt and a large --steps run past the 256-token training context rather than being truncated to it. The flags map to ORACLE_* environment variables that generate.tw reads, so the defaults live at the top of that file.
Oracle can pack its weights to int8, which shrinks the checkpoint on disk and the model in memory at a quality cost that is negligible at this scale. From the repository root:
make quantize
or directly:
twill run quantize.tw
This loads models/oracle.bin, packs every dense weight into int8 with a per-row scale (in pure Twill, so the file is small too, not just the model in memory), and writes models/oracle-int8.bin. The token table and the layernorm parameters stay f64; there is no position table to carry, because RoPE places positions inside attention. generate.tw runs either checkpoint (both load the same models/oracle-tok.bin tokenizer); pass the int8 one as a second argument:
twill run generate.tw "To be, or not to be" models/oracle-int8.bin
It detects the int8 file and rebuilds the packed weights into Twill's int8 matmul kernel before sampling.
The same prompt, "To be, or not to be", the same seed and default sampling, showing the 0.5.0 model (character-level tokenizer, about 1.79 million parameters) against this 0.6.0 model (byte-level BPE, about 3.42 million parameters):
Version 0.5.0 (character-level):
To be, or not to befrour his
There am, the dignereful but capsing.
MENENIUS:
Your rendule, I'll what heart hight: fares!
Version 0.6.0 (byte-level BPE):
To be, or not to bein.
Second Servingman: I is it:
And so in the chearsed I cannot had: my cow for.
Third Citizen:
Stance no ra.
HASTINGS: sir,
Whwell of me; and it is him to your good mister me?
MENENIUS:
Not,
Well, that wound;
Both are still small-model output with some invented words, which is the honest ceiling at this scale. The 0.6.0 text is clearly more word-coherent: whole real words dominate ("I cannot had", "it is him to your good", "that wound"), the speaker labels are real character names, and the dialogue structure holds. BPE is the reason: the model composes from word-shaped tokens rather than spelling every word one character at a time. Your exact continuation depends on the decoding flags and seed.
Measured on this machine (Apple Silicon, macOS, Twill 1.18.4, CPU) on 2026-09-22, from bench.tw. Reproduce with:
make bench # strict matmul
make bench MATMUL=fast # fast matmul microkernels
Model and checkpoint:
| Quantity | fp64 | int8 |
|---|---|---|
| Parameters | 3,417,600 | 3,417,600 |
| Checkpoint on disk | 27,342,719 B (26.08 MiB) | 5,398,241 B (5.15 MiB) |
Model footprint (nbytes) |
27,340,800 B | 5,394,432 B |
The int8 checkpoint is 5.07x smaller on disk and the model is 5.07x smaller in memory. Only the dense weights are packed; the f64 token table and norms are carried through. The ratio is further from the 8x of a pure int8-for-f64 swap than the 0.5.0 char model's 7.2x, and the reason is the vocabulary: the f64 token-embedding table is now 1024 rows of width 256 rather than 62 rows of width 192, so the un-quantized table is a much larger fixed share of the int8 model. That is a real and explainable cost of a bigger vocabulary, not a regression in the packing.
Generation speed, 56 tokens continued from a short prompt, tokens per second:
| Path | strict matmul | fast matmul |
|---|---|---|
| Uncached (re-run whole context each step) | 71.6 | 60.8 |
| KV-cache | 462.2 | 524.7 |
The KV-cache is 6.45x faster than re-running the whole context (8.63x with fast matmul), and the cached and uncached greedy continuations are identical token for token (0 mismatches) on a run of 144 tokens. TWILL_MATMUL=fast is a win for the cached path (about 14 percent) and a small loss for the uncached path: the hand-written microkernels amortize over large matmuls, and even at d_model 256 Oracle's are on the small side for the setup to fully pay off on the uncached path. The flag is wired up and reported so the effect is visible rather than assumed.
Quality proxy, mean cross-entropy and perplexity over 30 held-out 256-token windows drawn from a slice of the corpus past the training prefix, so the windows are unseen (lower is better):
| Model | cross-entropy | perplexity |
|---|---|---|
| fp64 | 5.13203 | 169.360 |
| int8 | 5.13155 | 169.280 |
This perplexity is over BPE tokens and is NOT comparable to the 0.5.0 char-level perplexity of 5.09. A token carries more information than a single character, so a per-token perplexity of 169 is not worse than a per-character perplexity of 5; they are different units over different alphabets (1024 tokens versus 62 characters), and the only honest comparison between the two models is the sample text, not the number. Within this release the comparison that does hold is fp64 versus int8: int8 is 0.08 of perplexity lower here, which is within the noise of the measurement, so int8 remains the efficient default with no meaningful quality regression.
Peak process memory, from /usr/bin/time -l on a 200-token generation:
| Run | peak resident set |
|---|---|
| fp64 generate | ~103 MB |
| int8 generate | ~72 MB |
The int8 peak stays below the fp64 peak, so the row-by-row int8 reconstruction from 0.5.0 (which removed the old ~163 MB load spike) still holds at the larger vocabulary and model size.
Before 0.5.0 the int8 load reconstructed each packed weight by appending every
value into one Twill list, and append copies its whole list on each call, so a
single weight cost O((rows*cols)^2) copies and left that much transient garbage.
The int8 peak was ~163 MB, well above both the ~1.9 MB steady footprint (see
nbytes above) and the fp64 peak. 0.5.0 streams the reconstruction one row at a
time: each row becomes a [1, cols] tensor, the rows are stacked once with
concat, and only that one f64 weight is ever expanded at a time. The peak drops
to ~64 MB, below the fp64 peak, and the load is also much faster because the
quadratic copying is gone. A native twill builtin that read packed codes straight
into a quantized tensor (the quantize builtin only ingests a full 2-D tensor in
1.18.4) would remove even the one-weight f64 reconstruction; that stays a
twill-side follow-up, not a property of this format.
Everything with logic is Twill; the Python under scripts/ is one-time weight
conversion and the retrieval driver, and it is stdlib-only except for numpy in
the converters.
oracle/
bin/oracle one CLI over every command below
src/ the model runtimes, all Twill
model.tw tokenizer.tw quant.tw the from-scratch transformer, its BPE, its int8
gpt2.tw gpt2_tok.tw gpt2_quant.tw the GPT-2 124M runtime
qwen.tw qwen_tok.tw the Qwen2.5-Coder-0.5B runtime
embed.tw the all-MiniLM sentence encoder (semantic search)
train.tw generate.tw quantize.tw bench.tw the from-scratch train/sample/pack/measure
qwen_gen.tw chat.tw serve.tw the coder: one-shot, interactive, and the live server
agent.tw the text-based, command-confirming agent
gpt2_gen.tw quantize_gpt2.tw the GPT-2 entrypoints
gui/index.html the web console served by oracle serve
scripts/ one-time data prep and the retrieval driver
fetch_*.sh convert_*.py download and convert the open weights
retrieve.py wordpiece.py keyword + semantic retrieval and the tokenizer
serve.py client.py the HTTP server and its streaming client
rstr.py write Twill save files from Python
tests/ tokenizer_test.tw, and Python tests for retrieval
data/corpus.txt the committed public-domain training text
models/ checkpoints and downloaded weights (mostly gitignored)
.github/workflows/ CI (shape-check + tests) and tag-triggered releases
Oracle is a teaching-scale model. At about 3.4 million parameters trained for about half an hour on 250 KB of text, it learns spelling, spacing, real words, speaker labels, punctuation, and the rough cadence of the corpus, and byte-level BPE lets it compose from word-shaped tokens so its output is clearly more word-coherent than the character-level 0.5.0 model. It still does not learn grammar, meaning, or facts, and it will still produce invented words and broken sentences. It has no instruction following, no chat behavior, and no knowledge of anything outside its training text. It is a small, honest, from-scratch demonstration of how a transformer language model and its tokenizer are built and trained, all the way down, in one language. Bigger and longer-trained would read better, but the point is to stay home-runnable and readable, not to chase fluency.
Phase 1 built a working, trained, generating model. Phase 2 made inference efficient and measured it: int8 quantization, a KV-cache, the fast-matmul option, and the benchmarks above. Phase 3 was the first public release: the rename to Oracle, the unified oracle CLI, CI that shape-checks every file, tag-triggered releases, and this documentation. Phase 4 (0.4.0) modernized the architecture: rotary positions in place of the learned table, which removes the context cap, plus top-p and a repetition penalty in the sampler, a larger model, and a larger corpus. Phase 5 (0.5.0) was an efficiency release: it removed the int8 load memory spike by streaming the weight reconstruction one row at a time. Phase 6 (0.6.0, this work) is the quality release: a byte-level BPE tokenizer written in Twill and a base-size 3.4M-parameter model, which lift the quality ceiling above character-level and, by design, leave the tokenizer's encode/decode reusable for an external merge table. That reuse is the groundwork for the next step, an open-weights GPT-2 runtime that loads GPT-2's own byte-level BPE tables through the same encoder and decoder.
MIT, Copyright (c) 2026 Martin Muskov. See LICENSE.
