override.conf.j2 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. [Service]
  2. # ── Ollama API & model settings ────────────────────────────────────────────
  3. Environment="OLLAMA_API_KEY={{ ollama_api_key }}"
  4. Environment="OLLAMA_HOST=0.0.0.0:11434"
  5. Environment="OLLAMA_MODELS=/mnt/ai_data/ollama_models"
  6. Environment="OLLAMA_KEEP_ALIVE=-1"
  7. # ── Inference performance ──────────────────────────────────────────────────
  8. # Flash attention: fused softmax, ~20% less memory bandwidth, faster on AVX2
  9. Environment="OLLAMA_FLASH_ATTENTION=1"
  10. # Threads: 14 physical cores on NUMA node 1 only (no hyperthreads).
  11. # LLM inference is memory-bandwidth-bound; HT siblings share the same memory
  12. # pipeline and add scheduling overhead without adding bandwidth.
  13. Environment="OLLAMA_NUM_THREADS={{ ollama_num_threads }}"
  14. # Parallel inference streams — 2 simultaneous requests, 7 threads each.
  15. # Keeps per-request throughput high for interactive/single-user workloads.
  16. Environment="OLLAMA_NUM_PARALLEL={{ ollama_num_parallel }}"
  17. # Keep 3 models warm in RAM per instance (KEEP_ALIVE=-1 means never unload; 6 total across both sockets)
  18. Environment="OLLAMA_MAX_LOADED_MODELS={{ ollama_max_loaded_models }}"
  19. # ── NUMA / CPU binding ────────────────────────────────────────────────────
  20. # ExecStart override: numactl --membind=1 guarantees model weights and KV
  21. # cache are allocated from NUMA node 1 RAM (120 GB free). CPUAffinity alone
  22. # does not set the memory policy; numactl makes it explicit.
  23. ExecStart=
  24. ExecStart=/usr/bin/numactl --membind=1 {{ ollama_binary_path }} serve
  25. # Restrict scheduler to physical cores on node 1 only (odd CPUs 1–27).
  26. # Omitting HT siblings (29–55) prevents cross-HT contention on the memory bus.
  27. CPUAffinity={{ ollama_cpu_affinity }}
  28. # ── Memory hardening ───────────────────────────────────────────────────────
  29. # Prevent model weights from being paged out under memory pressure
  30. LimitMEMLOCK=infinity
  31. # Sufficient file descriptors for parallel connections and mmap'd model files
  32. LimitNOFILE=65535
  33. # Disable OOM kill — losing a loaded model mid-inference is worse than
  34. # the kernel reclaiming other memory first
  35. OOMScoreAdjust=-500