8000 GitHub - vishsangale/inkling: A measurement-driven discovery loop for tiny language-model architectures. · GitHub
[go: up one dir, main page]

Skip to content
vishsangalePublic

About

A measurement-driven discovery loop for tiny language-model architectures.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

38 Commits

Folders and files

Repository files navigation

inkling

A discovery loop for very small language models, where the verdict is a measurement rather than a judgement.

A language model proposes one change to an architecture. Code trains it, scores it, and decides. Nothing the proposer says enters the accept path — it writes code and an explanation, and the explanation is filed, never consulted.

Why not just ask a model whether an idea is good

Because that was tried, at length. A predecessor loop in this lab ran ~635 rounds behind four successive quality gates and produced roughly one survivor per seventy rounds, none independently confirmed. A controlled experiment found the failure precisely: its in-loop gate preferred refined ideas 7/15 to 2/15, while blind graders put the same comparison at 0.53 and 0.38. The loop was improving — against the judge. Reading the biggest changes by hand showed what that meant in practice: told its core mechanism was flawed, the model dropped the core and retreated to something generic that scored well.

Adding a gate does not fix this. Each gate is one more surface to climb.

What is measured

task FineWeb-Edu, next-token
vocabulary 8,192 byte-level BPE (scripts/train_tokenizer.py, artifact committed)
model ≤ 10,000,000 non-embedding parameters
budget 201,211,904 tokens — one pass over the pool, steps derived
loss one definition, in train.py:loss_of, computed by the harness
also recorded bits-per-byte, which survives a change of tokenizer

The vocabulary is the arena's biggest single decision. The predecessor ran 1M parameters against GPT-2's 50,257-token vocabulary, which put 87% of every forward FLOP into the output projection and left the architecture under search at 13% of the network. At 8,192 tokens and 10M parameters that inverts: the body is 82% of the parameters and the vocabulary head is 13% of the FLOPs. Nothing off the shelf sits below 32k, so the tokenizer is trained here and committed.

Tokens, not wallclock or steps. A wallclock budget makes a fast GPU's result look better than a slow one's; a step budget lets a bigger batch smuggle in e 8000 xtra compute. Tokens are invariant to both.

Packed, not padded. Texts are concatenated and chunked, so labels == input_ids and every position is real signal. The predecessor padded and masked with -100, applied that mask inconsistently across its solutions, and ended up with two incomparable definitions of "eval loss" in one table — a 0.47-nat gap between two rows that both called themselves the champion. There is no mask here to get wrong.

The harness owns the number. A solution returns logits. It never returns a loss, so it can never author its own score. The predecessor let forward return a loss and, when it could not recompute the canonical one, silently recorded the model's self-reported value with a warning.

What the gates catch

Cheap and deterministic, before any GPU time (gates.py):

  • static contract — parses, exposes get_model/build_optimizer, imports inside an allowlist at any nesting depth, no __import__/eval/exec, no torch.save/torch.load/torch.hub
  • parameter cap, counted after build_optimizer — which receives the live model and can register parameters the first count never saw. Exactly one nn.Embedding of exactly that type has exactly its .weight exempted
  • optimizer audit — every optimised tensor belongs to the model. The cap counts model.parameters(); a trainable tensor held as a plain attribute is free capacity otherwise
  • causality — swept over every split point, not one. Run inside the scored process at the real batch shape, and again after training, since a leak can be learned rather than written
  • compute ratio — written and tested, but deliberately NOT wired in. The token budget bounds tokens, not work inside forward(), so a candidate can weight-tie its blocks and recurse them for free — but the only signal available is per-step wallclock, and the scoring box is shared. A single benchmark config measured 72.2, 72.2 and 36.1 ms/step in one sitting because another project's job took CPU mid-run, and this step is launch-bound rather than compute-bound. A gate that rejects on a number that swings 2x for reasons outside the candidate is worse than no gate. Losses are unaffected — arithmetic does not care about clock speed

