ai newsMi., 25. Nov.
EilmeldungYale’s Sonnenfeld: Nvidia is a ‘detriment’ to U.S. industrial might — not a champion

llama.cpp: Lokale LLM-Inferenz auf CPU und GPU mit GGUF-Modellen

llama.cpp ist eine C/C++-Implementierung ohne schwere Abhängigkeiten, die Sprachmodelle auf normaler CPU, Consumer-GPU oder Mac ausführt. Das von Georgi Gerganov gestartete Projekt zählt zu den meistbeobachteten im Bereich lokaler Inferenz.

dev.toMontag 12:30 · 23.11.DE5 Min. Lesezeit
Bild: dev.to

Veröffentlicht am 23. November, ursprünglich erschienen auf span.observer

llama.cpp ist die Engine, die lokales LLM-Inference für jedermann zugänglich gemacht hat: eine C/C++-Implementierung ohne schwere Abhängigkeiten, die ein Sprachmodell auf einer gewöhnlichen CPU, einer Consumer-GPU oder einem Mac ausführen kann. Das von Georgi Gerganov gestartete und inzwischen unter der Organisation ggml-org gepflegte Projekt ist eines der meistbeobachteten Open-Source-Projekte auf GitHub und ein Baustein für viele Werkzeuge, darunter Ollama.

Die direkte Nutzung von llama.cpp statt über einen Wrapper bietet mehrere Vorteile: feingranulare Kontrolle über Quantisierung, Kontextgröße und die Aufteilung der Layer zwischen CPU und GPU, schlanke Binaries, die sich leicht paketieren lassen, sowie ein eingebauter HTTP-Server, der den OpenAI-API-Dialekt spricht.

In diesem Artikel behandeln wir die zentralen Konzepte (GGUF, Quantisierung, GPU-Offloading), bauen llama-server und starten es, und betrachten dann die Überwachung: Health-Endpoint, Prometheus-Metriken, Logs und OpenTelemetry-Traces auf der Anwendungsseite, bis hin zu einem Backend wie Dynatrace.

Drei Konzepte genügen für den Einstieg.

Das Projekt liefert mehrere Werkzeuge mit: llama-cli für Chats im Terminal, llama-server, um ein Modell über HTTP bereitzustellen, llama-quantize zur Erzeugung quantisierter Varianten und llama-bench zur Leistungsmessung auf der eigenen Hardware.

Der schnellste Weg führt über ein Paket (Homebrew, winget und andere) oder über die vorgefertigten Binaries, die zu jedem Release auf GitHub veröffentlicht werden. Um ein bestimmtes Backend zu aktivieren, wird mit CMake gebaut:

git clone https://github.com/ggml-org/llama.cpp cd llama.cpp cmake -B build # nur CPU # cmake -B build -DGGML_CUDA=ON # mit CUDA cmake --build build --config Release -j ls build/bin/ # llama-cli, llama-server,... Vollbildmodus aktivieren Vollbildmodus beenden Build-Optionen und die Voraussetzungen für jedes Backend sind im Build-Guide im offiziellen llama.cpp-Repository beschrieben.

Eine.gguf-Datei lässt sich von Hugging Face herunterladen, oder llama.cpp übernimmt das mit der Option -hf, die ein Hugging-Face-Repository (und optional eine Quantisierungsvariante) entgegennimmt:

build/bin/llama-cli -hf ggml-org/gemma-3-1b-it-GGUF Vollbildmodus aktivieren Vollbildmodus beenden Wählen Sie die Quantisierung entsprechend dem verfügbaren Speicher: Ein Modell mit 7 bis 8 Milliarden Parametern in 4 Bit passt in wenige Gigabyte, während die 16-Bit-Version ein Vielfaches davon benötigt.

