32 independent transformer blocks › Attention
Row-wise softmax
×no parametersF.softmax(scores.float(), dim=-1).type_as(xq)
Convert each query row into normalized attention weights.
- in
- [B batch, 32 q heads, T queries, T keys]
- out
- [B batch, 32 q heads, T queries, T keys]
In float32, then cast back to the query type.
Explanation
, , and index batch, head, query and key; runs over the keys.
Codemodel.py 187
scores = F.softmax(scores.float(), dim=-1).type_as(xq)Sources1
Direct evidence
Softmax normalizes the last score axis in float32 and restores the query dtype.
attn-softmax · meta-llama/llama3 / llama/model.py
Pinned revision a0940f9cf706 ↗ · lines 187–187
Read code excerpt
scores = F.softmax(scores.float(), dim=-1).type_as(xq)