Skip to content
Merged
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
5 changes: 5 additions & 0 deletions OpenCOOD/opencood/models/fuse_modules/self_attn.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ def __init__(self, dim):
self.sqrt_dim = np.sqrt(dim)

def forward(self, query, key, value):
# Single-element attention is an identity operation. Skip backend kernel
# dispatch for this degenerate case (for example, Triton on CUDA).
if query.size(1) == 1 and key.size(1) == 1 and value.size(1) == 1:
return value

score = torch.bmm(query, key.transpose(1, 2)) / self.sqrt_dim
attn = F.softmax(score, -1)
context = torch.bmm(attn, value)
Expand Down
Loading