Avoid float32 copies of q / k in the RoPE helpers (#15215)
* Avoid float32 copies of the input in apply_rotary_emb
`x.float() * cos + x_rotated.float() * sin` materializes float32 copies of
x and x_rotated. With float32 cos / sin, type promotion already computes
the products in float32, so drop the explicit casts. Bit-identical output.
Signed-off-by: Lin, KuanTing <Kuanting.Lin@amd.com>
* Drop the float32 copies in the model-local RoPE helpers too
Same change as in apply_rotary_emb, applied to the helpers that repeat the
`x.float() * cos + x_rotated.float() * sin` expression: LTX, LTX-2, QwenImage,
LongCat-AudioDiT, JoyImage, JoyImage-Edit-Plus and Allegro (plus the
`# Copied from` copies in QwenImage 2.1, NucleusMoE and the SANA-WM refiner,
synced with `make fix-copies`). Bit-identical output.
Signed-off-by: Lin, KuanTing <Kuanting.Lin@amd.com>
* Test apply_rotary_emb against the float32 reference
Checks that apply_rotary_emb matches the explicit float32 formula bit for bit
for fp32 / fp16 / bf16 inputs, both use_real_unbind_dim values and both
sequence_dim values.
Signed-off-by: Lin, KuanTing <Kuanting.Lin@amd.com>
* Use one comment for the RoPE type-promotion casts and drop the unit test
Address review: the same comment at every call site, and remove the
apply_rotary_emb test from test_layers_utils.py.
Signed-off-by: Lin, KuanTing <Kuanting.Lin@amd.com>
---------
Signed-off-by: Lin, KuanTing <Kuanting.Lin@amd.com>