Files
myWiki/concepts/position-id-discrepancy.md

58 lines
1.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: "Position ID Discrepancy (位置 ID 偏差)"
created: 2025-06-02
updated: 2025-06-02
type: concept
tags: [position-encoding, multi-turn-reasoning, training]
sources: ["[[goru-one-pass-to-reason-2025]]"]
---
# Position ID Discrepancy
> 在多轮推理训练中,回复 token 在"生成时刻"与"作为上下文"两种场景下的位置不一致问题。
## 问题
考虑第 i 轮对话:
**生成时刻**(训练时的前向传播):
```
... hi-1, ri-1, hi, [ti, ri] ← ri 跟在 ti 后面
```
ri 的绝对位置:`length(H_{<i}) + |hi| + |ti|`
**作为上下文时刻**(后续轮次训练时):
```
... hi-1, ri-1, hi, ri, hi+1, ... ← ri 直接跟在 hi 后面ti 已丢弃
```
ri 的绝对位置:`length(H_{<i}) + |hi|`
同一 token 在不同场景中有不同的位置编码 → 如果不加处理,模型学到的位置关系是错的。
## 根本原因
这是 [[multi-turn-reasoning|多轮推理]] 的特有现象:
- 普通多轮对话没有推理 token → ri 的位置始终一致
- 推理对话中 ti 被丢弃 → ri 的位置在两种场景中不同
## One-Pass to Reason 的解决方案
通过 [[token-duplication]] + 策略性位置 ID 分配:
```python
s_ti = s_ri_in = e_hi + 1 # ti 和 ri_in 共享同一位置起点
s_ri_out = e_ti + 1 # ri_out 从 ti 之后开始(模拟生成场景)
s_h_{i+1} = e_ri_in + 1 # 下一轮从 ri_in 后开始(模拟上下文场景)
```
这个分配方案确保:
- ri_out 与 ti 的相对位置关系正确(模拟生成)
- 后续轮次看到的位置关系正确ri_in 在 hi 后,模拟上下文)
## 相关
- [[token-duplication]]
- [[multi-turn-reasoning]]
- [[position-encoding]]
- [[goru-one-pass-to-reason-2025|One-Pass to Reason 论文]]