Skip to content

fix: align causal mask bias with attention mask value - #108

Open
dajiaohuang wants to merge 1 commit into
salesforce:mainfrom
dajiaohuang:fix/attention-mask-values
Open

dajiaohuang wants to merge 1 commit into
salesforce:mainfrom
dajiaohuang:fix/attention-mask-values

Conversation

@dajiaohuang

Copy link
Copy Markdown

Summary

Fix inconsistent mask values in CodeGenAttention that cause pre-softmax attention score discrepancies between causally masked tokens and padded tokens.

Problem

In modeling_codegen.py:

  • Line 74: masked_bias = -1e9 (used for causal mask)
  • Line 439: attention_mask = (1.0 - attention_mask) * -10000.0 (used for padding mask)

These use different large negative values (-1e9 vs -10000), causing inconsistent pre-softmax attention scores as noted in issue #49.

Fix

Change masked_bias from -1e9 to -1e4 to match the -10000.0 value used in attention mask processing.

Testing

The change aligns the two mask values, ensuring consistent behavior during inference when both causal masking and padding are present.

Fixes #49

Use -1e4 instead of -1e9 for masked_bias to match the -10000.0
value used in attention_mask processing, ensuring consistent
pre-softmax attention scores for causally masked and padded tokens.

Fixes salesforce#49
@salesforce-cla

Copy link
Copy Markdown

Thanks for the contribution! Unfortunately we can't verify the commit author(s): RepoStew Worker <w***@.repo>. One possible solution is to add that email to your GitHub account. Alternatively you can change your commits to another email and force push the change. After getting your commits associated with your GitHub account, sign the Salesforce Inc. Contributor License Agreement and this Pull Request will be revalidated.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mismatch in attention weights for causal masked tokens vs attention masked tokens

1 participant