transformers
45729398 - Make the SDPA position_bias mask contiguous so T5-style models use fused kernels (#49517)

Commit
40 days ago
Make the SDPA position_bias mask contiguous so T5-style models use fused kernels (#49517) * Make T5-style compute_bias return a contiguous position_bias compute_bias returns values.permute([2, 0, 1]).unsqueeze(0), a non-contiguous view. Since #47014 it is passed to scaled_dot_product_attention as attn_mask, fused kernels reject it (mask stride(-1) != 1), and SDPA falls back to MATH. Add .contiguous() to that line in t5, mt5, pop2piano, udop, longt5, switch_transformers, umt5 and pix2struct. Values are unchanged; only the memory layout changes. Fixes #49516 * Revert "Make T5-style compute_bias return a contiguous position_bias" This reverts commit c8ba553997b22e6f433304572a8ba00d754414bd. * Make the sdpa position_bias mask contiguous T5-style compute_bias returns values.permute([2, 0, 1]).unsqueeze(0), a non-contiguous view. create_position_bias_mask passes it on as the attn_mask, fused sdpa kernels reject it (mask stride(-1) != 1), and SDPA falls back to MATH. Call .contiguous() once in create_position_bias_mask instead of in each model's compute_bias, as suggested in review. Values are unchanged; only the memory layout changes. Fixes #49516 * Add a test that the sdpa position_bias mask stays on a fused kernel Restrict SDPA to EFFICIENT_ATTENTION (no math fallback) and call sdpa_attention_forward with a T5-layout position_bias (stride(-1) == num_heads), over the create_position_bias_mask branches T5-style models take: no mask, causal, and bool mask. Without the .contiguous() fix the call raises "No available kernel"; with it the call succeeds. Checked on AMD Radeon 8060S and NVIDIA GeForce RTX 5090. * Reference issue #49516 in the position_bias sdpa test
Author
Parents
Loading