> 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/saving-to-ollama.md).

# モデルをOllamaに保存

モデルを保存する方法の完全な手順については、以下のガイドをご覧ください [Ollama](https://github.com/ollama/ollama):

{% content-ref url="/pages/f46773a93603b1da44e6319f55fd3b900d7700fc" %}
[Tutorial: Finetune Llama-3 and Use In Ollama](/docs/jp/meru/fine-tuning-llms-guide/tutorial-how-to-finetune-llama-3-and-use-in-ollama.md)
{% endcontent-ref %}

### Google Colabでの保存

以下のように、ファインチューニングしたモデルを LoRA アダプタ と呼ばれる 100MB の小さなファイルとして保存できます。モデルをアップロードしたい場合は、代わりに Hugging Face Hub にプッシュすることもできます。Hugging Face トークンは以下から取得してください： <https://huggingface.co/settings/tokens> そしてトークンを追加してください！

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

モデルを保存した後は、再び Unsloth を使ってモデル自体を実行できます！ `FastLanguageModel` をもう一度使って推論を呼び出しましょう！

<figure><img src="/files/346616de5166da98e0faaf51576a79ebb1a572db" alt=""><figcaption></figcaption></figure>

### Ollama へのエクスポート

最後に、ファインチューニングしたモデルを Ollama 自体にエクスポートできます！ まず、Colab ノートブックに Ollama をインストールする必要があります：

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

次に、ファインチューニングしたモデルを以下のように llama.cpp の GGUF 形式にエクスポートします：

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

変換の注意 `False` を `True` にしてください。1行だけでよく、すべての行を `True`に変更しないでください。さもないと、かなり長い時間待つことになります！ 通常は最初の行を `True`に設定することをおすすめします。そうすれば、ファインチューニングしたモデルをすばやく `Q8_0` 形式（8ビット量子化）にエクスポートできます。また、量子化手法の一覧全体へのエクスポートも可能で、人気のあるものとして `q4_k_m`.

へアクセスしてください <https://github.com/ggml-org/llama.cpp> GGUF について詳しく知ることができます。GGUF への手動エクスポート方法についての手順も、必要であればこちらにあります： <https://github.com/unslothai/unsloth/wiki#manually-saving-to-gguf>

以下のような長いテキストの一覧が表示されますが、5〜10分お待ちください！！

<figure><img src="/files/5d662b28f425af8d1925925f6fc77f809f367a2c" alt=""><figcaption></figcaption></figure>

そして最後の最後には、以下のようになります：

<figure><img src="/files/22a36601d1e385efdacab33e8e2df11d181b7821" alt=""><figcaption></figcaption></figure>

次に、Ollama 自体をバックグラウンドで実行する必要があります。私たちは `subprocess` を使います。Colab は非同期呼び出しを好まないためですが、通常は単に `ollama serve` をターミナル／コマンドプロンプトで実行します。

<figure><img src="/files/9661f12f349ed855630594174e083bdf1a359a92" alt=""><figcaption></figcaption></figure>

### 自動 `Modelfile` 作成

Unsloth が提供する工夫は、必要な `Modelfile` を自動的に作成することです！ これは設定の一覧であり、ファインチューニング過程で使ったチャットテンプレートも含まれます！ また、以下のように `Modelfile` が生成されたものを表示することもできます：

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

次に、 `Modelfile`

<figure><img src="/files/23b91e3fcfe5156f1dcf8abcf2522b8e2abf835c" alt=""><figcaption></figcaption></figure>

### Ollama 推論

を使って、Ollama と互換性のあるモデルを作成するよう Ollama に依頼します。これで、必要であれば、ローカルマシン上、または無料の Colab ノートブックのバックグラウンドで動作している Ollama サーバー自体を呼び出して推論できます。黄色の下線部分は編集できることを忘れないでください。

<figure><img src="/files/3906fb6bd91704143a31a0d297f0c685a92cc785" alt=""><figcaption></figcaption></figure>

### Unsloth では正常に動作するのに、エクスポートして Ollama で実行すると結果が悪い

モデルは Unsloth 上では正常に動作して良い結果を出すのに、Ollama のような別のプラットフォームで使うと結果が悪かったり、文字化け、終わりのない／無限の生成が発生したりすることがあります *または* 繰り返し出&#x529B;**.**

* このエラーの最も一般的な原因は、 <mark style="background-color:blue;">**誤ったチャットテンプレート**</mark>**.** を使っていることです。Unsloth でモデルを学習させたときと、その後 llama.cpp や Ollama など別のフレームワークで実行するときに、同じチャットテンプレートを使うことが不可欠です。保存済みモデルから推論する場合、正しいテンプレートを適用することが重要です。
* 正しい `eos トークン`を使わなければなりません。そうしないと、長い生成で文字化けが起こることがあります。
* 推論エンジンが不要な「シーケンス開始」トークンを追加していること（あるいはその逆に、追加していないこと）も原因かもしれないので、両方の可能性を確認してください！
* <mark style="background-color:green;">**チャットテンプレートを強制するには、会話用ノートブックを使ってください。これでほとんどの問題は解決します。**</mark>
  * Qwen-3 14B 会話用ノートブック [**Colabで開く**](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Qwen3_\(14B\)-Reasoning-Conversational.ipynb)
  * Gemma-3 4B 会話用ノートブック [**Colabで開く**](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Gemma3_\(4B\).ipynb)
  * Llama-3.2 3B 会話用ノートブック [**Colabで開く**](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Llama3.2_\(1B_and_3B\)-Conversational.ipynb)
  * Phi-4 14B 会話用ノートブック [**Colabで開く**](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Phi_4-Conversational.ipynb)
  * Mistral v0.3 7B 会話用ノートブック [**Colabで開く**](https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Mistral_v0.3_\(7B\)-Conversational.ipynb)
  * **さらに多くのノートブックは、こちらの** [**ノートブックのドキュメント**](/docs/jp/meru/unsloth-notebooks.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/saving-to-ollama.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.