A dropped causal mask is the exploit that matters most: it lowers eval loss dramatically and reads as a breakthrough.

static_contract is a stumble-guard, not a security boundary. torch alone reaches the filesystem and the network, and no AST check catches every escape. The real boundary is running training as a restricted user with no network.

An adversarial review broke four of these, and each break is now a regression test. The cap exempted every parameter of anything passing isinstance(m, nn.Embedding), so a subclass holding a 1M-parameter MLP reported cap usage of zero. The causality probe perturbed only the back half and checked only the front, so a model reading token t+1 across the entire front half passed cleanly — and the leak is tunable, so it could have landed under the quarantine threshold and been crowned as a discovery. tt = torch; tt.load(...) defeated the torch.load denial outright, and getattr defeated all of them.

What the accept rule does

Unpaired Welch against a champion baseline measured once and reused, one-sided at α=0.01, with one pre-committed decision point and a replication at fresh seeds before anything is crowned.

Three things were measured on 2026-08-20 that shaped it, all reproducible via scripts/variance_study.py in the predecessor repo:

1. Run-to-run σ is ~0.012 nats at this arena — consistent with the predecessor's own 0.006–0.025 across solutions.

2. Pairing does not work here. The plan had been to run candidate and champion over identical batches and test the difference. Over 8 matched seeds the paired std came out at 0.0147 — larger than either arm's marginal std (0.0111, 0.0131). The arms correlate at only ρ≈0.27. Batch order is a minor variance component; weight init dominates. Pairing costs a second run per comparison and buys nothing, so the rule is unpaired and the champion's runs amortise across every candidate it faces.

3. Peeking destroyed the alpha. The first version polled the rule after every run and accepted the first time a bound cleared — optional stopping. Simulated under the null it crowned at 5.45% against a nominal 0.01, i.e. exactly the 5% regime α=0.01 was chosen to avoid. Worse, the test that looked like it covered this took a single look at fixed n and reported an honest 1.1%, so the property the design most needed was never actually exercised. There is now one decision point at decide_at; earlier looks may only reject for futility, which cannot inflate the false-accept rate.

4. A shared baseline ratchets the lineage. Reusing one champion measurement across hundreds of candidates means an unlucky champion crowns many nulls in a row — 98% of simulated lineages crowned at least one, and the winner's curse on a false crowning was 0.0083 nats, larger than the ~0.0067 the rule can resolve. Every phantom crowning would bank an improvement bigger than the finest real effect visible: the exact ratchet this project exists to escape. Crowning now requires a replication at fresh seeds on both arms, since the curse lives in the seeds. Measured after the fix: false-crowning <0.5%, while a real 0.030-nat win still gets through >50% of the time.

5. The champion baseline is a hard floor. More candidate runs do not buy unlimited resolution: the standard error tends to σ·√(1/n_champion), not to zero. With a 24-run baseline, 0.005 nats is unreachable at any cost. Only a bigger baseline moves it. accept.resolution_floor() reports this, and runs_needed() returns None rather than a large number when an effect is simply out of reach.

What to expect

With σ≈0.012 and a 64-run champion, the 24-run ceiling resolves ~0.0067 nats and resolving 0.010 needs ~12 candidate runs. Adjacent champions in the predecessor's leaderboard differ by 0.0005–0.009.

So most of that leaderboard's fine ordering was never distinguishable from noise — its top two entries sit 0.0015 apart against σ of 0.012. This loop will reject nearly everything, and that is the rule working. A run of nulls here is information about the arena, not a malfunction.

It also means this arena may be close to saturated. It is a documented sharp local optimum, and if nothing above ~0.007 nats remains in it, the right move is a harder arena rather than a longer search. Arena is a frozen dataclass with a fingerprint on every row precisely so that swapping it is cheap and can never silently pool incomparable numbers.

Layout

