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

推荐订阅源

Apple Machine Learning Research
Apple Machine Learning Research
Help Net Security
Help Net Security
A
About on SuperTechFans
博客园_首页
M
MIT News - Artificial intelligence
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
量子位
F
Fortinet All Blogs
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
爱范儿
爱范儿
L
LINUX DO - 最新话题
The GitHub Blog
The GitHub Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
C
Cybersecurity and Infrastructure Security Agency CISA
N
News and Events Feed by Topic
S
Security @ Cisco Blogs
A
Arctic Wolf
V
Vulnerabilities – Threatpost
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
T
Tailwind CSS Blog
The Last Watchdog
The Last Watchdog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Security Latest
Security Latest
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
H
Heimdal Security Blog
H
Hacker News: Front Page
Simon Willison's Weblog
Simon Willison's Weblog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Recent Announcements
Recent Announcements
N
Netflix TechBlog - Medium
SecWiki News
SecWiki News
酷 壳 – CoolShell
酷 壳 – CoolShell
I
InfoQ
MyScale Blog
MyScale Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LangChain Blog
Stack Overflow Blog
Stack Overflow Blog
Vercel News
Vercel News
AI
AI
L
LINUX DO - 热门话题
G
Google Developers Blog
P
Proofpoint News Feed
腾讯CDC
Schneier on Security
Schneier on Security
美团技术团队
V
V2EX
PCI Perspectives
PCI Perspectives
L
Lohrmann on Cybersecurity
Jina AI
Jina AI
博客园 - 司徒正美

中文博客 on 范叶亮 | Leo Van

