Skip to main content

Module attention

Module attention 

Source
Expand description

Scaled dot-product attention — the STEM definition of the transformer’s attention operation, as the composition it actually is:

Attention(Q, K, V) = softmax( (Q·Kᵀ) · scale ) · V

There is nothing proprietary here: it is two matrix multiplies (super::linear_algebra::gemm) with a row-wise normalized exponential (super::activation::softmax) between them. This module is the inspectable home for that math. The LLM runtime’s cpu_attention_pass / GPU attention shaders are backends that compute this same function (plus the integrated KV-cache, RoPE and projection plumbing); gguf is only the weight file format.

Caller-owned, zero internal allocation: the n_q × n_k score matrix and the n_q × d_v output are caller-supplied buffers.

Functions§

scaled_dot_product_attention
Compute O = softmax((Q·Kᵀ)·scale) · V, row-major, caller-owned.