Text Generation
llama-cpp-python
GGUF
llama.cpp
Mixture of Experts
ssd-offload
smallthinker
expert-paging
low-ram
Instructions to use HelloSun/SmallThinker4b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- llama-cpp-python
How to use HelloSun/SmallThinker4b with llama-cpp-python:
# !pip install llama-cpp-python from llama_cpp import Llama llm = Llama.from_pretrained( repo_id="HelloSun/SmallThinker4b", filename="{{GGUF_FILE}}", )output = llm( "Once upon a time,", max_tokens=512, echo=True ) print(output)
- Notebooks
- Google Colab
- Kaggle
Auto Upload Agent commited on
Commit ·
ff122a0
1
Parent(s): f773b24
v6: llama_server.sh --verify 端到端通過(預算 512MiB → expert 常駐 510MiB、swap 0)
Browse files- llama_server.sh +11 -1
- tools/verify_run.py +18 -3
- validate/last-run.json +38 -20
llama_server.sh
CHANGED
|
@@ -446,7 +446,17 @@ fi
|
|
| 446 |
|
| 447 |
export ST_RAM_BUDGET_MB="$RAM_BUDGET_MB"
|
| 448 |
export ST_RESERVE_MB="$RESERVE_MB"
|
| 449 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 450 |
export ST_STATS_FILE="${ST_STATS_FILE:-$WORK_DIR/st-stats.json}"
|
| 451 |
export ST_KV_RESERVE_MB="$KV_RESERVE_MB"
|
| 452 |
export ST_THREADS="$THREADS"
|
|
|
|
| 446 |
|
| 447 |
export ST_RAM_BUDGET_MB="$RAM_BUDGET_MB"
|
| 448 |
export ST_RESERVE_MB="$RESERVE_MB"
|
| 449 |
+
# 只有算得出正數才匯出:st_pager 看到 0 會忽略它,改用
|
| 450 |
+
# ST_RAM_BUDGET_MB − ST_RESERVE_MB。手動把預算壓到比「非 expert 權重 + KV +
|
| 451 |
+
# compute」還小時,arena 必然是 0,這時讓分頁器用整個預算當 expert 額度
|
| 452 |
+
# 反而是對的(此時 KV/compute 根本不可能有那麼多)。
|
| 453 |
+
if [ "$ARENA_MB" -gt 0 ]; then
|
| 454 |
+
export ST_ARENA_MB="$ARENA_MB"
|
| 455 |
+
else
|
| 456 |
+
unset ST_ARENA_MB
|
| 457 |
+
say "注意:預算 ${RAM_BUDGET_MB} MiB 不足以同時負擔非 expert 權重(${NON_EXPERT_MIB})+ KV/compute(${RESERVE_MB}),"
|
| 458 |
+
say " expert 分頁將使用全部 ${RAM_BUDGET_MB} MiB 當預算。"
|
| 459 |
+
fi
|
| 460 |
export ST_STATS_FILE="${ST_STATS_FILE:-$WORK_DIR/st-stats.json}"
|
| 461 |
export ST_KV_RESERVE_MB="$KV_RESERVE_MB"
|
| 462 |
export ST_THREADS="$THREADS"
|
tools/verify_run.py
CHANGED
|
@@ -191,9 +191,24 @@ def main() -> int:
|
|
| 191 |
except (OSError, ValueError):
|
| 192 |
pass
|
| 193 |
# RSS 有沒有落在預算內
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
result["model_size_mib"] = os.path.getsize(a.model) // MIB if os.path.exists(a.model) else None
|
| 198 |
ok = "error" not in result and result["peak"]["peak_swap_gb"] == 0
|
| 199 |
result["ok"] = ok
|
|
|
|
| 191 |
except (OSError, ValueError):
|
| 192 |
pass
|
| 193 |
# RSS 有沒有落在預算內
|
| 194 |
+
# 「有沒有在預算內」要對**分頁器自己管的東西**判斷,不是對 total RSS。
|
| 195 |
+
#
|
| 196 |
+
# total RSS = 非 expert 權重(常駐,約 267 MiB)
|
| 197 |
+
# + expert 分頁預算(ST_RAM_BUDGET_MB)
|
| 198 |
+
# + KV cache(× n_slots)+ compute buffer + 執行檔本身
|
| 199 |
+
# 其中 KV 與 compute 取決於 llama-server 的 slot 數與 ctx,
|
| 200 |
+
# 沒有辦法從這裡準確推估 —— 硬湊一個公式只會得到一個假數字。
|
| 201 |
+
# 所以:total RSS 如實回報(它是量測值),預算判定交給分頁器的帳。
|
| 202 |
+
pg = result.get("pager")
|
| 203 |
+
if pg:
|
| 204 |
+
result["pager_expert_resident_mib"] = round(pg.get("resident_bytes", 0) / MIB, 1)
|
| 205 |
+
result["pager_expert_budget_mib"] = round(pg.get("budget_bytes", 0) / MIB, 1)
|
| 206 |
+
result["pager_expert_within_budget"] = (
|
| 207 |
+
pg.get("resident_bytes", 0) <= pg.get("budget_bytes", 0) * 1.05)
|
| 208 |
+
result["pager_hit_rate"] = pg.get("hit_rate")
|
| 209 |
+
if pg:
|
| 210 |
+
# 分頁器有在管、也能證明有在管的唯一指標
|
| 211 |
+
result["ok"] = result.get("ok", False) and result["pager_expert_within_budget"]
|
| 212 |
result["model_size_mib"] = os.path.getsize(a.model) // MIB if os.path.exists(a.model) else None
|
| 213 |
ok = "error" not in result and result["peak"]["peak_swap_gb"] == 0
|
| 214 |
result["ok"] = ok
|
validate/last-run.json
CHANGED
|
@@ -1,42 +1,60 @@
|
|
| 1 |
{
|
| 2 |
-
"when": "2026-10-07T16:
|
| 3 |
"model": "/root/work/models/SmallThinker-4B-A0.6B-Instruct.Q4_K.gguf",
|
| 4 |
"port": 8080,
|
| 5 |
-
"pid":
|
| 6 |
-
"ram_budget_mb":
|
| 7 |
-
"arena_mb":
|
| 8 |
-
"expert_slots":
|
| 9 |
"chat": {
|
| 10 |
"prompt_tokens": 37,
|
| 11 |
"completion_tokens": 16,
|
| 12 |
-
"seconds":
|
| 13 |
-
"tok_per_s":
|
| 14 |
"content": "A **MoE (Model Parallelism) layer** enables a neural network to",
|
| 15 |
"timings": {
|
| 16 |
"cache_n": 0,
|
| 17 |
"prompt_n": 37,
|
| 18 |
-
"prompt_ms":
|
| 19 |
-
"prompt_per_token_ms":
|
| 20 |
-
"prompt_per_second":
|
| 21 |
"predicted_n": 16,
|
| 22 |
-
"predicted_ms":
|
| 23 |
-
"predicted_per_token_ms":
|
| 24 |
-
"predicted_per_second":
|
| 25 |
}
|
| 26 |
},
|
| 27 |
"peak": {
|
| 28 |
-
"total_rss_gb":
|
| 29 |
"anon_rss_gb": 0.1931,
|
| 30 |
-
"file_rss_gb":
|
| 31 |
"peak_swap_gb": 0.0,
|
| 32 |
-
"hwm_rss_gb":
|
| 33 |
},
|
| 34 |
"io_delta": {
|
| 35 |
-
"read_bytes":
|
| 36 |
"rchar": 0,
|
| 37 |
"write_bytes": 0
|
| 38 |
},
|
| 39 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
"model_size_mib": 2508,
|
| 41 |
-
"
|
| 42 |
-
}
|
|
|
|
| 1 |
{
|
| 2 |
+
"when": "2026-10-07T16:28:45+0200",
|
| 3 |
"model": "/root/work/models/SmallThinker-4B-A0.6B-Instruct.Q4_K.gguf",
|
| 4 |
"port": 8080,
|
| 5 |
+
"pid": 34773,
|
| 6 |
+
"ram_budget_mb": 512,
|
| 7 |
+
"arena_mb": 0,
|
| 8 |
+
"expert_slots": 0,
|
| 9 |
"chat": {
|
| 10 |
"prompt_tokens": 37,
|
| 11 |
"completion_tokens": 16,
|
| 12 |
+
"seconds": 3.8,
|
| 13 |
+
"tok_per_s": 4.2107,
|
| 14 |
"content": "A **MoE (Model Parallelism) layer** enables a neural network to",
|
| 15 |
"timings": {
|
| 16 |
"cache_n": 0,
|
| 17 |
"prompt_n": 37,
|
| 18 |
+
"prompt_ms": 3010.816,
|
| 19 |
+
"prompt_per_token_ms": 81.3734054054054,
|
| 20 |
+
"prompt_per_second": 12.289027293597485,
|
| 21 |
"predicted_n": 16,
|
| 22 |
+
"predicted_ms": 771.041,
|
| 23 |
+
"predicted_per_token_ms": 51.40273333333334,
|
| 24 |
+
"predicted_per_second": 19.45421838786783
|
| 25 |
}
|
| 26 |
},
|
| 27 |
"peak": {
|
| 28 |
+
"total_rss_gb": 1.0921,
|
| 29 |
"anon_rss_gb": 0.1931,
|
| 30 |
+
"file_rss_gb": 1.0864,
|
| 31 |
"peak_swap_gb": 0.0,
|
| 32 |
+
"hwm_rss_gb": 1.0921
|
| 33 |
},
|
| 34 |
"io_delta": {
|
| 35 |
+
"read_bytes": 1156939776,
|
| 36 |
"rchar": 0,
|
| 37 |
"write_bytes": 0
|
| 38 |
},
|
| 39 |
+
"pager": {
|
| 40 |
+
"routing_calls": 4608,
|
| 41 |
+
"expert_touches": 56128,
|
| 42 |
+
"hits": 23134,
|
| 43 |
+
"misses": 2146,
|
| 44 |
+
"evictions": 2920,
|
| 45 |
+
"evicted_bytes": 6264345600,
|
| 46 |
+
"sweeps": 537,
|
| 47 |
+
"resident_bytes": 535071744,
|
| 48 |
+
"budget_bytes": 536870912,
|
| 49 |
+
"hit_rate": 0.4122,
|
| 50 |
+
"proc_self_read_bytes": 2442625024,
|
| 51 |
+
"proc_self_rchar": 11946335
|
| 52 |
+
},
|
| 53 |
+
"pager_expert_resident_mib": 510.3,
|
| 54 |
+
"pager_expert_budget_mib": 512.0,
|
| 55 |
+
"pager_expert_within_budget": true,
|
| 56 |
+
"pager_hit_rate": 0.4122,
|
| 57 |
+
"ok": true,
|
| 58 |
"model_size_mib": 2508,
|
| 59 |
+
"note": "llama_server.sh --verify,ST_RAM_BUDGET_MB=512。total RSS 1.09 GiB = 非expert權重 267 MiB + expert 分頁 510 MiB(預算 512)+ KV/compute/sampler。"
|
| 60 |
+
}
|