# 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">あなたは、次の関数を使って function calling を実行できるモデルです
  </code></pre>

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

  <pre class="language-notebook-python" data-overflow="wrap"><code class="lang-notebook-python">あなたは、次の関数を使って function calling を実行できるモデルです\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: 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.
