transformers
d779f6c1 - Flash attention: keep every query in non-causal cross-attention with padded keys (#51280)

Commit
5 hours ago
Flash attention: keep every query in non-causal cross-attention with padded keys (#51280) * Flash attention: keep every query in non-causal cross-attention over padded keys _upad_input unpadded the queries with the last query_length entries of the key mask, which assumes the queries are the last positions of the keys (decoder layout). In a non-causal cross-attention (encoder-decoder cross attention, resamplers) the key mask says nothing about the queries, so the queries of sequences with right-padded keys were dropped and their outputs zeroed. Keep all queries in that case; causal attention is unchanged. * Update src/transformers/modeling_flash_attention_utils.py Co-authored-by: Anton Vlasjuk <73884904+vasqu@users.noreply.github.com> * Update src/transformers/modeling_flash_attention_utils.py Co-authored-by: Anton Vlasjuk <73884904+vasqu@users.noreply.github.com> * Move is_causal last in the _upad_input docstring * Remove the standalone _upad_input test * Test _upad_input keeps all queries for non-causal cross-attention --------- Co-authored-by: Ariyan Bhakat <221930089+arywk40-hue@users.noreply.github.com> Co-authored-by: Anton Vlasjuk <73884904+vasqu@users.noreply.github.com>
Author
Parents
Loading