多智能体系统 (Multi-Agent System) 确定性和掌控欲 - 你的 AI 不是你的 AI LLM Token 消耗节省计划 (How to Save Token for LLM) 智能体的角色定位和身份演化 (Agent Role Orientation and Identity Evolution) 本地部署 OpenClaw,QwenPaw 和 Hermes Agent (Local Deployment of OpenClaw, QwenPaw and Hermes Agent) 本地部署智能体 - OpenClaw,QwenPaw,Hermes Agent ... 部署 Matrix 服务器 Synapse (Deployment of Matrix Server Synapse) 部署 frp 内网穿透服务 (Deployment of frp NAT Traversal Service) AI 时代的生产力和生产关系 (Forces and Relations of Production in AI Era) 业余无线电入门 - CQ, CQ, CQ, this is BD1CZP. Calling CQ and standing by. 重构 - 之于代码、之于工作、之于生活 大语言模型微调 (Fine-tuning Large Language Models) 提升图片分辨率和质量 - Invoke AI 101 教程 使用画布创建和组合生成新的图片 - Invoke AI 101 教程 探索 AI 模型和概念适配器 - Invoke AI 101 教程 理解图像到图像和降噪过程 - Invoke AI 101 教程 使用控制层和指示控制图片的生成 - Invoke AI 101 教程 使用 Invoke 创作你的第一张图片 - Invoke AI 101 教程 在 OpenWrt 和群晖中自动申请和部署证书 凡人歌 - 凡人,但不要烦心 Shell 调用方式 fork,exec 和 source (Run Shell with fork, exec and source) 重定向和管道 (Redirect and Pipe) 模型压缩和推理加速 (Model Compression and Inference Acceleration) 我们需要多少种编程语言 (How Many Programming Languages do We Need) 数据可视化小贴士 - 面向动态文档生成,秉承规范、统一和实用的理念 从 rm -rf * 说起 - 喜新、怀旧、再出发 当我谈摄影时,我谈些什么 - 色彩篇 Part 1 CSS 布局和定位 (CSS Layout and Position) 当我谈修图时,我谈些什么 - 色彩篇 Part 1 在 Windows 下利用 WSL2 和 Ubuntu 配置 GPU 机器学习环境 文学编程和可重复性研究 (Literate Programming and Reproducible Research) 在 OpenWrt 中安装 Jellyfin 搭建家庭影音中心 自私和贪婪 (Selfish and Greedy) 评分和排名算法 (Rating & Ranking Algorithms) 小记这一波裁员浪潮 基于内容的图像检索 (Content-based Image Retrieval, CBIR) 你所应该知道的 A/B 测试 (A/B Test You Should Know) 一个人的摩旅 (Travel with My Motorcycle Alone) 设计语言初探 (A Glimpse of Design Language) Spark 集群搭建 (Spark Cluster Setup) Hive 安装和配置 (Hive Setup) Hadoop 集群搭建 (Hadoop Cluster Setup) 虚拟环境准备 (Virtual Environment Preparation) 大数据 SQL 性能调优 (Big Data SQL Performance Tuning) SQL 样式指南 (SQL Style Guide) 进程,线程和协程 (Process, Thread and Coroutine) - 实现篇 进程,线程和协程 (Process, Thread and Coroutine) - 理论篇 胶囊网络 (Capsule Network) 投票公平合理吗? 图存储与计算 (Network Storage and Computing) - 复杂网络系列 网络算法 (Network Algorithms) - 复杂网络系列 真实世界网络结构 (Structure of Real-World Network) - 复杂网络系列 网络表示,测度和度量 (Network Representation, Measures and Metrics) - 复杂网络系列 文本相似度 (Text Similarity) 而立之前 (Life before 30) 最近邻搜索 (Nearest Neighbor Search) 无模型策略预测和控制 - 时序差分学习 (Model-Free Policy Prediction and Control - Temporal Difference Learning) - 强化学习系列 无模型策略预测和控制 - 蒙特卡洛方法 (Model-Free Policy Prediction and Control - Monte-Carlo Learning) - 强化学习系列 利用动态规划求解马尔可夫决策过程 (Planning by Dynamic Programming) - 强化学习系列 贝叶斯优化 (Bayesian Optimization) 马尔可夫决策过程 (Markov Decision Process) - 强化学习系列 多臂赌博机 (Multi-armed Bandit) - 强化学习系列 强化学习简介 (Introduction of Reinforcement Learning) - 强化学习系列 在群晖 NAS 上编译安装 tmux 隐马尔可夫,条件随机场和序列标注 (Hidden Markov Model, Conditional Random Fields and Sequence Labeling) 图嵌入和图神经网络 (Graph Embedding and Graph Neural Network) 预训练自然语言模型 (Pre-trained Models for NLP) toB 产品用户权限 (User Privileges of toB Products) 京东数科 HIPO 学习之旅 (JDD HIPO Learning Journey) 杭州和东京之旅 (Tour of Hangzhou and Tokyo) 国际智慧温室种植挑战赛 (International Autonomous Greenhouse Challenge) 记忆中的儿时 (My Childhood in Memory) 启发式算法 (Heuristic Algorithms) 关不掉的浏览器标签页 (Browser Tabs You do not Close) 贝塞尔曲线 (Bézier Curve) 如何阅读一本书 (How to Read a Book) 相似性和距离度量 (Similarity and Distance Measurement) 集成学习算法 (Ensemble Learning) 计算复杂性与动态规划 (Computational Complexity and Dynamic Programming) 利用 Flask 和 Google App Engine 部署模型服务 序列到序列和注意力机制 (Seq2Seq and Attention Machanism) 词向量 (Word Embeddings) 循环神经网络 (Recurrent Neural Network, RNN) 泰国之行 (Tour of Thailand) 媒介之战 (War of Medias) 卷积神经网络 (Convolutional Neural Network, CNN) 买书,囤书,看书 (Buy Books, Hoard Books and Read Books) Play Safe, Smart Choice & Yuppie 基于 PyQt5/PySide2 和 QML 的跨平台 GUI 程序开发 流形学习 (Manifold Learning) 深度学习优化算法 (Optimization Methods for Deep Learning) 深度学习优化算法 (Optimization Methods for Deeplearning) 生成对抗网络简介 (GAN Introduction) Ising 模型,Hopfield 网络和受限的玻尔兹曼机 (Ising, Hopfield and RBM) 马尔科夫链蒙特卡洛方法和吉布斯采样 (MCMC and Gibbs Sampling) 特征值分解,奇异值分解和主成分分析 (EVD, SVD and PCA) 墨尔本之行 (Trip to Melbourne)
本地部署大模型服务 (Local Deployment of LLM Services)
范叶亮 · 2026-04-05 · via 中文博客 on 范叶亮 | Leo Van

本地部署大模型服务

Local Deployment of LLM Services

