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

[TEST ONLY]Drop scaled_dot_product_attention #6367

Open
wants to merge 1 commit into
base: gh/helunwencser/60/base
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion examples/models/llama/llama_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

# Please refer to README.md in the same folder for more information.

import math
from dataclasses import dataclass
from functools import partial
from typing import Dict, Optional, Tuple
Expand Down Expand Up @@ -251,7 +252,10 @@ def forward(

k = k.repeat_interleave(self.n_rep, dim=1)
v = v.repeat_interleave(self.n_rep, dim=1)
y = F.scaled_dot_product_attention(q, k, v, attn_mask=attn_mask, dropout_p=0.0)
scores = torch.matmul(q, k.transpose(2, 3)) / math.sqrt(self.head_dim)
scores = scores + attn_mask
scores = F.softmax(scores.float(), dim=-1).type_as(q)
y = torch.matmul(scores, v)

return y.transpose(1, 2).contiguous().view(bsz, seqlen, self.dim)

Expand Down
Loading