How to run local AI models on M4 Mac with LM Studio: A complete 30-minute tutorial
Starting from scratch, install LM Studio and run Qwen local model on M4 MacBook
Beginner · 30 min · May 11, 2026
<
Tutorial Objectives
In 30 minutes, use LM Studio to run through the local AI model on M4 Mac to achieve daily programming assistance and basic task processing without relying on cloud APIs. This article is a complete step-by-step tutorial.
What you will get
- Local inference environment: Run through Qwen 3.5-9B model on M4 MacBook, reaching a practical speed of about 40 tokens/second
- Complete Toolchain: LM Studio + Local Models + Utilities (Pi/OpenCode)
- Cost Conscious: One-time hardware investment (if you already have a Mac), no subsequent API fees, and data is completely local
Preparation list
- M4 Mac (24GB memory is the best configuration, 16GB can also run small models)
- macOS 14+ (Sonoma or Sequoia)
- Approximately 8GB free disk space
- LM Studio (free, download from the official website)
- Optional: Pi or OpenCode (command line AI tool)
Overall architecture
The local AI workflow is broken down into 3 steps, which can be operated in sequence.
| Module | Input | Output | Estimated time |
|---|---|---|---|
| Installing LM Studio and models | M4 Mac + Network | Running local model | 15 minutes |
| Configure inference parameters | Loaded model | Optimized inference settings | 10 minutes |
| Access to command line tools | Local API + Pi/OpenCode | Complete development environment | 5 minutes |
Step 1: Install LM Studio and download the model
Download the macOS version from LM Studio 官网 and install it (native on Apple Silicon). After the installation is complete, search for the Qwen 3.5-9B model in the search bar and select the q4_k_s quantized version.
Why choose Qwen 3.5-9B? After multiple actual tests (including the HN community), this is currently the best choice with the best overall performance on M4 24GB memory:
- About 40 tokens/second, completely smooth for daily use
- Supports 128K context windows, enough to handle large code bases
- Good tool calling ability and can be used with command line tools
- Supports thinking mode, suitable for complex reasoning tasks
# 模型信息(参考)
# 名称: Qwen3.5-9B @ q4_k_s
# 大小: ~5.6GB
# 上下文: 128K tokens
# 速度: ~40 tok/s (M4 24GB)
# HuggingFace: Qwen/Qwen3.5-9B-GGUF提示:如果内存只有 16GB,可以尝试 Qwen 3-4B 或 Gemma 4B,速度会更快但推理能力弱一些。如果内存达到 32GB 以上,可以考虑 Qwen 3.6 Q3 或 Devstral Small 24B。
第 2 步:配置推理参数
LM Studio 的默认参数效果一般,要获得最佳效果需要手动调整。以下是经过验证的推荐配置:
| 参数 | 推荐值 | 说明 |
|---|---|---|
| temperature | 0.6 | 编码任务偏确定性,创意任务可调至 0.8 |
| top_p | 0.95 | 保持词汇多样性 |
| top_k | 20 | 限制候选词范围 |
| min_p | 0.0 | 不设最低概率门槛 |
| presence_penalty | 0.0 | 不惩罚重复词汇 |
| repetition_penalty | 1.0 | 不额外惩罚重复 |
启用思考模式(Thinking Mode):
这一步很关键但容易忽略。在 LM Studio 中加载模型后,进入 Configuration → Inference 标签页,滚动到底部的 Prompt Template 区域,在模板中追加:
{%- set enable_thinking = true %}
保存后重新加载模型,即可在思考模式下运行。Qwen 3.5-9B 的思考模式能显著提升复杂编程任务的准确率。
第 3 步:接入命令行工具
本地模型的最大价值在于融入你的日常开发流程。目前有两个主流命令行工具支持连接 LM Studio:
OpenCode — 轻量级 AI 编码助手,支持自定义模型提供者。装上后配置 LM Studio 的本地 API 地址(默认 http://localhost:1234/v1),就能在终端中直接用本地模型写代码。
Pi — A more feature-rich AI terminal tool that supports multi-model switching and customized workflows. LM Studio will locally start an API service compatible with the OpenAI format, and Pi can be used directly after configuration.
It is recommended to use OpenCode for development and use Claude Code or ChatGPT to handle complex reasoning - this hybrid method can not only protect code privacy, but also obtain the reasoning capabilities of top models when needed.
It is recommended to use Claude Code in OpenCode to handle complex reconstruction tasks that cannot be handled by the local model, which is both cost-effective and efficient.
Frequently Asked Questions (FAQ)
Q1: What should I do if the system becomes stuck after loading the model?
Close unnecessary browser tabs and apps. Lower the Context Length setting in LM Studio to 32K or 64K to reduce memory usage. If it still gets stuck, switch to a smaller model (such as Qwen 3-4B).
Q2: The speed is less than 10 tokens/second?
Check if you are using a non-native Apple Silicon version. In the LM Studio settings make sure Metal (GPU accelerated) is selected instead of CPU Only. Q4_K_S quantization is a balance between speed and quality, and the GGUF format is more memory-saving than the EXL2 format.
Q3: The model output quality is too poor?
Confirm thinking mode is enabled. Check if temperature is too high (0.6 is recommended for coding tasks), try lowering top_p to 0.85. If you are still not satisfied, switch to a larger quantized version or close the 128K context window and run a shorter context.
Tool entry
The platform side will automatically match the tool names used naturally in the text and generate a hover-card based on the maintained tool library:
LM Studio, OpenAI, ChatGPT, Claude, Claude Code, Qwen, Pi, OpenCode, HuggingFace
Reference material
Internal link guidance
- Someone has successfully practiced it: Claude Code 48小时创业:一人+29美元月费,3个月做到月入$9,000
- Recommended tool: LM Studio
Related tutorials
AI Coding Agents Complete Guide: Setup, Security, Workflow & Case Studies
If you are researching AI coding agents and want to know which one to use, how to set it up safely, and what real developers are building with them — this hub organizes every tutorial, case study, and comparison we have published. Start with the decision guide below to find the right path for your skill level and goals.
AI Micro SaaS FAQ: 25 Common Questions Answered (2026)
Everything you need to know about building and profiting from AI Micro SaaS products. This FAQ covers idea generation, tech stack choices, pricing strategy, marketing on a $0 budget, legal considerations, and scaling from $100 to $10K MRR. Based on real case studies and data from successful solo builders using Claude Code, Cursor, and other AI coding tools.
Monetization angle
How can you make money from this trend?
WayToClawEarn focuses on verified earn playbooks—not just news. Start from these cases.
n8n + OpenAI affiliate site
Automate content and affiliate monetization
Claude + n8n automation agency
Charge monthly for agent workflow builds