分类: AI, Tech101, 教程 / 字数: 2197 / 标签: 人工智能, AI, 本地部署, 大模型, ollama, LM Studio, vllm, oMLX, Gemma, Qwen, CoPaw


环境信息

本教程将介绍在 macOS 和 Windows 环境下部署本地大模型服务。如无特殊说明,macOS 系统下需在终端中执行命令,Windows 系统下需要在 PowerShell 中执行命令。本教程涉及到的软件和模型信息如下:

软件信息
软件 版本
ollama 0.20.2
LM Studio 0.4.9+1
vllm 0.19.0
vllm-metal v0.1.0-20260404-164341
vllm-mlx 0.2.7
oMLX 0.3.4
模型信息
名称 架构 量化 内存 / 显存 能力 链接
gemma-4-31B-it 稠密 4bit 32 GB 及以上 GGUF / GGUF / MLX
GGUF / GGUF / MLX
gemma-4-26B-A4B-it MoE 4bit 32 GB 及以上 GGUF / GGUF / MLX
GGUF / GGUF / MLX
Qwen3.5-27B 稠密 4bit 32 GB 及以上 GGUF / GGUF / MLX
GGUF / GGUF / MLX
Qwen3.5-35B-A3B MoE 4bit 32 GB 及以上 GGUF / GGUF / MLX
GGUF / GGUF / MLX
CoPaw-Flash-9B 稠密 4bit 16 GB 及以上 GGUF
GGUF
:图片,:视频,:音频,:工具调用,:思考
:Hugging Face,:ModelScope

为了加速从 Hugging Face 模型仓库下载模型,可以运行如下命令配置相关环境变量:

macOS

echo "HF_ENDPOINT=https://hf-mirror.com" >> ~/.bash_profile

Windows

[Environment]::SetEnvironmentVariable("HF_ENDPOINT", "https://hf-mirror.com", "User")

更多使用方式可参考 HF-Mirror 官方网站。

ollama

推荐在终端运行如下命令安装 ollama:

macOS

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

Windows

irm https://ollama.com/install.ps1 | iex

运行如下命令可以显示当前安装的版本号:

ollama --version
# ollama version is 0.20.2

ollama 当前采用 ollama pull MODEL 命令下载模型,除了使用官方模型库中的模型名称外(例如:qwen3.5:27b-nvfp4),还可以使用 Hugging Face 的模型链接(例如:https://huggingface.co/lmstudio-community/Qwen3.5-27B-GGUF),运行如下命令下载模型:

ollama pull qwen3.5:27b-nvfp4
ollama pull https://huggingface.co/lmstudio-community/Qwen3.5-27B-GGUF

ollama 当前仅支持通过环境变量配置监听地址和端口,运行如下命令进行配置:

macOS

echo "OLLAMA_HOST=0.0.0.0:11434" >> ~/.bash_profile

Windows

[Environment]::SetEnvironmentVariable("OLLAMA_HOST", "0.0.0.0:11434", "User")

运行如下命令启动模型服务:

提示

ollama 默认会选择最适合的运行库,如果需要切换可以手动指定 LLM 运行库,运行如下命令表示使用 CPU 进行推理:

OLLAMA_LLM_LIBRARY="cpu_avx2" ollama serve <模型名称>

注意

在 Settings 中将 Context length 设置为最大值,以确保在后续使用过程中不会因上下文长度不足而导致效果下降。

macOS

Windows

打开 ollama 主页面,选择对应的模型,即可开始对话:

macOS

Windows

模型服务运行在 http://127.0.0.1:11434,API 文档详见:https://docs.ollama.com/api/introduction。运行如下命令以 OpenAI 兼容的接口测试服务:

macOS

curl http://127.0.0.1:11434/v1/chat/completions \
    -H "Content-Type: application/json" \
    -d '{
        "model": "<模型名称>",
        "messages": [
            {
                "role": "user",
                "content": "你好"
            }
        ]
    }'

Windows

iwr -Uri http://127.0.0.1:11434/v1/chat/completions `
    -Method Post `
    -ContentType "application/json" `
    -Body '{
        "model": "<模型名称>",
        "messages": [
            {
                "role": "user",
                "content": "你好"
            }
        ]
    }'

LM Studio

