Cuda: Decoder Masked Multihead Attention Q values get corrupted when using cross attention (#16721)

### Description
Some code was accidentally moved into the
`if(!params.is_cross_attention)' block, it must stay outside to work in
both cases.

### Motivation and Context
This causes invalid results. We detected this as a performance bug, as
it caused the EOS early exit to never happen, and the runs would always
take max_length to complete which was slow.
This commit is contained in:
Ryan Hill 2023-07-15 00:41:06 -07:00 committed by GitHub
parent 2b7a94e65b
commit 2cf31a20cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -179,6 +179,11 @@ __global__ void masked_multihead_attention_kernel(DecoderMaskedMultiHeadAttentio
const float inv_sqrt_dh = params.scale;
if (!is_masked) {
// Store the Q values to shared memory.
*reinterpret_cast<Qk_vec_k*>(&q_smem[tidx * QK_VEC_SIZE]) = q;
}
if (!params.is_cross_attention) {
Qk_vec_k k;
@ -241,9 +246,6 @@ __global__ void masked_multihead_attention_kernel(DecoderMaskedMultiHeadAttentio
}
if (!is_masked) {
// Store the Q values to shared memory.
*reinterpret_cast<Qk_vec_k*>(&q_smem[tidx * QK_VEC_SIZE]) = q;
// Write the K values to the global memory cache.
// NOTE: The stores are uncoalesced as we have multiple chunks of 16B spread across the memory
// system. We designed it this way as it allows much better memory loads (and there are many