惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Vercel News
Vercel News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Apple Machine Learning Research
Apple Machine Learning Research
T
Tailwind CSS Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
人人都是产品经理
人人都是产品经理
V
V2EX
量子位
Last Week in AI
Last Week in AI
Jina AI
Jina AI
博客园 - 【当耐特】
爱范儿
爱范儿
宝玉的分享
宝玉的分享
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Hugging Face - Blog
Hugging Face - Blog
博客园 - 三生石上(FineUI控件)
有赞技术团队
有赞技术团队
小众软件
小众软件
IT之家
IT之家
博客园_首页
博客园 - 聂微东
S
SegmentFault 最新的问题
阮一峰的网络日志
阮一峰的网络日志
博客园 - 叶小钗

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
로컬 LLM 셋업 가이드 (v18)
matias yoon · 2026-05-25 · via DEV Community

Local LLM Setup Guide (v18)

1. Overview & Prerequisites

Running LLMs locally requires minimal hardware but careful resource management. This guide assumes:

  • Ubuntu 20.04/22.04 or Debian 11/12
  • 8GB+ RAM (16GB+ recommended)
  • NVIDIA GPU with CUDA support (RTX 3060+), or CPU-only setup
  • 20GB+ free disk space for models

For GPU-accelerated inference, install CUDA:

# Install NVIDIA drivers
sudo apt update
sudo apt install nvidia-driver-535

# Install CUDA toolkit
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.0-1_all.deb
sudo dpkg -i cuda-keyring_1.0-1_all.deb
sudo apt-get update
sudo apt-get install cuda-toolkit-12-4

2. Framework Comparison

Framework GPU Support Ease of Use Performance Best For
llama.cpp Yes Medium Fast Quick prototyping
Ollama Yes Easy Fast Development/testing
vLLM Yes Medium Fastest Production inference
LocalAI Yes Easy Fast API-first workflows

Recommendation: Use llama.cpp with Ollama for development workflow.

3. Step-by-Step Installation

Install llama.cpp:

git clone https://github.com/ggerganov/llama.cpp
cd llama.cpp
make

Install Ollama (for easier model management):

curl -fsSL https://ollama.com/install.sh | sh

Test installation:

ollama run llama3:8b

Setup model directory:

mkdir -p ~/llm-models
cd ~/llm-models

4. Model Selection Guide

Use Case: Code Generation

  • Model: codellama:7b or phi3:3.8b
  • RAM: 8GB minimum
  • Command: ollama run codellama:7b

Use Case: Chatbot

  • Model: llama3:8b or mistral:7b
  • RAM: 8GB minimum
  • Command: ollama run llama3:8b

Use Case: High Precision

  • Model: llama3:70b or mixtral:8x7b
  • RAM: 16GB minimum
  • Command: ollama run llama3:70b

5. Quantization Types Explained

Quantization reduces model size while maintaining performance:

  • Q4_K_M: 4-bit quantization, 4.5GB for 7B model
  • Q5_K_M: 5-bit quantization, 5.5GB for 7B model
  • Q8_0: 8-bit quantization, 8GB for 7B model
  • F16: Full precision, 16GB for 7B model

Example: Download and convert model:

# Download 7B model
ollama pull llama3:8b

# Convert to Q4_K_M (smallest size, good performance)
ollama run llama3:8b --quantize Q4_K_M

6. API Setup and Integration

Create API server with llama.cpp:

# Start llama.cpp server
./server -m ~/llm-models/llama3-8b-Q4_K_M.gguf \
    --host 0.0.0.0 \
    --port 1234 \
    --threads 8 \
    --ctx-size 8192

Test API:

curl http://localhost:1234/completion \
    -H "Content-Type: application/json" \
    -d '{
        "prompt": "Write a Python function to reverse a string.",
        "temperature": 0.7,
        "max_tokens": 100
    }'

Integrate with Python:

import requests

def llm_query(prompt):
    response = requests.post(
        'http://localhost:1234/completion',
        json={
            'prompt': prompt,
            'temperature': 0.7,
            'max_tokens': 200
        }
    )
    return response.json()['content']

# Usage
result = llm_query("Explain quantum computing in simple terms")

7. Systemd Service for 24/7 Operation

Create service file:

sudo nano /etc/systemd/system/llm-server.service

Content:

[Unit]
Description=Local LLM Server
After=network.target

[Service]
Type=simple
User=your_username
WorkingDirectory=/home/your_username/llama.cpp
ExecStart=/home/your_username/llama.cpp/server \
    -m /home/your_username/llm-models/llama3-8b-Q4_K_M.gguf \
    --host 0.0.0.0 \
    --port 1234 \
    --threads 8 \
    --ctx-size 8192
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target

Enable and start:

sudo systemctl daemon-reload
sudo systemctl enable llm-server
sudo systemctl start llm-server

8. Monitoring and Performance Tuning

Monitor GPU usage:

nvidia-smi -l 1  # Update every second

Monitor memory usage:

watch -n 1 free -h

Benchmark inference:

# Test 100 token generation
time ./server -m ~/llm-models/llama3-8b-Q4_K_M.gguf \
    --prompt "The future of AI is" \
    --max-tokens 100 \
    --threads 8

Performance tuning parameters:

  • --ctx-size: 8192 for 8B models, 16384 for 70B models
  • --threads: CPU cores / 2 for optimal performance
  • --n-gpu-layers: Number of layers on GPU (default: 100 for 8B models)

9. Real Command Examples

Full workflow example:

# 1. Install dependencies
sudo apt update
sudo apt install git cmake build-essential

# 2. Clone and build llama.cpp
git clone https://github.com/ggerganov/llama.cpp
cd llama.cpp
make

# 3. Download model
ollama pull llama3:8b

# 4. Start server
./server -m ~/llm-models/llama3-8b-Q4_K_M.gguf \
    --host 0.0.0.0 \
    --port 1234 \
    --threads 8 \
    --ctx-size 8192 \
    --n-gpu-layers 100

# 5. Test API
curl http://localhost:1234/completion \
    -H "Content-Type: application/json" \
    -d '{"prompt": "Hello world", "max_tokens": 10}'

Production-ready startup script:

#!/bin/bash
# ~/start-llm.sh

MODEL_PATH="$HOME/llm-models/llama3-8b-Q4_K_M.gguf"
PORT=1234

if [ ! -f "$MODEL_PATH" ]; then
    echo "Model not found at $MODEL_PATH"
    exit 1
fi

echo "Starting LLM server on port $PORT..."
./server \
    -m "$MODEL_PATH" \
    --host 0.0.0.0 \
    --port $PORT \
    --threads 8 \
    --ctx-size 8192 \
    --n-gpu-layers 100

This setup provides a production-ready local LLM infrastructure with minimal hardware requirements and optimal performance. The combination of llama.cpp for low-level control and Ollama for easy model management gives developers the best of both worlds for local LLM development.


📥 Get the full guide on Gumroad: https://gumroad.com/l/auto ($7)