ai newsDi., 1. Dez.

KI-Modelle lokal ohne GPU: Praktischer Einstieg in GGUF und llama.cpp

Ein M1 MacBook Pro mit 16 GB RAM ohne dedizierte NVIDIA-GPU schafft mit llama.cpp und dem GGUF-Format rund 18 Tokens pro Sekunde mit Llama 3.1 8B, komplett offline. Ein Leitfaden zeigt, wie sich größere Sprachmodelle auf solcher Consumer-Hardware betreiben lassen.

dev.toSamstag 00:00 · 28.11.DE3 Min. Lesezeit
Bild: dev.to

Veröffentlicht am 27. November, ursprünglich erschienen auf mangodeveloper.com

Ich schreibe dies auf einem MacBook Pro M1 aus dem Jahr 2021 mit 16 GB RAM. Von einer NVIDIA-GPU ist keine Spur. Und gerade läuft darauf ein Llama 3.1 8B Modell mit 18 Tokens pro Sekunde, beantwortet Fragen zu meiner Codebasis, fasst PDFs zusammen, und das alles offline. Vor drei Jahren wäre dieser Satz Science-Fiction gewesen.

Der Trick ist Quantisierung, konkret das GGUF-Format und die llama.cpp-Runtime. Wer sich bisher einredet hat, keine lokalen LLMs betreiben zu können, weil keine GPU vorhanden ist, für den ist dieser Leitfaden gedacht. Wir richten einen echten lokalen Inference-Stack auf einem Laptop oder einem günstigen VPS ein, und ich zeige die Produktionsmuster, mit denen ich tatsächlich damit liefere.

Drei Gründe, in der Reihenfolge ihrer Bedeutung für die meisten Teams:

Datenschutz und Datenresidenz. Rechtliches, Gesundheitsdaten, Finanzdaten, interne Unternehmensdaten lassen sich nicht immer an eine API schicken. Lokale Inferenz auf einem Laptop oder einem air-gapped Server ist die einzige konforme Option.

Kosten im Long Tail. Bei Batch-Verarbeitung, etwa dem Zusammenfassen von 100.000 Dokumenten oder der Klassifizierung einer Million Support-Tickets, summieren sich die API-Kosten schnell. Ein VPS für 40 Dollar im Monat, auf dem Qwen2.5-7B-Q5 läuft, verarbeitet unbegrenzt viele Tokens. Die Rechnung amortisiert sich rasch.

Latenz und Offline-Nutzung. Kein Netzwerk-Roundtrip. Keine Rate-Limits. Keine API-Ausfälle. Für interaktive Coding-Assistenten und Embedded-Anwendungsfälle ist lokal einfach besser.

Der Kompromiss ist natürlich die Qualität. Ein quantisiertes 7B-Modell ist kein GPT-4. Aber für eine überraschend breite Palette von Aufgaben wie Klassifizierung, Zusammenfassung, Code-Vervollständigung und strukturierter Extraktion reicht es aus, und man hat die volle Kontrolle darüber.

Dies sind die drei wichtigsten Quantisierungsformate, denen man begegnet. Sie gehören zu unterschiedlichen Runtimes.

Für ein Setup ohne GPU ist GGUF die einzige Option. GPTQ und AWQ sind GPU-first. Die Formate sind nicht austauschbar, ein GPTQ-Modell lässt sich nicht in llama.cpp laden.

Keine GPU erforderlich. Falls doch eine vorhanden ist, nutzt llama.cpp sie, aber das ist ein Bonus, keine Voraussetzung.

Das ist die Frage, die ich am häufigsten bekomme. Hier ist mein Entscheidungsbaum:

Ein praktischer Hinweis: Das Betriebssystem und andere Apps belegen ebenfalls RAM. 4 bis 6 GB Reserve einplanen. Beginnt das System während der Inferenz zu swappen, bricht die Performance dramatisch ein, denn die Festplatte ist rund 1000-mal langsamer als RAM.

# langchain_local.py from langchain_community. chat_models import ChatOllama from langchain_core. prompts import ChatPromptTemplate from langchain_core. output_parsers import StrOutputParser llm = ChatOllama ( model = "llama3.1:8b", temperature = 0.3, num_ctx = 8192, # WICHTIG, Standard ist 2048, zu klein für RAG ) prompt = ChatPromptTemplate. from_messages ( [ ( "system", "You are a concise technical writer." ), ( "user", "{input}" ), ] ) chain = prompt | llm | StrOutputParser ( ) print ( chain. invoke ( { "input": "Explain what a mutex is." } ) ) Vollbildmodus aufrufen Vollbildmodus beenden Die Einstellung num_ctx ist der häufigste Fehler, den ich sehe. Ollama verwendet standardmäßig ein 2048-Token-Kontextfenster, das für Chat reicht, aber für RAG unbrauchbar ist. Beim Übergeben abgerufener Chunks auf 8192 oder höher setzen.

