Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

attention_mask fill with -inf for UnfusedDotProductAttention #1268

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Agoniii
Copy link

@Agoniii Agoniii commented Oct 18, 2024

Description

UnfusedDotProductAttention in TE uses -10000 to fill in the attention mask, but the value is not small enough for some cases which leads to large diff between TE and HF.

The logits of model forward with FP32.
HF baseline:

logits: tensor([[[-0.6598, -4.5184, -4.0881,  ..., -5.0321, -5.0322, -5.0315],
         [ 2.3831,  2.2049, -0.3057,  ..., -6.5912, -6.5907, -6.5909],
         [-2.3334, -2.7213, -4.7815,  ..., -9.8526, -9.8525, -9.8523],
         ...,
         [ 3.3538,  1.4944,  1.0958,  ..., -6.4574, -6.4574, -6.4577],
         [ 5.6523,  0.4127,  1.0138,  ..., -8.7066, -8.7066, -8.7068],
         [ 0.3297, -0.7106, -0.8580,  ..., -7.7929, -7.7928, -7.7930]]],
       device='cuda:0', grad_fn=<UnsafeViewBackward0>)

TE before:

logits: tensor([[[-0.6598, -4.5184, -4.0881,  ..., -5.0321, -5.0322, -5.0316],
         [ 2.1408,  2.3935, -0.1826,  ..., -6.7005, -6.7000, -6.7002],
         [-2.5307, -3.0045, -4.9231,  ..., -9.4020, -9.4019, -9.4017],
         ...,
         [ 3.3538,  1.4944,  1.0958,  ..., -6.4574, -6.4574, -6.4578],
         [ 5.6524,  0.4127,  1.0138,  ..., -8.7066, -8.7066, -8.7068],
         [ 0.3297, -0.7106, -0.8580,  ..., -7.7929, -7.7928, -7.7930]]],
       device='cuda:0', grad_fn=<TransposeBackward0>)

TE after:

logits: tensor([[[-0.6598, -4.5184, -4.0881,  ..., -5.0321, -5.0322, -5.0316],
         [ 2.3831,  2.2049, -0.3057,  ..., -6.5912, -6.5907, -6.5909],
         [-2.3334, -2.7213, -4.7815,  ..., -9.8526, -9.8525, -9.8523],
         ...,
         [ 3.3538,  1.4944,  1.0958,  ..., -6.4574, -6.4574, -6.4578],
         [ 5.6524,  0.4127,  1.0138,  ..., -8.7066, -8.7066, -8.7068],
         [ 0.3297, -0.7106, -0.8580,  ..., -7.7929, -7.7928, -7.7930]]],
       device='cuda:0', grad_fn=<TransposeBackward0>)

Type of change

  • Documentation change (change only to the documentation, either a fix or a new content)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Infra/Build change
  • Code refractor

Changes

Please list the changes introduced in this PR:

  • Change A
  • Change B

Checklist:

  • I have read and followed the contributing guidelines
  • The functionality is complete
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@xrennvidia
Copy link
Collaborator

/te-ci pytorch

@xrennvidia
Copy link
Collaborator

/te-ci pytorch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants