MMaDA icon indicating copy to clipboard operation
MMaDA copied to clipboard

About attention mask

Open Kaiwen-Zhu opened this issue 1 year ago • 2 comments

Thanks for your awesome work! However, I have questions about the attention mask. https://github.com/Gen-Verse/MMaDA/blob/b347cf3cbc8181631b358aa6d1922a9438c98949/models/modeling_mmada.py#L160-L162 The code above computes attention mask to prevent normal tokens from attending [PAD] tokens. However, it appears that the attention mask is NOT USED indeed (see this, attention_bias is not passed to _scaled_dot_product_attention). Is this intentional? Could this make training difficult and degrade the performance? Or do I misunderstand something?

PS: I am also confused about the implementation of attention_mask. The code above is in the loop of unmasking steps. The concatenation is conducted at each step, keeping increasing the first dimension of attention_mask. Is there any issue here?

Kaiwen-Zhu avatar Jun 06 '25 14:06 Kaiwen-Zhu

Hi, thanks for your attention. This was a bug and you can check this pr: https://github.com/Gen-Verse/MMaDA/pull/19, where I fix this bug.

However, we have not verified whether this fix will affect training so it's yet to be merged before we complete a training process to verify. You can use this pr in training and any outcomes are welcome to discuss!

tyfeld avatar Jun 06 '25 16:06 tyfeld

@tyfeld I find that attn_mask will significantly slow down the generation speed. In my experiments on an A800 GPU, generating a 512x512 image in 15 steps costs 4-5s when attn_mask=None, but when attn_mask is passed to F._scaled_dot_product_attention, the generation time will reach 10s. Do you know why? Is it possible to fix it?

Kaiwen-Zhu avatar Sep 04 '25 16:09 Kaiwen-Zhu