> 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-chu/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="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fgit-blob-8c577103f7c4fe883cabaf35c8437307c6501686%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fgit-blob-1a1be852ca551240bdce47cf99e6ccd7d31c1326%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

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

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

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fgit-blob-24f9429ed4a8b3a630dc8f68dcf81555da0a80ee%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

その後、以下のようにファインチューニング済みモデルを llama.cpp の GGUF 形式へエクスポートします:

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fgit-blob-56991ea7e2685bb9905af9baf2f3f685123dcdd8%2Fimage%20(52).png?alt=media" 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="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fgit-blob-271b392fdafd0e7d01c525d7a11a97ee5c34b713%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fgit-blob-a554bd388fd0394dd8cdef85fd9d208bfd7feee7%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fgit-blob-e431609dfc5c742f0b5ab2388dbbd0d8e15c7670%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

### 自動 `Modelfile` 作成

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

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fgit-blob-6945ba10a2e25cfc198848c0e863001375c32c4c%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

その後、 `Modelfile`

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fgit-blob-d431a64613b39d913d1780c22cde37edc6564272%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

### Ollama 推論

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

<figure><img src="https://735611837-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2Fgit-blob-49b93efa192fdd741f3ac8484cef8c3fd7415283%2FInference.png?alt=media" 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 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/ji-chu/inference-and-deployment/saving-to-ollama.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.
