快速结论:这个报错通常出现在 llama.cpp 使用 Vulkan 后端启动 llama-server 加载模型时,设备显存不足以分配指定大小的 buffer。本次 Issue 中,根因不是模型本身,而是默认 slot 数量导致自动扩展上下文,进而把峰值显存需求推高。优先检查 llama-server 的 slot/上下文设置。
适用环境:llama.cpp 0.4.1-dev(build 11059,commit 059a34f8d),GNU 14.2.0,Linux aarch64;Asahi Debian;Apple M1(G13G B1)16GB 统一内存;GGML 后端为 Vulkan;模型为 unsloth/gemma-4-E2B-it-GGUF:Q4_0。
最快修复方案:Issue 中确认,使用 llama-server -np 1 ... 不再触发 ErrorOutOfDeviceMemory;同时等待/合并 PR #29437 以恢复原来的默认行为。
注意事项:-np 1 会限制并行 slot 数量,可能影响多并发场景。PR #29437 在 Issue 关闭时被描述为“revert behavior 并解决此 Issue”,但具体合并状态需以仓库实际为准。
问题场景
用户在 Apple M1 2020、16GB 统一内存、Asahi Debian 环境下,使用 Vulkan 后端编译 llama.cpp,并运行 llama-server 加载 unsloth/gemma-4-E2B-it-GGUF:Q4_0 模型。启动时出现 Vulkan 设备内存分配失败。同一环境下,较小的 TheBloke--TinyLlama-1.1B-Chat-v1.0-GGUF 模型可以正常运行。
报错原文
ggml_vulkan: Device memory allocation of size 369827840 failed.
ggml_vulkan: vk::Device::allocateMemory: ErrorOutOfDeviceMemory
/home/farhi/src/llama.cpp.farhi/ggml/src/ggml-backend.cpp:188: GGML_ASSERT(buffer) failed
0.04.186.898 E alloc_tensor_range: failed to allocate Vulkan0 buffer of size 369827840
原因分析
Issue 讨论中给出的主要原因是:默认 slot 数量与统一 KV 导致自动扩展上下文。日志显示 n_ctx_seq (524288) > n_ctx_train (131072),评论摘要指出,在默认 4 个 slot 下,auto-fit 把上下文从 131072 提升到 524288,峰值内存从约 4.9 GiB 升到约 7.6 GiB,从而超出当前可用的设备显存。Issue 作者最初怀疑 commit 4bc272f(vulkan: work around NV bug with argsort_large.comp)是首个坏提交,但评论认为现象与 #28849 一致,而不是 4bc272f。
环境排查
- 确认 llama.cpp 版本与构建参数:0.4.1-dev build 11059,commit 059a34f8d,是否启用
-DGGML_VULKAN=ON。 - 确认操作系统与硬件:Linux aarch64,Asahi Debian,Apple M1 16GB 统一内存。
- 确认
llama-server启动参数,特别是是否使用默认 slot 数量,以及--tools all等选项。 - 确认日志中是否出现
n_ctx_seq大于n_ctx_train的提示。 - 确认模型与大小:gemma-4-E2B-it-GGUF:Q4_0 约 2.9 GB,MMPROJ 约 942MB;TinyLlama-1.1B-Chat-v1.0-GGUF 可正常运行。
- 确认观察到的空闲显存:Issue 中称系统使用 6 GB、GPU 可用约 10 GB,但实际分配仍然失败。
解决步骤
- 用
-np 1启动llama-server,验证是否不再出现ErrorOutOfDeviceMemory。Issue 中作者已确认该方式有效。 - 在启动命令中显式检查 slot 数量相关设置,避免默认 4 个 slot 触发自动扩展上下文。
- 关注并合并 PR #29437,该 PR 被描述为 revert 引起此行为变更的改动,可解决此 Issue。
- 如果仍失败,结合日志确认
n_ctx_seq与n_ctx_train的值,并核对可用设备显存。
验证方法
重新运行相同模型和 llama-server 命令后,日志中不再出现 ggml_vulkan: vk::Device::allocateMemory: ErrorOutOfDeviceMemory 和 failed to allocate Vulkan0 buffer,模型可正常加载并服务。使用 -np 1 时,应确认 slot 数量已降为 1,且未再触发 524288 上下文扩展。
参考来源
AI 工具推荐
想把多个 AI 模型放在一个入口?
GamsGo AI 集成 ChatGPT、DeepSeek、Gemini、Claude、Midjourney、Veo 等常用模型,适合写作、绘图、视频和日常 AI 工作流。
推广链接:通过此链接购买,我可能获得佣金,不影响你的价格。
这个方案解决了吗?
可以继续搜索完整报错,或查看同一工具的其他排查指南。


![[Bug]: Kimi-K3-NVFP4 on 8xB300 produces degenerate, incoherent output in the reasoning channel on v0.27.0](https://www.chat-gpts.plus/wp-content/uploads/2026/09/51798-e8ba3af0-768x403.jpg)