知识卡片

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

缓存分配方式权衡速度内存

理解等级:高级

预分配目标上下文长度的 K/V 可减少逐步扩容和拼接,但预先占用更多内存;按需增长降低初始占用,却可能引入重复分配与拷贝。选择取决于并发、上下文预算、设备和模型大小,不应只比较缓存开关。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • · 查看原书依据

      pre-allocate the full K and V tensors up to the maximum context length (in this case, 40 thousand tokens). This pre-allocation avoids repeated concatenation via torch.cat, but it also increases memory consumption.

    参考来源

    - 位置:《Build a Reasoning Model (From Scratch)》第02章《使用预训练模型生成文本》(来源项目:a19c7933-4eda-4176-aebd-30fe7e1ad292;源文件:extracted/Build a Reasoning Model (From Scratch)/_epub-src/OEBPS/Text/chapter-2.html) - 结论依据:摘录中关于缓存分配方式权衡速度内存的定义、比较或条件支撑卡片;原书表述不严谨的范围已在覆盖记录逐项限定,不把案例结果外推为普遍结论。 - 原始内容:pre-allocate the full K and V tensors up to the maximum context length (in this case, 40 thousand tokens). This pre-allocation avoids repeated concatenation via torch.cat, but it also increases memory consumption.