Absolute position indices
×Assigns an absolute position index to each token in the sequence.
- in
- [B batch, T positions]
- out
- [B batch, T positions]
Explanation
The helper reads only the batch size and the sequence length from the tokens, and tiles the same indices across the batch (model.py 141–144). counts positions already in the cache; a full-sequence pass has .
Sources
In codepositions_for(X, past_length)
Direct evidence
The position helper constructs indices from sequence length and past length; token values do not enter the calculation.
model.py 141–144 ↗ · openai/gpt-2 @ 9b63575ef427
Excerpt
def positions_for(tokens, past_length):
batch_size = tf.shape(tokens)[0]
nsteps = tf.shape(tokens)[1]
return expand_tile(past_length + tf.range(nsteps), batch_size)