Build a small language-model runtime - Internet Explorer
Address
https://freetolearn.world/small-llm-runtime.html
free to learn.world
← Course Directory

Terminal project · 8 units · Free

Build a small language-model runtime

Build a CPU decoder runtime with a KV cache, reproducible sampling and explicit generation limits.

Get the course on GitHub
What you’ll learn
Model loading, causal attention, KV caching, sampling and bounded generation.
Your project
Your own decoder, streaming generator and investigation of a cache discrepancy.
How you’ll work
Clone the Node.js project from GitHub. The numeric backend and trained assets are supplied; no GPU or API key.

What you’ll build

  • Validate a model and tokenizer, then implement stable numerical operations and decoder blocks.
  • Add causal attention, rotary positions and cached decoding that agrees with full-prefix computation.
  • Deliver a local generator and investigate unfamiliar cache corruption.

Before you start

JavaScript arrays, functions, objects and ES modules; matrix multiplication and dimensions. A complete numerical backend is supplied, so the tensor course is optional.

Node.js 22+ is advertised; Node 26.5.1 was tested. Minimum-version support remains unqualified. No GPU, model download, package installation, API key or inference bill.

The first numerical exercises use a tiny untrained checkpoint. The final project adapts your own runtime to the bundled trained Stories260K profile; see TRAINED.md in the course folder. These are bounded CPU experiments, not a production language service.

Keep trained project dependencies together

The documented optional project.mjs sibling is now included in trained attempt snapshots and exports. Edits, removal or addition make older results stale. Unlisted helper imports remain unsupported; preserve the matching package and all original exports.

Clone and start the terminal project

Use the already-installed tools listed above. Clone the learner source, enter this course directory and run its first check:

git clone https://github.com/itsHabib/free-to-learn.git
cd free-to-learn
git checkout ba8bd2c3d0d8c4cb65956f7e737984511d38960a
cd courses/small-llm-runtime
node lab.mjs start work
node lab.mjs check 01 work --help-used none

Implement work/runtime.mjs through the pocket checks, then work/trained.mjs and your own trained-project.mjs using TRAINED.md. The trained assets are bundled. Finish the generator/cache investigation and check all and trained before exporting to a fresh ZIP.

The unfinished starter should fail with a named diagnostic. Implement your own code; supplied worked/prerequisite layers are labelled assistance. Preserve first attempts and declare actual help.

Terminal CPU implementation, trained generation and standalone export/replay. No server, GPU, paid inference service or extra model download is required for this route.

Browse the pinned learner source · Reuse terms and attribution

Browser-only material in the course keeps its own stated limitations.

Give site feedback →

Course overviewInternet
Mission.txt - Notepad

Learning without paywalls.

Find what people pay to learn.
Build a great course. Give it away.

One course at a time.

Usage & privacy

Start