> For the complete documentation index, see [llms.txt](https://unsloth.ai/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://unsloth.ai/docs/jp/tong-he/connections/llamacppwounslothnisuru-llama-serverdeggufwosuru.md).

# llama.cppをUnslothに接続する: llama-serverでGGUFを実行する

Llama.cpp は、GGUFモデルをローカルハードウェア上で効率的に実行するためのオープンソース推論エンジンで、 [Unsloth](https://github.com/unslothai/unsloth) それらのモデルをオープンソースのUIチャットインターフェース上で直接実行しやすくします。ローカルの `llama-server`を起動すれば、マシン上または Hugging Face から GGUF モデルを提供し、Unsloth に接続して、ほかの外部チャットモデルと同じように使えます。

このガイドでは、llama.cpp のインストールと起動を順に説明します。 `llama-server`、Unsloth への接続、モデルの有効化、プロンプトキャッシュ、コンテキスト長、APIキー、FA、チャットテンプレートの設定を行います。

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FhoLxJoFPUmjxslMPot7h%2Fexport-1779046578662.gif?alt=media&amp;token=83b946dd-d8e1-4630-a143-b7b0e4d052a4" alt=""><figcaption></figcaption></figure>

## セットアップ

{% stepper %}
{% step %}

### llama.cpp をインストール

まず llama.cpp をインストールして、 `llama-server` コマンドを実行できるようにします。

公式のインストール方法のいずれかを使用してください：

* あらかじめビルドされた [llama.cpp バイナリ](https://github.com/ggml-org/llama.cpp/releases)
* llama.cpp を [ソースからビルドする](https://github.com/ggml-org/llama.cpp/blob/master/docs/build.md)

インストール後、ターミナルで llama-server が動作することを確認します：

`llama-server --help`
{% endstep %}

{% step %}

### GGUFモデルを選ぶ

llama-server は、ローカルの .gguf ファイルを読み込むことも、Hugging Face から GGUF モデルをダウンロードすることもできます。

Hugging Face の GGUF リポジトリを直接サーブするには、リポジトリ名と量子化名を使います：

`llama-server -hf unsloth/Qwen3.6-27B-GGUF:UD-Q4_K_XL`

ローカルモデルを読み込みたい場合は、以下の手順に従うこともできます。&#x20;

開始 `llama-server` サーブしたいモデルで：

```bash
llama-server \\
  --model /path/to/model.gguf \\
  --host 0.0.0.0 \\
  --port 8080
```

これにより、次の API エンドポイントが公開されます： `http://localhost:8080/v1`

APIキーを必須にするには、次を追加します：

```bash
--api-key 1234-myapi-key
```

{% endstep %}

{% step %}

### Llama.cpp を Unsloth に接続する

開く **設定 → 接続**、次に **接続を追加**。選択してください **llama.cpp**、その後サーバーの詳細を入力します：

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FU9TcWUfyBHEDWs91g8jx%2Fimage.png?alt=media&amp;token=2a7a974a-9e2e-4bac-96f4-09e55e1767b9" alt="" width="563"><figcaption></figcaption></figure>

llama-server を次のオプション付きで起動していない場合は `--api-key`、APIキー欄は空のままにします。サーバーのベースURLを入力してください。例： `http://localhost:8080/v1`\
クリックします **モデルを読み込む** 利用可能なモデルIDを取得するため、またはサーバーが公開していない場合は手動でモデルIDを入力します `/models`.

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FXBMWShY6KWmxRJLwmieH%2Fimage.png?alt=media&amp;token=1809ec26-84c6-4c61-b6a5-6dfa5bed769c" alt="" width="563"><figcaption></figcaption></figure>

その後、 **接続を追加 をクリックすると、** 有効にしたモデルは次に表示されるようになります： **接続済み** の **モデルを選択** ドロップダウンに表示されます。
{% endstep %}

{% step %}

### チャット準備完了&#x20;

接続を保存すると、llama.cpp モデルは次の下に表示されます： **接続** モデルのドロップダウンに表示されます。それを選択してチャットを開始します **llama-server**.

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FhoLxJoFPUmjxslMPot7h%2Fexport-1779046578662.gif?alt=media&amp;token=83b946dd-d8e1-4630-a143-b7b0e4d052a4" alt=""><figcaption></figcaption></figure>
{% endstep %}
{% endstepper %}

### プロンプトキャッシュ

プロンプトキャッシュは、リクエストが同じ長いプレフィックスを再利用する際の遅延とコストを削減します。 **プロンプトキャッシュ** 対応する接続のキャッシュ動作を制御するには、Unsloth のサイドパネルの設定を使用します。

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fq4csmTX5rS9isMkNkhTX%2FPrompt%20Caching%20Diagram%20(1).png?alt=media&amp;token=ade433bf-5eaf-4146-a266-525a85a6c98d" alt="" width="375"><figcaption></figcaption></figure>

llama.cpp では、プロンプトキャッシュは既定で有効になっており、起動時に無効化できます\
`llama-server` 次のオプションで：

```bash
--no-cache-prompt
```

### **一般的な llama-server 引数**

上の例では、必要な接続設定のみを使用しています。モデルやハードウェアに応じて、さらに llama-server 引数を追加できます。

一般的なオプションには次があります：

```bash
  --ctx-size 8192 \\        # コンテキスト長を設定
  --parallel 2 \\           # 並列スロット数を設定
  --flash-attn on \\        # 対応している場合は Flash Attention を有効化
  --jinja \\                # モデルのチャットテンプレートを使用
  --api-key 1234-key \\     # APIキーを必須にする
  --no-cache-prompt        # プロンプトキャッシュを無効化
```

サーバー引数の全一覧については、公式の [llama.cpp サーバー README](https://github.com/ggml-org/llama.cpp/blob/master/tools/server/README.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://unsloth.ai/docs/jp/tong-he/connections/llamacppwounslothnisuru-llama-serverdeggufwosuru.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
