Serve a local model on the CPU
Load compatible local weights and serve bounded loopback chat with one scheduled sequence.
// Development source runtime with the optional native LLM engine required.
// Replace the path with an admitted single-file llama/qwen2 chat GGUF.
// Host RAM must accommodate the weights, context, workspace and operating system.
import aner.llm
import aner.api
let base = llm.load("models/local-instruct-q4.gguf", context: 2048,
device: "cpu", kv_cache_type: "f16", flash_attention: "auto")
let tuned = base.with_optimizer(
threads: 4, prefill_threads: 4,
batch_tokens: 128, micro_batch_tokens: 32,
prefix_cache_entries: 0, prefix_cache_tokens: 1024,
speculative_tokens: 0)
// One shared scheduler context. Named conversation sessions are unavailable.
let serving = tuned.with_batching(max_sequences: 1)
tuned.close()
base.close()
// Exercise context/workspace allocation before binding the server socket.
let warmup = serving.generate("Say hello.", max_tokens: 1)
print(warmup.text())
print(serving.load_summary())
print(serving.memory_summary())
let app = api.app("Aner CPU chat").llm(path: "/chat", model: serving)
.bind(host: "127.0.0.1", port: 11435)
.limits(max_rows: 64, timeout_ms: 120000)
.output_limit(max_tokens: 128)
app.serve()
serving.close()
Make it your experiment.
Use Aner 0.1.0 or newer. Save this program as examples/llm_cpu_server.aner inside a folder for your experiment. Open a terminal in that folder, then check and run the program.
aner check examples/llm_cpu_server.aner
aner run examples/llm_cpu_server.anerThe aner command must be on your PATH. Follow the installation guide if your terminal cannot find it.
Requires Aner 0.1.0 or newer. Requires Aner 0.0.9 or newer. Requires a matching native inference runtime and a separately supplied compatible local GGUF model. Checking loads no model and opens no listener or connection. Running loads weights, performs a short warmup and serves on loopback until stopped. Adjust context and budgets to the actual machine.
aner check examples/llm_cpu_server.aner
aner run examples/llm_cpu_server.anerClient construction and syntax checking send no inference request. Running this program calls its explicit model service. Inspect the returned finish reason and reported usage; unavailable token counts remain unknown and usage does not verify charges.
Read token accounting and provider requirements