# 本章小结

**自回归解码**通过逐步生成词元来构建完整文本，核心问题是如何从模型输出的概率分布中选择词元。

**贪心搜索**简单高效但容易陷入局部最优；**束搜索**通过多路探索保留更高概率候选，但仍是固定宽度的启发式近似，在开放式任务中过于保守。

**温度**控制分布的尖锐程度（模型的“创造力”水平），**Top-k** 限制候选范围但阈值固定，\*\*Top-p（Nucleus 采样）\*\*通过自适应阈值在多样性和质量之间取得了最佳平衡。实际应用中这些策略常组合使用。

**约束解码**通过在解码过程中施加语法规则，确保输出满足结构化格式要求（如合法 JSON），是 LLM 与外部系统集成的关键技术。

**推理时计算扩展**从解码角度体现为更长的单路径生成、多路采样/选择、搜索和外部验证。更完整的长思维链训练、过程奖励模型和强化学习推理系统放在 [14.6 节](/llm_internals/di-si-bu-fen-mo-xing-yu-qian-yan-pian/14_future_trends/14.6_test_time_scaling.md) 讨论。

下一章将讨论推理阶段的性能优化——如何让模型更快、更省资源地生成高质量文本。

***

> 📝 **发现错误或有改进建议？** 欢迎提交 [Issue](https://github.com/yeasy/llm_internals/issues) 或 [PR](https://github.com/yeasy/llm_internals/pulls)。


---

# 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://yeasy.gitbook.io/llm_internals/di-san-bu-fen-tui-li-yu-bu-shu-pian/09_decoding/summary.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.