build/bin/llama-server \ -m models/my-model-Q4_K_M.gguf \ --host 127.0.0.1 --port 8080 \ -c 8192 \ -ngl 99 \ --metrics Vollbildmodus aktivieren Vollbildmodus beenden -c legt die Kontextgröße fest, -ngl die Anzahl der auf die GPU ausgelagerten Layer (ein hoher Wert legt sie bei ausreichendem Speicher alle dorthin), und --metrics aktiviert den Prometheus-Endpoint. Eine Option --api-key schützt den Zugriff, und eine Parallelismus-Option legt fest, wie viele Anfragen gleichzeitig bedient werden. Optionsnamen ändern sich im Laufe der Zeit: llama-server --help ist die maßgebliche Referenz.

Der Server bietet außerdem an seiner Root-Adresse eine kleine Weboberfläche an, praktisch für einen schnellen Test. Ein offizielles Container-Image wird in der GitHub-Registry des Projekts veröffentlicht.

curl -s http://127.0.0.1:8080/v1/chat/completions \ -H "Content-Type: application/json" \ -d '{"messages": [{"role": "user", "content": "Give three causes of network latency."}]}' Vollbildmodus aktivieren Vollbildmodus beenden Antworten enthalten Token-Anzahlen und auf dem nativen Endpoint zusätzlich Zeitinformationen für Prompt-Verarbeitung und Generierung.

Der Endpoint /health verrät, ob der Server bereit ist; er liefert einen Fehler zurück, solange das Modell noch lädt. Er ist das natürliche Ziel für einen Kubernetes-Readiness-Probe oder einen synthetischen Monitor.

Mit --metrics stellt der Pfad /metrics Metriken mit dem Präfix llamacpp:: bereit: Zähler für Prompt-Tokens und generierte Tokens, durchschnittlicher Durchsatz, laufend verarbeitete Anfragen sowie wegen fehlender freier Slots zurückgestellte Anfragen, dazu die durchschnittliche Anzahl belegter Slots pro Decode-Aufruf und die höchste beobachtete Kontextgröße. Fragen Sie Ihre Instanz ab, um die genaue Liste zu sehen:

curl -s http://127.0.0.1:8080/metrics | grep '^llamacpp' Vollbildmodus aktivieren Vollbildmodus beenden Zurückgestellte Anfragen sind der Sättigungsindikator, den man zuerst im Blick behalten sollte: Sie bedeuten, dass jeder Slot belegt ist und Clients warten.

llama-server schreibt auf die Standardausgabe: Hardwareerkennung, Laden des Modells, wie die Layer zwischen CPU und GPU aufgeteilt werden, dann pro Anfrage eine Zeile mit Zeitwerten (Zeit für die Prompt-Verarbeitung, Tokens pro Sekunde während der Generierung). Diese Zeilen sind unschätzbar, um eine Verschlechterung zu verstehen; ein OpenTelemetry-Collector oder ein Host-Agent kann sie zentralisieren.

Nach unserem Wissen erzeugt der Server keine OpenTelemetry-Traces. Da er OpenAI-kompatibel ist, liegt der einfachste Weg darin, die aufrufende Anwendung mit einer OpenAI-Instrumentierung für OpenTelemetry zu versehen (zum Beispiel denen von OpenLLMetry), wobei der Client auf die llama-server-URL zeigt. Jeder Aufruf wird so zu einem Span, der Modell, Tokens und Dauer enthält und an den Trace der Benutzeranfrage angehängt wird.

Die Pipeline ist dieselbe wie bei vLLM: Ein OpenTelemetry-Collector liest /metrics mit dem Prometheus-Receiver aus, wandelt die Zähler in Delta um, empfängt OTLP-Traces von der Anwendung und exportiert sie an den Dynatrace-OTLP-Endpoint mit einem API-Token. Diese Konfiguration beschreiben wir ausführlich in vLLM in production; Sie müssen lediglich das Scrape-Ziel ändern. Auf einem Host mit OneAgent vervollständigen Prozess- und GPU-Metriken das Bild.

