Lesson 2: Serving a foundation model: memory, batching and cost
33 min read·
Module 12 · Lesson 2 · About 50 minutes · Needs: lesson 1 (the SmolLM2 model and its adapter), Module 8 lessons 2 and 3 (KV caching, dynamic batching, the benchmark harness). Runs on a CPU.
The situation
Week 12 at Kestrel, day three. Lesson 1 produced a 9.4 MiB adapter for message intents. Rhys must serve it and asks two things: how much memory, and what p99 under load. Imran asks the other: is a machine of our own cheaper than paying an API per token? Hannah's rule still stands: customer text stays inside Kestrel unless a decision record says otherwise.
The running example is the same message, M0001 (simulated), 17 tokens long, and an illustrative inbox of 4,000 messages a day, added in this lesson.