A lightweight, hackable LLM inference engine built from scratch.
Project description
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
Pre-alpha. The repository is a skeleton — most components currently raise
NotImplementedError. The structure, contracts, and test/benchmark
harness are in place so that each feature can be implemented and verified
in isolation.
Installation
git clone https://github.com/ValeGian/liteinfer.git
cd liteinfer
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
# Optional: install vLLM for benchmark comparisons
pip install -e ".[dev,bench]"
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)
Repository layout
liteinfer/
├── liteinfer/ # Library source
│ ├── llm.py # User-facing LLM class
│ ├── config.py # EngineConfig
│ ├── engine/ # Orchestration: scheduler, sequence, model runner
│ ├── models/ # Model loaders + per-architecture implementations
│ ├── layers/ # Reusable building blocks (attention, RMSNorm, …)
│ ├── cache/ # KV cache (paged, prefix-cached, …)
│ └── sampling/ # SamplingParams + Sampler
├── tests/ # Unit / integration / e2e tests
├── benchmarks/ # vLLM comparison harness
└── pyproject.toml
Each module's __init__.py documents the contract it owns.
Architecture (brief)
User code calls LLM, a thin facade over LLMEngine, which owns:
Scheduler— picks which sequences run on the next forward pass (continuous batching; later, prefix-cache aware).ModelRunner— runs the actual forward pass for the selected batch on the GPU. Tensor parallelism,torch.compile, and CUDA graph capture plug in here.KVCache— paged blocks shared across sequences. Prefix caching is aKVCachevariant.
Sampling is a separate stage so strategies (greedy, top-p, …) can be swapped without touching the engine.
Testing
liteinfer is test-first: every feature ships with the tests that
pin its contract.
pytest # everything that runs in this env
pytest -m "not gpu and not slow" # the fast suite
pytest -m gpu # GPU-only tests
pytest tests/unit/ # one directory
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.
Benchmarking against vLLM
Every engine implements the same EngineRunner interface, so comparing
liteinfer against vLLM (or future variants of liteinfer itself) is a
single command:
python -m benchmarks.compare \
--model meta-llama/Llama-3.2-1B-Instruct \
--engines liteinfer vllm \
--workload throughput \
--output benchmarks/results/throughput.json
Metrics: requests/sec, output tokens/sec, TTFT (p50/p99), inter-token
latency, peak GPU memory. See benchmarks/README.md for adding
workloads or new engines.
Roadmap
- Single-GPU greedy generation on Llama-family models
- Continuous batching
- Paged KV cache
- Prefix caching
-
torch.compileintegration - CUDA graph capture for decode
- Tensor parallelism (single node)
- Speculative decoding
License
Apache-2.0.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file liteinfer-0.0.2.tar.gz.
File metadata
- Download URL: liteinfer-0.0.2.tar.gz
- Upload date:
- Size: 12.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6cc40b70a4a669ae3db74f17e05c044a3b05bf671339f555490e5f945b9c1e8b
|
|
| MD5 |
17f431d74eea3717636144d23a03c4dd
|
|
| BLAKE2b-256 |
0236ae9bf9346180241d7eee72fea088fa2ac5b5335aa45577a7b77a78bac5a5
|
Provenance
The following attestation bundles were made for liteinfer-0.0.2.tar.gz:
Publisher:
publish.yml on ValeGian/liteinfer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
liteinfer-0.0.2.tar.gz -
Subject digest:
6cc40b70a4a669ae3db74f17e05c044a3b05bf671339f555490e5f945b9c1e8b - Sigstore transparency entry: 1435096936
- Sigstore integration time:
-
Permalink:
ValeGian/liteinfer@619905f525b02bee227306881c3074e4a34cafa0 -
Branch / Tag:
refs/tags/v0.0.2 - Owner: https://github.com/ValeGian
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@619905f525b02bee227306881c3074e4a34cafa0 -
Trigger Event:
release
-
Statement type:
File details
Details for the file liteinfer-0.0.2-py3-none-any.whl.
File metadata
- Download URL: liteinfer-0.0.2-py3-none-any.whl
- Upload date:
- Size: 9.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
518dd98a266424da76991b1d1afa4c2e47c598847f29d6ae26ae29372d3c26ac
|
|
| MD5 |
a2fd0119658c6fdd57b855ae00de6678
|
|
| BLAKE2b-256 |
918c21d9178c69cd98a63f1dd5232a23d0b6b15e51c0fc3525e61a7d88be0ae2
|
Provenance
The following attestation bundles were made for liteinfer-0.0.2-py3-none-any.whl:
Publisher:
publish.yml on ValeGian/liteinfer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
liteinfer-0.0.2-py3-none-any.whl -
Subject digest:
518dd98a266424da76991b1d1afa4c2e47c598847f29d6ae26ae29372d3c26ac - Sigstore transparency entry: 1435096953
- Sigstore integration time:
-
Permalink:
ValeGian/liteinfer@619905f525b02bee227306881c3074e4a34cafa0 -
Branch / Tag:
refs/tags/v0.0.2 - Owner: https://github.com/ValeGian
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@619905f525b02bee227306881c3074e4a34cafa0 -
Trigger Event:
release
-
Statement type: