Skip to content

RoPE and attention mask mismatch #120

Description

@probablyabot

When doing inference with prompts of different length, having an attention mask is super useful so that model outputs are invariant to padding/batch size. Normally I expect that the model's answer to a question shouldn't change if I add pad tokens or batch it with another question, which is true for normal (autoregressive) LLMs.

For LLaDA, while the authors have recently added support for an attention_mask argument in model.forward(), which correctly masks out any padding tokens from the attention computation, there is still an issue with RoPE that causes the output to depend on batching/padding.

Since the RoPE module uses inferred positions based on only the tensor shape, adding pad tokens on the left (even with a proper attention mask) will shift all the subsequent positions, causing the qk vectors to change.

I think the RoPE module should accept a position_ids argument that allows it to ignore any pad tokens. This along with the attention mask will make the behavior deterministic regardless of padding.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions