Model and Inference EngineeringTransformer and model mechanicsPrincipal
How should a checkpoint conversion preserve rotary-position coordinate pairing?
By Amit Kumar3 min readWorked answer includedReviewed 28 Sept 2026
The question
Interview question
A converted model loads, produces fluent short text and has correctly shaped query/key tensors, but longer prompts regress. Projection bytes were copied while the destination uses a different rotary-coordinate convention. Explain the required layout conversion and design pre/post-rotation parity checks at multiple positions and cached decode steps.
Draft your approach first
Take a few minutes before you read the answer. Name the constraint that matters most, the failure you are designing for and how you would know it worked.
Reveal the worked answerWorked answer
Rotary position embedding (RoPE) rotates pairs of coordinates in each attention head by an angle determined by position. Implementations can lay out those paired coordinates differently. One may pair adjacent coordinates. Another may pair corresponding coordinates from two halves of the head. A conversion that changes the layout of activations must permute the corresponding Q and K projection rows, or use a rotary kernel matching the original layout. Copying bytes into an identically shaped tensor is not enough. Hugging Face's weight conversion documentation explicitly has a PermuteForRope operation for this kind of conversion.
For a hypothetical four-coordinate vector (1,2,3,4), rotate both pairs by 90 degrees solely to illustrate layout. Adjacent pairing gives (-2, 1, -4, 3), while pairing coordinates from opposite halves gives (-3, -4, 1, 2). Both are well-shaped vectors. To represent the same model, projection layout and rotation convention must agree through the appropriate permutation. Real RoPE uses position-dependent frequencies, so this is a layout example rather than a checkpoint recipe.
I would choose a fixed token sequence and compare source and destination implementations layer by layer, before looking at generated prose. First compare the unrotated Q and K in a common coordinate convention. Then compare rotated Q and K at positions zero, one and a much later position. Finally compare per-head attention logits, outputs and the next-token logits. At position zero some errors can be less visible, so a one-token smoke test can give false comfort. Use deliberately different values in every coordinate and head. A fixture with repeated values can hide a permutation.
The exact conversion depends on the architecture, rotary dimension, head layout, tensor-parallel slicing and any fused QKV representation. V does not get the same rotary permutation merely because it sits next to Q and K in a fused tensor. Likewise, changing the frequency base or position IDs is a separate possible fault. If Q/K parity holds before rotation and diverges after it, inspect the kernel and position handling. If it already diverges before rotation, inspect the projection weight conversion. This gives a fault boundary instead of guessing from a benchmark score.
What if the converted model passes a perplexity check? I would ask which lengths and whether the source and destination were evaluated on identical token IDs and masks. Put logit parity tests at several positions and across a cached decode step into the release gate. A small numerical tolerance is reasonable across kernels, but a systematic head-coordinate permutation is not numerical noise. The GQA cache has the right shape. Why do answers change after tensor parallel reshaping? is about mapping query heads to KV heads after reshaping. Here the head mapping can be correct while the coordinate pairing inside each head is wrong.
Related questions
Keep practising model and inference engineering
Follow another question in this area, or search the complete library.
Get my essays on AI engineering and distributed systems by email. Subscribe to ArchCrux