# pzsacc/nano-vllm-lite architecture

> Architecture diagram of the GitHub repository pzsacc/nano-vllm-lite, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pzsacc/nano-vllm-lite
- Repository: https://github.com/pzsacc/nano-vllm-lite

## Overview

nano-vllm-lite is a lightweight, vLLM-style LLM inference engine. Its principal workflow accepts prompts and sampling parameters, schedules prefill/decode work, executes the Qwen3 model with paged KV cache, samples tokens, and returns decoded output; a separate async engine streams incremental text. The graph also preserves documented optimizations including prefix caching, chunked prefill, FP8 KV cache, CUDA Graphs, tensor parallelism, and custom kernels. Relationships are limited to shown imports/calls or README statements; unsampled subsystem links are omitted or marked unverified.

Main entry points: [`nano_vllm/engine/model_runner.py`](https://github.com/pzsacc/nano-vllm-lite/blob/main/nano_vllm/engine/model_runner.py) (GPU model runner), [`nano_vllm/models/qwen3.py`](https://github.com/pzsacc/nano-vllm-lite/blob/main/nano_vllm/models/qwen3.py) (Qwen3 model), [`nano_vllm/engine/llm_engine.py`](https://github.com/pzsacc/nano-vllm-lite/blob/main/nano_vllm/engine/llm_engine.py) (Offline engine), [`nano_vllm/engine/sequence.py`](https://github.com/pzsacc/nano-vllm-lite/blob/main/nano_vllm/engine/sequence.py) (Request sequence)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Request interfaces"]
  node_sync["Offline engine<br/>[llm_engine.py]"]
  node_async["Async stream engine"]
  node_sampling["Sampling settings<br/>[sampling_params.py]"]
end

subgraph group_runtime["Scheduling and state"]
  node_config["Engine configuration<br/>[config.py]"]
  node_scheduler["Batch scheduler<br/>[scheduler.py]"]
  node_sequence["Request sequence<br/>[sequence.py]"]
  node_blocks[("Paged KV manager<br/>[block_manager.py]")]
end

subgraph group_execution["Model execution"]
  node_runner["GPU model runner<br/>[model_runner.py]"]
  node_context["Step context<br/>[context.py]"]
  node_weights["Weight loader<br/>[loader.py]"]
end

subgraph group_compute["Model operations"]
  node_qwen["Qwen3 model<br/>[qwen3.py]"]
  node_attention["Paged attention<br/>[attention.py]"]
  node_linear["Linear layers<br/>[linear.py]"]
  node_norm["Normalization<br/>[layernorm.py]"]
  node_activation["SwiGLU activation<br/>[activation.py]"]
  node_embedding["Embedding and head<br/>[embed_head.py]"]
  node_rope["Rotary embedding"]
  node_sampler["Token sampler<br/>[sampler.py]"]
  node_kernels["Custom CUDA kernels"]
end

node_caller(("Inference client"))

node_caller -->|"requests generation"| node_sync
node_caller -->|"requests streaming"| node_async
node_sync -->|"creates config"| node_config
node_sync -->|"creates scheduler"| node_scheduler
node_sync -->|"runs steps"| node_runner
node_sync -->|"creates requests"| node_sequence
node_sync -->|"accepts parameters"| node_sampling
node_async -->|"extends engine"| node_sync
node_async -->|"creates requests"| node_sequence
node_async -->|"accepts parameters"| node_sampling
node_scheduler -->|"schedules"| node_sequence
node_scheduler -->|"allocates cache"| node_blocks
node_blocks -->|"maps blocks"| node_sequence
node_runner -->|"reads settings"| node_config
node_runner -->|"prepares batches"| node_sequence
node_runner -->|"runs forward"| node_qwen
node_runner -->|"samples logits"| node_sampler
node_runner -->|"sets step metadata"| node_context
node_runner -->|"loads weights"| node_weights
node_qwen -->|"builds attention"| node_attention
node_qwen -->|"builds projections"| node_linear
node_qwen -->|"builds norms"| node_norm
node_qwen -->|"uses activation"| node_activation
node_qwen -->|"builds token layers"| node_embedding
node_qwen -->|"uses RoPE"| node_rope
node_attention -->|"reads metadata"| node_context
node_norm -.->|"may use fused kernels"| node_kernels

click node_sync "https://github.com/pzsacc/nano-vllm-lite/blob/main/nano_vllm/engine/llm_engine.py"
click node_async "https://github.com/pzsacc/nano-vllm-lite/blob/main/nano_vllm/engine/async_llm_engine.py"
click node_sampling "https://github.com/pzsacc/nano-vllm-lite/blob/main/nano_vllm/sampling_params.py"
click node_config "https://github.com/pzsacc/nano-vllm-lite/blob/main/nano_vllm/config.py"
click node_scheduler "https://github.com/pzsacc/nano-vllm-lite/blob/main/nano_vllm/engine/scheduler.py"
click node_sequence "https://github.com/pzsacc/nano-vllm-lite/blob/main/nano_vllm/engine/sequence.py"
click node_blocks "https://github.com/pzsacc/nano-vllm-lite/blob/main/nano_vllm/engine/block_manager.py"
click node_runner "https://github.com/pzsacc/nano-vllm-lite/blob/main/nano_vllm/engine/model_runner.py"
click node_context "https://github.com/pzsacc/nano-vllm-lite/blob/main/nano_vllm/utils/context.py"
click node_weights "https://github.com/pzsacc/nano-vllm-lite/blob/main/nano_vllm/utils/loader.py"
click node_qwen "https://github.com/pzsacc/nano-vllm-lite/blob/main/nano_vllm/models/qwen3.py"
click node_attention "https://github.com/pzsacc/nano-vllm-lite/blob/main/nano_vllm/layers/attention.py"
click node_linear "https://github.com/pzsacc/nano-vllm-lite/blob/main/nano_vllm/layers/linear.py"
click node_norm "https://github.com/pzsacc/nano-vllm-lite/blob/main/nano_vllm/layers/layernorm.py"
click node_activation "https://github.com/pzsacc/nano-vllm-lite/blob/main/nano_vllm/layers/activation.py"
click node_embedding "https://github.com/pzsacc/nano-vllm-lite/blob/main/nano_vllm/layers/embed_head.py"
click node_rope "https://github.com/pzsacc/nano-vllm-lite/blob/main/nano_vllm/layers/rotary_embedding.py"
click node_sampler "https://github.com/pzsacc/nano-vllm-lite/blob/main/nano_vllm/layers/sampler.py"
click node_kernels "https://github.com/pzsacc/nano-vllm-lite/tree/main/nano_vllm/kernels"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_sync,node_async,node_sampling,node_caller toneBlue
class node_config,node_scheduler,node_sequence,node_blocks toneAmber
class node_runner,node_context,node_weights toneMint
class node_qwen,node_attention,node_linear,node_norm,node_activation,node_embedding,node_rope,node_sampler,node_kernels toneRose
```

## Components

### Request interfaces

- [Offline engine](https://github.com/pzsacc/nano-vllm-lite/blob/main/nano_vllm/engine/llm_engine.py): `nano_vllm/engine/llm_engine.py`
- [Async stream engine](https://github.com/pzsacc/nano-vllm-lite/blob/main/nano_vllm/engine/async_llm_engine.py): `nano_vllm/engine/async_llm_engine.py`
- [Sampling settings](https://github.com/pzsacc/nano-vllm-lite/blob/main/nano_vllm/sampling_params.py): `nano_vllm/sampling_params.py`

### Scheduling and state

- [Engine configuration](https://github.com/pzsacc/nano-vllm-lite/blob/main/nano_vllm/config.py): `nano_vllm/config.py`
- [Batch scheduler](https://github.com/pzsacc/nano-vllm-lite/blob/main/nano_vllm/engine/scheduler.py): `nano_vllm/engine/scheduler.py`
- [Request sequence](https://github.com/pzsacc/nano-vllm-lite/blob/main/nano_vllm/engine/sequence.py): `nano_vllm/engine/sequence.py`
- [Paged KV manager](https://github.com/pzsacc/nano-vllm-lite/blob/main/nano_vllm/engine/block_manager.py): `nano_vllm/engine/block_manager.py`

### Model execution

- [GPU model runner](https://github.com/pzsacc/nano-vllm-lite/blob/main/nano_vllm/engine/model_runner.py): `nano_vllm/engine/model_runner.py`
- [Step context](https://github.com/pzsacc/nano-vllm-lite/blob/main/nano_vllm/utils/context.py): `nano_vllm/utils/context.py`
- [Weight loader](https://github.com/pzsacc/nano-vllm-lite/blob/main/nano_vllm/utils/loader.py): `nano_vllm/utils/loader.py`

### Model operations

- [Qwen3 model](https://github.com/pzsacc/nano-vllm-lite/blob/main/nano_vllm/models/qwen3.py): `nano_vllm/models/qwen3.py`
- [Paged attention](https://github.com/pzsacc/nano-vllm-lite/blob/main/nano_vllm/layers/attention.py): `nano_vllm/layers/attention.py`
- [Linear layers](https://github.com/pzsacc/nano-vllm-lite/blob/main/nano_vllm/layers/linear.py): `nano_vllm/layers/linear.py`
- [Normalization](https://github.com/pzsacc/nano-vllm-lite/blob/main/nano_vllm/layers/layernorm.py): `nano_vllm/layers/layernorm.py`
- [SwiGLU activation](https://github.com/pzsacc/nano-vllm-lite/blob/main/nano_vllm/layers/activation.py): `nano_vllm/layers/activation.py`
- [Embedding and head](https://github.com/pzsacc/nano-vllm-lite/blob/main/nano_vllm/layers/embed_head.py): `nano_vllm/layers/embed_head.py`
- [Rotary embedding](https://github.com/pzsacc/nano-vllm-lite/blob/main/nano_vllm/layers/rotary_embedding.py): `nano_vllm/layers/rotary_embedding.py`
- [Token sampler](https://github.com/pzsacc/nano-vllm-lite/blob/main/nano_vllm/layers/sampler.py): `nano_vllm/layers/sampler.py`
- [Custom CUDA kernels](https://github.com/pzsacc/nano-vllm-lite/tree/main/nano_vllm/kernels): `nano_vllm/kernels`

### Other components

- **Inference client**

## Connections

- Inference client → Offline engine: requests generation (evidence: `README.md`)
- Inference client → Async stream engine: requests streaming (evidence: `README.md`)
- Offline engine → Engine configuration: creates config (evidence: `nano_vllm/engine/llm_engine.py`)
- Offline engine → Batch scheduler: creates scheduler (evidence: `nano_vllm/engine/llm_engine.py`)
- Offline engine → GPU model runner: runs steps (evidence: `nano_vllm/engine/llm_engine.py`)
- Offline engine → Request sequence: creates requests (evidence: `nano_vllm/engine/llm_engine.py`)
- Offline engine → Sampling settings: accepts parameters (evidence: `nano_vllm/engine/llm_engine.py`)
- Async stream engine → Offline engine: extends engine (evidence: `nano_vllm/engine/async_llm_engine.py`)
- Async stream engine → Request sequence: creates requests (evidence: `nano_vllm/engine/async_llm_engine.py`)
- Async stream engine → Sampling settings: accepts parameters (evidence: `nano_vllm/engine/async_llm_engine.py`)
- Batch scheduler → Request sequence: schedules (evidence: `nano_vllm/engine/scheduler.py`)
- Batch scheduler → Paged KV manager: allocates cache (evidence: `nano_vllm/engine/scheduler.py`)
- Paged KV manager → Request sequence: maps blocks (evidence: `nano_vllm/engine/block_manager.py`)
- GPU model runner → Engine configuration: reads settings (evidence: `nano_vllm/engine/model_runner.py`)
- GPU model runner → Request sequence: prepares batches (evidence: `nano_vllm/engine/model_runner.py`)
- GPU model runner → Qwen3 model: runs forward (evidence: `nano_vllm/engine/model_runner.py`)
- GPU model runner → Token sampler: samples logits (evidence: `nano_vllm/engine/model_runner.py`)
- GPU model runner → Step context: sets step metadata (evidence: `nano_vllm/engine/model_runner.py`)
- GPU model runner → Weight loader: loads weights (evidence: `nano_vllm/engine/model_runner.py`)
- Qwen3 model → Paged attention: builds attention (evidence: `nano_vllm/models/qwen3.py`)
- Qwen3 model → Linear layers: builds projections (evidence: `nano_vllm/models/qwen3.py`)
- Qwen3 model → Normalization: builds norms (evidence: `nano_vllm/models/qwen3.py`)
- Qwen3 model → SwiGLU activation: uses activation (evidence: `nano_vllm/models/qwen3.py`)
- Qwen3 model → Embedding and head: builds token layers (evidence: `nano_vllm/models/qwen3.py`)
- Qwen3 model → Rotary embedding: uses RoPE (evidence: `nano_vllm/models/qwen3.py`)
- Paged attention → Step context: reads metadata (evidence: `nano_vllm/layers/attention.py`)
- Normalization → Custom CUDA kernels: may use fused kernels (evidence: `nano_vllm/layers/layernorm.py`)
