> 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/ji-ben/inference-and-deployment/llama-server-and-openai-endpoint.md).

# llama-serverとOpenAIエンドポイントのデプロイガイド

Devstral-2 をデプロイします - こちらを参照してください [Devstral 2](/docs/jp/moderu/tutorials/devstral-2.md) モデルの詳細についてはこちら。&#x20;

最新の `llama.cpp` オン [GitHub はこちら](https://github.com/ggml-org/llama.cpp)で入手してください。以下のビルド手順に従っても構いません。変更してください `-DGGML_CUDA=ON` を `-DGGML_CUDA=OFF` GPU がない場合、または CPU 推論だけを使いたい場合。 **Apple Mac / Metal デバイスの場合**、次のように設定し `-DGGML_CUDA=OFF` その後は通常どおり続けてください。Metal サポートはデフォルトで有効です。

{% code overflow="wrap" %}

```bash
apt-get update
apt-get install pciutils build-essential cmake curl libcurl4-openssl-dev -y
git clone https://github.com/ggml-org/llama.cpp
cmake llama.cpp -B llama.cpp/build \
    -DBUILD_SHARED_LIBS=OFF -DGGML_CUDA=ON -DLLAMA_CURL=ON
cmake --build llama.cpp/build --config Release -j --clean-first --target llama-cli llama-mtmd-cli llama-server llama-gguf-split
cp llama.cpp/build/bin/llama-* llama.cpp
```

{% endcode %}

{% hint style="info" %}
使用する場合 `--jinja` llama-server は、ツールがサポートされている場合、次のシステムメッセージを追加します: `JSON 形式で応答し、tool_call（ツール呼び出しの要求）またはユーザーの要求に対する response reply のいずれかを返してください` 。このため、ファインチューニングで問題が発生することがあります！こちらを参照してください [llama.cpp リポジトリ](https://github.com/ggml-org/llama.cpp/blob/12ee1763a6f6130ce820a366d220bbadff54b818/common/chat.cpp#L849) 詳細について。
{% endhint %}

まず Devstral 2 をダウンロードします:

{% code overflow="wrap" %}

```python
# !pip install huggingface_hub hf_transfer
import os
os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"
from huggingface_hub import snapshot_download
snapshot_download(
    repo_id = "unsloth/Devstral-2-123B-Instruct-2512-GGUF",
    local_dir = "Devstral-2-123B-Instruct-2512-GGUF",
    allow_patterns = ["*UD-Q2_K_XL*", "*mmproj-F16*"],
)
```

{% endcode %}

Devstral 2 を本番環境向けにデプロイするには、次を使用します `llama-server` 新しい端末で、tmux 経由などで、以下を使ってモデルをデプロイします：

{% code overflow="wrap" %}

```bash
./llama.cpp/llama-server \\
    --model Devstral-Small-2-24B-Instruct-2512-GGUF/Devstral-Small-2-24B-Instruct-2512-UD-Q4_K_XL.gguf \
    --mmproj Devstral-Small-2-24B-Instruct-2512-GGUF/mmproj-F16.gguf \
    --alias "unsloth/Devstral-Small-2-24B-Instruct-2512" \
    --threads -1 \
    --n-gpu-layers 999 \
    --prio 3 \
    --min-p 0.01 \
    --ctx-size 16384 \\
    --port 8001 \\
    --jinja
```

{% endcode %}

上記を実行すると、次の結果になります:

<figure><img src="/files/6a1a068c15d3bf101a38942c8ac628404ba41d78" alt=""><figcaption></figcaption></figure>

その後、新しい端末で、 `pip install openai`を実行した後、次を行います：

{% code overflow="wrap" %}

```python
from openai import OpenAI
import json
openai_client = OpenAI(
    base_url = "http://127.0.0.1:8001/v1",
    api_key = "sk-no-key-required",
)
completion = openai_client.chat.completions.create(
    model = "unsloth/Devstral-Small-2-24B-Instruct-2512",
    messages = [{"role": "user", "content": "What is 2+2?"},],
)
print(completion.choices[0].message.content)
```

{% endcode %}

これは単純に 4 を表示します。\
\
llama-server の画面に戻ると、興味深い統計情報が表示されることがあります:

<figure><img src="/files/c43c02656b7a5b5dceb7ba2f30e2716665e074f9" alt=""><figcaption></figcaption></figure>

speculative decoding の使用などの引数については、こちらを参照してください <https://github.com/ggml-org/llama.cpp/blob/master/tools/server/README.md>

## :grey\_question:Llama-server の癖

* 使用する場合 `--jinja` llama-server は、ツールがサポートされている場合、次のシステムメッセージを追加します: `JSON 形式で応答し、tool_call（ツール呼び出しの要求）またはユーザーの要求に対する response reply のいずれかを返してください` 。このため、ファインチューニングで問題が発生することがあります！こちらを参照してください [llama.cpp リポジトリ](https://github.com/ggml-org/llama.cpp/blob/12ee1763a6f6130ce820a366d220bbadff54b818/common/chat.cpp#L849) 詳細はこちら。\
  \
  これを停止するには、次を使用します `--no-jinja` ただし、その場合 `ツール` はサポートされなくなります。\
  \
  たとえば、FunctionGemma はデフォルトで次を使用します:

  <pre class="language-notebook-python" data-overflow="wrap"><code class="lang-notebook-python">あなたは、次の関数で関数呼び出しができるモデルです
  </code></pre>

  しかし、llama-server が追加のメッセージを付け加えるため、次のようになります:

  <pre class="language-notebook-python" data-overflow="wrap"><code class="lang-notebook-python">あなたは、次の関数で関数呼び出しができるモデルです\n\nJSON 形式で応答し、`tool_call`（ツール呼び出しの要求）またはユーザーの要求に対する `response` reply のいずれかを返してください
  </code></pre>

  この問題を報告しました <https://github.com/ggml-org/llama.cpp/issues/18323> そして llama.cpp の開発者は修正に取り組んでいます！\
  \
  それまでの間、すべてのファインチューニングでは、ツール呼び出し専用のプロンプトを追加してください！

## :toolbox:llama-server でのツール呼び出し

参照： [Tool Calling Guide](/docs/jp/ji-ben/tool-calling-guide-for-local-llms.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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://unsloth.ai/docs/jp/ji-ben/inference-and-deployment/llama-server-and-openai-endpoint.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