GGUF und llama.cpp haben die LLM-Inferenz demokratisiert. Was vor drei Jahren ein Rechenzentrum brauchte, läuft heute auf einem MacBook. Wer sich bisher wegen des Arguments "Ich habe keine GPU" nicht für lokale Modelle entscheiden konnte, dem ist die Ausrede jetzt genommen.

Der pragmatische Weg: Ollama installieren, ein Q5_K_M 7B-Modell pullen, den bestehenden OpenAI-kompatiblen Code auf localhost:11434 richten und sehen, was passiert. Man ist vielleicht überrascht, wie weit ein quantisiertes 7B-Modell trägt, und wie angenehm es ist, den eigenen Inference-Stack vollständig zu besitzen.

Ursprünglich veröffentlicht auf Mango Developer.

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

Original (Englisch) anzeigen

Posted on Nov 27 • Originally published at mangodeveloper.com

I'm writing this on a 2021 M1 MacBook Pro with 16GB of RAM. There's no NVIDIA GPU in sight. And right now, it's running a Llama 3.1 8B model at 18 tokens per second, answering questions about my codebase, summarizing PDFs, and doing it all offline. Three years ago, that sentence would have been science fiction.

The trick is quantization -specifically the GGUF format and the llama.cpp runtime. If you've been telling yourself you can't run local LLMs because you don't have a GPU, this guide is for you. We're going to set up a real local inference stack on a laptop or a cheap VPS, and I'll show you the production patterns I use to actually ship with it.

Three reasons, in order of importance for most teams:

Privacy and data residency. Legal, healthcare, finance, internal corporate data-you can't always ship it to an API. Local inference on a laptop or air-gapped server is the only compliant option.

Cost at the long tail. If you're doing batch processing-summarizing 100K documents, classifying a million support tickets-API costs add up fast. A $40/month VPS running Qwen2.5-7B-Q5 processes unlimited tokens. The math breaks even quickly.

Latency and offline use. No network round-trip. No rate limits. No API outages. For interactive coding assistants and embedded use cases, local is just better.

The trade-off, of course, is quality. A quantized 7B model is not GPT-4. But for a surprising range of tasks-classification, summarization, code completion, structured extraction-it's good enough, and you control it entirely.

These are the three main quantization formats you'll see. They serve different runtimes.

For a no-GPU setup, GGUF is the only game in town. GPTQ and AWQ are GPU-first. The formats aren't interchangeable-you can't load a GPTQ model in llama.cpp.

No GPU required. If you do have one, llama.cpp will use it-but that's a bonus, not a requirement.

This is the question I get most. Here's my decision tree:

A practical note: your OS and other apps use RAM too. Leave 4-6GB of headroom. If your system starts swapping during inference, performance falls off a cliff-disk is 1000x slower than RAM.

# langchain_local.py from langchain_community. chat_models import ChatOllama from langchain_core. prompts import ChatPromptTemplate from langchain_core. output_parsers import StrOutputParser llm = ChatOllama ( model = "llama3.1:8b", temperature = 0.3, num_ctx = 8192, # IMPORTANT - default is 2048, too small for RAG ) prompt = ChatPromptTemplate. from_messages ( [ ( "system", "You are a concise technical writer." ), ( "user", "{input}" ), ] ) chain = prompt | llm | StrOutputParser ( ) print ( chain. invoke ( { "input": "Explain what a mutex is." } ) ) Enter fullscreen mode Exit fullscreen mode The num_ctx setting is the single most common bug I see. Ollama defaults to a 2048-token context window, which is fine for chat but useless for RAG. Set it to 8192 or higher when you're passing retrieved chunks.

GGUF and llama.cpp have democratized LLM inference. What required a data center three years ago runs on a MacBook today. If you've been on the fence about local models because "I don't have a GPU," the excuse is gone.

The pragmatic path: install Ollama, pull a Q5_K_M 7B model, point your existing OpenAI-compatible code at localhost:11434, and see what happens. You might be surprised how far a quantized 7B gets you-and how nice it is to own your inference stack entirely.

Originally published on Mango Developer.

Originaltitel: Running AI Models Locally Without a GPU: A Practical Guide to GGUF and llama.cppQuelle: dev.to (dev.to). Original öffnen