dev.to | 📄 原文链接 | 2026-10-25 收录

4GB 显卡上用纯 PyTorch 跑 Gemma 4,比 llama.cpp 还快

来源:dev.to — 2026-10-24

📋 概述

4GB 的 GTX 1650 Ti 上,Gemma 4 E2B 的 16-bit 权重仅层就占 3.58GiB,装不下;Transformers 自带的 4-bit 路径在第一次前向就爆显存;按层解包用 PyTorch 跑只有每秒 0.58 token。作者的做法是从磁盘到算术全程留在 Google 训练时的 4-bit 网格上,用 Triton 内核直接读打包权重做 4-bit 运算,再加 CUDA graph,结果是 87.8 tok/s,同卡同日 llama.cpp 是 82.1 tok/s,并且能保住完整 131,072 token 上下文。文章还给了 OpenAI 兼容的小服务端,跑起来和别的本地模型服务没差别。

🔑 核心要点

💡 金句

“Every weight stays on the 4-bit grid Google trained, and the speed comes from doing the 4-bit arithmetic in kernels that read the packed weights directly.”
译:每个权重都留在 Google 训练时的 4-bit 网格上,速度来自那些直接读取打包权重、就地做 4-bit 算术的内核。
← 返回 dev.to 首页