Tiny-LLM:面向系统工程师的苹果硅上LLM部署课程
Tiny-LLM – a course of serving LLM on Apple Silicon for systems engineers

原始链接: https://github.com/skyzh/tiny-llm

本教程重点介绍如何使用 MLX 从零开始构建 LLM 服务基础设施,主要利用其数组/矩阵 API。目标是理解高效 LLM 服务背后的优化技术,特别是针对像 Qwen2 这样的模型。 《tiny-llm》一书(可在 skyzh.github.io/tiny-llm/ 获取)指导用户完成整个过程。课程内容按章节结构安排,从注意力机制和 RoPE 等基础概念开始。后续章节深入探讨高级技术,例如分组查询注意力 (Grouped Query Attention)、RMSNorm、MLP、Transformer 块以及模型的加载/解码。 更高级的部分涵盖优化方法:KV 缓存、量化矩阵乘法(CPU 和 GPU)、Flash Attention、连续批处理、推测解码以及提示/前缀缓存。最后几章探讨分页注意力 (Paged Attention)、预填充解码分离、调度、并行处理、AI 智能体集成以及流式 API 服务器实现。本教程省略了量化/压缩 KV 缓存的内容。读者可以加入 skyzh 的 Discord 社区寻求支持和协作学习。

Hacker News 的一个帖子讨论了 Tiny-LLM,这是一门关于在 Apple Silicon 上运行大型语言模型 (LLM) 的课程。评论者们对 Apple 的机器学习框架 MLX 表示热情,称赞其快速发展以及其在 Mac 上运行 LLM 的适用性。一位用户分享了一条命令,该命令使用 MLX 在终端聊天界面中运行 Llama 3.2 3B。其他人则讨论了安装问题,建议使用特定版本的 Python(3.12)以确保兼容性。MLX 被拿来与 numpy/pytorch 进行比较,但它是专门为 Apple Silicon 设计的,而 mlx-lm 被视为 llama.cpp 的替代方案。用户们正在分享他们在 M2/M4 Mac 上的 token/秒速率和模型大小。帖子中还讨论了 Apple Silicon 与英伟达 GPU 在运行 LLM 方面的能效。HuggingFace 上的 MLX 社区也得到了推荐。Metal-JAX 和 Desloth LLMs 等替代框架也被提及。几位用户分享了他们使用 MLX 和其他工具进行旁白脚本编写、角色扮演代理和本地 RAG 等任务的经验。

原文

CI (main)

Still WIP and in very early stage. A tutorial on LLM serving using MLX for system engineers. The codebase is solely (almost!) based on MLX array/matrix APIs without any high-level neural network APIs, so that we can build the model serving infrastructure from scratch and dig into the optimizations.

The goal is to learn the techniques behind efficiently serving an LLM model (i.e., Qwen2 models).

The tiny-llm book is available at https://skyzh.github.io/tiny-llm/. You can follow the guide and start building.

You may join skyzh's Discord server and study with the tiny-llm community.

Join skyzh's Discord Server

Week + Chapter Topic Code Test Doc
1.1 Attention
1.2 RoPE
1.3 Grouped Query Attention 🚧 🚧
1.4 RMSNorm and MLP 🚧 🚧
1.5 Transformer Block 🚧 🚧
1.6 Load the Model 🚧 🚧
1.7 Generate Responses (aka Decoding) 🚧
2.1 KV Cache 🚧 🚧
2.2 Quantized Matmul and Linear - CPU 🚧 🚧
2.3 Quantized Matmul and Linear - GPU 🚧 🚧
2.4 Flash Attention and Other Kernels 🚧 🚧 🚧
2.5 Continuous Batching 🚧 🚧 🚧
2.6 Speculative Decoding 🚧 🚧 🚧
2.7 Prompt/Prefix Cache 🚧 🚧 🚧
3.1 Paged Attention - Part 1 🚧 🚧 🚧
3.2 Paged Attention - Part 2 🚧 🚧 🚧
3.3 Prefill-Decode Separation 🚧 🚧 🚧
3.4 Scheduler 🚧 🚧 🚧
3.5 Parallelism 🚧 🚧 🚧
3.6 AI Agent 🚧 🚧 🚧
3.7 Streaming API Server 🚧 🚧 🚧

Other topics not covered: quantized/compressed kv cache

联系我们 contact @ memedata.com