知识卡片
零温度是解码分支约定
本章生成器把 temperature=0 或 None 显式路由到贪心选择,而不是执行除以零。缩放函数本身要求正温度。实现接口时应区分数学定义与特殊值协议,并检查负值、非有限值等无效输入。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
- · 推理时计算扩展
原书出处 · 1 处
- · 查看原书依据
if temperature is None or temperature == 0.0: next_token = torch.argmax(out, dim=-1, keepdim=True) else: logits = scale_logits_by_temperature(out, temperature) #B probas = torch.softmax(logits, dim=-1) #C next_token = torch.multinomial(probas.cpu(), num_samples=1) #D next_token = next_token.to(orig_device) ######################################### if (eos_token_id is not None and next_token.item() == eos_token_id): break yield next_token out = model(next_token, cache=cache)[:, -1] #A Step 3.1: Get logits #B Step 3.2: Apply temperature scaling on logits #C Step
参考来源
- 位置:《Build a Reasoning Model (From Scratch)》第04章《推理时计算扩展》(来源项目:a19c7933-4eda-4176-aebd-30fe7e1ad292;源文件:extracted/Build a Reasoning Model (From Scratch)/_epub-src/OEBPS/Text/chapter-4.html)
- 结论依据:摘录中关于零温度是解码分支约定的定义、比较或条件支撑卡片;原书表述不严谨的范围已在覆盖记录逐项限定,不把案例结果外推为普遍结论。
- 原始内容:if temperature is None or temperature == 0.0: next_token = torch.argmax(out, dim=-1, keepdim=True) else: logits = scale_logits_by_temperature(out, temperature) #B probas = torch.softmax(logits, dim=-1) #C next_token = torch.multinomial(probas.cpu(), num_samples=1) #D next_token = next_token.to(orig_device) ######################################### if (eos_token_id is not None and next_token.item() == eos_token_id): break yield next_token out = model(next_token, cache=cache)[:, -1] #A Step 3.1: Get logits #B Step 3.2: Apply temperature scaling on logits #C Step