Mask/tensor shape mismatch when using input flattening and Flash Attention 2
Author: marianrh-apaCreated Sep 24, 2026Updated Sep 24, 2026
Hi,
since upgrading Sentence Transformers I'm getting the error IndexError: The shape of the mask [32, 32] at index 0 does not match the shape of the indexed tensor [64, 2048] at index 0 when trying to train an embedding model using CachedGISTEmbedLoss and Flash Attention 2. The version I upgraded from (where everything still worked) was v5.3.0.
The stack trace points to this line.
The issue seems to be related to the input flattening feature introduced in v5.4.0, since the problem disappears when setting model[0].unpad_inputs = False.
The workaround works for me now, but it would be nice if I could make use of input flattening, of course.
Source: huggingface/sentence-transformers