知识卡片
采样无需图而评分需要图
采样离散 token 时可关闭梯度以降低资源;随后用当前参数重新前向计算选中 token 的 logprob,保留计算图供反向传播。no_grad 与 eval 职责不同,eval 不会自动关闭梯度;采样阶段的 detached 分数不能直接承担训练梯度。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- · 查看原书依据
from listing 6.2 to generate the rollouts. When we defined that function earlier, though, we decorated it with @inference_mode, which disables several PyTorch features for efficiency. Since we will later perform a backward pass, this makes the function incompatible with our training setup. Instead, we need to use the @torch.no_grad decorator, which disables gradient tracking for the forward pass without switching PyTorch into inference-only mode.
参考来源
- 位置:《Build a Reasoning Model (From Scratch)》第06章《强化学习训练推理模型》(来源项目:a19c7933-4eda-4176-aebd-30fe7e1ad292;源文件:extracted/Build a Reasoning Model (From Scratch)/_epub-src/OEBPS/Text/chapter-6.html)
- 结论依据:摘录中关于采样无需图而评分需要图的定义、比较或条件支撑卡片;原书表述不严谨的范围已在覆盖记录逐项限定,不把案例结果外推为普遍结论。
- 原始内容:from listing 6.2 to generate the rollouts. When we defined that function earlier, though, we decorated it with @inference_mode, which disables several PyTorch features for efficiency. Since we will later perform a backward pass, this makes the function incompatible with our training setup. Instead, we need to use the @torch.no_grad decorator, which disables gradient tracking for the forward pass without switching PyTorch into inference-only mode.