liteinfer
A lightweight, hackable LLM inference engine built from scratch — designed
to make state-of-the-art inference techniques (paged KV cache, prefix
caching, tensor parallelism, torch.compile, CUDA graphs, …) easy to read,
test, and benchmark.
Goals
- Fast offline inference — throughput in the same league as vLLM on a single node.
- Readable codebase — clean, minimal, well-structured. The core engine should fit in your head.
- Optimization suite — a clear place for each technique (prefix caching, TP,
torch.compile, CUDA graphs, …) with isolated, testable implementations. - HuggingFace compatibility — load any compatible HF model from the Hub or a local safetensors directory.
Status
v0 — greedy/sampled inference on local safetensors via continuous batching over
a paged KV cache. AsyncLLM is the native interface (async context manager plus
streaming); LLM is a synchronous facade for offline batch use. See
docs/milestones.md for what is in, and
docs/roadmap.md for what is queued.
Installation
pip install liteinfer
For development or benchmark comparisons:
git clone https://github.com/ValeGian/liteinfer.git
cd liteinfer
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
Quick start
from liteinfer import LLM, SamplingParams
llm = LLM(model="meta-llama/Llama-3.2-1B-Instruct")
params = SamplingParams(temperature=0.8, max_tokens=128)
outputs = llm.generate(["Explain paged attention in one paragraph."], params)
print(outputs[0].text)
# Async continuous batching with streaming
import asyncio
from liteinfer import AsyncLLM, SamplingParams
async def main():
async with AsyncLLM("meta-llama/Llama-3.2-1B-Instruct") as llm:
# Batch — all requests processed concurrently
results = await llm.generate(prompts, SamplingParams(max_tokens=128))
# Streaming — per-token events
async for event in llm.stream("Explain paged attention.", SamplingParams(max_tokens=128)):
print(event.text, end="\r")
asyncio.run(main())
Repository layout
liteinfer/
├── liteinfer/ # Library source
│ ├── llm.py # Synchronous LLM facade
│ ├── async_llm.py # AsyncLLM: the engine's native interface
│ ├── config.py # EngineConfig
│ ├── engine/ # Orchestration: scheduler, sequence, model runner, metrics
│ ├── models/ # Loader + per-architecture implementations (layers included)
│ ├── cache/ # Paged KV cache: block pool + slot addressing
│ └── sampling/ # SamplingParams + Sampler
├── tests/ # Unit / integration / e2e tests
├── benchmarks/ # Benchmark matrix, harness, and report
└── pyproject.toml
Each module's __init__.py documents the contract it owns.
Architecture (brief)
One engine: continuous batching over a paged KV cache.
AsyncLLM— asyncio API:await llm.generate(...), orasync forto stream tokens.LLMis a synchronous facade over it for offline batch use.ContinuousScheduler— fills empty batch slots from the waiting queue on every step and evicts finished sequences individually.ContinuousModelRunner— runs one prefill or decode forward pass.torch.compile, CUDA graph capture and tensor parallelism plug in here.ContinuousKVCache— per-sequence blocks drawn from a sharedBlockPool;slot_tablemaps logical token positions to physical slots, so a whole batch is read or written with a single indexing op.
Sampling is a separate stage so strategies (greedy, top-p, …) can be swapped
without touching the engine. stats records a StepMetrics per forward pass.
Earlier designs — no cache, DynamicCache, plain-tensor cache, static
batching — were measured against each other and then removed; the numbers live
in docs/benchmarks.md and the reasoning in
docs/milestones.md.
Testing
liteinfer is test-first: every feature ships with the tests that
pin its contract.
pytest # full suite — runs sequentially, GPU-safe
pytest -m "not gpu and not slow" # fast suite (no model downloads, no GPU)
pytest -m gpu # GPU tests only — sequential, never use -n auto
pytest -n auto # parallel mode — CPU-only tests only
pytest tests/unit/ # one directory
GPU tests: always run sequentially. The e2e tests (
tests/e2e/) load real models onto GPU. Running them in parallel (-n auto) will cause OOM or cross-process interference.
Test layout:
tests/unit/— single-component tests. CPU-only, fast, no model loading.tests/integration/— multiple components wired together (still no HF download).tests/e2e/— load a small real model and verify generation againsttransformers.
See tests/README.md for conventions.
Performance
A40 · Llama-3.2-1B-Instruct · ISL 128 · OSL 256 · vs vLLM 0.28.0 at matched batch width.
| liteinfer | vLLM | ||
|---|---|---|---|
| Decode step (ITL p50) | 13.7 ms | 5.2 ms | 2.6× behind |
| Throughput, B=4 | 282 tok/s | 724 tok/s | 2.6× behind |
| Throughput, B=32 | 1,268 tok/s | 4,467 tok/s | 3.5× behind |
| Batching gain, B=1 → B=4 | 3.84× | 3.84× | on par |
| Time to first token (p50) | 15.7 ms | 22.7 ms | 1.4× ahead* |
* At this prompt length TTFT is mostly fixed per-call API overhead rather than prefill compute, so read it as offline round-trip latency, not prefill speed.
Batching is competitive at both tiers; what remains is a roughly flat ~3× per-step
decode constant at every batch width — no CUDA graphs, no fused attention.
Throughput figures are certified against vllm bench throughput to within 1%. Full tables, methodology, and per-milestone deltas:
docs/benchmarks.md · live dashboard.
Benchmarking
Every liteinfer configuration is measured against the one it improves on, and against vLLM, on byte-identical prompts.
pip install -e ".[dev,bench]"
# 1. Build a dataset (once per model + ISL/OSL)
bench dataset --model meta-llama/Llama-3.2-1B-Instruct --isl 128 --osl 256 -n 200
DS=benchmarks/datasets/isl128_osl256_n200_meta_llama_llama_3_2_1b_instruct.json
# 2. Run every config, in both modes
bench run --all --dataset "$DS" --mode throughput -n 200
bench run --all --dataset "$DS" --mode latency -n 50
# 3. Report
bench report --out docs/index.html
Engines: liteinfer, vllm. See benchmarks/README.md
for the config matrix and controls, and docs/benchmarks.md
for methodology and results.
Every performance change is measured against the config it improves on. A
general win replaces that config; a win scoped to a precondition (MoE,
quantization, long context) joins it instead — see "Shipping an improvement" in
docs/roadmap.md.
Roadmap
High-level direction:
- Greedy/sampled generation from local safetensors
- Paged KV cache
- Continuous batching (async, streaming) — superseded static batching, now removed
- prefix caching
-
torch.compileand CUDA graphs for decode - Tensor parallelism (single node)
- Speculative decoding
Detailed, fine-grained backlog with scope and parity-test notes lives
in docs/roadmap.md. Achieved milestones are
tracked separately in docs/milestones.md.
License
Apache-2.0.
Metadata
Release files for liteinfer 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| liteinfer-0.3.0.tar.gz | 93.4 kB | With provenance | Details for liteinfer-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| liteinfer-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for liteinfer-0.3.0-py3-none-any.whl |
Total release size: 172.1 kB
Release files / liteinfer-0.3.0.tar.gz
| Download URL | liteinfer-0.3.0.tar.gz |
|---|---|
| Size | 93.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
579d005b0a5b9434a704ca5f9aced16fdc38794b710784e0eedfdf5bdeb1ce97
|
|
BLAKE2b-256 checksum How to use checksums |
9aa63b4ce8f35f51365b6dcb50488bc8bfe40ddd43a1b905e73f414bb53df618
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 5, 2026.
Transparency logRelease files / liteinfer-0.3.0-py3-none-any.whl
| Download URL | liteinfer-0.3.0-py3-none-any.whl |
|---|---|
| Size | 78.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
03a0d229cc6321a9771d9c9a6875943bca8f38492080160d0a341a91357f51f8
|
|
BLAKE2b-256 checksum How to use checksums |
0d37609c32d65bb6d6f3db566553b8b10c36109c9f10b5941732baf435d598c5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 5, 2026.
Transparency logSecurity for liteinfer 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for liteinfer-0.3.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 5, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.