Skip to content

2026-08-18 tiny-llm vs llama.cpp 对比(RTX 3060 Laptop)

本文件为 benchmark-methodology.md 的实测归档。所有数字由下述命令在 同一块 GPU、同一时段测得。

后续口径审计(2026-08-23):本报告使用 benchmark schema v1。其 TTFT 来自 独立 1-token 请求,TPOT 用另一条完整请求墙钟减去该 TTFT;这是历史配对估计,不是 同一请求内的事件计时。数字保留用于优化沿革,不与 schema v2 直接合并,也不作为新的 简历基准。

1. 元信息

日期2026-08-18
GPUNVIDIA GeForce RTX 3060 Laptop GPU(6144 MiB,驱动 591.44)
CUDA Toolkit12.0(nvcc 12.0.140)
tiny-llm commitd234157
llama.cpp commit885c5bb(build-cuda:-DGGML_CUDA=ON,backend=CUDA,-ngl 99
模型Qwen2.5-0.5B-Instruct,GGUF Q4_K_M
采样tiny-llm 使用 greedy;llama-bench 只测合成 token 吞吐、不执行文本采样;-t 1 是 CPU 线程数
原始日志仓库内仅存 markdown 摘要;stdout 重定向见各命令(可原样复现)

2. 复现命令(完整记录)

bash
# tiny-llm(tiny-llm 仓库根目录)
./build/tiny_llm_bench /home/shane/github/open-infra-ai/models/qwen2.5-0.5b-instruct-q4_k_m.gguf \
    --prompt "你好" --max-tokens 64 --warmup 3 --iters 10

# llama.cpp(llama.cpp 仓库根目录,CUDA 构建)
./build-cuda/bin/llama-bench \
    -m /home/shane/github/open-infra-ai/models/qwen2.5-0.5b-instruct-q4_k_m.gguf \
    -ngl 99 -n 64 -p 1 -t 1 -r 3

3. 结果

3.1 端到端指标

指标tiny-llmllama.cpp比值 (tiny/llama)
TTFT (ms)22.9(1 token prompt,含首次 logits)未按同口径测量;pp1=4.9ms 不是 TTFT不可比
TPOT (ms/token)22.13.7(tg64: 272.15 t/s)6.0
decode tok/s45.3272.20.17
常驻显存差值 (MB)2490(加载前 vs 运行后;非峰值)未测(同口径)

TTFT 口径声明:tiny-llm 的 TTFT 从调用 generate() 到第一个新 token 采样完成(含 prefill + 首次 logits + 采样);llama-bench 的 pp1 只测 1 个 prompt token 的 prompt 处理时间,不含 decode 首个 token。两者不可 直接相除,因此上表不再给出比值。要严格对齐 TTFT 需用 llama-cli 端到端计时(见 methodology 第 4 节)。

3.2 decode 吞吐口径

  • tiny-llm:--warmup 3 --iters 10,64 新 token,墙钟均值。
  • llama.cpp:llama-bench -n 64 -r 3 -t 1 -ngl 99tg64 列;-t 1 固定 CPU 线程,不表示 greedy。

4. 差距归因(实测后初判,待 profiling 数据回填)

对 0.5B decode 场景,tiny/llama ≈ 0.17,按 methodology 第 6 节假设排序:

  1. GEMM 实现差距:llama.cpp Q4_K_M 内核 SIMD 向量化 + 分块; tiny-llm W8A16 m1 kernel 是每 warp 一列、32 lane 归约 K 的简单实现, lm_head(FP16,[1, 512] @ [512, 151936])在 decode 中占比大。
  2. attention / KV 复用差距:tiny-llm decode attention 未做 KV L2/共享内存复用。
  3. launch 开销:24 层 × 多 kernel 串行;CUDA Graphs 已实现 (见 cuda-graphs.md)但本次对比为默认关闭状态。

5. 复现核对

  • [x] 命令可原样执行
  • [x] 数字与原始日志一致
  • [x] 硬件 / commit / 命令已记录

基于 MIT 许可证发布