Skip to content

perf(backend): trim llama-server flags for the embedding-only workload#15

Merged
couragehong merged 1 commit into
CryptoLabInc:mainfrom
couragehong:perf/llama-server-embed-memory
Jul 14, 2026
Merged

perf(backend): trim llama-server flags for the embedding-only workload#15
couragehong merged 1 commit into
CryptoLabInc:mainfrom
couragehong:perf/llama-server-embed-memory

Conversation

@couragehong

@couragehong couragehong commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

문제

runed가 스폰하는 llama-server가 임베딩 전용 워크로드인데 chat 서빙 기본값으로 떠서 메모리를 크게 낭비합니다:

원인 비용 근거
프롬프트 캐시 (기본 상한 8 GiB) 요청당 ~14 MiB 축적, 적중률 ~0% (임베딩 텍스트는 매번 유일) 대량 capture 주행 중 RSS 1.8 GB → 3.6 GB 실측, prompt_save 로그 95건 × 14 MiB와 일치
CPU REPACK mmap 가중치 640 MiB를 첫 추론 때 익명 메모리로 복사 vmmap 실측
n_parallel auto=4 슬롯 KV 캐시 ×4 (ctx 2048에서 ~940 MiB) 기동 로그

변경

startLocked 스폰 인자에 추가: --cache-ram 0 --no-repack --parallel 1 --batch-size 256 --ubatch-size 256 --cache-type-k q8_0 --cache-type-v q8_0

--ctx-size는 의도적으로 유지 — 최대 입력 토큰 의미(초과 시 HTTP 400)라 줄이면 동작 변경이 됩니다.

실측 (darwin-arm64, qwen3-embedding-0.6b q8)

  • 메모리: 실질 footprint 2.8 GB(8 GB까지 성장 중) → 1.0 GB 고정 (동형 부하 2라운드에 +2 MB)
  • 품질: 스톡 플래그 대비 임베딩 코사인 0.9986–0.9996 (한글 단문 / 장문 1,700토큰 / 영문 / 코드 혼합), 랭킹 보존, ctx 초과 거절 동작 동일
  • 지연: ~+15–20% (no-repack, CPU 백엔드) — capture 실경로 p50 333→382 ms
  • 유휴 시에는 기존 idle-suspend가 프로세스째 내리므로(기본 10 m) 유휴 메모리는 변함없이 0

llama-server's defaults are tuned for chat serving and cost an embedding
daemon real memory:

- prompt cache (default cap 8 GiB) saves ~14 MiB of state per request at
  a ~0% hit rate, since every embedded text is unique — measured growing
  1.8 GB -> 3.6 GB during a bulk-capture run. --cache-ram 0 disables it.
- CPU REPACK copies the mmap'd q8 weights (~640 MiB) into private
  anonymous memory on first use. --no-repack keeps them on the shared,
  reclaimable file mapping (~+20% embed latency on CPU).
- n_parallel auto-selects 4 slots, quadrupling the KV cache (~940 MiB at
  ctx 2048) for concurrency a one-shot embed workload lacks. --parallel 1.
- smaller physical batch + q8_0 KV shrink compute scratch and cache
  without changing results or the max input length.

Measured on darwin-arm64 (qwen3-embedding-0.6b q8): steady physical
footprint 2.8 GB (growing toward 8 GB) -> 1.0 GB flat. Embedding output
parity vs stock flags verified: cosine 0.9986-0.9996 across short/long/
Korean/English/code inputs; over-ctx rejection behavior identical.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014oTj8KKuD2q3feKTaqh81Y
@couragehong couragehong merged commit 93f51ac into CryptoLabInc:main Jul 14, 2026
6 checks passed
couragehong added a commit to couragehong/runed that referenced this pull request Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants