简报·YT
← 返回 GitHub 动态
ggerganov/llama.cpp · 📌 手动指定 已完成

ggerganov/llama.cpp v0.4.1

2026-09-14 18:27 · ⭐ 12.8万 · GitHub Release 原文 ↗
#推理引擎 #版本更新 #GGML后端

ggerganov/llama.cpp v0.4.1

一句话概括:新增 Maple 20B-A1B、Tencent Hy 4、Spark2.5 三个模型的架构支持,全面改进 JSON schema / chat 解析 / 日志 / server 子进程管理,并把 ggml 升级到 v0.24.0。

要点

API 变更(含 breaking change) - llama_sampler_chain_n() 返回类型由 int 改为 int32_t (#28631),下游调用方需注意类型匹配。 - 新增 server_subproc 与 waiter,用于 router 子进程监控,定义在 server-common.h (#28555)。

新增模型支持 - Maple 20B-A1B:ternary MoE 架构,目前为 CPU 实现 (#27000)。 - Tencent Hy 4(hy_v4)preview 架构 (#28127)。 - Spark2.5 (#27868)。 - Kimi-K3 新增 recurrent-state rollback 支持 (#28466)。

核心修复 - 修复 DeepSeek2、GLM-MoE 等模型的 MTP context KV cache 分配 (#28630)。 - GDN normalization 由 max 改为 rsqrt,影响 Qwen/Kimi/GLM 系列 (#28068)。 - 修正 Granite 全家族参数量统计,以及 Granite3 MoE 未知参数量统计 (#28643、#28632)。 - 修复 MIMO2 的 SWA pattern 加载错误与 get_key_or_arr 误用 (#28865、#28868)。 - 修复多模态输入之后的投机解码,以及 DFlash 的 mtmd chunk decode (#28715、#28587)。 - 修复 Jinja 的点属性整数字面量与 null in 成员判断 (#28817、#28620)。 - 改进 grammar 的 insert/move 合并机制与 max repetition 阈值 (#26885、#28469)。 - 提升 qwen3-coder 复杂类型解析与 typed content 检测能力 (#28742、#28511)。

转换与构建 - 新增 --fuse-qkv 转换标志,在 HF→GGUF 转换时融合 Q/K/V 张量 (#22780)。 - Qwen3-Next / Qwen3.5 转换时写出显式的 recurrent_layers 元数据 (#28208)。 - 引入 PCH 与 unity build 以缩短编译时间 (#28091);cpp-httplib 升级至 0.56.0 (#28787)。

CLI 与配置(breaking change) - 正式废弃并移除 --mmap / --mlock / --direct-io,统一改用 --load-mode (#28334)。 - mmproj 与 draft 设备默认跟随全局 --device 选择 (#28390)。 - iGPU 上默认关闭 lazy tensor loading (#28326)。 - 新增 --log-jsonl 与 LOG_JSON 宏,支持结构化 JSONL 日志 (#28437、#28586)。

架构重构 - JSON schema 处理重构,引入 common_schema 内部表示 (#28736)。 - 专用 chat 解析器拆分到 common/parsers (#27764)。

多模态 - 视频 hash 传播到 bitmap ID,格式为 {hash}+{frame},用于缓存识别 (#28601)。 - 修复 DFlash 在 mtmd chunks 上的投机解码失败 (#28587)。

Server - 子进程处理重构为单一 monitor 线程 (#28555)。 - 修复同一模型多个请求时的 LRU 挂起 (#28539)。 - --models-max 已达上限时仍允许下载模型 (#28530)。 - 修复 prompt 短于 checkpoint_min_step 时的 context checkpoint 驱逐逻辑 (#28302)。 - router 子进程状态命令改为按整行 framing (#28747)。 - 默认启用 --reasoning-preserve (#28437)。

UI - 聊天消息渲染性能优化:lazy mounting + 对 compositor 友好的动画 (#28460)。 - 新增 UI 资源缓存,改用 CMake 直接嵌入 UI 资源并移除构建期 helper (#28802、#28445)。 - 修复 MCP 图像附件不显示在 tool block 的问题 (#28089)。 - 对话导出改为从数据库而非缓存 store 读取 (#27432)。

ggml 升级 - ggml 由 v0.23.0 升至 v0.24.0,重点是扩展后端覆盖与健壮性:新增精度控制 API,Vulkan/SYCL/Hexagon/OpenCL 大量工作,以及 CPU、CUDA、Metal 等后端的正确性与性能修复。 - Nightly build 对应 b10964。

▸ Release Notes 英文原文(17594 字符)
## Overview llama.cpp 0.4.1 adds Maple 20B-A1B, Tencent Hy 4, and Spark2.5 support, improves JSON schema handling, chat parsing, logging, and server child-process management, and updates ggml to v0.24.0. ### API changes - Changed `llama_sampler_chain_n()` to return `int32_t` instead of `int` ([#28631](https://github.com/ggml-org/llama.cpp/pull/28631)). - Added `server_subproc` and `waiter` for router child-process monitoring in `server-common.h` ([#28555](https://github.com/ggml-org/llama.cpp/pull/28555)). ### New models - Added Maple 20B-A1B ternary MoE architecture (CPU) ([#27000](https://github.com/ggml-org/llama.cpp/pull/27000)). - Added Tencent Hy 4 (`hy_v4`) preview architecture support ([#28127](https://github.com/ggml-org/llama.cpp/pull/28127)). - Added Spark2.5 support ([#27868](https://github.com/ggml-org/llama.cpp/pull/27868)). ### Core changes - Added Kimi-K3 recurrent-state rollback support ([#28466](https://github.com/ggml-org/llama.cpp/pull/28466)). - Fixed MTP context KV cache allocation for DeepSeek2, GLM-MoE, and related models ([#28630](https://github.com/ggml-org/llama.cpp/pull/28630)). - Fixed GDN normalization from `max` to `rsqrt` for affected Qwen/Kimi/GLM models ([#28068](https://github.com/ggml-org/llama.cpp/pull/28068)). - Fixed Granite parameter counts and Granite3 MoE unknown parameter counts ([#28643](https://github.com/ggml-org/llama.cpp/pull/28643), [#28632](https://github.com/ggml-org/llama.cpp/pull/28632)). - Fixed MIMO2 SWA pattern loading and incorrect `get_key_or_arr` uses ([#28865](https://github.com/ggml-org/llama.cpp/pull/28865), [#28868](https://github.com/ggml-org/llama.cpp/pull/28868)). - Added `--fuse-qkv` conversion flag to fuse Q/K/V tensors during HF-to-GGUF conversion ([#22780](https://github.com/ggml-org/llama.cpp/pull/22780)). - Wrote explicit `recurrent_layers` metadata for Qwen3-Next/Qwen3.5 conversion ([#28208](https://github.com/ggml-org/llama.cpp/pull/28208)). - Refactored JSON schema handling with a `common_schema` internal representation ([#28736](https://github.com/ggml-org/llama.cpp/pull/28736)). - Split specialized chat parsers into `common/parsers` ([#27764](https://github.com/ggml-org/llama.cpp/pull/27764)). - Added structured JSONL logging via `--log-jsonl` and `LOG_JSON` ([#28437](https://github.com/ggml-org/llama.cpp/pull/28437), [#28586](https://github.com/ggml-org/llama.cpp/pull/28586)). - Removed deprecated `--mmap`/`--mlock`/`--direct-io` args in favor of `--load-mode` ([#28334](https://github.com/ggml-org/llama.cpp/pull/28334)). - Made mmproj and draft devices default to the global `--device` selection ([#28390](https://github.com/ggml-org/llama.cpp/pull/28390)). - Disabled lazy tensor loading by default on iGPUs ([#28326](https://github.com/ggml-org/llama.cpp/pull/28326)). - Fixed speculative decoding after multimodal input and DFlash mtmd chunk decode ([#28715](https://github.com/ggml-org/llama.cpp/pull/28715), [#28587](https://github.com/ggml-org/llama.cpp/pull/28587)). - Fixed Jinja dot-property integer literals and null `in` membership ([#28817](https://github.com/ggml-org/llama.cpp/pull/28817), [#28620](https://github.com/ggml-org/llama.cpp/pull/28620)). - Improved grammar insert/move handling and max repetition threshold ([#26885](https://github.com/ggml-org/llama.cpp/pull/26885), [#28469](https://github.com/ggml-org/llama.cpp/pull/28469)). - Improved qwen3-coder complex-type parsing and typed content detection ([#28742](https://github.com/ggml-org/llama.cpp/pull/28742), [#28511](https://github.com/ggml-org/llama.cpp/pull/28511)). - Added PCH and unity build support to improve build times ([#28091](https://github.com/ggml-org/llama.cpp/pull/28091)). - Updated cpp-httplib to 0.56.0 ([#28787](https://github.com/ggml-org/llama.cpp/pull/28787)). ### Multi-modality changes - Propagated video hash to bitmap IDs (`{hash}+{frame}`) for cache identification ([#28601](https://github.com/ggml-org/llama.cpp/pull/28601)). - Fixed DFlash speculative decoding failures on mtmd chunks ([#28587](https://github.com/ggml-org/llama.cpp/pull/28587)). ### Server changes - Refactored server child-process handling into a single monitor thread ([#28555](https://github.com/ggml-org/llama.cpp/pull/28555)). - Fixed LRU hang on multiple requests for the same model ([#28539](https://github.com/ggml-org/llama.cpp/pull/28539)). - Allow model downloads when `--models-max` is already reached ([#28530](https://github.com/ggml-org/llama.cpp/pull/28530)). - Fixed context checkpoint eviction on prompts shorter than `checkpoint_min_step` ([#28302](https://github.com/ggml-org/llama.cpp/pull/28302)). - Fixed speculative decoding after image input ([#28715](https://github.com/ggml-org/llama.cpp/pull/28715)). - Frame router child state commands as whole lines ([#28747](https://github.com/ggml-org/llama.cpp/pull/28747)). - Enabled `--reasoning-preserve` by default ([#28437](https://github.com/ggml-org/llama.cpp/pull/28437)). ### UI changes - Improved chat message rendering performance with lazy mounting and compositor-friendly animations ([#28460](https://github.com/ggml-org/llama.cpp/pull/28460)). - Added UI asset cache for faster builds ([#28802](https://github.com/ggml-org/llama.cpp/pull/28802)). - Embedded UI assets directly with CMake, removing the build-time helper ([#28445](https://github.com/ggml-org/llama.cpp/pull/28445)). - Fixed MCP image attachments not displayed in tool blocks ([#28089](https://github.com/ggml-org/llama.cpp/pull/28089)). - Export conversations from the database instead of the cached store ([#27432](https://github.com/ggml-org/llama.cpp/pull/27432)). ### ggml changes - Bumped ggml from v0.23.0 to v0.24.0 ([release](https://github.com/ggml-org/ggml/releases/tag/v0.24.0)). Version 0.24.0 focuses on expanding backend coverage and robustness, with a new precision-control API, major Vulkan/SYCL/Hexagon/OpenCL work, and numerous correctness and performance fixes across CPU, CUDA, Metal, and other backends. ## Assets **Nightly build:** [b10964](https://github.com/ggml-org/llama.cpp/releases/tag/b10964) ## More info - [Releases and versioning of `ggml-org` projects](https://github.com/ggml-org/ggml/discussions/1579) ## Changelog since v0.4.0 b29c606e2 llama.cpp : bump version to 0.4.1 (#28900) d9e03f107 sync : ggml eeea73161 ggml : bump version to 0.24.0 (ggml/1627) bbdd9f246 tests : add fusion baseline README and broaden fusion CI triggers (#28893) 97e4ca735 models : fix incorrect uses of get_key_or_arr (#28868) 1aca1f9fc models : fix mimo2 swa pattern load (#28865) be2c6d7d1 tests(s390x): add non-vxe build to tests (#28776) 3d10bcd19 llama: add Maple 20B-A1B ternary MoE architecture (CPU) (#27000) 21f6b0d22 sycl: rfc: Use radix select for top_k (#28670) 2f539596c ggml-cpu : disable PCH and fix CACHE_LINE_SIZE ambiguity to fix heap corruption (#28882) 89fe24240 ci : trigger self-hosted CI on changes to ci/run.sh (#28859) 15d8f2d59 ci : remove gg_sum summary logic (#28857) 661643e43 sycl : fix oneDNN scratchpad breaking the pool free order (#28704) 093a2f86c common : move llama_n_rs_seq to before llama_decode (#28749) ad6c66839 ggml-cuda: fallback to F32 on device without BF16 hardware acceleration (#28846) 7a16a6ce3 grammar : coalesce find + insert into a single insert and adjust move/copy mechanics (#26885) 5f436dddb tests : exclude HY_V4 from WebGPU test-llama-archs tests (#28855) e49d2c276 models : guard the expert FFN size fallback in nemotron-h against a zero divisor (#28779) 697805298 ggml-cpu(s390x): guard VXE-only repack helpers (#28775) 243a3082d tests : fix typo in test-quant-type-selection for nemotron 3 nano (#28835) b6b003d2c sycl : Fix get mem error (#28227) c95f8e47b ci : run editorconfig and code-style checks on ubuntu-slim (#28854) bc52a12b3 pi : prefer PI_MODEL_NAME env var for model disclosure (#28853) 4a8993735 tests : reduce FA test sizes (#28842) 37b3a9e0c ci : remove leftover command (#28839) 002a12ad2 ci : cap test-backend-ops parallel jobs at 2 and add a 3600s timeout (#28833) f1e44dcc1 vulkan: workaround NV queuesubmit driver bug (#28830) 56b9eb280 opencl: apply the noshuffle row-alignment rule to q4_K, q5_K and q8_0, not just q6_K (#28575) 790cf51aa chat : improve parsing of complex types in qwen3-coder (#28742) 8e330954a common: add LOG_JSON macro to log structured data (#28586) acecd5603 common : implement common_schema internal representation for JSON schemas (#28736) ae9afff8d jinja : support dot property integer literals (#28817) 737e0980f cmake: leave the timestamp out of precompiled headers on clang (#28816) 3057bb66c ui : add cache (#28802) 56381e407 server : allow model downloads at model limit fix issue #26809 (#28530) c8edceb06 ggml-cuda: hip add specific config table for AMD GCN (#27841) e192abb40 server : add missing headers (#28795) 718f7b417 vendor : update cpp-httplib to 0.56.0 (#28787) 2a3005c23 syscl : Handle (fail gracefully) unsupported tq1_0 quants (#28681) f3a33dff2 rpc : fix linking when compiling with BUILD_SHARED_LIBS=OFF (#28492) c069aa7f5 server: frame the router child state command as a whole line (#28747) 8a56aedd6 opencl: fix several bugs where the backend aborts (#27630) 07fc97716 opencl: add bin kernel `kernel_gemm_noshuffle_q4_k_f32_32b_trans_ila_a8_bin` (#28677) 3f5e94d7c webgpu: align tensor bindings to the type block size (#28382) eafe15a5e hexagon: support for multi-device model split (aka row-split) (#28589) d3146f2b5 ggml-webgpu: Update to a recent version of Dawn (#28683) 82d6bb284 server: refactor subproc handling (#28555) 8ea290247 cmake : skip PCH for llama-server PCH when using MSVC (#28763) b78a39a2f ci : run test-backend-ops as a dedicated ci/run.sh test (#28740) 982937a33 tests: extend test-quantize-fns to test nrc=2 (i8mm) kernels (#16234) 8172e6577 tests: tolerate a shared pool abort in test_completion_unified (#28759) 43f3dda62 ggml: skip 0-sized ids tensor when offloading selected experts (#28739) 5bda51bfb metal : skip the empty half of the mul_mm_id token tile (#28301) 3bcfeb700 cmake : add PCH and unity build to improve build times (#28091) 1dfe94e04 common : fix typo in speculative.cpp comment [no ci] (#28750) a2878d30d metal : single-source fusion table + fusion debug rework (#28164) aac810230 metal : fix idle threads in the remaining iq mul_mv kernels for ne00 < 1024 (#28692) 5cdd3d1da model : fix MTP context kv cache allocation for deepseek2, glm4moe, … (#28630) b0dcb8192 server: fix speculation after an image (#28715) 16378d93f CUDA/HIP: Flash Attention tuning (gfx1201) (#28102) 451b89bae ci : key cache to sanitizer matrix (#28708) 481c65f09 vulkan: fix data race and OOB access in argsort(large) (#28705) df03399b8 opencl: add A8 Q4_0 mm binary kernel support (#28268) 28ff09582 vulkan: use CPU writes in ggml_backend_vk_cpy_tensor_async if the context is idle (#28618) 50182a53f vulkan: use add_alloc_dep to enable topk_moe fusion for prefill (#28422) 6788edb4f vulkan: small M matrix optimizations for qwen (#28457) 52d426865 ci : add self-hosted-gpu-cuda and server-sanitize to hf-jobs (#28693) 18c17b4d6 ci : Update WoA CUDA 13.4 release to use 13.4.1 GA redistributables (#28687) fa6769818 spec: fix failed to decode mtmd chunk with DFlash (#28587) 41fc7584f scripts : use sed instead of grep for version parsing [no ci] (#28700) d344123fe models: clean up some dead switch branches in old models (#28669) c32d1dabe tests : increase tolerance for Add fusion tests (#28691) e5a8d439c tests : drop SYCL special-casing in test-backend-ops.cpp (#28688) 3ff67eb43 vulkan: fall back to shared-memory reduction for dmmv on PowerVR (#28341) 8c322d5bc convert : expand Nemotron H conversion fix (#28689) 311d4211b memory : avoid allocating V cache for indexer (it's not used) (#28330) 72797e891 vulkan : add command-buffer debug labels for GPU profilers (#28101) 4ea6d1bb6 ggml-cpu(s390x): add repack support for q4_0 (#28667) f1b6fbf35 ggml-cpu(s390x): add Q1_0 vector intrinsic support (#28606) d7e86430a model: fix all granite family parameter counts (#28643) 434ddbbc0 ci: fix sanitizer tests (#28583) 91f6a6cf3 vulkan: use spec constant for matrix matrix multiplication A-type (#25773) 6d9c82ea2 hexagon: rope updates (#28628) 22397c31a vulkan: Convert FILL to distribute workgroups in 2D to avoid exceeding maxComputeWorkGroupCount (#28592) 4b98ab805 py : lower numpy to 2.2.6 (#28654) 9cf3bf256 py : bump numpy to 2.4.6 (#28649) 4850c7727 llama : use int32_t for llama_sampler_chain_n return type (#28631) d4abd573f CUDA: size routed MoE MMQ N-tiles from typical expert width on RDNA3 (#28552) 5a4d0feca CUDA: replace GGML_FA_ALL_QUANTS with GGML_FA_QUANTS, more control over what is compiled (#28079) 14a9d09f7 args: officially deprecate --mmap|mlock|dio (#28334) e2d2c0d6a model: fix granite3 moe unknown parameter count (#28632) 6de9cdb26 mtmd: propagate video ID to bitmap (#28601) b31b71f3a jinja: treat a null left operand of in as a plain lookup (#28620) df750f76b vulkan: add dedicated iq4_xs mat-vec shader (#28426) 1945e0920 vulkan: add f16 B-type matmul pipelines and warp tile size tuning for Intel coopmat1 (#27471) 30b6a755e tests : use less threads for data initialization (#28325) 304665fe7 Add IQ type handling for MoE (#28476) f3f1a8f27 llama: disable lazy tensor loading by default on iGPUs (#28326) 9113cc188 ggml : fix msvc+clang ggml_vld1q_u32 (#28284) d4389a4dd Revert "ggml-cuda : restore prop.integrated on HIP builds (#24233)" (#28604) 5d806aa25 server : apply checkpoint min-step eviction only when the checkpoint list is full (#28302) 88ada91c1 metal : fix idle threads in mul_mv_iq3_xxs for ne00 < 1024 (#28086) 415e909d8 spec: single device drafter should create meta backend wrapper (#28390) 03fa73cb2 ci : disable npm gha cache (#28600) 1744c6bde ci : add PYTEST_WORKERS=1 to fix server-self-hosted job (#28603) ca86fb222 llama : add missing headers (#28566) 64e9bceb2 vulkan : fuse UNARY(GELU|SIGMOID|SILU|SOFTPLUS) + MUL (#27220) f014bfef8 Fix Vulkan-Hpp handle usage on 32-bit targets. (#22892) 895c045fd chat : split specialized parsers into common/parsers (#27764) 7d701b592 opencl: properly handle non-contiguous inputs to conv2d (#28503) 5a6caa05f ggml : update ggml_prec specification (#26675) 9dcf84e5a model : support Kimi-K3 recurrent-state rollback (#28466) 050dde50c hexagon: add RELU and LEAKY_RELU ops (#28585) 67672dc5b ci : bump ty to 0.0.78 (#28548) f114f91f9 tests : initialize the L2_NORM batch array (#28553) e71b80510 Revert "CUDA: size routed MoE MMQ N-tiles from typical expert width on RDNA3 (#24546)" (#28551) ccc3646c6 nix : update deprecated expressions (#28145) c0b1871bc webgpu: format the GET_ROWS case block (#28542) 160bd031b server: fix LRU hang on multiple requests same model (#28539) dbeb37548 sycl: add a batched L2_NORM kernel (#28222) 7a333e724 vulkan: add DeepSeek-V4 hyper-connection fused ops (DSV4_HC_COMB/PRE/POST) (#26578) 0c963452e CUDA: size routed MoE MMQ N-tiles from typical expert width on RDNA3 (#24546) 473599738 ggml: add gfx90c HIP support (#26454) d23c47f2a convert : refactor Hy4-preview conversion - move HC tensor mapping to the global map (#28451) 73ab7599b CUDA: branchless Q4_K/Q5_K unpack to speed up mmvq, L2 prefetch on DGX Spark (#26705) 0cae43063 vulkan: support type-aligned GET_ROWS (#28253) 1173700b9 examples : print ggml_version and ggml_commit in test-cmake [no ci] (#28538) 5202104b5 caps : recheck typed content if template checks for string (#28511) 9a7570587 convert : write explicit recurrent_layers for Qwen3-Next / Qwen3.5 (#28208) b74f590ea ggml-cuda: fix divergent barrier in f16 flash attention (#27870) 992cb503c ggml: allow backend inputs to not create another split (#28387) 9ac8c408a vulkan: rms_norm fusion opportunities (#28024) 2092353c8 ci : add container image checking and tagging (wip) (#28394) 8fe90e1fb vulkan: add TQ1_0 support (mm, mat-vec, mat-vec-id, dequant, get_rows) (#27765) 465e49b9c convert : add `--fuse-qkv` flag to fuse Q/K/V into QKV during HF-to-GGUF conversion (#22780) 5fdfa6282 models : fix GDN normalization from `max` to `rsqrt` (#28068) 3ad1ba733 [Model] Support for Spark2_5ForCausalLM implementation (#27868) d03efa5d5 opencl: properly choose weights pack for q4_K, q5_K mul_mat (#28402) 73a43d1f6 cuda: fixes races in mmid and mmf (#28475) 9e0e22059 grammar : fix max repetition threshold (#28469) 0afb805b1 ui: Improve Chat Messages rendering performance (#28460) 7620399f5 common: add --log-jsonl (#28437) c457e3bf7 ui : embed assets directly with CMake (#28445) 971595d66 metal : add remaining fa-vec tunings for M2 Max (#28458) 74a7c897f Github: limit blank issues to maintainers (#28435) 6a1a922d2 metal : fix memory leak in early return (#28399) 4d9176092 sycl : fix test-backend-ops CI break && restore Kronecker product FWHT support (#28016) (#28254) cd8cdf397 sycl: attribute device allocations by site (GGML_SYCL_MEMTRACE) (#27631) 427291b5b metal : add remaining fa-vec tunings for M3 (#28396) 85d5703a3 ui : fix MCP image attachments not displayed in tool block (#25789) (#28089) 1548a240e opencl: extend the elementwise and data‐movement op coverage (#27633) 4acf4a4cb opencl: add Adreno xmem SDPA path (#26331) 8b4b3558f ci : move more jobs to ccache-buckets (#28375) 1863ac033 ui: export conversations from database instead of cached store (#27432) 49c0dc82b model : add Tencent Hy 4 (hy_v4) preview architecture support (#28127)
▸ 主项目介绍 · ggerganov/llama.cpp
▸ README 原文(同步于 2026-07-19 13:24)
# llama.cpp ![llama](https://raw.githubusercontent.com/ggml-org/llama.brand/refs/heads/master/cover/llama-cpp/cover-llama-cpp-dark.svg) [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT) [![Release](https://img.shields.io/github/v/release/ggml-org/llama.cpp)](https://github.com/ggml-org/llama.cpp/releases) [![Server](https://github.com/ggml-org/llama.cpp/actions/workflows/server.yml/badge.svg)](https://github.com/ggml-org/llama.cpp/actions/workflows/server.yml) [![Docker](https://github.com/ggml-org/llama.cpp/actions/workflows/docker.yml/badge.svg)](https://github.com/ggml-org/llama.cpp/actions/workflows/docker.yml) [![Winget](https://github.com/ggml-org/llama.cpp/actions/workflows/winget.yml/badge.svg)](https://github.com/ggml-org/llama.cpp/actions/workflows/winget.yml) [Manifesto](https://github.com/ggml-org/llama.cpp/discussions/205) / [ggml](https://github.com/ggml-org/ggml) / [ops](https://github.com/ggml-org/llama.cpp/blob/master/docs/ops.md) / [maintainer PRs](https://github.com/ggml-org/llama.cpp/issues?q=is%3Apr%20is%3Aopen%20draft%3AFalse%20(author%3Argerganov%20OR%20author%3AKitaitiMakoto%20OR%20author%3Adanbev%20OR%20author%3Aaldehir%20OR%20author%3Amax-krasnyansky%20OR%20author%3ACISC%20OR%20author%3Aggerganov%20OR%20author%3Aam17an%20OR%20author%3Abartowski1182%20OR%20author%3Ahipudding%20OR%20author%3AServeurpersoCom%20OR%20author%3Apwilkin%20OR%20author%3Areeselevine%20OR%20author%3Angxson%20OR%20author%3Ajeffbolznv%20OR%20author%3A0cc4m%20OR%20author%3Aangt%20OR%20author%3AIMbackK%20OR%20author%3Aarthw%20OR%20author%3AJohannesGaessler%20OR%20author%3AORippler%20OR%20author%3Aruixiang63%20OR%20author%3Axctan%20OR%20author%3Aallozaur%20OR%20author%3Ayomaytk%20OR%20author%3Aaendk%20OR%20author%3Agaugarg-nv%20OR%20author%3Ataronaeo%20OR%20author%3Aforforever73%20OR%20author%3Alhez%20OR%20author%3Anetrunnereve%20OR%20author%3Afairydreaming)%20sort%3Aupdated-desc) LLM inference in C/C++ ## Recent API changes - [Changelog for `libllama` API](https://github.com/ggml-org/llama.cpp/issues/9289) - [Changelog for `llama-server` REST API](https://github.com/ggml-org/llama.cpp/issues/9291) ## Hot topics - **Hugging Face cache migration: models downloaded with `-hf` are now stored in the standard Hugging Face cache directory, enabling sharing with other HF tools.** - **[guide : using the new WebUI of llama.cpp](https://github.com/ggml-org/llama.cpp/discussions/16938)** - [guide : running gpt-oss with llama.cpp](https://github.com/ggml-org/llama.cpp/discussions/15396) - [[FEEDBACK] Better packaging for llama.cpp to support downstream consumers 🤗](https://github.com/ggml-org/llama.cpp/discussions/15313) - Support for the `gpt-oss` model with native MXFP4 format has been added | [PR](https://github.com/ggml-org/llama.cpp/pull/15091) | [Collaboration with NVIDIA](https://blogs.nvidia.com/blog/rtx-ai-garage-openai-oss) | [Comment](https://github.com/ggml-org/llama.cpp/discussions/15095) - Multimodal support arrived in `llama-server`: [#12898](https://github.com/ggml-org/llama.cpp/pull/12898) | [documentation](./docs/multimodal.md) - VS Code extension for FIM completions: https://github.com/ggml-org/llama.vscode - Vim/Neovim plugin for FIM completions: https://github.com/ggml-org/llama.vim - Hugging Face Inference Endpoints now support GGUF out of the box! https://github.com/ggml-org/llama.cpp/discussions/9669 - Hugging Face GGUF editor: [discussion](https://github.com/ggml-org/llama.cpp/discussions/9268) | [tool](https://huggingface.co/spaces/CISCai/gguf-editor) - WebGPU support is now available in the browser, see a blog/demo introducing it [here](https://reeselevine.github.io/llamas-on-the-web/). ---- ## Quick start Getting started with llama.cpp is straightforward. Here are several ways to install it on your machine: - Install `llama.cpp` using [brew, nix, winget, or conda-forge](docs/install.md) - Run with Docker - see our [Docker documentation](docs/docker.md) - Download pre-built binaries from the [releases page](https://github.com/ggml-org/llama.cpp/releases) - Build from source by cloning this repository - check out [our build guide](docs/build.md) Once installed, you'll need a model to work with. Head to the [Obtaining and quantizing models](#obtaining-and-quantizing-models) section to learn more. Example command: ```sh # Use a local model file llama-cli -m my_model.gguf # Or download and run a model directly from Hugging Face llama-cli -hf ggml-org/gemma-3-1b-it-GGUF # Launch OpenAI-compatible API server llama-server -hf ggml-org/gemma-3-1b-it-GGUF ``` ## Description The main goal of `llama.cpp` is to enable LLM inference with minimal setup and state-of-the-art performance on a wide range of hardware - locally and in the cloud. - Plain C/C++ implementation without any dependencies - Apple silicon is a first-class citizen - optimized via ARM NEON, Accelerate and Metal frameworks - AVX, AVX2, AVX512 and AMX support for x86 architectures - RVV, ZVFH, ZFH, ZICBOP and ZIHINTPAUSE support for RISC-V architectures - 1.5-bit, 2-bit, 3-bit, 4-bit, 5-bit, 6-bit, and 8-bit integer quantization for faster inference and reduced memory use - Custom CUDA kernels for running LLMs on NVIDIA GPUs (support for AMD GPUs via HIP and Moore Threads GPUs via MUSA) - Vulkan and SYCL backend support - CPU+GPU hybrid inference to partially accelerate models larger than the total VRAM capacity The `llama.cpp` project is the main playground for developing new features for the [ggml](https://github.com/ggml-org/ggml) library. <details> <summary>Models</summary> Typically finetunes of the base models below are supported as well. Instructions for adding support for new models: [HOWTO-add-model.md](docs/development/HOWTO-add-model.md) #### Text-only - [X] LLaMA 🦙 - [x] LLaMA 2 🦙🦙 - [x] LLaMA 3 🦙🦙🦙 - [X] [Mistral 7B](https://huggingface.co/mistralai/Mistral-7B-v0.1) - [x] [Mixtral MoE](https://huggingface.co/models?search=mistral-ai/Mixtral) - [x] [DBRX](https://huggingface.co/databricks/dbrx-instruct) - [x] [Jamba](https://huggingface.co/ai21labs) - [X] [Falcon](https://huggingface.co/models?search=tiiuae/falcon) - [X] [Chinese LLaMA / Alpaca](https://github.com/ymcui/Chinese-LLaMA-Alpaca) and [Chinese LLaMA-2 / Alpaca-2](https://github.com/ymcui/Chinese-LLaMA-Alpaca-2) - [X] [Vigogne (French)](https://github.com/bofenghuang/vigogne) - [X] [BERT](https://github.com/ggml-org/llama.cpp/pull/5423) - [X] [Koala](https://bair.berkeley.edu/blog/2023/04/03/koala/) - [X] [Baichuan 1 & 2](https://huggingface.co/models?search=baichuan-inc/Baichuan) + [derivations](https://huggingface.co/hiyouga/baichuan-7b-sft) - [X] [Aquila 1 & 2](https://huggingface.co/models?search=BAAI/Aquila) - [X] [Starcoder models](https://github.com/ggml-org/llama.cpp/pull/3187) - [X] [Refact](https://huggingface.co/smallcloudai/Refact-1_6B-fim) - [X] [MPT](https://github.com/ggml-org/llama.cpp/pull/3417) - [X] [Bloom](https://github.com/ggml-org/llama.cpp/pull/3553) - [x] [Yi models](https://huggingface.co/models?search=01-ai/Yi) - [X] [StableLM models](https://huggingface.co/stabilityai) - [x] [Deepseek models](https://huggingface.co/models?search=deepseek-ai/deepseek) - [x] [Qwen models](https://huggingface.co/models?search=Qwen/Qwen) - [x] [PLaMo-13B](https://github.com/ggml-org/llama.cpp/pull/3557) - [x] [Phi models](https://huggingface.co/models?search=microsoft/phi) - [x] [PhiMoE](https://github.com/ggml-org/llama.cpp/pull/11003) - [x] [GPT-2](https://huggingface.co/gpt2) - [x] [Orion 14B](https://github.com/ggml-org/llama.cpp/pull/5118) - [x] [InternLM2](https://huggingface.co/models?search=internlm2) - [x] [CodeShell](https://github.com/WisdomShell/codeshell) - [x] [Gemma](https://ai.google.dev/gemma) - [x] [Mamba](https://github.com/state-spaces/mamba) - [x] [Grok-1](https://huggingface.co/keyfan/grok-1-hf) - [x] [Xverse](https://huggingface.co/models?search=xverse) - [x] [Command-R models](https://huggingface.co/models?search=CohereForAI/c4ai-command-r) - [x] [SEA-LION](https://huggingface.co/models?search=sea-lion) - [x] [GritLM-7B](https://huggingface.co/GritLM/GritLM-7B) + [GritLM-8x7B](https://huggingface.co/GritLM/GritLM-8x7B) - [x] [OLMo](https://allenai.org/olmo) - [x] [OLMo 2](https://allenai.org/olmo) - [x] [OLMoE](https://huggingface.co/allenai/OLMoE-1B-7B-0924) - [x] [Granite models](https://huggingface.co/collections/ibm-granite/granite-code-models-6624c5cec322e4c148c8b330) - [x] [GPT-NeoX](https://github.com/EleutherAI/gpt-neox) + [Pythia](https://github.com/EleutherAI/pythia) - [x] [Snowflake-Arctic MoE](https://huggingface.co/collections/Snowflake/arctic-66290090abe542894a5ac520) - [x] [Smaug](https://huggingface.co/models?search=Smaug) - [x] [Poro 34B](https://huggingface.co/LumiOpen/Poro-34B) - [x] [Bitnet b1.58 models](https://huggingface.co/1bitLLM) - [x] [Flan T5](https://huggingface.co/models?search=flan-t5) - [x] [Open Elm models](https://huggingface.co/collections/apple/openelm-instruct-models-6619ad295d7ae9f868b759ca) - [x] [ChatGLM3-6b](https://huggingface.co/THUDM/chatglm3-6b) + [ChatGLM4-9b](https://huggingface.co/THUDM/glm-4-9b) + [GLMEdge-1.5b](https://huggingface.co/THUDM/glm-edge-1.5b-chat) + [GLMEdge-4b](https://huggingface.co/THUDM/glm-edge-4b-chat) - [x] [GLM-4-0414](https://huggingface.co/collections/THUDM/glm-4-0414-67f3cbcb34dd9d252707cb2e) - [x] [SmolLM](https://huggingface.co/collections/HuggingFaceTB/smollm-6695016cad7167254ce15966) - [x] [EXAONE-3.0-7.8B-Instruct](https://huggingface.co/LGAI-EXAONE/EXAONE-3.0-7.8B-Instruct) - [x] [FalconMamba Models](https://huggingface.co/collections/tiiuae/falconmamba-7b-66b9a580324dd1598b0f6d4a) - [x] [Jais](https://huggingface.co/inceptionai/jais-13b-chat) - [x] [Bielik-11B-v2.3](https://huggingface.co/collections/speakleash/bielik-11b-v23-66ee813238d9b526a072408a) - [x] [RWKV-7](https://huggingface.co/collections/shoumenchougou/rwkv7-gxx-gguf) - [x] [RWKV-6](https://github.com/BlinkDL/RWKV-LM) - [x] [QRWKV-6](https://huggingface.co/recursal/QRWKV6-32B-Instruct-Preview-v0.1) - [x] [GigaChat-20B-A3B](https://huggingface.co/ai-sage/GigaChat-20B-A3B-instruct) - [X] [Trillion-7B-preview](https://huggingface.co/trillionlabs/Trillion-7B-preview) - [x] [Ling models](https://huggingface.co/collections/inclusionAI/ling-67c51c85b34a7ea0aba94c32) - [x] [Liquid LFM2 models](https://huggingface.co/collections/LiquidAI/lfm2) - [x] [Liquid LFM2.5 models](https://huggingface.co/collections/LiquidAI/lfm25) - [x] [Liquid Nanos](https://huggingface.co/collections/LiquidAI/liquid-nanos) - [x] [Hunyuan models](https://huggingface.co/collections/tencent/hunyuan-dense-model-6890632cda26b19119c9c5e7) - [x] [BailingMoeV2 (Ring/Ling 2.0) models](https://huggingface.co/collections/inclusionAI/ling-v2-68bf1dd2fc34c306c1fa6f86) - [x] [Mellum models](https://huggingface.co/JetBrains/models?search=mellum) #### Multimodal - [x] [LLaVA 1.5 models](https://huggingface.co/collections/liuhaotian/llava-15-653aac15d994e992e2677a7e), [LLaVA 1.6 models](https://huggingface.co/collections/liuhaotian/llava-16-65b9e40155f60fd046a5ccf2) - [x] [BakLLaVA](https://huggingface.co/models?search=SkunkworksAI/Bakllava) - [x] [Obsidian](https://huggingface.co/NousResearch/Obsidian-3B-V0.5) - [x] [ShareGPT4V](https://huggingface.co/models?search=Lin-Chen/ShareGPT4V) - [x] [MobileVLM 1.7B/3B models](https://huggingface.co/models?search=mobileVLM) - [x] [Yi-VL](https://huggingface.co/models?search=Yi-VL) - [x] [Mini CPM](https://huggingface.co/models?search=MiniCPM) - [x] [Moondream](https://huggingface.co/vikhyatk/moondream2) - [x] [Bunny](https://github.com/BAAI-DCAI/Bunny) - [x] [GLM-EDGE](https://huggingface.co/models?search=glm-edge) - [x] [Qwen2-VL](https://huggingface.co/collections/Qwen/qwen2-vl-66cee7455501d7126940800d) - [x] [LFM2-VL](https://huggingface.co/collections/LiquidAI/lfm2-vl-68963bbc84a610f7638d5ffa) </details> <details> <summary>Bindings</summary> - Python: [ddh0/easy-llama](https://github.com/ddh0/easy-llama) - Python: [abetlen/llama-cpp-python](https://github.com/abetlen/llama-cpp-python) - Go: [go-skynet/go-llama.cpp](https://github.com/go-skynet/go-llama.cpp) - Node.js: [withcatai/node-llama-cpp](https://github.com/withcatai/node-llama-cpp) - JS/TS (llama.cpp server client): [lgrammel/modelfusion](https://modelfusion.dev/integration/model-provider/llamacpp) - JS/TS (Programmable Prompt Engine CLI): [offline-ai/cli](https://github.com/offline-ai/cli) - JavaScript/Wasm (works in browser): [tangledgroup/llama-cpp-wasm](https://github.com/tangledgroup/llama-cpp-wasm) - Typescript/Wasm (nicer API, available on npm): [ngxson/wllama](https://github.com/ngxson/wllama) - Ruby: [yoshoku/llama_cpp.rb](https://github.com/yoshoku/llama_cpp.rb) - Ruby: [docusealco/rllama](https://github.com/docusealco/rllama) - Rust (more features): [edgenai/llama_cpp-rs](https://github.com/edgenai/llama_cpp-rs) - Rust (nicer API): [mdrokz/rust-llama.cpp](https://github.com/mdrokz/rust-llama.cpp) - Rust (more direct bindings): [utilityai/llama-cpp-rs](https://github.com/utilityai/llama-cpp-rs) - Rust (automated build from crates.io): [ShelbyJenkins/llm_client](https://github.com/ShelbyJenkins/llm_client) - C#/.NET: [SciSharp/LLamaSharp](https://github.com/SciSharp/LLamaSharp) - C#/VB.NET (more features - community license): [LM-Kit.NET](https://docs.lm-kit.com/lm-kit-net/index.html) - Scala 3: [donderom/llm4s](https://github.com/donderom/llm4s) - Clojure: [phronmophobic/llama.clj](https://github.com/phronmophobic/llama.clj) - React Native: [mybigday/llama.rn](https://github.com/mybigday/llama.rn) - Java: [kherud/java-llama.cpp](https://github.com/kherud/java-llama.cpp) - Java: [QuasarByte/llama-cpp-jna](https://github.com/QuasarByte/llama-cpp-jna) - Zig: [deins/llama.cpp.zig](https://github.com/Deins/llama.cpp.zig) - Flutter/Dart: [netdur/llama_cpp_dart](https://github.com/netdur/llama_cpp_dart) - Flutter: [xuegao-tzx/Fllama](https://github.com/xuegao-tzx/Fllama) - PHP (API bindings and features built on top of llama.cpp): [distantmagic/resonance](https://github.com/distantmagic/resonance) [(more info)](https://github.com/ggml-org/llama.cpp/pull/6326) - Guile Scheme: [guile_llama_cpp](https://savannah.nongnu.org/projects/guile-llama-cpp) - Swift [srgtuszy/llama-cpp-swift](https://github.com/srgtuszy/llama-cpp-swift) - Swift [ShenghaiWang/SwiftLlama](https://github.com/ShenghaiWang/SwiftLlama) - Delphi [Embarcadero/llama-cpp-delphi](https://github.com/Embarcadero/llama-cpp-delphi) - Go (no CGo needed): [hybridgroup/yzma](https://github.com/hybridgroup/yzma) - Android: [llama.android](/examples/llama.android) </details> <details> <summary>UIs</summary> *(to have a project listed here, it should clearly state that it depends on `llama.cpp`)* - [AI Sublime Text plugin](https://github.com/yaroslavyaroslav/OpenAI-sublime-text) (MIT) - [BonzAI App](https://apps.apple.com/us/app/bonzai-your-local-ai-agent/id6752847988) (proprietary) - [cztomsik/ava](https://github.com/cztomsik/ava) (MIT) - [Dot](https://github.com/alexpinel/Dot) (GPL) - [eva](https://github.com/ylsdamxssjxxdd/eva) (MIT) - [iohub/collama](https://github.com/iohub/coLLaMA) (Apache-2.0) - [janhq/jan](https://github.com/janhq/jan) (AGPL) - [johnbean393/Sidekick](https://github.com/johnbean393/Sidekick) (MIT) - [KanTV](https://github.com/zhouwg/kantv?tab=readme-ov-file) (Apache-2.0) - [KodiBot](https://github.com/firatkiral/kodibot) (GPL) - [llama.vim](https://github.com/ggml-org/llama.vim) (MIT) - [LARS](https://github.com/abgulati/LARS) (AGPL) - [Llama Assistant](https://github.com/vietanhdev/llama-assistant) (GPL) - [LlamaLib](https://github.com/undreamai/LlamaLib) (Apache-2.0) - [LLMFarm](https://github.com/guinmoon/LLMFarm?tab=readme-ov-file) (MIT) - [LLMUnity](https://github.com/undreamai/LLMUnity) (MIT) - [LMStudio](https://lmstudio.ai/) (proprietary) - [LocalAI](https://github.com/mudler/LocalAI) (MIT) - [LostRuins/koboldcpp](https://github.com/LostRuins/koboldcpp) (AGPL) - [MindMac](https://mindmac.app) (proprietary) - [MindWorkAI/AI-Studio](https://github.com/MindWorkAI/AI-Studio) (FSL-1.1-MIT) - [Mobile-Artificial-Intelligence/maid](https://github.com/Mobile-Artificial-Intelligence/maid) (MIT) - [Mozilla-Ocho/llamafile](https://github.com/Mozilla-Ocho/llamafile) (Apache-2.0) - [nat/openplayground](https://github.com/nat/openplayground) (MIT) - [nomic-ai/gpt4all](https://github.com/nomic-ai/gpt4all) (MIT) - [ollama/ollama](https://github.com/ollama/ollama) (MIT) - [oobabooga/text-generation-webui](https://github.com/oobabooga/text-generation-webui) (AGPL) - [PocketPal AI](https://github.com/a-ghorbani/pocketpal-ai) (MIT) - [psugihara/FreeChat](https://github.com/psugihara/FreeChat) (MIT) - [ptsochantaris/emeltal](https://github.com/ptsochantaris/emeltal) (MIT) - [pythops/tenere](https://github.com/pythops/tenere) (AGPL) - [ramalama](https://github.com/containers/ramalama) (MIT) - [semperai/amica](https://github.com/semperai/amica) (MIT) - [withcatai/catai](https://github.com/withcatai/catai) (MIT) - [Autopen](https://github.com/blackhole89/autopen) (GPL) </details> <details> <summary>Tools</summary> - [akx/ggify](https://github.com/akx/ggify) – download PyTorch models from Hugging Face Hub and convert them to GGML - [akx/ollama-dl](https://github.com/akx/ollama-dl) – download models from the Ollama library to be used directly with llama.cpp - [crashr/gppm](https://github.com/crashr/gppm) – launch llama.cpp instances utilizing NVIDIA Tesla P40 or P100 GPUs with reduced idle power consumption - [gpustack/gguf-parser](https://github.com/gpustack/gguf-parser-go/tree/main/cmd/gguf-parser) - review/check the GGUF file and estimate the memory usage - [Styled Lines](https://marketplace.unity.com/packages/tools/generative-ai/styled-lines-llama-cpp-model-292902) (proprietary licensed, async wrapper of inference part for game development in Unity3d with pre-built Mobile and Web platform wrappers and a model example) - [unslothai/unsloth](https://github.com/unslothai/unsloth) – 🦥 exports/saves fine-tuned and trained models to GGUF (Apache-2.0) </details> <details> <summary>Infrastructure</summary> - [Paddler](https://github.com/intentee/paddler) - Open-source LLMOps platform for hosting and scaling AI in your own infrastructure - [GPUStack](https://github.com/gpustack/gpustack) - Manage GPU clusters for running LLMs - [llama_cpp_canister](https://github.com/onicai/llama_cpp_canister) - llama.cpp as a smart contract on the Internet Computer, using WebAssembly - [llama-swap](https://github.com/mostlygeek/llama-swap) - transparent proxy that adds automatic model switching with llama-server - [Kalavai](https://github.com/kalavai-net/kalavai-client) - Crowdsource end to end LLM deployment at any scale - [llmaz](https://github.com/InftyAI/llmaz) - ☸️ Easy, advanced inference platform for large language models on Kubernetes. - [LLMKube](https://github.com/defilantech/llmkube) - Kubernetes operator for llama.cpp with multi-GPU and Apple Silicon Metal support" </details> <details> <summary>Games</summary> - [Lucy's Labyrinth](https://github.com/MorganRO8/Lucys_Labyrinth) - A simple maze game where agents controlled by an AI model will try to trick you. </details> ## Supported backends | Backend | Target devices | | --- | --- | | [Metal](docs/build.md#metal-build) | Apple Silicon | | [BLAS](docs/build.md#blas-build) | All | | [BLIS](docs/backend/BLIS.md) | All | | [SYCL](docs/backend/SYCL.md) | Intel GPU | | [OpenVINO [In Progress]](docs/backend/OPENVINO.md) | Intel CPUs, GPUs, and NPUs | | [MUSA](docs/build.md#musa) | Moore Threads GPU | | [CUDA](docs/build.md#cuda) | Nvidia GPU | | [HIP](docs/build.md#hip) | AMD GPU | | [ZenDNN](docs/build.md#zendnn) | AMD CPU | | [Vulkan](docs/build.md#vulkan) | GPU | | [CANN](docs/build.md#cann) | Ascend NPU | | [OpenCL](docs/backend/OPENCL.md) | Adreno GPU | | [IBM zDNN](docs/backend/zDNN.md) | IBM Z & LinuxONE | | [WebGPU](docs/build.md#webgpu) | All | | [RPC](https://github.com/ggml-org/llama.cpp/tree/master/tools/rpc) | All | | [Hexagon [In Progress]](docs/backend/snapdragon/README.md) | Snapdragon | | [VirtGPU](docs/backend/VirtGPU.md) | VirtGPU APIR | ## Obtaining and quantizing models The [Hugging Face](https://huggingface.co) platform hosts a [number of LLMs](https://huggingface.co/models?library=gguf&sort=trending) compatible with `llama.cpp`: - [Trending](https://huggingface.co/models?library=gguf&sort=trending) - [LLaMA](https://huggingface.co/models?sort=trending&search=llama+gguf) You can either manually download the GGUF file or directly use any `llama.cpp`-compatible models from [Hugging Face](https://huggingface.co/) or other model hosting sites, by using this CLI argument: `-hf <user>/<model>[:quant]`. For example: ```sh llama-cli -hf ggml-org/gemma-3-1b-it-GGUF ``` By default, the CLI would download from Hugging Face, you can switch to other options with the environment variable `MODEL_ENDPOINT`. The `MODEL_ENDPOINT` must point to a Hugging Face compatible API endpoint. After downloading a model, use the CLI tools to run it locally - see below. `llama.cpp` requires the model to be stored in the [GGUF](https://github.com/ggml-org/ggml/blob/master/docs/gguf.md) file format. Models in other data formats can be converted to GGUF using the `convert_*.py` Python scripts in this repo. The Hugging Face platform provides a variety of online tools for converting, quantizing and hosting models with `llama.cpp`: - Use the [GGUF-my-repo space](https://huggingface.co/spaces/ggml-org/gguf-my-repo) to convert to GGUF format and quantize model weights to smaller sizes - Use the [GGUF-my-LoRA space](https://huggingface.co/spaces/ggml-org/gguf-my-lora) to convert LoRA adapters to GGUF format (more info: https://github.com/ggml-org/llama.cpp/discussions/10123) - Use the [GGUF-editor space](https://huggingface.co/spaces/CISCai/gguf-editor) to edit GGUF meta data in the browser (more info: https://github.com/ggml-org/llama.cpp/discussions/9268) - Use the [Inference Endpoints](https://ui.endpoints.huggingface.co/) to directly host `llama.cpp` in the cloud (more info: https://github.com/ggml-org/llama.cpp/discussions/9669) To learn more about model quantization, [read this documentation](tools/quantize/README.md) ## [`llama-cli`](tools/cli) #### A CLI tool for accessing and experimenting with most of `llama.cpp`'s functionality. - <details open> <summary>Run in conversation mode</summary> Models with a built-in chat template will automatically activate conversation mode. If this doesn't occur, you can manually enable it by adding `-cnv` and specifying a suitable chat template with `--chat-template NAME` ```bash llama-cli -m model.gguf # > hi, who are you? # Hi there! I'm your helpful assistant! I'm an AI-powered chatbot designed to assist and provide information to users like you. I'm here to help answer your questions, provide guidance, and offer support on a wide range of topics. I'm a friendly and knowledgeable AI, and I'm always happy to help with anything you need. What's on your mind, and how can I assist you today? # # > what is 1+1? # Easy peasy! The answer to 1+1 is... 2! ``` </details> - <details> <summary>Run in conversation mode with custom chat template</summary> ```bash # use the "chatml" template (use -h to see the list of supported templates) llama-cli -m model.gguf -cnv --chat-template chatml # use a custom template llama-cli -m model.gguf -cnv --in-prefix 'User: ' --reverse-prompt 'User:' ``` </details> - <details> <summary>Constrain the output with a custom grammar</summary> ```bash llama-cli -m model.gguf -n 256 --grammar-file grammars/json.gbnf -p 'Request: schedule a call at 8pm; Command:' # {"appointmentTime": "8pm", "appointmentDetails": "schedule a a call"} ``` The [grammars/](grammars/) folder contains a handful of sample grammars. To write your own, check out the [GBNF Guide](grammars/README.md). For authoring more complex JSON grammars, check out https://grammar.intrinsiclabs.ai/ </details> ## [`llama-server`](tools/server) #### A lightweight, [OpenAI API](https://github.com/openai/openai-openapi) compatible, HTTP server for serving LLMs. - <details open> <summary>Start a local HTTP server with default configuration on port 8080</summary> ```bash llama-server -m model.gguf --port 8080 # Basic web UI can be accessed via browser: http://localhost:8080 # Chat completion endpoint: http://localhost:8080/v1/chat/completions ``` </details> - <details> <summary>Support multiple-users and parallel decoding</summary> ```bash # up to 4 concurrent requests, each with 4096 max context llama-server -m model.gguf -c 16384 -np 4 ``` </details> - <details> <summary>Enable speculative decoding</summary> ```bash # the draft.gguf model should be a small variant of the target model.gguf llama-server -m model.gguf -md draft.gguf ``` </details> - <details> <summary>Serve an embedding model</summary> ```bash # use the /embedding endpoint llama-server -m model.gguf --embedding --pooling cls -ub 8192 ``` </details> - <details> <summary>Serve a reranking model</summary> ```bash # use the /reranking endpoint llama-server -m model.gguf --reranking ``` </details> - <details> <summary>Constrain all outputs with a grammar</summary> ```bash # custom grammar llama-server -m model.gguf --grammar-file grammar.gbnf # JSON llama-server -m model.gguf --grammar-file grammars/json.gbnf ``` </details> ## [`llama-perplexity`](tools/perplexity) #### A tool for measuring the [perplexity](tools/perplexity/README.md) [^1] (and other quality metrics) of a model over a given text. - <details open> <summary>Measure the perplexity over a text file</summary> ```bash llama-perplexity -m model.gguf -f file.txt # [1]15.2701,[2]5.4007,[3]5.3073,[4]6.2965,[5]5.8940,[6]5.6096,[7]5.7942,[8]4.9297, ... # Final estimate: PPL = 5.4007 +/- 0.67339 ``` </details> - <details> <summary>Measure KL divergence</summary> ```bash # TODO ``` </details> [^1]: [https://huggingface.co/docs/transformers/perplexity](https://huggingface.co/docs/transformers/perplexity) ## [`llama-bench`](tools/llama-bench) #### Benchmark the performance of the inference for various parameters. - <details open> <summary>Run default benchmark</summary> ```bash llama-bench -m model.gguf # Output: # | model | size | params | backend | threads | test | t/s | # | ------------------- | ---------: | ---------: | ---------- | ------: | ------------: | -------------------: | # | qwen2 1.5B Q4_0 | 885.97 MiB | 1.54 B | Metal,BLAS | 16 | pp512 | 5765.41 ± 20.55 | # | qwen2 1.5B Q4_0 | 885.97 MiB | 1.54 B | Metal,BLAS | 16 | tg128 | 197.71 ± 0.81 | # # build: 3e0ba0e60 (4229) ``` </details> ## [`llama-simple`](examples/simple) #### A minimal example for implementing apps with `llama.cpp`. Useful for developers. - <details> <summary>Basic text completion</summary> ```bash llama-simple -m model.gguf # Hello my name is Kaitlyn and I am a 16 year old girl. I am a junior in high school and I am currently taking a class called "The Art of ``` </details> ## Contributing - Contributors can open PRs - Collaborators will be invited based on contributions - Maintainers can push to branches in the `llama.cpp` repo and merge PRs into the `master` branch - Any help with managing issues, PRs and projects is very appreciated! - See [good first issues](https://github.com/ggml-org/llama.cpp/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22) for tasks suitable for first contributions - Read the [CONTRIBUTING.md](CONTRIBUTING.md) for more information - Make sure to read this: [Inference at the edge](https://github.com/ggml-org/llama.cpp/discussions/205) - A bit of backstory for those who are interested: [Changelog podcast](https://changelog.com/podcast/532) ## Other documentation - [cli](tools/cli/README.md) - [completion](tools/completion/README.md) - [server](tools/server/README.md) - [GBNF grammars](grammars/README.md) #### Development documentation - [How to build](docs/build.md) - [Running on Docker](docs/docker.md) - [Build on Android](docs/android.md) - [Multi-GPU usage](docs/multi-gpu.md) - [Performance troubleshooting](docs/development/token_generation_performance_tips.md) - [GGML tips & tricks](https://github.com/ggml-org/llama.cpp/wiki/GGML-Tips-&-Tricks) #### Seminal papers and background on the models If your issue is with model generation quality, then please at least scan the following links and papers to understand the limitations of LLaMA models. This is especially important when choosing an appropriate model size and appreciating both the significant and subtle differences between LLaMA models and ChatGPT: - LLaMA: - [Introducing LLaMA: A foundational, 65-billion-parameter large language model](https://ai.facebook.com/blog/large-language-model-llama-meta-ai/) - [LLaMA: Open and Efficient Foundation Language Models](https://arxiv.org/abs/2302.13971) - GPT-3 - [Language Models are Few-Shot Learners](https://arxiv.org/abs/2005.14165) - GPT-3.5 / InstructGPT / ChatGPT: - [Aligning language models to follow instructions](https://openai.com/research/instruction-following) - [Training language models to follow instructions with human feedback](https://arxiv.org/abs/2203.02155) ## XCFramework The XCFramework is a precompiled version of the library for iOS, visionOS, tvOS, and macOS. It can be used in Swift projects without the need to compile the library from source. For example: ```swift // swift-tools-version: 5.10 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription let package = Package( name: "MyLlamaPackage", targets: [ .executableTarget( name: "MyLlamaPackage", dependencies: [ "LlamaFramework" ]), .binaryTarget( name: "LlamaFramework", url: "https://github.com/ggml-org/llama.cpp/releases/download/b5046/llama-b5046-xcframework.zip", checksum: "c19be78b5f00d8d29a25da41042cb7afa094cbf6280a225abe614b03b20029ab" ) ] ) ``` The above example is using an intermediate build `b5046` of the library. This can be modified to use a different version by changing the URL and checksum. ## Completions Command-line completion is available for some environments. #### Bash Completion ```bash $ build/bin/llama-cli --completion-bash > ~/.llama-completion.bash $ source ~/.llama-completion.bash ``` Optionally this can be added to your `.bashrc` or `.bash_profile` to load it automatically. For example: ```console $ echo "source ~/.llama-completion.bash" >> ~/.bashrc ``` ## Dependencies - [yhirose/cpp-httplib](https://github.com/yhirose/cpp-httplib) - Single-header HTTP server, used by `llama-server` - MIT license - [stb-image](https://github.com/nothings/stb) - Single-header image format decoder, used by multimodal subsystem - Public domain - [nlohmann/json](https://github.com/nlohmann/json) - Single-header JSON library, used by various tools/examples - MIT License - [miniaudio.h](https://github.com/mackron/miniaudio) - Single-header audio format decoder, used by multimodal subsystem - Public domain - [subprocess.h](https://github.com/sheredom/subprocess.h) - Single-header process launching solution for C and C++ - Public domain
▸ 中文总结(生成于 2026-07-30 14:17)

ggerganov/llama.cpp 项目介绍

项目概述

llama.cpp 是一个完全用 C/C++ 实现的大语言模型(LLM)推理引擎,旨在以最小的配置和领先的性能,在各种硬件(本地和云端)上运行 LLM 推理。项目由 ggerganov 维护,目前已获得 122100+ Star,是开源社区最流行的本地 LLM 推理方案之一。

核心目标

  • 零依赖:纯 C/C++ 实现,不依赖任何外部框架或库。
  • 跨平台高性能:优先支持 Apple Silicon,同时覆盖 x86(AVX/AVX2/AVX512/AMX)、RISC-V(RVV/ZVFH/ZFH 等)、NVIDIA GPU(CUDA)、AMD GPU(HIP)、Moore Threads GPU(MUSA)、Intel GPU(SYCL)、Vulkan、WebGPU 等几乎所有主流计算后端。
  • 低资源消耗:提供 1.5-bit、2-bit、3-bit、4-bit、5-bit、6-bit、8-bit 的整数量化,大幅减少显存占用并加速推理。
  • CPU+GPU 混合推理:支持将超过显存容量的大模型部分卸载到 CPU,实现更大模型的本地运行。

核心技术架构

  • ggml 库:llama.cpp 是 ggml 库的主要试验田。ggml 是一个面向机器学习的张量库,专门为 LLM 推理优化。
  • 量化技术:支持多种位宽的整数量化(如 Q4_0、Q5_1 等),可在几乎不损失精度的前提下将模型体积压缩至 1/4 甚至更小,使模型能运行在 8GB 显存的消费级显卡上。
  • 后端抽象:通过 Metal、CUDA、Vulkan、SYCL 等后端实现硬件加速,用户只需在编译时选择对应的后端即可。
  • GGUF 模型格式:所有模型需转换为统一的 GGUF 格式,Hugging Face 上已有大量预转换的 GGUF 模型可直接使用。

支持模型

llama.cpp 兼容大量开源模型及其微调版本,包括但不限于:

  • 纯文本模型:LLaMA 全系列、Mistral 7B、Mixtral MoE、Falcon、Qwen、DeepSeek、Gemma、Phi、Yi、Baichuan、InternLM2、Mamba、RWKV-6/7、GPT-2、BERT、StableLM、Command-R、OLMo、SmolLM、Hunyuan 等数十种。
  • 多模态模型:LLaVA 1.5/1.6、BakLLaVA、Qwen2-VL、Mini CPM、Moondream 等。
  • 特殊架构:支持 MoE(混合专家)、Mamba(状态空间模型)、BitNet b1.58(1.58 bit 量化)等。

详细支持列表见 README 中的 models 折叠区。

技术亮点

  • 极高的性能实测:在 Apple Silicon 上通过 Metal 后端达到行业领先的推理速度;在 x86 上利用 AVX 指令集进一步加速。
  • 量化精度与速度平衡:官方提供了详尽的量化方案,用户可根据需求选择。例如 Q4_0 在 1.5B 模型上可达到 5765 tokens/s (pp512)和 197 tokens/s(tg128)的 benchmark 结果(Metal+BLAS,16 线程)。
  • 多用户并行解码:llama-server 支持多用户并发请求,最大并行数可配置,适用于生产环境。
  • 推测解码:支持使用较小的 draft 模型加速主模型推理。
  • 约束输出:通过 GBNF 语法文件控制模型输出,例如强制输出 JSON 格式。
  • REST API 兼容 OpenAI:llama-server 提供 /v1/chat/completions 等端点,可直接替代 OpenAI API。
  • WebGPU 浏览器端推理:可在浏览器中直接运行 LLM,无需下载任何二进制文件。
  • 丰富的生态:已有 20+ 种语言的绑定(Python、Go、Node.js、Rust、C#、Java 等)、10+ 个主流 UI(如 Ollama、LM Studio、GPT4All、text-generation-webui)、以及大量基础设施工具(如 GPUStack、llama-swap)。

快速开始(摘自 README)

安装方式

  • 通过 Homebrew/nix/winget/conda-forge 安装
  • 使用 Docker(官方提供 Dockerfile)
  • 从 Releases 页面下载预编译二进制
  • 从源码编译(参见 build guide)

示例命令

# 使用本地模型文件
llama-cli -m my_model.gguf

# 直接从 Hugging Face 下载并运行
llama-cli -hf ggml-org/gemma-3-1b-it-GGUF

# 启动兼容 OpenAI API 的 HTTP 服务器
llama-server -hf ggml-org/gemma-3-1b-it-GGUF

对话模式

llama-cli -m model.gguf
# 模型带内置聊天模板时会自动进入对话模式

约束输出(JSON)

llama-cli -m model.gguf -n 256 --grammar-file grammars/json.gbnf -p 'Request: schedule a call at 8pm; Command:'

项目生态

  • 绑定:支持 Python、Go、Node.js、Rust、C#/ .NET、Java、Ruby、Swift、Zig、Flutter/Dart 等 20+ 语言。
  • UI:Ollama、LM Studio、GPT4All、Jan、LocalAI、koboldcpp、text-generation-webui 等 20+ 知名项目均基于 llama.cpp。
  • 工具:GGUF 编辑器、模型格式转换脚本、量化工具、Hugging Face 推理端点等。
  • 基础设施:GPUStack、Kubernetes Operator、llama-swap 等用于模型部署和集群管理。

性能数据样例(官方 Benchmark)

模型 大小 参数 后端 线程 测试 tokens/s
qwen2 1.5B Q4_0 885.97 MiB 1.54 B Metal,BLAS 16 pp512 5765.41 ± 20.55
tg128 197.71 ± 0.81

(注:pp 为 prompt processing,tg 为 text generation,数据来自 llama-bench 工具)

总结

llama.cpp 是目前最成熟、最流行的本地 LLM 推理引擎之一,凭借纯 C/C++ 实现、极致的量化优化、广泛的硬件支持和庞大的社区生态,为开发者和企业提供了在消费级硬件上运行大语言模型的能力。它不仅是推理工具,也是 ggml 库的核心试验场,持续推动着边缘 AI 推理的边界。