RoPE constants
BF16
rope.freq_bf16:
- shape:
[1, 4096, 64], 4096 denotes maximum sequence length, 64 is half of the head dimension (128/2=64) - each element is $m \theta_i$ where $m$ is the position id, $i$ is the head dimension index.
rope.cos_bf16: cos_bf16 = cos(freq_bf16)
rope.sin_bf16: sin_bf16 = sin(freq_bf16)
FP32 for reference
HuggingFace forces the RoPE constants to be in FP32 format because both BF16 and FP16 introduce errors in the output cos and sin values. For example, BF16 cannot represent the exact value of 4088, 4089, ..., 4095 (all these values are rounded to 4096). This issue discusses this problem.
Therefore, we also provide the FP32 version of the RoPE constants for reference. This assumes all the constants are computed in FP32 format.
rope.freq_fp32rope.cos_fp32rope.sin_fp32