{"id":50585620,"url":"https://github.com/ifuryst/nanollmserve","last_synced_at":"2026-06-05T06:02:16.752Z","repository":{"id":358180036,"uuid":"1240373468","full_name":"iFurySt/nanoLLMServe","owner":"iFurySt","description":"🌱 A tiny, readable LLM serving engine with vLLM/SGLang-style features.","archived":false,"fork":false,"pushed_at":"2026-05-28T06:29:07.000Z","size":280,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-28T08:14:43.308Z","etag":null,"topics":["ai-infra","continuous-batching","fastapi","inference","kv-cache","llm","llm-engine","llm-inference","llm-infra","llm-serving","lora","openai-compatible","paged-attention","pytorch","quantization","sglang","speculative-decoding","teaching","transformers","vllm"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iFurySt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":"AGENTS.md","dco":null,"cla":null}},"created_at":"2026-05-16T04:09:53.000Z","updated_at":"2026-05-28T06:29:11.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/iFurySt/nanoLLMServe","commit_stats":null,"previous_names":["ifuryst/nanollmserve"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/iFurySt/nanoLLMServe","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iFurySt%2FnanoLLMServe","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iFurySt%2FnanoLLMServe/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iFurySt%2FnanoLLMServe/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iFurySt%2FnanoLLMServe/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iFurySt","download_url":"https://codeload.github.com/iFurySt/nanoLLMServe/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iFurySt%2FnanoLLMServe/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33932040,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-05T02:00:06.157Z","response_time":120,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai-infra","continuous-batching","fastapi","inference","kv-cache","llm","llm-engine","llm-inference","llm-infra","llm-serving","lora","openai-compatible","paged-attention","pytorch","quantization","sglang","speculative-decoding","teaching","transformers","vllm"],"created_at":"2026-06-05T06:02:14.880Z","updated_at":"2026-06-05T06:02:16.747Z","avatar_url":"https://github.com/iFurySt.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nanoLLMServe\n\n[![English](https://img.shields.io/badge/English-Click-yellow)](./README.md)\n[![简体中文](https://img.shields.io/badge/简体中文-点击查看-orange)](./README.zh-CN.md)\n\n`nanoLLMServe` is a tiny, readable LLM serving engine.\n\nThe goal is to build a small vLLM/SGLang-style system that can actually run,\nwhile keeping each production serving idea easy to inspect:\n\n- OpenAI-compatible API\n- KV cache decode\n- batching and continuous batching\n- block KV cache management\n- prefix cache\n- chunked prefill\n- metrics, structured output, speculative decoding, LoRA, quantization, and distributed serving\n\nIt is not trying to be faster than vLLM. It is trying to make the serving stack\nunderstandable.\n\n## Roadmap\n\nMilestones live in [`docs/exec-plans/active/milestones`](./docs/exec-plans/active/milestones).\n\nStart with [`v0.0-naive-single-request`](./docs/exec-plans/active/milestones/v0.0-naive-single-request.md),\nexpose it through the [`v0.1 OpenAI-compatible server`](./docs/exec-plans/active/milestones/v0.1-openai-compatible-server.md),\nthen switch generation to [`v0.2 KV cache decode`](./docs/exec-plans/active/milestones/v0.2-kv-cache-decode.md).\n\n## Quick Start\n\nInstall the package in a virtual environment:\n\n```bash\nuv venv --python python3\nsource .venv/bin/activate\nuv pip install -e \".[dev]\"\n```\n\nGenerate text for one prompt:\n\n```bash\nnanollm-generate \\\n  --model Qwen/Qwen3-1.7B \\\n  --prompt \"Explain KV cache in one sentence.\" \\\n  --max-new-tokens 32 \\\n  --temperature 0 \\\n  --show-stats\n```\n\nOn the A100 harness machine, use the cached local weights:\n\n```bash\nnanollm-generate \\\n  --model /data2/nanoLLMServe/models/Qwen3-1.7B \\\n  --local-files-only \\\n  --prompt \"Explain KV cache in one sentence.\" \\\n  --max-new-tokens 32 \\\n  --temperature 0 \\\n  --show-stats\n```\n\n## v0.2 KV Cache Decode\n\nThe default generation path now runs one prefill pass over the prompt and then\nuses Hugging Face `past_key_values` so each later decode step only receives the\nlast generated token.\n\nRun the benchmark with a v0.0-style naive baseline comparison:\n\n```bash\npython benchmarks/benchmark_generate.py \\\n  --model /data2/nanoLLMServe/models/Qwen3-1.7B \\\n  --local-files-only \\\n  --runs 3 \\\n  --warmup 1\n```\n\nThe JSON output includes `kv_cache_decode.mean_ttft_seconds`,\n`kv_cache_decode.mean_tpot_seconds`, and a `comparison` section with elapsed and\nTPOT speedup against the naive full-sequence loop.\n\n## v0.3 Static Batching (Teaching-Scale)\n\nYou can benchmark fixed-size static batching with `--batch-size`:\n\n```bash\npython benchmarks/benchmark_generate.py \\\n  --model /data2/nanoLLMServe/models/Qwen3-1.7B \\\n  --local-files-only \\\n  --batch-size 4 \\\n  --runs 5 \\\n  --warmup 2\n```\n\nThe output will include `static_batch`, including batch elapsed time and mean\nrow-level token throughput for the fixed-size group.\n\n## v0.4 Continuous Batching (Teaching-Scale)\n\nWhen `--batch-size` is greater than 1, the benchmark now also runs a\nteaching-scale continuous batching path. It admits requests over scheduler\nsteps, rebuilds the active batch each step, and reports active batch sizes:\n\n```bash\npython benchmarks/benchmark_generate.py \\\n  --model /data2/nanoLLMServe/models/Qwen3-1.7B \\\n  --local-files-only \\\n  --batch-size 4 \\\n  --runs 5 \\\n  --warmup 2 \\\n  --skip-naive-baseline\n```\n\nThe output includes `continuous_batch.active_batch_sizes` and\n`continuous_batch.mean_active_batch_size`. This milestone intentionally\nrecomputes full active rows; paged KV cache for dynamic rows belongs to v0.5.\n\n## v0.5 Block KV Cache Manager\n\nv0.5 adds allocator metadata for fixed-size KV blocks: a free block pool,\nrequest-to-block tables, allocation/release hooks in generation, and observable\nfragmentation metrics. It demonstrates the memory-management motivation behind\nPagedAttention without adding a custom GPU kernel yet.\n\nRun the synthetic fragmentation benchmark:\n\n```bash\npython benchmarks/benchmark_block_manager.py \\\n  --block-size 16 \\\n  --total-blocks 64 \\\n  --request-tokens 9,17,33,5,41,12\n```\n\nThe output compares block allocation against a contiguous fixed-slot baseline\nand reports `internal_fragmentation_tokens`, `block_utilization`, and\n`fragmentation_tokens_saved_vs_contiguous`.\n\n## v0.6 Prefix Cache\n\nv0.6 adds a teaching-scale prefix cache for the single-request generation path.\nIt hashes block-aligned prompt prefixes, stores sliced Hugging Face\n`past_key_values`, tracks hit/miss/ref-count/LRU state, and lets later requests\nwith the same prefix prefill only the uncached suffix.\n\nRun the repeated-prefix benchmark:\n\n```bash\npython benchmarks/benchmark_prefix_cache.py \\\n  --model /data2/nanoLLMServe/models/Qwen3-1.7B \\\n  --local-files-only \\\n  --runs 3 \\\n  --warmup 1\n```\n\nThe output compares `no_prefix_cache` with `prefix_cache` and reports\n`cache_hits`, `cache_misses`, `mean_ttft_seconds`, `mean_prefill_seconds`, and\nTTFT/prefill speedup ratios.\n\n## v0.7 Chunked Prefill\n\nv0.7 adds a decode-first chunked prefill scheduler for mixed long/short prompt\nworkloads. Long prompts are split by `max_prefill_tokens_per_step`, while short\nremaining prefills can run before the long prompt consumes another scheduler\nstep.\n\nRun the mixed workload benchmark:\n\n```bash\npython benchmarks/benchmark_chunked_prefill.py \\\n  --model /data2/nanoLLMServe/models/Qwen3-1.7B \\\n  --local-files-only \\\n  --max-prefill-tokens-per-step 64\n```\n\nThe output compares an arrival-order monolithic prefill baseline with\n`chunked_prefill`, including `prefill_tokens_per_step`,\n`short_first_token_step`, and `short_time_to_first_token_speedup`.\n\n## v0.1 OpenAI-Compatible Server\n\nServe one local or Hugging Face causal LM:\n\n```bash\nnanollm-serve \\\n  --model /data2/nanoLLMServe/models/Qwen3-1.7B \\\n  --served-model-name Qwen3-1.7B \\\n  --local-files-only \\\n  --host 127.0.0.1 \\\n  --port 8000\n```\n\nList models:\n\n```bash\ncurl http://127.0.0.1:8000/v1/models\n```\n\nCall the recommended Responses endpoint:\n\n```bash\ncurl http://127.0.0.1:8000/v1/responses \\\n  -H 'Content-Type: application/json' \\\n  -d '{\n    \"model\": \"Qwen3-1.7B\",\n    \"instructions\": \"Answer in one sentence.\",\n    \"input\": \"Explain KV cache.\",\n    \"max_output_tokens\": 32,\n    \"temperature\": 0\n  }'\n```\n\nCall the chat completions endpoint:\n\n```bash\ncurl http://127.0.0.1:8000/v1/chat/completions \\\n  -H 'Content-Type: application/json' \\\n  -d '{\n    \"model\": \"Qwen3-1.7B\",\n    \"messages\": [{\"role\": \"user\", \"content\": \"Explain KV cache in one sentence.\"}],\n    \"max_tokens\": 32,\n    \"temperature\": 0\n  }'\n```\n\nStreaming uses OpenAI-style server-sent events:\n\n```bash\ncurl -N http://127.0.0.1:8000/v1/responses \\\n  -H 'Content-Type: application/json' \\\n  -d '{\n    \"model\": \"Qwen3-1.7B\",\n    \"input\": \"KV cache is\",\n    \"max_output_tokens\": 16,\n    \"temperature\": 0,\n    \"stream\": true\n  }'\n```\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fifuryst%2Fnanollmserve","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fifuryst%2Fnanollmserve","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fifuryst%2Fnanollmserve/lists"}