Nützliche Indikatoren: generierte Tokens pro Sekunde, zurückgestellte Anfragen, clientseitige Latenz pro Anfrage, GPU-Auslastung und Speicher sowie Anzahl der Neustarts. Um diese Daten mit dem Rest der Kette zu korrelieren, wenden Sie die Prinzipien aus unserem Artikel end-to-end OpenTelemetry an.

Ollama baut auf llama.cpp auf und ergänzt ein vereinfachtes Modellmanagement. llama.cpp gibt Ihnen mehr Kontrolle und mehr Optionen, bei etwas mehr Konfigurationsaufwand. Siehe unser Guide Ollama locally.

Ja, dort hat es tatsächlich angefangen. Die Leistung hängt dann stark von der CPU, der Speicherbandbreite und der gewählten Quantisierung ab.

Starten Sie den Server mit der Option --metrics; die Metriken werden dann unter /metrics auf demselben Port wie die API bereitgestellt.

llama.cpp bleibt die Referenz für schlankes lokales Inference, vom Laptop bis zum kleinen GPU-Server. Sein eingebauter, OpenAI-kompatibler Server mit Prometheus-Metriken macht Integration und Beobachtbarkeit einfach. Um zu sehen, wie es sich im Vergleich zu Ollama, vLLM und den anderen Bausteinen schlägt, lesen Sie unseren Vergleich self-hosteter Open-Source-KI-Stacks.

span.observer ist ein unabhängiger Community-Blog, weder mit Dynatrace LLC noch mit den genannten Projekten verbunden. Marken gehören ihren jeweiligen Eigentümern. Werkzeuge ändern sich schnell: Prüfen Sie Befehle und Optionen in der offiziellen Dokumentation.

Ursprünglich veröffentlicht auf span.observer. Französische Version: https://span.observer/fr/llama-cpp-inference-locale/.

Automatisch übersetzt. Das Original auf Englisch ist unten aufklappbar.

Original (Englisch) anzeigen

Posted on Nov 23 • Originally published at span.observer

llama.cpp is the engine that brought local LLM inference to everyone: a C/C++ implementation with no heavy dependencies, able to run a language model on an ordinary CPU, a consumer GPU or a Mac. Started by Georgi Gerganov and now maintained under the ggml-org organisation, it is one of the most-followed open source projects on GitHub, and a building block for many tools, including Ollama.

Using llama.cpp directly rather than through a wrapper has several benefits: fine control over quantisation, context size and how layers are split between CPU and GPU, lightweight binaries that are easy to package, and a built-in HTTP server that speaks the OpenAI API dialect.

In this article we cover the key concepts (GGUF, quantisation, GPU offloading), build and start llama-server, then look at how to monitor it: health endpoint, Prometheus metrics, logs and OpenTelemetry traces on the application side, all the way to a backend such as Dynatrace.

Three concepts are enough to get started.

The project ships several tools: llama-cli to chat in the terminal, llama-server to serve a model over HTTP, llama-quantize to produce quantised variants, and llama-bench to measure performance on your own hardware.

The quickest route is a package (Homebrew, winget…) or the prebuilt binaries published with every release on GitHub. To enable a specific backend, build with CMake:

git clone https://github.com/ggml-org/llama.cpp cd llama.cpp cmake -B build # CPU only # cmake -B build -DGGML_CUDA=ON # with CUDA cmake --build build --config Release -j ls build/bin/ # llama-cli, llama-server,... Enter fullscreen mode Exit fullscreen mode Build options and the prerequisites for each backend are described in the build guide in the official llama.cpp repository.

You can download a.gguf file from Hugging Face, or let llama.cpp do it with the -hf option, which takes a Hugging Face repository (and optionally a quantisation variant):

build/bin/llama-cli -hf ggml-org/gemma-3-1b-it-GGUF Enter fullscreen mode Exit fullscreen mode Pick the quantisation according to the memory available: a 7 to 8 billion parameter model in 4-bit fits in a few gigabytes, whereas the 16-bit version needs several times more.

