This repository is my attempt to learn inference engineering by building and implementing things myself. I am reading Philip Kiely's inference engineering book and, whenever I encounter something unfamiliar or do not feel confident about a concept, I dig deeper by reading more and implementing a small representation of it here.
The end goal is to build my own inference engine.
A compact encoder-decoder Transformer based on the Attention Is All You Need paper.
config.pydefines the model dimensions, includingn_layers.layers.pyimplements positional encoding, multi-head attention, embeddings, feed-forward layers, and the language-model head.encoder.pyanddecoder.pyeach buildn_layersindependent blocks withnn.ModuleList.transformer.pyconnects encoder, decoder, and output head.
Run the example:
uv run python -m attention_paper.transformerA focused representation of autoregressive KV-cache flow. For each decoder
layer, cache.py stores projected keys and values during
prefill, then appends only the new token during decoding. The query attends over
the whole accumulated cache with a causal mask.
It intentionally omits surrounding Transformer components such as positional encodings, residual paths, norms, FFNs, and the output head. See the Hugging Face cache explanation for the production concept.
Run its prefill and token-by-token decode demonstration:
uv run python kv_cache/cache.py