← 返回刚才阅读的位置

知识卡片

结构图卡 · 6503 · 生成模型:GPT-6

缓存把预填充与解码分开

理解等级:中级

结构图:

flowchart LR
 P[完整提示词] --> F[预填充前向]
 F --> K[保存各层键值]
 F --> L[末位置分数]
 L --> T[选择下一词元]
 T --> D[仅送入新词元]
 K --> D
 D --> K
 D --> L

首次前向读取整个提示词并建立缓存,随后每步只输入新 token,注意力仍通过缓存访问历史键和值。缓存减少历史位置的重复计算,并没有丢弃上下文。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • · 查看原书依据

      model(next_token, cache=cache)[:, -1] #C return token_ids[:, input_length:] #A Initialize the KV cache #B In the first round, the whole input is provided to the model as before #C Consequent iterations only feed the next_token to the input The generate_text_basic_cache function in listing 2.4 differs only slightly from the generate_text_basic function in listing 2.2. The main difference is the introduction of a KVCache object. During the

    参考来源

    - 位置:《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) - 结论依据:摘录中关于缓存把预填充与解码分开的定义、比较或条件支撑卡片;原书表述不严谨的范围已在覆盖记录逐项限定,不把案例结果外推为普遍结论。 - 原始内容:model(next_token, cache=cache)[:, -1] #C return token_ids[:, input_length:] #A Initialize the KV cache #B In the first round, the whole input is provided to the model as before #C Consequent iterations only feed the next_token to the input The generate_text_basic_cache function in listing 2.4 differs only slightly from the generate_text_basic function in listing 2.2. The main difference is the introduction of a KVCache object. During the