You now have all the moving parts of the input pipeline. Let's assemble them.
- Tokenization. Raw text → token IDs. Frozen at training time, must be the model's tokenizer.
- Embedding lookup. Token IDs → dense vectors via emb.weight[ids]. Output shape (seq_len, d_model).
- Position injection. One of:
- Add sinusoidal PE to the embedding (original Transformer).
- Add learned positional embeddings to the embedding (BERT, GPT-2).
- Apply RoPE to Q and K inside attention; embedding is unchanged at the input (Llama, Mistral, Qwen).
- Apply ALiBi bias to attention scores; embedding is unchanged at the input (BLOOM, MPT).
- Layer-norm and dropout (optional). Some models normalize and apply dropout to the input embedding before the first block.
- The result enters the first Transformer block.
The key conceptual point: position is information and the architecture chooses where to insert it. There is no neutral choice. RoPE is currently winning, but the rest of the architecture is independent of which scheme you pick — you can swap RoPE for ALiBi in any modern decoder-only Transformer with a few hundred lines of code change.