Compare and Audit Position Methods

Compare methods by where they enter the computation, which parameters they add, which indices they can represent, and what evidence supports longer contexts. Audit IDs, padding, masks, rotations, biases, and caches for silent errors.

Position methods differ first in where they enter the computation. A useful comparison starts there instead of asking which method is universally best.

MethodWhere position entersLearned position entriesPairwise distance enters directly?
Learned absoluteadded to token representationLmaxdmodelL_{max}d_{model}no
Sinusoidaladded to token representation0indirectly through fixed frequency pairs
Shaw-style relativescore and optionally value interactionrelation-table dependentyes
RoPErotations of query and key pairs0 in the original frequency scheduleyes, in query-key dot products
ALiBiadditive attention-score bias0 in the original fixed slope scheduleyes

This table describes the versions taught in this chapter. Later variants may learn frequencies, rescale indices, bucket offsets, rotate only part of a head, or combine methods.

Four Questions for Every Method

1. What is the index convention?

State whether positions begin at 0, how left or right padding affects IDs, how special tokens are counted, and whether the key-minus-query or query-minus-key offset is used.

2. Where is the operation applied?

Adding a model-width vector, rotating Q/K pairs, adding a score bias, and altering values produce different functions. A matching final shape cannot prove that the operation was placed correctly.

3. What range can the implementation represent?

A learned table has a finite row range. A formula can calculate new indices, but numerical precision or a configured cache may impose other limits. This question concerns execution, not trained-model quality.

4. What evidence supports behavior outside the training range?

Report training length, evaluation lengths, model, data, metric, baselines, and any interpolation or scaling procedure. One perplexity comparison does not establish every long-context capability.

Interpolation and Extrapolation Are Different

  • Interpolation evaluates positions within the range represented during training, even if a particular sequence length was not observed.
  • Extrapolation evaluates positions or lengths beyond the training range.

Some context-extension methods rescale large inference indices into a smaller effective range. That is an interpolation strategy applied to position values, not unchanged extrapolation. Chapter 10 will compare such variants after the base mechanisms are established.

A Position Audit

For one fixed token batch, record:

  1. token IDs and padding locations;
  2. position IDs for every non-padding token;
  3. causal and padding masks separately;
  4. token and position vectors before addition, if used;
  5. unrotated and rotated Q/K pairs, if used;
  6. content scores and position biases separately;
  7. the combined score tensor before softmax;
  8. selected normalized rows and forbidden zeros;
  9. cached and uncached logits under identical position IDs;
  10. behavior at the largest trained and evaluated indices.

Valid Shapes Can Hide Position Errors

Common silent failures include:

FailureWhy shape checks passDirect evidence
left-padded tokens receive shifted IDs at evaluation onlyID tensor retains (B,T)(B,T)print token-to-position mapping
RoPE pairing convention changesQ and K retain their widthscompare selected rotated coordinates and logits
key offset uses iji-j instead of jij-irelation lookup still returns a vectortest asymmetric signed offsets
cached decode restarts the next token at 0cache and logits retain expected shapescompare cached and full-prefix logits
ALiBi slopes attach to different headsscore tensor retains (B,h,T,T)(B,h,T,T)log per-head bias rows

Q1. Diagnose a cached position error

Full-prefix decoding assigns positions [0,1,2,3][0,1,2,3] to four tokens. Cached decoding stores the first three keys correctly but assigns the fourth token position 0. Tensor shapes and cache length are correct, but logits differ. Which check most directly identifies the error?

Choose one

Select one choice, then check.

Hint
Ask which invariant cached and uncached execution must share before their logits can agree.
Solution
Compare the actual position IDs and selected Q/K transformations. The fourth token must use position 3 in both paths.
Not attempted
Review

Not marked done.

Choose by Requirements and Evidence

A position method is part of an architecture contract. Choose or evaluate it using the required context, training setup, memory and parameter constraints, cache behavior, available evidence, and reproducibility of its conventions. Method names alone are not enough.

Pause and reflect

In your own words, note what you understood, what remains unclear, or what you want to revisit. The note stays with this lesson.

0 of 1 exercises marked done

Review

Not marked done.