MCPcopy Create free account
hub / github.com/OpenDriveLab/ReSim / attention

Function attention

SwissArmyTransformer/tests/test_mea.py:20–26  ·  view source on GitHub ↗
(query, key, value)

Source from the content-addressed store, hash-verified

18 return out
19
20def attention(query, key, value):
21 scale = 1 / query.shape[-1] ** 0.5
22 query = query * scale
23 attn = query @ key.transpose(-2, -1)
24 attn = attn.softmax(-1)
25 attn = torch.nn.functional.dropout(attn, 0)
26 return attn @ value
27
28def test_standard_attention(seq_len, hidden_size, num_heads, batch_size=8, qkv=None):
29 # set random seed

Callers 1

test_standard_attentionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected