diff --git a/tensorrt_llm/functional.py b/tensorrt_llm/functional.py index f39b6eac7a03..4258696f2c83 100644 --- a/tensorrt_llm/functional.py +++ b/tensorrt_llm/functional.py @@ -264,8 +264,16 @@ def create_sinusoidal_positions_for_attention_plugin( # Other scaling configs that only used by certain scaling types. rope_scaling_config: dict = None, duplicate_data: bool = False, - dtype=np.float32, ): + # The rotary table dtype is pinned to fp32 and is intentionally not a caller + # argument. inv_freq and the positions are built at this dtype, so the stored + # angle (position * inv_freq) accumulates the fp32 rounding of inv_freq -- an + # error that is invisible in short contexts but grows ~linearly with position + # (about a milliradian at 32k). Reference implementations also round inv_freq + # to fp32, and building in fp64 was measured and deliberately not adopted (it + # removes one side of a two-sided rounding difference rather than improving + # agreement). Change this only with a re-measurement. + dtype = np.float32 if scale_type == RotaryScalingType.linear: scale = 1.0 / scale if scale_type == RotaryScalingType.llama3: