> 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/zh/ji-chu-zhi-shi/inference-and-deployment/troubleshooting-inference.md).

# 推理故障排除

如果你在运行或保存模型时遇到问题。

### 在 Unsloth 中运行效果很好，但导出并在其他平台上运行后，结果很差

你有时可能会遇到这样的问题：你的模型在 Unsloth 上运行并产生良好结果，但当你在 Ollama 或 vLLM 等其他平台上使用它时，结果很差，或者可能会得到胡言乱语、无尽/无限生成 *或* 重复输&#x51FA;**.**

* 这种错误最常见的原因是使用了 <mark style="background-color:blue;">**不正确的聊天模板**</mark>**.** 至关重要的是，要使用与在 Unsloth 中训练模型时相同的聊天模板，并在之后于其他框架中运行时也保持一致，例如 llama.cpp 或 Ollama。从已保存的模型进行推理时，应用正确的模板非常关键。
* 您必须使用正确的 `eos token`。否则，长文本生成时可能会出现乱码。
* 也可能是因为您的推理引擎添加了一个不必要的“序列开始”token（反之亦然，即缺少它），因此请确保检查这两种可能性！
* <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)
  * **更多笔记本请见我们的** [**notebooks 仓库**](https://github.com/unslothai/notebooks)**.**

### 保存到 `safetensors`，而不是 `bin` Colab 中的格式

我们保存为 `.bin` 在 Colab 中，这样快约 4 倍，但请设置 `safe_serialization = None` 以强制保存为 `.safetensors`。因此 `model.save_pretrained(..., safe_serialization = None)` 或 `model.push_to_hub(..., safe_serialization = None)`

### 如果保存为 GGUF 或 vLLM 16 位时崩溃

你可以尝试通过修改以下设置来降低保存期间的最大 GPU 使用量 `maximum_memory_usage`.

默认值为 `model.save_pretrained(..., maximum_memory_usage = 0.75)`。例如将其降低到 0.5，以使用 GPU 峰值内存的 50% 或更少。这可以减少保存期间的 OOM 崩溃。


---

# 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/zh/ji-chu-zhi-shi/inference-and-deployment/troubleshooting-inference.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.