推荐从 LM Studio 官网下载安装包,并运行安装 LM Studio。如果只需要安装 LM Studio 核心,不需要 GUI 界面,则可以在终端运行如下命令:

macOS

curl -fsSL https://lmstudio.ai/install.sh | bash

Windows

irm https://lmstudio.ai/install.ps1 | iex

下载并安装所需的 Runtime,macOS 系统支持 GGUF 和 MLX 两种格式,Windows 系统仅支持 GGUF 格式。

macOS

Windows

注意

在 Settings - Model Defaults 中将 Default Context Length 设置为 Model Maximum,以确保在后续使用过程中不会因上下文长度不足而导致效果下降。

打开 LM Studio 主页面,选择对应的模型,即可开始对话:

macOS

Windows

单击左侧的 按钮,单击 Local Server,将 Status 滑动至 Running 状态。模型服务运行在 http://127.0.0.1:1234,API 文档详见:https://lmstudio.ai/docs/developer。运行如下命令以 OpenAI 兼容的接口测试服务:

macOS

curl http://127.0.0.1:1234/v1/chat/completions \
    -H "Content-Type: application/json" \
    -d '{
        "model": "<模型名称>",
        "messages": [
            {
                "role": "user",
                "content": "你好"
            }
        ]
    }'

Windows

iwr -Uri http://127.0.0.1:1234/v1/chat/completions `
    -Method Post `
    -ContentType "application/json" `
    -Body '{
        "model": "<模型名称>",
        "messages": [
            {
                "role": "user",
                "content": "你好"
            }
        ]
    }'

oMLX

推荐从 oMLX 官网下载安装包,并运行安装 oMLX。安装完毕后启动,并从 macOS 菜单栏或 Windows 系统托盘单击 oMLX 图标,选择 Start Server 启动服务。待服务启动后,单击 Admin Panel 从浏览器打开管理面板,初次登录需要设置 API Key。在 Models - Downloader 中可以直接从 Hugging Face 和 ModelScope 模型仓库下载模型。

提示

建议国内用户切换至 ModelScope 标签,复制上文 ModelScope 模型连接的尾部(例如:mlx-community/gemma-4-31b-it-nvfp4)至 REPOSITORY ID 中下载模型。

在 Settings - Model Settings 中单击对应模型 STATUS 中的按钮载入模型。

注意

在 Settings - Global Settings 中将 Max Context Window 和 Max Tokens 设置为合适的值,以确保在后续使用过程中不会因上下文长度不足而导致效果下降。

单击 Chat 进入对话页面,选择对应的模型,即可开始对话:

模型服务运行在 http://127.0.0.1:8000。运行如下命令以 OpenAI 兼容的接口测试服务:

curl http://127.0.0.1:8000/v1/chat/completions \
    -H "Authorization: Bearer <API_KEY>" \
    -H "Content-Type: application/json" \
    -d '{
        "model": "<模型名称>",
        "messages": [
            {
                "role": "user",
                "content": "你好"
            }
        ]
    }'

vllm

提示

vllm 官方仅支持 macOS 和 Linux 系统,暂无 GUI 界面。在此以 macOS 系统为例进行安装。

在 macOS 系统上,使用 vllm-metal 库安装 vllm 服务,运行如下命令:

curl -fsSL https://raw.githubusercontent.com/vllm-project/vllm-metal/main/install.sh | bash

这会在 ~/.venv-vllm-metal 路径下创建一个 Python 虚拟环境,并安装 vllm 服务。运行如下命令即可删除安装:

rm -rf ~/.venv-vllm-metal

运行如下命令激活 Python 虚拟环境:

source ~/.venv-vllm-metal/bin/activate

运行如下命令启动 vllm 服务:

模型服务运行在 http://127.0.0.1:8000,更多环境变量设置请参考:https://github.com/vllm-project/vllm-metal,更多命令行参数设置请参考:https://docs.vllm.ai/en/stable/api/。运行如下命令以 OpenAI 兼容的接口测试服务:

curl http://127.0.0.1:8000/v1/chat/completions \
    -H "Content-Type: application/json" \
    -d '{
        "model": "<模型名称>",
        "messages": [
            {
                "role": "user",
                "content": "你好"
            }
        ]
    }'