build/bin/llama-server \ -m models/my-model-Q4_K_M.gguf \ --host 127.0.0.1 --port 8080 \ -c 8192 \ -ngl 99 \ --metrics Enter fullscreen mode Exit fullscreen mode -c sets the context size, -ngl the number of layers offloaded to the GPU (a high value puts them all there if memory allows), and --metrics enables the Prometheus endpoint. An --api-key option protects access, and a parallelism option sets how many requests are served at once. Option names change over time: llama-server --help is the authority.

The server also offers a small web interface at its root, handy for a quick test. An official container image is published on the project’s GitHub registry.

curl -s http://127.0.0.1:8080/v1/chat/completions \ -H "Content-Type: application/json" \ -d '{"messages": [{"role": "user", "content": "Give three causes of network latency."}]}' Enter fullscreen mode Exit fullscreen mode Responses include token counts and, on the native endpoint, timing information for prompt processing and generation.

The /health endpoint tells you whether the server is ready; it returns an error while the model is still loading. It is the natural target for a Kubernetes readiness probe or a synthetic monitor.

With --metrics, the /metrics path exposes metrics prefixed with llamacpp:: counters for prompt tokens and generated tokens, average throughput, requests being processed and requests deferred for lack of a free slot, plus the average number of busy slots per decode call and the highest context size observed. Query your instance to see the exact list:

curl -s http://127.0.0.1:8080/metrics | grep '^llamacpp' Enter fullscreen mode Exit fullscreen mode Deferred requests are the saturation indicator to watch first: they mean every slot is busy and clients are waiting.

llama-server writes to standard output: hardware detection, model loading, how layers are split between CPU and GPU, then one timings line per request (prompt processing time, tokens per second during generation). These lines are invaluable for understanding a degradation; an OpenTelemetry Collector or a host agent can centralise them.

To our knowledge, the server does not emit OpenTelemetry traces. Since it is OpenAI-compatible, the simplest approach is to instrument the calling application with an OpenAI instrumentation for OpenTelemetry (for example those from OpenLLMetry), with the client pointed at the llama-server URL. Each call becomes a span carrying the model, the tokens and the duration, attached to the trace of the user request.

The pipeline is the same as for vLLM: an OpenTelemetry Collector scrapes /metrics with the prometheus receiver, converts the counters to delta, receives OTLP traces from the application and exports to the Dynatrace OTLP endpoint with an API token. We detail this configuration in vLLM in production; you only need to change the scrape target. On a host running OneAgent, process and GPU metrics complete the picture.

Useful indicators: generated tokens per second, deferred requests, client-side latency per request, GPU utilisation and memory, and number of restarts. To correlate this data with the rest of the chain, apply the principles from our article end-to-end OpenTelemetry.

Ollama is built on llama.cpp and adds simplified model management. llama.cpp gives you more control and more options, with a little more configuration. See our guide Ollama locally.

Yes, that is in fact where it started. Performance then depends heavily on the CPU, memory bandwidth and the quantisation chosen.

Start the server with the --metrics option; the metrics are then exposed on /metrics, on the same port as the API.

llama.cpp remains the reference for lightweight local inference, from a laptop to a small GPU server. Its built-in server, OpenAI-compatible and equipped with Prometheus metrics, makes it easy to integrate and to observe. To see how it compares with Ollama, vLLM and the other building blocks, read our comparison of self-hosted open source AI stacks.

span.observer is an independent community blog, not affiliated with Dynatrace LLC or with the projects mentioned. Trademarks belong to their respective owners. Tools change quickly: check commands and options in their official documentation.

Originally published on span.observer. French version: https://span.observer/fr/llama-cpp-inference-locale/.

Originaltitel: llama.cpp: local inference on CPU and GPU, GGUF models and the built-in HTTP serverQuelle: dev.to (dev.to). Original öffnen