← 返回刚才阅读的位置

知识卡片

普通读书笔记卡 · 6516.d · 生成模型:GPT-6

因果遮罩对齐缓存与新词

理解等级:高级

预填充的遮罩形状可为[T,T],已有K个历史键、输入T个新token时则需[T,K+T],每个新位置只看到历史与自身之前。广播批次和头维并不能替代位置对齐;错误遮罩会泄漏未来或屏蔽有效历史。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • · 查看原书依据

      = self.final_norm(x) logits = self.out_head(x.to(self.cfg["dtype"])) return logits def reset_kv_cache(self): self.current_pos = 0 #A Prefill: Shape (1, 1, T, T) to broadcast across batch and heads. Cached: Shape (1, 1, T, K+T) where T=new tokens, K=cached keys. Since we already have all the main ingredients, the Qwen3Model class in listing C.6 only adds a few more components around the transformer block, namely the embedding and output

    参考来源

    - 位置:《Build a Reasoning Model (From Scratch)》第09章《附录C Qwen3模型源码》(来源项目:a19c7933-4eda-4176-aebd-30fe7e1ad292;源文件:extracted/Build a Reasoning Model (From Scratch)/_epub-src/OEBPS/Text/appendix-c.html) - 结论依据:摘录中关于因果遮罩对齐缓存与新词的定义、比较或条件支撑卡片;原书表述不严谨的范围已在覆盖记录逐项限定,不把案例结果外推为普遍结论。 - 原始内容:= self.final_norm(x) logits = self.out_head(x.to(self.cfg["dtype"])) return logits def reset_kv_cache(self): self.current_pos = 0 #A Prefill: Shape (1, 1, T, T) to broadcast across batch and heads. Cached: Shape (1, 1, T, K+T) where T=new tokens, K=cached keys. Since we already have all the main ingredients, the Qwen3Model class in listing C.6 only adds a few more components around the transformer block, namely the embedding and output