← 返回刚才阅读的位置

知识卡片

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

归一化统计可提高计算精度

理解等级:高级

本章兼容实现先把输入转换为 float32 计算均方和倒平方根,再缩放并转回原类型。这是在内部统计稳定性与输出存储成本间做选择;变量名 variance 此处实际代表均方值,不是去均值的方差。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • · 查看原书依据

      x = x.to(torch.float32) variance = x.pow(2).mean(dim=-1, keepdim=True) norm_x = x * torch.rsqrt(variance + self.eps) norm_x = norm_x * self.scale if self.shift is not None: norm_x = norm_x + self.shift return norm_x.to(input_dtype) Note that, for brevity, this appendix does not provide detailed code walkthroughs for each LLM component. Instead, in section C.6, we will integrate all components into the Qwen3Model class, load the pre-trained weights into

    参考来源

    - 位置:《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) - 结论依据:摘录中关于归一化统计可提高计算精度的定义、比较或条件支撑卡片;原书表述不严谨的范围已在覆盖记录逐项限定,不把案例结果外推为普遍结论。 - 原始内容:x = x.to(torch.float32) variance = x.pow(2).mean(dim=-1, keepdim=True) norm_x = x * torch.rsqrt(variance + self.eps) norm_x = norm_x * self.scale if self.shift is not None: norm_x = norm_x + self.shift return norm_x.to(input_dtype) Note that, for brevity, this appendix does not provide detailed code walkthroughs for each LLM component. Instead, in section C.6, we will integrate all components into the Qwen3Model class, load the pre-trained weights into