<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>C API on KbWen Blog</title>
    <link>https://www.kbwen.com/tags/c-api/</link>
    <description>Articles and notes on AI systems, machine learning, Python, data engineering, and software development.</description>
    <generator>Hugo</generator>
    <language>zh-tw</language>
    <image>
      <url>https://www.kbwen.com/images/og-default.png</url>
      <title>KbWen Blog</title>
      <link>https://www.kbwen.com/</link>
    </image>
    
    <lastBuildDate>Wed, 25 Nov 2026 18:25:00 +0800</lastBuildDate><atom:link href="https://www.kbwen.com/tags/c-api/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>llama.cpp 升到 1.0.0，哪些用法會受影響？</title>
      <link>https://www.kbwen.com/llama-cpp-1-0-public-c-api/</link>
      <pubDate>Wed, 25 Nov 2026 18:25:00 +0800</pubDate><dc:creator>KbWen</dc:creator>
      <guid>https://www.kbwen.com/llama-cpp-1-0-public-c-api/</guid>
      <description>llama.cpp 與 ggml 在 2026 年 11 月發布 v1.0.0。拿被移除的 llama_set_warmup 當例子，看看直接連結 libllama 的程式和只開 llama-server 的人，升級時各自會碰到什麼。</description>
      <content:encoded><![CDATA[<p>llama.cpp 和 ggml 在 2026 年 11 月 13 日一起發了 v1.0.0。用它的人多半會先想到同一件事：有甚麼新功能？這個大版本升級後我現在跑得好好的東西，升上去會不會壞？</p>
<p>這要看你怎麼用 llama.cpp。有人只是下載編好的 <code>llama-server</code>，開起來接 API；也有人在自己的 C 或 C++ 專案裡直接連結 libllama，呼叫 header 裡宣告的函式。</p>
<h2 id="版本號">版本號</h2>
<p><a href="https://huggingface.co/blog/ggml-org/llama-cpp-v1">Hugging Face 上的發布文章</a>把規則寫成一張表格。MAJOR 只用在 <code>./include</code> 裡公開 C API 的破壞性變更；新功能、後端更新、模型支援或新增 API 屬於 MINOR；沒有動到 API 的 bug 修正是 PATCH。</p>
<p>llama.cpp 對應的函式庫是 libllama，公開 header 放在 <code>llama.cpp/include/</code>。文章說往後 API 和 ABI 不相容的改動都會反映在 major 版本號上。</p>
<h2 id="llama_set_warmup-去哪了"><code>llama_set_warmup</code> 去哪了</h2>
<p>根據 <a href="https://github.com/ggml-org/llama.cpp/releases/tag/v1.0.0">v1.0.0 的 release notes</a>，<code>llama.h</code> 移除了 <code>llama_set_warmup</code>，連同 35 個 deprecated 函式一起拿掉。</p>
<p>在 <a href="https://github.com/ggml-org/llama.cpp/blob/v0.9.0/include/llama.h">v0.9.0 的 <code>include/llama.h</code></a> 裡，<code>llama_set_warmup</code> 有一段註解：設成 true 時，<code>llama_decode()</code> 會把模型所有的 tensor 都用上，讓權重載入並快取起來；但在 MoE 模型上，計算圖會因此多做幾次重新配置，一般不建議使用，以後會移除。</p>
<p>用 GCC 編譯的時候，這個巨集會展開成 <code>deprecated</code> 屬性，所以呼叫它的程式還是可以編譯，只是每次 build 都多一行警告。專案如果大一點，build log 本來就會很長，當這行警告夾在中間，很容易就被略過了。</p>
<p>到了 v1.0.0 的 header，<code>llama_set_warmup</code> 已經不在。<code>DEPRECATED</code> 巨集的定義雖然還留著，不過整份檔案裡沒有任何函式再使用到。今天如果你拿同一份程式新的 header 和函式庫重新 build，就會因為 <code>llama_set_warmup</code> 而失敗。</p>
<h2 id="只開-llama-server">只開 llama-server</h2>
<p>如果你平常是開 <code>llama-server</code> 或 <code>llama-cli</code> 來用，<code>llama_set_warmup</code> 被拿掉多半感覺不到。指令列上的 <code>--warmup</code>／<code>--no-warmup</code> 在 1.0.0 還在，並沒有呼叫 <code>llama_set_warmup</code>。</p>
<p>同一份 release notes 也拿掉了 <code>--defrag-thold</code>。這個參數在 0.9.0 就已經不做任何事，帶上去只有一行 deprecated 警告；在 1.0.0，參數解析找不到它，則丟出 <code>error: invalid argument: --defrag-thold</code>。啟動腳本裡如果還留著 <code>--defrag-thold</code>，server 會在啟動時就停下來，所以升級前把腳本裡的參數看過一遍，比較保險。</p>
<p>回到連結 libllama 的情況，升級前可以先拿 0.9.0 編一次，把 deprecated 警告整理出來，大致就是這次要改的地方。只有 <code>llama_context_params</code> 裡的 <code>defrag_thold</code> 欄位不會出現在警告裡，它在 0.9.0 只在註解寫了 DEPRECATED，編譯器不會提醒，有設定這個欄位的程式要另外找出來。原本靠 <code>llama_set_warmup</code> 暖機的程式，替代寫法可以參考 <a href="https://github.com/ggml-org/llama.cpp/blob/v1.0.0/common/common.cpp">common 的暖機</a>：把模型的 BOS 和 EOS token 送進去執行一次推論，結束後清空 KV cache。llama-server 預設每次啟動都會跑這一段。</p>
]]></content:encoded>
    </item>
    
  </channel>
</rss>