inkling/arena.py     data, budget, the fingerprint that makes rows comparable
inkling/train.py     train + eval; owns the loss
inkling/gates.py     the mechanical checks, including the one-knob limit
inkling/accept.py    the accept rule — pure, replayable over history
inkling/ledger.py    append-only JSONL; leaderboard and champion are derived
inkling/workspace.py per-loop state; three loops kept blind by the filesystem
inkling/submit.py    stages a minimal upload, drives Ray through `lab`
inkling/trace.py     every CLI invocation, for diagnosing a wedged loop
inkling/cli.py       the agent interface — the state machine lives here
scripts/ray_entry.py runs on the head, trains on the pinned GPU worker
solutions/seed.py    the seed architecture, one definition per mutable axis
SKILL.md             what a loop is told, once
tests/               99 tests

solutions/seed.py is laid out with one factory per axis — make_norm, make_positional, make_attention, make_mlp, make_block, build_optimizer — so a one-knob mutation can be enforced: diff the candidate, see which definitions moved, compare against the declared axis. In the predecessor these all lived tangled inside two or three shared classes, so no such mapping was possible.

What the loop actually runs

inkling status                  champion, baseline depth, what to do next
inkling gate <file>             every cheap check, seconds, no GPU
inkling run <file> --runs N     score it on the cluster; rows land in the ledger
inkling judge <file>            the accept rule over what is in the ledger
inkling crown <file>            only after an ACCEPT verdict exists

Two more are the operator's, not the loop's: inkling doctor reports the worker environment, and inkling prepare builds the arena's tokenized cache on the scoring worker. A scored run refuses to tokenize. If the cache is missing, loaders raises rather than building one, because the first run to arrive at an empty cache would otherwise pay a download and a tokenize pass that no other run pays — a difference between runs that has nothing to do with the architecture being measured — and three loops starting together would do it three times at once on one box.

Every command ends with a NEXT: line. The state machine is in cli.py, not in the prompt, because a prompt is the part of a loop that degrades under context pressure. The loop never calls lab or ray — the harness fixes the arena, the seeds and the device, and a loop that could choose any of those could not be compared to anything.

Three loops run the same task blind to each other. Each owns a directory under ~/.inkling/<name> holding its own ledger, trace and candidates; the upload staged for the cluster contains the package, the entrypoint and one solution file, so a ledger can never travel to a shared machine and become a channel between loops.

One knob is enforced, not requested. gates.one_knob diffs the top-level definitions structurally — insensitive to formatting, comments and renaming — and rejects a candidate that moved more than two. Because seed.py defines one factory per axis, the set of definitions that moved is the set of axes touched, so a win stays attributable.

Status

Measurement core and harness built; 99 tests, including a regression test for every exploit an adversarial review found and for the full gate → run → judge → replicate → crown state machine on synthetic losses.

First contact with a real proposer, 2026-08-20. Qwen3.8-27B via opencode on dgx1 was asked for one mutation off the champion. It passed all four gates in 755 s and changed exactly one line — lr=cfg["max_lr"] to lr=3.0e-3 — reproducing the other 195 byte-for-byte, with a correct diagnosis attached (10M tokens against 1M parameters is ~10 tokens per parameter, roughly half of Chinchilla). That was against the previous arena — TinyStories, a 50k vocabulary and a 1M cap. That candidate is the fixture behind test_the_real_first_contact_candidate_moved_exactly_one_definition.

It also showed where the cost is: of 13,269 generated tokens, ~1,900 were the file and ~11,000 were deliberation, and opencode's own system prompt and tool schemas accounted for 16.5k of the 18.8k prompt tokens. Hence the skill tells a loop to edit the champion with its file tools rather than retype it.

Not yet run on the cluster. Runs reproduce bit-identically on MPS at fixed seeds; CUDA is unverified and its reductions are non-deterministic by default, so sigma must be measured on whatever device the loop scores on — every row records its device. inkling doctor reports the worker environment and inkling run --dry-run prints a submission without spending cluster time.

uv venv && uv pip install -e '.[dev]'
.venv/bin/python -m pytest -q

About

A measurement-driven discovery loop for tiny language-model architectures.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0