← Inference From First Principles

Designing the Inference Runtime

Capstone architecture, interfaces, safety.

Chapter 40 designed benchmarks. Part 8 now builds the Inference Lab capstone, starting with design.

Architecture

The runtime integrates tokenizer, model backend, sampler, cache, scheduler, API, and metrics. Each component has a typed contract.

ADRs

Architecture decision records document choices. The example includes two ADRs: CPU-first and typed contracts.

Contracts

Contracts enable swappable backends and testability. The contract test verifies a backend generates expected output.

Research context

Compare runtimes by explicit subsystems: request state, scheduler, cache manager, executor, sampler, protocol, and telemetry. Pinned implementations such as DeepInfer, PagedAttention, and SGLang distinguish reusable patterns from model- or vendor-specific choices. Define invariants at subsystem boundaries before optimising.

Experiment

The example produced 2 ADRs and a valid contract. Tests verify contract validation, demo, and serialisation.

Limitations

  • Toy backend.
  • No real integration.
  • No performance.
  • No safety audit.

Key terms

  • ADR: architecture decision record.
  • Contract: typed interface.
  • Backend: model implementation.
  • Capstone: final integration.
  • Non-goals: explicit exclusions.

Reader exercises

  1. Add an ADR for caching.
  2. Design a backend contract for streaming.
  3. Explain non-goals.
  4. Draw the integration diagram.

References

Implementation status

  • Manuscript: content/books/inference/41-chapter.md
  • Runnable example: examples/ch41/
  • Tests: tests/test_ch41_contracts.py
  • Evidence: research/ch41/sources.md and research/ch41/results.json
  • Verification command: python -m unittest discover -s tests -v

The chapter is a draft. It does not claim production runtime. The next chapter will implement scheduling and caching.