Repository navigation
Keep rotary angles in float32 after model dtype conversion - #2173
sylvesterkaczmarek wants to merge 2 commits into
Conversation
Signed-off-by: Sylvester Kaczmarek <[email protected]>
|
Reproduced this on
So in the second half of every training sequence, groups of ~4 neighbouring tokens get the same rotary angle. Not fatal, since the causal mask still separates them, but it's a real handicap for a baseline. Some context that might help review: I grepped |
|
Thanks for independently reproducing this and checking the record scripts. I added the README note you suggested: the precision correction can change future baseline runs, while archived submissions and scores remain unchanged. The 18 rotary tests still pass, and the combined baseline-fix checkout passed 121 CPU tests across PyTorch and MLX. I have not measured a GPU training or leaderboard improvement. |
Problem
The baseline converts the model to bfloat16, including Rotary's floating inverse-frequency buffer. Rotary then creates its position sequence in that buffer's dtype. Positions 256 and 257 become identical, and frequency rounding introduces further angular error.
A CPU reproduction is
Rotary(64).bfloat16()(1024, torch.device("cpu"), torch.float32): positions 256 and 257 have identical cosine and sine tables. The maximum cosine difference from the float32 construction is approximately 1.9684.Change
Keep nonpersistent integer frequency indices and construct inverse frequencies and positions explicitly in float32 whenever the cache is rebuilt. The integer buffer still follows device moves but survives model dtype conversion. Cache reuse, requested output dtype, and checkpoint keys are preserved. The baseline remains under its 1,500-line limit.
PyTorch documents the reduced-precision/repeated-value risk in torch.arange.
Validation
torch.compile(backend="eager"), including cache rebuilds at different sequence lengths.git diff --checkpass.Python 3.12.14 and PyTorch 2.14.1 on macOS arm64. No model or dataset downloads, CUDA kernels, distributed training, or benchmark runs were used. Graph capture does not establish CUDA/Inductor performance. This changes future baseline calculations; it does not modify archived submissions or claim a leaderboard improvement.
Reproduced against
f5c079314c4877fbb0af378c0abade5a8ca33d3a.Maintenance validation on 6 November 2026
Added a README note explaining that float32 rotary calculations can change future baseline training results while archived submissions and scores remain unchanged. This addresses the independent reproduction and documentation suggestion in the discussion.
Focused validation at
2a107cbe4b48: 18 CPU tests passed. The combined six-PR checkout passed 121 tests, including the actual PyTorch and MLX CPU implementations. The two baseline scripts remain below 1,500 lines; archived record scripts were not modified.Python 3.12.14, PyTorch 2.15.0 and SentencePiece 0.2.3 on macOS arm64. Tests used synthetic inputs with external sockets disabled. No pretrained checkpoint, external dataset, GPU training, full validation benchmark or leaderboard measurement was used. There are no hosted test runs on these PR heads. Earlier validation counts above are historical.