มาอธิบายเรื่องนี้แบบครบจบในที่เดียวเลยครับ
เรียกว่า "LLM Serving" หรือ "LLM Inference Server" — หมายถึงระบบที่เอาโมเดลภาษา (LLM) มา "เปิดบริการ" ผ่าน API (มักเป็น OpenAI-compatible) เพื่อให้แอปหรือ agent เรียกใช้ได้ตลอดเวลา แบบเดียวกับที่ OpenAI เปิด endpoint api.openai.com — แต่รันบนเครื่องตัวเองinference
Engine | เหมาะกับ | Backend | Quantization | ข้อเด่น |
|---|---|---|---|---|
llama.cpp | Local / CPU+GPU | C++ GGUF | GGUF (Q4, Q8, etc.) | รันบน CPU ได้, VRAM น้อยก็ไหว |
SGLang | Production GPU | Python/CUDA | fp8, fp4, AWQ, GPTQ | Throughput สูงสุด, structured output |
vLLM | Production GPU | Python/CUDA | GPTQ, AWQ, fp8 | Stability, รองรับ 50+ architectures |
MLX | Apple Silicon | Metal | 4-bit, 8-bit | เฉพาะ Mac, ใช้ Unified Memory |
dev+1
llama.cpp คือ C++ inference engine ที่รัน GGUF format ใช้ได้ทั้ง CPU และ GPU แบบ hybrid offload เหมาะมากสำหรับคนมี VRAM ไม่พอรันโมเดลเต็มjia
bash# เปิด server (OpenAI-compatible API)
llama-server \
--model Qwen3.6-35B-A3B-UD-Q4_K_XL.gguf \
--ctx-size 131072 \
--n-gpu-layers 99 \
--flash-attn \
--host 0.0.0.0 \
--port 8008--n-gpu-layers 99→ offload layers ทั้งหมดขึ้น GPU เท่าที่ VRAM รับได้--ctx-size 131072→ context window 128K tokens--flash-attn→ ประหยัด VRAM ลดได้มากGGUF format ที่นิยม:
Q4_K_XL,Q3_K_XLจาก unslothjia
ทดสอบด้วย Q4_K_XL บน RTX 4090 ได้ประมาณ 30–50 tokens/sec ขึ้นอยู่กับ context lengthjia
คำสั่งที่ยกมานั้นถูกต้องและเป็น Production-grade SGLang setup ครับ — มาแกะทีละ flag:
bash--gpus all # ให้ container เข้าถึง GPU ทุกตัว
--ipc host # shared memory กับ host (จำเป็นสำหรับ multi-GPU NCCL)
--shm-size 64gb # ขยาย /dev/shm สำหรับ tensor sharing
--restart unless-stopped # auto-restart เมื่อ crash--ipc host+--shm-size→ คู่นี้สำคัญมากสำหรับ tensor parallelism ถ้าไม่มีจะ crashdevVolume mount PTXAS → map binary ของ CUDA Triton compiler เข้าไปตรงๆ เพราะ container อาจมี version ไม่ตรงกับ host
bash--mem-fraction-static 0.6 # จอง 60% ของ VRAM เป็น static KV cache
--context-length 262144 # 256K context (ยาวมาก!)
--trust-remote-code # Qwen ต้องการ flag นี้
--reasoning-parser qwen3 # parse <think>...</think> tokens
--tool-call-parser qwen3_coder # parse function calling format
--quantization modelopt_fp4 # NVIDIA fp4 quant (ต้องการ Blackwell/Hopper)
--disable-cuda-graph # ปิด CUDA graph (debug หรือ compatibility)--reasoning-parser qwen3→ SGLang จะแยก reasoning trace กับ output ออกจากกันอัตโนมัติdeveloper.nvidiamodelopt_fp4→ เป็น NVIDIA-specific quantization ต้องการ GPU รุ่น H100/B200 ขึ้นไปjoshua8--disable-cuda-graph→ ถ้าเจอ bug หรือ OOM ปิดก่อนได้ แต่จะช้าลงนิดหน่อย
Feature | SGLang | vLLM | Ollama |
|---|---|---|---|
Max throughput | ⭐⭐⭐ สูงสุด | ⭐⭐ | ⭐ |
Concurrent users | 100% pass @ 128 req | 100% pass @ 128 req | break joshua8 |
Setup ยาก | ปานกลาง | ปานกลาง | ง่ายมาก |
Docker image |
|
|
|
Structured output | native | ||
Reasoning parser | (qwen3, deepseek) |
joshua8+1
llama.cpp → เลือกถ้า VRAM ไม่พอ หรืออยาก run บน CPU/Mac — ใช้ GGUF format
SGLang → เลือกถ้ามี GPU เต็มๆ และต้องการ throughput + tool-use + reasoning parser ครบ
vLLM → เลือกถ้าต้องการ stability และรองรับ model architecture หลากหลาย
MLX → เลือกถ้าเป็น Apple Silicon (M-series) อย่างเดียว — ไม่มีบน Linux/Windows
Unsloth → ไม่ใช่ serving engine ตรงๆ แต่เป็นตัว fine-tune + export GGUF/gguf-quant ที่เร็วและประหยัด VRAMjia

