RoPE Position Indices Must Ignore Padding Tokens
Rotary position embeddings encode token position by rotating query and key coordinates with an angle determined by an integer position index. That index is part of the model input semantics even when it is generated inside a framework wrapper. In a padded decoder batch, using the physical tensor column as the position can therefore change logits for a sequence that has not changed textually. The issue is distinct from attention masking. A mask can stop valid tokens from attending to padding while the valid tokens still receive shifted rotary coordinates. Correct masking and correct position assignment solve separate problems.